2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: option.c /main/3 1995/11/08 10:46:37 rswiston $ */
24 /* Copyright (c) 1986, 1987, 1988, 1989, 1992 Hewlett-Packard Co. */
25 /* Functions for command-line options for Help Tag/Cache Creek translator */
29 #if defined(hpux) || defined(_AIX) || defined(sun)
30 /* get definition of getenv(3c) for getting of environment variables */
35 /* Interpret options from command line and specified files */
36 #define OPTLEN 512 /* If OPTLEN changes, change fscanf call below */
37 #define TAGDOTOPT "helptag.opt"
41 void options(LOGICAL filelenonly)
43 void options(filelenonly)
49 char option[OPTLEN + 1];
52 /* Check helptag.opt in installation directory */
53 nameofoptfile = (char *) m_malloc(strlen(install) + strlen(TAGDOTOPT) + 1,
54 "installation helptag.opt");
55 strcpy(nameofoptfile, install);
56 strcat(nameofoptfile, TAGDOTOPT);
57 if (optfile = fopen(nameofoptfile, "r"))
59 while (fscanf(optfile, "%512s", option) != EOF)
60 setopt(option, filelenonly);
63 m_free(nameofoptfile, "installation helptag.opt");
65 #if defined(hpux) || defined(_AIX) || defined(sun) || defined(__osf__)
69 /* Check options in $TAGOPT */
70 opts = getenv("TAGOPT");
73 while (m_whitespace(*opts)) opts++;
74 while (sscanf(opts, "%512s", option) != EOF)
76 setopt(option, filelenonly);
77 opts += strlen(option);
78 while (m_whitespace(*opts)) opts++;
82 #endif /* hpux or _AIX or sun or __osf__ */
84 /* Check helptag.opt in input directory */
87 nameofoptfile = (char *) m_malloc(strlen(indir) + strlen(TAGDOTOPT) + 1,
89 strcpy(nameofoptfile, indir);
90 strcat(nameofoptfile, TAGDOTOPT);
92 else nameofoptfile = TAGDOTOPT;
94 if (optfile = fopen(nameofoptfile, "r"))
96 while (fscanf(optfile, "%512s", option) != EOF)
97 setopt(option, filelenonly);
101 if (indir) m_free(nameofoptfile, "input helptag.opt");
103 /* Check basename.opt in input directory */
104 nameofoptfile = (char *) m_malloc((indir ? strlen(indir) : 0) +
105 strlen(nodirbase) + strlen(DOTOPT) + 1,
107 *nameofoptfile = M_EOS;
109 if (indir) strcpy(nameofoptfile, indir);
111 strcat(nameofoptfile, nodirbase);
112 strcat(nameofoptfile, DOTOPT);
114 if (optfile = fopen(nameofoptfile, "r"))
116 while (fscanf(optfile, "%512s", option) != EOF)
117 setopt(option, filelenonly);
120 m_free(nameofoptfile, "basename.opt");
122 /* Read command line options */
123 for (i = 3 ; i < m_argc ; i++)
124 if (*m_argv[i] == '@')
126 if (optfile = fopen(m_argv[i] + 1, "r"))
128 while (fscanf(optfile, "%512s", option) != EOF)
129 setopt(option, filelenonly);
134 m_mberr1("Unable to open option file %s", (m_argv[i] + 1));
137 else setopt(m_argv[i], filelenonly);
139 if (filelenonly) return ;
143 m_mberr1("%s: Expecting value for option on command line or in option file",
150 /* Set a single option */
151 /* Workonly parameter described with function options()*/
153 void setopt(char *string, LOGICAL filelenonly)
155 void setopt(string, filelenonly)
166 /* Ignore '=' by itself */
167 if (*string == '=' && *(string + 1) == M_EOS) return;
168 setvalopt(optval, string, filelenonly);
173 if (p = strchr(string, '='))
176 for (thisopt = 0 ; thisopt < NUMOPTIONS ; thisopt++)
177 if (! m_mbmbupstrcmp(string, optkey[thisopt]))
180 /* Note: call setvalopt only if thisopt < NUMOPTIONS */
182 ((thisopt < NUMOPTIONS) && setvalopt(thisopt + 1, p + 1, filelenonly));
184 if (! ok && ! filelenonly)
185 m_mberr1("%s: Unrecognized option on command line or in option file",
188 } /* End strchr(string, '=') */
190 for (thisopt = 0 ; thisopt < NUMOPTIONS ; thisopt++)
191 if (! m_mbmbupstrcmp(string, optkey[thisopt]))
194 if (thisopt >= NUMOPTIONS)
197 m_mberr1("%s: Unrecognized option on command line or in option file",
201 else switch(thisopt + 1)
204 optval = thisopt + 1;
209 /* Process a value for a command line option */
211 LOGICAL setvalopt(int thisopt, char *string, LOGICAL filelenonly)
213 LOGICAL setvalopt(thisopt, string, filelenonly)
223 /* Ignore leading = (occurs if "option =val" is entered in .opt file) */
224 if (*string == '=') string++;
226 /* Check for empty string (occurs if "option= val" is entered in .opt file) */
240 if (! m_mbmbupstrcmp(string, "GO"))
242 else if (! m_mbmbupstrcmp(string, "STOP"))
244 else m_mberr1("Invalid ONERROR option: %s", string);