2 * $Id: configfile.c,v 1.21 2007/04/15 19:01:18 bkorb Exp $
3 * Time-stamp: "2007-04-15 11:22:46 bkorb"
5 * configuration/rc/ini file handling.
9 * Automated Options copyright 1992-2007 Bruce Korb
11 * Automated Options is free software.
12 * You may redistribute it and/or modify it under the terms of the
13 * GNU General Public License, as published by the Free Software
14 * Foundation; either version 2, or (at your option) any later version.
16 * Automated Options is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with Automated Options. See the file "COPYING". If not,
23 * write to: The Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA.
27 * As a special exception, Bruce Korb gives permission for additional
28 * uses of the text contained in his release of AutoOpts.
30 * The exception is that, if you link the AutoOpts library with other
31 * files to produce an executable, this does not by itself cause the
32 * resulting executable to be covered by the GNU General Public License.
33 * Your use of that executable is in no way restricted on account of
34 * linking the AutoOpts library code into it.
36 * This exception does not however invalidate any other reasons why
37 * the executable file might be covered by the GNU General Public License.
39 * This exception applies only to the code released by Bruce Korb under
40 * the name AutoOpts. If you copy code from other sources under the
41 * General Public License into a copy of AutoOpts, as the General Public
42 * License permits, the exception does not apply to the code that you add
43 * in this way. To avoid misleading anyone as to the status of such
44 * modified files, you must delete this exception notice from them.
46 * If you write modifications of your own for AutoOpts, it is your choice
47 * whether to permit this exception to apply to your modifications.
48 * If you do not wish that, delete this exception notice.
51 /* = = = START-STATIC-FORWARD = = = */
52 /* static forward declarations maintained by :mkfwd */
56 char const* pzFileName,
60 handleComment( char* pzText );
90 tOptionValue* pType );
95 tOptionLoadMode* pMode );
101 tOptionValue* pType );
106 tOptionValue* pType );
109 skipUnknown( char* pzText );
110 /* = = = END-STATIC-FORWARD = = = */
113 /*=export_func configFileLoad
115 * what: parse a configuration file
116 * arg: + char const* + pzFile + the file to load +
118 * ret_type: const tOptionValue*
119 * ret_desc: An allocated, compound value structure
122 * This routine will load a named configuration file and parse the
123 * text as a hierarchically valued option. The option descriptor
124 * created from an option definition file is not used via this interface.
125 * The returned value is "named" with the input file name and is of
126 * type "@code{OPARG_TYPE_HIERARCHY}". It may be used in calls to
127 * @code{optionGetValue()}, @code{optionNextValue()} and
128 * @code{optionUnloadNested()}.
131 * If the file cannot be loaded or processed, @code{NULL} is returned and
132 * @var{errno} is set. It may be set by a call to either @code{open(2)}
133 * @code{mmap(2)} or other file system calls, or it may be:
136 * @code{ENOENT} - the file was empty.
138 * @code{EINVAL} - the file contents are invalid -- not properly formed.
140 * @code{ENOMEM} - not enough memory to allocate the needed structures.
144 configFileLoad( char const* pzFile )
147 tOptionValue* pRes = NULL;
148 tOptionLoadMode save_mode = option_load_mode;
151 text_mmap( pzFile, PROT_READ, MAP_PRIVATE, &cfgfile );
153 if (TEXT_MMAP_FAILED_ADDR(pzText))
154 return NULL; /* errno is set */
156 option_load_mode = OPTION_LOAD_COOKED;
157 pRes = optionLoadNested(pzText, pzFile, strlen(pzFile));
161 text_munmap( &cfgfile );
164 text_munmap( &cfgfile );
166 option_load_mode = save_mode;
171 /*=export_func optionFindValue
173 * what: find a hierarcicaly valued option instance
174 * arg: + const tOptDesc* + pOptDesc + an option with a nested arg type +
175 * arg: + char const* + name + name of value to find +
176 * arg: + char const* + value + the matching value +
178 * ret_type: const tOptionValue*
179 * ret_desc: a compound value structure
182 * This routine will find an entry in a nested value option or configurable.
183 * It will search through the list and return a matching entry.
186 * The returned result is NULL and errno is set:
189 * @code{EINVAL} - the @code{pOptValue} does not point to a valid
190 * hierarchical option value.
192 * @code{ENOENT} - no entry matched the given name.
196 optionFindValue( const tOptDesc* pOptDesc,
197 char const* pzName, char const* pzVal )
199 const tOptionValue* pRes = NULL;
201 if ( (pOptDesc == NULL)
202 || (OPTST_GET_ARGTYPE(pOptDesc->fOptState) != OPARG_TYPE_HIERARCHY)) {
206 else if (pOptDesc->optCookie == NULL) {
211 tArgList* pAL = pOptDesc->optCookie;
213 void** ppOV = (void**)(pAL->apzArgs);
220 if (pzName == NULL) {
221 pRes = (tOptionValue*)*ppOV;
226 const tOptionValue* pOV = *(ppOV++);
227 const tOptionValue* pRV = optionGetValue( pOV, pzName );
245 /*=export_func optionFindNextValue
247 * what: find a hierarcicaly valued option instance
248 * arg: + const tOptDesc* + pOptDesc + an option with a nested arg type +
249 * arg: + const tOptionValue* + pPrevVal + the last entry +
250 * arg: + char const* + name + name of value to find +
251 * arg: + char const* + value + the matching value +
253 * ret_type: const tOptionValue*
254 * ret_desc: a compound value structure
257 * This routine will find the next entry in a nested value option or
258 * configurable. It will search through the list and return the next entry
259 * that matches the criteria.
262 * The returned result is NULL and errno is set:
265 * @code{EINVAL} - the @code{pOptValue} does not point to a valid
266 * hierarchical option value.
268 * @code{ENOENT} - no entry matched the given name.
272 optionFindNextValue( const tOptDesc* pOptDesc, const tOptionValue* pPrevVal,
273 char const* pzName, char const* pzVal )
276 tOptionValue* pRes = NULL;
278 if ( (pOptDesc == NULL)
279 || (OPTST_GET_ARGTYPE(pOptDesc->fOptState) != OPARG_TYPE_HIERARCHY)) {
283 else if (pOptDesc->optCookie == NULL) {
288 tArgList* pAL = pOptDesc->optCookie;
290 void** ppOV = (void**)pAL->apzArgs;
298 tOptionValue* pOV = *(ppOV++);
314 /*=export_func optionGetValue
316 * what: get a specific value from a hierarcical list
317 * arg: + const tOptionValue* + pOptValue + a hierarchcal value +
318 * arg: + char const* + valueName + name of value to get +
320 * ret_type: const tOptionValue*
321 * ret_desc: a compound value structure
324 * This routine will find an entry in a nested value option or configurable.
325 * If "valueName" is NULL, then the first entry is returned. Otherwise,
326 * the first entry with a name that exactly matches the argument will be
330 * The returned result is NULL and errno is set:
333 * @code{EINVAL} - the @code{pOptValue} does not point to a valid
334 * hierarchical option value.
336 * @code{ENOENT} - no entry matched the given name.
340 optionGetValue( const tOptionValue* pOld, char const* pzValName )
343 tOptionValue* pRes = NULL;
345 if ((pOld == NULL) || (pOld->valType != OPARG_TYPE_HIERARCHY)) {
349 pAL = pOld->v.nestVal;
351 if (pAL->useCt > 0) {
353 void** papOV = (void**)(pAL->apzArgs);
355 if (pzValName == NULL) {
356 pRes = (tOptionValue*)*papOV;
360 tOptionValue* pOV = *(papOV++);
361 if (strcmp( pOV->pzName, pzValName ) == 0) {
373 /*=export_func optionNextValue
375 * what: get the next value from a hierarchical list
376 * arg: + const tOptionValue* + pOptValue + a hierarchcal list value +
377 * arg: + const tOptionValue* + pOldValue + a value from this list +
379 * ret_type: const tOptionValue*
380 * ret_desc: a compound value structure
383 * This routine will return the next entry after the entry passed in. At the
384 * end of the list, NULL will be returned. If the entry is not found on the
385 * list, NULL will be returned and "@var{errno}" will be set to EINVAL.
386 * The "@var{pOldValue}" must have been gotten from a prior call to this
387 * routine or to "@code{opitonGetValue()}".
390 * The returned result is NULL and errno is set:
393 * @code{EINVAL} - the @code{pOptValue} does not point to a valid
394 * hierarchical option value or @code{pOldValue} does not point to a
395 * member of that option value.
397 * @code{ENOENT} - the supplied @code{pOldValue} pointed to the last entry.
401 optionNextValue(tOptionValue const * pOVList,tOptionValue const * pOldOV )
404 tOptionValue* pRes = NULL;
407 if ((pOVList == NULL) || (pOVList->valType != OPARG_TYPE_HIERARCHY)) {
411 pAL = pOVList->v.nestVal;
414 void** papNV = (void**)(pAL->apzArgs);
417 tOptionValue* pNV = *(papNV++);
424 pRes = (tOptionValue*)*papNV;
438 * Load a file containing presetting information (a configuration file).
443 char const* pzFileName,
447 tOptState st = OPTSTATE_INITIALIZER(PRESET);
449 text_mmap( pzFileName, PROT_READ|PROT_WRITE, MAP_PRIVATE, &cfgfile );
451 if (TEXT_MMAP_FAILED_ADDR(pzFileText))
454 if (direction == DIRECTION_CALLED) {
455 st.flags = OPTST_DEFINED;
456 direction = DIRECTION_PROCESS;
460 * IF this is called via "optionProcess", then we are presetting.
461 * This is the default and the PRESETTING bit will be set.
462 * If this is called via "optionFileLoad", then the bit is not set
463 * and we consider stuff set herein to be "set" by the client program.
465 if ((pOpts->fOptSet & OPTPROC_PRESETTING) == 0)
466 st.flags = OPTST_SET;
469 while (isspace( (int)*pzFileText )) pzFileText++;
471 if (isalpha( (int)*pzFileText )) {
472 pzFileText = handleConfig( pOpts, &st, pzFileText, direction );
474 } else switch (*pzFileText) {
476 if (isalpha( (int)pzFileText[1] ))
477 pzFileText = handleStructure(pOpts, &st, pzFileText, direction);
479 else switch (pzFileText[1]) {
481 pzFileText = handleDirective( pOpts, pzFileText );
485 pzFileText = handleComment( pzFileText );
489 pzFileText = strchr( pzFileText+2, '>' );
490 if (pzFileText++ != NULL)
499 pzFileText = handleProgramSection( pOpts, pzFileText );
503 pzFileText = strchr( pzFileText+1, '\n' );
507 goto all_done; /* invalid format */
509 } while (pzFileText != NULL);
512 text_munmap( &cfgfile );
518 * "pzText" points to a "<!" sequence.
519 * Theoretically, we should ensure that it begins with "<!--",
520 * but actually I don't care that much. It ends with "-->".
523 handleComment( char* pzText )
525 char* pz = strstr( pzText, "-->" );
534 * "pzText" points to the start of some value name.
535 * The end of the entry is the end of the line that is not preceded by
536 * a backslash escape character. The string value is always processed
546 char* pzName = pzText++;
547 char* pzEnd = strchr( pzText, '\n' );
550 return pzText + strlen(pzText);
552 while (ISNAMECHAR( (int)*pzText )) pzText++;
553 while (isspace( (int)*pzText )) pzText++;
554 if (pzText > pzEnd) {
557 loadOptionLine( pOpts, pOS, pzName, direction, OPTION_LOAD_UNCOOKED );
562 * Either the first character after the name is a ':' or '=',
563 * or else we must have skipped over white space. Anything else
564 * is an invalid format and we give up parsing the text.
566 if ((*pzText == '=') || (*pzText == ':')) {
567 while (isspace( (int)*++pzText )) ;
570 } else if (! isspace((int)pzText[-1]))
574 * IF the value is continued, remove the backslash escape and push "pzEnd"
575 * on to a newline *not* preceded by a backslash.
577 if (pzEnd[-1] == '\\') {
604 * The newline was not preceded by a backslash. NUL it out
610 * "pzName" points to what looks like text for one option/configurable.
611 * It is NUL terminated. Process it.
613 loadOptionLine( pOpts, pOS, pzName, direction, OPTION_LOAD_UNCOOKED );
621 * "pzText" points to a "<?" sequence.
622 * For the moment, we only handle "<?program" directives.
629 char ztitle[32] = "<?";
630 size_t title_len = strlen( zProg );
633 if ( (strncmp( pzText+2, zProg, title_len ) != 0)
634 || (! isspace( (int)pzText[title_len+2] )) ) {
635 pzText = strchr( pzText+2, '>' );
641 name_len = strlen( pOpts->pzProgName );
642 strcpy( ztitle+2, zProg );
648 if (isspace((int)*pzText)) {
649 while (isspace((int)*pzText)) pzText++;
650 if ( (strneqvcmp( pzText, pOpts->pzProgName, (int)name_len) == 0)
651 && (pzText[name_len] == '>')) {
652 pzText += name_len + 1;
657 pzText = strstr( pzText, ztitle );
658 } while (pzText != NULL);
664 /* handleProgramSection
666 * "pzText" points to a '[' character.
667 * The "traditional" [PROG_NAME] segmentation of the config file.
668 * Do not ever mix with the "<?program prog-name>" variation.
671 handleProgramSection(
675 size_t len = strlen( pOpts->pzPROGNAME );
676 if ( (strncmp( pzText+1, pOpts->pzPROGNAME, len ) == 0)
677 && (pzText[len+1] == ']'))
678 return strchr( pzText + len + 2, '\n' );
685 sprintf( z, "[%s]", pOpts->pzPROGNAME );
686 pzText = strstr( pzText, z );
690 pzText = strchr( pzText, '\n' );
697 * "pzText" points to a '<' character, followed by an alpha.
698 * The end of the entry is either the "/>" following the name, or else a
708 tOptionLoadMode mode = option_load_mode;
711 char* pzName = ++pzText;
715 while (ISNAMECHAR( *pzText )) pzText++;
717 valu.valType = OPARG_TYPE_STRING;
722 pzText = parseAttributes( pOpts, pzText, &mode, &valu );
730 if (pzText[1] != '>')
734 loadOptionLine( pOpts, pOS, pzName, direction, mode );
741 pzText = strchr( pzText, '>');
748 * If we are here, we have a value. "pzText" points to a closing angle
749 * bracket. Separate the name from the value for a moment.
755 * Find the end of the option text and NUL terminate it
759 size_t len = strlen(pzName) + 4;
761 pz = AGALOC(len, "scan name");
763 sprintf( pz, "</%s>", pzName );
765 pzText = strstr( pzText, pz );
766 if (pz != z) AGFREE(pz);
777 * Rejoin the name and value for parsing by "loadOptionLine()".
778 * Erase any attributes parsed by "parseAttributes()".
780 memset(pcNulPoint, ' ', pzData - pcNulPoint);
783 * "pzName" points to what looks like text for one option/configurable.
784 * It is NUL terminated. Process it.
786 loadOptionLine( pOpts, pOS, pzName, direction, mode );
794 * Load a configuration file. This may be invoked either from
795 * scanning the "homerc" list, or from a specific file request.
796 * (see "optionFileLoad()", the implementation for --load-opts)
799 internalFileLoad( tOptions* pOpts )
802 int inc = DIRECTION_PRESET;
803 char zFileName[ AG_PATH_MAX+1 ];
805 if (pOpts->papzHomeList == NULL)
809 * Find the last RC entry (highest priority entry)
811 for (idx = 0; pOpts->papzHomeList[ idx+1 ] != NULL; ++idx) ;
814 * For every path in the home list, ... *TWICE* We start at the last
815 * (highest priority) entry, work our way down to the lowest priority,
816 * handling the immediate options.
817 * Then we go back up, doing the normal options.
824 * IF we've reached the bottom end, change direction
827 inc = DIRECTION_PROCESS;
831 pzPath = pOpts->papzHomeList[ idx ];
834 * IF we've reached the top end, bail out
841 if (! optionMakePath( zFileName, (int)sizeof(zFileName),
842 pzPath, pOpts->pzProgPath ))
846 * IF the file name we constructed is a directory,
847 * THEN append the Resource Configuration file name
848 * ELSE we must have the complete file name
850 if (stat( zFileName, &StatBuf ) != 0)
851 continue; /* bogus name - skip the home list entry */
853 if (S_ISDIR( StatBuf.st_mode )) {
854 size_t len = strlen( zFileName );
857 if (len + 1 + strlen( pOpts->pzRcName ) >= sizeof( zFileName ))
860 pz = zFileName + len;
863 strcpy( pz, pOpts->pzRcName );
866 filePreset( pOpts, zFileName, inc );
869 * IF we are now to skip config files AND we are presetting,
870 * THEN change direction. We must go the other way.
873 tOptDesc * pOD = pOpts->pOptDesc + pOpts->specOptIdx.save_opts+1;
874 if (DISABLED_OPT(pOD) && PRESETTING(inc)) {
875 idx -= inc; /* go back and reprocess current file */
876 inc = DIRECTION_PROCESS;
879 } /* twice for every path in the home list, ... */
883 /*=export_func optionFileLoad
885 * what: Load the locatable config files, in order
887 * arg: + tOptions* + pOpts + program options descriptor +
888 * arg: + char const* + pzProg + program name +
891 * ret_desc: 0 -> SUCCESS, -1 -> FAILURE
895 * This function looks in all the specified directories for a configuration
896 * file ("rc" file or "ini" file) and processes any found twice. The first
897 * time through, they are processed in reverse order (last file first). At
898 * that time, only "immediate action" configurables are processed. For
899 * example, if the last named file specifies not processing any more
900 * configuration files, then no more configuration files will be processed.
901 * Such an option in the @strong{first} named directory will have no effect.
903 * Once the immediate action configurables have been handled, then the
904 * directories are handled in normal, forward order. In that way, later
905 * config files can override the settings of earlier config files.
907 * See the AutoOpts documentation for a thorough discussion of the
908 * config file format.
910 * Configuration files not found or not decipherable are simply ignored.
912 * err: Returns the value, "-1" if the program options descriptor
913 * is out of date or indecipherable. Otherwise, the value "0" will
914 * always be returned.
917 optionFileLoad( tOptions* pOpts, char const* pzProgram )
919 if (! SUCCESSFUL( validateOptionsStruct( pOpts, pzProgram )))
922 pOpts->pzProgName = pzProgram;
923 internalFileLoad( pOpts );
928 /*=export_func optionLoadOpt
931 * what: Load an option rc/ini file
932 * arg: + tOptions* + pOpts + program options descriptor +
933 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
936 * Processes the options found in the file named with
937 * pOptDesc->optArg.argString.
940 optionLoadOpt( tOptions* pOpts, tOptDesc* pOptDesc )
943 * IF the option is not being disabled, THEN load the file. There must
944 * be a file. (If it is being disabled, then the disablement processing
945 * already took place. It must be done to suppress preloading of ini/rc
948 if (! DISABLED_OPT( pOptDesc )) {
950 if (stat( pOptDesc->optArg.argString, &sb ) != 0) {
951 if ((pOpts->fOptSet & OPTPROC_ERRSTOP) == 0)
954 fprintf( stderr, zFSErrOptLoad, errno, strerror( errno ),
955 pOptDesc->optArg.argString );
960 if (! S_ISREG( sb.st_mode )) {
961 if ((pOpts->fOptSet & OPTPROC_ERRSTOP) == 0)
964 fprintf( stderr, zNotFile, pOptDesc->optArg.argString );
969 filePreset(pOpts, pOptDesc->optArg.argString, DIRECTION_CALLED);
976 * Parse the various attributes of an XML-styled config file entry
982 tOptionLoadMode* pMode,
983 tOptionValue* pType )
985 size_t lenLoadType = strlen( zLoadType );
986 size_t lenKeyWords = strlen( zKeyWords );
987 size_t lenSetMem = strlen( zSetMembers );
991 case '/': pType->valType = OPARG_TYPE_NONE;
992 case '>': return pzText;
995 case NUL: return NULL;
1006 while (isspace( (int)*++pzText )) ;
1008 if (strncmp( pzText, zLoadType, lenLoadType ) == 0) {
1009 pzText = parseValueType( pzText+lenLoadType, pType );
1013 if (strncmp( pzText, zKeyWords, lenKeyWords ) == 0) {
1014 pzText = parseKeyWordType( pOpts, pzText+lenKeyWords, pType );
1018 if (strncmp( pzText, zSetMembers, lenSetMem ) == 0) {
1019 pzText = parseSetMemType( pOpts, pzText+lenSetMem, pType );
1023 pzText = parseLoadMode( pzText, pMode );
1024 } while (pzText != NULL);
1032 * "pzText" points to the character after "words=".
1033 * What should follow is a name of a keyword (enumeration) list.
1039 tOptionValue* pType )
1041 return skipUnknown( pzText );
1047 * "pzText" points to some name character. We check for "cooked" or
1048 * "uncooked" or "keep". This function should handle any attribute
1049 * that does not have an associated value.
1054 tOptionLoadMode* pMode )
1057 size_t len = strlen(zLoadCooked);
1058 if (strncmp( pzText, zLoadCooked, len ) == 0) {
1059 if ( (pzText[len] == '>')
1060 || (pzText[len] == '/')
1061 || isspace((int)pzText[len])) {
1062 *pMode = OPTION_LOAD_COOKED;
1063 return pzText + len;
1070 size_t len = strlen(zLoadUncooked);
1071 if (strncmp( pzText, zLoadUncooked, len ) == 0) {
1072 if ( (pzText[len] == '>')
1073 || (pzText[len] == '/')
1074 || isspace((int)pzText[len])) {
1075 *pMode = OPTION_LOAD_UNCOOKED;
1076 return pzText + len;
1083 size_t len = strlen(zLoadKeep);
1084 if (strncmp( pzText, zLoadKeep, len ) == 0) {
1085 if ( (pzText[len] == '>')
1086 || (pzText[len] == '/')
1087 || isspace((int)pzText[len])) {
1088 *pMode = OPTION_LOAD_KEEP;
1089 return pzText + len;
1096 return skipUnknown( pzText );
1102 * "pzText" points to the character after "members="
1103 * What should follow is a name of a "set membership".
1104 * A collection of bit flags.
1110 tOptionValue* pType )
1112 return skipUnknown( pzText );
1118 * "pzText" points to the character after "type="
1123 tOptionValue* pType )
1126 size_t len = strlen(zLtypeString);
1127 if (strncmp( pzText, zLtypeString, len ) == 0) {
1128 if ((pzText[len] == '>') || isspace((int)pzText[len])) {
1129 pType->valType = OPARG_TYPE_STRING;
1130 return pzText + len;
1137 size_t len = strlen(zLtypeInteger);
1138 if (strncmp( pzText, zLtypeInteger, len ) == 0) {
1139 if ((pzText[len] == '>') || isspace((int)pzText[len])) {
1140 pType->valType = OPARG_TYPE_NUMERIC;
1141 return pzText + len;
1148 size_t len = strlen(zLtypeBool);
1149 if (strncmp( pzText, zLtypeBool, len ) == 0) {
1150 if ((pzText[len] == '>') || isspace(pzText[len])) {
1151 pType->valType = OPARG_TYPE_BOOLEAN;
1152 return pzText + len;
1159 size_t len = strlen(zLtypeKeyword);
1160 if (strncmp( pzText, zLtypeKeyword, len ) == 0) {
1161 if ((pzText[len] == '>') || isspace((int)pzText[len])) {
1162 pType->valType = OPARG_TYPE_ENUMERATION;
1163 return pzText + len;
1170 size_t len = strlen(zLtypeSetMembership);
1171 if (strncmp( pzText, zLtypeSetMembership, len ) == 0) {
1172 if ((pzText[len] == '>') || isspace((int)pzText[len])) {
1173 pType->valType = OPARG_TYPE_MEMBERSHIP;
1174 return pzText + len;
1181 size_t len = strlen(zLtypeNest);
1182 if (strncmp( pzText, zLtypeNest, len ) == 0) {
1183 if ((pzText[len] == '>') || isspace((int)pzText[len])) {
1184 pType->valType = OPARG_TYPE_HIERARCHY;
1185 return pzText + len;
1192 pType->valType = OPARG_TYPE_NONE;
1193 return skipUnknown( pzText );
1199 * Skip over some unknown attribute
1202 skipUnknown( char* pzText )
1205 if (isspace( (int)*pzText )) return pzText;
1207 case NUL: return NULL;
1209 case '>': return pzText;
1215 /* validateOptionsStruct
1217 * Make sure the option descriptor is there and that we understand it.
1218 * This should be called from any user entry point where one needs to
1219 * worry about validity. (Some entry points are free to assume that
1220 * the call is not the first to the library and, thus, that this has
1221 * already been called.)
1224 validateOptionsStruct( tOptions* pOpts, char const* pzProgram )
1226 if (pOpts == NULL) {
1227 fputs( zAO_Bad, stderr );
1232 * IF the client has enabled translation and the translation procedure
1233 * is available, then go do it.
1235 if ( ((pOpts->fOptSet & OPTPROC_TRANSLATE) != 0)
1236 && (pOpts->pTransProc != 0) ) {
1237 (*pOpts->pTransProc)();
1238 pOpts->fOptSet &= ~OPTPROC_TRANSLATE;
1242 * IF the struct version is not the current, and also
1243 * either too large (?!) or too small,
1244 * THEN emit error message and fail-exit
1246 if ( ( pOpts->structVersion != OPTIONS_STRUCT_VERSION )
1247 && ( (pOpts->structVersion > OPTIONS_STRUCT_VERSION )
1248 || (pOpts->structVersion < OPTIONS_MINIMUM_VERSION )
1251 fprintf( stderr, zAO_Err, pOpts->origArgVect[0],
1252 NUM_TO_VER( pOpts->structVersion ));
1253 if (pOpts->structVersion > OPTIONS_STRUCT_VERSION )
1254 fputs( zAO_Big, stderr );
1256 fputs( zAO_Sml, stderr );
1262 * If the program name hasn't been set, then set the name and the path
1263 * and the set of equivalent characters.
1265 if (pOpts->pzProgName == NULL) {
1266 char const* pz = strrchr( pzProgram, DIRCH );
1269 pOpts->pzProgName = pzProgram;
1270 else pOpts->pzProgName = pz+1;
1272 pOpts->pzProgPath = pzProgram;
1275 * when comparing long names, these are equivalent
1277 strequate( zSepChars );
1287 * c-file-style: "stroustrup"
1288 * indent-tabs-mode: nil
1290 * end of autoopts/configfile.c */