Fix small bug: space following a replacement list was included in the list
authorceriel <none@none>
Tue, 26 Jan 1993 11:49:23 +0000 (11:49 +0000)
committerceriel <none@none>
Tue, 26 Jan 1993 11:49:23 +0000 (11:49 +0000)
lang/cem/cpp.ansi/domacro.c

index 633066f..802ad6f 100644 (file)
@@ -669,7 +669,7 @@ get_text(formals, length)
        *repl->r_ptr = '\0';
        while ((c != EOI) && (class(c) != STNL)) {
                if (BLANK(c)) {
-                       if (!blank++) add2repl(repl, ' ');
+                       blank++;
                        c = GetChar();
                        continue;
                }
@@ -677,6 +677,10 @@ get_text(formals, length)
                if (c == '\'' || c == '"') {
                        register int delim = c;
 
+                       if (blank) {
+                               blank = 0;
+                               add2repl(repl, ' ');
+                       }
                        do {
                                add2repl(repl, c);
                                if (c == '\\') add2repl(repl, GetChar());
@@ -692,10 +696,15 @@ get_text(formals, length)
                        c = GetChar();
                        if (c == '*') {
                                skipcomment();
-                               if (!blank++) add2repl(repl,' ');
+                               blank++;
                                c = GetChar();
-                               continue;       /* skip zero'ing of blank */
-                       } else add2repl(repl, '/');
+                               continue;
+                       } 
+                       if (blank) {
+                               blank = 0;
+                               add2repl(repl, ' ');
+                       }
+                       add2repl(repl, '/');
                } else if (formals
                            && (class(c) == STIDF || class(c) == STELL)) {
                        char id_buf[IDFSIZE + 1];
@@ -711,6 +720,10 @@ get_text(formals, length)
                        } while (in_idf(c));
                        *--idp = '\0';
 
+                       if (blank) {
+                               blank = 0;
+                               add2repl(repl, ' ');
+                       }
                        /* construct the formal parameter mark or identifier */
                        if (n = find_name(id_buf, formals))
                                add2repl(repl, FORMALP | (char) n);
@@ -719,11 +732,15 @@ get_text(formals, length)
                                while (*idp) add2repl(repl, *idp++);
                        }
                } else if (class(c) == STNUM) {
+                       if (blank) {
+                               blank = 0;
+                               add2repl(repl, ' ');
+                       }
                        add2repl(repl, c);
                        if (c == '.') {
                                c = GetChar();
                                if (class(c) != STNUM) {
-                                       blank = 0; continue;
+                                       continue;
                                }
                                add2repl(repl, c);
                        }
@@ -740,10 +757,13 @@ get_text(formals, length)
                                }
                        }
                } else {
+                       if (blank) {
+                               blank = 0;
+                               add2repl(repl, ' ');
+                       }
                        add2repl(repl, c);
                        c = GetChar();
                }
-               blank = 0;
        }
        *length = repl->r_ptr - repl->r_text;
        return Realloc(repl->r_text, (unsigned)(repl->r_ptr - repl->r_text +1));