int ConfigFile::_ReadEntry(const char *entry, char *buf, int bufSize,bool strip ) { /* 功能:读取entry的值 参数: entry[IN]:entry名称 buf[IN]:存放entry的值的缓冲区 bufSize[IN]:缓冲区长度 strip[IN]:去除空格标志 返回值: 成功返回读取的长度 失败返回-1 */ char lineBuf[1024]; //memset(lineBuf,0,1024); char *p, *cur; int len; cur = buf; *cur = '\0'; len = -1; while(FGetS(lineBuf,1023,fin)) { if( isTitleLine( lineBuf ) ) // section fis ended break; p = textPos( lineBuf, entry ); // not equal this entry if( p == 0 ) continue; if( strip ) stripQuotationChar( p ); len = strlen(p); if( bufSize-1 < len ) len = bufSize-1; strncpy( cur, p, len ); cur[len] = 0; break; } 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; }