// --------------------------------------------------------------------------- // readPair: read content of entry // --------------------------------------------------------------------------- Int32 UdrCfgParser::readPair( FILE *is, char *buf, Int32 bufSize , NAString &errorText ) { char lineBuf[BUFFMAX+2]; char *p, *cur; Int32 len = -1; NABoolean quote = FALSE; while( fgets( lineBuf, sizeof(lineBuf), is ) ) { len = -1; remEOL(lineBuf); if( isTitleLine( lineBuf ) ) // section is ended break; p=lineBuf; if (quote == FALSE) stripComment( p ); rtrim(p); if ((len = (Int32)strlen(p)) == 0) continue; if( bufSize-1 < len ) { errorText += "*** ERROR: UdrCfgParser():fgets read line longer than BUFFMAX of "; errorText += LongToNAString((Lng32) BUFFMAX); errorText += " in config file "; errorText += cfgFileName; errorText += ".\n"; return -1; } cur = buf; *cur = '\0'; strncpy( cur, p, len ); cur[len] = 0; break; } if (ferror(is)) { errorText += "*** ERROR: UdrCfgParser(): fgets failed on config file "; errorText += cfgFileName; errorText += " due to an I/O error: "; errorText += strerror(errno); errorText += ".\n"; } return len; }
/* ------------------------------------------------------------------------------ */ static int readEntry( FILE *is, const char *entry, char *buf, int bufSize, int strip ) { char lineBuf[256]; char *p, *cur; int len; bool quote = false; cur = buf; *cur = '\0'; len = -1; while( fgets( lineBuf, 256, is ) ) { remEOL(lineBuf); if( isTitleLine( lineBuf ) ) /* section is ended */ break; p = textPos( lineBuf, entry ); /* not equal this entry */ if( p == 0 ) continue; if( strip ) quote = stripQuotationChar( p ); if (quote == false) stripComment( p ); rtrim(p); len = (int)strlen(p); if( bufSize-1 < len ) len = bufSize-1; strncpy( cur, p, len ); cur[len] = 0; break; } return len; }