int fifo_get_param(FILE* fp, string& p, char* line_buf, unsigned int size) { if( fifo_get_line(fp,line_buf,size) !=-1 ) { if(!strcmp(".",line_buf)) line_buf[0]='\0'; p = line_buf; } else { ERROR("could not read from FIFO: %s\n",strerror(errno)); return -1; } return 0; }
int fifo_get_lines(FILE* fifo_stream, char* str, size_t len) { int l=0,max=len; char* s=str; if(!len) return 0; while( max>0 && (l=fifo_get_line(fifo_stream,s,max)) && l!=-1 ) { if(!strcmp(".",s)) break; s+=l; *(s++)='\n'; max-=l+1; } s[0]='\0'; return (l!=-1 ? s-str : -1); }
int AmConfigReader::loadFile(const string& path) { FILE* fp = fopen(path.c_str(),"r"); if(!fp){ WARN("could not open configuration file '%s': %s\n", path.c_str(),strerror(errno)); return -1; } int lc = 0; int ls = 0; char lb[MAX_CONFIG_LINE] = {'\0'}; char *c,*key_beg,*key_end,*val_beg,*val_end,*inc_beg,*inc_end; c=key_beg=key_end=val_beg=val_end=inc_beg=inc_end=0; while(!feof(fp) && ((ls = fifo_get_line(fp, lb, MAX_CONFIG_LINE)) != -1)){ c=key_beg=key_end=val_beg=val_end=0; lc++; c = lb; TRIM(c); if(IS_EOL(*c)) continue; if (*c == '@') { /* process included config file */ c++; TRIM(c); inc_beg = c++; while( !IS_EOL(*c) && !IS_SPACE(*c) ) c++; inc_end = c; string fname = string(inc_beg,inc_end-inc_beg); if (fname.length() && fname[0] != '/') fname = AmConfig::ModConfigPath + fname; if(loadFile(fname)) goto error; continue; } key_beg = c; while( (*c != '=') && !IS_SPACE(*c) ) c++; key_end = c; if(IS_SPACE(*c)) TRIM(c); else if( !(c - key_beg) ) goto syntax_error; if(*c != '=') goto syntax_error; c++; TRIM(c); if(*c == '"'){ char last_c = ' '; val_beg = ++c; while( ((*c != '"') || (last_c == '\\')) && (*c != '\0') ) { last_c = *c; c++; } if(*c == '\0') goto syntax_error; val_end = c; } else { val_beg = c; while( !IS_EOL(*c) && !IS_SPACE(*c) ) c++; val_end = c; } if((key_beg < key_end) && (val_beg <= val_end)) { string keyname = string(key_beg,key_end-key_beg); string val = string(val_beg,val_end-val_beg); if (hasParameter(keyname)) { WARN("while loading '%s': overwriting configuration " "'%s' value '%s' with '%s'\n", path.c_str(), keyname.c_str(), getParameter(keyname).c_str(), val.c_str()); } keys[keyname] = val; // small hack to make include work with right path if (keyname == "plugin_config_path") AmConfig::ModConfigPath = val; } else goto syntax_error; } fclose(fp); return 0; syntax_error: ERROR("syntax error line %i in %s\n",lc,path.c_str()); error: fclose(fp); return -1; }