URI:
       cc1: Unify copies in getdefs() - scc - simple c99 compiler
  HTML git clone git://git.simple-cc.org/scc
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
   DIR commit a8aff41b8b4d91534abe9a039681fdb2ca7a0399
   DIR parent 21863f4266b66c813746b9380b19d27c7c5d9c68
  HTML Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
       Date:   Wed,  8 Apr 2026 16:13:42 +0200
       
       cc1: Unify copies in getdefs()
       
       Getdefs() has to copy the definition of the macro from different places
       and the code was using a if for it, but we can just use a variable to
       unify all the copies.
       
       Diffstat:
         M src/cmd/scc-cc/cc1/cpp.c            |      19 ++++++++-----------
       
       1 file changed, 8 insertions(+), 11 deletions(-)
       ---
   DIR diff --git a/src/cmd/scc-cc/cc1/cpp.c b/src/cmd/scc-cc/cc1/cpp.c
       @@ -565,10 +565,9 @@ getpars(Symbol *args[NR_MACROARG])
        static int
        getdefs(Symbol *args[NR_MACROARG], int nargs, char *buffer, size_t bufsiz)
        {
       -        size_t len;
       -        char *bp, *p;
       +        char c, *bp, *s, *p;
                Symbol **argp, *sym;
       -        int c, id, token, prevc, ispar;
       +        int len, id, token, prevc, ispar;
        
                while (isspace(*input->p))
                        ++input->p;
       @@ -577,15 +576,16 @@ getdefs(Symbol *args[NR_MACROARG], int nargs, char *buffer, size_t bufsiz)
                for (prevc = 0; (c = *input->p) != '\n' && c != '\0'; ++input->p) {
                        len = 1;
                        ispar = 0;
       +                s = &c;
                        token = c;
                        sym = NULL;
        
                        if (c == '#') {
                                if (input->p[1] == '#') {
       -                                token = CONCAT;
       +                                c = token = CONCAT;
                                        ++input->p;
                                } else {
       -                                token = STRINGIZE;
       +                                c = token = STRINGIZE;
                                }
                        } else if (c == '_' || isalpha(c)) {
                                token = IDEN;
       @@ -596,7 +596,7 @@ getdefs(Symbol *args[NR_MACROARG], int nargs, char *buffer, size_t bufsiz)
                                        cpperror("identifier too long in macro definition");
                                        return 0;
                                }
       -                        memcpy(yytext, input->p, len);
       +                        s = memcpy(yytext, input->p, len);
                                yytext[len] = '\0';
                                yylen = len;
                                input->p = p - 1;
       @@ -605,6 +605,7 @@ getdefs(Symbol *args[NR_MACROARG], int nargs, char *buffer, size_t bufsiz)
                                next();
                                assert(yytoken == STRING || yytoken == CONSTANT);
                                token = yytoken;
       +                        s = yytext;
                                len = yylen;
                        }
        
       @@ -635,11 +636,7 @@ getdefs(Symbol *args[NR_MACROARG], int nargs, char *buffer, size_t bufsiz)
                                return 0;
                        }
        
       -                if (token == IDEN || token == STRING || token == CONSTANT)
       -                        memcpy(bp, yytext, yylen);
       -                else
       -                        *bp = token;
       -
       +                memcpy(bp, s, len);
                        bp += len;
                        bufsiz -= len;
                        prevc = token;