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 11:18:32 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) || defined(USL)
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(USL)
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 */
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)
206 optval = thisopt + 1;
214 #if defined(FUTURE_FEATURE)
231 m_free(tocfile, "TOC option");
239 m_free(tocfile, "NOTOC option");
247 #endif /* FUTURE_FEATURE */
256 SEARCH *searchp, *searchq;
258 for (searchp = path ; searchp ;)
261 searchp = searchp->next;
262 m_free(searchq->directory, "search directory");
263 m_free(searchq, "search path");
272 usingshortnames = FALSE;
277 usingshortnames = TRUE;
282 /* Process a value for a command line option */
284 LOGICAL setvalopt(int thisopt, char *string, LOGICAL filelenonly)
286 LOGICAL setvalopt(thisopt, string, filelenonly)
296 /* Ignore leading = (occurs if "option =val" is entered in .opt file) */
297 if (*string == '=') string++;
299 /* Check for empty string (occurs if "option= val" is entered in .opt file) */
315 if ( (parentsrch==TRUE) && (*string!=M_EOS) && (*string!=dirsep)
317 && ( *(string+1) != ':' )
321 /* prepend "..", for index processing in temporary sub-directory */
322 tempstr = (char *) m_malloc( strlen(string) + 4, "tempstr search");
323 strcpy(tempstr, "..");
324 strcat(tempstr, SSEP);
325 strcat(tempstr, string);
329 tempstr = (char *) m_malloc( strlen(string) + 1, "tempstr search");
330 strcpy(tempstr, string);
333 *endpath = (SEARCH *) m_malloc(sizeof(SEARCH), "search path");
334 p = strchr(tempstr, M_EOS);
335 if (p != tempstr && *(p - 1) != dirsep
342 (*endpath)->directory = (char *) m_malloc(i + 2,
344 strcpy((*endpath)->directory, tempstr);
345 (*endpath)->directory[i] = dirsep;
346 (*endpath)->directory[i + 1] = M_EOS;
350 (*endpath)->directory = (char *) m_malloc(strlen(tempstr) + 1,
352 strcpy((*endpath)->directory, tempstr);
354 (*endpath)->next = NULL;
355 endpath = &(*endpath)->next;
356 m_free(tempstr, "tempstr search");
359 m_free(helpcharset, "help charset");
360 helpcharset = MakeWideCharString(string);
363 if (! m_mbmbupstrcmp(string, "GO"))
365 else if (! m_mbmbupstrcmp(string, "STOP"))
367 else m_mberr1("Invalid ONERROR option: %s", string);