1 /* $XConsortium: option.c /main/3 1995/11/08 10:46:37 rswiston $ */
2 /* Copyright (c) 1986, 1987, 1988, 1989, 1992 Hewlett-Packard Co. */
3 /* Functions for command-line options for Help Tag/Cache Creek translator */
7 #if defined(hpux) || defined(_AIX) || defined(sun) || defined(USL) || defined(__uxp__)
8 /* get definition of getenv(3c) for getting of environment variables */
13 /* Interpret options from command line and specified files */
14 #define OPTLEN 512 /* If OPTLEN changes, change fscanf call below */
15 #define TAGDOTOPT "helptag.opt"
19 void options(LOGICAL filelenonly)
21 void options(filelenonly)
27 char option[OPTLEN + 1];
30 /* Check helptag.opt in installation directory */
31 nameofoptfile = (char *) m_malloc(strlen(install) + strlen(TAGDOTOPT) + 1,
32 "installation helptag.opt");
33 strcpy(nameofoptfile, install);
34 strcat(nameofoptfile, TAGDOTOPT);
35 if (optfile = fopen(nameofoptfile, "r"))
37 while (fscanf(optfile, "%512s", option) != EOF)
38 setopt(option, filelenonly);
41 m_free(nameofoptfile, "installation helptag.opt");
43 #if defined(hpux) || defined(_AIX) || defined(sun) || defined(USL) || defined(__uxp__)|| defined(__osf__)
47 /* Check options in $TAGOPT */
48 opts = getenv("TAGOPT");
51 while (m_whitespace(*opts)) opts++;
52 while (sscanf(opts, "%512s", option) != EOF)
54 setopt(option, filelenonly);
55 opts += strlen(option);
56 while (m_whitespace(*opts)) opts++;
60 #endif /* hpux or _AIX or sun or __osf__ */
62 /* Check helptag.opt in input directory */
65 nameofoptfile = (char *) m_malloc(strlen(indir) + strlen(TAGDOTOPT) + 1,
67 strcpy(nameofoptfile, indir);
68 strcat(nameofoptfile, TAGDOTOPT);
70 else nameofoptfile = TAGDOTOPT;
72 if (optfile = fopen(nameofoptfile, "r"))
74 while (fscanf(optfile, "%512s", option) != EOF)
75 setopt(option, filelenonly);
79 if (indir) m_free(nameofoptfile, "input helptag.opt");
81 /* Check basename.opt in input directory */
82 nameofoptfile = (char *) m_malloc((indir ? strlen(indir) : 0) +
83 strlen(nodirbase) + strlen(DOTOPT) + 1,
85 *nameofoptfile = M_EOS;
87 if (indir) strcpy(nameofoptfile, indir);
89 strcat(nameofoptfile, nodirbase);
90 strcat(nameofoptfile, DOTOPT);
92 if (optfile = fopen(nameofoptfile, "r"))
94 while (fscanf(optfile, "%512s", option) != EOF)
95 setopt(option, filelenonly);
98 m_free(nameofoptfile, "basename.opt");
100 /* Read command line options */
101 for (i = 3 ; i < m_argc ; i++)
102 if (*m_argv[i] == '@')
104 if (optfile = fopen(m_argv[i] + 1, "r"))
106 while (fscanf(optfile, "%512s", option) != EOF)
107 setopt(option, filelenonly);
112 m_mberr1("Unable to open option file %s", (m_argv[i] + 1));
115 else setopt(m_argv[i], filelenonly);
117 if (filelenonly) return ;
121 m_mberr1("%s: Expecting value for option on command line or in option file",
128 /* Set a single option */
129 /* Workonly parameter described with function options()*/
131 void setopt(char *string, LOGICAL filelenonly)
133 void setopt(string, filelenonly)
144 /* Ignore '=' by itself */
145 if (*string == '=' && *(string + 1) == M_EOS) return;
146 setvalopt(optval, string, filelenonly);
151 if (p = strchr(string, '='))
154 for (thisopt = 0 ; thisopt < NUMOPTIONS ; thisopt++)
155 if (! m_mbmbupstrcmp(string, optkey[thisopt]))
158 /* Note: call setvalopt only if thisopt < NUMOPTIONS */
160 ((thisopt < NUMOPTIONS) && setvalopt(thisopt + 1, p + 1, filelenonly));
162 if (! ok && ! filelenonly)
163 m_mberr1("%s: Unrecognized option on command line or in option file",
166 } /* End strchr(string, '=') */
168 for (thisopt = 0 ; thisopt < NUMOPTIONS ; thisopt++)
169 if (! m_mbmbupstrcmp(string, optkey[thisopt]))
172 if (thisopt >= NUMOPTIONS)
175 m_mberr1("%s: Unrecognized option on command line or in option file",
179 else switch(thisopt + 1)
182 optval = thisopt + 1;
187 /* Process a value for a command line option */
189 LOGICAL setvalopt(int thisopt, char *string, LOGICAL filelenonly)
191 LOGICAL setvalopt(thisopt, string, filelenonly)
201 /* Ignore leading = (occurs if "option =val" is entered in .opt file) */
202 if (*string == '=') string++;
204 /* Check for empty string (occurs if "option= val" is entered in .opt file) */
218 if (! m_mbmbupstrcmp(string, "GO"))
220 else if (! m_mbmbupstrcmp(string, "STOP"))
222 else m_mberr1("Invalid ONERROR option: %s", string);