From: Peter Avalos Date: Wed, 27 Dec 2006 21:29:02 +0000 (+0000) Subject: Sync with FreeBSD. Notable changes: X-Git-Tag: v2.0.1~3903 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/10c3f15b12b6834ada2e49e9e9810a546f929483 Sync with FreeBSD. Notable changes: Kill extraneous whitespace. Flush streams before calling system() so that the output appears in the right place in the output stream when redirected to a file (when full buffering is enabled). Store a pointer to "null" in struct ndblock's defn member instead of a duplicate allocated on the heap; the address defn points to is significant, and is checked against the address of "null" in certain conditionals. Fix m4 to properly handle bitwise operators &, ^, and |. Fix operator precedence. Add short-circuit evaluation. Respect locale settings from the environment. Add a new m4 script to test the functionality of math operators in eval(). --- diff --git a/usr.bin/m4/Makefile b/usr.bin/m4/Makefile index 3d75f17435..72880dc177 100644 --- a/usr.bin/m4/Makefile +++ b/usr.bin/m4/Makefile @@ -1,6 +1,6 @@ # $OpenBSD: Makefile,v 1.10 2002/04/26 13:13:41 espie Exp $ -# $FreeBSD: src/usr.bin/m4/Makefile,v 1.2.12.1 2002/07/15 02:06:15 jmallett Exp $ -# $DragonFly: src/usr.bin/m4/Makefile,v 1.2 2003/06/17 04:29:28 dillon Exp $ +# $FreeBSD: src/usr.bin/m4/Makefile,v 1.7 2005/01/28 16:08:07 ru Exp $ +# $DragonFly: src/usr.bin/m4/Makefile,v 1.3 2006/12/27 21:29:02 pavalos Exp $ # -DEXTENDED # if you want the paste & spaste macros. @@ -9,6 +9,5 @@ PROG= m4 CFLAGS+=-DEXTENDED SRCS= eval.c expr.c look.c main.c misc.c gnum4.c trace.c -MAN= m4.1 .include diff --git a/usr.bin/m4/TEST/math.m4 b/usr.bin/m4/TEST/math.m4 new file mode 100644 index 0000000000..e75bf604d8 --- /dev/null +++ b/usr.bin/m4/TEST/math.m4 @@ -0,0 +1,182 @@ +dnl $DragonFly: src/usr.bin/m4/TEST/math.m4,v 1.1 2006/12/27 21:29:02 pavalos Exp $ +dnl $FreeBSD: src/usr.bin/m4/TEST/math.m4,v 1.1 2004/05/01 03:27:05 smkelly Exp $ +dnl A regression test for m4 C operators (ksb,petef) +dnl If you think you have a short-circuiting m4, run us m4 -DSHORCIRCUIT=yes +dnl +dnl first level of precedence +ifelse(expr(-7),-7,,`failed - +')dnl +ifelse(expr(- -2),2,,`failed - +')dnl +ifelse(expr(!0),1,,`failed ! +')dnl +ifelse(expr(!7),0,,`failed ! +')dnl +ifelse(expr(~-1),0,,`failed ~ +')dnl +dnl next level of precedence +ifelse(expr(3*5),15,,`failed * +')dnl +ifelse(expr(3*0),0,,`failed * +')dnl +ifelse(expr(11/2),5,,`failed / +')dnl +ifelse(expr(1/700),0,,`failed / +')dnl +ifelse(expr(10%5),0,,`failed % +')dnl +ifelse(expr(2%5),2,,`failed % +')dnl +ifelse(expr(2%-1),0,,`failed % +')dnl +dnl next level of precedence +ifelse(expr(2+2),4,,`failed + +')dnl +ifelse(expr(2+-2),0,,`failed + +')dnl +ifelse(expr(2- -2),4,,`failed - +')dnl +ifelse(expr(2-2),0,,`failed - +')dnl +dnl next level of precedence +ifelse(expr(1<<4),16,,`failed << +')dnl +ifelse(expr(16>>4),1,,`failed >> +')dnl +dnl next level of precedence +ifelse(expr(4<4),0,,`failed < +')dnl +ifelse(expr(4<5),1,,`failed < +')dnl +ifelse(expr(4<3),0,,`failed < +')dnl +ifelse(expr(4>4),0,,`failed > +')dnl +ifelse(expr(4>5),0,,`failed > +')dnl +ifelse(expr(4>3),1,,`failed > +')dnl +ifelse(expr(4<=4),1,,`failed <= +')dnl +ifelse(expr(4<=5),1,,`failed <= +')dnl +ifelse(expr(4<=3),0,,`failed <= +')dnl +ifelse(expr(4>=4),1,,`failed >= +')dnl +ifelse(expr(4>=5),0,,`failed >= +')dnl +ifelse(expr(4>=3),1,,`failed >= +')dnl +dnl next level of precedence +ifelse(expr(1==1),1,,`failed == +')dnl +ifelse(expr(1==-1),0,,`failed == +')dnl +ifelse(expr(1!=1),0,,`failed != +')dnl +ifelse(expr(1!=2),1,,`failed != +')dnl +dnl next level of precedence +ifelse(expr(3&5),1,,`failed & +')dnl +ifelse(expr(8&7),0,,`failed & +')dnl +dnl next level of precedence +ifelse(expr(1^1),0,,`failed ^ +')dnl +ifelse(expr(21^5),16,,`failed ^ +')dnl +dnl next level of precedence +ifelse(expr(1|1),1,,`failed | +')dnl +ifelse(expr(21|5),21,,`failed | +')dnl +ifelse(expr(100|1),101,,`failed | +')dnl +dnl next level of precedence +ifelse(expr(1&&1),1,,`failed && +')dnl +ifelse(expr(0&&1),0,,`failed && +')dnl +ifelse(expr(1&&0),0,,`failed && +')dnl +ifelse(SHORTCIRCUIT,`yes',`ifelse(expr(0&&10/0),0,,`failed && shortcircuit +')')dnl +dnl next level of precedence +ifelse(expr(1||1),1,,`failed || +')dnl +ifelse(expr(1||0),1,,`failed || +')dnl +ifelse(expr(0||0),0,,`failed || +')dnl +ifelse(SHORTCIRCUIT,`yes',`ifelse(expr(1||10/0),1,,`failed || shortcircuit +')')dnl +dnl next level of precedence +ifelse(expr(0 ? 2 : 5),5,,`failed ?: +')dnl +ifelse(expr(1 ? 2 : 5),2,,`failed ?: +')dnl +ifelse(SHORTCIRCUIT,`yes',`ifelse(expr(0 ? 10/0 : 7),7,,`failed ?: shortcircuit +')')dnl +ifelse(SHORTCIRCUIT,`yes',`ifelse(expr(1 ? 7 : 10/0),7,,`failed ?: shortcircuit +')')dnl +dnl operator precedence +ifelse(expr(!0*-2),-2,,`precedence wrong, ! * +')dnl +ifelse(expr(~8/~2),3,,`precedence wrong ~ / +')dnl +ifelse(expr(~-20%7),5,,`precedence wrong ~ % +')dnl +ifelse(expr(3*2+100),106,,`precedence wrong * + +')dnl +ifelse(expr(3+2*100),203,,`precedence wrong + * +')dnl +ifelse(expr(2%5-6/3),0,,`precedence wrong % - +')dnl +ifelse(expr(2/5-5%3),-2,,`precedence wrong / - +')dnl +ifelse(expr(2+5%5+1),3,,`precedence wrong % + +')dnl +ifelse(expr(7+9<<1),32,,`precedence wrong + << +')dnl +ifelse(expr(35-3>>2),8,,`precedence wrong - >> +')dnl +ifelse(expr(9<10<<5),1,,`precedence wrong << < +')dnl +ifelse(expr(9>10<<5),0,,`precedence wrong << > +')dnl +ifelse(expr(32>>2<32),1,,`precedence wrong >> < +')dnl +ifelse(expr(9<=10<<5),1,,`precedence wrong << < +')dnl +ifelse(expr(5<<1<=20>>1),1,,`precedence wrong << <= +')dnl +ifelse(expr(5<<1>=20>>1),1,,`precedence wrong << >= +')dnl +ifelse(expr(0<7==5>=5),1,,`precedence wrong < == +')dnl +ifelse(expr(0<7!=5>=5),0,,`precedence wrong < != +')dnl +ifelse(expr(0>7==5>=5),0,,`precedence wrong > == +')dnl +ifelse(expr(0>7!=5>=5),1,,`precedence wrong > != +')dnl +ifelse(expr(1&7==7),1,,`precedence wrong & == +')dnl +ifelse(expr(0&7!=6),0,,`precedence wrong & != +')dnl +ifelse(expr(9&1|5),5,,`precedence wrong & | +')dnl +ifelse(expr(9&1^5),4,,`precedence wrong & ^ +')dnl +ifelse(expr(9^1|5),13,,`precedence wrong ^ | +')dnl +ifelse(expr(5|0&&1),1,,`precedence wrong | && +')dnl +ifelse(expr(5&&0||0&&5||5),1,,`precedence wrong && || +')dnl +ifelse(expr(0 || 1 ? 0 : 1),0,,`precedence wrong || ?: +')dnl +ifelse(expr(5&&(0||0)&&(5||5)),0,,`precedence wrong || parens +')dnl diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c index 916bf77a5c..09c9c1bd1a 100644 --- a/usr.bin/m4/eval.c +++ b/usr.bin/m4/eval.c @@ -38,8 +38,8 @@ * * @(#)eval.c 8.2 (Berkeley) 4/27/95 * $OpenBSD: eval.c,v 1.44 2002/04/26 16:15:16 espie Exp $ - * $FreeBSD: src/usr.bin/m4/eval.c,v 1.10.2.5 2002/07/15 02:06:15 jmallett Exp $ - * $DragonFly: src/usr.bin/m4/eval.c,v 1.2 2003/06/17 04:29:28 dillon Exp $ + * $FreeBSD: src/usr.bin/m4/eval.c,v 1.22 2004/08/16 14:18:21 tjr Exp $ + * $DragonFly: src/usr.bin/m4/eval.c,v 1.3 2006/12/27 21:29:02 pavalos Exp $ */ /* @@ -111,7 +111,7 @@ eval(const char *argv[], int argc, int td) ssize_t mark = -1; expansion_id++; - if (td & RECDEF) + if (td & RECDEF) errx(1, "%s at line %lu: expanding recursive definition for %s", CURRENT_NAME, CURRENT_LINE, argv[1]); if (traced_macros && is_traced(argv[1])) @@ -233,15 +233,17 @@ expand_builtin(const char *argv[], int argc, int td) /* * dosys - execute system command */ - if (argc > 2) + if (argc > 2) { + fflush(NULL); sysval = system(argv[2]); + } break; case SYSVTYPE: /* * dosysval - return value of the last * system call. - * + * */ pbnum(sysval); break; @@ -265,7 +267,7 @@ expand_builtin(const char *argv[], int argc, int td) case PASTTYPE: if (argc > 2) if (!dopaste(argv[2])) - err(1, "%s at line %lu: paste(%s)", + err(1, "%s at line %lu: paste(%s)", CURRENT_NAME, CURRENT_LINE, argv[2]); break; @@ -291,7 +293,7 @@ expand_builtin(const char *argv[], int argc, int td) case SUBSTYPE: /* * dosub - select substring - * + * */ if (argc > 3) dosub(argv, argc); @@ -367,11 +369,11 @@ expand_builtin(const char *argv[], int argc, int td) char *temp; temp = xstrdup(argv[2]); - + fd = mkstemp(temp); if (fd == -1) - err(1, - "%s at line %lu: couldn't make temp file %s", + err(1, + "%s at line %lu: couldn't make temp file %s", CURRENT_NAME, CURRENT_LINE, argv[2]); close(fd); pbstr(temp); @@ -456,7 +458,7 @@ expand_builtin(const char *argv[], int argc, int td) if (argc > 2) doindir(argv, argc); break; - + case BUILTINTYPE: /* Builtins only */ if (argc > 2) dobuiltin(argv, argc); @@ -583,12 +585,12 @@ dodefine(const char *name, const char *defn) p->type = n & TYPEMASK; if ((n & NOARGS) == 0) p->type |= NEEDARGS; - p->defn = xstrdup(null); + p->defn = null; return; } } if (!*defn) - p->defn = xstrdup(null); + p->defn = null; else p->defn = xstrdup(defn); p->type = MACRTYPE; @@ -635,7 +637,7 @@ dopushdef(const char *name, const char *defn) CURRENT_LINE); p = addent(name); if (!*defn) - p->defn = xstrdup(null); + p->defn = null; else p->defn = xstrdup(defn); p->type = MACRTYPE; @@ -868,7 +870,7 @@ dodiv(int n) if (outfile[n] == NULL) { char fname[] = _PATH_DIVNAME; - if ((fd = mkstemp(fname)) < 0 || + if ((fd = mkstemp(fname)) < 0 || (outfile[n] = fdopen(fd, "w+")) == NULL) err(1, "%s: cannot divert", fname); if (unlink(fname) == -1) @@ -995,7 +997,7 @@ map(char *dest, const char *src, const char *from, const char *to) * "to" */ while (*from) - mapvec[(unsigned char)(*from++)] = (*to) ? + mapvec[(unsigned char)(*from++)] = (*to) ? (unsigned char)(*to++) : 0; while (*src) { @@ -1029,12 +1031,12 @@ static const char * handledash(char *buffer, char *end, const char *src) { char *p; - + p = buffer; while(*src) { if (src[1] == '-' && src[2]) { unsigned char i; - for (i = (unsigned char)src[0]; + for (i = (unsigned char)src[0]; i <= (unsigned char)src[2]; i++) { *p++ = i; if (p == end) { diff --git a/usr.bin/m4/expr.c b/usr.bin/m4/expr.c index 070cfd67e2..91f8ccde17 100644 --- a/usr.bin/m4/expr.c +++ b/usr.bin/m4/expr.c @@ -38,8 +38,8 @@ * * @(#)expr.c 8.2 (Berkeley) 4/29/95 * $OpenBSD: expr.c,v 1.14 2002/04/26 16:15:16 espie Exp $ - * $FreeBSD: src/usr.bin/m4/expr.c,v 1.3.12.1 2002/07/15 02:06:15 jmallett Exp $ - * $DragonFly: src/usr.bin/m4/expr.c,v 1.3 2004/07/27 21:03:51 dillon Exp $ + * $FreeBSD: src/usr.bin/m4/expr.c,v 1.14 2004/05/01 03:59:43 smkelly Exp $ + * $DragonFly: src/usr.bin/m4/expr.c,v 1.4 2006/12/27 21:29:02 pavalos Exp $ */ #include @@ -59,31 +59,24 @@ * query : lor * | lor "?" query ":" query * lor : land { "||" land } - * land : not { "&&" not } - * not : eqrel - * | '!' not - * eqrel : shift { eqrelop shift } - * shift : primary { shop primary } - * primary : term { addop term } - * term : exp { mulop exp } - * exp : unary { expop unary } + * land : bor { "&&" bor } + * bor : xor { "|" xor } + * xor : band { "^" eqrel } + * band : eqrel { "&" eqrel } + * eqrel : nerel { ("==" | "!=") nerel } + * nerel : shift { ("<" | ">" | "<=" | ">=") shift } + * shift : primary { ("<<" | ">>") primary } + * primary : term { ("+" | "-") term } + * term : exp { ("*" | "/" | "%") exp } + * exp : unary { "**" unary } * unary : factor - * | unop unary + * | ("+" | "-" | "~" | "!") unary * factor : constant * | "(" query ")" * constant: num * | "'" CHAR "'" * num : DIGIT * | DIGIT num - * shop : "<<" - * | ">>" - * eqrel : "=" - * | "==" - * | "!=" - * | "<" - * | ">" - * | "<=" - * | ">=" * * * This expression evaluator is lifted from a public-domain @@ -107,20 +100,23 @@ static const char *nxtch; /* Parser scan pointer */ static const char *where; -static int query(void); -static int lor(void); -static int land(void); -static int not(void); -static int eqrel(void); -static int shift(void); -static int primary(void); -static int term(void); -static int expx(void); -static int unary(void); -static int factor(void); -static int constant(void); -static int num(void); -static int geteqrel(void); +static int query(int mayeval); +static int lor(int mayeval); +static int land(int mayeval); +static int bor(int mayeval); +static int xor(int mayeval); +static int band(int mayeval); +static int eqrel(int mayeval); +static int nerel(int mayeval); +static int shift(int mayeval); +static int primary(int mayeval); +static int term(int mayeval); +static int expx(int mayeval); +static int unary(int mayeval); +static int factor(int mayeval); +static int constant(int mayeval); +static int num(int mayeval); +static int geteqrel(int mayeval); static int skipws(void); static void experr(const char *); @@ -148,7 +144,7 @@ expr(const char *expbuf) if (setjmp(expjump) != 0) return FALSE; - rval = query(); + rval = query(1); if (skipws() == EOS) return rval; @@ -160,21 +156,21 @@ expr(const char *expbuf) * query : lor | lor '?' query ':' query */ static int -query(void) +query(int mayeval) { int result, true_val, false_val; - result = lor(); + result = lor(mayeval); if (skipws() != '?') { ungetch(); return result; } - true_val = query(); + true_val = query(result); if (skipws() != ':') - experr("bad query"); + experr("bad query: missing \":\""); - false_val = query(); + false_val = query(!result); return result ? true_val : false_val; } @@ -182,15 +178,19 @@ query(void) * lor : land { '||' land } */ static int -lor(void) +lor(int mayeval) { int c, vl, vr; - vl = land(); + vl = land(mayeval); while ((c = skipws()) == '|') { - if (getch() != '|') + if (getch() != '|') { ungetch(); - vr = land(); + break; + } + if (vl != 0) + mayeval = 0; + vr = land(mayeval); vl = vl || vr; } @@ -202,15 +202,19 @@ lor(void) * land : not { '&&' not } */ static int -land(void) +land(int mayeval) { int c, vl, vr; - vl = not(); + vl = bor(mayeval); while ((c = skipws()) == '&') { - if (getch() != '&') + if (getch() != '&') { ungetch(); - vr = not(); + break; + } + if (vl == 0) + mayeval = 0; + vr = bor(mayeval); vl = vl && vr; } @@ -219,74 +223,131 @@ land(void) } /* - * not : eqrel | '!' not + * bor : xor { "|" xor } */ static int -not(void) +bor(int mayeval) { - int val, c; + int vl, vr, c, cr; - if ((c = skipws()) == '!' && getch() != '=') { + vl = xor(mayeval); + while ((c = skipws()) == '|') { + cr = getch(); ungetch(); - val = not(); - return !val; + if (cr == '|') + break; + vr = xor(mayeval); + vl |= vr; } + ungetch(); + return (vl); +} - if (c == '!') - ungetch(); +/* + * xor : band { "^" band } + */ +static int +xor(int mayeval) +{ + int vl, vr, c; + + vl = band(mayeval); + while ((c = skipws()) == '^') { + vr = band(mayeval); + vl ^= vr; + } ungetch(); - return eqrel(); + return (vl); } /* - * eqrel : shift { eqrelop shift } + * band : eqrel { "&" eqrel } */ static int -eqrel(void) +band(int mayeval) { - int vl, vr, op; + int c, cr, vl, vr; - vl = shift(); - while ((op = geteqrel()) != -1) { - vr = shift(); + vl = eqrel(mayeval); + while ((c = skipws()) == '&') { + cr = getch(); + ungetch(); + if (cr == '&') + break; + vr = eqrel(mayeval); + vl &= vr; + } + ungetch(); + return vl; +} - switch (op) { +/* + * eqrel : nerel { ("==" | "!=" ) nerel } + */ +static int +eqrel(int mayeval) +{ + int vl, vr, c, cr; - case EQL: + vl = nerel(mayeval); + while ((c = skipws()) == '!' || c == '=') { + if ((cr = getch()) != '=') { + ungetch(); + break; + } + vr = nerel(mayeval); + switch (c) { + case '=': vl = (vl == vr); break; - case NEQ: + case '!': vl = (vl != vr); break; + } + } + ungetch(); + return vl; +} - case LEQ: - vl = (vl <= vr); - break; - case LSS: - vl = (vl < vr); - break; - case GTR: - vl = (vl > vr); +/* + * nerel : shift { ("<=" | ">=" | "<" | ">") shift } + */ +static int +nerel(int mayeval) +{ + int vl, vr, c, cr; + + vl = shift(mayeval); + while ((c = skipws()) == '<' || c == '>') { + if ((cr = getch()) != '=') { + ungetch(); + cr = '\0'; + } + vr = shift(mayeval); + switch (c) { + case '<': + vl = (cr == '\0') ? (vl < vr) : (vl <= vr); break; - case GEQ: - vl = (vl >= vr); + case '>': + vl = (cr == '\0') ? (vl > vr) : (vl >= vr); break; } } + ungetch(); return vl; } /* - * shift : primary { shop primary } + * shift : primary { ("<<" | ">>") primary } */ static int -shift(void) +shift(int mayeval) { int vl, vr, c; - vl = primary(); + vl = primary(mayeval); while (((c = skipws()) == '<' || c == '>') && getch() == c) { - vr = primary(); + vr = primary(mayeval); if (c == '<') vl <<= vr; @@ -301,16 +362,16 @@ shift(void) } /* - * primary : term { addop term } + * primary : term { ("+" | "-") term } */ static int -primary(void) +primary(int mayeval) { int c, vl, vr; - vl = term(); + vl = term(mayeval); while ((c = skipws()) == '+' || c == '-') { - vr = term(); + vr = term(mayeval); if (c == '+') vl += vr; @@ -323,29 +384,33 @@ primary(void) } /* - * := { } + * term : exp { ("*" | "/" | "%") exp } */ static int -term(void) +term(int mayeval) { int c, vl, vr; - vl = expx(); + vl = expx(mayeval); while ((c = skipws()) == '*' || c == '/' || c == '%') { - vr = expx(); + vr = expx(mayeval); switch (c) { case '*': vl *= vr; break; case '/': - if (vr == 0) + if (!mayeval) + /* short-circuit */; + else if (vr == 0) errx(1, "division by zero in eval."); else vl /= vr; break; case '%': - if (vr == 0) + if (!mayeval) + /* short-circuit */; + else if (vr == 0) errx(1, "modulo zero in eval."); else vl %= vr; @@ -357,24 +422,20 @@ term(void) } /* - * := { } + * exp : unary { "**" exp } */ static int -expx(void) +expx(int mayeval) { int c, vl, vr, n; - vl = unary(); - switch (c = skipws()) { - - case '*': + vl = unary(mayeval); + while ((c = skipws()) == '*') { if (getch() != '*') { ungetch(); break; } - - case '^': - vr = expx(); + vr = unary(mayeval); n = 1; while (vr-- > 0) n *= vl; @@ -386,15 +447,15 @@ expx(void) } /* - * unary : factor | unop unary + * unary : factor | ("+" | "-" | "~" | "!") unary */ static int -unary(void) +unary(int mayeval) { int val, c; - if ((c = skipws()) == '+' || c == '-' || c == '~') { - val = unary(); + if ((c = skipws()) == '+' || c == '-' || c == '~' || c == '!') { + val = unary(mayeval); switch (c) { case '+': @@ -403,30 +464,32 @@ unary(void) return -val; case '~': return ~val; + case '!': + return !val; } } ungetch(); - return factor(); + return factor(mayeval); } /* * factor : constant | '(' query ')' */ static int -factor(void) +factor(int mayeval) { int val; if (skipws() == '(') { - val = query(); + val = query(mayeval); if (skipws() != ')') - experr("bad factor"); + experr("bad factor: missing \")\""); return val; } ungetch(); - return constant(); + return constant(mayeval); } /* @@ -434,7 +497,7 @@ factor(void) * Note: constant() handles multi-byte constants */ static int -constant(void) +constant(int mayeval) { int i; int value; @@ -443,9 +506,9 @@ constant(void) if (skipws() != '\'') { ungetch(); - return num(); + return num(mayeval); } - for (i = 0; i < (int)sizeof(int); i++) { + for (i = 0; i < (ssize_t)sizeof(int); i++) { if ((c = getch()) == '\'') { ungetch(); break; @@ -461,7 +524,7 @@ constant(void) case '6': case '7': ungetch(); - c = num(); + c = num(mayeval); break; case 'n': c = 012; @@ -495,7 +558,7 @@ constant(void) * num : digit | num digit */ static int -num(void) +num(int mayeval) { int rval, c, base; int ndig; @@ -517,10 +580,10 @@ num(void) for(;;) { switch(c) { case '8': case '9': - if (base == OCTAL) + if (base == OCTAL) goto bad_digit; /*FALLTHRU*/ - case '0': case '1': case '2': case '3': + case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': rval *= base; rval += c - '0'; @@ -542,55 +605,11 @@ num(void) } bad_digit: ungetch(); - + if (ndig == 0) experr("bad constant"); - - return rval; -} - -/* - * eqrel : '=' | '==' | '!=' | '<' | '>' | '<=' | '>=' - */ -static int -geteqrel(void) -{ - int c1, c2; - - c1 = skipws(); - c2 = getch(); - - switch (c1) { - - case '=': - if (c2 != '=') - ungetch(); - return EQL; - - case '!': - if (c2 == '=') - return NEQ; - ungetch(); - ungetch(); - return -1; - - case '<': - if (c2 == '=') - return LEQ; - ungetch(); - return LSS; - - case '>': - if (c2 == '=') - return GEQ; - ungetch(); - return GTR; - default: - ungetch(); - ungetch(); - return -1; - } + return rval; } /* @@ -607,7 +626,7 @@ skipws(void) } /* - * resets environment to eval(), prints an error + * resets environment to eval(), prints an error * and forces eval to return FALSE. */ static void diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h index 32a2ec9828..652b620382 100644 --- a/usr.bin/m4/extern.h +++ b/usr.bin/m4/extern.h @@ -37,8 +37,8 @@ * SUCH DAMAGE. * * @(#)extern.h 8.1 (Berkeley) 6/6/93 - * $FreeBSD: src/usr.bin/m4/extern.h,v 1.3.6.3 2002/07/15 02:06:15 jmallett Exp $ - * $DragonFly: src/usr.bin/m4/extern.h,v 1.2 2003/06/17 04:29:28 dillon Exp $ + * $FreeBSD: src/usr.bin/m4/extern.h,v 1.12 2004/08/16 14:18:22 tjr Exp $ + * $DragonFly: src/usr.bin/m4/extern.h,v 1.3 2006/12/27 21:29:02 pavalos Exp $ */ /* eval.c */ @@ -61,7 +61,7 @@ extern void doprintlineno(struct input_file *); extern void doprintfilename(struct input_file *); extern void doesyscmd(const char *); - + /* look.c */ extern ndptr addent(const char *); @@ -105,7 +105,7 @@ extern void release_input(struct input_file *); enlarge_bufspace(); \ *bp++ = (c); \ } while(0) - + #define CHRSAVE(c) \ do { \ if (ep >= endest) \ @@ -150,7 +150,7 @@ extern char ecommt[MAXCCHARS+1];/* end character for comment */ extern char *ep; /* first free char in strspace */ extern char lquote[MAXCCHARS+1];/* left quote character (`) */ extern const char *m4wraps; /* m4wrap string default. */ -extern const char *null; /* as it says.. just a null. */ +extern char null[]; /* as it says.. just a null. */ extern char rquote[MAXCCHARS+1];/* right quote character (') */ extern char scommt[MAXCCHARS+1];/* start character for comment */ extern int synccpp; /* Line synchronisation for C preprocessor */ @@ -163,7 +163,7 @@ static __inline int gpbc(void) int chscratch; /* Scratch space. */ if (bp > bufbase) { - if (*--bp) + if (*--bp) return ((unsigned char)*bp); else return (EOF); diff --git a/usr.bin/m4/gnum4.c b/usr.bin/m4/gnum4.c index 230107fcf5..abc23a2afa 100644 --- a/usr.bin/m4/gnum4.c +++ b/usr.bin/m4/gnum4.c @@ -24,8 +24,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/usr.bin/m4/gnum4.c,v 1.7.2.1 2002/07/15 02:06:15 jmallett Exp $ - * $DragonFly: src/usr.bin/m4/gnum4.c,v 1.2 2003/06/17 04:29:28 dillon Exp $ + * $FreeBSD: src/usr.bin/m4/gnum4.c,v 1.9 2004/05/18 15:53:58 stefanf Exp $ + * $DragonFly: src/usr.bin/m4/gnum4.c,v 1.3 2006/12/27 21:29:02 pavalos Exp $ */ /* @@ -83,8 +83,8 @@ new_path_entry(const char *dirname) n->next = 0; return n; } - -void + +void addtoincludepath(const char *dirname) { struct path_entry *n; @@ -111,13 +111,13 @@ ensure_m4path(void) return; envpathdone = TRUE; envpath = getenv("M4PATH"); - if (!envpath) + if (!envpath) return; /* for portability: getenv result is read-only */ envpath = strdup(envpath); if (!envpath) errx(1, "out of memory"); - for (sweep = envpath; + for (sweep = envpath; (path = strsep(&sweep, ":")) != NULL;) addtoincludepath(path); free(envpath); @@ -159,7 +159,7 @@ fopen_trypath(struct input_file *i, const char *filename) return dopath(i, filename); } -void +void doindir(const char *argv[], int argc) { ndptr p; @@ -171,7 +171,7 @@ doindir(const char *argv[], int argc) eval(argv+1, argc-1, p->type); } -void +void dobuiltin(const char *argv[], int argc) { int n; @@ -181,7 +181,7 @@ dobuiltin(const char *argv[], int argc) eval(argv+1, argc-1, n); else errx(1, "unknown builtin %s", argv[2]); -} +} /* We need some temporary buffer space, as pb pushes BACK and substitution @@ -202,7 +202,7 @@ static void add_sub(size_t, const char *, regex_t *, regmatch_t *); static void add_replace(const char *, regex_t *, const char *, regmatch_t *); #define addconstantstring(s) addchars((s), sizeof(s)-1) -static void +static void addchars(const char *c, size_t n) { if (n == 0) @@ -220,7 +220,7 @@ addchars(const char *c, size_t n) current += n; } -static void +static void addchar(int c) { if (current +1 > bufsize) { @@ -244,7 +244,7 @@ getstring(void) } -static void +static void exit_regerror(int er, regex_t *re) { size_t errlen; @@ -273,7 +273,7 @@ add_sub(size_t n, const char *string, regex_t *re, regmatch_t *pm) /* Add replacement string to the output buffer, recognizing special * constructs and replacing them with substrings of the original string. */ -static void +static void add_replace(const char *string, regex_t *re, const char *replace, regmatch_t *pm) { const char *p; @@ -306,7 +306,7 @@ add_replace(const char *string, regex_t *re, const char *replace, regmatch_t *pm } } -static void +static void do_subst(const char *string, regex_t *re, const char *replace, regmatch_t *pm) { int error; @@ -321,11 +321,11 @@ do_subst(const char *string, regex_t *re, const char *replace, regmatch_t *pm) flags = REG_NOTBOL; } - /* NULL length matches are special... We use the `vi-mode' + /* NULL length matches are special... We use the `vi-mode' * rule: don't allow a NULL-match at the last match - * position. + * position. */ - if (pm[0].rm_so == pm[0].rm_eo && + if (pm[0].rm_so == pm[0].rm_eo && string + pm[0].rm_so == last_match) { if (*string == '\0') return; @@ -346,13 +346,13 @@ do_subst(const char *string, regex_t *re, const char *replace, regmatch_t *pm) pbstr(string); } -static void +static void do_regexp(const char *string, regex_t *re, const char *replace, regmatch_t *pm) { int error; switch(error = regexec(re, string, re->re_nsub+1, pm, 0)) { - case 0: + case 0: add_replace(string, re, replace, pm); pbstr(getstring()); break; @@ -363,7 +363,7 @@ do_regexp(const char *string, regex_t *re, const char *replace, regmatch_t *pm) } } -static void +static void do_regexpindex(const char *string, regex_t *re, regmatch_t *pm) { int error; @@ -439,13 +439,13 @@ dopatsubst(const char *argv[], int argc) warnx("Too few arguments to patsubst"); return; } - error = regcomp(&re, mimic_gnu ? twiddle(argv[3]) : argv[3], + error = regcomp(&re, mimic_gnu ? twiddle(argv[3]) : argv[3], REG_NEWLINE | REG_EXTENDED); if (error != 0) exit_regerror(error, &re); - + pmatch = xalloc(sizeof(regmatch_t) * (re.re_nsub+1)); - do_subst(argv[2], &re, + do_subst(argv[2], &re, argc != 4 && argv[4] != NULL ? argv[4] : "", pmatch); pbstr(getstring()); free(pmatch); @@ -463,11 +463,11 @@ doregexp(const char *argv[], int argc) warnx("Too few arguments to regexp"); return; } - error = regcomp(&re, mimic_gnu ? twiddle(argv[3]) : argv[3], + error = regcomp(&re, mimic_gnu ? twiddle(argv[3]) : argv[3], REG_EXTENDED); if (error != 0) exit_regerror(error, &re); - + pmatch = xalloc(sizeof(regmatch_t) * (re.re_nsub+1)); if (argv[4] == NULL || argc == 4) do_regexpindex(argv[2], &re, pmatch); @@ -499,7 +499,7 @@ doesyscmd(const char *cmd) (void) close(p[0]); (void) dup2(p[1], 1); (void) close(p[1]); - execl(_PATH_BSHELL, "sh", "-c", cmd, NULL); + execl(_PATH_BSHELL, "sh", "-c", cmd, (char *)NULL); exit(1); default: /* Read result in two stages, since m4's buffer is diff --git a/usr.bin/m4/look.c b/usr.bin/m4/look.c index ba7c7e065d..dca6c6ce50 100644 --- a/usr.bin/m4/look.c +++ b/usr.bin/m4/look.c @@ -35,8 +35,8 @@ * * @(#)look.c 8.1 (Berkeley) 6/6/93 * $OpenBSD: look.c,v 1.10 2002/04/26 16:15:16 espie Exp $ - * $FreeBSD: src/usr.bin/m4/look.c,v 1.2.12.1 2002/07/15 02:06:15 jmallett Exp $ - * $DragonFly: src/usr.bin/m4/look.c,v 1.2 2003/06/17 04:29:28 dillon Exp $ + * $FreeBSD: src/usr.bin/m4/look.c,v 1.7 2002/07/15 02:15:12 jmallett Exp $ + * $DragonFly: src/usr.bin/m4/look.c,v 1.3 2006/12/27 21:29:02 pavalos Exp $ */ /* @@ -68,7 +68,7 @@ hash(const char *name) /* * find name in the hash table */ -ndptr +ndptr lookup(const char *name) { ndptr p; @@ -85,7 +85,7 @@ lookup(const char *name) * hash and create an entry in the hash table. * The new entry is added in front of a hash bucket. */ -ndptr +ndptr addent(const char *name) { unsigned int h; diff --git a/usr.bin/m4/m4.1 b/usr.bin/m4/m4.1 index f9f643ce48..6cc7f90377 100644 --- a/usr.bin/m4/m4.1 +++ b/usr.bin/m4/m4.1 @@ -1,8 +1,8 @@ .\" @(#) $OpenBSD: m4.1,v 1.24 2002/04/18 18:57:23 espie Exp $ -.\" $FreeBSD: src/usr.bin/m4/m4.1,v 1.10.2.9 2003/04/26 14:29:55 schweikh Exp $ -.\" $DragonFly: src/usr.bin/m4/m4.1,v 1.2 2003/06/17 04:29:28 dillon Exp $ +.\" $FreeBSD: src/usr.bin/m4/m4.1,v 1.27 2005/01/17 07:44:22 ru Exp $ +.\" $DragonFly: src/usr.bin/m4/m4.1,v 1.3 2006/12/27 21:29:02 pavalos Exp $ .\" -.Dd April 17, 2002 +.Dd July 3, 2004 .Dt M4 1 .Os .Sh NAME @@ -22,8 +22,9 @@ The .Nm utility is a macro processor that can be used as a front end to any language (e.g., C, ratfor, fortran, lex, and yacc). +The .Nm -reads from the standard input and writes +utility reads from the standard input and writes the processed text to the standard output. .Pp Macro calls have the form @@ -248,7 +249,7 @@ argument is not found, returns \-1. .It Ic indir Indirectly calls the macro whose name is passed as the first arguments, -with the remaining arguments passed as first, etc. arguments. +with the remaining arguments passed as first, etc.\& arguments. .It Ic len Returns the number of characters in the first argument. Extra arguments @@ -350,16 +351,18 @@ Returns the current file's line number. .It Ic __file__ Returns the current file's name. .El -.Sh DIAGNOSTICS +.Sh EXIT STATUS .Ex -std .Pp The .Ic m4exit macro may be used to change the exit status from the input file. .Sh COMPATIBILITY +The .Nm -follows the Single Unix 2 specification, along with a few extensions taken -from GNU-m4. +utility follows the +.St -susv2 , +along with a few extensions taken from GNU-m4. Flags .Fl I , d , and @@ -413,3 +416,7 @@ and .An Richard A. O'Keefe Aq ok@goanna.cs.rmit.OZ.AU . GNU-m4 compatibility extensions by .An Marc Espie Aq espie@cvs.openbsd.org . +.Sh BUGS +The +.Nm +utility does not recognize multibyte characters. diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c index 9afe834938..6689264380 100644 --- a/usr.bin/m4/main.c +++ b/usr.bin/m4/main.c @@ -39,8 +39,8 @@ * @(#) Copyright (c) 1989, 1993 The Regents of the University of California. All rights reserved. * @(#)main.c 8.1 (Berkeley) 6/6/93 * $OpenBSD: main.c,v 1.53 2002/04/26 16:15:16 espie Exp $ - * $FreeBSD: src/usr.bin/m4/main.c,v 1.6.2.6 2002/07/15 02:06:15 jmallett Exp $ - * $DragonFly: src/usr.bin/m4/main.c,v 1.2 2003/06/17 04:29:28 dillon Exp $ + * $FreeBSD: src/usr.bin/m4/main.c,v 1.26 2004/08/16 14:18:22 tjr Exp $ + * $DragonFly: src/usr.bin/m4/main.c,v 1.3 2006/12/27 21:29:02 pavalos Exp $ */ /* @@ -60,6 +60,7 @@ #include #include #include +#include #include "mdef.h" #include "stdd.h" #include "extern.h" @@ -79,7 +80,7 @@ int maxout; FILE *active; /* active output file pointer */ int ilevel = 0; /* input file stack pointer */ int oindex = 0; /* diversion index.. */ -const char *null = ""; /* as it says.. just a null.. */ +char null[] = ""; /* as it says.. just a null.. */ const char *m4wraps = ""; /* m4wrap string default.. */ char lquote[MAXCCHARS+1] = {LQUOTE}; /* left quote character (`) */ char rquote[MAXCCHARS+1] = {RQUOTE}; /* right quote character (') */ @@ -134,7 +135,7 @@ struct keyblk keywrds[] = { /* m4 keywords to be installed */ { "traceon", TRACEONTYPE | NOARGS }, { "traceoff", TRACEOFFTYPE | NOARGS }, -#if defined(unix) || defined(__unix__) +#if defined(unix) || defined(__unix__) { "unix", SELFTYPE | NOARGS }, #else #ifdef vms @@ -169,6 +170,8 @@ main(int argc, char *argv[]) int rval; char *p; + setlocale(LC_ALL, ""); + traceout = stderr; if (signal(SIGINT, SIG_IGN) != SIG_IGN) @@ -191,6 +194,8 @@ main(int argc, char *argv[]) for (p = optarg; *p; p++) if (*p == '=') break; + if (p == optarg) + errx(1, "null variable cannot be defined"); if (*p) *p++ = EOS; dodefine(optarg, p); @@ -248,7 +253,7 @@ main(int argc, char *argv[]) continue; } sp = -1; - fp = 0; + fp = 0; if ((inname[0] = strdup(p)) == NULL) err(1, NULL); inlineno[0] = 1; @@ -324,7 +329,7 @@ macro(void) p = inspect(t, token); if (p != nil) putback(l = gpbc()); - if (p == nil || (l != LPAREN && + if (p == nil || (l != LPAREN && (p->type & NEEDARGS) != 0)) outputstr(token); else { @@ -342,13 +347,13 @@ macro(void) pushs1(p->name); /* macro name */ pushs(ep); /* start next..*/ - if (l != LPAREN && PARLEV == 0) { + if (l != LPAREN && PARLEV == 0) { /* no bracks */ chrsave(EOS); if ((uintptr_t)sp == STACKMAX) errx(1, "internal stack overflow"); - eval((const char **) mstack+fp+1, 2, + eval((const char **) mstack+fp+1, 2, CALTYP); ep = PREVEP; /* flush strspace */ @@ -448,7 +453,7 @@ macro(void) if ((uintptr_t)sp == STACKMAX) errx(1, "internal stack overflow"); - eval((const char **) mstack+fp+1, sp-fp, + eval((const char **) mstack+fp+1, sp-fp, CALTYP); ep = PREVEP; /* flush strspace */ @@ -491,8 +496,8 @@ macro(void) } } -/* - * output string directly, without pushing it for reparses. +/* + * output string directly, without pushing it for reparses. */ void outputstr(const char *s) @@ -511,13 +516,13 @@ outputstr(const char *s) * combo with lookup to speed things up. */ static ndptr -inspect(int c, char *tp) +inspect(int c, char *tp) { char *name = tp; char *etp = tp+MAXTOK; ndptr p; unsigned int h; - + h = *tp++ = c; while ((isalnum(c = gpbc()) || c == '_') && tp < etp) @@ -546,9 +551,9 @@ inspect(int c, char *tp) } /* - * initkwds - initialise m4 keywords as fast as possible. + * initkwds - initialise m4 keywords as fast as possible. * This very similar to install, but without certain overheads, - * such as calling lookup. Malloc is not used for storing the + * such as calling lookup. Malloc is not used for storing the * keyword strings, since we simply use the static pointers * within keywrds block. */ @@ -565,7 +570,7 @@ initkwds(void) p->nxtptr = hashtab[h % HASHSIZE]; hashtab[h % HASHSIZE] = p; p->name = xstrdup(keywrds[i].knam); - p->defn = xstrdup(null); + p->defn = null; p->hv = h; p->type = keywrds[i].ktyp & TYPEMASK; if ((keywrds[i].ktyp & NOARGS) == 0) @@ -574,7 +579,7 @@ initkwds(void) } /* Look up a builtin type, even if overridden by the user */ -int +int builtin_type(const char *key) { int i; @@ -615,20 +620,20 @@ dump_stack(struct position *t, int lev) fprintf(stderr, " ...\n"); break; } - fprintf(stderr, " %s at line %lu\n", + fprintf(stderr, " %s at line %lu\n", t[i].name, t[i].line); } } -static void +static void enlarge_stack(void) { STACKMAX *= 2; mstack = realloc(mstack, sizeof(stae) * STACKMAX); sstack = realloc(sstack, STACKMAX); if (mstack == NULL || sstack == NULL) - errx(1, "Evaluation stack overflow (%lu)", + errx(1, "Evaluation stack overflow (%lu)", (unsigned long)STACKMAX); } diff --git a/usr.bin/m4/mdef.h b/usr.bin/m4/mdef.h index 7db6d020da..2673acf313 100644 --- a/usr.bin/m4/mdef.h +++ b/usr.bin/m4/mdef.h @@ -37,8 +37,8 @@ * SUCH DAMAGE. * * @(#)mdef.h 8.1 (Berkeley) 6/6/93 - * $FreeBSD: src/usr.bin/m4/mdef.h,v 1.3.12.2 2002/07/15 02:06:15 jmallett Exp $ - * $DragonFly: src/usr.bin/m4/mdef.h,v 1.2 2003/06/17 04:29:28 dillon Exp $ + * $FreeBSD: src/usr.bin/m4/mdef.h,v 1.10 2002/07/15 02:15:12 jmallett Exp $ + * $DragonFly: src/usr.bin/m4/mdef.h,v 1.3 2006/12/27 21:29:02 pavalos Exp $ */ #define MACRTYPE 1 @@ -85,7 +85,7 @@ #define TRACEONTYPE 42 #define TRACEOFFTYPE 43 - + #define TYPEMASK 63 /* Keep bits really corresponding to a type. */ #define RECDEF 256 /* Pure recursive def, don't expand it */ #define NOARGS 512 /* builtin needs no args */ @@ -94,7 +94,7 @@ /* * m4 special characters */ - + #define ARGFLAG '$' #define LPAREN '(' #define RPAREN ')' @@ -121,10 +121,10 @@ #define MAXTOK 512 /* maximum chars in a tokn */ #define HASHSIZE 199 /* maximum size of hashtab */ #define MAXCCHARS 5 /* max size of comment/quote delim */ - + #define ALL 1 #define TOP 0 - + #define TRUE 1 #define FALSE 0 #define cycle for(;;) @@ -132,9 +132,9 @@ /* * m4 data structures */ - + typedef struct ndblock *ndptr; - + struct ndblock { /* hastable structure */ char *name; /* entry name.. */ char *defn; /* definition.. */ @@ -142,9 +142,9 @@ struct ndblock { /* hastable structure */ unsigned int hv; /* hash function value.. */ ndptr nxtptr; /* link to next entry.. */ }; - + #define nil ((ndptr) 0) - + struct keyblk { const char *knam; /* keyword name */ int ktyp; /* keyword type */ diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c index 5945b9da3c..838324e3b1 100644 --- a/usr.bin/m4/misc.c +++ b/usr.bin/m4/misc.c @@ -38,8 +38,8 @@ * * @(#)misc.c 8.1 (Berkeley) 6/6/93 * $OpenBSD: misc.c,v 1.27 2002/04/26 16:15:16 espie Exp $ - * $FreeBSD: src/usr.bin/m4/misc.c,v 1.5.2.4 2002/07/15 02:06:15 jmallett Exp $ - * $DragonFly: src/usr.bin/m4/misc.c,v 1.2 2003/06/17 04:29:28 dillon Exp $ + * $FreeBSD: src/usr.bin/m4/misc.c,v 1.15 2002/07/15 02:15:12 jmallett Exp $ + * $DragonFly: src/usr.bin/m4/misc.c,v 1.3 2006/12/27 21:29:02 pavalos Exp $ */ #include @@ -143,7 +143,7 @@ pbunsigned(unsigned long n) while ((n /= 10) > 0); } -void +void initspaces(void) { int i; @@ -159,7 +159,7 @@ initspaces(void) bbase[i] = buf; } -void +void enlarge_strspace(void) { char *newstrspace; @@ -170,9 +170,9 @@ enlarge_strspace(void) if (!newstrspace) errx(1, "string space overflow"); memcpy(newstrspace, strspace, strsize/2); - for (i = 0; i <= sp; i++) + for (i = 0; i <= sp; i++) if (sstack[i]) - mstack[i].sstr = (mstack[i].sstr - strspace) + mstack[i].sstr = (mstack[i].sstr - strspace) + newstrspace; ep = (ep-strspace) + newstrspace; free(strspace); @@ -204,7 +204,7 @@ enlarge_bufspace(void) void chrsave(int c) { - if (ep >= endest) + if (ep >= endest) enlarge_strspace(); *ep++ = c; } @@ -291,7 +291,7 @@ usage(void) exit(1); } -int +int obtain_char(struct input_file *f) { if (f->c == EOF) @@ -303,7 +303,7 @@ obtain_char(struct input_file *f) return f->c; } -void +void set_input(struct input_file *f, FILE *real, const char *name) { f->file = real; @@ -312,14 +312,14 @@ set_input(struct input_file *f, FILE *real, const char *name) f->name = xstrdup(name); } -void +void release_input(struct input_file *f) { if (f->file != stdin) fclose(f->file); f->c = EOF; /* - * XXX can't free filename, as there might still be + * XXX can't free filename, as there might still be * error information pointing to it. */ } @@ -338,7 +338,7 @@ doprintfilename(struct input_file *f) pbstr(lquote); } -/* +/* * buffer_mark/dump_buffer: allows one to save a mark in a buffer, * and later dump everything that was added since then to a file. */ diff --git a/usr.bin/m4/pathnames.h b/usr.bin/m4/pathnames.h index d0b4b097ba..844b4c566a 100644 --- a/usr.bin/m4/pathnames.h +++ b/usr.bin/m4/pathnames.h @@ -37,8 +37,8 @@ * SUCH DAMAGE. * * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 - * $FreeBSD: src/usr.bin/m4/pathnames.h,v 1.1.1.1.14.2 2002/07/15 02:06:15 jmallett Exp $ - * $DragonFly: src/usr.bin/m4/pathnames.h,v 1.3 2004/01/21 21:48:21 rob Exp $ + * $FreeBSD: src/usr.bin/m4/pathnames.h,v 1.4 2002/05/02 05:25:23 jmallett Exp $ + * $DragonFly: src/usr.bin/m4/pathnames.h,v 1.4 2006/12/27 21:29:02 pavalos Exp $ */ /* diff --git a/usr.bin/m4/stdd.h b/usr.bin/m4/stdd.h index e21e7809c8..1124a08237 100644 --- a/usr.bin/m4/stdd.h +++ b/usr.bin/m4/stdd.h @@ -37,8 +37,8 @@ * SUCH DAMAGE. * * @(#)stdd.h 8.1 (Berkeley) 6/6/93 - * $FreeBSD: src/usr.bin/m4/stdd.h,v 1.2.12.1 2002/07/15 02:06:15 jmallett Exp $ - * $DragonFly: src/usr.bin/m4/stdd.h,v 1.2 2003/06/17 04:29:28 dillon Exp $ + * $FreeBSD: src/usr.bin/m4/stdd.h,v 1.4 2002/07/15 02:15:12 jmallett Exp $ + * $DragonFly: src/usr.bin/m4/stdd.h,v 1.3 2006/12/27 21:29:02 pavalos Exp $ */ /* @@ -50,9 +50,9 @@ #define iswhite(c) ((c) == ' ' || (c) == '\t') -/* - * STREQ is an optimised strcmp(a,b)==0 - * STREQN is an optimised strncmp(a,b,n)==0; assumes n > 0 +/* + * STREQ is an optimised strcmp(a,b)==0 + * STREQN is an optimised strncmp(a,b,n)==0; assumes n > 0 */ #define STREQ(a, b) ((a)[0] == (b)[0] && strcmp(a, b) == 0) #define STREQN(a, b, n) ((a)[0] == (b)[0] && strncmp(a, b, n) == 0) diff --git a/usr.bin/m4/trace.c b/usr.bin/m4/trace.c index 205b11b8cb..0f2f5831dd 100644 --- a/usr.bin/m4/trace.c +++ b/usr.bin/m4/trace.c @@ -23,8 +23,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/usr.bin/m4/trace.c,v 1.6.2.1 2002/07/15 02:06:15 jmallett Exp $ - * $DragonFly: src/usr.bin/m4/trace.c,v 1.2 2003/06/17 04:29:28 dillon Exp $ + * $FreeBSD: src/usr.bin/m4/trace.c,v 1.7 2002/07/15 02:15:12 jmallett Exp $ + * $DragonFly: src/usr.bin/m4/trace.c,v 1.3 2006/12/27 21:29:02 pavalos Exp $ */ #include @@ -109,7 +109,7 @@ mark_traced(const char *name, int on) } } -int +int is_traced(const char *name) { struct t *n; @@ -193,7 +193,7 @@ frame_level(void) int level; int framep; - for (framep = fp, level = 0; framep != 0; + for (framep = fp, level = 0; framep != 0; level++,framep = mstack[framep-2].sfra) ; return level; @@ -212,7 +212,7 @@ print_header(struct input_file *inp) fprintf(traceout, "id %lu: ", expansion_id); } -ssize_t +ssize_t trace(const char *argv[], int argc, struct input_file *inp) { print_header(inp); @@ -228,9 +228,9 @@ trace(const char *argv[], int argc, struct input_file *inp) delim[0] = LPAREN; delim[1] = EOS; for (i = 2; i < argc; i++) { - fprintf(traceout, "%s%s%s%s", delim, - (flags & TRACE_QUOTE) ? lquote : "", - argv[i], + fprintf(traceout, "%s%s%s%s", delim, + (flags & TRACE_QUOTE) ? lquote : "", + argv[i], (flags & TRACE_QUOTE) ? rquote : ""); delim[0] = COMMA; delim[1] = ' '; @@ -251,7 +251,7 @@ trace(const char *argv[], int argc, struct input_file *inp) } } -void +void finish_trace(size_t mark) { fprintf(traceout, " -> ");