[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
60-m4-patterns.patch
From: |
Akim Demaille |
Subject: |
60-m4-patterns.patch |
Date: |
Tue, 05 Dec 2000 09:44:17 +0100 |
Index: ChangeLog
from Akim Demaille <address@hidden>
* m4sugar.m4 (m4_dquote, m4_pattern_forbid, m4_pattern_allow)
(m4_cr_letters, m4_cr_LETTERS, m4_cr_Letters, m4_cr_digits)
(m4_cr_symbols1, m4_cr_symbols2, m4_re_string, m4_re_string)
(m4_init): New macros.
(m4_token_allow): Remove.
* acgeneral.m4: Don't push BODY into the diversion stack.
(AC_PLAIN_SCRIPT): Do it.
Call m4_init, define the Autoconf patterns.
(AC_INIT): Use AC_PLAIN_SCRIPT.
Remove the useless `dnl' (those where the current diversion is
KILL).
* autoconf.sh (m4_common): Fix quotation.
(finalize.awk): Load forbidden.rx and allowed.rx.
Split the line into tokens, and check their validity.
* tests/tools.at (Forbidden tokens): Adjust.
Index: acgeneral.m4
--- acgeneral.m4 Sat, 02 Dec 2000 12:27:01 +0100 akim (ace/27_acgeneral.
1.169.8.98 644)
+++ acgeneral.m4 Sat, 02 Dec 2000 12:30:01 +0100 akim (ace/27_acgeneral.
1.169.8.98 644)
@@ -154,9 +154,8 @@ m4_define([AC_DIVERT_POP],
[m4_divert_pop($@)])
-# Initialize the diversion setup.
-m4_define([_m4_divert_diversion], _m4_divert([BODY]))
# Throw away output until AC_INIT is called.
+# FIXME: Should not be here.
m4_pushdef([_m4_divert_diversion], _m4_divert([KILL]))
@@ -194,6 +193,7 @@ m4_define([AC_OBSOLETE],
+
## ----------------------------- ##
## Dependencies between macros. ##
## ----------------------------- ##
@@ -593,10 +593,10 @@ m4_define([AC_HELP_STRING],
# _AC_INIT_PACKAGE(PACKAGE, VERSION, [BUG-REPORT])
# ------------------------------------------------
m4_define([_AC_INIT_PACKAGE],
-[m4_define([AC_PACKAGE_NAME], [$1])dnl
-m4_define([AC_PACKAGE_VERSION], [$2])dnl
-m4_define([AC_PACKAGE_STRING], [$1 $2])dnl
-m4_define([AC_PACKAGE_BUGREPORT], [$3])dnl
+[m4_define([AC_PACKAGE_NAME], [$1])
+m4_define([AC_PACKAGE_VERSION], [$2])
+m4_define([AC_PACKAGE_STRING], [$1 $2])
+m4_define([AC_PACKAGE_BUGREPORT], [$3])
])
@@ -1518,6 +1518,18 @@ m4_define([_AC_INIT_PREPARE],
])
+# AC_PLAIN_SCRIPT
+# ---------------
+# Simulate AC_INIT, i.e., pretend this is the beginning of the `configure'
+# generation. This is used by some tests, and let `autoconf' be used to
+# generate other scripts than `configure'.
+m4_define([AC_PLAIN_SCRIPT],
+[m4_init
+m4_pattern_forbid([^A]m4_dquote(m4_defn([m4_cr_LETTERS]))[_])
+m4_pattern_forbid([_AC_])
+m4_divert_push([BODY])])
+
+
# AC_INIT([PACKAGE, VERSION, [BUG-REPORT])
# ----------------------------------------
# Include the user macro files, prepare the diversions, and output the
@@ -1525,10 +1537,9 @@ m4_define([_AC_INIT_PREPARE],
# Note that the order is important: first initialize, then set the
# AC_CONFIG_SRCDIR.
m4_define([AC_INIT],
-[m4_ifval([$2], [_AC_INIT_PACKAGE($@)])dnl
+[m4_ifval([$2], [_AC_INIT_PACKAGE($@)])
m4_divert_text([BINSH], address@hidden:@! /bin/sh])
-_AC_INIT_DEFAULTS()dnl
-m4_divert_pop()dnl to BODY
+_AC_INIT_DEFAULTS
_AC_INIT_PARSE_ARGS
_AC_INIT_SRCDIR
_AC_INIT_HELP
@@ -1539,16 +1550,11 @@ m4_define([AC_INIT],
_AC_INIT_NOTICE
_AC_INIT_COPYRIGHT
m4_ifval([$2], , [m4_ifval([$1], [AC_CONFIG_SRCDIR([$1])])])dnl
+# Initialize the diversion setup.
+AC_PLAIN_SCRIPT
])
-# AC_PLAIN_SCRIPT
-# ---------------
-# Simulate AC_INIT, i.e., pretend this is the beginning of the `configure'
-# generation. This is used by some tests, and let `autoconf' be used to
-# generate other scripts than `configure'.
-m4_define([AC_PLAIN_SCRIPT],
-[m4_divert_pop()])
## ----------------------------- ##
Index: autoconf.sh
--- autoconf.sh Sun, 12 Nov 2000 15:15:02 +0100 akim (ace/17_autoconf.s
1.31.8.33 644)
+++ autoconf.sh Sat, 02 Dec 2000 12:28:14 +0100 akim (ace/17_autoconf.s
1.31.8.33 644)
@@ -261,7 +261,7 @@
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 \
- -Dm4_tmpdir=\"$tmp\""
+ -Dm4_tmpdir=$tmp"
run_m4="$M4 $autoconf_dir/autoconf.m4 $m4_common"
run_m4f="$M4 --reload $autoconf_dir/autoconf.m4f $m4_common"
@@ -314,43 +314,37 @@
# Put the real line numbers into configure to make config.log more
# helpful. Because quoting can sometimes get really painful in m4,
# there are special @tokens@ to substitute.
- cat >$tmp/finalize.awk <<EOF
+ sed 's/^ //' >$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")
+ # around \`tmp "/forbidden.rx"'.
+ while ((getline pattern < (tmp "/forbidden.rx")) > 0)
+ forbidden = (forbidden ? forbidden "|" : "") pattern
+ close (tmp "/forbidden.rx")
+ if (verbose)
+ errprint("$me: forbidden: " forbidden)
+
+ while ((getline pattern < (tmp "/allowed.rx")) > 0)
+ allowed = (allowed ? allowed "|" : "") pattern
+ close (tmp "/allowed.rx")
+ if (verbose)
+ errprint("$me: allowed: " allowed)
}
- function undefined (file, line, macro)
+ function errprint (message)
{
- print file ":" line ": error: undefined macro: " macro | "cat >&2"
+ print message | "cat >&2"
}
- # If the token in CODE_PART from BEGIN to END is forbidden,
- # register it for further complains.
- function check_pattern (pattern, offset)
+ function undefined (file, line, macro)
{
- 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
- }
- }
+ errprint(file ":" line ": error: undefined macro: " macro)
}
# Body.
{
- sub(/[ ]*$/, "")
+ sub (/[ \t]*$/, "")
if (\$0 == "")
{
if (!duplicate)
@@ -364,7 +358,7 @@
duplicate = 0
oline++
if (\$0 ~ /__oline__/)
- while (sub(/__oline__/, oline))
+ while (sub (/__oline__/, oline))
continue
while (sub (/@<:@/, "["))
continue
@@ -374,17 +368,22 @@
continue
while (sub (/@%:@/, "#"))
continue
- # Dubious feature: we tolerate macro names when commented.
- code_part = \$0
- sub (/#.*/, "", code_part)
- # 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.
- check_pattern("[^$WORDCHAR](A[$ALPHABET]|m4)_[$WORDCHAR]*", 1)
- check_pattern("^(A[$ALPHABET]|m4)_[$WORDCHAR]*", 0)
- check_pattern("[$WORDCHAR]*_A[$ALPHABET]_[$WORDCHAR]*", 0)
print
+
+ # Dubious feature: we tolerate macro names when commented.
+ sub (/#.*/, "")
+
+ # Get the tokens.
+ split (\$0, tokens, /[^$WORDCHAR]*/)
+
+ for (token in tokens)
+ if (match (tokens[token], forbidden) &&
+ !match (tokens[token], allowed))
+ {
+ macros [tokens [token]] = oline
+ some_macros_were_not_expanded = 1
+ }
}
# If there are some macros which are left unexpanded in the output,
Index: m4sugar.m4
--- m4sugar.m4 Sat, 02 Dec 2000 12:27:01 +0100 akim (ace/b/27_libm4.m4 1.43 644)
+++ m4sugar.m4 Sat, 02 Dec 2000 12:28:14 +0100 akim (ace/b/27_libm4.m4 1.43 644)
@@ -492,6 +492,7 @@ m4_define([m4_dumpdefs],
# expansion of EXP, while in the latter you just obtain the string
# `exp'.
m4_define([m4_quote], [[$*]])
+m4_define([m4_dquote], [[[$*]]])
# m4_noquote(STRING)
@@ -1123,12 +1124,19 @@ m4_define([$1],
[_m4_defun_pro([$1])$2[]_m4_defun_epi([$1])])])])
-# m4_token_allow(TOKEN)
+# m4_pattern_forbid(ERE)
+# ----------------------
+# Declare that no token matching the extended regular expression ERE
+# should be seen in the output but if...
+m4_define([m4_pattern_forbid],
+[m4_file_append(m4_defn([m4_tmpdir])/forbidden.rx, [$1])])
+
+
+# m4_pattern_allow(ERE)
# ---------------------
-# 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])])
+# ... but if that token matches the extended regular expression ERE.
+m4_define([m4_pattern_allow],
+[m4_file_append(m4_defn([m4_tmpdir])/allowed.rx, [$1])])
## ----------------------------- ##
@@ -1226,6 +1234,51 @@ m4_define([m4_provide_ifelse],
## 9. Text processing. ##
## -------------------- ##
+# m4_cr_letters
+# m4_cr_LETTERS
+# m4_cr_Letters
+# -------------
+m4_define([m4_cr_letters], [abcdefghijklmnopqrstuvwxyz])
+m4_define([m4_cr_LETTERS], [ABCDEFGHIJKLMNOPQRSTUVWXYZ])
+m4_define([m4_cr_Letters],
+m4_defn([m4_cr_letters])dnl
+m4_defn([m4_cr_LETTERS])dnl
+)
+
+# m4_cr_digits
+# ------------
+m4_define([m4_cr_digits], [0123456789])
+
+
+# m4_cr_symbols1 & m4_cr_symbols2
+# -------------------------------
+m4_define([m4_cr_symbols1],
+m4_defn([m4_cr_Letters])dnl
+_)
+
+m4_define([m4_cr_symbols2],
+m4_defn([m4_cr_symbols1])dnl
+m4_defn([m4_cr_digits])dnl
+)
+
+
+# m4_re_string
+# ------------
+# Regexp for `[a-zA-Z_0-9]*'
+m4_define([m4_re_string],
+m4_dquote(m4_defn([m4_cr_symbols2]))dnl
+[*]dnl
+)
+
+
+# m4_re_string
+# ------------
+# Regexp for `[a-zA-Z_][a-zA-Z_0-9]*'
+m4_define([m4_re_word],
+m4_dquote(m4_defn([m4_cr_symbols1]))dnl
+m4_defn([m4_re_string])dnl
+)
+
# m4_tolower(STRING)
# m4_toupper(STRING)
# ------------------
@@ -1549,4 +1602,26 @@ m4_define([m4_version_compare],
m4_define([m4_file_append],
[m4_syscmd([cat >>$1 <<_m4eof
$2
-_m4eof])])
+_m4eof])
+ifelse(m4_sysval, [0], [],
+ [m4_fatal([$0: cannot write: $1])])])
+
+
+
+## ------------------------ ##
+## 13. Setting M4sugar up. ##
+## ------------------------ ##
+
+
+# m4_init
+# -------
+m4_defun([m4_init],
+[# We need a tmp directory.
+m4_ifndef([m4_tmpdir],
+ [m4_define([m4_tmpdir], [/tmp])])
+
+
+# M4sugar reserves `m4_[A-Za-z0-9_]*'. We'd need \b and +,
+# but they are not portable.
+m4_pattern_forbid([^m4_])
+])
Index: tests/tools.at
--- tests/tools.at Mon, 27 Nov 2000 22:06:51 +0100 akim (ace/b/30_tools.m4 1.25
644)
+++ tests/tools.at Sat, 02 Dec 2000 12:28:14 +0100 akim (ace/b/30_tools.m4 1.25
644)
@@ -337,27 +337,32 @@ AC_DEFUN([TRACE2], [[$2], $1])
AT_DATA([configure.in],
[[AC_PLAIN_SCRIPT()dnl
-AB_THIS_IS_PROBABLY_NOT_DEFINED
-AND_AZ_THAT_EITHER
-and_AZ_that_too
-# This is legal, also there is `AC_DEFINE' in there.
+
+# This is allowed in spite of the name.
+m4_pattern_allow([^AC_ALLOWED$])
+NOT_AC_ALLOWED AC_ALLOWED AC_ALLOWED_NOT
+
+# Test forbidding.
+m4_pattern_forbid([^FORBIDDEN$])
+NOT_FORBIDDEN FORBIDDEN FORBIDDEN_NOT
+
+# Test Autoconf's patterns.
+AC_THIS_IS_INVALID and AZ_THIS_IS_INVALID_TOO
+BUT_AZ_THIS_IS_NOT ALTHOUGH_AC_THIS_IS
+# This is legal, although there is `AC_DEFINE' in there.
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
+[[configure.in:5: error: undefined macro: NOT_AC_ALLOWED
+configure.in:5: error: undefined macro: AC_ALLOWED_NOT
+configure.in:8: error: undefined macro: FORBIDDEN
+configure.in:12: error: undefined macro: AC_THIS_IS_INVALID
+configure.in:12: error: undefined macro: AZ_THIS_IS_INVALID_TOO
+configure.in:13: error: undefined macro: ALTHOUGH_AC_THIS_IS
+configure:16: error: undefined macro: AC_OUTPUT
]])
AT_CLEANUP(configure)
- 60-m4-patterns.patch,
Akim Demaille <=