home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume1 / cpp / part3 < prev    next >
Internet Message Format  |  1986-11-30  |  66KB

  1. From: decvax!minow
  2. Date: Tue, 8 Jan 85 00:05:58 est
  3. Subject: cpp3.arc
  4.  
  5. -h- cpp4.c    Mon Jan  7 23:59:34 1985    cpp4.c
  6. /*
  7.  *                C P P 4 . C
  8.  *        M a c r o  D e f i n i t i o n s
  9.  *
  10.  * Edit History
  11.  * 31-Aug-84    MM    USENET net.sources release
  12.  * 04-Oct-84    MM    __LINE__ and __FILE__ must call ungetstring()
  13.  *            so they work correctly with token concatenation.
  14.  *            Added string formal recognition.
  15.  * 25-Oct-84    MM    "Short-circuit" evaluate #if's so that we
  16.  *            don't print unnecessary error messages for
  17.  *            #if !defined(FOO) && FOO != 0 && 10 / FOO ...
  18.  * 31-Oct-84    ado/MM    Added token concatenation
  19.  *  6-Nov-84    MM    Split off eval stuff
  20.  */
  21.  
  22. #include    <stdio.h>
  23. #include    <ctype.h>
  24. #include    "cppdef.h"
  25. #include    "cpp.h"
  26. /*
  27.  * parm[], parmp, and parlist[] are used to store #define() argument
  28.  * lists.  nargs contains the actual number of parameters stored.
  29.  */
  30. static char    parm[NPARMWORK + 1];    /* define param work buffer     */
  31. static char    *parmp;            /* Free space in parm        */
  32. static char    *parlist[LASTPARM];    /* -> start of each parameter    */
  33. static int    nargs;            /* Parameters for this macro    */
  34.  
  35. dodefine()
  36. /*
  37.  * Called from control when a #define is scanned.  This module
  38.  * parses formal parameters and the replacement string.  When
  39.  * the formal parameter name is encountered in the replacement
  40.  * string, it is replaced by a character in the range 128 to
  41.  * 128+NPARAM (this allows up to 32 parameters within the
  42.  * Dec Multinational range).  If cpp is ported to an EBCDIC
  43.  * machine, you will have to make other arrangements.
  44.  *
  45.  * There is some special case code to distinguish
  46.  *    #define foo    bar
  47.  * from    #define foo()    bar
  48.  *
  49.  * Also, we make sure that
  50.  *    #define    foo    foo
  51.  * expands to "foo" but doesn't put cpp into an infinite loop.
  52.  *
  53.  * A warning message is printed if you redefine a symbol to a
  54.  * different text.  I.e,
  55.  *    #define    foo    123
  56.  *    #define foo    123
  57.  * is ok, but
  58.  *    #define foo    123
  59.  *    #define    foo    +123
  60.  * is not.
  61.  *
  62.  * The following subroutines are called from define():
  63.  * checkparm    called when a token is scanned.  It checks through the
  64.  *        array of formal parameters.  If a match is found, the
  65.  *        token is replaced by a control byte which will be used
  66.  *        to locate the parameter when the macro is expanded.
  67.  * textput    puts a string in the macro work area (parm[]), updating
  68.  *        parmp to point to the first free byte in parm[].
  69.  *        textput() tests for work buffer overflow.
  70.  * charput    puts a single character in the macro work area (parm[])
  71.  *        in a manner analogous to textput().
  72.  */
  73. {
  74.     register int        c;
  75.     register DEFBUF        *dp;        /* -> new definition    */
  76.     int            isredefine;    /* TRUE if redefined    */
  77.     char            *old;        /* Remember redefined    */
  78.     extern int        save();        /* Save char in work[]    */
  79.  
  80.     if (type[(c = skipws())] != LET)
  81.         goto bad_define;
  82.     isredefine = FALSE;            /* Set if redefining    */
  83.     if ((dp = lookid(c)) == NULL)        /* If not known now    */
  84.         dp = defendel(token, FALSE);    /* Save the name    */
  85.     else {                    /* It's known:        */
  86.         isredefine = TRUE;            /* Remember this fact    */
  87.         old = dp->repl;            /* Remember replacement    */
  88.         dp->repl = NULL;            /* No replacement now    */
  89.     }
  90.     parlist[0] = parmp = parm;        /* Setup parm buffer    */
  91.     if ((c = get()) == '(') {        /* With arguments?    */
  92.         nargs = 0;                /* Init formals counter    */
  93.         do {                /* Collect formal parms    */
  94.         if (nargs >= LASTPARM)
  95.             cfatal("Too many arguments for macro", NULLST);
  96.         else if ((c = skipws()) == ')')
  97.             break;            /* Got them all        */
  98.         else if (type[c] != LET)    /* Bad formal syntax    */
  99.             goto bad_define;
  100.         scanid(c);            /* Get the formal param    */
  101.         parlist[nargs++] = parmp;    /* Save its start    */
  102.         textput(token);            /* Save text in parm[]    */
  103.         } while ((c = skipws()) == ',');    /* Get another argument    */
  104.         if (c != ')')            /* Must end at )    */
  105.         goto bad_define;
  106.         c = ' ';                /* Will skip to body    */
  107.     }
  108.     else {
  109.         /*
  110.          * DEF_NOARGS is needed to distinguish between
  111.          * "#define foo" and "#define foo()".
  112.          */
  113.         nargs = DEF_NOARGS;            /* No () parameters    */
  114.     }
  115.     if (type[c] == SPA)            /* At whitespace?    */
  116.         c = skipws();            /* Not any more.    */
  117.     workp = work;                /* Replacement put here    */
  118.     inmacro = TRUE;                /* Keep \<newline> now    */
  119.     while (c != EOF_CHAR && c != '\n') {    /* Compile macro body    */
  120. #if OK_CONCAT
  121.         if (c == '#') {            /* Token concatenation?    */
  122.         while (workp > work && type[workp[-1]] == SPA)
  123.             --workp;            /* Erase leading spaces    */
  124.         save(TOK_SEP);            /* Stuff a delimiter    */
  125.         c = skipws();            /* Eat whitespace    */
  126.         if (type[c] == LET)        /* Another token here?    */
  127.             ;                /* Stuff it normally    */
  128.         else if (type[c] == DIG) {    /* Digit string after?    */
  129.             while (type[c] == DIG) {    /* Stuff the digits    */
  130.             save(c);
  131.             c = get();
  132.             }
  133.             save(TOK_SEP);        /* Delimit 2nd token    */
  134.         }
  135.         else {
  136.             ciwarn("Strange character after # (%d.)", c);
  137.         }
  138.         continue;
  139.         }
  140. #endif
  141.         switch (type[c]) {
  142.         case LET:
  143.         checkparm(c, dp);        /* Might be a formal    */
  144.         break;
  145.  
  146.         case DIG:                /* Number in mac. body    */
  147.         case DOT:                /* Maybe a float number    */
  148.         scannumber(c, save);        /* Scan it off        */
  149.         break;
  150.  
  151.         case QUO:                /* String in mac. body    */
  152. #if STRING_FORMAL
  153.         stparmscan(c, dp);        /* Do string magic    */
  154. #else
  155.         stparmscan(c);
  156. #endif
  157.         break;
  158.  
  159.         case BSH:                /* Backslash        */
  160.         save('\\');
  161.         if ((c = get()) == '\n')
  162.             wrongline = TRUE;
  163.         save(c);
  164.         break;
  165.  
  166.         case SPA:                /* Absorb whitespace    */
  167.         /*
  168.          * Note: the "end of comment" marker is passed on
  169.          * to allow comments to separate tokens.
  170.          */
  171.         if (workp[-1] == ' ')        /* Absorb multiple    */
  172.             break;            /* spaces        */
  173.         else if (c == '\t')
  174.             c = ' ';            /* Normalize tabs    */
  175.         /* Fall through to store character            */
  176.         default:                /* Other character    */
  177.         save(c);
  178.         break;
  179.         }
  180.         c = get();
  181.     }
  182.     inmacro = FALSE;            /* Stop newline hack    */
  183.     unget();                /* For control check    */
  184.     if (workp > work && workp[-1] == ' ')    /* Drop trailing blank    */
  185.         workp--;
  186.     *workp = EOS;                /* Terminate work    */
  187.     dp->repl = savestring(work);        /* Save the string    */
  188.     dp->nargs = nargs;            /* Save arg count    */
  189. #if DEBUG
  190.     if (debug)
  191.         dumpadef("macro definition", dp);
  192. #endif
  193.     if (isredefine) {            /* Error if redefined    */
  194.         if ((old != NULL && dp->repl != NULL && !streq(old, dp->repl))
  195.          || (old == NULL && dp->repl != NULL)
  196.          || (old != NULL && dp->repl == NULL)) {
  197.         cerror("Redefining defined variable \"%s\"", dp->name);
  198.         }
  199.         if (old != NULL)            /* We don't need the    */
  200.         free(old);            /* old definition now.    */
  201.     }     
  202.     return;
  203.  
  204. bad_define:
  205.     cerror("#define syntax error", NULLST);
  206.     inmacro = FALSE;            /* Stop <newline> hack    */
  207. }
  208.  
  209. checkparm(c, dp)
  210. register int    c;
  211. DEFBUF        *dp;
  212. /*
  213.  * Replace this param if it's defined.  Note that the macro name is a
  214.  * possible replacement token.  We stuff DEF_MAGIC in front of the token
  215.  * which is treated as a LETTER by the token scanner and eaten by
  216.  * the output routine.  This prevents the macro expander from
  217.  * looping if someone writes "#define foo foo".
  218.  */
  219. {
  220.     register int        i;
  221.     register char        *cp;
  222.  
  223.     scanid(c);                /* Get parm to token[]    */
  224.     for (i = 0; i < nargs; i++) {        /* For each argument    */
  225.         if (streq(parlist[i], token)) {    /* If it's known    */
  226.         save(i + MAC_PARM);        /* Save a magic cookie    */
  227.         return;                /* And exit the search    */
  228.         }
  229.     }
  230.     if (streq(dp->name, token))        /* Macro name in body?    */
  231.         save(DEF_MAGIC);            /* Save magic marker    */
  232.     for (cp = token; *cp != EOS;)        /* And save        */
  233.         save(*cp++);            /* The token itself    */
  234. }
  235.  
  236. #if STRING_FORMAL
  237. stparmscan(delim, dp)
  238. int        delim;
  239. register DEFBUF    *dp;
  240. /*
  241.  * Scan the string (starting with the given delimiter).
  242.  * The token is replaced if it is the only text in this string or
  243.  * character constant.  The algorithm follows checkparm() above.
  244.  * Note that scanstring() has approved of the string.
  245.  */
  246. {
  247.     register int        c;
  248.  
  249.     /*
  250.      * Warning -- this code hasn't been tested for a while.
  251.      * It exists only to preserve compatibility with earlier
  252.      * implementations of cpp.  It is not part of the Draft
  253.      * ANSI Standard C language.
  254.      */
  255.     save(delim);
  256.     instring = TRUE;
  257.     while ((c = get()) != delim
  258.          && c != '\n'
  259.          && c != EOF_CHAR) {
  260.         if (type[c] == LET)            /* Maybe formal parm    */
  261.         checkparm(c, dp);
  262.         else {
  263.         save(c);
  264.         if (c == '\\')
  265.             save(get());
  266.         }
  267.     }
  268.     instring = FALSE;
  269.     if (c != delim)
  270.         cerror("Unterminated string in macro body", NULLST);
  271.     save(c);
  272. }
  273. #else
  274. stparmscan(delim)
  275. int        delim;
  276. /*
  277.  * Normal string parameter scan.
  278.  */
  279. {
  280.     register char        *wp;
  281.     register int        i;
  282.     extern int        save();
  283.  
  284.     wp = workp;            /* Here's where it starts    */
  285.     if (!scanstring(delim, save))
  286.         return;            /* Exit on scanstring error    */
  287.     workp[-1] = EOS;        /* Erase trailing quote        */
  288.     wp++;                /* -> first string content byte    */ 
  289.     for (i = 0; i < nargs; i++) {
  290.         if (streq(parlist[i], wp)) {
  291.         *wp++ = MAC_PARM + PAR_MAC;    /* Stuff a magic marker    */
  292.         *wp++ = (i + MAC_PARM);        /* Make a formal marker    */
  293.         *wp = wp[-3];            /* Add on closing quote    */
  294.         workp = wp + 1;            /* Reset string end    */
  295.         return;
  296.         }
  297.     }
  298.     workp[-1] = wp[-1];        /* Nope, reset end quote.    */
  299. }
  300. #endif
  301.  
  302. doundef()
  303. /*
  304.  * Remove the symbol from the defined list.
  305.  * Called from the #control processor.
  306.  */
  307. {
  308.     register int        c;
  309.  
  310.     if (type[(c = skipws())] != LET)
  311.         cerror("Illegal #undef argument", NULLST);
  312.     else {
  313.         scanid(c);                /* Get name to token[]    */
  314.         if (defendel(token, TRUE) == NULL) {
  315.         cwarn("Symbol \"%s\" not defined in #undef", token);
  316.         }
  317.     }
  318. }
  319.  
  320. textput(text)
  321. char        *text;
  322. /*
  323.  * Put the string in the parm[] buffer.
  324.  */
  325. {
  326.     register int    size;
  327.  
  328.     size = strlen(text) + 1;
  329.     if ((parmp + size) >= &parm[NPARMWORK])
  330.         cfatal("Macro work area overflow", NULLST);
  331.     else {
  332.         strcpy(parmp, text);
  333.         parmp += size;
  334.     }
  335. }
  336.  
  337. charput(c)
  338. register int    c;
  339. /*
  340.  * Put the byte in the parm[] buffer.
  341.  */
  342. {
  343.     if (parmp >= &parm[NPARMWORK])
  344.         cfatal("Macro work area overflow", NULLST);
  345.     else {
  346.         *parmp++ = c;
  347.     }
  348. }
  349.  
  350. /*
  351.  *        M a c r o   E x p a n s i o n
  352.  */
  353.  
  354. static DEFBUF    *macro;        /* Catches start of infinite macro    */
  355.  
  356. expand(tokenp)
  357. register DEFBUF    *tokenp;
  358. /*
  359.  * Expand a macro.  Called from the cpp mainline routine (via subroutine
  360.  * macroid()) when a token is found in the symbol table.  It calls
  361.  * expcollect() to parse actual parameters, checking for the correct number.
  362.  * It then creates a "file" containing a single line containing the
  363.  * macro with actual parameters inserted appropriately.  This is
  364.  * "pushed back" onto the input stream.  (When the get() routine runs
  365.  * off the end of the macro line, it will dismiss the macro itself.)
  366.  */
  367. {
  368.     register int        c;
  369.     register FILEINFO    *file;
  370.     extern FILEINFO        *getfile();
  371.  
  372. #if DEBUG
  373.     if (debug)
  374.         dumpadef("expand entry", tokenp);
  375. #endif
  376.     /*
  377.      * If no macro is pending, save the name of this macro
  378.      * for an eventual error message.
  379.      */
  380.     if (recursion++ == 0)
  381.         macro = tokenp;
  382.     else if (recursion == RECURSION_LIMIT) {
  383.         cerror("Recursive macro definition of \"%s\"", tokenp->name);
  384.         fprintf(stderr, "(Defined by \"%s\")\n", macro->name);
  385.         if (rec_recover) {
  386.         do {
  387.             c = get();
  388.         } while (infile != NULL && infile->fp == NULL);
  389.         unget();
  390.         recursion = 0;
  391.         return;
  392.         }
  393.     }
  394.     /*
  395.      * Here's a macro to expand.
  396.      */
  397.     nargs = 0;                /* Formals counter    */
  398.     parmp = parm;                /* Setup parm buffer    */
  399.     switch (tokenp->nargs) {
  400.     case (-2):                /* __LINE__        */
  401.         sprintf(work, "%d", line);
  402.         ungetstring(work);
  403.         break;
  404.  
  405.     case (-3):                /* __FILE__        */
  406.         for (file = infile; file != NULL; file = file->parent) {
  407.         if (file->fp != NULL) {
  408.             sprintf(work, "\"%s\"", (file->progname != NULL)
  409.             ? file->progname : file->filename);
  410.             ungetstring(work);
  411.             break;
  412.         }
  413.         }
  414.         break;
  415.  
  416.     default:
  417.         /*
  418.          * Nothing funny about this macro.
  419.          */
  420.         if (tokenp->nargs < 0)
  421.         cfatal("Bug: Illegal __ macro \"%s\"", tokenp->name);
  422.         while ((c = skipws()) == '\n')    /* Look for (, skipping    */
  423.         wrongline = TRUE;        /* spaces and newlines    */
  424.         if (c != '(') {
  425.         /*
  426.          * If the programmer writes
  427.          *    #define foo() ...
  428.          *    ...
  429.          *    foo [no ()]
  430.          * just write foo to the output stream.
  431.          */
  432.         unget();
  433.         cwarn("Macro \"%s\" needs arguments", tokenp->name);
  434.         fputs(tokenp->name, stdout);
  435.         return;
  436.         }
  437.         else if (expcollect()) {        /* Collect arguments    */
  438.         if (tokenp->nargs != nargs) {    /* Should be an error?    */
  439.             cwarn("Wrong number of macro arguments for \"%s\"",
  440.             tokenp->name);
  441.         }
  442. #if DEBUG
  443.         if (debug)
  444.             dumpparm("expand");
  445. #endif
  446.         }                /* Collect arguments        */
  447.     case DEF_NOARGS:        /* No parameters just stuffs    */
  448.         expstuff(tokenp);        /* Do actual parameters        */
  449.     }                /* nargs switch            */
  450. }
  451.  
  452. FILE_LOCAL int
  453. expcollect()
  454. /*
  455.  * Collect the actual parameters for this macro.  TRUE if ok.
  456.  */
  457. {
  458.     register int    c;
  459.     register int    paren;            /* For embedded ()'s    */
  460.     extern int    charput();
  461.  
  462.     for (;;) {
  463.         paren = 0;                /* Collect next arg.    */
  464.         while ((c = skipws()) == '\n')    /* Skip over whitespace    */
  465.         wrongline = TRUE;        /* and newlines.    */
  466.         if (c == ')') {            /* At end of all args?    */
  467.         /*
  468.          * Note that there is a guard byte in parm[]
  469.          * so we don't have to check for overflow here.
  470.          */
  471.         *parmp = EOS;            /* Make sure terminated    */
  472.         break;                /* Exit collection loop    */
  473.         }
  474.         else if (nargs >= LASTPARM)
  475.         cfatal("Too many arguments in macro expansion", NULLST);
  476.         parlist[nargs++] = parmp;        /* At start of new arg    */
  477.         for (;; c = cget()) {        /* Collect arg's bytes    */
  478.         if (c == EOF_CHAR) {
  479.             cerror("end of file within macro argument", NULLST);
  480.             return (FALSE);        /* Sorry.        */
  481.         }
  482.         else if (c == '\\') {        /* Quote next character    */
  483.             charput(c);            /* Save the \ for later    */
  484.             charput(cget());        /* Save the next char.    */
  485.             continue;            /* And go get another    */
  486.         }
  487.         else if (type[c] == QUO) {    /* Start of string?    */
  488.             scanstring(c, charput);    /* Scan it off        */
  489.             continue;            /* Go get next char    */
  490.         }
  491.         else if (c == '(')        /* Worry about balance    */
  492.             paren++;            /* To know about commas    */
  493.         else if (c == ')') {        /* Other side too    */
  494.             if (paren == 0) {        /* At the end?        */
  495.             unget();        /* Look at it later    */
  496.             break;            /* Exit arg getter.    */
  497.             }
  498.             paren--;            /* More to come.    */
  499.         }
  500.         else if (c == ',' && paren == 0) /* Comma delimits args    */
  501.             break;
  502.         else if (c == '\n')        /* Newline inside arg?    */
  503.             wrongline = TRUE;        /* We'll need a #line    */
  504.         charput(c);            /* Store this one    */
  505.         }                    /* Collect an argument    */
  506.         charput(EOS);            /* Terminate argument    */
  507. #if DEBUG
  508.         if (debug)
  509.             printf("parm[%d] = \"%s\"\n", nargs, parlist[nargs - 1]);
  510. #endif
  511.     }                    /* Collect all args.    */
  512.     return (TRUE);                /* Normal return    */
  513. }
  514.  
  515. FILE_LOCAL
  516. expstuff(tokenp)
  517. DEFBUF        *tokenp;        /* Current macro being expanded    */
  518. /*
  519.  * Stuff the macro body, replacing formal parameters by actual parameters.
  520.  */
  521. {
  522.     register int    c;            /* Current character    */
  523.     register char    *inp;            /* -> repl string    */
  524.     register char    *defp;            /* -> macro output buff    */
  525.     int        size;            /* Actual parm. size    */
  526.     char        *defend;        /* -> output buff end    */
  527.     int        string_magic;        /* String formal hack    */
  528.     FILEINFO    *file;            /* Funny #include    */
  529.     extern FILEINFO    *getfile();
  530.  
  531.     file = getfile(NBUFF, tokenp->name);
  532.     inp = tokenp->repl;            /* -> macro replacement    */
  533.     defp = file->buffer;            /* -> output buffer    */
  534.     defend = defp + (NBUFF - 1);        /* Note its end        */
  535.     if (inp != NULL) {
  536.         while ((c = (*inp++ & 0xFF)) != EOS) {
  537.         if (c >= MAC_PARM && c <= (MAC_PARM + PAR_MAC)) {
  538.             string_magic = (c == (MAC_PARM + PAR_MAC));
  539.             if (string_magic)
  540.              c = (*inp++ & 0xFF);
  541.             /*
  542.              * Replace formal parameter by actual parameter string.
  543.              */
  544.             if ((c -= MAC_PARM) < nargs) {
  545.             size = strlen(parlist[c]);
  546.             if ((defp + size) >= defend)
  547.                 goto nospace;
  548.             /*
  549.              * Erase the extra set of quotes.
  550.              */
  551.             if (string_magic && defp[-1] == parlist[c][0]) {
  552.                 strcpy(defp-1, parlist[c]);
  553.                 defp += (size - 2);
  554.             }
  555.             else {
  556.                 strcpy(defp, parlist[c]);
  557.                 defp += size;
  558.             }
  559.             }
  560.         }
  561.         else if (defp >= defend) {
  562. nospace:        cfatal("Out of space in macro \"%s\" arg expansion",
  563.             tokenp->name);
  564.         }
  565.         else {
  566.             *defp++ = c;
  567.         }
  568.         }
  569.     }
  570.     *defp = EOS;
  571. #if DEBUG
  572.     if (debug > 1)
  573.         printf("macroline: \"%s\"\n", file->buffer);
  574. #endif
  575. }
  576.  
  577. #if DEBUG
  578. dumpparm(why)
  579. char        *why;
  580. /*
  581.  * Dump parameter list.
  582.  */
  583. {
  584.     register int    i;
  585.  
  586.     printf("dump of %d parameters (%d bytes total) %s\n",
  587.         nargs, parmp - parm, why);
  588.     for (i = 0; i < nargs; i++) {
  589.         printf("parm[%d] (%d) = \"%s\"\n",
  590.         i + 1, strlen(parlist[i]), parlist[i]);
  591.     }
  592. }
  593. #endif
  594. -h- cpp5.c    Mon Jan  7 23:59:34 1985    cpp5.c
  595. /*
  596.  *                C P P 5 . C
  597.  *        E x p r e s s i o n   E v a l u a t i o n
  598.  *
  599.  * Edit History
  600.  * 31-Aug-84    MM    USENET net.sources release
  601.  * 04-Oct-84    MM    __LINE__ and __FILE__ must call ungetstring()
  602.  *            so they work correctly with token concatenation.
  603.  *            Added string formal recognition.
  604.  * 25-Oct-84    MM    "Short-circuit" evaluate #if's so that we
  605.  *            don't print unnecessary error messages for
  606.  *            #if !defined(FOO) && FOO != 0 && 10 / FOO ...
  607.  * 31-Oct-84    ado/MM    Added token concatenation
  608.  *  6-Nov-84    MM    Split from #define stuff, added sizeof stuff
  609.  * 19-Nov-84    ado    #if error returns TRUE for (sigh) compatibility
  610.  */
  611.  
  612. #include    <stdio.h>
  613. #include    <ctype.h>
  614. #include    "cppdef.h"
  615. #include    "cpp.h"
  616.  
  617. /*
  618.  * Evaluate an #if expression.
  619.  */
  620.  
  621. static char    *opname[] = {        /* For debug and error messages    */
  622. "end of expression", "val", "id",
  623.   "+",   "-",  "*",  "/",  "%",
  624.   "<<", ">>",  "&",  "|",  "^",
  625.   "==", "!=",  "<", "<=", ">=",  ">",
  626.   "&&", "||",  "?",  ":",  ",",
  627.   "unary +", "unary -", "~", "!",  "(",  ")", "(none)",
  628. };
  629.  
  630. /*
  631.  * opdope[] has the operator precedence:
  632.  *     Bits
  633.  *      7    Unused (so the value is always positive)
  634.  *    6-2    Precedence (000x .. 017x)
  635.  *    1-0    Binary op. flags:
  636.  *        01    The binop flag should be set/cleared when this op is seen.
  637.  *        10    The new value of the binop flag.
  638.  * Note:  Expected, New binop
  639.  * constant    0    1    Binop, end, or ) should follow constants
  640.  * End of line    1    0    End may not be preceeded by an operator
  641.  * binary    1    0    Binary op follows a value, value follows.
  642.  * unary    0    0    Unary op doesn't follow a value, value follows
  643.  *   (        0    0    Doesn't follow value, value or unop follows
  644.  *   )        1    1    Follows value.  Op follows.
  645.  */
  646.  
  647. static char    opdope[OP_MAX] = {
  648.   0001,                    /* End of expression        */
  649.   0002,                    /* Digit            */
  650.   0000,                    /* Letter (identifier)        */
  651.   0141, 0141, 0151, 0151, 0151,        /* ADD, SUB, MUL, DIV, MOD    */
  652.   0131, 0131, 0101, 0071, 0071,        /* ASL, ASR, AND,  OR, XOR    */
  653.   0111, 0111, 0121, 0121, 0121,    0121,    /*  EQ,  NE,  LT,  LE,  GE,  GT    */
  654.   0061, 0051, 0041, 0041, 0031,        /* ANA, ORO, QUE, COL, CMA    */
  655. /*
  656.  * Unary op's follow
  657.  */
  658.   0160, 0160, 0160, 0160,        /* NEG, PLU, COM, NOT        */
  659.   0170, 0013, 0023,            /* LPA, RPA, END        */
  660. };
  661. /*
  662.  * OP_QUE and OP_RPA have alternate precedences:
  663.  */
  664. #define    OP_RPA_PREC    0013
  665. #define OP_QUE_PREC    0034
  666.  
  667. /*
  668.  * S_ANDOR and S_QUEST signal "short-circuit" boolean evaluation, so that
  669.  *    #if FOO != 0 && 10 / FOO ...
  670.  * doesn't generate an error message.  They are stored in optab.skip.
  671.  */
  672. #define S_ANDOR        2
  673. #define S_QUEST        1
  674.  
  675. typedef struct optab {
  676.     char    op;            /* Operator            */
  677.     char    prec;            /* Its precedence        */
  678.     char    skip;            /* Short-circuit: TRUE to skip    */
  679. } OPTAB;
  680. static int    evalue;            /* Current value from evallex()    */
  681.  
  682. #ifdef    nomacargs
  683. FILE_LOCAL int
  684. isbinary(op)
  685. register int    op;
  686. {
  687.     return (op >= FIRST_BINOP && op <= LAST_BINOP);
  688. }
  689.  
  690. FILE_LOCAL int
  691. isunary(op)
  692. register int    op;
  693. {
  694.     return (op >= FIRST_UNOP && op <= LAST_UNOP);
  695. }
  696. #else
  697. #define    isbinary(op)    (op >= FIRST_BINOP && op <= LAST_BINOP)
  698. #define    isunary(op)    (op >= FIRST_UNOP  && op <= LAST_UNOP)
  699. #endif
  700.  
  701. /*
  702.  * The following definitions are used to specify basic variable sizes.
  703.  */
  704.  
  705. #ifndef    S_CHAR
  706. #define    S_CHAR        (sizeof (char))
  707. #endif
  708. #ifndef    S_SINT
  709. #define    S_SINT        (sizeof (short int))
  710. #endif
  711. #ifndef    S_INT
  712. #define    S_INT        (sizeof (int))
  713. #endif
  714. #ifndef    S_LINT
  715. #define    S_LINT        (sizeof (long int))
  716. #endif
  717. #ifndef    S_FLOAT
  718. #define    S_FLOAT        (sizeof (float))
  719. #endif
  720. #ifndef    S_DOUBLE
  721. #define    S_DOUBLE    (sizeof (double))
  722. #endif
  723. #ifndef    S_PCHAR
  724. #define    S_PCHAR        (sizeof (char *))
  725. #endif
  726. #ifndef    S_PSINT
  727. #define    S_PSINT        (sizeof (short int *))
  728. #endif
  729. #ifndef    S_PINT
  730. #define    S_PINT        (sizeof (int *))
  731. #endif
  732. #ifndef    S_PLINT
  733. #define    S_PLINT        (sizeof (long int *))
  734. #endif
  735. #ifndef    S_PFLOAT
  736. #define    S_PFLOAT    (sizeof (float *))
  737. #endif
  738. #ifndef    S_PDOUBLE
  739. #define    S_PDOUBLE    (sizeof (double *))
  740. #endif
  741. #ifndef    S_PFPTR
  742. #define S_PFPTR        (sizeof (int (*)()))
  743. #endif
  744.  
  745. typedef struct types {
  746.     short    type;            /* This is the bit if        */
  747.     char    *name;            /* this is the token word    */
  748. } TYPES;
  749.  
  750. static TYPES basic_types[] = {
  751.     { T_CHAR,    "char",        },
  752.     { T_INT,    "int",        },
  753.     { T_FLOAT,    "float",    },
  754.     { T_DOUBLE,    "double",    },
  755.     { T_SHORT,    "short",    },
  756.     { T_LONG,    "long",        },
  757.     { T_SIGNED,    "signed",    },
  758.     { T_UNSIGNED,    "unsigned",    },
  759.     { 0,        NULL,        },    /* Signal end        */
  760. };
  761.  
  762. /*
  763.  * Test_table[] is used to test for illegal combinations.
  764.  */
  765. static short test_table[] = {
  766.     T_FLOAT | T_DOUBLE | T_LONG | T_SHORT,
  767.     T_FLOAT | T_DOUBLE | T_CHAR | T_INT,
  768.     T_FLOAT | T_DOUBLE | T_SIGNED | T_UNSIGNED,
  769.     T_LONG  | T_SHORT  | T_CHAR,
  770.     0                        /* end marker    */
  771. };
  772.  
  773. /*
  774.  * The order of this table is important -- it is also referenced by
  775.  * the command line processor to allow run-time overriding of the
  776.  * built-in size values.  The order must not be changed:
  777.  *    char, short, int, long, float, double (func pointer)
  778.  */
  779. SIZES size_table[] = {
  780.     { T_CHAR,    S_CHAR,        S_PCHAR        },    /* char        */
  781.     { T_SHORT,    S_SINT,        S_PSINT        },    /* short int    */
  782.     { T_INT,    S_INT,        S_PINT        },    /* int        */
  783.     { T_LONG,    S_LINT,        S_PLINT        },    /* long        */
  784.     { T_FLOAT,    S_FLOAT,    S_PFLOAT    },    /* float    */
  785.     { T_DOUBLE,    S_DOUBLE,    S_PDOUBLE    },    /* double    */
  786.     { T_FPTR,    0,        S_PFPTR        },    /* int (*())     */
  787.     { 0,    0,        0        },    /* End of table    */
  788. };
  789.  
  790. int
  791. eval()
  792. /*
  793.  * Evaluate an expression.  Straight-forward operator precedence.
  794.  * This is called from control() on encountering an #if statement.
  795.  * It calls the following routines:
  796.  * evallex    Lexical analyser -- returns the type and value of
  797.  *        the next input token.
  798.  * evaleval    Evaluate the current operator, given the values on
  799.  *        the value stack.  Returns a pointer to the (new)
  800.  *        value stack.
  801.  * For compatiblity with older cpp's, this return returns 1 (TRUE)
  802.  * if a syntax error is detected.
  803.  */
  804. {
  805.     register int    op;        /* Current operator        */
  806.     register int    *valp;        /* -> value vector        */
  807.     register OPTAB    *opp;        /* Operator stack        */
  808.     int        prec;        /* Op precedence        */
  809.     int        binop;        /* Set if binary op. needed    */
  810.     int        op1;        /* Operand from stack        */
  811.     int        skip;        /* For short-circuit testing    */
  812.     int        value[NEXP];    /* Value stack            */
  813.     OPTAB        opstack[NEXP];    /* Operand stack        */
  814.     extern int    *evaleval();    /* Does actual evaluation    */
  815.  
  816.     valp = value;
  817.     opp = opstack;
  818.     opp->op = OP_END;        /* Mark bottom of stack        */
  819.     opp->prec = opdope[OP_END];    /* And its precedence        */
  820.     opp->skip = 0;            /* Not skipping now        */
  821.     binop = 0;
  822. again:    ;
  823. #ifdef    DEBUG_EVAL
  824.     printf("In #if at again: skip = %d, binop = %d, line is: %s",
  825.         opp->skip, binop, infile->bptr);
  826. #endif
  827.     if ((op = evallex(opp->skip)) == OP_SUB && binop == 0)
  828.         op = OP_NEG;            /* Unary minus        */
  829.     else if (op == OP_ADD && binop == 0)
  830.         op = OP_PLU;            /* Unary plus        */
  831.     else if (op == OP_FAIL)
  832.         return (1);                /* Error in evallex    */
  833. #ifdef    DEBUG_EVAL
  834.     printf("op = %s, opdope = %03o, binop = %d, skip = %d\n",
  835.         opname[op], opdope[op], binop, opp->skip);
  836. #endif
  837.     if (op == DIG) {            /* Value?        */
  838.         if (binop != 0) {
  839.         cerror("misplaced constant in #if", NULLST);
  840.         return (1);
  841.         }
  842.         else if (valp >= &value[NEXP-1]) {
  843.         cerror("#if value stack overflow", NULLST);
  844.         return (1);
  845.         }
  846.         else {
  847. #ifdef    DEBUG_EVAL
  848.         printf("pushing %d onto value stack[%d]\n",
  849.             evalue, valp - value);
  850. #endif
  851.         *valp++ = evalue;
  852.         binop = 1;
  853.         }
  854.         goto again;
  855.     }
  856.     else if (op > OP_END) {
  857.         cerror("Illegal #if line", NULLST);
  858.         return (1);
  859.     }
  860.     prec = opdope[op];
  861.     if (binop != (prec & 1)) {
  862.         cerror("Operator %s in incorrect context", opname[op]);
  863.         return (1);
  864.     }
  865.     binop = (prec & 2) >> 1;
  866.     for (;;) {
  867. #ifdef    DEBUG_EVAL
  868.         printf("op %s, prec %d., stacked op %s, prec %d, skip %d\n",
  869.         opname[op], prec, opname[opp->op], opp->prec, opp->skip);
  870. #endif
  871.         if (prec > opp->prec) {
  872.         if (op == OP_LPA)
  873.             prec = OP_RPA_PREC;
  874.         else if (op == OP_QUE)
  875.             prec = OP_QUE_PREC;
  876.         op1 = opp->skip;        /* Save skip for test    */
  877.         /*
  878.          * Push operator onto op. stack.
  879.          */
  880.         opp++;
  881.         if (opp >= &opstack[NEXP]) {
  882.             cerror("expression stack overflow at op \"%s\"",
  883.             opname[op]);
  884.             return (1);
  885.         }
  886.         opp->op = op;
  887.         opp->prec = prec;
  888.         skip = (valp[-1] != 0);        /* Short-circuit tester    */
  889.         /*
  890.          * Do the short-circuit stuff here.  Short-circuiting
  891.          * stops automagically when operators are evaluated.
  892.          */
  893.         if ((op == OP_ANA && !skip)
  894.          || (op == OP_ORO && skip))
  895.             opp->skip = S_ANDOR;    /* And/or skip starts    */
  896.         else if (op == OP_QUE)        /* Start of ?: operator    */
  897.             opp->skip = (op1 & S_ANDOR) | ((!skip) ? S_QUEST : 0);
  898.         else if (op == OP_COL) {    /* : inverts S_QUEST    */
  899.             opp->skip = (op1 & S_ANDOR)
  900.                   | (((op1 & S_QUEST) != 0) ? 0 : S_QUEST);
  901.         }
  902.         else {                /* Other ops leave    */
  903.             opp->skip = op1;        /*  skipping unchanged.    */
  904.         }
  905. #ifdef    DEBUG_EVAL
  906.         printf("stacking %s, valp[-1] == %d at %s",
  907.             opname[op], valp[-1], infile->bptr);
  908.         dumpstack(opstack, opp, value, valp);
  909. #endif
  910.         goto again;
  911.         }
  912.         /*
  913.          * Pop operator from op. stack and evaluate it.
  914.          * End of stack and '(' are specials.
  915.          */
  916.         skip = opp->skip;            /* Remember skip value    */
  917.         switch ((op1 = opp->op)) {        /* Look at stacked op    */
  918.         case OP_END:            /* Stack end marker    */
  919.         if (op == OP_EOE)
  920.             return (valp[-1]);        /* Finished ok.        */
  921.         goto again;            /* Read another op.    */
  922.  
  923.         case OP_LPA:            /* ( on stack        */
  924.         if (op != OP_RPA) {        /* Matches ) on input    */
  925.             cerror("unbalanced paren's, op is \"%s\"", opname[op]);
  926.             return (1);
  927.         }
  928.         opp--;                /* Unstack it        */
  929.         /* goto again;            -- Fall through        */
  930.  
  931.         case OP_QUE:
  932.         goto again;            /* Evaluate true expr.    */
  933.  
  934.         case OP_COL:            /* : on stack.        */
  935.         opp--;                /* Unstack :        */
  936.         if (opp->op != OP_QUE) {    /* Matches ? on stack?    */
  937.             cerror("Misplaced '?' or ':', previous operator is %s",
  938.             opname[opp->op]);
  939.             return (1);
  940.         }
  941.         /*
  942.          * Evaluate op1.
  943.          */
  944.         default:                /* Others:        */
  945.         opp--;                /* Unstack the operator    */
  946. #ifdef    DEBUG_EVAL
  947.         printf("Stack before evaluation of %s\n", opname[op1]);
  948.         dumpstack(opstack, opp, value, valp);
  949. #endif
  950.         valp = evaleval(valp, op1, skip);
  951. #ifdef    DEBUG_EVAL
  952.         printf("Stack after evaluation\n");
  953.         dumpstack(opstack, opp, value, valp);
  954. #endif
  955.         }                    /* op1 switch end    */
  956.     }                    /* Stack unwind loop    */
  957. }
  958.  
  959. FILE_LOCAL int
  960. evallex(skip)
  961. int        skip;        /* TRUE if short-circuit evaluation    */
  962. /*
  963.  * Return next eval operator or value.  Called from eval().  It
  964.  * calls a special-purpose routines for 'char' strings and
  965.  * numeric values:
  966.  * evalchar    called to evaluate 'x'
  967.  * evalnum    called to evaluate numbers.
  968.  */
  969. {
  970.     register int    c, c1, t;
  971.  
  972. again:  do {                    /* Collect the token    */
  973.         c = skipws();
  974.         if ((c = macroid(c)) == EOF_CHAR || c == '\n') {
  975.         unget();
  976.         return (OP_EOE);        /* End of expression    */
  977.         }
  978.     } while ((t = type[c]) == LET && catenate());
  979.     if (t == INV) {                /* Total nonsense    */
  980.         if (!skip) {
  981.         if (isascii(c) && isprint(c))
  982.             cierror("illegal character '%c' in #if", c);
  983.         else
  984.             cierror("illegal character (%d decimal) in #if", c);
  985.         }
  986.         return (OP_FAIL);
  987.     }
  988.     else if (t == QUO) {            /* ' or "        */
  989.         if (c == '\'') {            /* Character constant    */
  990.         evalue = evalchar(skip);    /* Somewhat messy    */
  991. #ifdef    DEBUG_EVAL
  992.         printf("evalchar returns %d.\n", evalue);
  993. #endif
  994.         return (DIG);            /* Return a value    */
  995.         }
  996.         cerror("Can't use a string in an #if", NULLST);
  997.         return (OP_FAIL);
  998.     }
  999.     else if (t == LET) {            /* ID must be a macro    */
  1000.         if (streq(token, "defined")) {    /* Or defined name    */
  1001.         c1 = c = skipws();
  1002.         if (c == '(')            /* Allow defined(name)    */
  1003.             c = skipws();
  1004.         if (type[c] == LET) {
  1005.             evalue = (lookid(c) != NULL);
  1006.             if (c1 != '('        /* Need to balance    */
  1007.              || skipws() == ')')    /* Did we balance?    */
  1008.             return (DIG);        /* Parsed ok        */
  1009.         }
  1010.         cerror("Bad #if ... defined() syntax", NULLST);
  1011.         return (OP_FAIL);
  1012.         }
  1013.         else if (streq(token, "sizeof"))    /* New sizeof hackery    */
  1014.         return (dosizeof());        /* Gets own routine    */
  1015.         /*
  1016.          * The Draft ANSI C Standard says that an undefined symbol
  1017.          * in an #if has the value zero.  We are a bit pickier,
  1018.          * warning except where the programmer was careful to write
  1019.          *         #if defined(foo) ? foo : 0
  1020.          */
  1021.         if (!skip)
  1022.         cwarn("undefined symbol \"%s\" in #if, 0 used", token);
  1023.         evalue = 0;
  1024.         return (DIG);
  1025.     }
  1026.     else if (t == DIG) {            /* Numbers are harder    */
  1027.         evalue = evalnum(c);
  1028. #ifdef    DEBUG_EVAL
  1029.         printf("evalnum returns %d.\n", evalue);
  1030. #endif
  1031.     }
  1032.     else if (strchr("!=<>&|\\", c) != NULL) {
  1033.         /*
  1034.          * Process a possible multi-byte lexeme.
  1035.          */
  1036.         c1 = cget();            /* Peek at next char    */
  1037.         switch (c) {
  1038.         case '!':
  1039.         if (c1 == '=')
  1040.             return (OP_NE);
  1041.         break;
  1042.  
  1043.         case '=':
  1044.         if (c1 != '=') {        /* Can't say a=b in #if    */
  1045.             unget();
  1046.             cerror("= not allowed in #if", NULLST);
  1047.             return (OP_FAIL);
  1048.         }
  1049.         return (OP_EQ);
  1050.  
  1051.         case '>':
  1052.         case '<':
  1053.         if (c1 == c)
  1054.             return ((c == '<') ? OP_ASL : OP_ASR);
  1055.         else if (c1 == '=')
  1056.             return ((c == '<') ? OP_LE  : OP_GE);
  1057.         break;
  1058.  
  1059.         case '|':
  1060.         case '&':
  1061.         if (c1 == c)
  1062.             return ((c == '|') ? OP_ORO : OP_ANA);
  1063.         break;
  1064.  
  1065.         case '\\':
  1066.         if (c1 == '\n')            /* Multi-line if    */
  1067.             goto again;
  1068.         cerror("Unexpected \\ in #if", NULLST);
  1069.         return (OP_FAIL);
  1070.         }
  1071.         unget();
  1072.     }
  1073.     return (t);
  1074. }
  1075.  
  1076. FILE_LOCAL int
  1077. dosizeof()
  1078. /*
  1079.  * Process the sizeof (basic type) operation in an #if string.
  1080.  * Sets evalue to the size and returns
  1081.  *    DIG        success
  1082.  *    OP_FAIL        bad parse or something.
  1083.  */
  1084. {
  1085.     register int    c;
  1086.     register TYPES    *tp;
  1087.     register SIZES    *sizp;
  1088.     register short    *testp;
  1089.     short        typecode;
  1090.  
  1091.     if ((c = skipws()) != '(')
  1092.         goto nogood;
  1093.     /*
  1094.      * Scan off the tokens.
  1095.      */
  1096.     typecode = 0;
  1097.     while ((c = skipws())) {
  1098.         if ((c = macroid(c)) == EOF_CHAR || c == '\n')
  1099.         goto nogood;            /* End of line is a bug    */
  1100.         else if (c == '(') {        /* thing (*)() func ptr    */
  1101.         if (skipws() == '*'
  1102.          && skipws() == ')') {        /* We found (*)        */
  1103.             if (skipws() != '(')    /* Let () be optional    */
  1104.             unget();
  1105.             else if (skipws() != ')')
  1106.             goto nogood;
  1107.             typecode |= T_FPTR;        /* Function pointer    */
  1108.         }
  1109.         else {                /* Junk is a bug    */
  1110.             goto nogood;
  1111.         }
  1112.         }
  1113.         else if (type[c] != LET)        /* Exit if not a type    */
  1114.         break;
  1115.         else if (!catenate()) {        /* Maybe combine tokens    */
  1116.         /*
  1117.          * Look for this unexpandable token in basic_types.
  1118.          * The code accepts "int long" as well as "long int"
  1119.          * which is a minor bug as bugs go (and one shared with
  1120.          * a lot of C compilers).
  1121.          */
  1122.         for (tp = basic_types; tp->name != NULLST; tp++) {
  1123.             if (streq(token, tp->name))
  1124.             break;
  1125.         }
  1126.         if (tp->name == NULLST) {
  1127.             cerror("#if sizeof, unknown type \"%s\"", token);
  1128.             return (OP_FAIL);
  1129.         }
  1130.         typecode |= tp->type;        /* Or in the type bit    */
  1131.         }
  1132.     }
  1133.     /*
  1134.      * We are at the end of the type scan.  Chew off '*' if necessary.
  1135.      */
  1136.     if (c == '*') {
  1137.         typecode |= T_PTR;
  1138.         c = skipws();
  1139.     }
  1140.     if (c == ')') {                /* Last syntax check    */
  1141.         for (testp = test_table; *testp != 0; testp++) {
  1142.         if (!bittest(typecode & *testp)) {
  1143.             cerror("#if ... sizeof: illegal type combination", NULLST);
  1144.             return (OP_FAIL);
  1145.         }
  1146.         }
  1147.         /*
  1148.          * We assume that all function pointers are the same size:
  1149.          *        sizeof (int (*)()) == sizeof (float (*)())
  1150.          * We assume that signed and unsigned don't change the size:
  1151.          *        sizeof (signed int) == (sizeof unsigned int)
  1152.          */
  1153.         if ((typecode & T_FPTR) != 0)    /* Function pointer    */
  1154.         typecode = T_FPTR | T_PTR;
  1155.         else {                /* Var or var * datum    */
  1156.         typecode &= ~(T_SIGNED | T_UNSIGNED);
  1157.         if ((typecode & (T_SHORT | T_LONG)) != 0)
  1158.             typecode &= ~T_INT;
  1159.         }
  1160.         if ((typecode & ~T_PTR) == 0) {
  1161.         cerror("#if sizeof() error, no type specified", NULLST);
  1162.         return (OP_FAIL);
  1163.         }
  1164.         /*
  1165.          * Exactly one bit (and possibly T_PTR) may be set.
  1166.          */
  1167.         for (sizp = size_table; sizp->bits != 0; sizp++) {
  1168.         if ((typecode & ~T_PTR) == sizp->bits) {
  1169.             evalue = ((typecode & T_PTR) != 0)
  1170.             ? sizp->psize : sizp->size;
  1171.             return (DIG);
  1172.         }
  1173.         }                    /* We shouldn't fail    */
  1174.         cierror("#if ... sizeof: bug, unknown type code 0x%x", typecode);
  1175.         return (OP_FAIL);
  1176.     }
  1177.  
  1178. nogood:    unget();
  1179.     cerror("#if ... sizeof() syntax error", NULLST);
  1180.     return (OP_FAIL);
  1181. }
  1182.  
  1183. FILE_LOCAL int
  1184. bittest(value)
  1185. /*
  1186.  * TRUE if value is zero or exactly one bit is set in value.
  1187.  */
  1188. {
  1189. #if (4096 & ~(-4096)) == 0
  1190.     return ((value & ~(-value)) == 0);
  1191. #else
  1192.     /*
  1193.      * Do it the hard way (for non 2's complement machines)
  1194.      */
  1195.     return (value == 0 || value ^ (value - 1) == (value * 2 - 1));
  1196. #endif
  1197. }
  1198.  
  1199. FILE_LOCAL int
  1200. evalnum(c)
  1201. register int    c;
  1202. /*
  1203.  * Expand number for #if lexical analysis.  Note: evalnum recognizes
  1204.  * the unsigned suffix, but only returns a signed int value.
  1205.  */
  1206. {
  1207.     register int    value;
  1208.     register int    base;
  1209.     register int    c1;
  1210.  
  1211.     if (c != '0')
  1212.         base = 10;
  1213.     else if ((c = cget()) == 'x' || c == 'X') {
  1214.         base = 16;
  1215.         c = cget();
  1216.     }
  1217.     else base = 8;
  1218.     value = 0;
  1219.     for (;;) {
  1220.         c1 = c;
  1221.         if (isascii(c) && isupper(c1))
  1222.         c1 = tolower(c1);
  1223.         if (c1 >= 'a')
  1224.         c1 -= ('a' - 10);
  1225.         else c1 -= '0';
  1226.         if (c1 < 0 || c1 >= base)
  1227.         break;
  1228.         value *= base;
  1229.         value += c1;
  1230.         c = cget();
  1231.     }
  1232.     if (c == 'u' || c == 'U')    /* Unsigned nonsense        */
  1233.         c = cget();
  1234.     unget();
  1235.     return (value);
  1236. }
  1237.  
  1238. FILE_LOCAL int
  1239. evalchar(skip)
  1240. int        skip;        /* TRUE if short-circuit evaluation    */
  1241. /*
  1242.  * Get a character constant
  1243.  */
  1244. {
  1245.     register int    c;
  1246.     register int    value;
  1247.     register int    count;
  1248.  
  1249.     instring = TRUE;
  1250.     if ((c = cget()) == '\\') {
  1251.         switch ((c = cget())) {
  1252.         case 'a':                /* New in Standard    */
  1253. #if ('a' == '\a' || '\a' == ALERT)
  1254.         value = ALERT;            /* Use predefined value    */
  1255. #else
  1256.         value = '\a';            /* Use compiler's value    */
  1257. #endif
  1258.         break;
  1259.  
  1260.         case 'b':
  1261.         value = '\b';
  1262.         break;
  1263.  
  1264.         case 'f':
  1265.         value = '\f';
  1266.         break;
  1267.  
  1268.         case 'n':
  1269.         value = '\n';
  1270.         break;
  1271.  
  1272.         case 'r':
  1273.         value = '\r';
  1274.         break;
  1275.  
  1276.         case 't':
  1277.         value = '\t';
  1278.         break;
  1279.  
  1280.         case 'v':                /* New in Standard    */
  1281. #if ('v' == '\v' || '\v' == VT)
  1282.         value = VT;            /* Use predefined value    */
  1283. #else
  1284.         value = '\v';            /* Use compiler's value    */
  1285. #endif
  1286.         break;
  1287.  
  1288.         case 'x':                /* '\xFF'        */
  1289.         count = 3;
  1290.         value = 0;
  1291.         while ((((c = get()) >= '0' && c <= '9')
  1292.              || (c >= 'a' && c <= 'f')
  1293.              || (c >= 'A' && c <= 'F'))
  1294.             && (--count >= 0)) {
  1295.             value *= 16;
  1296.             value += (c <= '9') ? (c - '0') : ((c & 0xF) + 9);
  1297.         }
  1298.         unget();
  1299.         break;
  1300.  
  1301.         default:
  1302.         if (c >= '0' && c <= '7') {
  1303.             count = 3;
  1304.             value = 0;
  1305.             while (c >= '0' && c <= '7' && --count >= 0) {
  1306.             value *= 8;
  1307.             value += (c - '0');
  1308.             c = get();
  1309.             }
  1310.             unget();
  1311.         }
  1312.         else value = c;
  1313.         break;
  1314.         }
  1315.     }
  1316.     else if (c == '\'')
  1317.         value = 0;
  1318.     else value = c;
  1319.     /*
  1320.      * We warn on multi-byte constants and try to hack
  1321.      * (big|little)endian machines.
  1322.      */
  1323. #if BIG_ENDIAN
  1324.     count = 0;
  1325. #endif
  1326.     while ((c = get()) != '\'' && c != EOF_CHAR && c != '\n') {
  1327.         if (!skip)
  1328.         ciwarn("multi-byte constant '%c' isn't portable", c);
  1329. #if BIG_ENDIAN
  1330.         count += BITS_CHAR;
  1331.         value += (c << count);
  1332. #else
  1333.         value <<= BITS_CHAR;
  1334.         value += c;
  1335. #endif
  1336.     }
  1337.     instring = FALSE;
  1338.     return (value);
  1339. }
  1340.  
  1341. FILE_LOCAL int *
  1342. evaleval(valp, op, skip)
  1343. register int    *valp;
  1344. int        op;
  1345. int        skip;        /* TRUE if short-circuit evaluation    */
  1346. /*
  1347.  * Apply the argument operator to the data on the value stack.
  1348.  * One or two values are popped from the value stack and the result
  1349.  * is pushed onto the value stack.
  1350.  *
  1351.  * OP_COL is a special case.
  1352.  *
  1353.  * evaleval() returns the new pointer to the top of the value stack.
  1354.  */
  1355. {
  1356.     register int    v1, v2;
  1357.  
  1358.     if (isbinary(op))
  1359.         v2 = *--valp;
  1360.     v1 = *--valp;
  1361. #ifdef    DEBUG_EVAL
  1362.     printf("%s op %s", (isbinary(op)) ? "binary" : "unary",
  1363.         opname[op]);
  1364.     if (isbinary(op))
  1365.         printf(", v2 = %d.", v2);
  1366.     printf(", v1 = %d.\n", v1);
  1367. #endif
  1368.     switch (op) {
  1369.     case OP_EOE:
  1370.          break;
  1371.  
  1372.     case OP_ADD:
  1373.         v1 += v2;
  1374.         break;
  1375.  
  1376.     case OP_SUB:
  1377.         v1 -= v2;
  1378.         break;
  1379.  
  1380.     case OP_MUL:
  1381.         v1 *= v2;
  1382.         break;
  1383.  
  1384.     case OP_DIV:
  1385.     case OP_MOD:
  1386.         if (v2 == 0) {
  1387.         if (!skip) {
  1388.             cwarn("%s by zero in #if, zero result assumed",
  1389.             (op == OP_DIV) ? "divide" : "mod");
  1390.         }
  1391.         v1 = 0;
  1392.         }
  1393.         else if (op == OP_DIV)
  1394.         v1 /= v2;
  1395.         else
  1396.         v1 %= v2;
  1397.         break;
  1398.  
  1399.     case OP_ASL:
  1400.         v1 <<= v2;
  1401.         break;
  1402.  
  1403.     case OP_ASR:
  1404.         v1 >>= v2;
  1405.         break;
  1406.  
  1407.     case OP_AND:
  1408.         v1 &= v2;
  1409.         break;
  1410.  
  1411.     case OP_OR:
  1412.         v1 |= v2;
  1413.         break;
  1414.  
  1415.     case OP_XOR:
  1416.         v1 ^= v2;
  1417.         break;
  1418.  
  1419.     case OP_EQ:
  1420.         v1 = (v1 == v2);
  1421.         break;
  1422.  
  1423.     case OP_NE:
  1424.         v1 = (v1 != v2);
  1425.         break;
  1426.  
  1427.     case OP_LT:
  1428.         v1 = (v1 < v2);
  1429.         break;
  1430.  
  1431.     case OP_LE:
  1432.         v1 = (v1 <= v2);
  1433.         break;
  1434.  
  1435.     case OP_GE:
  1436.         v1 = (v1 >= v2);
  1437.         break;
  1438.  
  1439.     case OP_GT:
  1440.         v1 = (v1 > v2);
  1441.         break;
  1442.  
  1443.     case OP_ANA:
  1444.         v1 = (v1 && v2);
  1445.         break;
  1446.  
  1447.     case OP_ORO:
  1448.         v1 = (v1 || v2);
  1449.         break;
  1450.  
  1451.     case OP_COL:
  1452.         /*
  1453.          * v1 has the "true" value, v2 the "false" value.
  1454.          * The top of the value stack has the test.
  1455.          */
  1456.         v1 = (*--valp) ? v1 : v2;
  1457.         break;
  1458.  
  1459.     case OP_NEG:
  1460.         v1 = (-v1);
  1461.         break;
  1462.  
  1463.     case OP_PLU:
  1464.         break;
  1465.  
  1466.     case OP_COM:
  1467.         v1 = ~v1;
  1468.         break;
  1469.  
  1470.     case OP_NOT:
  1471.         v1 = !v1;
  1472.         break;
  1473.  
  1474.     default:
  1475.         cierror("#if bug, operand = %d.", op);
  1476.         v1 = 0;
  1477.     }
  1478.     *valp++ = v1;
  1479.     return (valp);
  1480. }
  1481.  
  1482. #ifdef    DEBUG_EVAL
  1483. dumpstack(opstack, opp, value, valp)
  1484. OPTAB        opstack[NEXP];    /* Operand stack        */
  1485. register OPTAB    *opp;        /* Operator stack        */
  1486. int        value[NEXP];    /* Value stack            */
  1487. register int    *valp;        /* -> value vector        */
  1488. {
  1489.     printf("index op prec skip name -- op stack at %s", infile->bptr);
  1490.     while (opp > opstack) {
  1491.         printf(" [%2d] %2d  %03o    %d %s\n", opp - opstack,
  1492.         opp->op, opp->prec, opp->skip, opname[opp->op]);
  1493.         opp--;
  1494.     }
  1495.     while (--valp >= value) {
  1496.         printf("value[%d] = %d\n", (valp - value), *valp);
  1497.     }
  1498. }
  1499. #endif
  1500.  
  1501. -h- cpp6.c    Mon Jan  7 23:59:34 1985    cpp6.c
  1502. /*
  1503.  *                C P P 6 . C
  1504.  *        S u p p o r t   R o u t i n e s
  1505.  *
  1506.  * Edit History
  1507.  * 25-May-84 MM        Added 8-bit support to type table.
  1508.  * 30-May-84 ARF    sharp() should output filename in quotes
  1509.  * 02-Aug-84 MM        Newline and #line hacking.  sharp() now in cpp1.c
  1510.  * 31-Aug-84 MM        USENET net.sources release
  1511.  * 11-Sep-84 ado/MM    Keepcomments, also line number pathological
  1512.  * 12-Sep-84 ado/MM    bug if comment changes to space and we unget later.
  1513.  * 03-Oct-84 gkr/MM    Fixed scannumber bug for '.e' (as in struct.element).
  1514.  * 04-Oct-84 MM        Added ungetstring() for token concatenation
  1515.  * 08-Oct-84 MM        Yet another attack on number scanning
  1516.  * 31-Oct-84 ado    Parameterized $ in identifiers
  1517.  *  2-Nov-84 MM        Token concatenation is messier than I thought
  1518.  *  6-Dec-84 MM        \<nl> is everywhere invisible.
  1519.  */
  1520.  
  1521. #include    <stdio.h>
  1522. #include    <ctype.h>
  1523. #include    "cppdef.h"
  1524. #include    "cpp.h"
  1525.  
  1526. /*
  1527.  * skipnl()    skips over input text to the end of the line.
  1528.  * skipws()    skips over "whitespace" (spaces or tabs), but
  1529.  *        not skip over the end of the line.  It skips over
  1530.  *        TOK_SEP, however (though that shouldn't happen).
  1531.  * scanid()    reads the next token (C identifier) into token[].
  1532.  *        The caller has already read the first character of
  1533.  *        the identifier.  Unlike macroid(), the token is
  1534.  *        never expanded.
  1535.  * macroid()    reads the next token (C identifier) into token[].
  1536.  *        If it is a #defined macro, it is expanded, and
  1537.  *        macroid() returns TRUE, otherwise, FALSE.
  1538.  * catenate()    Does the dirty work of token concatenation, TRUE if it did.
  1539.  * scanstring()    Reads a string from the input stream, calling
  1540.  *        a user-supplied function for each character.
  1541.  *        This function may be output() to write the
  1542.  *        string to the output file, or save() to save
  1543.  *        the string in the work buffer.
  1544.  * scannumber()    Reads a C numeric constant from the input stream,
  1545.  *        calling the user-supplied function for each
  1546.  *        character.  (output() or save() as noted above.)
  1547.  * save()    Save one character in the work[] buffer.
  1548.  * savestring()    Saves a string in malloc() memory.
  1549.  * getfile()    Initialize a new FILEINFO structure, called when
  1550.  *        #include opens a new file, or a macro is to be
  1551.  *        expanded.
  1552.  * getmem()    Get a specified number of bytes from malloc memory.
  1553.  * output()    Write one character to stdout (calling putchar) --
  1554.  *        implemented as a function so its address may be
  1555.  *        passed to scanstring() and scannumber().
  1556.  * lookid()    Scans the next token (identifier) from the input
  1557.  *        stream.  Looks for it in the #defined symbol table.
  1558.  *        Returns a pointer to the definition, if found, or NULL
  1559.  *        if not present.  The identifier is stored in token[].
  1560.  * defnedel()    Define enter/delete subroutine.  Updates the
  1561.  *        symbol table.
  1562.  * get()    Read the next byte from the current input stream,
  1563.  *        handling end of (macro/file) input and embedded
  1564.  *        comments appropriately.  Note that the global
  1565.  *        instring is -- essentially -- a parameter to get().
  1566.  * cget()    Like get(), but skip over TOK_SEP.
  1567.  * unget()    Push last gotten character back on the input stream.
  1568.  * cerror(), cwarn(), cfatal(), cierror(), ciwarn()
  1569.  *        These routines format an print messages to the user.
  1570.  *        cerror & cwarn take a format and a single string argument.
  1571.  *        cierror & ciwarn take a format and a single int (char) argument.
  1572.  *        cfatal takes a format and a single string argument.
  1573.  */
  1574.  
  1575. /*
  1576.  * This table must be rewritten for a non-Ascii machine.
  1577.  *
  1578.  * Note that several "non-visible" characters have special meaning:
  1579.  * Hex 1D DEF_MAGIC -- a flag to prevent #define recursion.
  1580.  * Hex 1E TOK_SEP   -- a delimiter for token concatenation
  1581.  * Hex 1F COM_SEP   -- a zero-width whitespace for comment concatenation
  1582.  */
  1583. #if TOK_SEP != 0x1E || COM_SEP != 0x1F || DEF_MAGIC != 0x1D
  1584.     << error type table isn't correct >>
  1585. #endif
  1586.  
  1587. #if OK_DOLLAR
  1588. #define    DOL    LET
  1589. #else
  1590. #define    DOL    000
  1591. #endif
  1592.  
  1593. char type[256] = {        /* Character type codes    Hex        */
  1594.    END,   000,   000,   000,   000,   000,   000,   000, /* 00        */
  1595.    000,   SPA,   000,   000,   000,   000,   000,   000, /* 08        */
  1596.    000,   000,   000,   000,   000,   000,   000,   000, /* 10        */
  1597.    000,   000,   000,   000,   000,   LET,   000,   SPA, /* 18        */
  1598.    SPA,OP_NOT,   QUO,   000,   DOL,OP_MOD,OP_AND,   QUO, /* 20  !"#$%&'    */
  1599. OP_LPA,OP_RPA,OP_MUL,OP_ADD,   000,OP_SUB,   DOT,OP_DIV, /* 28 ()*+,-./    */
  1600.    DIG,   DIG,   DIG,   DIG,   DIG,   DIG,   DIG,   DIG, /* 30 01234567    */
  1601.    DIG,   DIG,OP_COL,   000, OP_LT, OP_EQ, OP_GT,OP_QUE, /* 38 89:;<=>?    */
  1602.    000,   LET,   LET,   LET,   LET,   LET,   LET,   LET, /* 40 @ABCDEFG    */
  1603.    LET,   LET,   LET,   LET,   LET,   LET,   LET,   LET, /* 48 HIJKLMNO    */
  1604.    LET,   LET,   LET,   LET,   LET,   LET,   LET,   LET, /* 50 PQRSTUVW    */
  1605.    LET,   LET,   LET,   000,   BSH,   000,OP_XOR,   LET, /* 58 XYZ[\]^_    */
  1606.    000,   LET,   LET,   LET,   LET,   LET,   LET,   LET, /* 60 `abcdefg    */
  1607.    LET,   LET,   LET,   LET,   LET,   LET,   LET,   LET, /* 68 hijklmno    */
  1608.    LET,   LET,   LET,   LET,   LET,   LET,   LET,   LET, /* 70 pqrstuvw    */
  1609.    LET,   LET,   LET,   000, OP_OR,   000,OP_NOT,   000, /* 78 xyz{|}~    */
  1610.    000,   000,   000,   000,   000,   000,   000,   000, /*   80 .. FF    */
  1611.    000,   000,   000,   000,   000,   000,   000,   000, /*   80 .. FF    */
  1612.    000,   000,   000,   000,   000,   000,   000,   000, /*   80 .. FF    */
  1613.    000,   000,   000,   000,   000,   000,   000,   000, /*   80 .. FF    */
  1614.    000,   000,   000,   000,   000,   000,   000,   000, /*   80 .. FF    */
  1615.    000,   000,   000,   000,   000,   000,   000,   000, /*   80 .. FF    */
  1616.    000,   000,   000,   000,   000,   000,   000,   000, /*   80 .. FF    */
  1617.    000,   000,   000,   000,   000,   000,   000,   000, /*   80 .. FF    */
  1618. };
  1619.  
  1620. skipnl()
  1621. /*
  1622.  * Skip to the end of the current input line.
  1623.  */
  1624. {
  1625.     register int        c;
  1626.  
  1627.     do {                /* Skip to newline    */
  1628.         c = get();
  1629.     } while (c != '\n' && c != EOF_CHAR);
  1630. }
  1631.  
  1632. int
  1633. skipws()
  1634. /*
  1635.  * Skip over whitespace
  1636.  */
  1637. {
  1638.     register int        c;
  1639.  
  1640.     do {                /* Skip whitespace    */
  1641.         c = get();
  1642. #if COMMENT_INVISIBLE
  1643.     } while (type[c] == SPA || c == COM_SEP);
  1644. #else
  1645.     } while (type[c] == SPA);
  1646. #endif
  1647.     return (c);
  1648. }
  1649.  
  1650. scanid(c)
  1651. register int    c;                /* First char of id    */
  1652. /*
  1653.  * Get the next token (an id) into the token buffer.
  1654.  * Note: this code is duplicated in lookid().
  1655.  * Change one, change both.
  1656.  */
  1657. {
  1658.     register char    *bp;
  1659.  
  1660.     if (c == DEF_MAGIC)            /* Eat the magic token    */
  1661.         c = get();                /* undefiner.        */
  1662.     bp = token;
  1663.     do {
  1664.         if (bp < &token[IDMAX])        /* token dim is IDMAX+1    */
  1665.         *bp++ = c;
  1666.         c = get();
  1667.     } while (type[c] == LET || type[c] == DIG);
  1668.     unget();
  1669.     *bp = EOS;
  1670. }
  1671.  
  1672. int
  1673. macroid(c)
  1674. register int        c;
  1675. /*
  1676.  * If c is a letter, scan the id.  if it's #defined, expand it and scan
  1677.  * the next character and try again.
  1678.  *
  1679.  * Else, return the character.  If type[c] is a LET, the token is in token.
  1680.  */
  1681. {
  1682.     register DEFBUF    *dp;
  1683.  
  1684.     if (infile != NULL && infile->fp != NULL)
  1685.         recursion = 0;
  1686.     while (type[c] == LET && (dp = lookid(c)) != NULL) {
  1687.         expand(dp);
  1688.         c = get();
  1689.     }
  1690.     return (c);
  1691. }
  1692.  
  1693. int
  1694. catenate()
  1695. /*
  1696.  * A token was just read (via macroid).
  1697.  * If the next character is TOK_SEP, concatenate the next token
  1698.  * return TRUE -- which should recall macroid after refreshing
  1699.  * macroid's argument.  If it is not TOK_SEP, unget() the character
  1700.  * and return FALSE.
  1701.  */
  1702. {
  1703.     register int        c;
  1704.     register char        *token1;
  1705.  
  1706. #if OK_CONCAT
  1707.     if (get() != TOK_SEP) {            /* Token concatenation    */
  1708.         unget();
  1709.         return (FALSE);
  1710.     }
  1711.     else {
  1712.         token1 = savestring(token);        /* Save first token    */
  1713.         c = macroid(get());            /* Scan next token    */
  1714.         switch(type[c]) {            /* What was it?        */
  1715.         case LET:                /* An identifier, ...    */
  1716.         if (strlen(token1) + strlen(token) >= NWORK)
  1717.             cfatal("work buffer overflow doing %s #", token1);
  1718.         sprintf(work, "%s%s", token1, token);
  1719.         break;
  1720.  
  1721.         case DIG:                /* A digit string    */
  1722.         strcpy(work, token1);
  1723.         workp = work + strlen(work);
  1724.         do {
  1725.             save(c);
  1726.         } while ((c = get()) != TOK_SEP);
  1727.         /*
  1728.          * The trailing TOK_SEP is no longer needed.
  1729.          */
  1730.         save(EOS);
  1731.         break;
  1732.  
  1733.         default:                /* An error, ...    */
  1734.         if (isprint(c))
  1735.             cierror("Strange character '%c' after #", c);
  1736.         else
  1737.             cierror("Strange character (%d.) after #", c);
  1738.         strcpy(work, token1);
  1739.         unget();
  1740.         break;
  1741.         }
  1742.         /*
  1743.          * work has the concatenated token and token1 has
  1744.          * the first token (no longer needed).  Unget the
  1745.          * new (concatenated) token after freeing token1.
  1746.          * Finally, setup to read the new token.
  1747.          */
  1748.         free(token1);            /* Free up memory    */
  1749.         ungetstring(work);            /* Unget the new thing,    */
  1750.         return (TRUE);
  1751.     }
  1752. #else
  1753.     return (FALSE);                /* Not supported    */
  1754. #endif
  1755. }
  1756.  
  1757. int
  1758. scanstring(delim, outfun)
  1759. register int    delim;            /* ' or "            */
  1760. int        (*outfun)();        /* Output function        */
  1761. /*
  1762.  * Scan off a string.  Warning if terminated by newline or EOF.
  1763.  * outfun() outputs the character -- to a buffer if in a macro.
  1764.  * TRUE if ok, FALSE if error.
  1765.  */
  1766. {
  1767.     register int        c;
  1768.  
  1769.     instring = TRUE;        /* Don't strip comments        */
  1770.     (*outfun)(delim);
  1771.     while ((c = get()) != delim
  1772.          && c != '\n'
  1773.          && c != EOF_CHAR) {
  1774.         (*outfun)(c);
  1775.         if (c == '\\')
  1776.         (*outfun)(get());
  1777.     }
  1778.     instring = FALSE;
  1779.     if (c == delim) {
  1780.         (*outfun)(c);
  1781.         return (TRUE);
  1782.     }
  1783.     else {
  1784.         cerror("Unterminated string", NULLST);
  1785.         unget();
  1786.         return (FALSE);
  1787.     }
  1788. }
  1789.  
  1790. scannumber(c, outfun)
  1791. register int    c;                /* First char of number    */
  1792. register int    (*outfun)();            /* Output/store func    */
  1793. /*
  1794.  * Process a number.  We know that c is from 0 to 9 or dot.
  1795.  * Algorithm from Dave Conroy's Decus C.
  1796.  */
  1797. {
  1798.     register int    radix;            /* 8, 10, or 16        */
  1799.     int        expseen;        /* 'e' seen in floater    */
  1800.     int        signseen;        /* '+' or '-' seen    */
  1801.     int        octal89;        /* For bad octal test    */
  1802.     int        dotflag;        /* TRUE if '.' was seen    */
  1803.  
  1804.     expseen = FALSE;            /* No exponent seen yet    */
  1805.     signseen = TRUE;            /* No +/- allowed yet    */
  1806.     octal89 = FALSE;            /* No bad octal yet    */
  1807.     radix = 10;                /* Assume decimal    */
  1808.     if ((dotflag = (c == '.')) != FALSE) {    /* . something?        */
  1809.         (*outfun)('.');            /* Always out the dot    */
  1810.         if (type[(c = get())] != DIG) {    /* If not a float numb,    */
  1811.         unget();            /* Rescan strange char    */
  1812.         return;                /* All done for now    */
  1813.         }
  1814.     }                    /* End of float test    */
  1815.     else if (c == '0') {            /* Octal or hex?    */
  1816.         (*outfun)(c);            /* Stuff initial zero    */
  1817.         radix = 8;                /* Assume it's octal    */
  1818.         c = get();                /* Look for an 'x'    */
  1819.         if (c == 'x' || c == 'X') {        /* Did we get one?    */
  1820.         radix = 16;            /* Remember new radix    */
  1821.         (*outfun)(c);            /* Stuff the 'x'    */
  1822.         c = get();            /* Get next character    */
  1823.         }
  1824.     }
  1825.     for (;;) {                /* Process curr. char.    */
  1826.         /*
  1827.          * Note that this algorithm accepts "012e4" and "03.4"
  1828.          * as legitimate floating-point numbers.
  1829.          */
  1830.         if (radix != 16 && (c == 'e' || c == 'E')) {
  1831.         if (expseen)            /* Already saw 'E'?    */
  1832.             break;            /* Exit loop, bad nbr.    */
  1833.         expseen = TRUE;            /* Set exponent seen    */
  1834.         signseen = FALSE;        /* We can read '+' now    */
  1835.         radix = 10;            /* Decimal exponent    */
  1836.         }
  1837.         else if (radix != 16 && c == '.') {
  1838.         if (dotflag)            /* Saw dot already?    */
  1839.             break;            /* Exit loop, two dots    */
  1840.         dotflag = TRUE;            /* Remember the dot    */
  1841.         radix = 10;            /* Decimal fraction    */
  1842.         }
  1843.         else if (c == '+' || c == '-') {    /* 1.0e+10        */
  1844.         if (signseen)            /* Sign in wrong place?    */
  1845.             break;            /* Exit loop, not nbr.    */
  1846.         /* signseen = TRUE; */        /* Remember we saw it    */
  1847.         }
  1848.         else {                /* Check the digit    */
  1849.         switch (c) {
  1850.         case '8': case '9':        /* Sometimes wrong    */
  1851.             octal89 = TRUE;        /* Do check later    */
  1852.         case '0': case '1': case '2': case '3':
  1853.         case '4': case '5': case '6': case '7':
  1854.             break;            /* Always ok        */
  1855.  
  1856.         case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
  1857.         case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
  1858.             if (radix == 16)        /* Alpha's are ok only     */
  1859.             break;            /* if reading hex.    */
  1860.         default:            /* At number end    */
  1861.             goto done;            /* Break from for loop    */
  1862.         }                /* End of switch    */
  1863.         }                    /* End general case    */
  1864.         (*outfun)(c);            /* Accept the character    */
  1865.         signseen = TRUE;            /* Don't read sign now    */
  1866.         c = get();                /* Read another char    */
  1867.     }                    /* End of scan loop    */
  1868.     /*
  1869.      * When we break out of the scan loop, c contains the first
  1870.      * character (maybe) not in the number.  If the number is an
  1871.      * integer, allow a trailing 'L' for long and/or a trailing 'U'
  1872.      * for unsigned.  If not those, push the trailing character back
  1873.      * on the input stream.  Floating point numbers accept a trailing
  1874.      * 'L' for "long double".
  1875.      */
  1876. done:    if (dotflag || expseen) {        /* Floating point?    */
  1877.         if (c == 'l' || c == 'L') {
  1878.         (*outfun)(c);
  1879.         c = get();            /* Ungotten later    */
  1880.         }
  1881.     }
  1882.     else {                    /* Else it's an integer    */
  1883.         /*
  1884.          * We know that dotflag and expseen are both zero, now:
  1885.          * dotflag signals "saw 'L'", and
  1886.          * expseen signals "saw 'U'".
  1887.          */
  1888.         for (;;) {
  1889.         switch (c) {
  1890.         case 'l':
  1891.         case 'L':
  1892.             if (dotflag)
  1893.             goto nomore;
  1894.             dotflag = TRUE;
  1895.             break;
  1896.  
  1897.         case 'u':
  1898.         case 'U':
  1899.             if (expseen)
  1900.             goto nomore;
  1901.             expseen = TRUE;
  1902.             break;
  1903.  
  1904.         default:
  1905.             goto nomore;
  1906.         }
  1907.         (*outfun)(c);            /* Got 'L' or 'U'.    */
  1908.         c = get();            /* Look at next, too.    */
  1909.         }
  1910.     }
  1911. nomore:    unget();                /* Not part of a number    */
  1912.     if (octal89 && radix == 8)
  1913.         cwarn("Illegal digit in octal number", NULLST);
  1914. }
  1915.  
  1916. save(c)
  1917. register int    c;
  1918. {
  1919.     if (workp >= &work[NWORK])
  1920.         cfatal("Work buffer overflow", NULLST);
  1921.     else *workp++ = c;
  1922. }
  1923.  
  1924. char *
  1925. savestring(text)
  1926. char        *text;
  1927. /*
  1928.  * Store a string into free memory.
  1929.  */
  1930. {
  1931.     register char    *result;
  1932.  
  1933.     result = getmem(strlen(text) + 1);
  1934.     strcpy(result, text);
  1935.     return (result);
  1936. }
  1937.  
  1938. FILEINFO    *
  1939. getfile(bufsize, name)
  1940. int        bufsize;        /* Line or define buffer size    */
  1941. char        *name;            /* File or macro name string    */
  1942. /*
  1943.  * Common FILEINFO buffer initialization for a new file or macro.
  1944.  */
  1945. {
  1946.     register FILEINFO    *file;
  1947.     register int        size;
  1948.  
  1949.     size = strlen(name);            /* File/macro name    */
  1950.     file = (FILEINFO *) getmem(sizeof (FILEINFO) + bufsize + size);
  1951.     file->parent = infile;            /* Chain files together    */
  1952.     file->fp = NULL;            /* No file yet        */
  1953.     file->filename = savestring(name);    /* Save file/macro name    */
  1954.     file->progname = NULL;            /* No #line seen yet    */
  1955.     file->unrecur = 0;            /* No macro fixup    */
  1956.     file->bptr = file->buffer;        /* Initialize line ptr    */
  1957.     file->buffer[0] = EOS;            /* Force first read    */
  1958.     file->line = 0;                /* (Not used just yet)    */
  1959.     if (infile != NULL)            /* If #include file    */
  1960.         infile->line = line;        /* Save current line    */
  1961.     infile = file;                /* New current file    */
  1962.     line = 1;                /* Note first line    */
  1963.     return (file);                /* All done.        */
  1964. }
  1965.  
  1966. char *
  1967. getmem(size)
  1968. int        size;
  1969. /*
  1970.  * Get a block of free memory.
  1971.  */
  1972. {
  1973.     register char    *result;
  1974.     extern char    *malloc();
  1975.  
  1976.     if ((result = malloc((unsigned) size)) == NULL)
  1977.         cfatal("Out of memory", NULLST);
  1978.     return (result);
  1979. }
  1980.  
  1981. /*
  1982.  *            C P P   S y m b o l   T a b l e s
  1983.  */
  1984.  
  1985. /*
  1986.  * SBSIZE defines the number of hash-table slots for the symbol table.
  1987.  * It must be a power of 2.
  1988.  */
  1989. #ifndef    SBSIZE
  1990. #define    SBSIZE    64
  1991. #endif
  1992. #define    SBMASK    (SBSIZE - 1)
  1993. #if (SBSIZE ^ SBMASK) != ((SBSIZE * 2) - 1)
  1994.     << error, SBSIZE must be a power of 2 >>
  1995. #endif
  1996.  
  1997. static DEFBUF    *symtab[SBSIZE];    /* Symbol table queue headers    */
  1998.  
  1999. DEFBUF *
  2000. lookid(c)
  2001. int    c;                /* First character of token    */
  2002. /*
  2003.  * Look for the next token in the symbol table.  Returns token in "token".
  2004.  * If found, returns the table pointer;  Else returns NULL.
  2005.  */
  2006. {
  2007.     register int        nhash;
  2008.     register DEFBUF        *dp;
  2009.     register char        *np;
  2010.     int            temp;
  2011.     int            isrecurse;    /* For #define foo foo    */
  2012.  
  2013.     np = token;
  2014.     nhash = 0;
  2015.     if ((isrecurse = (c == DEF_MAGIC)))    /* If recursive macro    */
  2016.         c = get();                /* hack, skip DEF_MAGIC    */
  2017.     do {
  2018.         if (np < &token[IDMAX]) {        /* token dim is IDMAX+1    */
  2019.         *np++ = c;            /* Store token byte    */
  2020.         nhash += c;            /* Update hash value    */
  2021.         }
  2022.         c = get();                /* And get another byte    */
  2023.     } while (type[c] == LET || type[c] == DIG);
  2024.     unget();                /* Rescan terminator    */
  2025.     *np = EOS;                /* Terminate token    */
  2026.     if (isrecurse)                /* Recursive definition    */
  2027.         return (NULL);            /* undefined just now    */
  2028.     nhash += (np - token);            /* Fix hash value    */
  2029.     dp = symtab[nhash & SBMASK];        /* Starting bucket    */
  2030.     while (dp != (DEFBUF *) NULL) {        /* Search symbol table    */
  2031.         if (dp->hash == nhash        /* Fast precheck    */
  2032.          && (temp = strcmp(dp->name, token)) >= 0)
  2033.         break;
  2034.         dp = dp->link;            /* Nope, try next one    */
  2035.     }
  2036.     return ((temp == 0) ? dp : NULL);
  2037. }
  2038.  
  2039. DEFBUF *
  2040. defendel(name, delete)
  2041. char        *name;
  2042. int        delete;            /* TRUE to delete a symbol    */
  2043. /*
  2044.  * Enter this name in the lookup table (delete = FALSE)
  2045.  * or delete this name (delete = TRUE).
  2046.  * Returns a pointer to the define block (delete = FALSE)
  2047.  * Returns NULL if the symbol wasn't defined (delete = TRUE).
  2048.  */
  2049. {
  2050.     register DEFBUF        *dp;
  2051.     register DEFBUF        **prevp;
  2052.     register char        *np;
  2053.     int            nhash;
  2054.     int            temp;
  2055.     int            size;
  2056.  
  2057.     for (nhash = 0, np = name; *np != EOS;)
  2058.         nhash += *np++;
  2059.     size = (np - name);
  2060.     nhash += size;
  2061.     prevp = &symtab[nhash & SBMASK];
  2062.     while ((dp = *prevp) != (DEFBUF *) NULL) {
  2063.         if (dp->hash == nhash
  2064.          && (temp = strcmp(dp->name, name)) >= 0) {
  2065.         if (temp > 0)
  2066.             dp = NULL;            /* Not found        */
  2067.         else {
  2068.             *prevp = dp->link;        /* Found, unlink and    */
  2069.             if (dp->repl != NULL)    /* Free the replacement    */
  2070.             free(dp->repl);        /* if any, and then    */
  2071.             free((char *) dp);        /* Free the symbol    */
  2072.         }
  2073.         break;
  2074.         }
  2075.         prevp = &dp->link;
  2076.     }
  2077.     if (!delete) {
  2078.         dp = (DEFBUF *) getmem(sizeof (DEFBUF) + size);
  2079.         dp->link = *prevp;
  2080.         *prevp = dp;
  2081.         dp->hash = nhash;
  2082.         dp->repl = NULL;
  2083.         dp->nargs = 0;
  2084.         strcpy(dp->name, name);
  2085.     }
  2086.     return (dp);
  2087. }
  2088.  
  2089. #if DEBUG
  2090.  
  2091. dumpdef(why)
  2092. char        *why;
  2093. {
  2094.     register DEFBUF        *dp;
  2095.     register DEFBUF        **syp;
  2096.  
  2097.     printf("CPP symbol table dump %s\n", why);
  2098.     for (syp = symtab; syp < &symtab[SBSIZE]; syp++) {
  2099.         if ((dp = *syp) != (DEFBUF *) NULL) {
  2100.         printf("symtab[%d]\n", (syp - symtab));
  2101.         do {
  2102.             dumpadef((char *) NULL, dp);
  2103.         } while ((dp = dp->link) != (DEFBUF *) NULL);
  2104.         }
  2105.     }
  2106. }
  2107.  
  2108. dumpadef(why, dp)
  2109. char        *why;            /* Notation            */
  2110. register DEFBUF    *dp;
  2111. {
  2112.     register char        *cp;
  2113.     register int        c;
  2114.  
  2115.     printf(" \"%s\" [%d]", dp->name, dp->nargs);
  2116.     if (why != NULL)
  2117.         printf(" (%s)", why);
  2118.     if (dp->repl != NULL) {
  2119.         printf(" => ");
  2120.         for (cp = dp->repl; (c = *cp++ & 0xFF) != EOS;) {
  2121.         if (c >= MAC_PARM && c <= (MAC_PARM + PAR_MAC))
  2122.             printf("<%d>", c - MAC_PARM);
  2123.         else if (isprint(c) || c == '\n' || c == '\t')
  2124.             putchar(c);
  2125.         else if (c < ' ')
  2126.             printf("<^%c>", c + '@');
  2127.         else
  2128.             printf("<\\0%o>", c);
  2129.         }
  2130.     }
  2131.     else {
  2132.         printf(", no replacement.");
  2133.     }
  2134.     putchar('\n');
  2135. }
  2136. #endif
  2137.  
  2138. /*
  2139.  *            G E T
  2140.  */
  2141.  
  2142. int
  2143. get()
  2144. /*
  2145.  * Return the next character from a macro or the current file.
  2146.  * Handle end of file from #include files.
  2147.  */
  2148. {
  2149.     register int        c;
  2150.     register FILEINFO    *file;
  2151.     register int        popped;        /* Recursion fixup    */
  2152.  
  2153.     popped = 0;
  2154. get_from_file:
  2155.     if ((file = infile) == NULL)
  2156.         return (EOF_CHAR);
  2157. newline:
  2158. #if 0
  2159.     printf("get(%s), recursion %d, line %d, bptr = %d, buffer \"%s\"\n",
  2160.         file->filename, recursion, line,
  2161.         file->bptr - file->buffer, file->buffer);
  2162. #endif
  2163.     /*
  2164.      * Read a character from the current input line or macro.
  2165.      * At EOS, either finish the current macro (freeing temp.
  2166.      * storage) or read another line from the current input file.
  2167.      * At EOF, exit the current file (#include) or, at EOF from
  2168.      * the cpp input file, return EOF_CHAR to finish processing.
  2169.      */
  2170.     if ((c = *file->bptr++ & 0xFF) == EOS) {
  2171.         /*
  2172.          * Nothing in current line or macro.  Get next line (if
  2173.          * input from a file), or do end of file/macro processing.
  2174.          * In the latter case, jump back to restart from the top.
  2175.          */
  2176.         if (file->fp == NULL) {        /* NULL if macro    */
  2177.         popped++;
  2178.         recursion -= file->unrecur;
  2179.         if (recursion < 0)
  2180.             recursion = 0;
  2181.         infile = file->parent;        /* Unwind file chain    */
  2182.         }
  2183.         else {                /* Else get from a file    */
  2184.         if ((file->bptr = fgets(file->buffer, NBUFF, file->fp))
  2185.             != NULL) {
  2186. #if DEBUG
  2187.             if (debug > 1) {        /* Dump it to stdout    */
  2188.             printf("\n#line %d (%s), %s",
  2189.                 line, file->filename, file->buffer);
  2190.             }
  2191. #endif
  2192.             goto newline;        /* process the line    */
  2193.         }
  2194.         else {
  2195.             fclose(file->fp);        /* Close finished file    */
  2196.             if ((infile = file->parent) != NULL) {
  2197.             /*
  2198.              * There is an "ungotten" newline in the current
  2199.              * infile buffer (set there by doinclude() in
  2200.              * cpp1.c).  Thus, we know that the mainline code
  2201.              * is skipping over blank lines and will do a
  2202.              * #line at its convenience.
  2203.              */
  2204.             wrongline = TRUE;    /* Need a #line now    */
  2205.             }
  2206.         }
  2207.         }
  2208.         /*
  2209.          * Free up space used by the (finished) file or macro and
  2210.          * restart input from the parent file/macro, if any.
  2211.          */
  2212.         free(file->filename);        /* Free name and    */
  2213.         if (file->progname != NULL)        /* if a #line was seen,    */
  2214.         free(file->progname);        /* free it, too.    */
  2215.         free((char *) file);        /* Free file space    */
  2216.         if (infile == NULL)            /* If at end of file    */
  2217.         return (EOF_CHAR);        /* Return end of file    */
  2218.         line = infile->line;         /* Reset line number    */
  2219.         goto get_from_file;            /* Get from the top.    */
  2220.     }
  2221.     /*
  2222.      * Common processing for the new character.
  2223.      */
  2224.     if (c == DEF_MAGIC && file->fp != NULL)    /* Don't allow delete    */
  2225.         goto newline;            /* from a file        */
  2226.     if (file->parent != NULL) {        /* Macro or #include    */
  2227.         if (popped != 0)
  2228.         file->parent->unrecur += popped;
  2229.         else {
  2230.         recursion -= file->parent->unrecur;
  2231.         if (recursion < 0)
  2232.             recursion = 0;
  2233.         file->parent->unrecur = 0;
  2234.         }
  2235.     }
  2236.     if (c == '\n')                /* Maintain current    */
  2237.         ++line;                /* line counter        */
  2238.     if (instring)                /* Strings just return    */
  2239.         return (c);                /* the character.    */
  2240.     else if (c == '/') {            /* Comment?        */
  2241.         instring = TRUE;            /* So get() won't loop    */
  2242.         if ((c = get()) != '*') {        /* Next byte '*'?    */
  2243.         instring = FALSE;        /* Nope, no comment    */
  2244.         unget();            /* Push the char. back    */
  2245.         return ('/');            /* Return the slash    */
  2246.         }
  2247.         if (keepcomments) {            /* If writing comments    */
  2248.         putchar('/');            /* Write out the    */
  2249.         putchar('*');            /*   initializer    */
  2250.         }
  2251.         for (;;) {                /* Eat a comment    */
  2252.         c = get();
  2253. test:        if (keepcomments && c != EOF_CHAR)
  2254.             cput(c);
  2255.         switch (c) {
  2256.         case EOF_CHAR:
  2257.             cerror("EOF in comment", NULLST);
  2258.             return (EOF_CHAR);
  2259.  
  2260.         case '/':
  2261.             if ((c = get()) != '*')    /* Don't let comments    */
  2262.             goto test;        /* Nest.        */
  2263.             cwarn("Nested comments", NULLST);
  2264.                         /* Fall into * stuff    */
  2265.         case '*':
  2266.             if ((c = get()) != '/')    /* If comment doesn't    */
  2267.             goto test;        /* end, look at next    */
  2268.             instring = FALSE;        /* End of comment,    */
  2269.             if (keepcomments) {        /* Put out the comment    */
  2270.             cput(c);        /* terminator, too    */
  2271.             }
  2272.             /*
  2273.              * A comment is syntactically "whitespace" --
  2274.              * however, there are certain strange sequences
  2275.              * such as
  2276.              *        #define foo(x)    (something)
  2277.              *            foo|* comment *|(123)
  2278.              *       these are '/' ^           ^
  2279.              * where just returning space (or COM_SEP) will cause
  2280.              * problems.  This can be "fixed" by overwriting the
  2281.              * '/' in the input line buffer with ' ' (or COM_SEP)
  2282.              * but that may mess up an error message.
  2283.              * So, we peek ahead -- if the next character is
  2284.              * "whitespace" we just get another character, if not,
  2285.              * we modify the buffer.  All in the name of purity.
  2286.              */
  2287.             if (*file->bptr == '\n'
  2288.              || type[*file->bptr & 0xFF] == SPA)
  2289.             goto newline;
  2290. #if COMMENT_INVISIBLE
  2291.             /*
  2292.              * Return magic (old-fashioned) syntactic space.
  2293.              */
  2294.             return ((file->bptr[-1] = COM_SEP));
  2295. #else
  2296.             return ((file->bptr[-1] = ' '));
  2297. #endif
  2298.  
  2299.         case '\n':            /* we'll need a #line    */
  2300.             if (!keepcomments)
  2301.             wrongline = TRUE;    /* later...        */
  2302.         default:            /* Anything else is    */
  2303.             break;            /* Just a character    */
  2304.         }                /* End switch        */
  2305.         }                    /* End comment loop    */
  2306.     }                    /* End if in comment    */
  2307.     else if (!inmacro && c == '\\') {    /* If backslash, peek     */
  2308.         if ((c = get()) == '\n') {        /* for a <nl>.  If so,    */
  2309.         wrongline = TRUE;
  2310.         goto newline;
  2311.         }
  2312.         else {                /* Backslash anything    */
  2313.         unget();            /* Get it later        */
  2314.         return ('\\');            /* Return the backslash    */
  2315.         }
  2316.     }
  2317.     else if (c == '\f' || c == VT)        /* Form Feed, Vertical    */
  2318.         c = ' ';                /* Tab are whitespace    */
  2319.     return (c);                /* Just return the char    */
  2320. }
  2321.  
  2322. unget()
  2323. /*
  2324.  * Backup the pointer to reread the last character.  Fatal error
  2325.  * (code bug) if we backup too far.  unget() may be called,
  2326.  * without problems, at end of file.  Only one character may
  2327.  * be ungotten.  If you need to unget more, call ungetstring().
  2328.  */
  2329. {
  2330.     register FILEINFO    *file;
  2331.  
  2332.     if ((file = infile) == NULL)
  2333.         return;            /* Unget after EOF        */
  2334.     if (--file->bptr < file->buffer)
  2335.         cfatal("Too much pushback", NULLST);
  2336.     if (*file->bptr == '\n')    /* Ungetting a newline?        */
  2337.         --line;            /* Unget the line number, too    */
  2338. }
  2339.  
  2340. ungetstring(text)
  2341. char        *text;
  2342. /*
  2343.  * Push a string back on the input stream.  This is done by treating
  2344.  * the text as if it were a macro.
  2345.  */
  2346. {
  2347.     register FILEINFO    *file;
  2348.     extern FILEINFO        *getfile();
  2349.  
  2350.     file = getfile(strlen(text) + 1, "");
  2351.     strcpy(file->buffer, text);
  2352. }
  2353.  
  2354. int
  2355. cget()
  2356. /*
  2357.  * Get one character, absorb "funny space" after comments or
  2358.  * token concatenation
  2359.  */
  2360. {
  2361.     register int    c;
  2362.  
  2363.     do {
  2364.         c = get();
  2365. #if COMMENT_INVISIBLE
  2366.     } while (c == TOK_SEP || c == COM_SEP);
  2367. #else
  2368.     } while (c == TOK_SEP);
  2369. #endif
  2370.     return (c);
  2371. }
  2372.  
  2373. /*
  2374.  * Error messages and other hacks.  The first byte of severity
  2375.  * is 'S' for string arguments and 'I' for int arguments.  This
  2376.  * is needed for portability with machines that have int's that
  2377.  * are shorter than  char *'s.
  2378.  */
  2379.  
  2380. static
  2381. domsg(severity, format, arg)
  2382. char        *severity;        /* "Error", "Warning", "Fatal"    */
  2383. char        *format;        /* Format for the error message    */
  2384. char        *arg;            /* Something for the message    */
  2385. /*
  2386.  * Print filenames, macro names, and line numbers for error messages.
  2387.  */
  2388. {
  2389.     register char        *tp;
  2390.     register FILEINFO    *file;
  2391.  
  2392.     fprintf(stderr, "%sline %d, %s: ", MSG_PREFIX, line, &severity[1]);
  2393.     if (*severity == 'S')
  2394.         fprintf(stderr, format, arg);
  2395.     else
  2396.         fprintf(stderr, format, (int) arg);
  2397.     putc('\n', stderr);
  2398.     if ((file = infile) == NULL)
  2399.         return;                /* At end of file    */
  2400.     if (file->fp != NULL) {
  2401.         tp = file->buffer;            /* Print current file    */
  2402.         fprintf(stderr, "%s", tp);        /* name, making sure    */
  2403.         if (tp[strlen(tp) - 1] != '\n')    /* there's a newline    */
  2404.         putc('\n', stderr);
  2405.     }
  2406.     while ((file = file->parent) != NULL) {    /* Print #includes, too    */
  2407.         if (file->fp == NULL)
  2408.         fprintf(stderr, "from macro %s\n", file->filename);
  2409.         else {
  2410.         tp = file->buffer;
  2411.         fprintf(stderr, "from file %s, line %d:\n%s",
  2412.             (file->progname != NULL)
  2413.             ? file->progname : file->filename,
  2414.             file->line, tp);
  2415.         if (tp[strlen(tp) - 1] != '\n')
  2416.             putc('\n', stderr);
  2417.         }
  2418.     }
  2419. }
  2420.  
  2421. cerror(format, sarg)
  2422. char        *format;
  2423. char        *sarg;        /* Single string argument        */
  2424. /*
  2425.  * Print a normal error message, string argument.
  2426.  */
  2427. {
  2428.     domsg("SError", format, sarg);
  2429.     errors++;
  2430. }
  2431.  
  2432. cierror(format, narg)
  2433. char        *format;
  2434. int        narg;        /* Single numeric argument        */
  2435. /*
  2436.  * Print a normal error message, numeric argument.
  2437.  */
  2438. {
  2439.     domsg("IError", format, (char *) narg);
  2440.     errors++;
  2441. }
  2442.  
  2443. cfatal(format, sarg)
  2444. char        *format;
  2445. char        *sarg;            /* Single string argument    */
  2446. /*
  2447.  * A real disaster
  2448.  */
  2449. {
  2450.     domsg("SFatal error", format, sarg);
  2451.     exit(IO_ERROR);
  2452. }
  2453.  
  2454. cwarn(format, sarg)
  2455. char        *format;
  2456. char        *sarg;            /* Single string argument    */
  2457. /*
  2458.  * A non-fatal error, string argument.
  2459.  */
  2460. {
  2461.     domsg("SWarning", format, sarg);
  2462. }
  2463.  
  2464. ciwarn(format, narg)
  2465. char        *format;
  2466. int        narg;            /* Single numeric argument    */
  2467. /*
  2468.  * A non-fatal error, numeric argument.
  2469.  */
  2470. {
  2471.     domsg("IWarning", format, (char *) narg);
  2472. }
  2473.  
  2474.  
  2475.  
  2476.