From e43386442ef771290d40e0edb7cb7cbe7c2777f8 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 6 Dec 2000 08:58:13 +0000 Subject: [PATCH] * 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_word) (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. --- ChangeLog | 18 +++++++++ acgeneral.m4 | 38 ++++++++++-------- autoconf.in | 73 +++++++++++++++++----------------- autoconf.sh | 73 +++++++++++++++++----------------- bin/autoconf.in | 73 +++++++++++++++++----------------- lib/autoconf/general.m4 | 38 ++++++++++-------- lib/m4sugar/m4sugar.m4 | 87 ++++++++++++++++++++++++++++++++++++++--- m4sugar.m4 | 87 ++++++++++++++++++++++++++++++++++++++--- man/autoconf.1 | 2 +- tests/tools.at | 35 ++++++++++------- 10 files changed, 353 insertions(+), 171 deletions(-) diff --git a/ChangeLog b/ChangeLog index 27156b42..6e86c5ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2000-12-06 Akim Demaille + + * 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_word) + (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. + 2000-12-05 Bob Wilson * acspecific.m4 (_AC_OBJEXT, _AC_EXEEXT): Ignore .d files produced diff --git a/acgeneral.m4 b/acgeneral.m4 index 51f0b65c..026f9e43 100644 --- a/acgeneral.m4 +++ b/acgeneral.m4 @@ -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_popdef([AC_Prefix])dnl # _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 @@ AC_CONFIG_SRCDIR([$1])], [[AC_INIT]])])[]dnl ]) +# 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 @@ AC_CONFIG_SRCDIR([$1])], [[AC_INIT]])])[]dnl # 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], [@%:@! /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 @@ dnl it dumps into a diversion prepared by _AC_INIT_VERSION. _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()]) ## ----------------------------- ## diff --git a/autoconf.in b/autoconf.in index b6836b59..feca9b81 100644 --- a/autoconf.in +++ b/autoconf.in @@ -261,7 +261,7 @@ $debug || 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 @@ case $task in # 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 <$tmp/finalize.awk < 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 errprint (message) + { + print message | "cat >&2" } 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 - } - } + errprint(file ":" line ": error: undefined macro: " macro) } # Body. { - sub(/[ ]*$/, "") + sub (/[ \t]*$/, "") if (\$0 == "") { if (!duplicate) @@ -364,7 +358,7 @@ case $task in duplicate = 0 oline++ if (\$0 ~ /__oline__/) - while (sub(/__oline__/, oline)) + while (sub (/__oline__/, oline)) continue while (sub (/@<:@/, "[")) continue @@ -374,17 +368,22 @@ case $task in 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, diff --git a/autoconf.sh b/autoconf.sh index b6836b59..feca9b81 100644 --- a/autoconf.sh +++ b/autoconf.sh @@ -261,7 +261,7 @@ $debug || 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 @@ case $task in # 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 <$tmp/finalize.awk < 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 errprint (message) + { + print message | "cat >&2" } 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 - } - } + errprint(file ":" line ": error: undefined macro: " macro) } # Body. { - sub(/[ ]*$/, "") + sub (/[ \t]*$/, "") if (\$0 == "") { if (!duplicate) @@ -364,7 +358,7 @@ case $task in duplicate = 0 oline++ if (\$0 ~ /__oline__/) - while (sub(/__oline__/, oline)) + while (sub (/__oline__/, oline)) continue while (sub (/@<:@/, "[")) continue @@ -374,17 +368,22 @@ case $task in 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, diff --git a/bin/autoconf.in b/bin/autoconf.in index b6836b59..feca9b81 100644 --- a/bin/autoconf.in +++ b/bin/autoconf.in @@ -261,7 +261,7 @@ $debug || 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 @@ case $task in # 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 <$tmp/finalize.awk < 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 errprint (message) + { + print message | "cat >&2" } 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 - } - } + errprint(file ":" line ": error: undefined macro: " macro) } # Body. { - sub(/[ ]*$/, "") + sub (/[ \t]*$/, "") if (\$0 == "") { if (!duplicate) @@ -364,7 +358,7 @@ case $task in duplicate = 0 oline++ if (\$0 ~ /__oline__/) - while (sub(/__oline__/, oline)) + while (sub (/__oline__/, oline)) continue while (sub (/@<:@/, "[")) continue @@ -374,17 +368,22 @@ case $task in 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, diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4 index 51f0b65c..026f9e43 100644 --- a/lib/autoconf/general.m4 +++ b/lib/autoconf/general.m4 @@ -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_popdef([AC_Prefix])dnl # _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 @@ AC_CONFIG_SRCDIR([$1])], [[AC_INIT]])])[]dnl ]) +# 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 @@ AC_CONFIG_SRCDIR([$1])], [[AC_INIT]])])[]dnl # 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], [@%:@! /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 @@ dnl it dumps into a diversion prepared by _AC_INIT_VERSION. _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()]) ## ----------------------------- ## diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index d468b4bf..2a8b2460 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -492,6 +492,7 @@ _m4_dumpdefs_down([$1])]) # 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_word +# ---------- +# 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_]) +]) diff --git a/m4sugar.m4 b/m4sugar.m4 index d468b4bf..2a8b2460 100644 --- a/m4sugar.m4 +++ b/m4sugar.m4 @@ -492,6 +492,7 @@ _m4_dumpdefs_down([$1])]) # 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_word +# ---------- +# 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_]) +]) diff --git a/man/autoconf.1 b/man/autoconf.1 index cb5e5261..327c1a61 100644 --- a/man/autoconf.1 +++ b/man/autoconf.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.23. -.TH AUTOCONF "1" "November 2000" "GNU autoconf 2.49b" FSF +.TH AUTOCONF "1" "December 2000" "GNU autoconf 2.49b" FSF .SH NAME autoconf \- Generate configuration scripts .SH SYNOPSIS diff --git a/tests/tools.at b/tests/tools.at index c5cadef5..4aa93215 100644 --- a/tests/tools.at +++ b/tests/tools.at @@ -347,27 +347,32 @@ AT_SETUP([Forbidden tokens]) 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)