FINISHED =8,
} parse_state_t;
+// variables
+
+const char *ini_specials=";\\#[]=";
+
// functions
// ini_line_parse()
char c;
int type=SYNTAX_ERROR;
int spaces=0;
- bool outer_quote=FALSE;
+ bool quoted;
while(state!=FINISHED){
c=line[index++];
-// printf("STATE=%d c=[%c]\n",state,c);
+ quoted=FALSE;
+ if(c=='\\'){
+ if(strchr(ini_specials,line[index])){
+ quoted=TRUE;
+ c=line[index++];
+ }
+ }
+ // printf("STATE=%d quoted=%d c=[%c]\n",state,quoted,c);
switch(state){
case START:
- if((c==';')||(c=='#')||(c=='\r')||(c=='\n')||(c=='\0')){
+ if(!quoted && ((c==';')||(c=='#')||(c=='\r')||
+ (c=='\n')||(c=='\0'))){
type=EMPTY_LINE;
state=FINISHED;
- }else if(c=='['){
+ }else if(!quoted && c=='['){
state=SECTION_NAME;
- }else if(c!=' '){
+ }else if(quoted || c!=' '){
name[name_index++]=c;
state=NAME;
}
goto next;
break;
case NAME:
- if(c=='='){
+ if(!quoted && c=='='){
state=START_VALUE;
- }else if(c==' '){
+ }else if(!quoted && c==' '){
state=NAME_SPACE;
spaces=1;
- }else if((c==';')||(c=='#')||(c=='\r')||(c=='\n')||(c=='\0')){
+ }else if(!quoted && ((c==';')||(c=='#')||(c=='\r')
+ ||(c=='\n')||(c=='\0'))){
type=SYNTAX_ERROR;
state=FINISHED;
}else{
goto next;
break; // we don't get here
case NAME_SPACE:
- if(c==' '){
+ if(!quoted && c==' '){
spaces++;
- }else if(c=='='){
+ }else if(!quoted && c=='='){
state=START_VALUE;
- }else if((c==';')||(c=='#')||(c=='\r')||(c=='\n')||(c=='\0')){
+ }else if(!quoted && ((c==';')||(c=='#')||(c=='\r')||
+ (c=='\n')||(c=='\0'))){
type=SYNTAX_ERROR;
state=FINISHED;
}else{
goto next;
break; // we don't get here
case START_VALUE:
- if(c=='"'){
- outer_quote=TRUE;
- spaces=0;
- state=VALUE_SPACE;
- }else if((c==';')||(c=='#')||(c=='\r')||(c=='\n')||(c=='\0')){
+ if(!quoted && ((c==';')||(c=='#')||(c=='\r')||
+ (c=='\n')||(c=='\0'))){
type=EMPTY_VALUE;
state=FINISHED;
- }else if(c!=' '){
+ }else if(quoted || c!=' '){
value[value_index++]=c;
state=VALUE;
}
goto next;
break; // we don't get here
case VALUE:
- if(c=='"'){
- state=QUOTE_SPACE;
- spaces=0;
- }else if(c==' '){
+ if(!quoted && c==' '){
state=VALUE_SPACE;
spaces=1;
- }else if((c=='\r' || c=='\n' || c==';' || c=='#'||(c=='\0'))&&
- !outer_quote){
+ }else if(!quoted && ((c=='\r' || c=='\n' || c==';' ||
+ c=='#'||(c=='\0')))){
type=NAME_VALUE;
state=FINISHED;
}else{
goto next;
break; // we don't get here
case VALUE_SPACE:
- if(c==' '){
+ if(!quoted && c==' '){
spaces++;
- }else if((c=='\r' || c=='\n' || c==';' || c=='#'||(c=='\0'))&&
- !outer_quote){
+ }else if(!quoted && ((c=='\r' || c=='\n' || c==';' ||
+ c=='#'||(c=='\0')))){
type=NAME_VALUE;
state=FINISHED;
}else{
value[value_index++]=' ';
}
spaces=0;
- if(c!='"'){
- value[value_index++]=c;
- state=VALUE;
- }else{
- state=QUOTE_SPACE;
- }
- }
- goto next;
- break; // we don't get here
- case QUOTE_SPACE:
- if(c==' '){
- spaces++;
- }else if(c=='\r' || c=='\n' || c==';' || c=='#'||(c=='\0')){
- type=NAME_VALUE;
- state=FINISHED;
- }else{
- value[value_index++]='"';
- for(i=0;i<spaces;i++){
- value[value_index++]=' ';
- }
- spaces=0;
- if(c!='"'){
- value[value_index++]=c;
- state=VALUE;
- }else{
- state=QUOTE_SPACE;
- }
+ value[value_index++]=c;
+ state=VALUE;
}
goto next;
break; // we don't get here
case SECTION_NAME:
- if(c==']'){
+ if(!quoted && c==']'){
type=SECTION;
state=FINISHED;
}else{
ini->index=0;
}
+// ini_copy()
+
+void ini_copy(ini_t *dst, ini_t *src){
+ int i;
+ dst->index=src->index;
+ dst->iter=src->iter;
+ for(i=0;i<src->index;i++){
+ my_string_set(&dst->entries[i].section,src->entries[i].section);
+ my_string_set(&dst->entries[i].name,src->entries[i].name);
+ my_string_set(&dst->entries[i].value,src->entries[i].value);
+ }
+}
+
// ini_find()
ini_entry_t *ini_find(ini_t *ini, const char *section, const char* name){
void ini_disp(ini_t *ini){
int i;
- my_log("POLYGLOT Current options\n");
for(i=0;i<ini->index;i++){
my_log("POLYGLOT [%s] %s=\"%s\"\n",
(ini->entries)[i].section,
return &ini->entries[ini->iter++];
}
-// ini_create_pg()