-/* Copyright (C) 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2000, 2001, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
{ 0, NULL, "$((-1))", 0, 1, { "-1", }, IFS },
{ 0, NULL, "$[50+20]", 0, 1, { "70", }, IFS },
{ 0, NULL, "$(((2+3)*(4+5)))", 0, 1, { "45", }, IFS },
+ { 0, NULL, "$((010))", 0, 1, { "8" }, IFS },
+ { 0, NULL, "$((0x10))", 0, 1, { "16" }, IFS },
+ { 0, NULL, "$((010+0x10))", 0, 1, { "24" }, IFS },
+ { 0, NULL, "$((-010+0x10))", 0, 1, { "8" }, IFS },
+ { 0, NULL, "$((-0x10+010))", 0, 1, { "-8" }, IFS },
/* Advanced parameter expansion */
{ 0, NULL, "${var:-bar}", 0, 1, { "bar", }, IFS },
{ WRDE_SYNTAX, NULL, "$(for i in)", 0, 0, { NULL, }, IFS },
{ WRDE_SYNTAX, NULL, "$((2+))", 0, 0, { NULL, }, IFS },
{ WRDE_SYNTAX, NULL, "`", 0, 0, { NULL, }, IFS },
+ { WRDE_SYNTAX, NULL, "$((010+4+))", 0, 0, { NULL }, IFS },
{ -1, NULL, NULL, 0, 0, { NULL, }, IFS },
};
internal_function
eval_expr_val (char **expr, long int *result)
{
- int sgn = +1;
char *digit;
/* Skip white space */
for (digit = *expr; digit && *digit && isspace (*digit); ++digit);
- switch (*digit)
+ if (*digit == '(')
{
- case '(':
-
/* Scan for closing paren */
for (++digit; **expr && **expr != ')'; ++(*expr));
return WRDE_SYNTAX;
return 0;
-
- case '+': /* Positive value */
- ++digit;
- break;
-
- case '-': /* Negative value */
- ++digit;
- sgn = -1;
- break;
-
- default:
- if (!isdigit (*digit))
- return WRDE_SYNTAX;
}
- *result = 0;
- for (; *digit && isdigit (*digit); ++digit)
- *result = (*result * 10) + (*digit - '0');
+ /* POSIX requires that decimal, octal, and hexadecimal constants are
+ recognized. Therefore we pass 0 as the third parameter to strtol. */
+ *result = strtol (digit, expr, 0);
+ if (digit == *expr)
+ return WRDE_SYNTAX;
- *expr = digit;
- *result *= sgn;
return 0;
}