=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/m4/main.c,v retrieving revision 1.26 retrieving revision 1.27 diff -c -r1.26 -r1.27 *** src/usr.bin/m4/main.c 2000/01/12 17:49:53 1.26 --- src/usr.bin/m4/main.c 2000/01/13 17:35:09 1.27 *************** *** 1,4 **** ! /* $OpenBSD: main.c,v 1.26 2000/01/12 17:49:53 espie Exp $ */ /* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */ /*- --- 1,4 ---- ! /* $OpenBSD: main.c,v 1.27 2000/01/13 17:35:09 espie Exp $ */ /* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */ /*- *************** *** 47,53 **** #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #else ! static char rcsid[] = "$OpenBSD: main.c,v 1.26 2000/01/12 17:49:53 espie Exp $"; #endif #endif /* not lint */ --- 47,53 ---- #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #else ! static char rcsid[] = "$OpenBSD: main.c,v 1.27 2000/01/13 17:35:09 espie Exp $"; #endif #endif /* not lint */ *************** *** 139,144 **** --- 139,153 ---- extern int optind; extern char *optarg; + #define MAXRECORD 50 + static struct position { + char *name; + unsigned long line; + } quotes[MAXRECORD], paren[MAXRECORD]; + + static void record __P((struct position *, int)); + static void dump_stack __P((struct position *, int)); + static void macro __P((void)); static void initkwds __P((void)); static ndptr inspect __P((char, char *)); *************** *** 304,311 **** } } else if (t == EOF) { ! if (sp > -1) ! errx(1, "unexpected end of input"); if (ilevel <= 0) break; /* all done thanks.. */ release_input(infile+ilevel--); --- 313,323 ---- } } else if (t == EOF) { ! if (sp > -1) { ! warnx( "unexpected end of input, unclosed parenthesis:"); ! dump_stack(paren, PARLEV); ! exit(1); ! } if (ilevel <= 0) break; /* all done thanks.. */ release_input(infile+ilevel--); *************** *** 317,323 **** * [the order of else if .. stmts is important.] */ else if (LOOK_AHEAD(t,lquote)) { /* strip quotes */ ! nlpar = 1; do { l = gpbc(); --- 329,336 ---- * [the order of else if .. stmts is important.] */ else if (LOOK_AHEAD(t,lquote)) { /* strip quotes */ ! nlpar = 0; ! record(quotes, nlpar++); do { l = gpbc(); *************** *** 325,337 **** nlpar--; s = rquote; } else if (LOOK_AHEAD(l,lquote)) { ! nlpar++; s = lquote; } else if (l == EOF) { if (nlpar == 1) ! errx(1, "missing right quote."); else ! errx(1, "missing %d right quotes.", nlpar); } else { chars[0] = l; chars[1] = EOS; --- 338,352 ---- nlpar--; s = rquote; } else if (LOOK_AHEAD(l,lquote)) { ! record(quotes, nlpar++); s = lquote; } else if (l == EOF) { if (nlpar == 1) ! warnx("unclosed quote:"); else ! warnx("%d unclosed quotes:", nlpar); ! dump_stack(quotes, nlpar); ! exit(1); } else { chars[0] = l; chars[1] = EOS; *************** *** 370,376 **** while (isspace(l = gpbc())) ; /* skip blank, tab, nl.. */ putback(l); ! PARLEV++; break; case RPAREN: --- 385,391 ---- while (isspace(l = gpbc())) ; /* skip blank, tab, nl.. */ putback(l); ! record(paren, PARLEV++); break; case RPAREN: *************** *** 501,503 **** --- 516,545 ---- } } + static void + record(t, lev) + struct position *t; + int lev; + { + if (lev < MAXRECORD) { + t[lev].name = CURRENT_NAME; + t[lev].line = CURRENT_LINE; + } + } + + static void + dump_stack(t, lev) + struct position *t; + int lev; + { + int i; + + for (i = 0; i < lev; i++) { + if (i == MAXRECORD) { + fprintf(stderr, " ...\n"); + break; + } + fprintf(stderr, " %s at line %lu\n", + t[i].name, t[i].line); + } + }