diff options
author | Stuart Henderson <sthen@cvs.openbsd.org> | 2009-10-14 17:19:48 +0000 |
---|---|---|
committer | Stuart Henderson <sthen@cvs.openbsd.org> | 2009-10-14 17:19:48 +0000 |
commit | 5b12bc258fe8c9e40a38b5d45689be67d677bb9e (patch) | |
tree | 9e0f7f43bfddd3c3f782e4ff31d6d91d1ecb59d4 /usr.bin/m4 | |
parent | 63b309eaa3257f1ab6ca190c82bea9ab4960f18f (diff) |
Support the -P option from gnu m4, which prefixes builtins with the
string m4_. Feedback from jmc@, Tobias Ulmer, Matthew Dempsky - thanks!
ok espie@
Diffstat (limited to 'usr.bin/m4')
-rw-r--r-- | usr.bin/m4/extern.h | 3 | ||||
-rw-r--r-- | usr.bin/m4/look.c | 14 | ||||
-rw-r--r-- | usr.bin/m4/m4.1 | 13 | ||||
-rw-r--r-- | usr.bin/m4/main.c | 14 | ||||
-rw-r--r-- | usr.bin/m4/misc.c | 4 |
5 files changed, 35 insertions, 13 deletions
diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h index 26c8afaef52..e2cb60e9f87 100644 --- a/usr.bin/m4/extern.h +++ b/usr.bin/m4/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.48 2008/08/21 20:59:14 espie Exp $ */ +/* $OpenBSD: extern.h,v 1.49 2009/10/14 17:19:47 sthen Exp $ */ /* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */ /*- @@ -173,4 +173,5 @@ extern char scommt[MAXCCHARS+1];/* start character for comment */ extern int synch_lines; /* line synchronisation directives */ extern int mimic_gnu; /* behaves like gnu-m4 */ +extern int prefix_builtins; /* prefix builtin macros with m4_ */ diff --git a/usr.bin/m4/look.c b/usr.bin/m4/look.c index c99cc1a8ae9..e6a0a6ff4be 100644 --- a/usr.bin/m4/look.c +++ b/usr.bin/m4/look.c @@ -1,4 +1,4 @@ -/* $OpenBSD: look.c,v 1.19 2009/06/26 22:03:17 guenther Exp $ */ +/* $OpenBSD: look.c,v 1.20 2009/10/14 17:19:47 sthen Exp $ */ /* * Copyright (c) 1989, 1993 @@ -231,11 +231,19 @@ void setup_builtin(const char *name, unsigned int type) { ndptr n; + char *name2; - n = create_entry(name); + if(prefix_builtins) { + name2 = xalloc(strlen(name)+3+1, NULL); + memcpy(name2, "m4_", 3); + memcpy(name2 + 3, name, strlen(name)+1); + } else + name2 = xstrdup(name); + + n = create_entry(name2); n->builtin_type = type; n->d = xalloc(sizeof(struct macro_definition), NULL); - n->d->defn = xstrdup(name); + n->d->defn = name2; n->d->type = type; n->d->next = NULL; } diff --git a/usr.bin/m4/m4.1 b/usr.bin/m4/m4.1 index 18d0f194f22..e191518b983 100644 --- a/usr.bin/m4/m4.1 +++ b/usr.bin/m4/m4.1 @@ -1,4 +1,4 @@ -.\" @(#) $OpenBSD: m4.1,v 1.55 2009/02/08 17:15:10 jmc Exp $ +.\" @(#) $OpenBSD: m4.1,v 1.56 2009/10/14 17:19:47 sthen Exp $ .\" .\" Copyright (c) 1989, 1993 .\" The Regents of the University of California. All rights reserved. @@ -30,7 +30,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: February 8 2009 $ +.Dd $Mdocdate: October 14 2009 $ .Dt M4 1 .Os .Sh NAME @@ -38,7 +38,7 @@ .Nd macro language processor .Sh SYNOPSIS .Nm m4 -.Op Fl gs +.Op Fl gPs .Oo .Sm off .Fl D Ar name Op No = Ar value @@ -150,6 +150,13 @@ to the include path. .It Fl o Ar filename Send trace output to .Ar filename . +.It Fl P +Prefix all built-in macros with +.Sq m4_ . +For example, instead of writing +.Ic define , +use +.Ic m4_define . .It Fl s Output line synchronization directives, suitable for .Xr cpp 1 . diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c index 377af13a2f3..8b4017d8d68 100644 --- a/usr.bin/m4/main.c +++ b/usr.bin/m4/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.76 2008/08/16 12:21:46 espie Exp $ */ +/* $OpenBSD: main.c,v 1.77 2009/10/14 17:19:47 sthen Exp $ */ /* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */ /*- @@ -77,6 +77,7 @@ 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 */ int synch_lines = 0; /* line synchronisation for C preprocessor */ +int prefix_builtins = 0; /* -P option to prefix builtin keywords */ struct keyblk { char *knam; /* keyword name */ @@ -175,7 +176,6 @@ main(int argc, char *argv[]) signal(SIGINT, onintr); init_macros(); - initkwds(); initspaces(); STACKMAX = INITSTACKMAX; @@ -186,7 +186,7 @@ main(int argc, char *argv[]) outfile = NULL; resizedivs(MAXOUT); - while ((c = getopt(argc, argv, "gst:d:D:U:o:I:")) != -1) + while ((c = getopt(argc, argv, "gst:d:D:U:o:I:P")) != -1) switch(c) { case 'D': /* define something..*/ @@ -200,12 +200,14 @@ main(int argc, char *argv[]) case 'I': addtoincludepath(optarg); break; + case 'P': + prefix_builtins = 1; + break; case 'U': /* undefine... */ macro_popdef(optarg); break; case 'g': mimic_gnu = 1; - setup_builtin("format", FORMATTYPE); break; case 'd': set_trace_flags(optarg); @@ -226,6 +228,10 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; + initkwds(); + if (mimic_gnu) + setup_builtin("format", FORMATTYPE); + active = stdout; /* default active output */ bbase[0] = bufbase; if (!argc) { diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c index 38637b1a8dd..d03978beba7 100644 --- a/usr.bin/m4/misc.c +++ b/usr.bin/m4/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.40 2008/08/21 20:59:14 espie Exp $ */ +/* $OpenBSD: misc.c,v 1.41 2009/10/14 17:19:47 sthen Exp $ */ /* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */ /* @@ -341,7 +341,7 @@ xstrdup(const char *s) void usage() { - fprintf(stderr, "usage: m4 [-gs] [-Dname[=value]] [-d flags] " + fprintf(stderr, "usage: m4 [-gPs] [-Dname[=value]] [-d flags] " "[-I dirname] [-o filename]\n" "\t[-t macro] [-Uname] [file ...]\n"); exit(1); |