[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Changes to m4/src/Attic/builtin.c,v [branch-1_4]
From: |
Eric Blake |
Subject: |
Changes to m4/src/Attic/builtin.c,v [branch-1_4] |
Date: |
Thu, 13 Jul 2006 13:38:22 +0000 |
CVSROOT: /sources/m4
Module name: m4
Branch: branch-1_4
Changes by: Eric Blake <ericb> 06/07/13 13:38:20
Index: src/builtin.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/builtin.c,v
retrieving revision 1.1.1.1.2.20
retrieving revision 1.1.1.1.2.21
diff -u -b -r1.1.1.1.2.20 -r1.1.1.1.2.21
--- src/builtin.c 11 Jul 2006 12:17:11 -0000 1.1.1.1.2.20
+++ src/builtin.c 13 Jul 2006 13:38:20 -0000 1.1.1.1.2.21
@@ -315,13 +315,33 @@
{
char *endp;
- if (*arg == 0 || (*valuep = strtol (arg, &endp, 10), *endp != 0))
+ if (*arg == '\0')
+ {
+ *valuep = 0;
+ M4ERROR ((warning_status, 0,
+ "empty string treated as 0 in builtin `%s'",
+ TOKEN_DATA_TEXT (macro)));
+ }
+ else
+ {
+ errno = 0;
+ *valuep = strtol (arg, &endp, 10);
+ if (*endp != '\0')
{
M4ERROR ((warning_status, 0,
"non-numeric argument to builtin `%s'",
TOKEN_DATA_TEXT (macro)));
return FALSE;
}
+ if (isspace (to_uchar (*arg)))
+ M4ERROR ((warning_status, 0,
+ "leading whitespace ignored in builtin `%s'",
+ TOKEN_DATA_TEXT (macro)));
+ else if (errno == ERANGE)
+ M4ERROR ((warning_status, 0,
+ "numeric overflow detected in builtin `%s'",
+ TOKEN_DATA_TEXT (macro)));
+ }
return TRUE;
}
@@ -508,7 +528,7 @@
if (s != NULL && SYMBOL_TYPE (s) != TOKEN_VOID)
result = ARG (2);
- else if (argc == 4)
+ else if (argc >= 4)
result = ARG (3);
else
result = NULL;
@@ -873,7 +893,7 @@
static void
m4_eval (struct obstack *obs, int argc, token_data **argv)
{
- eval_t value;
+ eval_t value = 0;
int radix = 10;
int min = 1;
const char *s;
@@ -881,10 +901,10 @@
if (bad_argc (argv[0], argc, 2, 4))
return;
- if (argc >= 3 && !numeric_arg (argv[0], ARG (2), &radix))
+ if (*ARG (2) && !numeric_arg (argv[0], ARG (2), &radix))
return;
- if (radix <= 1 || radix > (int) strlen (digits))
+ if (radix < 1 || radix > (int) strlen (digits))
{
M4ERROR ((warning_status, 0,
"radix in builtin `%s' out of range (radix = %d)",
@@ -894,22 +914,40 @@
if (argc >= 4 && !numeric_arg (argv[0], ARG (3), &min))
return;
- if (min <= 0)
+ if (min < 0)
{
M4ERROR ((warning_status, 0,
"negative width to builtin `%s'", ARG (0)));
return;
}
- if (evaluate (ARG (1), &value))
+ if (!*ARG (1))
+ M4ERROR ((warning_status, 0,
+ "empty string treated as 0 in builtin `%s'", ARG (0)));
+ else if (evaluate (ARG (1), &value))
+ return;
+
+ if (radix == 1)
+ {
+ if (value < 0)
+ {
+ obstack_1grow (obs, '-');
+ value = -value;
+ }
+ /* This assumes 2's-complement for correctly handling INT_MIN. */
+ while (min-- - value > 0)
+ obstack_1grow (obs, '0');
+ while (value-- != 0)
+ obstack_1grow (obs, '1');
+ obstack_1grow (obs, '\0');
return;
+ }
s = ntoa (value, radix);
if (*s == '-')
{
obstack_1grow (obs, '-');
- min--;
s++;
}
for (min -= strlen (s); --min >= 0;)
@@ -962,7 +1000,7 @@
if (bad_argc (argv[0], argc, 1, 2))
return;
- if (argc == 2 && !numeric_arg (argv[0], ARG (1), &i))
+ if (argc >= 2 && !numeric_arg (argv[0], ARG (1), &i))
return;
make_diversion (i);
@@ -992,16 +1030,16 @@
{
int i, file;
FILE *fp;
+ char *endp;
if (argc == 1)
undivert_all ();
else
for (i = 1; i < argc; i++)
{
- if (sscanf (ARG (i), "%d", &file) == 1)
+ file = strtol (ARG (i), &endp, 10);
+ if (*endp == '\0' && !isspace (to_uchar (*ARG (i))))
insert_diversion (file);
- else if (!*ARG (i))
- /* Ignore empty string. */;
else if (no_gnu_extensions)
M4ERROR ((warning_status, 0,
"non-numeric argument to builtin `%s'", ARG (0)));
@@ -1219,7 +1257,7 @@
if (bad_argc (argv[0], argc, 1, 2))
return;
- if (argc == 2 && !numeric_arg (argv[0], ARG (1), &exit_code))
+ if (argc >= 2 && !numeric_arg (argv[0], ARG (1), &exit_code))
exit_code = 0;
exit (exit_code);
@@ -1424,7 +1462,8 @@
static void
m4_substr (struct obstack *obs, int argc, token_data **argv)
{
- int start, length, avail;
+ int start = 0;
+ int length, avail;
if (bad_argc (argv[0], argc, 3, 4))
return;
@@ -1433,7 +1472,7 @@
if (!numeric_arg (argv[0], ARG (2), &start))
return;
- if (argc == 4 && !numeric_arg (argv[0], ARG (3), &length))
+ if (argc >= 4 && !numeric_arg (argv[0], ARG (3), &length))
return;
if (start < 0 || length <= 0 || start >= avail)
@@ -1515,7 +1554,7 @@
return;
}
- if (argc == 4)
+ if (argc >= 4)
{
to = ARG (3);
if (strchr (to, '-') != NULL)
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/07/06
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/07/07
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/07/09
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/07/11
- Changes to m4/src/Attic/builtin.c,v [branch-1_4],
Eric Blake <=
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/07/13
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/07/13
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/07/14
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/07/14
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/07/17
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/07/24
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/07/27
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/07/29
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/07/30