big fix for #include in macro argument
authoreck <none@none>
Fri, 26 Jan 1990 14:59:50 +0000 (14:59 +0000)
committereck <none@none>
Fri, 26 Jan 1990 14:59:50 +0000 (14:59 +0000)
lang/cem/cemcom.ansi/main.c
lang/cem/cemcom.ansi/replace.c

index 9f434e0..35c0863 100644 (file)
@@ -88,7 +88,7 @@ main(argc, argv)
        inctable[0] = "";
        inctable[1] = "/usr/include";
        inctable[2] = 0;
-       inc_total = 2;
+       inc_total = 3;
        inc_max = 10;
 
        init_pp();      /* initialise the preprocessor macros   */
index 61a7346..6c01b13 100644 (file)
@@ -286,13 +286,13 @@ struct repl *repl;
                /* stash arguments */
                register int i;
 
-               *args->a_rawptr++ = '(';
                for (i = 0; ap->a_rawvec[i] != (char *)0; i++) {
+                       if (i == 0) stash(repl, '(', -1);
+                       else stash(repl, ',', -1);
                        for (p = ap->a_rawvec[i]; *p != '\0'; p++)
                                stash(repl, *p, -1);
-                       stash(repl, ',', -1);
                }
-               *(args->a_rawptr-1) = ')';      /* delete last ',' */
+               stash(repl, ')', -1);
        }
 }
 
@@ -386,16 +386,14 @@ actual(repl)
                                }
                        }
                        UnGetChar();
-               } else if (ch == '(' || ch == '[' || ch == '{') {
-                       /* a comma may occur within these constructions ???
-                        */
+               } else if (ch == '(') {
+                       /* a comma may occur between parentheses */
                        level++;
                        stash(repl, ch, !nostashraw);
-               } else if (ch == ')' || ch == ']' || ch == '}') {
+               } else if (ch == ')') {
                        level--;
-                       /* clossing parenthesis of macro call */
-                       if (ch == ')' && level < 0)
-                               return ')';
+                       /* closing parenthesis of macro call */
+                       if (level < 0) return ')';
                        stash(repl, ch, !nostashraw);
                } else if (ch == ',') {
                        if (level <= 0) { /* comma separator for next argument */
@@ -419,7 +417,7 @@ actual(repl)
                                interpreted as such.
                        */
 
-                       ch = GetChar();
+a_new_line:            ch = GetChar();
                        while (class(ch) == STSKIP || ch == '/') {
                            if (ch == '/') {
                                    if ((ch = GetChar()) == '*' && !InputLevel) {
@@ -435,9 +433,11 @@ actual(repl)
                                    break;
                            } else ch = GetChar();
                        }
-                       if (ch == '#')
+
+                       if (ch == '#') {
                                domacro();
-                       else if (ch == EOI) {
+                               goto a_new_line;
+                       } else if (ch == EOI) {
                                lexerror("unterminated macro call");
                                return ')';
                        }
@@ -738,7 +738,8 @@ add2repl(repl, ch)
 {
        register int index = repl->r_ptr - repl->r_text;
 
-       if (index + 1 >= repl->r_size) {
+       ASSERT(index < repl->r_size);
+       if (index + 2 >= repl->r_size) {
                repl->r_text = Realloc(repl->r_text, repl->r_size <<= 1);
                repl->r_ptr = repl->r_text + index;
        }
@@ -761,6 +762,7 @@ stash(repl, ch, stashraw)
        register int index = args->a_expptr - args->a_expbuf;
 
        if (stashraw >= 0) {
+               ASSERT(index < args->a_expsize);
                if (index + 1 >= args->a_expsize) {
                        args->a_expbuf = Realloc(args->a_expbuf,
                                                    args->a_expsize <<= 1);
@@ -771,6 +773,7 @@ stash(repl, ch, stashraw)
 
        if (stashraw) {
                index = args->a_rawptr - args->a_rawbuf;
+               ASSERT(index < args->a_rawsize);
                if (index + 1 >= args->a_rawsize) {
                        args->a_rawbuf = Realloc(args->a_rawbuf,
                                                    args->a_rawsize <<= 1);