autoconf-patches
[Top][All Lists]
Advanced

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

17-m4-token-allow.patch


From: Akim Demaille
Subject: 17-m4-token-allow.patch
Date: 12 Nov 2000 15:56:41 +0100
User-agent: Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.1 (Channel Islands)

This is the end of the AR_FLAGS problem.  But I start to think that we
should also give a means to the users to register other patterns.
Something like ac_token_forbid.  For instance Jim uses jm_.

This would make it possible to use better catching rules: instead of
*_AC_*, we should just catch AC_* and _AC_*.  The old *_AC_* rule was
good to help users catch their own macros, but m4_token_forbid is a
more dignified means to get the same result.  Yes, there is the
backward compatibility issue, but after all it's only 2.50 that
clearly displays the role of *_AC_*, so it's not too bad.  And the
people who really depend on this rule are all on Autoconf's lists :)

I have not provided any AC binding for this macro, but it can be
debated.  It is not documented either, since I'm first waiting for the
final interface to be decided.

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        Provide a means for escaping the forbidden patterns test.

        * tests/tools.at (Forbidden tokens): Test m4_token_allow.
        * m4sugar.m4 (m4_file_append, m4_token_allow): New macros.
        * autoconf.sh (task script): Pass `tmp' and `verbose' to
        finalize.awk.
        (finalize.awk::check_patterns): Eve out from the body.
        (finalize.awk): Read `$tmp/tokens_allowed', and don't complain for
        these exceptions.

Index: autoconf.sh
--- autoconf.sh Sat, 11 Nov 2000 16:02:51 +0100 akim (ace/17_autoconf.s 
1.31.8.32 644)
+++ autoconf.sh Sun, 12 Nov 2000 14:11:30 +0100 akim (ace/17_autoconf.s 
1.31.8.32 644)
@@ -260,7 +260,8 @@
 # Running m4.
 test -f "$autoconf_dir/acsite.m4" && acsite_m4="$autoconf_dir/acsite.m4"
 test -f "$localdir/aclocal.m4"   && aclocal_m4="$localdir/aclocal.m4"
-m4_common="$acsite_m4 $aclocal_m4 -I $autoconf_dir -I $localdir"
+m4_common="$acsite_m4 $aclocal_m4 -I $autoconf_dir -I $localdir \
+           -Dm4_tmpdir=\"$tmp\""
 run_m4="$M4           $autoconf_dir/autoconf.m4  $m4_common"
 run_m4f="$M4 --reload $autoconf_dir/autoconf.m4f $m4_common"

@@ -314,11 +315,40 @@
   # helpful.  Because quoting can sometimes get really painful in m4,
   # there are special @tokens@ to substitute.
   cat >$tmp/finalize.awk <<EOF
+    # Load the list of tokens which escape the forbidden patterns.
+    BEGIN {
+      # Be sure the read GAWK documentation to understand the parens
+      # around \`tmp "/tokens_allowed"'.
+      while ((getline token < (tmp "/tokens_allowed")) > 0)
+       {
+          if (verbose)
+            print "$0: token \`" token "' is allowed" | "cat >&2"
+          tokens_allowed[token] = 1
+       }
+      close (tmp "/tokens_allowed")
+    }
+
     function undefined (file, line, macro)
     {
       print file ":" line ": error: undefined macro: " macro | "cat >&2"
     }

+    # If the token in CODE_PART from BEGIN to END is forbidden,
+    # register it for further complains.
+    function check_pattern (pattern, offset)
+    {
+      if (match (code_part, pattern))
+        {
+         token = substr (code_part, RSTART + offset, RLENGTH - offset)
+         if (! tokens_allowed[token])
+           {
+             macros [token] = oline
+             some_macros_were_not_expanded = 1
+           }
+       }
+    }
+
+    # Body.
     {
       sub(/[         ]*$/, "")
       if (\$0 == "")
@@ -351,21 +381,9 @@
       # We don't \`if ... else if ...' because a single line may contain
       # several unexpanded names.  That's also why the last two \`match'
       # are not grouped together.
-      if (match (code_part, /[^$WORDCHAR](A[$ALPHABET]|m4)_[$WORDCHAR]*/))
-        {
-           macros [substr (code_part, RSTART + 1, RLENGTH - 1)] = oline
-           some_macros_were_not_expanded = 1
-        }
-      if (match (code_part, /^(A[$ALPHABET]|m4)_[$WORDCHAR]*/))
-        {
-           macros [substr (code_part, RSTART, RLENGTH)] = oline
-           some_macros_were_not_expanded = 1
-        }
-      if (match (code_part, /[$WORDCHAR]*_A[$ALPHABET]_[$WORDCHAR]*/))
-        {
-           macros [substr (code_part, RSTART, RLENGTH)] = oline
-           some_macros_were_not_expanded = 1
-        }
+      check_pattern("[^$WORDCHAR](A[$ALPHABET]|m4)_[$WORDCHAR]*", 1)
+      check_pattern("^(A[$ALPHABET]|m4)_[$WORDCHAR]*", 0)
+      check_pattern("[$WORDCHAR]*_A[$ALPHABET]_[$WORDCHAR]*", 0)
       print
     }

@@ -379,11 +397,11 @@
             {
               line++
               for (macro in macros)
-              if (index (\$0, macro))
-                {
-                  delete macros [macro]
-                  undefined("$infile", line, macro)
-                }
+                if (index (\$0, macro))
+                  {
+                    delete macros [macro]
+                    undefined("$infile", line, macro)
+                  }
             }
           close ("$infile")
           for (macro in macros)
@@ -392,7 +410,10 @@
         }
     }
 EOF
-    $AWK -f $tmp/finalize.awk <$tmp/configure >&4 || { (exit 1); exit; }
+    $AWK -v tmp="$tmp" \
+         `$verbose "-v verbose=1"` \
+         -f $tmp/finalize.awk <$tmp/configure >&4 ||
+      { (exit 1); exit; }
   ;; # End of the task script.


@@ -711,7 +732,7 @@
   ## Unknown task ##
   ## ------------ ##

-  *)echo "$me: internal error: unknown task: $task" >&2
+  *) echo "$me: internal error: unknown task: $task" >&2
     (exit 1); exit
 esac

Index: m4sugar.m4
--- m4sugar.m4 Sat, 11 Nov 2000 16:02:51 +0100 akim (ace/b/27_libm4.m4 1.32 644)
+++ m4sugar.m4 Sun, 12 Nov 2000 13:48:00 +0100 akim (ace/b/27_libm4.m4 1.32 644)
@@ -667,6 +667,7 @@ m4_define([m4_divert],
 ])


+
 ## -------------------------------------------- ##
 ## 8. Defining macros with bells and whistles.  ##
 ## -------------------------------------------- ##
@@ -1085,6 +1086,14 @@ m4_define([$1],
                              [_m4_defun_pro([$1])$2[]_m4_defun_epi([$1])])])])


+# m4_token_allow(TOKEN)
+# ---------------------
+# Declare TOKEN is allowed in the output, even if it matches the forbidden
+# patterns such as `m4_*'.
+m4_define([m4_token_allow],
+[m4_file_append(m4_defn([m4_tmpdir])/tokens_allowed, [$1])])
+
+
 ## ----------------------------- ##
 ## Dependencies between macros.  ##
 ## ----------------------------- ##
@@ -1489,3 +1498,22 @@ m4_define([m4_version_unletter],
 m4_define([m4_version_compare],
 [m4_list_cmp((m4_split(m4_version_unletter([$1]), [\.])),
              (m4_split(m4_version_unletter([$2]), [\.])))])
+
+
+
+## ------------------- ##
+## 12. File handling.  ##
+## ------------------- ##
+
+
+# It is a real pity that M4 comes with no macros to bind a diversion
+# to a file.  So we have to deal without, which makes us a lot more
+# fragile that we should.
+
+
+# m4_file_append(FILE-NAME, CONTENT)
+# ----------------------------------
+m4_define([m4_file_append],
+[m4_syscmd([cat >>$1 <<_m4eof
+$2
+_m4eof])])
Index: tests/tools.at
--- tests/tools.at Sat, 11 Nov 2000 16:02:51 +0100 akim (ace/b/30_tools.m4 1.21 
644)
+++ tests/tools.at Sun, 12 Nov 2000 13:40:50 +0100 akim (ace/b/30_tools.m4 1.21 
644)
@@ -330,11 +330,11 @@ AC_DEFUN([TRACE2], [[$2], $1])



-## ----------------------------------------------- ##
-## autoconf's ability to catch unexpanded macros.  ##
-## ----------------------------------------------- ##
+## ------------------ ##
+## Forbidden tokens.  ##
+## ------------------ ##

-AT_SETUP(unexpanded macros)
+AT_SETUP([Forbidden tokens])

 AT_DATA([configure.in],
 [[AC_PLAIN_SCRIPT()dnl
@@ -345,12 +345,19 @@ AC_DEFUN([TRACE2], [[$2], $1])
 BAC_DEFINE
 # AC_THIS_IS_A_COMMENT so just shut up.
 It would be very bad if Autoconf forgot to expand [AC_]OUTPUT!
+
+# This is allowed in spite of the name.
+m4_token_allow([AC_UNDEFINED])
+AC_UNDEFINED
+# But it does not allow this,
+MY_AC_UNDEFINED
 ]])

 AT_CHECK([autoconf --autoconf-dir .. -l $at_srcdir], 1, [],
 [[configure.in:2: error: undefined macro: AB_THIS_IS_PROBABLY_NOT_DEFINED
 configure.in:3: error: undefined macro: AND_AZ_THAT_EITHER
 configure.in:4: error: undefined macro: and_AZ_that_too
+configure.in:14: error: undefined macro: MY_AC_UNDEFINED
 configure:7: error: undefined macro: AC_OUTPUT
 ]])



reply via email to

[Prev in Thread] Current Thread [Next in Thread]