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 */
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; }