]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add, and use, macros to do locale-independent case mapping.
authorGuy Harris <[email protected]>
Tue, 11 Dec 2018 07:16:45 +0000 (23:16 -0800)
committerGuy Harris <[email protected]>
Tue, 11 Dec 2018 07:16:45 +0000 (23:16 -0800)
This means we get the same behavior in Turkish locales (where, if we
aren't in the C locale, we might get lower-case "i" mapped to upper-case
"I with dot" and upper-case "I" mapped to lower-case "i without dot),
and may also suppress some shortening warnings from MSVC.

netdissect.h
print-zephyr.c
util-print.c

index 0bacbfc7c1bb15cb1a3c88a80b281858f380aa01..36adf852c08c288f6cb80f5826e4997a6719251b 100644 (file)
@@ -350,15 +350,33 @@ extern void txtproto_print(netdissect_options *, const u_char *, u_int,
 
 /*
  * Locale-independent macros for testing character properties and
- * stripping the 8th bit from characters.  Assumed to be handed
- * a value between 0 and 255, i.e. don't hand them a char, as
- * those might be in the range -128 to 127.
+ * stripping the 8th bit from characters.
+ *
+ * Byte values outside the ASCII range are considered unprintable, so
+ * both ND_ISPRINT() and ND_ISGRAPH() return "false" for them.
+ *
+ * Assumed to be handed a value between 0 and 255, i.e. don't hand them
+ * a char, as those might be in the range -128 to 127.
  */
 #define ND_ISASCII(c)  (!((c) & 0x80)) /* value is an ASCII code point */
 #define ND_ISPRINT(c)  ((c) >= 0x20 && (c) <= 0x7E)
 #define ND_ISGRAPH(c)  ((c) > 0x20 && (c) <= 0x7E)
 #define ND_TOASCII(c)  ((c) & 0x7F)
 
+/*
+ * Locale-independent macros for coverting to upper or lower case.
+ *
+ * Byte values outside the ASCII range are not converted.  Byte values
+ * *in* the ASCII range are converted to byte values in the ASCII range;
+ * in particular, 'i' is upper-cased to 'I" and 'I' is lower-cased to 'i',
+ * even in Turkish locales.
+ *
+ * Assumed to be handed a value between 0 and 255, i.e. don't hand
+ * them a char, as those might be in the range -128 to 127.
+ */
+#define ND_TOLOWER(c)  (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A' + 'a' : (c))
+#define ND_TOUPPER(c)  (((c) >= 'a' && (c) <= 'z') ? (c) - 'a' + 'z' : (c))
+
 #if (defined(__i386__) || defined(_M_IX86) || defined(__X86__) || defined(__x86_64__) || defined(_M_X64)) || \
     (defined(__arm__) || defined(_M_ARM) || defined(__aarch64__)) || \
     (defined(__m68k__) && (!defined(__mc68000__) && !defined(__mc68010__))) || \
index bce7394b26ef0eb18e28306ae4b5a2be558b2d92..d2fbf4d05346d471d9276fc591f141f28099548b 100644 (file)
@@ -134,7 +134,7 @@ str_to_lower(const char *string)
 
     zb_string = z_buf;
     while (*zb_string) {
-       *zb_string = tolower((unsigned char)(*zb_string));
+       *zb_string = ND_TOLOWER((unsigned char)(*zb_string));
        zb_string++;
     }
 
index 5a8c8fe52099cfbeeb3b32409dbea94ea3680bf3..aa6cf87f8c9703fb8a1dfae64bfe2bc990bd6332 100644 (file)
@@ -892,7 +892,7 @@ txtproto_print(netdissect_options *ndo, const u_char *pptr, u_int len,
 
        /* Capitalize the protocol name */
        for (pnp = protoname; *pnp != '\0'; pnp++)
-               ND_PRINT("%c", toupper((u_char)*pnp));
+               ND_PRINT("%c", ND_TOUPPER((u_char)*pnp));
 
        if (print_this) {
                /*