[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gawk: conversion of funny numbers
From: |
Aharon Robbins |
Subject: |
gawk: conversion of funny numbers |
Date: |
Tue, 28 Sep 2004 18:42:37 +0200 |
Greetings. Current gawk has a bug whereby floating point numbers with
too many leading zeros were treated as octal. The following patch
fixes the problem.
Arnold
--------------------
Tue Sep 28 18:38:17 2004 Arnold D. Robbins <address@hidden>
* node.c (isnondecimal): New function, now smarter.
* awk.h (isnondecimal): Changed from macro to function.
--- awk.h.save 2004-08-22 17:23:34.000000000 +0300
+++ awk.h 2004-09-28 18:33:44.000000000 +0200
@@ -744,8 +744,6 @@
/* ------------------------- Pseudo-functions ------------------------- */
#define is_identchar(c) (isalnum(c) || (c) == '_')
-#define isnondecimal(str) (((str)[0]) == '0' && (ISDIGIT((str)[1]) \
- || (str)[1] == 'x' || (str)[1] == 'X'))
#define var_uninitialized(n) ((n)->var_value == Nnull_string)
@@ -1140,6 +1138,7 @@
extern int avoid_dfa P((NODE *re, char *str, size_t len)); /* temporary */
extern int reisstring P((const char *text, size_t len, Regexp *re, const char
*buf));
extern int remaybelong P((const char *text, size_t len));
+extern int isnondecimal P((const char *str));
/* strncasecmp.c */
#ifndef BROKEN_STRNCASECMP
--- node.c.save 2004-07-28 16:45:04.000000000 +0300
+++ node.c 2004-09-28 18:37:24.000000000 +0200
@@ -584,3 +584,32 @@
return c;
}
}
+
+/* isnondecimal --- return true if number is not a decimal number */
+
+int
+isnondecimal(const char *str)
+{
+ const char *cp;
+
+ /* leading 0 or 0x or 0X */
+ if (str[0] == '0'
+ && (ISDIGIT(str[1]) || str[1] == 'x' || str[1] == 'X')) {
+ /*
+ * Numbers with '.', 'e', or 'E' are decimal.
+ * Have to check so that things like 00.34 are handled right.
+ */
+ for (cp = str; *cp != '\0'; cp++) {
+ switch (*cp) {
+ case '.':
+ case 'e':
+ case 'E':
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gawk: conversion of funny numbers,
Aharon Robbins <=