NetBSD-Bugs archive

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

Re: bin/60921: m4 --undefine argument does not undefine



The following reply was made to PR bin/60921; it has been noted by GNATS.

From: mlelstv%serpens.de@localhost (Michael van Elst)
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: bin/60921: m4 --undefine argument does not undefine
Date: Sun, 25 Oct 2026 23:15:04 -0000 (UTC)

 phil%hagelb.org@localhost (Phil Hagelberg) writes:
 
 >"Michael van Elst via gnats" <gnats-admin%NetBSD.org@localhost> writes:
 
 >>  For now, it doesn't make sense to request a GNU extension and then
 >>  to undefine (or redefine) it. But with future multiple GNU extensions
 >>  you may want to ask for them but also remove specific ones.
 
 >I don't know what this means; I'm not really concerned with GNU. I am
 >just basing this off the seemingly intended behavior described in the
 >NetBSD man page for m4.
 
 
 The option '-g' or '-G' select if a GNU extension (the 'format' builtin)
 is enabled. It's the same kind of builtin that 'dnl' is. So if you talk
 about undefining or redefining builtins, you should also consider this one.
 
 
 
 >Maybe I should back up. My real purpose for reporting this bug is that I
 >wish to use m4 to process existing documents that have the word "shift"
 >in them. Right now NetBSD's m4 treats that word as a macro even when it
 >is clearly not being used as such. When I read the manual, I saw that it
 >said I should be able to undefine it so that these documents could be
 >processed normally, but that is not the case.
 
 Indeed, and a few years ago that was possible when option processing
 wasn't yet broken.
 
 
 
 {1} echo "foo bar dnl bla" | m4
 foo bar {2}
 {2} echo "foo bar dnl bla" | m4 --undefine dnl
 foo bar dnl bla
 
 
 This works after applying the following patch:
 
 ndex: usr.bin/m4/main.c
 ===================================================================
 RCS file: /cvsroot/src/usr.bin/m4/main.c,v
 retrieving revision 1.52
 diff -p -u -r1.52 main.c
 --- usr.bin/m4/main.c   10 Jun 2026 22:25:02 -0000      1.52
 +++ usr.bin/m4/main.c   25 Oct 2026 23:13:12 -0000
 @@ -211,6 +211,8 @@ main(int argc, char *argv[])
         int n;
         int error;
         char *p;
 +       int save_gnu;
 +       int save_prefix;
  
         setprogname(argv[0]);
  
 @@ -228,6 +230,38 @@ main(int argc, char *argv[])
         outfile = NULL;
         resizedivs(MAXOUT);
  
 +       save_gnu = mimic_gnu;
 +       save_prefix = prefix_builtins;
 +
 +       /*
 +        * We need to know if -P, -g or -G is there before checking -D and -U.
 +        */
 +       while ((c = getopt_long(argc, argv, "D:d:EF:GgI:iL:o:PR:Qst:U:v",
 +           longopts, NULL)) != -1) {
 +               switch(c) {
 +               case 'G':
 +                       mimic_gnu = 0;
 +                       break;
 +               case 'g':
 +                       mimic_gnu = 1;
 +                       break;
 +               case 'P':
 +                       prefix_builtins = 1;
 +                       break;
 +               }
 +       }
 +       optind = 1;
 +
 +       initkwds();
 +       if (mimic_gnu)
 +               setup_builtin("format", FORMATTYPE);
 +
 +       /*
 +        * reset options
 +        */
 +       mimic_gnu = save_gnu;
 +       prefix_builtins = save_prefix;
 +
         while ((c = getopt_long(argc, argv, "D:d:EF:GgI:iL:o:PR:Qst:U:v",
             longopts, NULL)) != -1)
                 switch(c) {
 @@ -320,10 +354,6 @@ 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;
 



Home | Main Index | Thread Index | Old Index