[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
15-fyi-fix-ifelse.patch
From: |
Akim Demaille |
Subject: |
15-fyi-fix-ifelse.patch |
Date: |
Sat, 13 Oct 2001 10:57:06 +0200 |
Index: ChangeLog
from Akim Demaille <address@hidden>
* m4/utility.c (m4_bad_argc): Display user argument counts, i.e.,
exclude the builtin name from the count.
* modules/m4.c (ifelse): Do not use the regular argc mechanism, as
calling ifelse with a single argument is valid.
* doc/m4.texinfo (Ifelse): Add an example where ifelse is invoked
with 1 and 2 args, mostly to strengthen the test suite.
Index: doc/m4.texinfo
--- doc/m4.texinfo Sat, 13 Oct 2001 08:43:17 +0200 akim
+++ doc/m4.texinfo Sat, 13 Oct 2001 09:14:09 +0200 akim
@@ -1491,6 +1491,14 @@ @node Ifelse
special usage is recognized by GNU @code{m4}, so that in this case, the
warning about missing arguments is never triggered.
address@hidden
+ifelse(`some comments')
address@hidden
+ifelse(`foo', `bar')
address@hidden: input.m4: 2: Warning: ifelse: too few arguments: 2 < 3
address@hidden
address@hidden example
+
If called with three or four arguments, @code{ifelse} expands into
@var{equal}, if @var{string-1} and @var{string-2} are equal (character
for character), otherwise it expands to @var{not-equal}.
Index: m4/utility.c
--- m4/utility.c Sat, 13 Oct 2001 08:43:17 +0200 akim
+++ m4/utility.c Sat, 13 Oct 2001 09:01:06 +0200 akim
@@ -98,11 +98,12 @@
-/* Give friendly warnings if a builtin macro is passed an inappropriate
- number of arguments. NAME is macro name for messages, ARGC is actual
- number of arguments, MIN is the minimum number of acceptable arguments,
- negative if not applicable, MAX is the maximum number, negative if not
- applicable. */
+/* Give friendly warnings if a builtin macro is passed an
+ inappropriate number of arguments. NAME is macro name for
+ messages, ARGC is actual number of arguments, MIN is the minimum
+ number of acceptable arguments, negative if not applicable, MAX is
+ the maximum number, negative if not applicable. ARGC, MIN, and MAX
+ count ARGV[0], the name of the macro. */
boolean
m4_bad_argc (m4_token *token, int argc, int min, int max)
{
@@ -110,7 +111,7 @@
{
M4WARN ((warning_status, 0,
_("Warning: %s: too few arguments: %d < %d"),
- TOKEN_TEXT (token), argc, min));
+ TOKEN_TEXT (token), argc - 1, min - 1));
return TRUE;
}
@@ -118,7 +119,7 @@
{
M4WARN ((warning_status, 0,
_("Warning: %s: too many arguments (ignored): %d > %d"),
- TOKEN_TEXT (token), argc, max));
+ TOKEN_TEXT (token), argc - 1, max - 1));
/* Return FALSE, otherwise it is not exactly `ignored'. */
return FALSE;
}
Index: modules/m4.c
--- modules/m4.c Sat, 13 Oct 2001 08:43:17 +0200 akim
+++ modules/m4.c Sat, 13 Oct 2001 08:59:24 +0200 akim
@@ -60,7 +60,7 @@
BUILTIN(errprint, FALSE, FALSE, 0, -1 ) \
BUILTIN(eval, FALSE, TRUE, 2, 4 ) \
BUILTIN(ifdef, FALSE, TRUE, 3, 4 ) \
- BUILTIN(ifelse, FALSE, TRUE, 4, -1 ) \
+ BUILTIN(ifelse, FALSE, TRUE, -1, -1 ) \
BUILTIN(include, FALSE, TRUE, 2, 2 ) \
BUILTIN(incr, FALSE, TRUE, 2, 2 ) \
BUILTIN(index, FALSE, TRUE, 3, 3 ) \
@@ -252,9 +252,13 @@
{
const char *result;
+ /* The valid ranges of argc for ifelse is discontinuous, we cannot
+ rely on the regular mechanisms. */
if (argc == 2)
return;
+ if (m4_bad_argc (argv[0], argc, 4, -1))
+ return;
else
/* Diagnose excess arguments if 5, 8, 11, etc., actual arguments. */
m4_bad_argc (argv[0], (argc + 2) % 3, -1, 1);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 15-fyi-fix-ifelse.patch,
Akim Demaille <=