/*=export_func optionFileLoad * * what: Load the locatable config files, in order * * arg: + tOptions* + pOpts + program options descriptor + * arg: + char const* + pzProg + program name + * * ret_type: int * ret_desc: 0 -> SUCCESS, -1 -> FAILURE * * doc: * * This function looks in all the specified directories for a configuration * file ("rc" file or "ini" file) and processes any found twice. The first * time through, they are processed in reverse order (last file first). At * that time, only "immediate action" configurables are processed. For * example, if the last named file specifies not processing any more * configuration files, then no more configuration files will be processed. * Such an option in the @strong{first} named directory will have no effect. * * Once the immediate action configurables have been handled, then the * directories are handled in normal, forward order. In that way, later * config files can override the settings of earlier config files. * * See the AutoOpts documentation for a thorough discussion of the * config file format. * * Configuration files not found or not decipherable are simply ignored. * * err: Returns the value, "-1" if the program options descriptor * is out of date or indecipherable. Otherwise, the value "0" will * always be returned. =*/ int optionFileLoad( tOptions* pOpts, char const* pzProgram ) { if (! SUCCESSFUL( validateOptionsStruct( pOpts, pzProgram ))) return -1; pOpts->pzProgName = pzProgram; internalFileLoad( pOpts ); return 0; }
/** * check for preset values from a config files or envrionment variables */ static tSuccess doPresets(tOptions* pOpts) { tOptDesc * pOD = NULL; if (! SUCCESSFUL(doImmediateOpts(pOpts))) return FAILURE; /* * IF this option set has a --save-opts option, then it also * has a --load-opts option. See if a command line option has disabled * option presetting. */ if ( (pOpts->specOptIdx.save_opts != NO_EQUIVALENT) && (pOpts->specOptIdx.save_opts != 0)) { pOD = pOpts->pOptDesc + pOpts->specOptIdx.save_opts + 1; if (DISABLED_OPT(pOD)) return SUCCESS; } /* * Until we return from this procedure, disable non-presettable opts */ pOpts->fOptSet |= OPTPROC_PRESETTING; /* * IF there are no config files, * THEN do any environment presets and leave. */ if (pOpts->papzHomeList == NULL) { doEnvPresets(pOpts, ENV_ALL); } else { doEnvPresets(pOpts, ENV_IMM); /* * Check to see if environment variables have disabled presetting. */ if ((pOD != NULL) && ! DISABLED_OPT(pOD)) internalFileLoad(pOpts); /* * ${PROGRAM_LOAD_OPTS} value of "no" cannot disable other environment * variable options. Only the loading of .rc files. */ doEnvPresets(pOpts, ENV_NON_IMM); } pOpts->fOptSet &= ~OPTPROC_PRESETTING; return SUCCESS; }
/*=export_func optionFileLoad * * what: Load the locatable config files, in order * * arg: + tOptions* + pOpts + program options descriptor + * arg: + char const* + pzProg + program name + * * ret_type: int * ret_desc: 0 -> SUCCESS, -1 -> FAILURE * * doc: * * This function looks in all the specified directories for a configuration * file ("rc" file or "ini" file) and processes any found twice. The first * time through, they are processed in reverse order (last file first). At * that time, only "immediate action" configurables are processed. For * example, if the last named file specifies not processing any more * configuration files, then no more configuration files will be processed. * Such an option in the @strong{first} named directory will have no effect. * * Once the immediate action configurables have been handled, then the * directories are handled in normal, forward order. In that way, later * config files can override the settings of earlier config files. * * See the AutoOpts documentation for a thorough discussion of the * config file format. * * Configuration files not found or not decipherable are simply ignored. * * err: Returns the value, "-1" if the program options descriptor * is out of date or indecipherable. Otherwise, the value "0" will * always be returned. =*/ int optionFileLoad(tOptions* pOpts, char const* pzProgram) { if (! SUCCESSFUL(validateOptionsStruct(pOpts, pzProgram))) return -1; { char const ** pp = (char const **)(void *)&(pOpts->pzProgName); *pp = pzProgram; } internalFileLoad(pOpts); return 0; }