/** * check for preset values from a config files or envrionment variables * * @param[in,out] opts the structure with the option names to check */ static tSuccess do_presets(tOptions * opts) { tOptDesc * od = NULL; if (! SUCCESSFUL(immediate_opts(opts))) 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 ( (opts->specOptIdx.save_opts != NO_EQUIVALENT) && (opts->specOptIdx.save_opts != 0)) { od = opts->pOptDesc + opts->specOptIdx.save_opts + 1; if (DISABLED_OPT(od)) return SUCCESS; } /* * Until we return from this procedure, disable non-presettable opts */ opts->fOptSet |= OPTPROC_PRESETTING; /* * IF there are no config files, * THEN do any environment presets and leave. */ if (opts->papzHomeList == NULL) { env_presets(opts, ENV_ALL); } else { env_presets(opts, ENV_IMM); /* * Check to see if environment variables have disabled presetting. */ if ((od != NULL) && ! DISABLED_OPT(od)) intern_file_load(opts); /* * ${PROGRAM_LOAD_OPTS} value of "no" cannot disable other environment * variable options. Only the loading of .rc files. */ env_presets(opts, ENV_NON_IMM); } opts->fOptSet &= ~OPTPROC_PRESETTING; return SUCCESS; }
/*=export_func optionFileLoad * * what: Load the locatable config files, in order * * arg: + tOptions * + opts + program options descriptor + * arg: + char const * + prog + 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 * opts, char const * prog) { if (! SUCCESSFUL(validate_struct(opts, prog))) return -1; /* * The pointer to the program name is "const". However, the * structure is in writable memory, so we coerce the address * of this pointer to point to writable memory. */ { char const ** pp = VOIDP(&(opts->pzProgName)); *pp = prog; } intern_file_load(opts); return 0; }