Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/m4 More gnu compatibility:



details:   https://anonhg.NetBSD.org/src/rev/142ca02c7144
branches:  trunk
changeset: 342960:142ca02c7144
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Jan 16 16:56:21 2016 +0000

description:
More gnu compatibility:
        - handle macros > $9
        - handle character remapping the the gnu way.
Add a shortcut for the "fake freeze" files to not expand include macros
during thawing.

diffstat:

 usr.bin/m4/eval.c |  55 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 42 insertions(+), 13 deletions(-)

diffs (103 lines):

diff -r 7aade563f262 -r 142ca02c7144 usr.bin/m4/eval.c
--- a/usr.bin/m4/eval.c Sat Jan 16 01:14:39 2016 +0000
+++ b/usr.bin/m4/eval.c Sat Jan 16 16:56:21 2016 +0000
@@ -1,5 +1,5 @@
 /*     $OpenBSD: eval.c,v 1.66 2008/08/21 21:01:47 espie Exp $ */
-/*     $NetBSD: eval.c,v 1.23 2015/01/29 19:26:20 christos Exp $       */
+/*     $NetBSD: eval.c,v 1.24 2016/01/16 16:56:21 christos Exp $       */
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,9 +42,10 @@
 #include "nbtool_config.h"
 #endif
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: eval.c,v 1.23 2015/01/29 19:26:20 christos Exp $");
+__RCSID("$NetBSD: eval.c,v 1.24 2016/01/16 16:56:21 christos Exp $");
 
 #include <sys/types.h>
+#include <ctype.h>
 #include <err.h>
 #include <errno.h>
 #include <limits.h>
@@ -541,7 +542,16 @@
                        case '7':
                        case '8':
                        case '9':
-                               if ((argno = *p - '0') < argc - 1)
+                               argno = *p - '0';
+                               if (mimic_gnu) {
+                                       const unsigned char *q =
+                                           (const unsigned char *)p;
+                                       while (isdigit(*++q)) {
+                                               bp--;
+                                               argno = argno * 10 + *q - '0';
+                                       }
+                               }
+                               if (argno < argc - 1)
                                        pbstr(argv[argno + 1]);
                                break;
                        case '*':
@@ -707,6 +717,10 @@
 static int
 doincl(const char *ifile)
 {
+#ifndef REAL_FREEZE
+       if (thawing)
+               return 1;
+#endif
        if (ilevel + 1 == MAXINP)
                m4errx(1, "too many include files.");
        if (fopen_trypath(infile+ilevel+1, ifile) != NULL) {
@@ -915,6 +929,7 @@
 {
        const char *tmp;
        unsigned char sch, dch;
+       unsigned char found[256];
        static char frombis[257];
        static char tobis[257];
        static unsigned char mapvec[256] = {
@@ -951,19 +966,33 @@
         * create a mapping between "from" and
         * "to"
         */
-               while (*from)
-                       mapvec[(unsigned char)(*from++)] = (*to) ? 
-                               (unsigned char)(*to++) : 0;
+               memset(found, 0, sizeof(found));
+               for (; (sch = (unsigned char)*from) != '\0'; from++) {
+                       if (!mimic_gnu || !found[sch]) {
+                               found[sch] = 1;
+                               mapvec[sch] = *to;
+                       }
+                       if (*to)
+                               to++;
+               }
 
-               while (*src) {
-                       sch = (unsigned char)(*src++);
-                       dch = mapvec[sch];
-                       while (dch != sch) {
-                               sch = dch;
+               if (mimic_gnu) {
+                       for (; (sch = (unsigned char)*src) != '\0'; src++) {
+                               if (!found[sch])
+                                       *dest++ = sch;
+                               else if ((dch = mapvec[sch]) != '\0')
+                                       *dest++ = dch;
+                       }
+               } else {
+                       while (*src) {
                                dch = mapvec[sch];
+                               while (dch != sch) {
+                                       sch = dch;
+                                       dch = mapvec[sch];
+                               }
+                               if ((*dest = (char)dch))
+                                       dest++;
                        }
-                       if ((*dest = (char)dch))
-                               dest++;
                }
        /*
         * restore all the changed characters



Home | Main Index | Thread Index | Old Index