can handle include now
git-svn-id: file:///raid/svn-personal/tewi/trunk@5 8739d7e6-ffea-ec47-b151-bdff447c6205
This commit is contained in:
parent
9e34a40944
commit
e8ba2c3751
|
@ -3,10 +3,14 @@
|
|||
#ifndef __CM_STRING_H__
|
||||
#define __CM_STRING_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
char* cm_strcat(const char* a, const char* b);
|
||||
char* cm_strdup(const char* str);
|
||||
char* cm_trimstart(const char* str);
|
||||
char* cm_trimend(const char* str);
|
||||
char* cm_trim(const char* str);
|
||||
char** cm_split(const char* str, const char* by);
|
||||
bool cm_strcaseequ(const char* a, const char* b);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h>
|
||||
|
||||
char* cm_strcat(const char* a, const char* b) {
|
||||
char* str = malloc(strlen(a) + strlen(b) + 1);
|
||||
|
@ -41,3 +43,64 @@ char* cm_trim(const char* str){
|
|||
free(tmp);
|
||||
return s;
|
||||
}
|
||||
|
||||
char** cm_split(const char* str, const char* by){
|
||||
int i;
|
||||
char** r = malloc(sizeof(*r));
|
||||
r[0] = NULL;
|
||||
char* b = malloc(1);
|
||||
b[0] = 0;
|
||||
char cbuf[2];
|
||||
cbuf[1] = 0;
|
||||
bool dq = false;
|
||||
bool sq = false;
|
||||
for(i = 0;; i++){
|
||||
int j;
|
||||
bool has = false;
|
||||
for(j = 0; by[j] != 0; j++){
|
||||
if(by[j] == str[i]){
|
||||
has = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!(dq || sq) && (has || str[i] == 0)){
|
||||
if(strlen(b) > 0){
|
||||
char** old = r;
|
||||
int j;
|
||||
for(j = 0; old[j] != NULL; j++);
|
||||
r = malloc(sizeof(*r) * (j + 2));
|
||||
for(j = 0; old[j] != NULL; j++) r[j] = old[j];
|
||||
r[j] = b;
|
||||
r[j + 1] = NULL;
|
||||
free(old);
|
||||
}
|
||||
b = malloc(1);
|
||||
b[0] = 0;
|
||||
if(str[i] == 0) break;
|
||||
}else{
|
||||
if(str[i] == '"' && !sq){
|
||||
dq = !dq;
|
||||
}else if(str[i] == '\'' && !dq){
|
||||
sq = !sq;
|
||||
}else{
|
||||
cbuf[0] = str[i];
|
||||
char* tmp = b;
|
||||
b = cm_strcat(tmp, cbuf);
|
||||
free(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
free(b);
|
||||
return r;
|
||||
}
|
||||
|
||||
bool cm_strcaseequ(const char* a, const char* b){
|
||||
if(a == NULL) return false;
|
||||
if(b == NULL) return false;
|
||||
if(strlen(a) != strlen(b)) return false;
|
||||
int i;
|
||||
for(i = 0; a[i] != 0; i++){
|
||||
if(tolower(a[i]) != tolower(b[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,22 @@ int tw_config_read(const char* path){
|
|||
if(cbuf[0] == '\n' || c <= 0){
|
||||
char* l = cm_trim(line);
|
||||
if(strlen(l) > 0 && l[0] != '#'){
|
||||
printf("[%s]\n", l);
|
||||
char** r = cm_split(l, " \t");
|
||||
int i;
|
||||
if(cm_strcaseequ(r[0], "Include") || cm_strcaseequ(r[0], "IncludeOptional")){
|
||||
for(i = 1; r[i] != NULL; i++){
|
||||
if(tw_config_read(r[i]) != 0 && cm_strcaseequ(r[0], "Include")){
|
||||
for(i = 0; r[i] != NULL; i++) free(r[i]);
|
||||
free(r);
|
||||
free(line);
|
||||
free(l);
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(i = 0; r[i] != NULL; i++) free(r[i]);
|
||||
free(r);
|
||||
}
|
||||
free(l);
|
||||
free(line);
|
||||
|
@ -39,6 +54,7 @@ int tw_config_read(const char* path){
|
|||
fclose(f);
|
||||
return 0;
|
||||
}else{
|
||||
cm_log("Config", "Could not open the file");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user