Implement the very useful `-P' option from GNU's m4 (causes all builtin
macros to be prefixed with the string `m4_').
This commit is contained in:
parent
4fd8325ec6
commit
01a5ecacd3
|
@ -1,4 +1,4 @@
|
||||||
.\" $NetBSD: m4.1,v 1.8 1998/01/23 23:05:34 lukem Exp $
|
.\" $NetBSD: m4.1,v 1.9 1999/06/23 19:09:35 tv Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd January 26, 1993
|
.Dd January 26, 1993
|
||||||
.Dt m4 1
|
.Dt m4 1
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
.Nd macro language processor
|
.Nd macro language processor
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
|
.Op Fl P
|
||||||
.Oo
|
.Oo
|
||||||
.Fl D Ns Ar name Ns Op Ar =value
|
.Fl D Ns Ar name Ns Op Ar =value
|
||||||
.Oc
|
.Oc
|
||||||
|
@ -38,6 +39,19 @@ the quote characters with the changequote built-in macro.
|
||||||
.Pp
|
.Pp
|
||||||
The options are as follows:
|
The options are as follows:
|
||||||
.Bl -tag -width "-Dname[=value]xxx"
|
.Bl -tag -width "-Dname[=value]xxx"
|
||||||
|
.It Fl P
|
||||||
|
Prefixes all
|
||||||
|
.Nm
|
||||||
|
builtin macros with the string
|
||||||
|
.Li m4_ .
|
||||||
|
This changes the macro names
|
||||||
|
.Li dnl
|
||||||
|
to
|
||||||
|
.Li m4_dnl ,
|
||||||
|
.Li index
|
||||||
|
to
|
||||||
|
.Li m4_index ,
|
||||||
|
and so forth.
|
||||||
.It Fl D Ns Ar name Ns Oo
|
.It Fl D Ns Ar name Ns Oo
|
||||||
.Ar =value
|
.Ar =value
|
||||||
.Oc
|
.Oc
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: main.c,v 1.21 1999/04/20 08:05:52 mrg Exp $ */
|
/* $NetBSD: main.c,v 1.22 1999/06/23 19:09:35 tv Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1989, 1993
|
* Copyright (c) 1989, 1993
|
||||||
|
@ -46,7 +46,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
|
||||||
#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
|
||||||
__RCSID("$NetBSD: main.c,v 1.21 1999/04/20 08:05:52 mrg Exp $");
|
__RCSID("$NetBSD: main.c,v 1.22 1999/06/23 19:09:35 tv Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
|
@ -91,6 +91,7 @@ int oindex = 0; /* diversion index.. */
|
||||||
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 */
|
||||||
|
int m4prefix = 0; /* prefix keywords with m4_ */
|
||||||
char lquote[MAXCCHARS+1] = {LQUOTE}; /* left quote character (`) */
|
char lquote[MAXCCHARS+1] = {LQUOTE}; /* left quote character (`) */
|
||||||
char rquote[MAXCCHARS+1] = {RQUOTE}; /* right quote character (') */
|
char rquote[MAXCCHARS+1] = {RQUOTE}; /* right quote character (') */
|
||||||
char scommt[MAXCCHARS+1] = {SCOMMT}; /* start character for comment */
|
char scommt[MAXCCHARS+1] = {SCOMMT}; /* start character for comment */
|
||||||
|
@ -166,9 +167,17 @@ main(argc,argv)
|
||||||
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
|
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
|
||||||
signal(SIGINT, onintr);
|
signal(SIGINT, onintr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We need to know if -P is there before checking -D and -U.
|
||||||
|
*/
|
||||||
|
while ((c = getopt(argc, argv, "tPD:U:")) != -1)
|
||||||
|
if (c == 'P')
|
||||||
|
m4prefix = 1;
|
||||||
|
optind = 1;
|
||||||
|
|
||||||
initkwds();
|
initkwds();
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "tD:U:o:")) != -1)
|
while ((c = getopt(argc, argv, "tPD:U:")) != -1)
|
||||||
switch(c) {
|
switch(c) {
|
||||||
|
|
||||||
case 'D': /* define something..*/
|
case 'D': /* define something..*/
|
||||||
|
@ -182,8 +191,10 @@ main(argc,argv)
|
||||||
case 'U': /* undefine... */
|
case 'U': /* undefine... */
|
||||||
remhash(optarg, TOP);
|
remhash(optarg, TOP);
|
||||||
break;
|
break;
|
||||||
case 'o': /* specific output */
|
case 'P':
|
||||||
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
|
default:
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,13 +494,17 @@ initkwds()
|
||||||
int i;
|
int i;
|
||||||
int h;
|
int h;
|
||||||
ndptr p;
|
ndptr p;
|
||||||
|
char *k;
|
||||||
|
|
||||||
for (i = 0; i < MAXKEYS; i++) {
|
for (i = 0; i < MAXKEYS; i++) {
|
||||||
h = hash(keywrds[i].knam);
|
k = keywrds[i].knam;
|
||||||
|
if (m4prefix && asprintf(&k, "m4_%s", k) == -1)
|
||||||
|
err(1, "asprintf");
|
||||||
|
h = hash(k);
|
||||||
p = (ndptr) xalloc(sizeof(struct ndblock));
|
p = (ndptr) xalloc(sizeof(struct ndblock));
|
||||||
p->nxtptr = hashtab[h];
|
p->nxtptr = hashtab[h];
|
||||||
hashtab[h] = p;
|
hashtab[h] = p;
|
||||||
p->name = keywrds[i].knam;
|
p->name = k;
|
||||||
p->defn = null;
|
p->defn = null;
|
||||||
p->type = keywrds[i].ktyp | STATIC;
|
p->type = keywrds[i].ktyp | STATIC;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue