| 176 | |
| 177 | |
| 178 | static BOOL Section( FILE *InFile, BOOL (*sfunc)(char *) ) |
| 179 | /* ------------------------------------------------------------------------ ** |
| 180 | * Scan a section name, and pass the name to function sfunc(). |
| 181 | * |
| 182 | * Input: InFile - Input source. |
| 183 | * sfunc - Pointer to the function to be called if the section |
| 184 | * name is successfully read. |
| 185 | * |
| 186 | * Output: True if the section name was read and True was returned from |
| 187 | * <sfunc>. False if <sfunc> failed or if a lexical error was |
| 188 | * encountered. |
| 189 | * |
| 190 | * ------------------------------------------------------------------------ ** |
| 191 | */ |
| 192 | { |
| 193 | int c; |
| 194 | int i; |
| 195 | int end; |
| 196 | char *func = "params.c:Section() -"; |
| 197 | |
| 198 | i = 0; /* <i> is the offset of the next free byte in bufr[] and */ |
| 199 | end = 0; /* <end> is the current "end of string" offset. In most */ |
| 200 | /* cases these will be the same, but if the last */ |
| 201 | /* character written to bufr[] is a space, then <end> */ |
| 202 | /* will be one less than <i>. */ |
| 203 | |
| 204 | c = EatWhitespace( InFile ); /* We've already got the '['. Scan */ |
| 205 | /* past initial white space. */ |
| 206 | |
| 207 | while( (EOF != c) && (c > 0) ) |
| 208 | { |
| 209 | |
| 210 | /* Check that the buffer is big enough for the next character. */ |
| 211 | if( i > (bSize - 2) ) |
| 212 | { |
| 213 | bSize += BUFR_INC; |
| 214 | bufr = realloc_array( bufr, char, bSize ); |
| 215 | } |
| 216 | |
| 217 | /* Handle a single character. */ |
| 218 | switch( c ) |
| 219 | { |
| 220 | case ']': /* Found the closing bracket. */ |
| 221 | bufr[end] = '\0'; |
| 222 | if( 0 == end ) /* Don't allow an empty name. */ |
| 223 | { |
| 224 | rprintf(FLOG, "%s Empty section name in config file.\n", func ); |
| 225 | return( False ); |
| 226 | } |
| 227 | if( !sfunc( bufr ) ) /* Got a valid name. Deal with it. */ |
| 228 | return( False ); |
| 229 | (void)EatComment( InFile ); /* Finish off the line. */ |
| 230 | return( True ); |
| 231 | |
| 232 | case '\n': /* Got newline before closing ']'. */ |
| 233 | i = Continuation( bufr, i ); /* Check for line continuation. */ |
| 234 | if( i < 0 ) |
| 235 | { |
no test coverage detected