I have added these macros to c.h:
#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. Applied patch attached.
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
Index: src/backend/access/common/heaptuple.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v
retrieving revision 1.104
diff -c -c -u -r1.104 heaptuple.c
--- src/backend/access/common/heaptuple.c 22 Nov 2005 18:17:05 -0000 1.104
+++ src/backend/access/common/heaptuple.c 25 Dec 2005 02:06:36 -0000
@@ -111,7 +111,7 @@
if (bit != NULL)
{
bitP = &bit[-1];
- bitmask = CSIGNBIT;
+ bitmask = HIGHBIT;
}
else
{
@@ -128,7 +128,7 @@
if (bit != NULL)
{
- if (bitmask != CSIGNBIT)
+ if (bitmask != HIGHBIT)
bitmask <<= 1;
else
{
@@ -210,7 +210,7 @@
if (bit != NULL)
{
bitP = &bit[-1];
- bitmask = CSIGNBIT;
+ bitmask = HIGHBIT;
}
else
{
@@ -227,7 +227,7 @@
if (bit != NULL)
{
- if (bitmask != CSIGNBIT)
+ if (bitmask != HIGHBIT)
bitmask <<= 1;
else
{
Index: src/backend/parser/scansup.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/parser/scansup.c,v
retrieving revision 1.30
diff -c -c -u -r1.30 scansup.c
--- src/backend/parser/scansup.c 15 Oct 2005 02:49:22 -0000 1.30
+++ src/backend/parser/scansup.c 25 Dec 2005 02:06:37 -0000
@@ -149,7 +149,7 @@
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: src/backend/utils/adt/network.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/network.c,v
retrieving revision 1.56
diff -c -c -u -r1.56 network.c
--- src/backend/utils/adt/network.c 17 Oct 2005 16:24:19 -0000 1.56
+++ src/backend/utils/adt/network.c 25 Dec 2005 02:06:37 -0000
@@ -904,16 +904,16 @@
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: src/backend/utils/adt/varbit.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v
retrieving revision 1.47
diff -c -c -u -r1.47 varbit.c
--- src/backend/utils/adt/varbit.c 15 Oct 2005 02:49:30 -0000 1.47
+++ src/backend/utils/adt/varbit.c 25 Dec 2005 02:06:38 -0000
@@ -120,7 +120,7 @@
{
/* 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 @@
x >>= 1;
if (x == 0)
{
- x = BITHIGH;
+ x = HIGHBIT;
r++;
}
}
@@ -401,7 +401,7 @@
{
/* 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 @@
x >>= 1;
if (x == 0)
{
- x = BITHIGH;
+ x = HIGHBIT;
r++;
}
}
@@ -477,14 +477,14 @@
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: src/backend/utils/mb/conv.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/mb/conv.c,v
retrieving revision 1.56
diff -c -c -u -r1.56 conv.c
--- src/backend/utils/mb/conv.c 29 Oct 2005 00:31:52 -0000 1.56
+++ src/backend/utils/mb/conv.c 25 Dec 2005 02:06:38 -0000
@@ -413,7 +413,7 @@
for (; len > 0 && *iso; len -= l)
{
- if (*iso < 0x80)
+ if (!IS_HIGHBIT_SET(*iso))
{
*utf++ = *iso++;
l = 1;
Index: src/backend/utils/mb/wchar.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/mb/wchar.c,v
retrieving revision 1.50
diff -c -c -u -r1.50 wchar.c
--- src/backend/utils/mb/wchar.c 24 Dec 2005 17:19:40 -0000 1.50
+++ src/backend/utils/mb/wchar.c 25 Dec 2005 02:06:38 -0000
@@ -79,7 +79,7 @@
*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 @@
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 @@
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 @@
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 @@
*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 @@
{
int len;
- if (*s & 0x80)
+ if (IS_HIGHBIT_SET(*s))
len = 2;
else
len = 1;
@@ -241,7 +241,7 @@
{
int len;
- if (*s & 0x80)
+ if (IS_HIGHBIT_SET(*s))
len = 2;
else
len = 1;
@@ -274,7 +274,7 @@
*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 @@
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 @@
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 @@
while (len > 0 && *from)
{
- if ((*from & 0x80) == 0)
+ if (!IS_HIGHBIT_SET(*from))
{
*to = *from++;
len--;
@@ -866,7 +866,7 @@
* 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: src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c,v
retrieving revision 1.10
diff -c -c -u -r1.10 euc_cn_and_mic.c
--- src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c 24 Sep 2005 17:53:18 -0000 1.10
+++ src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c 25 Dec 2005 02:06:38 -0000
@@ -77,7 +77,7 @@
while (len >= 0 && (c1 = *euc++))
{
- if (c1 & 0x80)
+ if (IS_HIGHBIT_SET(c1))
{
len -= 2;
*p++ = LC_GB2312_80;
Index: src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c,v
retrieving revision 1.10
diff -c -c -u -r1.10 euc_kr_and_mic.c
--- src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c 24 Sep 2005 17:53:19 -0000 1.10
+++ src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c 25 Dec 2005 02:06:38 -0000
@@ -77,7 +77,7 @@
while (len >= 0 && (c1 = *euc++))
{
- if (c1 & 0x80)
+ if (IS_HIGHBIT_SET(c1))
{
len -= 2;
*p++ = LC_KS5601;
Index: src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c,v
retrieving revision 1.10
diff -c -c -u -r1.10 euc_tw_and_big5.c
--- src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c 24 Sep 2005 17:53:19 -0000 1.10
+++ src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c 25 Dec 2005 02:06:38 -0000
@@ -177,7 +177,7 @@
*p++ = *euc++;
*p++ = *euc++;
}
- else if (c1 & 0x80)
+ else if (IS_HIGHBIT_SET(c1))
{ /* CNS11643-1 */
len -= 2;
*p++ = LC_CNS11643_1;
Index: src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c,v
retrieving revision 1.12
diff -c -c -u -r1.12 utf8_and_iso8859_1.c
--- src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c 24 Sep 2005 17:53:24 -0000 1.12
+++ src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c 25 Dec 2005 02:06:38 -0000
@@ -46,12 +46,12 @@
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: src/include/c.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/c.h,v
retrieving revision 1.192
diff -c -c -u -r1.192 c.h
--- src/include/c.h 6 Dec 2005 02:29:03 -0000 1.192
+++ src/include/c.h 25 Dec 2005 02:06:39 -0000
@@ -704,7 +704,8 @@
*/
/* 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: src/include/utils/varbit.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/utils/varbit.h,v
retrieving revision 1.21
diff -c -c -u -r1.21 varbit.h
--- src/include/utils/varbit.h 31 Dec 2004 22:03:46 -0000 1.21
+++ src/include/utils/varbit.h 25 Dec 2005 02:06:39 -0000
@@ -58,7 +58,6 @@
#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: src/port/pgstrcasecmp.c
===================================================================
RCS file: /cvsroot/pgsql/src/port/pgstrcasecmp.c,v
retrieving revision 1.5
diff -c -c -u -r1.5 pgstrcasecmp.c
--- src/port/pgstrcasecmp.c 31 Dec 2004 22:03:53 -0000 1.5
+++ src/port/pgstrcasecmp.c 25 Dec 2005 02:06:40 -0000
@@ -40,12 +40,12 @@
{
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 @@
{
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 @@
{
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 @@
{
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;
}