Bug Summary

File:src/cmdline.c
Warning:line 469, column 5
Value stored to 'opt' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name cmdline.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/kfp/aldor/aldor/aldor/src -fcoverage-compilation-dir=/home/kfp/aldor/aldor/aldor/src -resource-dir /usr/local/lib/clang/18 -D PACKAGE_NAME="aldor" -D PACKAGE_TARNAME="aldor" -D PACKAGE_VERSION="1.4.0" -D PACKAGE_STRING="aldor 1.4.0" -D PACKAGE_BUGREPORT="aldor@xinutec.org" -D PACKAGE_URL="" -D PACKAGE="aldor" -D VERSION="1.4.0" -D YYTEXT_POINTER=1 -D HAVE_STDIO_H=1 -D HAVE_STDLIB_H=1 -D HAVE_STRING_H=1 -D HAVE_INTTYPES_H=1 -D HAVE_STDINT_H=1 -D HAVE_STRINGS_H=1 -D HAVE_SYS_STAT_H=1 -D HAVE_SYS_TYPES_H=1 -D HAVE_UNISTD_H=1 -D STDC_HEADERS=1 -D HAVE_LIBREADLINE=1 -D HAVE_READLINE_READLINE_H=1 -D HAVE_READLINE_HISTORY=1 -D HAVE_READLINE_HISTORY_H=1 -D USE_GLOOP_SHELL=1 -D GENERATOR_COROUTINES=0 -D HAVE_DLFCN_H=1 -D LT_OBJDIR=".libs/" -I . -D VCSVERSION="2c53e759f1e00e345f8b172e7139debda72fda13" -internal-isystem /usr/local/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-empty-body -Wno-enum-compare -Wno-missing-field-initializers -Wno-unused -Wno-unused-parameter -Wno-error=format -Wno-error=type-limits -Wno-error=strict-aliasing -Wno-sign-compare -Wno-error=shift-negative-value -Wno-error=clobbered -std=c99 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2026-01-15-223856-845667-1 -x c cmdline.c
1/*****************************************************************************
2 *
3 * cmdline.c: OS Command line processing.
4 *
5 * Copyright (c) 1990-2007 Aldor Software Organization Ltd (Aldor.org).
6 *
7 ****************************************************************************/
8
9#include "bloop.h"
10#include "ccomp.h"
11#include "cmdline.h"
12#include "emit.h"
13#include "file.h"
14#include "fint.h"
15#include "gencpp.h"
16#include "genfoam.h"
17#include "genlisp.h"
18#include "include.h"
19#include "of_emerg.h"
20#include "of_util.h"
21#include "opsys.h"
22#include "optfoam.h"
23#include "phase.h"
24#include "store.h"
25#include "syscmd.h"
26#include "test.h"
27#include "tinfer.h"
28#include "util.h"
29#include "archive.h"
30#include "comsg.h"
31#include "strops.h"
32#include "java/genjava.h"
33
34String cmdName = "aldor"; /* Could use argv[0]. */
35String cmdInitFile = "aldorinit.as";
36
37Bool cmdVerboseFlag = false((int) 0);
38Bool cmdGcFlag = false((int) 0);
39Bool cmdGcFileFlag = false((int) 0);
40Bool cmdSExprFlag = false((int) 0);
41Bool cmdSEvalFlag = false((int) 0);
42Bool cmdTrapFlag = false((int) 0);
43int cmdFileCount = 0;
44
45#define optIs(a,b)((__uppercase[(a)+1]) == (__uppercase[(b)+1])) (toupper(a)(__uppercase[(a)+1]) == toupper(b)(__uppercase[(b)+1]))
46
47/*****************************************************************************
48 *
49 * :: General option processing
50 *
51 ****************************************************************************/
52
53/*
54 * These are the option characters used:
55 *
56 * A B C D E F G H I K L M O P Q R S U V W X Y Z -
57 *
58 * These are still available:
59 *
60 * T
61 */
62
63localstatic void cmdUseError (Msg fmt, String opt);
64
65localstatic Bool cmdIsOption (int);
66localstatic Bool cmdIsArgOption (int);
67localstatic int cmdGetOption (int argc,String*argv,
68 int *i, int *j, String *parg);
69
70localstatic int cmdDoOptHelp (String arg);
71localstatic int cmdDoOptDeveloper (String arg);
72localstatic int cmdDoOptDebug (String arg);
73localstatic int cmdDoOptGo (String arg);
74
75localstatic void cmdHandleJavaOption(String opt);
76static StringList cmdIncDirs;
77static StringList cmdLibDirs;
78static StringList cmdLibKeys;
79
80int
81cmdArguments(int argi0, int argc, String *argv)
82{
83 int opt, i, j;
84 String arg;
85 StringList sl;
86
87 /*
88 * Initialize default values.
89 */
90 cmdFileCount = argc - 1;
91 cmdIncDirs = cmdLibDirs = cmdLibKeys = 0;
92 _dont_assert = true1; /* Disable assertions by default. */
93
94 /*
95 * Handle the options.
96 */
97 for (i = argi0, j = 0; ; ) {
98 opt = cmdGetOption(argc, argv, &i, &j, &arg);
99 if (!opt) break;
100 if (cmdIsArgOption(opt) && !arg)
101 cmdUseError(ALDOR_F_CmdBadOption4, argv[i-1]);
102 cmdHandleOption(opt, arg);
103 }
104
105 /*
106 * After some sequence of -O and -Q do we still want cc -O ?
107 */
108 ccSetOptimize(optIsCcFNonStdWanted(),optIsCcOptimizeWanted());
109
110 /*
111 * Push directories etc in correct order.
112 */
113 for (sl = cmdIncDirs; sl; sl = cdr(sl)((sl)->rest))
114 fileAddIncludeDirectory(car(sl)((sl)->first));
115 for (sl = cmdLibDirs; sl; sl = cdr(sl)((sl)->rest))
116 fileAddLibraryDirectory(car(sl)((sl)->first));
117 for (sl = cmdLibKeys; sl; sl = cdr(sl)((sl)->rest)) {
118 String id, key, s;
119 int rc;
120 s = scmdScanLibraryOption(car(sl)((sl)->first), &id, &key);
121 rc = s ? scmdHandleLibrary(id, key) : -1;
122 if (rc < 0) cmdUseError(ALDOR_F_CmdBadOption4, "-l");
123 }
124 listFree(String)(String_listPointer->Free)(cmdIncDirs);
125 listFree(String)(String_listPointer->Free)(cmdLibDirs);
126 listFree(String)(String_listPointer->Free)(cmdLibKeys);
127
128 /*
129 * Determine number of arguments consumed.
130 */
131 if (i + cmdFileCount > argc) cmdFileCount = argc - i;
132
133 return i;
134}
135
136String cmdOptionArg = "";
137
138Bool
139cmdHasOptionPrefix(int opt0, String arg0, int argc, String *argv)
140{
141 int opt, i, j;
142
143 cmdOptionArg = NULL((void*)0);
144
145 for (i = 1, j = 0; ; ) {
146 opt = cmdGetOption(argc, argv, &i, &j, &cmdOptionArg);
147 if (!opt) break;
148
149 if (!cmdIsOption(opt)) { i++; j = 0; continue; }
150 if (optIs(opt, opt0)((__uppercase[(opt)+1]) == (__uppercase[(opt0)+1]))) {
151 if (!arg0) return true1;
152 if (cmdOptionArg && strAIsPrefix(arg0, cmdOptionArg)) {
153 cmdOptionArg+=strlen(arg0);
154 return true1;
155 }
156 }
157 }
158 return false((int) 0);
159}
160
161Bool
162cmdHasOption(int opt0, String arg0, int argc, String *argv)
163{
164 int opt, i, j;
165
166 cmdOptionArg = NULL((void*)0);
167
168 for (i = 1, j = 0; ; ) {
169 opt = cmdGetOption(argc, argv, &i, &j, &cmdOptionArg);
170 if (!opt) break;
171
172 if (!cmdIsOption(opt)) { i++; j = 0; continue; }
173 if (optIs(opt, opt0)((__uppercase[(opt)+1]) == (__uppercase[(opt0)+1]))) {
174 if (!arg0) return true1;
175 if (cmdOptionArg && strAEqual(arg0, cmdOptionArg))
176 return true1;
177 }
178 }
179 return false((int) 0);
180}
181
182/*
183 * Get command option, ignoring spaces after option name.
184 * Make i and j point to next one.
185 */
186localstatic int
187cmdGetOption(int argc, String *argv, int *i, int *j, String *parg)
188{
189 int opt;
190
191 *parg = NULL((void*)0);
192
193 if (argc <= *i) return 0;
194
195 /* Require leading hyphen. Handle free-standing "-" and "--". */
196
197 if (*j == 0) {
198 if (*argv[*i] != '-') return 0;
199 if (strEqual(argv[*i], "-" )) return 0;
200 if (strEqual(argv[*i], "--")) { *i += 1; return 0; }
201 *j = 1;
202 }
203
204 /* Grab option. */
205 opt = argv[*i][(*j)++];
206
207 /* If this is the last character in this argument, start next. */
208 if (!argv[*i][*j]) {
209 *i += 1;
210 *j = 0;
211 }
212
213 /* If the option takes an argument, grab it too. */
214 if (cmdIsArgOption(opt)) {
215 if (*i == argc) {
216 *parg = NULL((void*)0);
217 }
218 else {
219 *parg = &argv[*i][*j];
220 *i += 1;
221 *j = 0;
222 }
223 }
224 return opt;
225}
226
227/*
228 * Indicate whether the given character is a valid option.
229 */
230localstatic Bool
231cmdIsOption(int opt)
232{
233 switch (toupper(opt)(__uppercase[(opt)+1])) {
234 case '-':
235
236 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
237 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
238 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
239 case 'S': case 'U': case 'V': case 'W': case 'X':
240 case 'Y': case 'Z':
241 return true1;
242
243 default:
244 return false((int) 0);
245 }
246}
247
248/*
249 * Indicate whether the given option takes an argument.
250 */
251localstatic Bool
252cmdIsArgOption(int opt)
253{
254 switch (toupper(opt)(__uppercase[(opt)+1])) {
255 case 'A': case 'B': case 'C': case 'D': case 'E':
256 case 'F': case 'G': case 'H': case 'I': case 'J':
257 case 'K':
258 case 'L': case 'M': case 'N': case 'P': case 'Q':
259 case 'R': case 'S': case 'U': case 'W': case 'Y':
260 case 'Z':
261 return true1;
262 default:
263 return false((int) 0);
264 }
265}
266
267
268void
269cmdHandleOption(int opt, String arg)
270{
271 int rc = 0;
272 Msg bad = ALDOR_F_CmdBadOption4;
273
274 switch (toupper(opt)(__uppercase[(opt)+1])) {
275 case 'A':
276 /* already handled -- should not appear */
277 break;
278 case 'B':
279 /* already handled -- ignore */
280 break;
281 case 'N':
282 /* already handled -- ignore */
283 break;
284 case 'V':
285 cmdVerboseFlag = true1;
286 ccSetVerbose(true1);
287 break;
288 case 'H':
289 rc = cmdDoOptHelp(arg);
290 break;
291 case 'D':
292 inclGlobalAssert(arg);
293 break;
294 case 'U':
295 inclGlobalUnassert(arg);
296 break;
297 case 'R':
298 rc = emitSetOutputDir(arg);
299 bad = ALDOR_F_CmdNoOutputDir7;
300 break;
301 case 'I':
302 cmdIncDirs = listCons(String)(String_listPointer->Cons)(arg, cmdIncDirs);
303 break;
304 case 'J':
305 cmdHandleJavaOption(arg);
306 break;
307 case 'Y':
308 cmdLibDirs = listCons(String)(String_listPointer->Cons)(arg, cmdLibDirs);
309 break;
310 case 'L':
311 cmdLibKeys = listCons(String)(String_listPointer->Cons)(arg, cmdLibKeys);
312 break;
313 case 'O':
314 rc = optSetStdOptimization();
315 break;
316 case 'Q':
317 rc = optSetOptimization(arg);
318 break;
319 case 'F':
320 rc = emitSelect(arg);
321 break;
322 case 'E':
323 emitSetEntryFile(arg);
324 break;
325 case 'G':
326 rc = cmdDoOptGo(arg);
327 break;
328 case 'C':
329 rc = ccOption(arg);
330 break;
331 case 'P':
332 rc = cppOption(arg);
333 break;
334 case 'S':
335 rc = genLispOption(arg);
336 break;
337 case 'M':
338 rc = comsgSetOption(arg);
339 break;
340 case 'W':
341 rc = cmdDoOptDeveloper(arg);
342 break;
343 case 'Z':
344 rc = cmdDoOptDebug(arg);
345 break;
346 case 'K':
347 cmdFileCount = atoi(arg);
348 break;
349 case 'X':
350 arUseExpandedReplacement();
351 break;
352 default:
353 bad = ALDOR_F_CmdNoOption5;
354 rc = -1;
355 break;
356 }
357 if (rc < 0) {
358 char s[3];
359 sprintf(s, "-%c", opt);
360 cmdUseError(bad, s);
361 }
362}
363
364localstatic void
365cmdHandleJavaOption(String opt)
366{
367 if (strEqual(opt, "main")) {
368 gjGenSetMain(true1);
369 }
370 if (strEqual(opt, "no-main")) {
371 gjGenSetMain(false((int) 0));
372 }
373}
374
375/*****************************************************************************
376 *
377 * :: Echo a command line
378 *
379 ****************************************************************************/
380
381static FILE *cmdEchoFile;
382localstatic int cmdEchoChar(int c) { return fputc(c, cmdEchoFile); }
383
384void
385cmdEcho(FILE *fout, int argc, String *argv)
386{
387 int i;
388
389 cmdEchoFile = fout;
390 fprintf(cmdEchoFile, "Exec: ");
391 for (i = 0; i < argc; i++) {
392 if (i > 0) fputc(' ', cmdEchoFile);
393 osRunQuoteArg(argv[i], cmdEchoChar);
394 }
395 fprintf(cmdEchoFile, "\n");
396 fflush(cmdEchoFile);
397}
398
399
400
401/*****************************************************************************
402 *
403 * :: Response files
404 *
405 ****************************************************************************/
406
407/*
408 * 'startArg' points to the '-a' option.
409 * 'nextArg' points to the next option.
410 * Thus nextArg = startArg+1 if the filename abuts '-a'
411 * or nextArg = startArg+2 if there is whitespace between.
412 */
413localstatic void cmdOneResponse(int *pargc, String **pargv, String text,
414 int startArg, int nextArg);
415
416/*
417 * Subsume options in response file into argument vector.
418 * Only the slots 'argi0..*pargc-1 are treated as arguments.
419 */
420Bool
421cmdSubsumeResponseFiles(int argi0, int *pargc, String **pargv)
422{
423 int nresps = 0, i;
424 String *argv;
425 String envopts;
426
427 assert(*pargc >= 1)do { if (!(*pargc >= 1)) _do_assert(("*pargc >= 1"),"cmdline.c"
,427); } while (0)
;
428
429 /* Copy the original args into a new r/w vector.
430 * The extra slot is potentially used in handling AXIOMXLARGS.
431 */
432 argv = (String *) stoAlloc(OB_Other0, (*pargc+1) * sizeof(String *));
433 for (i = 0; i < *pargc; i++)
434 argv[i] = strCopy((*pargv)[i]);
435 *pargv = argv;
436
437 /* Check for ALDORARGS/AXIOMXLARGS environment variable. */
438 envopts = osGetEnv("ALDORARGS");
439 if (!envopts) envopts = osGetEnv("AXIOMXLARGS");
440 if (envopts) {
441 envopts = strCopy(envopts);
442 for (i = *pargc - 1; i >= argi0; i--)
443 (*pargv)[i+1] = (*pargv)[i];
444 (*pargv)[argi0] = strCopy("-aFake");
445 (*pargc)++;
446 cmdOneResponse(pargc, pargv, envopts, argi0, argi0+1);
447 nresps++;
448 strFree(envopts);
449 }
450
451 while (cmdHasOption('a', NULL((void*)0), *pargc, *pargv)) {
452 String fileName = 0, fileText;
453 FileName fn;
454 int opt = 0, nextArg, startArg, j;
455
456 for (nextArg = argi0, j = 0; ; ) {
457 startArg = nextArg;
458 opt = cmdGetOption(*pargc,*pargv,
459 &nextArg,&j,&fileName);
460
461 /* Have response file option by itself. */
462 if (optIs(opt, 'a')((__uppercase[(opt)+1]) == (__uppercase[('a')+1])))
463 break;
464
465 /* Next option is response file option. Must be last */
466 else if (j > 0 && optIs((*pargv)[startArg][j], 'a')((__uppercase[((*pargv)[startArg][j])+1]) == (__uppercase[('a'
)+1]))
) {
467 int oldStartArg = startArg, oldJ = j;
468 startArg = nextArg;
469 opt = cmdGetOption(*pargc,*pargv,
Value stored to 'opt' is never read
470 &nextArg,&j,&fileName);
471 (*pargv)[oldStartArg][oldJ] = '\0';
472 ++startArg;
473 break;
474 }
475 }
476
477 if (! fileName || ! fileName[0])
478 /* Can't use cmdUseError here - no msg db! */
479 comsgFatal(NULL((void*)0),ALDOR_F_CmdBadOption4,"-a",cmdName);
480
481 fn = fnameParse(fileName);
482 if (! fileIsReadable(fn)fileIsOpenable(fn,osIoRdMode))
483 comsgFatal(NULL((void*)0), ALDOR_F_CantOpen358, fileName);
484
485 /* We now have an existing response file */
486 fileText = fileContentsString(fn);
487 cmdOneResponse(pargc, pargv, fileText, startArg, nextArg);
488 fileFreeContentsString(fileText);
489
490 nresps++;
491 }
492
493 return nresps > 0;
494}
495
496localstatic void
497cmdOneResponse(int *pargc, String **pargv, String s, int startArg, int nextArg)
498{
499 static String *firstArgv = 0;
500 String *newArgv = 0;
501 int newArgc = 0;
502
503 if (firstArgv == 0) firstArgv = *pargv;
504
505 cmdParseOptions(s, &newArgc, &newArgv);
506
507 if (newArgv) {
508 int i, j;
509 String *oArgv = newArgv;
510
511 newArgv = (String *) stoAlloc(OB_Other0,
512 (*pargc+newArgc-(nextArg-startArg))*sizeof(String));
513
514 for (i = 0; i < newArgc; i++)
515 newArgv[startArg+i] = oArgv[i];
516 stoFree(oArgv);
517
518 for (i = 0; i < startArg; i++)
519 newArgv[i] = (*pargv)[i];
520
521 j = newArgc - (nextArg - startArg);
522
523 for (i = nextArg; i < *pargc; i++)
524 newArgv[i+j] = (*pargv)[i];
525 *pargc += j;
526
527 if (*pargv != firstArgv)
528 stoFree(*pargv);
529 *pargv = newArgv;
530 }
531 else {
532 /* response file is empty, so skip those args */
533
534 int i, k;
535 k = nextArg - startArg;
536 for (i = nextArg; i < *pargc; i++)
537 (*pargv)[i-k] = (*pargv)[i];
538 *pargc -= k;
539 }
540}
541
542
543/*****************************************************************************
544 *
545 * :: cmdParseOptions
546 * :: cmdFreeOptions
547 *
548 * Parse an option string for: -a <file>, AXIOMXLARGS, #int options ... etc.
549 *
550 ****************************************************************************/
551
552
553struct optionList {
554 char *opt;
555 struct optionList *next;
556};
557
558localstatic struct optionList *
559newOpt(String opt, int characters)
560{
561 struct optionList *ol;
562 String s;
563
564 ol = (struct optionList *) stoAlloc(OB_Other0, sizeof(*ol));
565 s = ol->opt = strAlloc(characters);
566 ol->next = 0;
567 while (*opt && characters > 0) {
568 *(s++) = *(opt++);
569 characters--;
570 }
571 *s = '\0';
572 return ol;
573}
574
575localstatic Bool
576isOptEnd(char ch)
577{
578 String optEnders = "\"\'";
579
580 return isspace(ch)((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int)
_ISspace)
|| strchr(optEnders, ch);
581}
582
583void
584cmdParseOptions(String opts, int *pargc, String **pargv)
585{
586 struct optionList *optList = 0;
587 String *argv;
588 int i, argc;
589
590 assert(pargc && pargv)do { if (!(pargc && pargv)) _do_assert(("pargc && pargv"
),"cmdline.c",590); } while (0)
;
591
592 /* strip leading white space */
593 if (opts) while (*opts && isspace(*opts)((*__ctype_b_loc ())[(int) ((*opts))] & (unsigned short int
) _ISspace)
) ++opts;
594
595 if (! opts || ! *opts) {
596 if (pargc) *pargc = 0;
597 if (pargv) *pargv = 0;
598 return;
599 }
600
601 for (argc = 0; *opts; argc++) {
602 char *opt = opts;
603 struct optionList *ol;
604
605 if (*opts == '-') {
606 ++opts;
607 if (! *opts || isspace(*opts)((*__ctype_b_loc ())[(int) ((*opts))] & (unsigned short int
) _ISspace)
)
608 ol = newOpt(opt, 1);
609 else {
610 ++opts;
611 while (*opts && ! isOptEnd(*opts))
612 ++opts;
613 ol = newOpt(opt, (int) (opts - opt));
614 }
615 }
616 else if (*opts == '\'' || *opts == '"') {
617 char q = *opts;
618 ++opts;
619 while (*opts && *opts != q)
620 ++opts;
621 if (*opts)
622 ++opts;
623 ol = newOpt(opt, (int) (opts - opt));
624 }
625 else {
626 ++opts;
627 while (*opts && ! isOptEnd(*opts))
628 ++opts;
629 ol = newOpt(opt, (int) (opts - opt));
630 }
631
632 ol->next = optList;
633 optList = ol;
634
635 while (*opts && isspace(*opts)((*__ctype_b_loc ())[(int) ((*opts))] & (unsigned short int
) _ISspace)
)
636 ++opts;
637 }
638
639 argv = (String *) stoAlloc(OB_Other0, argc*sizeof(String));
640
641 for (i = argc-1; i >= 0; i--) {
642 struct optionList *tmp = optList->next;
643 argv[i] = optList->opt;
644 stoFree(optList);
645 optList = tmp;
646 }
647
648 if (pargc) *pargc = argc;
649 if (pargv) *pargv = argv;
650}
651
652void
653cmdFreeOptions(int argc, String *argv)
654{
655 int i;
656 for (i = 0; i < argc; i++) stoFree((Pointer) argv[i]);
657 stoFree((Pointer) argv);
658}
659
660
661/*****************************************************************************
662 *
663 * :: HELP options (-h)
664 *
665 ****************************************************************************/
666
667localstatic int
668helpFPrintf(FILE *fout, Msg msg, ...)
669{
670 int cc;
671 va_list argp;
672
673 va_start(argp, msg)__builtin_va_start(argp, msg);
674
675 if (comsgOkBreakLoop())
676 cc = bloopMsgVFPrintf(fout, msg, argp);
677 else
678 cc = comsgVFPrintf (fout, msg, argp);
679
680 va_end(argp)__builtin_va_end(argp);
681 return cc;
682}
683
684
685localstatic int
686cmdDoOptHelp(String arg)
687{
688 int rc = 0;
689 if (!arg || strAEqual(arg, "elp")) {
690 helpFPrintf(osStdout, ALDOR_H_HelpCmd297);
691 }
692 else if (strAEqual(arg, "all")) {
693 helpFPrintf(osStdout, ALDOR_H_HelpCmd297);
694
695 helpFPrintf(osStdout, ALDOR_H_HelpFileTypes298, FTYPE_OBJECTosObjectFileType);
696 helpFPrintf(osStdout, ALDOR_H_HelpOptionSummary299);
697 helpFPrintf(osStdout, ALDOR_H_HelpHelpOpt300);
698 helpFPrintf(osStdout, ALDOR_H_HelpArgOpt301);
699 helpFPrintf(osStdout, ALDOR_H_HelpDirOpt302);
700 helpFPrintf(osStdout, ALDOR_H_HelpFileOpt303);
701 helpFPrintf(osStdout, ALDOR_H_HelpGoOpt304);
702 helpFPrintf(osStdout, ALDOR_H_HelpOptimOpt305);
703 helpFPrintf(osStdout, ALDOR_H_HelpDebugOpt306);
704 helpFPrintf(osStdout, ALDOR_H_HelpConfigOpt307);
705 helpFPrintf(osStdout, ALDOR_H_HelpCOpt308);
706 helpFPrintf(osStdout, ALDOR_H_HelpCppOpt309);
707 helpFPrintf(osStdout, ALDOR_H_HelpLispOpt310);
708 helpFPrintf(osStdout, ALDOR_H_HelpMsgOpt311);
709 helpFPrintf(osStdout, ALDOR_H_HelpDevOpt312);
710 }
711 else if (strAEqual(arg, "files")) {
712 helpFPrintf(osStdout, ALDOR_H_HelpFileTypes298, FTYPE_OBJECTosObjectFileType);
713 helpFPrintf(osStdout, ALDOR_H_HelpMenuPointer313);
714 }
715 else if (strAEqual(arg, "options")) {
716 helpFPrintf(osStdout, ALDOR_H_HelpOptionSummary299);
717 helpFPrintf(osStdout, ALDOR_H_HelpMenuPointer313);
718 }
719 else if (strAEqual(arg, "info")) {
720 helpFPrintf(osStdout, ALDOR_H_HelpProductInfo314);
721 }
722 else if (strAEqual(arg, "h") || strAEqual(arg, "help")) {
723 helpFPrintf(osStdout, ALDOR_H_HelpHelpOpt300);
724 helpFPrintf(osStdout, ALDOR_H_HelpMenuPointer313);
725 }
726 else if (strAEqual(arg, "a") || strAEqual(arg, "args")) {
727 helpFPrintf(osStdout, ALDOR_H_HelpArgOpt301);
728 helpFPrintf(osStdout, ALDOR_H_HelpMenuPointer313);
729 }
730 else if (strAEqual(arg, "dir")) {
731 helpFPrintf(osStdout, ALDOR_H_HelpDirOpt302);
732 helpFPrintf(osStdout, ALDOR_H_HelpMenuPointer313);
733 }
734 else if (strAEqual(arg, "F") || strAEqual(arg, "fout")) {
735 helpFPrintf(osStdout, ALDOR_H_HelpFileOpt303);
736 helpFPrintf(osStdout, ALDOR_H_HelpMenuPointer313);
737 }
738 else if (strAEqual(arg, "g") || strAEqual(arg, "go")) {
739 helpFPrintf(osStdout, ALDOR_H_HelpGoOpt304);
740 helpFPrintf(osStdout, ALDOR_H_HelpMenuPointer313);
741 }
742 else if (strAEqual(arg, "Q") || strAEqual(arg, "O") ||
743 strAEqual(arg, "optimize"))
744 {
745 helpFPrintf(osStdout, ALDOR_H_HelpOptimOpt305);
746 helpFPrintf(osStdout, ALDOR_H_HelpMenuPointer313);
747 }
748 else if (strAEqual(arg, "Z") || strAEqual(arg, "debug")) {
749 helpFPrintf(osStdout, ALDOR_H_HelpDebugOpt306);
750 helpFPrintf(osStdout, ALDOR_H_HelpMenuPointer313);
751 }
752 else if (strAEqual(arg, "N") || strAEqual(arg, "config")) {
753 helpFPrintf(osStdout, ALDOR_H_HelpConfigOpt307);
754 helpFPrintf(osStdout, ALDOR_H_HelpMenuPointer313);
755 }
756 else if (strAEqual(arg, "C")) {
757 helpFPrintf(osStdout, ALDOR_H_HelpCOpt308);
758 helpFPrintf(osStdout, ALDOR_H_HelpMenuPointer313);
759 }
760 else if (strAEqual(arg, "P")) {
761 helpFPrintf(osStdout, ALDOR_H_HelpCppOpt309);
762 helpFPrintf(osStdout, ALDOR_H_HelpMenuPointer313);
763 }
764 else if (strAEqual(arg, "S") || strAEqual(arg, "lisp")) {
765 helpFPrintf(osStdout, ALDOR_H_HelpLispOpt310);
766 helpFPrintf(osStdout, ALDOR_H_HelpMenuPointer313);
767 }
768 else if (strAEqual(arg, "M") || strAEqual(arg, "message")) {
769 helpFPrintf(osStdout, ALDOR_H_HelpMsgOpt311);
770 helpFPrintf(osStdout, ALDOR_H_HelpMenuPointer313);
771 }
772 else if (strAEqual(arg, "W") || strAEqual(arg, "dev")) {
773 helpFPrintf(osStdout, ALDOR_H_HelpDevOpt312);
774 helpFPrintf(osStdout, ALDOR_H_HelpMenuPointer313);
775 }
776 else
777 rc = -1;
778
779 return rc;
780}
781
782localstatic void
783cmdUseError(Msg msg, String s)
784{
785 helpFPrintf(osStdout, msg, s, cmdName);
786 if (fintMode != FINT_LOOP2)
787 exitFailure();
788}
789
790
791/*****************************************************************************
792 *
793 * :: GO options (-g)
794 *
795 ****************************************************************************/
796
797localstatic int
798cmdDoOptGo(String opt)
799{
800 int rc = 0;
801
802 if (strAEqual(opt, "run")) {
803 fintMode = FINT_DONT0;
804 emitSetRun(true1);
805 }
806 else if (strAEqual(opt, "interp")) {
807 fintMode = FINT_RUN1;
808 emitSetInterp(true1);
809 }
810 else if (strAEqual(opt, "loop")) {
811 fintMode = FINT_LOOP2;
812 emitSetInterp(false((int) 0));
813 emitSetRun(false((int) 0));
814 comsgSetInteractiveOption();
815 }
816 else
817 rc = -1;
818
819 return rc;
820}
821
822
823/*****************************************************************************
824 *
825 * :: DEBUG options (-Z)
826 *
827 ****************************************************************************/
828
829localstatic int
830cmdDoOptDebug(String arg)
831{
832 int rc = 0;
833
834 if (!arg[0])
835 rc = -1;
836
837 else if (strAEqual("db", arg))
838 emitSetDebug(true1);
839
840 else if (strAEqual("prof", arg))
841 emitSetProfile(true1);
842 else
843 rc = -1;
844
845 return rc;
846}
847
848
849/*****************************************************************************
850 *
851 * :: DEVELOPER options (-W)
852 *
853 ****************************************************************************/
854
855localstatic String cmdDGetOptArg (String, String, char *psep);
856localstatic int cmdDDebug (String, Bool sense);
857localstatic void cmdDoKeywordStatus (String, Bool);
858
859extern void gencSetTraceFuns(Bool);
860extern void stabSetDumbImport(Bool);
861extern void gfSetLazyCatch(Bool);
862extern void jflowSetNegate(Bool);
863extern Bool NoWhereHack;
864
865localstatic int
866cmdDoOptDeveloper(String arg)
867{
868 int rc = 0;
869
870 if (!arg[0])
871 rc = -1;
872
873 if (strAEqual("trap", arg)) {
874 cmdTrapFlag = true1;
875 }
876 else if (strAEqual("check", arg)) {
877 _dont_assert = false((int) 0); /* Test assertions. */
878 stoCtl(StoCtl_Wash3, true1); /* Initialize of store. */
879 }
880 else if (strAEqual("runtime", arg))
881 genSetRuntime()(gen0IsRuntime = 1);
882 else if (strEqual("debug", arg))
883 genSetDebugWanted(true1);
884 else if (strEqual("debugger", arg))
885 genSetDebuggerWanted(true1);
886 else if (strEqual("depend", arg))
887 emitSetDependsWanted(true1);
888 else if (strEqual("small-hcodes", arg))
889 genSetSmallHashCodes(true1);
890 else if (strEqual("lazy-catch", arg))
891 gfSetLazyCatch(true1);
892 else if (strEqual("dumb-import", arg))
893 stabSetDumbImport(true1);
894 else if (strEqual("trace-cfuns", arg))
895 gencSetTraceFuns(true1);
896 else if (strEqual("no-where", arg))
897 NoWhereHack = true1;
898 else if (strAEqual("runtime-hashcheck", arg))
899 genSetHashcheck()(gen0Hashcheck = 1);
900 else if (strAIsPrefix("keyword", arg)) {
901 String darg = cmdDGetOptArg(arg, "keyword", NULL((void*)0));
902 cmdDoKeywordStatus(darg, true1);
903 }
904 else if (strAIsPrefix("no-keyword", arg)) {
905 String darg = cmdDGetOptArg(arg, "no-keyword", NULL((void*)0));
906 cmdDoKeywordStatus(darg, false((int) 0));
907 }
908 else if (strEqual("no-negated-tests", arg))
909 jflowSetNegate(false((int) 0));
910 else if (strAEqual("audit", arg))
911 foamAuditSetAll();
912 else if (strAEqual("nhash", arg))
913 genSetAxiomAx(true1);
914 else if (strAEqual("missing-ok", arg))
915 tiSetSoftMissing(true1);
916 else if (strAEqual("sexpr", arg)) {
917 cmdSExprFlag = true1;
918 }
919 else if (strAEqual("seval", arg)) {
920 cmdSEvalFlag = true1;
921 }
922 else if (strAEqual("no-gc", arg)) {
923 /* Handled already - no action need be taken here */
924 }
925 else if (strAEqual("gc", arg)) {
926 /* Handled already - no action need be taken here */
927 cmdGcFlag = true1;
928 }
929 else if (strAEqual("gcfile", arg)) {
930 /* Handled already - no action need be taken here */
931 cmdGcFileFlag = true1;
932 }
933 else if (strAEqual("loops", arg)) {
934 optSetLoopOption();
935 }
936 else if (strAEqual("emerge-noalias", arg)) {
937 emSetNoAlias();
938 }
939 else if (strAIsPrefix("test", arg)) {
940 String darg = cmdDGetOptArg(arg, "test", NULL((void*)0));
941 testSelf(darg);
942 exitSuccess();
943 }
944 else if (strAIsPrefix("rtcache", arg)) {
945 String darg = cmdDGetOptArg(arg, "rtcache", NULL((void*)0));
946 long rtsize;
947 extern void gen0SetRtCacheSize(AInt);
948
949 sscanf(darg, "%ld", &rtsize);
950 gen0SetRtCacheSize((AInt)rtsize);
951 }
952 else if (strAIsPrefix("D", arg)) {
953 char sep;
954 String darg = cmdDGetOptArg(arg, "D", &sep);
955 rc = cmdDDebug(darg, sep == '+');
956 }
957 else if (strAIsPrefix("T", arg)) {
958 rc = phTraceOption(arg+strlen("T"));
959 }
960 else if (strAIsPrefix("name", arg)) {
961 String darg = cmdDGetOptArg(arg, "name", NULL((void*)0));
962 emitSetFileIdName(darg);
963 }
964 else if (strAIsPrefix("prefix", arg)) {
965 String darg = cmdDGetOptArg(arg, "prefix", NULL((void*)0));
966 emitSetFileIdPrefix(darg);
967 }
968 else if (strAEqual("floatrep", arg)) {
969 cmdFloatRepFlag = true1;
970 }
971 else
972 rc = -1;
973
974 return rc;
975}
976
977
978localstatic String
979cmdDGetOptArg(String arg, String prefix, char *psep)
980{
981 if (!strAIsPrefix(prefix, arg))
982 cmdUseError(ALDOR_F_CmdBadOption4, "-W");
983 arg += strlen(prefix);
984 if (*arg != '+' && *arg != '-' && *arg != '=' && *arg != ':')
985 cmdUseError(ALDOR_F_CmdBadOption4, "-W");
986
987 if (psep) *psep = *arg;
988 arg++;
989
990 if (!*arg)
991 cmdUseError(ALDOR_F_CmdBadOption4, "-W");
992 return arg;
993}
994
995
996localstatic void
997cmdDoKeywordStatus(String keyword, Bool enable)
998{
999 /* Turn keywords into normal identifiers */
1000 TokenTag tag = keyTag(keyword);
1001
1002
1003 /* Is this actually a keyword? */
1004 if (tag != TK_LIMIT)
1005 keySetDisabled(tag, !enable);
1006 else
1007 cmdUseError(ALDOR_W_DisableNotKeyword9, keyword);
1008}
1009
1010
1011/*****************************************************************************
1012 *
1013 * :: Setting of debug variables.
1014 *
1015 ****************************************************************************/
1016
1017extern Bool
1018 abDebug, abExpandDebug, ablogDebug,
1019 abnDefineDebug, abnWhereDebug, abnWithMergeDebug, abnormDebug,
1020 absDebug, arDebug,
1021 cfoldDebug, condApplyDebug, cpDebug, cpDfDebug,
1022 crinDebug,
1023 cseDebug, cseDfDebug, cseDfiDebug, daDebug,
1024 dnfDebug, dvDebug, emergeDebug, fileDebug,
1025 fintDebug, fintLinkDebug, fintStoDebug,
1026 flogDebug, foamConstDebug, foamDebug, foamSposDebug,
1027 fortranTypesDebug, fvDebug,
1028 gcrDebug, gcrFmtDebug,
1029 genfImplicitDebug,
1030 genfDebug, genfHashDebug, genfExportDebug,
1031 genfEnvDebug,
1032 gfaddDebug,
1033 implDebug, inlCallDebug,
1034 inlCallInfoDebug, inlExportDebug, inlExprDebug, inlExtendDebug,
1035 inlProgDebug, inlTransDebug, inlUnitDebug, inlineDebug,
1036 jflowCatDebug, jflowDfDebug, jflowDfiDebug, jflowGoDebug, jflowDmDebug,
1037 kpDebug,
1038 libConstDebug, libDebug, libLazyDebug, libRepDebug, libVerboseDebug,
1039 linDebug,
1040 macDebug, oeDebug,
1041 optfDebug, optfShowDebug, peepDebug,
1042 retDebug, rrfmtDebug,
1043 scoDebug, scoFluidDebug, scoStabDebug, scoUndoDebug,
1044 sefoCloseDebug, sefoEqualDebug, sefoFreeDebug,
1045 sefoPrintDebug, sefoSubstDebug, sefoUnionDebug, sefoInterDebug,
1046 sexprDebug, sstDebug, sstMarkDebug,
1047 stabConstDebug, stabDebug, stabImportDebug,
1048 symeDebug, symeFillDebug, symeHasDebug,
1049 symeRefreshDebug,
1050 tcDebug,
1051 tfDebug, tfCascadeDebug, tfCatDebug, tfCrossDebug,
1052 tfExprDebug, tfFloatDebug, tfHasDebug, tfHashDebug,
1053 tfImportDebug, tfMapDebug,
1054 tfMultiDebug, tfParentDebug, tfWithDebug,
1055 tfsDebug, tfsExportDebug, tfsMultiDebug, tfsParentDebug,
1056 tipAddDebug, tipApplyDebug, tipAssignDebug, tipBupDebug,
1057 tipDeclDebug,
1058 tipDeclareDebug, tipDefineDebug, tipExtendDebug,
1059 tipFarDebug, tipIdDebug,
1060 tipLitDebug, tipEmbedDebug, tipSefDebug, tipTdnDebug,
1061 titfDebug, titfOneDebug, titfStabDebug,
1062 udDfDebug, udDfiDebug, ylDebug;
1063
1064struct dbVarInfo {
1065 Bool *pvar;
1066 String name;
1067};
1068
1069struct dbVarInfo dbVarInfo[] = {
1070 { & abDebug, "ab" },
1071 { & abExpandDebug, "abExpand" },
1072 { & ablogDebug, "ablog" },
1073 { & abnDefineDebug, "abnDefine" },
1074 { & abnWhereDebug, "abnWhere" },
1075 { & abnWithMergeDebug, "abnWithMerge" },
1076 { & abnormDebug, "abnorm" },
1077 { & absDebug, "abs" },
1078 { & arDebug, "ar" },
1079 { & cfoldDebug, "cfold" },
1080 { & condApplyDebug, "condApply" },
1081 { & cpDebug, "cp" },
1082 { & cpDfDebug, "cpDf" },
1083 { & crinDebug, "crin" },
1084 { & cseDebug, "cse" },
1085 { & cseDfDebug, "cseDf" },
1086 { & cseDfiDebug, "cseDfi" },
1087 { & daDebug, "da" },
1088 { & dnfDebug, "dnf" },
1089 { & dvDebug, "dv" },
1090 { & emergeDebug, "emerge" },
1091 { & fileDebug, "file" },
1092 { & fintDebug, "fint" },
1093 { & fintLinkDebug, "fintLink" },
1094 { & fintStoDebug, "fintSto" },
1095 { & flogDebug, "flog" },
1096 { & foamConstDebug, "foamConst" },
1097 { & foamDebug, "foam" },
1098 { & foamSposDebug, "foamSpos" },
1099 { & fortranTypesDebug, "fortranTypes" },
1100 { & fvDebug, "fv" },
1101 { & gcrDebug, "gcr" },
1102 { & gcrFmtDebug, "gcrFmt" },
1103 { & genfEnvDebug, "genfEnv" },
1104 { & genfExportDebug, "genfExport" },
1105 { & genfImplicitDebug, "genfImplicit" },
1106 { & genfDebug, "genf"},
1107 { & genfHashDebug, "genfHash"},
1108 { & gfaddDebug, "gfadd"},
1109 { & implDebug, "impl" },
1110 { & inlCallDebug, "inlCall" },
1111 { & inlCallInfoDebug, "inlCallInfo" },
1112 { & inlExportDebug, "inlExport" },
1113 { & inlExprDebug, "inlExpr" },
1114 { & inlExtendDebug, "inlExtend" },
1115 { & inlProgDebug, "inlProg" },
1116 { & inlTransDebug, "inlTrans" },
1117 { & inlUnitDebug, "inlUnit" },
1118 { & inlineDebug, "inline" },
1119 { & jflowCatDebug, "jflowCat" },
1120 { & jflowDfDebug, "jflowDf" },
1121 { & jflowDfiDebug, "jflowDfi" },
1122 { & jflowGoDebug, "jflowGo" },
1123 { & jflowDmDebug, "jflowDm" },
1124 { & kpDebug, "killp" },
1125 { & libConstDebug, "libConst" },
1126 { & libDebug, "lib" },
1127 { & libLazyDebug, "libLazy" },
1128 { & libRepDebug, "libRep" },
1129 { & libVerboseDebug, "libVerbose" },
1130 { & linDebug, "lin" },
1131 { & macDebug, "macex" },
1132 { & oeDebug, "oe" },
1133 { & optfDebug, "optf" },
1134 { & optfShowDebug, "optfShow" },
1135 { & peepDebug, "peep" },
1136 { & retDebug, "ret" },
1137 { & rrfmtDebug, "rrfmt" },
1138 { & scoDebug, "sco" },
1139 { & scoFluidDebug, "scoFluid" },
1140 { & scoStabDebug, "scoStab" },
1141 { & scoUndoDebug, "scoUndo" },
1142 { & sefoCloseDebug, "sefoClose" },
1143 { & sefoEqualDebug, "sefoEqual" },
1144 { & sefoFreeDebug, "sefoFree" },
1145 { & sefoInterDebug, "sefoInter" },
1146 { & sefoPrintDebug, "sefoPrint" },
1147 { & sefoSubstDebug, "sefoSubst" },
1148 { & sefoUnionDebug, "sefoUnion" },
1149 { & sexprDebug, "sexpr" },
1150 { & sstDebug, "sst" },
1151 { & sstMarkDebug, "sstMark" },
1152 { & stabConstDebug, "stabConst" },
1153 { & stabDebug, "stab" },
1154 { & stabImportDebug, "stabImport" },
1155 { & symeDebug, "syme" },
1156 { & symeFillDebug, "symeFill" },
1157 { & symeHasDebug, "symeHas" },
1158 { & symeRefreshDebug, "symeRefresh" },
1159 { & tcDebug, "tc" },
1160 { & tfDebug, "tf" },
1161 { & tfCascadeDebug, "tfCascade" },
1162 { & tfCatDebug, "tfCat" },
1163 { & tfCrossDebug, "tfCross" },
1164 { & tfExprDebug, "tfExpr" },
1165 { & tfFloatDebug, "tfFloat" },
1166 { & tfHasDebug, "tfHas" },
1167 { & tfHashDebug, "tfHash" },
1168 { & tfImportDebug, "tfImport" },
1169 { & tfMapDebug, "tfMap" },
1170 { & tfMultiDebug, "tfMulti" },
1171 { & tfParentDebug, "tfParent" },
1172 { & tfWithDebug, "tfWith" },
1173 { & tfsDebug, "tfs" },
1174 { & tfsExportDebug, "tfsExport" },
1175 { & tfsMultiDebug, "tfsMulti" },
1176 { & tfsParentDebug, "tfsParent" },
1177 { & tipAddDebug, "tipAdd" },
1178 { & tipApplyDebug, "tipApply" },
1179 { & tipAssignDebug, "tipAssign" },
1180 { & tipBupDebug, "tipBup" },
1181 { & tipDeclDebug, "tipDecl" },
1182 { & tipDeclareDebug, "tipDeclare" },
1183 { & tipDefineDebug, "tipDefine" },
1184 { & tipExtendDebug, "tipExtend" },
1185 { & tipFarDebug, "tipFar" },
1186 { & tipIdDebug, "tipId" },
1187 { & tipLitDebug, "tipLit" },
1188 { & tipEmbedDebug, "tipEmbed" },
1189 { & tipSefDebug, "tipSef" },
1190 { & tipTdnDebug, "tipTdn" },
1191 { & titfDebug, "titf" },
1192 { & titfOneDebug, "titfOne" },
1193 { & titfStabDebug, "titfStab" },
1194 { & udDfDebug, "udDf" },
1195 { & udDfiDebug, "udDfi" },
1196 { & ylDebug, "yl" },
1197 { 0, 0}
1198};
1199
1200
1201localstatic int
1202cmdDDebug(String dbName, Bool sense)
1203{
1204 int i;
1205
1206 if (strAEqual(dbName, "show")) {
1207 printf("\nThe debug hooks are:");
1208 for (i = 0; dbVarInfo[i].name; i++)
1209 printf(" \"%s\"", dbVarInfo[i].name);
1210 printf("\n");
1211 return 0;
1212 }
1213
1214 if (strAEqual(dbName, "all")) {
1215 for (i = 0; dbVarInfo[i].name; i++)
1216 *dbVarInfo[i].pvar = sense;
1217 return 0;
1218 }
1219
1220 for (i = 0; dbVarInfo[i].name; i++) {
1221 if (strAEqual(dbName, dbVarInfo[i].name)) {
1222 *(dbVarInfo[i].pvar) = sense;
1223 return 0;
1224 }
1225 }
1226
1227 return -1;
1228}
1229
1230void
1231cmdDebugReset()
1232{
1233 int i;
1234 for (i = 0; dbVarInfo[i].name; i++) {
1235 *dbVarInfo[i].pvar = 0;
1236 }
1237}