-/* $NetBSD: eval.c,v 1.4 1995/09/28 05:37:28 tls Exp $ */
+/* $NetBSD: eval.c,v 1.5 1996/01/13 23:25:23 pk Exp $ */
/*
* Copyright (c) 1989, 1993
#if 0
static char sccsid[] = "@(#)eval.c 8.2 (Berkeley) 4/27/95";
#else
-static char rcsid[] = "$NetBSD: eval.c,v 1.4 1995/09/28 05:37:28 tls Exp $";
+static char rcsid[] = "$NetBSD: eval.c,v 1.5 1996/01/13 23:25:23 pk Exp $";
#endif
#endif /* not lint */
* argv[2])
*/
if (argc > 3) {
+ int k;
for (n = argc - 1; n > 3; n--) {
- putback(rquote);
+ k = strlen(rquote);
+ while (k--)
+ putback(rquote[k]);
pbstr(argv[n]);
- putback(lquote);
+ k = strlen(lquote);
+ while (k--)
+ putback(lquote[k]);
putback(',');
}
- putback(rquote);
+ k = strlen(rquote);
+ while (k--)
+ putback(rquote[k]);
pbstr(argv[3]);
- putback(lquote);
+ k = strlen(lquote);
+ while (k--)
+ putback(lquote[k]);
}
break;
register ndptr p;
if ((p = lookup(name)) != nil && p->defn != null) {
- putback(rquote);
+ int n = strlen(rquote);
+ while (n--)
+ putback(rquote[n]);
pbstr(p->defn);
- putback(lquote);
+ n = strlen(lquote);
+ while (n--)
+ putback(lquote[n]);
}
}
{
if (argc > 2) {
if (*argv[2])
- lquote = *argv[2];
+ strncpy(lquote, argv[2], MAXCCHARS);
if (argc > 3) {
if (*argv[3])
- rquote = *argv[3];
+ strncpy(rquote, argv[3], MAXCCHARS);
}
else
- rquote = lquote;
+ strcpy(rquote, lquote);
}
else {
- lquote = LQUOTE;
- rquote = RQUOTE;
+ lquote[0] = LQUOTE, lquote[1] = '\0';
+ rquote[0] = RQUOTE, rquote[1] = '\0';
}
}
{
if (argc > 2) {
if (*argv[2])
- scommt = *argv[2];
+ strncpy(scommt, argv[2], MAXCCHARS);
if (argc > 3) {
if (*argv[3])
- ecommt = *argv[3];
+ strncpy(ecommt, argv[3], MAXCCHARS);
}
else
- ecommt = ECOMMT;
+ ecommt[0] = ECOMMT, ecommt[1] = '\0';
}
else {
- scommt = SCOMMT;
- ecommt = ECOMMT;
+ scommt[0] = SCOMMT, scommt[1] = '\0';
+ ecommt[0] = ECOMMT, ecommt[1] = '\0';
}
}
-/* $NetBSD: extern.h,v 1.2 1995/09/28 05:37:34 tls Exp $ */
+/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
/*-
* Copyright (c) 1991, 1993
extern char buf[]; /* push-back buffer */
extern char *bufbase; /* buffer base for this ilevel */
extern char *bbase[]; /* buffer base per ilevel */
-extern char ecommt; /* end character for comment */
+extern char ecommt[]; /* end character for comment */
extern char *endest; /* end of string space */
extern char *endpbb; /* end of push-back buffer */
extern char *ep; /* first free char in strspace */
-extern char lquote; /* left quote character (`) */
+extern char lquote[]; /* left quote character (`) */
extern char *m4temp; /* filename for diversions */
extern char *m4wraps; /* m4wrap string default. */
extern char *null; /* as it says.. just a null. */
extern char *progname; /* program name */
-extern char rquote; /* right quote character (') */
-extern char scommt; /* start character for comment */
+extern char rquote[]; /* right quote character (') */
+extern char scommt[]; /* start character for comment */
-/* $NetBSD: main.c,v 1.10 1995/09/29 00:27:51 cgd Exp $ */
+/* $NetBSD: main.c,v 1.11 1996/01/13 23:25:26 pk Exp $ */
/*-
* Copyright (c) 1989, 1993
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$NetBSD: main.c,v 1.10 1995/09/29 00:27:51 cgd Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.11 1996/01/13 23:25:26 pk Exp $";
#endif
#endif /* not lint */
char *null = ""; /* as it says.. just a null.. */
char *m4wraps = ""; /* m4wrap string default.. */
char *progname; /* name of this program */
-char lquote = LQUOTE; /* left quote character (`) */
-char rquote = RQUOTE; /* right quote character (') */
-char scommt = SCOMMT; /* start character for comment */
-char ecommt = ECOMMT; /* end character for comment */
+char lquote[MAXCCHARS+1] = {LQUOTE}; /* left quote character (`) */
+char rquote[MAXCCHARS+1] = {RQUOTE}; /* right quote character (') */
+char scommt[MAXCCHARS+1] = {SCOMMT}; /* start character for comment */
+char ecommt[MAXCCHARS+1] = {ECOMMT}; /* end character for comment */
struct keyblk keywrds[] = { /* m4 keywords to be installed */
"include", INCLTYPE,
ndptr inspect();
+/*
+ * Look ahead (at most MAXCCHARS characters) for `token'.
+ * (on input `t == token[0]')
+ * Used for comment and quoting delimiters.
+ * Returns 1 if `token' present; copied to output.
+ * 0 if `token' not found; all characters pushed back
+ */
+int
+do_look_ahead(t, token)
+ int t;
+ char *token;
+{
+ int i;
+
+ if (t != token[0])
+ oops("internal error", "");
+
+ for (i = 1; *++token; i++) {
+ t = gpbc();
+ if (t == EOF || t != *token) {
+ if (t != EOF)
+ putback(t);
+ while (--i)
+ putback(*--token);
+ return 0;
+ }
+ }
+ return 1;
+}
+
+#define LOOK_AHEAD(t, token) ((t)==(token)[0] && do_look_ahead(t,token))
+
/*
* macro - the work horse..
*/
register int nlpar;
cycle {
- if ((t = gpbc()) == '_' || isalpha(t)) {
+ t = gpbc();
+ if (t == '_' || isalpha(t)) {
putback(t);
if ((p = inspect(s = token)) == nil) {
if (sp < 0)
* non-alpha single-char token seen..
* [the order of else if .. stmts is important.]
*/
- else if (t == lquote) { /* strip quotes */
+ else if (LOOK_AHEAD(t,lquote)) { /* strip quotes */
nlpar = 1;
do {
- if ((l = gpbc()) == rquote)
+ l = gpbc();
+ if (LOOK_AHEAD(l,rquote))
nlpar--;
- else if (l == lquote)
+ else if (LOOK_AHEAD(l,lquote))
nlpar++;
else if (l == EOF)
oops("missing right quote", "");
while (nlpar != 0);
}
- else if (sp < 0) { /* not in a macro at all */
- if (t == scommt) { /* comment handling here */
+ else if (sp < 0 && LOOK_AHEAD(t, scommt)) {
+ int i;
+ for (i = 0; i < MAXCCHARS && scommt[i]; i++)
+ putc(scommt[i], active);
+
+ for(;;) {
+ t = gpbc();
+ if (LOOK_AHEAD(t, ecommt)) {
+ for (i = 0; i < MAXCCHARS && ecommt[i];
+ i++)
+ putc(ecommt[i], active);
+ break;
+ }
+ if (t == EOF)
+ break;
putc(t, active);
- while ((t = gpbc()) != ecommt)
- putc(t, active);
}
+ }
+
+ else if (sp < 0) { /* not in a macro at all */
putc(t, active); /* output directly.. */
}