BOOL pm_process( char *FileName, BOOL (*sfunc)(char *), BOOL (*pfunc)(char *, char *) ) /* ------------------------------------------------------------------------ ** * Process the named parameter file. * * Input: FileName - The pathname of the parameter file to be opened. * sfunc - A pointer to a function that will be called when * a section name is discovered. * pfunc - A pointer to a function that will be called when * a parameter name and value are discovered. * * Output: TRUE if the file was successfully parsed, else FALSE. * * ------------------------------------------------------------------------ ** */ { int result; myFILE *InFile; char *func = "params.c:pm_process() -"; InFile = OpenConfFile( FileName ); /* Open the config file. */ if( NULL == InFile ) return( False ); DEBUG( 3, ("%s Processing configuration file \"%s\"\n", func, FileName) ); if( NULL != bufr ) /* If we already have a buffer */ result = Parse( InFile, sfunc, pfunc ); /* (recursive call), then just */ /* use it. */ else /* If we don't have a buffer */ { /* allocate one, then parse, */ bSize = BUFR_INC; /* then free. */ bufr = (char *)malloc( bSize ); if( NULL == bufr ) { DEBUG(0,("%s memory allocation failure.\n", func)); myfile_close(InFile); return( False ); } result = Parse( InFile, sfunc, pfunc ); free( bufr ); bufr = NULL; bSize = 0; } myfile_close(InFile); if( !result ) /* Generic failure. */ { DEBUG(0,("%s Failed. Error returned from params.c:parse().\n", func)); return( False ); } return( True ); /* Generic success. */ } /* pm_process */
int ReadFile(const char *filename, const char *target, int (*func) (Context ctx, int ac, char *av[], const char *file, int line), Context ctx) { FILE *fp; int ac; char *av[MAX_LINE_ARGS]; char *line; char buf[BIG_LINE_SIZE]; struct configfile *cf; int lineNum; /* Open file */ if ((fp = OpenConfFile(filename, &cf)) == NULL) return (-2); /* Find label */ if (SeekToLabel(fp, target, &lineNum, cf) < 0) { fclose(fp); return (-1); } /* Execute command list */ while ((line = ReadFullLine(fp, &lineNum, buf, sizeof(buf))) != NULL) { if (!isspace(*line)) { break; } ac = ParseLine(line, av, sizeof(av) / sizeof(*av), 0); (*func) (ctx, ac, av, filename, lineNum); } /* Done */ fclose(fp); return (0); }
bool pm_process( const char *FileName, bool (*sfunc)(const char *, void *), bool (*pfunc)(const char *, const char *, void *), void *userdata) { int result; myFILE *InFile; const char *func = "params.c:pm_process() -"; DATA_BLOB buf; InFile = OpenConfFile( FileName ); /* Open the config file. */ if( NULL == InFile ) return False; DEBUG( 3, ("%s Processing configuration file \"%s\"\n", func, FileName) ); buf = data_blob(NULL, 256); if (buf.data == NULL) { DEBUG(0,("%s memory allocation failure.\n", func)); myfile_close(InFile); return False; } result = Parse( &buf, InFile, sfunc, pfunc, userdata ); data_blob_free(&buf); myfile_close(InFile); if( !result ) { DEBUG(0,("%s Failed. Error returned from params.c:parse().\n", func)); return False; } return True; }