version 1.1, 1995/10/18 08:45:35 |
version 1.2, 1996/01/15 01:12:18 |
|
|
/* $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 |
* Copyright (c) 1989, 1993 |
|
|
#if 0 |
#if 0 |
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; |
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; |
#else |
#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 |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
|
|
char *null = ""; /* as it says.. just a null.. */ |
char *null = ""; /* as it says.. just a null.. */ |
char *m4wraps = ""; /* m4wrap string default.. */ |
char *m4wraps = ""; /* m4wrap string default.. */ |
char *progname; /* name of this program */ |
char *progname; /* name of this program */ |
char lquote = LQUOTE; /* left quote character (`) */ |
char lquote[MAXCCHARS+1] = {LQUOTE}; /* left quote character (`) */ |
char rquote = RQUOTE; /* right quote character (') */ |
char rquote[MAXCCHARS+1] = {RQUOTE}; /* right quote character (') */ |
char scommt = SCOMMT; /* start character for comment */ |
char scommt[MAXCCHARS+1] = {SCOMMT}; /* start character for comment */ |
char ecommt = ECOMMT; /* end character for comment */ |
char ecommt[MAXCCHARS+1] = {ECOMMT}; /* end character for comment */ |
|
|
struct keyblk keywrds[] = { /* m4 keywords to be installed */ |
struct keyblk keywrds[] = { /* m4 keywords to be installed */ |
"include", INCLTYPE, |
"include", INCLTYPE, |
|
|
ndptr inspect(); |
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.. |
* macro - the work horse.. |
*/ |
*/ |
void |
void |
|
|
register int nlpar; |
register int nlpar; |
|
|
cycle { |
cycle { |
if ((t = gpbc()) == '_' || isalpha(t)) { |
t = gpbc(); |
|
if (t == '_' || isalpha(t)) { |
putback(t); |
putback(t); |
if ((p = inspect(s = token)) == nil) { |
if ((p = inspect(s = token)) == nil) { |
if (sp < 0) |
if (sp < 0) |
|
|
* non-alpha single-char token seen.. |
* non-alpha single-char token seen.. |
* [the order of else if .. stmts is important.] |
* [the order of else if .. stmts is important.] |
*/ |
*/ |
else if (t == lquote) { /* strip quotes */ |
else if (LOOK_AHEAD(t,lquote)) { /* strip quotes */ |
nlpar = 1; |
nlpar = 1; |
do { |
do { |
if ((l = gpbc()) == rquote) |
l = gpbc(); |
|
if (LOOK_AHEAD(l,rquote)) |
nlpar--; |
nlpar--; |
else if (l == lquote) |
else if (LOOK_AHEAD(l,lquote)) |
nlpar++; |
nlpar++; |
else if (l == EOF) |
else if (l == EOF) |
oops("missing right quote", ""); |
oops("missing right quote", ""); |
|
|
while (nlpar != 0); |
while (nlpar != 0); |
} |
} |
|
|
else if (sp < 0) { /* not in a macro at all */ |
else if (sp < 0 && LOOK_AHEAD(t, scommt)) { |
if (t == scommt) { /* comment handling here */ |
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); |
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.. */ |
putc(t, active); /* output directly.. */ |
} |
} |
|
|