add -P flag to m4(1)
Peter Avalos
pavalos at theshell.com
Wed Dec 27 22:58:50 PST 2006
Here's a patch that will add the -P option to our m4. Please let me know
what you think. This is needed to bring in the latest flex sources.
http://www.theshell.com/~pavalos/wip/m4.patch
Thanks,
Peter
Index: usr.bin/m4/m4.1
===================================================================
RCS file: /home/dcvs/src/usr.bin/m4/m4.1,v
retrieving revision 1.3
diff -u -r1.3 m4.1
--- usr.bin/m4/m4.1 27 Dec 2006 21:29:02 -0000 1.3
+++ usr.bin/m4/m4.1 28 Dec 2006 00:10:12 -0000
@@ -12,7 +12,7 @@
.Nm
.Op Fl d Ar flags
.Op Fl t Ar name
-.Op Fl gs
+.Op Fl Pgs
.Op Fl D Ar name Ns Op = Ns Ar value
.Op Fl U Ar name
.Op Fl I Ar dirname
@@ -69,6 +69,19 @@
.It Fl U Ar name
Undefine the symbol
.Ar name .
+.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 I Ar dirname
Add directory
.Ar dirname
Index: usr.bin/m4/main.c
===================================================================
RCS file: /home/dcvs/src/usr.bin/m4/main.c,v
retrieving revision 1.3
diff -u -r1.3 main.c
--- usr.bin/m4/main.c 27 Dec 2006 21:29:02 -0000 1.3
+++ usr.bin/m4/main.c 28 Dec 2006 00:24:20 -0000
@@ -82,6 +82,7 @@
int oindex = 0; /* diversion index.. */
char null[] = ""; /* as it says.. just a null.. */
const char *m4wraps = ""; /* m4wrap string default.. */
+int m4prefix = 0; /* prefix keywords with m4_ */
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 */
@@ -177,6 +178,14 @@
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
signal(SIGINT, onintr);
+ /*
+ * We need to know if -P is there before checking -D and -U.
+ */
+ while ((c = getopt(argc, argv, "Pgst:d:D:U:o:I:")) != -1)
+ if (c == 'P')
+ m4prefix = 1;
+ optind = 1;
+
initkwds();
initspaces();
STACKMAX = INITSTACKMAX;
@@ -188,7 +197,7 @@
outfile = NULL;
resizedivs(MAXOUT);
- while ((c = getopt(argc, argv, "gst:d:D:U:o:I:")) != -1)
+ while ((c = getopt(argc, argv, "Pgst:d:D:U:o:I:")) != -1)
switch(c) {
case 'D': /* define something..*/
for (p = optarg; *p; p++)
@@ -203,6 +212,8 @@
case 'I':
addtoincludepath(optarg);
break;
+ case 'P':
+ break;
case 'U': /* undefine... */
remhash(optarg, TOP);
break;
@@ -563,9 +574,16 @@
size_t i;
unsigned int h;
ndptr p;
+ char *k;
for (i = 0; i < MAXKEYS; i++) {
- h = hash(keywrds[i].knam);
+ k = (char *)keywrds[i].knam;
+ if (m4prefix) {
+ if (asprintf(&k, "m4_%s", k) == -1)
+ err(1, "asprintf");
+ keywrds[i].knam = k;
+ }
+ h = hash(k);
p = (ndptr) xalloc(sizeof(struct ndblock));
p->nxtptr = hashtab[h % HASHSIZE];
hashtab[h % HASHSIZE] = p;
Attachment:
pgp00010.pgp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pgp00010.pgp
Type: application/octet-stream
Size: 189 bytes
Desc: "Description: PGP signature"
URL: <http://lists.dragonflybsd.org/pipermail/submit/attachments/20061227/bf1aa5b5/attachment-0018.obj>
More information about the Submit
mailing list