I have added these macros to c.h:
authorBruce Momjian
Sun, 25 Dec 2005 02:14:19 +0000 (02:14 +0000)
committerBruce Momjian
Sun, 25 Dec 2005 02:14:19 +0000 (02:14 +0000)
        #define HIGHBIT                 (0x80)
        #define IS_HIGHBIT_SET(ch)      ((unsigned char)(ch) & HIGHBIT)

and removed CSIGNBIT and mapped it uses to HIGHBIT.  I have also added
uses for IS_HIGHBIT_SET where appropriate.  This change is
purely for code clarity.

13 files changed:
src/backend/access/common/heaptuple.c
src/backend/parser/scansup.c
src/backend/utils/adt/network.c
src/backend/utils/adt/varbit.c
src/backend/utils/mb/conv.c
src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c
src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c
src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c
src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c
src/backend/utils/mb/wchar.c
src/include/c.h
src/include/utils/varbit.h
src/port/pgstrcasecmp.c

index f6683acd3d39bbd5328c6c3059ae715756d68119..3bf3db1b4f089c88cde595c51294576a63683bf2 100644 (file)
@@ -16,7 +16,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.104 2005/11/22 18:17:05 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.105 2005/12/25 02:14:17 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -111,7 +111,7 @@ heap_fill_tuple(TupleDesc tupleDesc,
    if (bit != NULL)
    {
        bitP = &bit[-1];
-       bitmask = CSIGNBIT;
+       bitmask = HIGHBIT;
    }
    else
    {
@@ -128,7 +128,7 @@ heap_fill_tuple(TupleDesc tupleDesc,
 
        if (bit != NULL)
        {
-           if (bitmask != CSIGNBIT)
+           if (bitmask != HIGHBIT)
                bitmask <<= 1;
            else
            {
@@ -210,7 +210,7 @@ DataFill(char *data,
    if (bit != NULL)
    {
        bitP = &bit[-1];
-       bitmask = CSIGNBIT;
+       bitmask = HIGHBIT;
    }
    else
    {
@@ -227,7 +227,7 @@ DataFill(char *data,
 
        if (bit != NULL)
        {
-           if (bitmask != CSIGNBIT)
+           if (bitmask != HIGHBIT)
                bitmask <<= 1;
            else
            {
index efa851ea0baa89abb334922ed5383b045f18fde5..fae0ef2e9a93049c810479392fdee2efc8b96613 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/parser/scansup.c,v 1.30 2005/10/15 02:49:22 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/parser/scansup.c,v 1.31 2005/12/25 02:14:17 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -149,7 +149,7 @@ downcase_truncate_identifier(const char *ident, int len, bool warn)
 
        if (ch >= 'A' && ch <= 'Z')
            ch += 'a' - 'A';
-       else if (ch >= 0x80 && isupper(ch))
+       else if (IS_HIGHBIT_SET(ch) && isupper(ch))
            ch = tolower(ch);
        result[i] = (char) ch;
    }
index 3b526d0655bc5984a5f69b136dec9e96371bfe3f..e3917960775761875d6976deed461918cdeca5bc 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * PostgreSQL type definitions for the INET and CIDR types.
  *
- * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.56 2005/10/17 16:24:19 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.57 2005/12/25 02:14:17 momjian Exp $
  *
  * Jon Postel RIP 16 Oct 1998
  */
@@ -904,16 +904,16 @@ bitncmp(void *l, void *r, int n)
    rb = ((const u_char *) r)[b];
    for (b = n % 8; b > 0; b--)
    {
-       if ((lb & 0x80) != (rb & 0x80))
+       if (IS_HIGHBIT_SET(lb) != IS_HIGHBIT_SET(rb))
        {
-           if (lb & 0x80)
-               return (1);
-           return (-1);
+           if (IS_HIGHBIT_SET(lb))
+               return 1;
+           return -1;
        }
        lb <<= 1;
        rb <<= 1;
    }
-   return (0);
+   return 0;
 }
 
 static bool
index 7dbbed16f6927dbeeb58fb9b2a5dd5110e1a44bd..8fb0e4186a06275516ff42b332f93e540683ccb3 100644 (file)
@@ -9,7 +9,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/adt/varbit.c,v 1.47 2005/10/15 02:49:30 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/adt/varbit.c,v 1.48 2005/12/25 02:14:17 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -120,7 +120,7 @@ bit_in(PG_FUNCTION_ARGS)
    {
        /* Parse the bit representation of the string */
        /* We know it fits, as bitlen was compared to atttypmod */
-       x = BITHIGH;
+       x = HIGHBIT;
        for (; *sp; sp++)
        {
            if (*sp == '1')
@@ -134,7 +134,7 @@ bit_in(PG_FUNCTION_ARGS)
            x >>= 1;
            if (x == 0)
            {
-               x = BITHIGH;
+               x = HIGHBIT;
                r++;
            }
        }
@@ -401,7 +401,7 @@ varbit_in(PG_FUNCTION_ARGS)
    {
        /* Parse the bit representation of the string */
        /* We know it fits, as bitlen was compared to atttypmod */
-       x = BITHIGH;
+       x = HIGHBIT;
        for (; *sp; sp++)
        {
            if (*sp == '1')
@@ -415,7 +415,7 @@ varbit_in(PG_FUNCTION_ARGS)
            x >>= 1;
            if (x == 0)
            {
-               x = BITHIGH;
+               x = HIGHBIT;
                r++;
            }
        }
@@ -477,14 +477,14 @@ varbit_out(PG_FUNCTION_ARGS)
        x = *sp;
        for (k = 0; k < BITS_PER_BYTE; k++)
        {
-           *r++ = (x & BITHIGH) ? '1' : '0';
+           *r++ = IS_HIGHBIT_SET(x) ? '1' : '0';
            x <<= 1;
        }
    }
    x = *sp;
    for (k = i; k < len; k++)
    {
-       *r++ = (x & BITHIGH) ? '1' : '0';
+       *r++ = IS_HIGHBIT_SET(x) ? '1' : '0';
        x <<= 1;
    }
    *r = '\0';
index a8c27f8cd354169e76976d58a20ab3b8609642c3..831a6061f19c68e3a7a34bf3b535fa72175aea8f 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/mb/conv.c,v 1.56 2005/10/29 00:31:52 petere Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/mb/conv.c,v 1.57 2005/12/25 02:14:17 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -413,7 +413,7 @@ LocalToUtf(unsigned char *iso, unsigned char *utf,
 
    for (; len > 0 && *iso; len -= l)
    {
-       if (*iso < 0x80)
+       if (!IS_HIGHBIT_SET(*iso))
        {
            *utf++ = *iso++;
            l = 1;
index 1e300086dbe2ef813e0ed3eafc5fe08ef235380b..17bad84329de7500f7242fb0646ef3435122496d 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c,v 1.10 2005/09/24 17:53:18 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c,v 1.11 2005/12/25 02:14:18 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -77,7 +77,7 @@ euc_cn2mic(unsigned char *euc, unsigned char *p, int len)
 
    while (len >= 0 && (c1 = *euc++))
    {
-       if (c1 & 0x80)
+       if (IS_HIGHBIT_SET(c1))
        {
            len -= 2;
            *p++ = LC_GB2312_80;
index f1a0aa112e8618cf26c8231dfbc314fff12c94da..bed09bf7370353c636affacf31058a9506f7988c 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c,v 1.10 2005/09/24 17:53:19 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c,v 1.11 2005/12/25 02:14:18 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -77,7 +77,7 @@ euc_kr2mic(unsigned char *euc, unsigned char *p, int len)
 
    while (len >= 0 && (c1 = *euc++))
    {
-       if (c1 & 0x80)
+       if (IS_HIGHBIT_SET(c1))
        {
            len -= 2;
            *p++ = LC_KS5601;
index d1223ba737fc6d7d853a051fe25cc321a6e08e82..3f11a0fba35ae20662ed755bd26ca6842f47419d 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c,v 1.10 2005/09/24 17:53:19 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c,v 1.11 2005/12/25 02:14:18 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -177,7 +177,7 @@ euc_tw2mic(unsigned char *euc, unsigned char *p, int len)
            *p++ = *euc++;
            *p++ = *euc++;
        }
-       else if (c1 & 0x80)
+       else if (IS_HIGHBIT_SET(c1))
        {                       /* CNS11643-1 */
            len -= 2;
            *p++ = LC_CNS11643_1;
index ca24b6d3f8c035befba98c51ecd943b1034181a3..f9208ee89a6c50e699497e6f5cc4c404861f37d6 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c,v 1.12 2005/09/24 17:53:24 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c,v 1.13 2005/12/25 02:14:18 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -46,12 +46,12 @@ iso8859_1_to_utf8(PG_FUNCTION_ARGS)
 
    while (len-- > 0 && (c = *src++))
    {
-       if (c < 0x80)
+       if (!IS_HIGHBIT_SET(c))
            *dest++ = c;
        else
        {
            *dest++ = (c >> 6) | 0xc0;
-           *dest++ = (c & 0x003f) | 0x80;
+           *dest++ = (c & 0x003f) | HIGHBIT;
        }
    }
    *dest = '\0';
index e7d6f7b020205b2628b83074949aef7915fa6fb7..3a0408614b5c224861586b2df81f30273b209067 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * conversion functions between pg_wchar and multibyte streams.
  * Tatsuo Ishii
- * $PostgreSQL: pgsql/src/backend/utils/mb/wchar.c,v 1.50 2005/12/24 17:19:40 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mb/wchar.c,v 1.51 2005/12/25 02:14:18 momjian Exp $
  *
  * WIN1250 client encoding updated by Pavel Behal
  *
@@ -79,7 +79,7 @@ static int    pg_euc2wchar_with_len
            *to |= *from++;
            len -= 3;
        }
-       else if ((*from & 0x80) && len >= 2)    /* JIS X 0208 KANJI */
+       else if (IS_HIGHBIT_SET(*from) && len >= 2) /* JIS X 0208 KANJI */
        {
            *to = *from++ << 8;
            *to |= *from++;
@@ -106,7 +106,7 @@ pg_euc_mblen(const unsigned char *s)
        len = 2;
    else if (*s == SS3)
        len = 3;
-   else if (*s & 0x80)
+   else if (IS_HIGHBIT_SET(*s))
        len = 2;
    else
        len = 1;
@@ -122,7 +122,7 @@ pg_euc_dsplen(const unsigned char *s)
        len = 2;
    else if (*s == SS3)
        len = 2;
-   else if (*s & 0x80)
+   else if (IS_HIGHBIT_SET(*s))
        len = 2;
    else
        len = 1;
@@ -153,7 +153,7 @@ pg_eucjp_dsplen(const unsigned char *s)
        len = 1;
    else if (*s == SS3)
        len = 2;
-   else if (*s & 0x80)
+   else if (IS_HIGHBIT_SET(*s))
        len = 2;
    else
        len = 1;
@@ -206,7 +206,7 @@ static int  pg_euccn2wchar_with_len
            *to |= *from++;
            len -= 3;
        }
-       else if ((*from & 0x80) && len >= 2)    /* code set 1 */
+       else if (IS_HIGHBIT_SET(*from) && len >= 2) /* code set 1 */
        {
            *to = *from++ << 8;
            *to |= *from++;
@@ -229,7 +229,7 @@ pg_euccn_mblen(const unsigned char *s)
 {
    int         len;
 
-   if (*s & 0x80)
+   if (IS_HIGHBIT_SET(*s))
        len = 2;
    else
        len = 1;
@@ -241,7 +241,7 @@ pg_euccn_dsplen(const unsigned char *s)
 {
    int         len;
 
-   if (*s & 0x80)
+   if (IS_HIGHBIT_SET(*s))
        len = 2;
    else
        len = 1;
@@ -274,7 +274,7 @@ static int  pg_euctw2wchar_with_len
            *to |= *from++;
            len -= 3;
        }
-       else if ((*from & 0x80) && len >= 2)    /* code set 2 */
+       else if (IS_HIGHBIT_SET(*from) && len >= 2) /* code set 2 */
        {
            *to = *from++ << 8;
            *to |= *from++;
@@ -301,7 +301,7 @@ pg_euctw_mblen(const unsigned char *s)
        len = 4;
    else if (*s == SS3)
        len = 3;
-   else if (*s & 0x80)
+   else if (IS_HIGHBIT_SET(*s))
        len = 2;
    else
        len = 1;
@@ -317,7 +317,7 @@ pg_euctw_dsplen(const unsigned char *s)
        len = 2;
    else if (*s == SS3)
        len = 2;
-   else if (*s & 0x80)
+   else if (IS_HIGHBIT_SET(*s))
        len = 2;
    else
        len = 1;
@@ -361,7 +361,7 @@ pg_utf2wchar_with_len(const unsigned char *from, pg_wchar *to, int len)
 
    while (len > 0 && *from)
    {
-       if ((*from & 0x80) == 0)
+       if (!IS_HIGHBIT_SET(*from))
        {
            *to = *from++;
            len--;
@@ -866,7 +866,7 @@ pg_verifymbstr(const char *mbstr, int len, bool noError)
                 * we expect that every multibyte char consists of bytes
                 * having the 8th bit set
                 */
-               if (i >= len || (mbstr[i] & 0x80) == 0)
+               if (i >= len || !IS_HIGHBIT_SET(mbstr[i]))
                {
                    char        buf[8 * 2 + 1];
                    char       *p = buf;
index 16b9f25a78c12e576bacdd88333638d31d2ea84e..1bf160f16180590319797a1c9dbe6dbe879d80dc 100644 (file)
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/c.h,v 1.192 2005/12/06 02:29:03 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/c.h,v 1.193 2005/12/25 02:14:18 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -704,7 +704,8 @@ typedef NameData *Name;
  */
 
 /* msb for char */
-#define CSIGNBIT (0x80)
+#define HIGHBIT                    (0x80)
+#define IS_HIGHBIT_SET(ch)     ((unsigned char)(ch) & HIGHBIT)
 
 #define STATUS_OK              (0)
 #define STATUS_ERROR           (-1)
index 0ce818249b772b0e68dba721e98fc1b9cac2b0c1..9565afed8457e970de6c813cf875fe26643beb9c 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/utils/varbit.h,v 1.21 2004/12/31 22:03:46 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/utils/varbit.h,v 1.22 2005/12/25 02:14:18 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -58,7 +58,6 @@ typedef struct
 #define VARBITEND(PTR)     (((bits8 *) (PTR)) + VARSIZE(PTR))
 /* Mask that will cover exactly one byte, i.e. BITS_PER_BYTE bits */
 #define BITMASK 0xFF
-#define BITHIGH 0x80
 
 
 extern Datum bit_in(PG_FUNCTION_ARGS);
index b66801547672830d4bb7a26af554258f242286c9..9feb573f6c040c88034ba623583367dc17b2af5e 100644 (file)
@@ -16,7 +16,7 @@
  *
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/port/pgstrcasecmp.c,v 1.5 2004/12/31 22:03:53 pgsql Exp $
+ * $PostgreSQL: pgsql/src/port/pgstrcasecmp.c,v 1.6 2005/12/25 02:14:19 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,12 +40,12 @@ pg_strcasecmp(const char *s1, const char *s2)
        {
            if (ch1 >= 'A' && ch1 <= 'Z')
                ch1 += 'a' - 'A';
-           else if (ch1 >= 0x80 && isupper(ch1))
+           else if (IS_HIGHBIT_SET(ch1) && isupper(ch1))
                ch1 = tolower(ch1);
 
            if (ch2 >= 'A' && ch2 <= 'Z')
                ch2 += 'a' - 'A';
-           else if (ch2 >= 0x80 && isupper(ch2))
+           else if (IS_HIGHBIT_SET(ch2) && isupper(ch2))
                ch2 = tolower(ch2);
 
            if (ch1 != ch2)
@@ -73,12 +73,12 @@ pg_strncasecmp(const char *s1, const char *s2, size_t n)
        {
            if (ch1 >= 'A' && ch1 <= 'Z')
                ch1 += 'a' - 'A';
-           else if (ch1 >= 0x80 && isupper(ch1))
+           else if (IS_HIGHBIT_SET(ch1) && isupper(ch1))
                ch1 = tolower(ch1);
 
            if (ch2 >= 'A' && ch2 <= 'Z')
                ch2 += 'a' - 'A';
-           else if (ch2 >= 0x80 && isupper(ch2))
+           else if (IS_HIGHBIT_SET(ch2) && isupper(ch2))
                ch2 = tolower(ch2);
 
            if (ch1 != ch2)
@@ -102,7 +102,7 @@ pg_toupper(unsigned char ch)
 {
    if (ch >= 'a' && ch <= 'z')
        ch += 'A' - 'a';
-   else if (ch >= 0x80 && islower(ch))
+   else if (IS_HIGHBIT_SET(ch) && islower(ch))
        ch = toupper(ch);
    return ch;
 }
@@ -119,7 +119,7 @@ pg_tolower(unsigned char ch)
 {
    if (ch >= 'A' && ch <= 'Z')
        ch += 'a' - 'A';
-   else if (ch >= 0x80 && isupper(ch))
+   else if (IS_HIGHBIT_SET(ch) && isupper(ch))
        ch = tolower(ch);
    return ch;
 }