home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 342b.lha / cpp / Cpp4.c < prev    next >
C/C++ Source or Header  |  1990-01-26  |  20KB  |  676 lines

  1. /*
  2.  *                C P P 4 . C
  3.  *        M a c r o  D e f i n i t i o n s
  4.  *
  5.  * Edit History
  6.  * 31-Aug-84    MM    USENET net.sources release
  7.  * 04-Oct-84    MM    __LINE__ and __FILE__ must call ungetstring()
  8.  *            so they work correctly with token concatenation.
  9.  *            Added string formal recognition.
  10.  * 25-Oct-84    MM    "Short-circuit" evaluate #if's so that we
  11.  *            don't print unnecessary error messages for
  12.  *            #if !defined(FOO) && FOO != 0 && 10 / FOO ...
  13.  * 31-Oct-84    ado/MM    Added token concatenation
  14.  *  6-Nov-84    MM    Split off eval stuff
  15.  * 21-Oct-85    RMS    Rename `token' to `tokenbuf'.
  16.  *            In doundef, don't complain if arg already not defined.
  17.  * 14-Mar-86    FNF    Incorporate macro based C debugging package.
  18.  *            Port to Commodore AMIGA.
  19.  * 21-Aug-88    Ois    Changed concatenation operator to ##. Changed hand-
  20.  *            ling of tokens following ##. Added new meaning of #.
  21.  */
  22.  
  23. #include    <stdio.h>
  24. #include    <ctype.h>
  25. #include    "cppdef.h"
  26. #include    "cpp.h"
  27. /*
  28.  * parm[], parmp, and parlist[] are used to store #define() argument
  29.  * lists.  nargs contains the actual number of parameters stored.
  30.  */
  31. static char    parm[NPARMWORK + 1];    /* define param work buffer    */
  32. static char    *parmp;         /* Free space in parm        */
  33. static char    *parlist[LASTPARM];    /* -> start of each parameter    */
  34. static int    nargs;            /* Parameters for this macro    */
  35.  
  36. dodefine()
  37. /*
  38.  * Called from control when a #define is scanned.  This module
  39.  * parses formal parameters and the replacement string.  When
  40.  * the formal parameter name is encountered in the replacement
  41.  * string, it is replaced by a character in the range 128 to
  42.  * 128+NPARAM (this allows up to 32 parameters within the
  43.  * Dec Multinational range).  If cpp is ported to an EBCDIC
  44.  * machine, you will have to make other arrangements.
  45.  *
  46.  * There is some special case code to distinguish
  47.  *    #define foo    bar
  48.  * from #define foo()   bar
  49.  *
  50.  * Also, we make sure that
  51.  *    #define foo    foo
  52.  * expands to "foo" but doesn't put cpp into an infinite loop.
  53.  *
  54.  * A warning message is printed if you redefine a symbol to a
  55.  * different text.  I.e,
  56.  *    #define foo    123
  57.  *    #define foo    123
  58.  * is ok, but
  59.  *    #define foo    123
  60.  *    #define foo    +123
  61.  * is not.
  62.  *
  63.  * The following subroutines are called from define():
  64.  * checkparm    called when a token is scanned.  It checks through the
  65.  *        array of formal parameters.  If a match is found, the
  66.  *        token is replaced by a control byte which will be used
  67.  *        to locate the parameter when the macro is expanded.
  68.  * textput    puts a string in the macro work area (parm[]), updating
  69.  *        parmp to point to the first free byte in parm[].
  70.  *        textput() tests for work buffer overflow.
  71.  * charput    puts a single character in the macro work area (parm[])
  72.  *        in a manner analogous to textput().
  73.  */
  74. {
  75.     register int        c;
  76.     register DEFBUF     *dp;        /* -> new definition    */
  77.     int            isredefine;    /* TRUE if redefined    */
  78.     char            *old;        /* Remember redefined    */
  79. #if OK_CONCAT
  80.     register int        quoting;    /* Remember we saw a #    */
  81. #endif
  82.     extern int        save();         /* Save char in work[]  */
  83.  
  84.     DBUG_ENTER ("dodefine");
  85.     if (type[(c = skipws())] != LET)
  86.         goto bad_define;
  87.     isredefine = FALSE;            /* Set if redefining    */
  88.     if ((dp = lookid(c)) == NULL)           /* If not known now     */
  89.         dp = defendel(tokenbuf, FALSE);     /* Save the name        */
  90.     else {                    /* It's known:          */
  91.         isredefine = TRUE;            /* Remember this fact    */
  92.         old = dp->repl;            /* Remember replacement */
  93.         dp->repl = NULL;            /* No replacement now    */
  94.     }
  95.     parlist[0] = parmp = parm;        /* Setup parm buffer    */
  96.     if ((c = get()) == '(') {               /* With arguments?      */
  97.         nargs = 0;                /* Init formals counter */
  98.         do {                /* Collect formal parms */
  99.         if (nargs >= LASTPARM)
  100.             cfatal("Too many arguments for macro", NULLST);
  101.         else if ((c = skipws()) == ')')
  102.             break;            /* Got them all     */
  103.         else if (type[c] != LET)        /* Bad formal syntax    */
  104.             goto bad_define;
  105.         scanid(c);                      /* Get the formal param */
  106.         parlist[nargs++] = parmp;    /* Save its start    */
  107.         textput(tokenbuf);              /* Save text in parm[]  */
  108.         } while ((c = skipws()) == ',');    /* Get another argument */
  109.         if (c != ')')                       /* Must end at )        */
  110.         goto bad_define;
  111.         c = ' ';                            /* Will skip to body    */
  112.     }
  113.     else {
  114.         /*
  115.          * DEF_NOARGS is needed to distinguish between
  116.          * "#define foo" and "#define foo()".
  117.          */
  118.         nargs = DEF_NOARGS;         /* No () parameters     */
  119.     }
  120.     if (type[c] == SPA)                     /* At whitespace?       */
  121.         c = skipws();                       /* Not any more.        */
  122.     workp = work;                /* Replacement put here */
  123.     inmacro = TRUE;             /* Keep \<newline> now    */
  124.     quoting = 0;                /* No # seen yet.    */
  125.     while (c != EOF_CHAR && c != '\n') {    /* Compile macro body   */
  126. #if OK_CONCAT
  127.         if (c == '#') {                     /* Token concatenation? */
  128.         if ((c = get()) != '#') {       /* No, not really       */
  129.             quoting = 1;        /* Maybe quoting op.    */
  130.             continue;
  131.         }
  132.         while (workp > work && type[workp[-1]] == SPA)
  133.             --workp;            /* Erase leading spaces */
  134.         save(TOK_SEP);                  /* Stuff a delimiter    */
  135.         c = skipws();                   /* Eat whitespace       */
  136. #if 0
  137.         if (type[c] == LET)             /* Another token here?  */
  138.             ;                /* Stuff it normally    */
  139.         else if (type[c] == DIG) {      /* Digit string after?  */
  140.             while (type[c] == DIG) {    /* Stuff the digits     */
  141.             save(c);                /* Note
  142.             c = get();
  143.             }
  144.             save(TOK_SEP);              /* Delimit 2nd token    */
  145.         }
  146.         else {
  147.             ciwarn("Strange character after ## (%d.)", c);
  148.         }
  149. #endif
  150.         continue;
  151.         }
  152. #endif
  153.         switch (type[c]) {
  154.         case LET:
  155. #if OK_CONCAT
  156.         checkparm(c, dp, quoting);      /* Might be a formal    */
  157. #else
  158.         checkparm(c, dp);               /* Might be a formal    */
  159. #endif
  160.         break;
  161.  
  162.         case DIG:                /* Number in mac. body    */
  163.         case DOT:                /* Maybe a float number */
  164.         scannumber(c, save);            /* Scan it off          */
  165.         break;
  166.  
  167.         case QUO:                /* String in mac. body    */
  168. #if STRING_FORMAL
  169.         stparmscan(c, dp);              /* Do string magic      */
  170. #else
  171.         stparmscan(c);
  172. #endif
  173.         break;
  174.  
  175.         case BSH:                /* Backslash        */
  176.         save('\\');
  177.         if ((c = get()) == '\n')
  178.             wrongline = TRUE;
  179.         save(c);
  180.         break;
  181.  
  182.         case SPA:                /* Absorb whitespace    */
  183.         /*
  184.          * Note: the "end of comment" marker is passed on
  185.          * to allow comments to separate tokens.
  186.          */
  187.         if (workp[-1] == ' ')           /* Absorb multiple      */
  188.             break;            /* spaces        */
  189.         else if (c == '\t')
  190.             c = ' ';                    /* Normalize tabs       */
  191.         /* Fall through to store character            */
  192.         default:                /* Other character    */
  193.         save(c);
  194.         break;
  195.         }
  196.         c = get();
  197.         quoting = 0;            /* Only when immediately*/
  198.                         /* preceding a formal    */
  199.     }
  200.     inmacro = FALSE;            /* Stop newline hack    */
  201.     unget();                                /* For control check    */
  202.     if (workp > work && workp[-1] == ' ')   /* Drop trailing blank  */
  203.         workp--;
  204.     *workp = EOS;                /* Terminate work    */
  205.     dp->repl = savestring(work);            /* Save the string      */
  206.     dp->nargs = nargs;            /* Save arg count    */
  207. #if DEBUG
  208.     if (debug)
  209.         dumpadef("macro definition", dp);
  210. #endif
  211.     if (isredefine) {                       /* Error if redefined   */
  212.         if ((old != NULL && dp->repl != NULL && !streq(old, dp->repl))
  213.          || (old == NULL && dp->repl != NULL)
  214.          || (old != NULL && dp->repl == NULL)) {
  215.         cerror("Redefining defined variable \"%s\"", dp->name);
  216.         }
  217.         if (old != NULL)                    /* We don't need the    */
  218.         free(old);                      /* old definition now.  */
  219.     }
  220.     DBUG_VOID_RETURN;
  221.  
  222. bad_define:
  223.     cerror("#define syntax error", NULLST);
  224.     inmacro = FALSE;            /* Stop <newline> hack    */
  225.     DBUG_VOID_RETURN;
  226. }
  227.  
  228. checkparm(c, dp, quoting)
  229. register int    c;
  230. DEFBUF        *dp;
  231. int        quoting;            /* Preceded by a # ?    */
  232. /*
  233.  * Replace this param if it's defined.  Note that the macro name is a
  234.  * possible replacement token.    We stuff DEF_MAGIC in front of the token
  235.  * which is treated as a LETTER by the token scanner and eaten by
  236.  * the output routine.    This prevents the macro expander from
  237.  * looping if someone writes "#define foo foo".
  238.  */
  239. {
  240.     register int        i;
  241.     register char        *cp;
  242.  
  243.     DBUG_ENTER ("checkparm");
  244.     scanid(c);                              /* Get parm to tokenbuf */
  245.     for (i = 0; i < nargs; i++) {           /* For each argument    */
  246.         if (streq(parlist[i], tokenbuf)) {  /* If it's known        */
  247. #if OK_CONCAT
  248.         if (quoting)                    /* Special handling of  */
  249.             save(QUOTE_PARM);           /* #formal inside defn  */
  250. #endif
  251.         save(i + MAC_PARM);             /* Save a magic cookie  */
  252.         DBUG_VOID_RETURN;        /* And exit the search    */
  253.         }
  254.     }
  255.     if (streq(dp->name, tokenbuf))          /* Macro name in body?  */
  256.         save(DEF_MAGIC);                    /* Save magic marker    */
  257.     for (cp = tokenbuf; *cp != EOS;)        /* And save             */
  258.         save(*cp++);                        /* The token itself     */
  259.     DBUG_VOID_RETURN;
  260. }
  261.  
  262. #if STRING_FORMAL
  263. stparmscan(delim, dp)
  264. int        delim;
  265. register DEFBUF *dp;
  266. /*
  267.  * Scan the string (starting with the given delimiter).
  268.  * The token is replaced if it is the only text in this string or
  269.  * character constant.    The algorithm follows checkparm() above.
  270.  * Note that scanstring() has approved of the string.
  271.  */
  272. {
  273.     register int        c;
  274.  
  275.     DBUG_ENTER ("stparmscan");
  276.     /*
  277.      * Warning -- this code hasn't been tested for a while.
  278.      * It exists only to preserve compatibility with earlier
  279.      * implementations of cpp.  It is not part of the Draft
  280.      * ANSI Standard C language.
  281.      */
  282.     save(delim);
  283.     instring = TRUE;
  284.     while ((c = get()) != delim
  285.          && c != '\n'
  286.          && c != EOF_CHAR) {
  287.         if (type[c] == LET)                 /* Maybe formal parm    */
  288.         checkparm(c, dp, 0);
  289.         else {
  290.         save(c);
  291.         if (c == '\\')
  292.             save(get());
  293.         }
  294.     }
  295.     instring = FALSE;
  296.     if (c != delim)
  297.         cerror("Unterminated string in macro body", NULLST);
  298.     save(c);
  299.     DBUG_VOID_RETURN;
  300. }
  301. #else
  302. stparmscan(delim)
  303. int        delim;
  304. /*
  305.  * Normal string parameter scan.
  306.  */
  307. {
  308.     register char        *wp;
  309.     register int        i;
  310.     extern int        save();
  311.  
  312.     DBUG_ENTER ("stparmscan");
  313.     wp = workp;            /* Here's where it starts       */
  314.     if (!scanstring(delim, save))
  315.         DBUG_VOID_RETURN;        /* Exit on scanstring error    */
  316.     workp[-1] = EOS;        /* Erase trailing quote     */
  317.     wp++;                /* -> first string content byte */
  318.     for (i = 0; i < nargs; i++) {
  319.         if (streq(parlist[i], wp)) {
  320.         *wp++ = MAC_PARM + PAR_MAC;    /* Stuff a magic marker */
  321.         *wp++ = (i + MAC_PARM);         /* Make a formal marker */
  322.         *wp = wp[-3];            /* Add on closing quote */
  323.         workp = wp + 1;         /* Reset string end    */
  324.         DBUG_VOID_RETURN;
  325.         }
  326.     }
  327.     workp[-1] = wp[-1];        /* Nope, reset end quote.    */
  328.     DBUG_VOID_RETURN;
  329. }
  330. #endif
  331.  
  332. doundef()
  333. /*
  334.  * Remove the symbol from the defined list.
  335.  * Called from the #control processor.
  336.  */
  337. {
  338.   register int c;
  339.  
  340.   DBUG_ENTER ("doundef");
  341.   if (type[(c = skipws())] != LET)
  342.     cerror("Illegal #undef argument", NULLST);
  343.   else
  344.     {
  345.       scanid(c);                                /* Get name to tokenbuf */
  346.       (void) defendel(tokenbuf, TRUE);
  347.     }
  348.   DBUG_VOID_RETURN;
  349. }
  350.  
  351. textput(text)
  352. char        *text;
  353. /*
  354.  * Put the string in the parm[] buffer.
  355.  */
  356. {
  357.     register int    size;
  358.  
  359.     DBUG_ENTER ("textput");
  360.     size = strlen(text) + 1;
  361.     if ((parmp + size) >= &parm[NPARMWORK])
  362.         cfatal("Macro work area overflow", NULLST);
  363.     else {
  364.         strcpy(parmp, text);
  365.         parmp += size;
  366.     }
  367.     DBUG_VOID_RETURN;
  368. }
  369.  
  370. charput(c)
  371. register int    c;
  372. /*
  373.  * Put the byte in the parm[] buffer.
  374.  */
  375. {
  376.     if (parmp >= &parm[NPARMWORK])
  377.         cfatal("Macro work area overflow", NULLST);
  378.     else {
  379.         *parmp++ = c;
  380.     }
  381. }
  382.  
  383. /*
  384.  *        M a c r o   E x p a n s i o n
  385.  */
  386.  
  387. static DEFBUF    *macro;     /* Catches start of infinite macro    */
  388.  
  389. expand(tokenp)
  390. register DEFBUF *tokenp;
  391. /*
  392.  * Expand a macro.  Called from the cpp mainline routine (via subroutine
  393.  * macroid()) when a token is found in the symbol table.  It calls
  394.  * expcollect() to parse actual parameters, checking for the correct number.
  395.  * It then creates a "file" containing a single line containing the
  396.  * macro with actual parameters inserted appropriately.  This is
  397.  * "pushed back" onto the input stream.  (When the get() routine runs
  398.  * off the end of the macro line, it will dismiss the macro itself.)
  399.  */
  400. {
  401.     register int        c;
  402.     register FILEINFO    *file;
  403.     extern FILEINFO     *getfile();
  404.  
  405.     DBUG_ENTER ("expand");
  406. #if DEBUG
  407.     if (debug)
  408.         dumpadef("expand entry", tokenp);
  409. #endif
  410.     /*
  411.      * If no macro is pending, save the name of this macro
  412.      * for an eventual error message.
  413.      */
  414.     if (recursion++ == 0)
  415.         macro = tokenp;
  416.     else if (recursion == RECURSION_LIMIT) {
  417.         cerror("Recursive macro definition of \"%s\"", tokenp->name);
  418.         fprintf(stderr, "(Defined by \"%s\")\n", macro->name);
  419.         if (rec_recover) {
  420.         do {
  421.             c = get();
  422.         } while (infile != NULL && infile->fp == NULL);
  423.         unget();
  424.         recursion = 0;
  425.         DBUG_VOID_RETURN;
  426.         }
  427.     }
  428.     /*
  429.      * Here's a macro to expand.
  430.      */
  431.     nargs = 0;                /* Formals counter    */
  432.     parmp = parm;                /* Setup parm buffer    */
  433.     switch (tokenp->nargs) {
  434.     case (-2):                              /* __LINE__             */
  435.         sprintf(work, "%d", line);
  436.         ungetstring(work);
  437.         break;
  438.  
  439.     case (-3):                              /* __FILE__             */
  440.         for (file = infile; file != NULL; file = file->parent) {
  441.         if (file->fp != NULL) {
  442.             sprintf(work, "\"%s\"", (file->progname != NULL)
  443.             ? file->progname : file->filename);
  444.             ungetstring(work);
  445.             break;
  446.         }
  447.         }
  448.         break;
  449.  
  450.     default:
  451.         /*
  452.          * Nothing funny about this macro.
  453.          */
  454.         if (tokenp->nargs < 0)
  455.         cfatal("Bug: Illegal __ macro \"%s\"", tokenp->name);
  456.         while ((c = skipws()) == '\n')      /* Look for (, skipping */
  457.         wrongline = TRUE;        /* spaces and newlines    */
  458.         if (c != '(') {
  459.         /*
  460.          * If the programmer writes
  461.          *    #define foo() ...
  462.          *    ...
  463.          *    foo [no ()]
  464.          * just write foo to the output stream.
  465.          */
  466.         unget();
  467.         cwarn("Macro \"%s\" needs arguments", tokenp->name);
  468.         fputs(tokenp->name, stdout);
  469.         DBUG_VOID_RETURN;
  470.         }
  471.         else if (expcollect()) {            /* Collect arguments    */
  472.         if (tokenp->nargs != nargs) {   /* Should be an error?  */
  473.             cwarn("Wrong number of macro arguments for \"%s\"",
  474.             tokenp->name);
  475.         }
  476. #if DEBUG
  477.         if (debug)
  478.             dumpparm("expand");
  479. #endif
  480.         }                /* Collect arguments        */
  481.     case DEF_NOARGS:        /* No parameters just stuffs    */
  482.         expstuff(tokenp);           /* Do actual parameters         */
  483.     }                /* nargs switch         */
  484.     DBUG_VOID_RETURN;
  485. }
  486.  
  487. FILE_LOCAL int
  488. expcollect()
  489. /*
  490.  * Collect the actual parameters for this macro.  TRUE if ok.
  491.  */
  492. {
  493.     register int    c;
  494.     register int    paren;            /* For embedded ()'s    */
  495.     extern int    charput();
  496.  
  497.     DBUG_ENTER ("expcollect");
  498.     for (;;) {
  499.         paren = 0;                /* Collect next arg.    */
  500.         while ((c = skipws()) == '\n')      /* Skip over whitespace */
  501.         wrongline = TRUE;        /* and newlines.    */
  502.         if (c == ')') {                     /* At end of all args?  */
  503.         /*
  504.          * Note that there is a guard byte in parm[]
  505.          * so we don't have to check for overflow here.
  506.          */
  507.         *parmp = EOS;            /* Make sure terminated */
  508.         break;                /* Exit collection loop */
  509.         }
  510.         else if (nargs >= LASTPARM)
  511.         cfatal("Too many arguments in macro expansion", NULLST);
  512.         parlist[nargs++] = parmp;        /* At start of new arg    */
  513.         for (;; c = cget()) {               /* Collect arg's bytes  */
  514.         if (c == EOF_CHAR) {
  515.             cerror("end of file within macro argument", NULLST);
  516.             DBUG_RETURN (FALSE);                /* Sorry.               */
  517.         }
  518.         else if (c == '\\') {           /* Quote next character */
  519.             charput(c);                 /* Save the \ for later */
  520.             charput(cget());            /* Save the next char.  */
  521.             continue;            /* And go get another    */
  522.         }
  523.         else if (type[c] == QUO) {      /* Start of string?     */
  524.             scanstring(c, charput);     /* Scan it off          */
  525.             continue;            /* Go get next char    */
  526.         }
  527.         else if (c == '(')              /* Worry about balance  */
  528.             paren++;            /* To know about commas */
  529.         else if (c == ')') {            /* Other side too       */
  530.             if (paren == 0) {           /* At the end?          */
  531.             unget();                /* Look at it later     */
  532.             break;            /* Exit arg getter.    */
  533.             }
  534.             paren--;            /* More to come.    */
  535.         }
  536.         else if (c == ',' && paren == 0) /* Comma delimits args */
  537.             break;
  538.         else if (c == '\n')             /* Newline inside arg?  */
  539.             wrongline = TRUE;        /* We'll need a #line   */
  540.         charput(c);                     /* Store this one       */
  541.         }                    /* Collect an argument    */
  542.         charput(EOS);                       /* Terminate argument   */
  543. #if DEBUG
  544.         if (debug)
  545.         printf("parm[%d] = \"%s\"\n", nargs, parlist[nargs - 1]);
  546. #endif
  547.     }                    /* Collect all args.    */
  548.     DBUG_RETURN (TRUE);                     /* Normal return        */
  549. }
  550.  
  551.  
  552. #if OK_CONCAT
  553.  
  554. FILE_LOCAL
  555. char *doquoting(to, from)
  556. register char *to;
  557. register char *from;
  558. {
  559.     *to++ = '"';
  560.     while (*from) {
  561.     if (*from == '\\' || *from == '"')
  562.         *to++ = '\\';
  563.     *to++ = *from++;
  564.     }
  565.     *to++ = '"';
  566.  
  567.     return to;
  568. }
  569.  
  570. #endif
  571.  
  572. FILE_LOCAL
  573. expstuff(tokenp)
  574. DEFBUF        *tokenp;        /* Current macro being expanded */
  575. /*
  576.  * Stuff the macro body, replacing formal parameters by actual parameters.
  577.  */
  578. {
  579.     register int    c;            /* Current character    */
  580.     register char    *inp;            /* -> repl string    */
  581.     register char    *defp;            /* -> macro output buff */
  582.     int        size;            /* Actual parm. size    */
  583.     char        *defend;        /* -> output buff end    */
  584.     int        string_magic;        /* String formal hack    */
  585.     FILEINFO    *file;            /* Funny #include    */
  586. #if OK_CONCAT
  587.     register char         quoting;    /* Quote macro argument */
  588. #endif
  589.     extern FILEINFO *getfile();
  590.  
  591.     DBUG_ENTER ("expstuff");
  592.     file = getfile(NBUFF, tokenp->name);
  593.     inp = tokenp->repl;            /* -> macro replacement */
  594.     defp = file->buffer;            /* -> output buffer    */
  595.     defend = defp + (NBUFF - 1);            /* Note its end         */
  596.     if (inp != NULL) {
  597.         quoting = 0;
  598.         while ((c = (*inp++ & 0xFF)) != EOS) {
  599. #if OK_CONCAT
  600.         if (c == QUOTE_PARM) {          /* Special token for #  */
  601.             quoting = 1;        /* set flag, for later    */
  602.             continue;            /* Get next character    */
  603.         }
  604. #endif
  605.         if (c >= MAC_PARM && c <= (MAC_PARM + PAR_MAC)) {
  606.             string_magic = (c == (MAC_PARM + PAR_MAC));
  607.             if (string_magic)
  608.             c = (*inp++ & 0xFF);
  609.             /*
  610.              * Replace formal parameter by actual parameter string.
  611.              */
  612.             if ((c -= MAC_PARM) < nargs) {
  613.             size = strlen(parlist[c]);
  614. #if OK_CONCAT
  615.             if (quoting) {
  616.                 size++;
  617.                 size *= 2;        /* worst case condition */
  618.             }
  619. #endif
  620.             if ((defp + size) >= defend)
  621.                 goto nospace;
  622.             /*
  623.              * Erase the extra set of quotes.
  624.              */
  625.             if (string_magic && defp[-1] == parlist[c][0]) {
  626.                 strcpy(defp-1, parlist[c]);
  627.                 defp += (size - 2);
  628.             }
  629. #if OK_CONCAT
  630.             else if (quoting)
  631.                 defp = doquoting(defp, parlist[c]);
  632. #endif
  633.             else {
  634.                 strcpy(defp, parlist[c]);
  635.                 defp += size;
  636.             }
  637.             }
  638.         }
  639.         else if (defp >= defend) {
  640. nospace:        cfatal("Out of space in macro \"%s\" arg expansion",
  641.             tokenp->name);
  642.         }
  643.         else {
  644.             *defp++ = c;
  645.         }
  646.         quoting = 0;
  647.         }
  648.     }
  649.     *defp = EOS;
  650. #if DEBUG
  651.     if (debug > 1)
  652.         printf("macroline: \"%s\"\n", file->buffer);
  653. #endif
  654.     DBUG_VOID_RETURN;
  655. }
  656.  
  657. #if DEBUG
  658. dumpparm(why)
  659. char        *why;
  660. /*
  661.  * Dump parameter list.
  662.  */
  663. {
  664.     register int    i;
  665.  
  666.     DBUG_ENTER ("dumpparm");
  667.     printf("dump of %d parameters (%d bytes total) %s\n",
  668.         nargs, parmp - parm, why);
  669.     for (i = 0; i < nargs; i++) {
  670.         printf("parm[%d] (%d) = \"%s\"\n",
  671.         i + 1, strlen(parlist[i]), parlist[i]);
  672.     }
  673.     DBUG_VOID_RETURN;
  674. }
  675. #endif
  676.