(IN_CTYPE_DOMAIN): Rename from ISASCII. SH-UTILS-1_14
authorJim Meyering <jim@meyering.net>
Fri, 13 Dec 1996 03:05:00 +0000 (03:05 +0000)
committerJim Meyering <jim@meyering.net>
Fri, 13 Dec 1996 03:05:00 +0000 (03:05 +0000)
(ISDIGIT): New definition from Paul Eggert.
This one evaluates its argument exactly once.
(yylex): Move increment out of ISALPHA argument.  Use a
comma-expression instead.

lib/getdate.y

index f704018..9dcb93f 100644 (file)
 #include <stdio.h>
 #include <ctype.h>
 
-#if defined (STDC_HEADERS) || !defined (isascii)
-# define ISASCII(c) 1
+#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
+# define IN_CTYPE_DOMAIN(c) 1
 #else
-# define ISASCII(c) isascii(c)
+# define IN_CTYPE_DOMAIN(c) isascii(c)
 #endif
 
-#define ISSPACE(c) (ISASCII (c) && isspace (c))
-#define ISALPHA(c) (ISASCII (c) && isalpha (c))
-#define ISUPPER(c) (ISASCII (c) && isupper (c))
-#define ISDIGIT(c) (ISASCII (c) && isdigit (c))
+#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
+#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
+#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
+#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
+/* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
+   - Its arg may be any int or unsigned int; it need not be an unsigned char.
+   - It's guaranteed to evaluate its argument exactly once.
+   - It's typically faster.
+   Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
+   only '0' through '9' are digits.  Prefer ISDIGIT to ISDIGIT_LOCALE unless
+   it's important to use the locale's definition of `digit' even when the
+   host does not conform to Posix.  */
+#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
 
 #if    defined (vms)
 #include <types.h>
@@ -902,7 +911,7 @@ yylex ()
       return sign ? tSNUMBER : tUNUMBER;
     }
     if (ISALPHA (c)) {
-      for (p = buff; ISALPHA (c = *yyInput++) || c == '.'; )
+      for (p = buff; (c = *yyInput++, ISALPHA (c)) || c == '.'; )
        if (p < &buff[sizeof buff - 1])
          *p++ = c;
       *p = '\0';