static void error3() { if (Cp) { struct call *mptr; /* fix limit */ *op = EOS; (Cp+1)->argp = Ap+1; for (mptr = callst; mptr <= Cp; ++mptr) { wchar_t **aptr, **lim; aptr = mptr->argp; lim = (mptr+1)->argp-1; if (mptr == callst) (void) fputws(*aptr, stderr); ++aptr; (void) fputs("(", stderr); if (aptr < lim) for (;;) { (void) fputws(*aptr++, stderr); if (aptr >= lim) break; (void) fputs(",", stderr); } } while (--mptr >= callst) (void) fputs(")", stderr); (void) fputs("\n", stderr); } delexit(NOT_OK, 1); }
/* ARGSUSED */ static void catchsig(int i) { (void) signal(SIGHUP, SIG_IGN); (void) signal(SIGINT, SIG_IGN); delexit(NOT_OK, 0); }
tdelexit() { delarg = 4; delexit(); }
int main(int argc, char **argv) { wchar_t t; int i, opt_end = 0; int sigs[] = {SIGHUP, SIGINT, SIGPIPE, 0}; #if defined(__lint) yydebug = 0; #endif for (i = 0; sigs[i]; ++i) { if (signal(sigs[i], SIG_IGN) != SIG_IGN) (void) signal(sigs[i], catchsig); } tempfile = mktemp(tmp_name); (void) close(creat(tempfile, 0)); (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); if ((mb_cur_max = MB_CUR_MAX) > 1) wide = 1; procnam = argv[0]; getflags(&argc, &argv, &opt_end); initalloc(); setfname("-"); if (argc > 1) { --argc; ++argv; if (strcmp(argv[0], "-")) { ifile[ifx] = m4open(&argv, "r", &argc); setfname(argv[0]); } } for (;;) { token[0] = t = getchr(); token[1] = EOS; if (t == WEOF) { if (ifx > 0) { (void) fclose(ifile[ifx]); ipflr = ipstk[--ifx]; continue; } getflags(&argc, &argv, &opt_end); if (argc <= 1) /* * If dowrap() has been called, the m4wrap * macro has been processed, and a linked * list of m4wrap strings has been created. * The list starts at wrapstart. */ if (wrapstart) { /* * Now that EOF has been processed, * display the m4wrap strings. */ showwrap(); continue; } else break; --argc; ++argv; if (ifile[ifx] != stdin) (void) fclose(ifile[ifx]); if (strcmp(argv[0], "-")) ifile[ifx] = m4open(&argv, "r", &argc); else ifile[ifx] = stdin; setfname(argv[0]); continue; } if (is_alpha(t) || t == '_') { wchar_t *tp = token+1; int tlim = toksize; struct nlist *macadd; /* temp variable */ while ((*tp = getchr()) != WEOF && (is_alnum(*tp) || *tp == '_')) { tp++; if (--tlim <= 0) error2(gettext( "more than %d chars in word"), toksize); } putbak(*tp); *tp = EOS; macadd = lookup(token); *Ap = (wchar_t *)macadd; if (macadd->def) { if ((wchar_t *)(++Ap) >= astklm) { --Ap; error2(gettext( "more than %d items on " "argument stack"), stksize); } if (Cp++ == NULL) Cp = callst; Cp->argp = Ap; *Ap++ = op; puttok(token); stkchr(EOS); t = getchr(); putbak(t); if (t != '(') pbstr(L"()"); else /* try to fix arg count */ *Ap++ = op; Cp->plev = 0; } else { puttok(token); } } else if (match(t, lquote)) { int qlev = 1; for (;;) { token[0] = t = getchr(); token[1] = EOS; if (match(t, rquote)) { if (--qlev > 0) puttok(token); else break; } else if (match(t, lquote)) { ++qlev; puttok(token); } else { if (t == WEOF) error(gettext( "EOF in quote")); putchr(t); } } } else if (match(t, lcom) && ((lcom[0] != L'#' || lcom[1] != L'\0') || prev_char != '$')) { /* * Don't expand commented macro (between lcom and * rcom). * What we know so far is that we have found the * left comment char (lcom). * Make sure we haven't found '#' (lcom) immediately * preceded by '$' because we want to expand "$#". */ puttok(token); for (;;) { token[0] = t = getchr(); token[1] = EOS; if (match(t, rcom)) { puttok(token); break; } else { if (t == WEOF) error(gettext( "EOF in comment")); putchr(t); } } } else if (Cp == NULL) { putchr(t); } else if (t == '(') { if (Cp->plev) stkchr(t); else { /* skip white before arg */ while ((t = getchr()) != WEOF && is_space(t)) ; putbak(t); } ++Cp->plev; } else if (t == ')') { --Cp->plev; if (Cp->plev == 0) { stkchr(EOS); expand(Cp->argp, Ap-Cp->argp-1); op = *Cp->argp; Ap = Cp->argp-1; if (--Cp < callst) Cp = NULL; } else stkchr(t); } else if (t == ',' && Cp->plev <= 1) { stkchr(EOS); *Ap = op; if ((wchar_t *)(++Ap) >= astklm) { --Ap; error2(gettext( "more than %d items on argument stack"), stksize); } while ((t = getchr()) != WEOF && is_space(t)) ; putbak(t); } else { stkchr(t); } } if (Cp != NULL) error(gettext( "EOF in argument list")); delexit(exitstat, 1); return (0); }
static void getflags(int *xargc, char ***xargv, int *option_end) { char *arg; char *t; wchar_t *s[3]; while (*xargc > 1) { arg = (*xargv)[1]; /* point arg to current argument */ /* * This argument is not an option if it equals "-" or if * "--" has already been parsed. */ if (arg[0] != '-' || arg[1] == EOS || *option_end) break; if (arg[0] == '-' && arg[1] == '-' && arg[2] == '\0') { *option_end = 1; } else { switch (arg[1]) { case 'B': chkspace(&arg, xargc, xargv); bufsize = atoi(&arg[2]); if (bufsize <= 0) { bufsize = DEF_BUFSIZE; } break; case 'D': initalloc(); chkspace(&arg, xargc, xargv); for (t = &arg[2]; *t; t++) { if (*t == '=') { *t++ = EOS; break; } } s[1] = str2wstr(&arg[2], 1); s[2] = str2wstr(t, 1); dodef(&s[0], 2); free(s[1]); free(s[2]); break; case 'H': chkspace(&arg, xargc, xargv); hshsize = atoi(&arg[2]); if (hshsize <= 0) { hshsize = DEF_HSHSIZE; } break; case 'S': chkspace(&arg, xargc, xargv); stksize = atoi(&arg[2]); if (stksize <= 0) { stksize = DEF_STKSIZE; } break; case 'T': chkspace(&arg, xargc, xargv); toksize = atoi(&arg[2]); if (toksize <= 0) { toksize = DEF_TOKSIZE; } break; case 'U': initalloc(); chkspace(&arg, xargc, xargv); s[1] = str2wstr(&arg[2], 1); doundef(&s[0], 1); free(s[1]); break; case 'e': setbuf(stdout, NULL); (void) signal(SIGINT, SIG_IGN); break; case 's': /* turn on line sync */ sflag = 1; break; default: (void) fprintf(stderr, gettext("%s: bad option: %s\n"), procnam, arg); delexit(NOT_OK, 0); } } /* end else not "--" */ (*xargv)++; --(*xargc); } /* end while options to process */ }