Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Apply patch from Darren for the ctype() functions/macros.



details:   https://anonhg.NetBSD.org/src/rev/a8771162af30
branches:  trunk
changeset: 571206:a8771162af30
user:      he <he%NetBSD.org@localhost>
date:      Sat Nov 13 19:14:48 2004 +0000

description:
Apply patch from Darren for the ctype() functions/macros.
Encapsulates the ctype() functions so that the casts are centralized.

diffstat:

 dist/ipf/ip_fil.c                  |   6 ++--
 dist/ipf/iplang/iplang_y.y         |  12 +++++-----
 dist/ipf/ipsd/sdlpi.c              |   4 +-
 dist/ipf/ipsend/sdlpi.c            |   4 +-
 dist/ipf/l4check/l4check.c         |  10 ++++----
 dist/ipf/lib/addicmp.c             |   6 ++--
 dist/ipf/lib/getportproto.c        |   4 +-
 dist/ipf/lib/getproto.c            |   4 +-
 dist/ipf/lib/hexdump.c             |   4 +-
 dist/ipf/lib/hostnum.c             |   4 +-
 dist/ipf/lib/icmpcode.c            |   4 +-
 dist/ipf/lib/inet_addr.c           |  26 ++++++++++++++++++-----
 dist/ipf/lib/ipft_hx.c             |   8 +++---
 dist/ipf/lib/ipft_tx.c             |  12 +++++-----
 dist/ipf/lib/natparse.c            |   6 ++--
 dist/ipf/lib/parse.c               |   4 +-
 dist/ipf/lib/portnum.c             |   4 +-
 dist/ipf/lib/ports.c               |   4 +-
 dist/ipf/lib/printbuf.c            |   4 +-
 dist/ipf/lib/printsbuf.c           |   4 +-
 dist/ipf/lib/var.c                 |   6 ++--
 dist/ipf/tools/ipfstat.c           |   6 ++--
 dist/ipf/tools/ipmon.c             |   8 +++---
 dist/ipf/tools/ipscan_y.y          |   8 +++---
 dist/ipf/tools/lexer.c             |  10 ++++----
 sys/dist/ipf/netinet/ip_compat.h   |  18 +++++++++++++++-
 sys/dist/ipf/netinet/ip_ftp_pxy.c  |  42 +++++++++++++++++++-------------------
 sys/dist/ipf/netinet/ip_irc_pxy.c  |  20 +++++++++---------
 sys/dist/ipf/netinet/ip_rcmd_pxy.c |   6 ++--
 sys/dist/ipf/netinet/ip_rpcb_pxy.c |   8 +++---
 sys/dist/ipf/netinet/ip_scan.c     |   4 +-
 31 files changed, 150 insertions(+), 120 deletions(-)

diffs (truncated from 992 to 300 lines):

diff -r 202994e14786 -r a8771162af30 dist/ipf/ip_fil.c
--- a/dist/ipf/ip_fil.c Sat Nov 13 18:43:49 2004 +0000
+++ b/dist/ipf/ip_fil.c Sat Nov 13 19:14:48 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_fil.c,v 1.4 2004/07/23 05:39:03 martti Exp $        */
+/*     $NetBSD: ip_fil.c,v 1.5 2004/11/13 19:16:10 he Exp $    */
 
 /*
  * Copyright (C) 1993-2001 by Darren Reed.
@@ -577,9 +577,9 @@
     (defined(__FreeBSD__) && (__FreeBSD_version >= 501113))
        (void) strncpy(ifp->if_xname, name, sizeof(ifp->if_xname));
 #else
-       for (s = name; *s && !isdigit(*s); s++)
+       for (s = name; *s && !ISDIGIT(*s); s++)
                ;
-       if (*s && isdigit(*s)) {
+       if (*s && ISDIGIT(*s)) {
                ifp->if_unit = atoi(s);
                ifp->if_name = (char *)malloc(s - name + 1);
                (void) strncpy(ifp->if_name, name, s - name);
diff -r 202994e14786 -r a8771162af30 dist/ipf/iplang/iplang_y.y
--- a/dist/ipf/iplang/iplang_y.y        Sat Nov 13 18:43:49 2004 +0000
+++ b/dist/ipf/iplang/iplang_y.y        Sat Nov 13 19:14:48 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iplang_y.y,v 1.5 2004/03/28 09:00:55 martti Exp $      */
+/*     $NetBSD: iplang_y.y,v 1.6 2004/11/13 19:16:10 he Exp $  */
 
 %{
 /*
@@ -767,7 +767,7 @@
 
        while ((c = *s++)) {
                if (todo) {
-                       if (isdigit(c)) {
+                       if (ISDIGIT(c)) {
                                todo--;
                                if (c > '7') {
                                        fprintf(stderr, "octal with %c!\n", c);
@@ -776,7 +776,7 @@
                                val <<= 3;
                                val |= (c - '0');
                        }
-                       if (!isdigit(c) || !todo) {
+                       if (!ISDIGIT(c) || !todo) {
                                *t++ = (u_char)(val & 0xff);
                                todo = 0;
                        }
@@ -784,7 +784,7 @@
                                continue;
                }
                if (quote) {
-                       if (isdigit(c)) {
+                       if (ISDIGIT(c)) {
                                todo = 2;
                                if (c > '7') {
                                        fprintf(stderr, "octal with %c!\n", c);
@@ -1320,7 +1320,7 @@
                                sprintf((char *)t, "    ");
                                t += 8;
                                for (k = 16; k; k--, s++)
-                                       *t++ = (isprint(*s) ? *s : '.');
+                                       *t++ = (ISPRINT(*s) ? *s : '.');
                                s--;
                        }
 
@@ -1338,7 +1338,7 @@
                        t += 7;
                        s -= j & 0xf;
                        for (k = j & 0xf; k; k--, s++)
-                               *t++ = (isprint(*s) ? *s : '.');
+                               *t++ = (ISPRINT(*s) ? *s : '.');
                        *t++ = '\n';
                        *t = '\0';
                }
diff -r 202994e14786 -r a8771162af30 dist/ipf/ipsd/sdlpi.c
--- a/dist/ipf/ipsd/sdlpi.c     Sat Nov 13 18:43:49 2004 +0000
+++ b/dist/ipf/ipsd/sdlpi.c     Sat Nov 13 19:14:48 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sdlpi.c,v 1.2 2002/01/24 08:21:38 martti Exp $ */
+/*     $NetBSD: sdlpi.c,v 1.3 2004/11/13 19:16:10 he Exp $     */
 
 /*
  * (C)opyright 1992-1998 Darren Reed. (from tcplog)
@@ -160,7 +160,7 @@
        (void) sprintf(devname, "/dev/%s", device);
 
        s = devname + 5;
-       while (*s && !isdigit(*s))
+       while (*s && !ISDIGIT(*s))
                s++;
        if (!*s)
            {
diff -r 202994e14786 -r a8771162af30 dist/ipf/ipsend/sdlpi.c
--- a/dist/ipf/ipsend/sdlpi.c   Sat Nov 13 18:43:49 2004 +0000
+++ b/dist/ipf/ipsend/sdlpi.c   Sat Nov 13 19:14:48 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sdlpi.c,v 1.3 2004/03/28 09:00:56 martti Exp $ */
+/*     $NetBSD: sdlpi.c,v 1.4 2004/11/13 19:16:10 he Exp $     */
 
 /*
  * (C)opyright 1992-1998 Darren Reed. (from tcplog)
@@ -70,7 +70,7 @@
        (void) strncat(devname, device, sizeof(devname) - strlen(devname));
 
        s = devname + 5;
-       while (*s && !isdigit(*s))
+       while (*s && !ISDIGIT(*s))
                s++;
        if (!*s)
            {
diff -r 202994e14786 -r a8771162af30 dist/ipf/l4check/l4check.c
--- a/dist/ipf/l4check/l4check.c        Sat Nov 13 18:43:49 2004 +0000
+++ b/dist/ipf/l4check/l4check.c        Sat Nov 13 19:14:48 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: l4check.c,v 1.1.1.3 2004/03/28 08:56:17 martti Exp $   */
+/*     $NetBSD: l4check.c,v 1.2 2004/11/13 19:16:10 he Exp $   */
 
 /*
  * (C)Copyright March, 2000 - Darren Reed.
@@ -418,10 +418,10 @@
                *port++ = '\0';
 
 #ifdef HAVE_INET_ATON
-       if (isdigit(*host) && inet_aton(host, &ip))
+       if (ISDIGIT(*host) && inet_aton(host, &ip))
                *ipp = ip.s_addr;
 #else
-       if (isdigit(*host))
+       if (ISDIGIT(*host))
                *ipp = inet_addr(host);
 #endif
        else {
@@ -434,7 +434,7 @@
        }
 
        if (port) {
-               if (isdigit(*port))
+               if (ISDIGIT(*port))
                        *portp = htons(atoi(port));
                else {
                        sp = getservbyname(port, "tcp");
@@ -527,7 +527,7 @@
                /*
                 * Skip leading whitespace
                 */
-               for (line = buf; (c = *line) && isspace(c); line++)
+               for (line = buf; (c = *line) && ISSPACE(c); line++)
                        ;
                if (!*line)
                        continue;
diff -r 202994e14786 -r a8771162af30 dist/ipf/lib/addicmp.c
--- a/dist/ipf/lib/addicmp.c    Sat Nov 13 18:43:49 2004 +0000
+++ b/dist/ipf/lib/addicmp.c    Sat Nov 13 19:14:48 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: addicmp.c,v 1.3 2004/11/13 18:44:43 he Exp $   */
+/*     $NetBSD: addicmp.c,v 1.4 2004/11/13 19:16:10 he Exp $   */
 
 /*
  * Copyright (C) 1993-2001 by Darren Reed.
@@ -36,7 +36,7 @@
                return -1;
        if (!fp->fr_proto)      /* to catch lusers */
                fp->fr_proto = IPPROTO_ICMP;
-       if (isdigit(***cp)) {
+       if (ISDIGIT(***cp)) {
                if (!ratoi(**cp, &i, 0, 255)) {
                        fprintf(stderr,
                                "%d: Invalid icmp-type (%s) specified\n",
@@ -70,7 +70,7 @@
        if (**cp && strcasecmp("code", **cp))
                return 0;
        (*cp)++;
-       if (isdigit(***cp)) {
+       if (ISDIGIT(***cp)) {
                if (!ratoi(**cp, &i, 0, 255)) {
                        fprintf(stderr,
                                "%d: Invalid icmp code (%s) specified\n",
diff -r 202994e14786 -r a8771162af30 dist/ipf/lib/getportproto.c
--- a/dist/ipf/lib/getportproto.c       Sat Nov 13 18:43:49 2004 +0000
+++ b/dist/ipf/lib/getportproto.c       Sat Nov 13 19:14:48 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getportproto.c,v 1.3 2004/11/13 18:44:43 he Exp $      */
+/*     $NetBSD: getportproto.c,v 1.4 2004/11/13 19:16:10 he Exp $      */
 
 #include <ctype.h>
 #include "ipf.h"
@@ -10,7 +10,7 @@
        struct servent *s;
        struct protoent *p;
 
-       if (isdigit(*name) && atoi(name) > 0)
+       if (ISDIGIT(*name) && atoi(name) > 0)
                return htons(atoi(name) & 65535);
 
        p = getprotobynumber(proto);
diff -r 202994e14786 -r a8771162af30 dist/ipf/lib/getproto.c
--- a/dist/ipf/lib/getproto.c   Sat Nov 13 18:43:49 2004 +0000
+++ b/dist/ipf/lib/getproto.c   Sat Nov 13 19:14:48 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getproto.c,v 1.1.1.1 2004/03/28 08:56:18 martti Exp $  */
+/*     $NetBSD: getproto.c,v 1.2 2004/11/13 19:16:10 he Exp $  */
 
 #include "ipf.h"
 
@@ -9,7 +9,7 @@
        char *s;
 
        for (s = name; *s != '\0'; s++)
-               if (!isdigit(*s))
+               if (!ISDIGIT(*s))
                        break;
        if (*s == '\0')
                return atoi(name);
diff -r 202994e14786 -r a8771162af30 dist/ipf/lib/hexdump.c
--- a/dist/ipf/lib/hexdump.c    Sat Nov 13 18:43:49 2004 +0000
+++ b/dist/ipf/lib/hexdump.c    Sat Nov 13 19:14:48 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hexdump.c,v 1.1.1.1 2004/03/28 08:56:18 martti Exp $   */
+/*     $NetBSD: hexdump.c,v 1.2 2004/11/13 19:16:10 he Exp $   */
 
 #include <ctype.h>
 
@@ -20,7 +20,7 @@
                        if (ascii != 0) {
                                fputc('\t', fpout);
                                for (t = s - 15; t<= s; t++)
-                                       fputc(isprint(*t) ? *t : '.', fpout);
+                                       fputc(ISPRINT(*t) ? *t : '.', fpout);
                        }
                        fputc('\n', fpout);
                } else if (i % 4 == 3) {
diff -r 202994e14786 -r a8771162af30 dist/ipf/lib/hostnum.c
--- a/dist/ipf/lib/hostnum.c    Sat Nov 13 18:43:49 2004 +0000
+++ b/dist/ipf/lib/hostnum.c    Sat Nov 13 19:14:48 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hostnum.c,v 1.3 2004/11/13 18:44:43 he Exp $   */
+/*     $NetBSD: hostnum.c,v 1.4 2004/11/13 19:16:10 he Exp $   */
 
 /*
  * Copyright (C) 1993-2001 by Darren Reed.
@@ -37,7 +37,7 @@
                        return -1;
        }
 #endif
-       if (isdigit(*host) && inet_aton(host, &ip)) {
+       if (ISDIGIT(*host) && inet_aton(host, &ip)) {
                *ipa = ip.s_addr;
                return 0;
        }
diff -r 202994e14786 -r a8771162af30 dist/ipf/lib/icmpcode.c
--- a/dist/ipf/lib/icmpcode.c   Sat Nov 13 18:43:49 2004 +0000
+++ b/dist/ipf/lib/icmpcode.c   Sat Nov 13 19:14:48 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: icmpcode.c,v 1.3 2004/11/13 18:44:43 he Exp $  */
+/*     $NetBSD: icmpcode.c,v 1.4 2004/11/13 19:16:10 he Exp $  */
 
 /*
  * Copyright (C) 1993-2001 by Darren Reed.
@@ -34,7 +34,7 @@
 
        if ((s = strrchr(str, ')')))
                *s = '\0';
-       if (isdigit(*str)) {
+       if (ISDIGIT(*str)) {
                if (!ratoi(str, &i, 0, 255))
                        return -1;
                else
diff -r 202994e14786 -r a8771162af30 dist/ipf/lib/inet_addr.c
--- a/dist/ipf/lib/inet_addr.c  Sat Nov 13 18:43:49 2004 +0000
+++ b/dist/ipf/lib/inet_addr.c  Sat Nov 13 19:14:48 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inet_addr.c,v 1.1.1.2 2004/07/23 05:34:35 martti Exp $ */
+/*     $NetBSD: inet_addr.c,v 1.2 2004/11/13 19:16:10 he Exp $ */
 
 /*
  * ++Copyright++ 1983, 1990, 1993
@@ -76,6 +76,20 @@
 int inet_aton __P((const char *, struct in_addr *));
 
 /*
+ * Because the ctype(3) posix definition, if used "safely" in code everywhere,
+ * would mean all normal code that walks through strings needed casts.  Yuck.
+ */
+#define        ISALNUM(x)      isalnum((u_char)(x))
+#define        ISALPHA(x)      isalpha((u_char)(x))
+#define        ISASCII(x)      isascii((u_char)(x))
+#define        ISDIGIT(x)      isdigit((u_char)(x))
+#define        ISPRINT(x)      isprint((u_char)(x))
+#define        ISSPACE(x)      isspace((u_char)(x))
+#define        ISUPPER(x)      isupper((u_char)(x))
+#define        ISXDIGIT(x)     isxdigit((u_char)(x))
+#define        ISLOWER(x)      islower((u_char)(x))
+
+/*
  * Check whether "cp" is a valid ascii representation
  * of an Internet address and convert to a binary address.
  * Returns 1 if the address is valid, 0 if not.
@@ -100,7 +114,7 @@
                 * Values are specified as for C:



Home | Main Index | Thread Index | Old Index