Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/m4 Implement the very useful `-P' option from GNU's ...



details:   https://anonhg.NetBSD.org/src/rev/2a844ef29260
branches:  trunk
changeset: 473964:2a844ef29260
user:      tv <tv%NetBSD.org@localhost>
date:      Wed Jun 23 19:09:35 1999 +0000

description:
Implement the very useful `-P' option from GNU's m4 (causes all builtin
macros to be prefixed with the string `m4_').

diffstat:

 usr.bin/m4/m4.1   |  16 +++++++++++++++-
 usr.bin/m4/main.c |  27 +++++++++++++++++++++------
 2 files changed, 36 insertions(+), 7 deletions(-)

diffs (114 lines):

diff -r f1200cc15baf -r 2a844ef29260 usr.bin/m4/m4.1
--- a/usr.bin/m4/m4.1   Wed Jun 23 19:00:17 1999 +0000
+++ b/usr.bin/m4/m4.1   Wed Jun 23 19:09:35 1999 +0000
@@ -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
 .Dt m4 1
@@ -8,6 +8,7 @@
 .Nd macro language processor
 .Sh SYNOPSIS
 .Nm
+.Op Fl P
 .Oo
 .Fl D Ns Ar name Ns Op Ar =value
 .Oc
@@ -38,6 +39,19 @@
 .Pp
 The options are as follows:
 .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
 .Ar =value
 .Oc
diff -r f1200cc15baf -r 2a844ef29260 usr.bin/m4/main.c
--- a/usr.bin/m4/main.c Wed Jun 23 19:00:17 1999 +0000
+++ b/usr.bin/m4/main.c Wed Jun 23 19:09:35 1999 +0000
@@ -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
@@ -46,7 +46,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.1 (Berkeley) 6/6/93";
 #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 /* not lint */
 
@@ -91,6 +91,7 @@
 char *null = "";                /* as it says.. just a null..  */
 char *m4wraps = "";             /* m4wrap string default..     */
 char *progname;                        /* name of this program        */
+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 */
@@ -166,9 +167,17 @@
        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, "tPD:U:")) != -1)
+               if (c == 'P')
+                       m4prefix = 1;
+       optind = 1;
+
        initkwds();
 
-       while ((c = getopt(argc, argv, "tD:U:o:")) != -1)
+       while ((c = getopt(argc, argv, "tPD:U:")) != -1)
                switch(c) {
 
                case 'D':               /* define something..*/
@@ -182,8 +191,10 @@
                case 'U':               /* undefine...       */
                        remhash(optarg, TOP);
                        break;
-               case 'o':               /* specific output   */
+               case 'P':
+                       break;
                case '?':
+               default:
                        usage();
                }
 
@@ -483,13 +494,17 @@
        int i;
        int h;
        ndptr p;
+       char *k;
 
        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->nxtptr = hashtab[h];
                hashtab[h] = p;
-               p->name = keywrds[i].knam;
+               p->name = k;
                p->defn = null;
                p->type = keywrds[i].ktyp | STATIC;
        }



Home | Main Index | Thread Index | Old Index