[PATCH] fix for isprint(3)
YONETANI Tomokazu
qhwt+dfly at les.ath.cx
Sat May 7 00:10:15 PDT 2005
> Ok, turned out that this patch doesn't cope with rune <-> ctype
> conversions. I gave up messing with it and just backed out the
> last commit so as to unbreak some basic tools.
Anyway, I took a further look at files in lib/libc/locale, and
I think attached patch should fix the isprint() problem
(I'm in the process of rebuilding all the ports after the
libc version bump, with this patch applied).
Adding another _x macro in ctype.h should probably be OK, since
names beginning with an underscore followed by an uppercase letter
are reserved(I made sure it's not used elsewhere in the DragonFly
source tree by running the following command)
$ grep -r '[^a-zA-Z0-9_]_W[^a-zA-Z0-9_]' /usr/src
This patch requires full buildworld and probably rebuild of
any programs depending on ctype(3) macros, because it changes
the meaning of bits in the libc_ctype table.
Index: include/ctype.h
===================================================================
RCS file: /home/source/dragonfly/cvs/src/include/ctype.h,v
retrieving revision 1.8
diff -u -r1.8 ctype.h
--- include/ctype.h 6 May 2005 14:25:17 -0000 1.8
+++ include/ctype.h 7 May 2005 01:27:20 -0000
@@ -51,6 +51,7 @@
#define _C 0x20
#define _X 0x40
#define _B 0x80
+#define _W 0x100
extern const __uint16_t *__libc_ctype_;
extern const __int16_t *__libc_tolower_tab_;
@@ -92,7 +93,7 @@
#define isalpha(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & (_U|_L)))
#define isxdigit(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & (_N|_X)))
#define isalnum(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & (_U|_L|_N)))
-#define isprint(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & (_P|_U|_L|_N|_B)))
+#define isprint(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & (_P|_U|_L|_N|_W)))
#define isgraph(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & (_P|_U|_L|_N)))
#define iscntrl(c) ((int)((__libc_ctype_ + 1)[(int)(c)] & _C))
#define tolower(c) ((int)((__libc_tolower_tab_ + 1)[(int)(c)]))
Index: lib/libc/gen/ctype.c
===================================================================
RCS file: /home/source/dragonfly/cvs/src/lib/libc/gen/ctype.c,v
retrieving revision 1.1
diff -u -r1.1 ctype.c
--- lib/libc/gen/ctype.c 16 Mar 2005 06:54:41 -0000 1.1
+++ lib/libc/gen/ctype.c 7 May 2005 01:28:59 -0000
@@ -47,7 +47,7 @@
_C, _C|_S|_B, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C,
_C, _C, _C, _C, _C, _C, _C, _C,
_C, _C, _C, _C, _C, _C, _C, _C,
- _S|_B, _P, _P, _P, _P, _P, _P, _P,
+ _S|_B|_W, _P, _P, _P, _P, _P, _P, _P,
_P, _P, _P, _P, _P, _P, _P, _P,
_N, _N, _N, _N, _N, _N, _N, _N,
_N, _N, _P, _P, _P, _P, _P, _P,
Index: lib/libc/gen/isctype.c
===================================================================
RCS file: /home/source/dragonfly/cvs/src/lib/libc/gen/isctype.c,v
retrieving revision 1.3
diff -u -r1.3 isctype.c
--- lib/libc/gen/isctype.c 21 Apr 2005 16:36:34 -0000 1.3
+++ lib/libc/gen/isctype.c 7 May 2005 01:29:12 -0000
@@ -91,7 +91,7 @@
int
isprint(int c)
{
- return((__libc_ctype_ + 1)[c] & (_P|_U|_L|_N|_B));
+ return((__libc_ctype_ + 1)[c] & (_P|_U|_L|_N|_W));
}
#undef ispunct
Index: lib/libc/locale/rune.c
===================================================================
RCS file: /home/source/dragonfly/cvs/src/lib/libc/locale/rune.c,v
retrieving revision 1.4
diff -u -r1.4 rune.c
--- lib/libc/locale/rune.c 21 Apr 2005 16:36:34 -0000 1.4
+++ lib/libc/locale/rune.c 7 May 2005 02:25:31 -0000
@@ -444,7 +444,7 @@
rl->rl_runetype[x] |= _CTYPE_G;
if (new_ctype[1 + x] & _B)
rl->rl_runetype[x] |= _CTYPE_B;
- if ((new_ctype[1 + x] & (_P|_U|_L|_N|_B)) || x == ' ')
+ if (new_ctype[1 + x] & (_P|_U|_L|_N|_W))
rl->rl_runetype[x] |= (_CTYPE_R | _CTYPE_SW1);
/* XXX may fail on non-8bit encoding only */
Index: lib/libc/locale/runeglue.c
===================================================================
RCS file: /home/source/dragonfly/cvs/src/lib/libc/locale/runeglue.c,v
retrieving revision 1.1
diff -u -r1.1 runeglue.c
--- lib/libc/locale/runeglue.c 16 Mar 2005 06:54:41 -0000 1.1
+++ lib/libc/locale/runeglue.c 7 May 2005 04:00:03 -0000
@@ -123,6 +123,8 @@
new_ctype[i + 1] |= _X;
if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_B)
new_ctype[i + 1] |= _B;
+ if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_R)
+ new_ctype[i + 1] |= _W;
new_toupper[i + 1] = (int16_t)_CurrentRuneLocale->rl_mapupper[i];
new_tolower[i + 1] = (int16_t)_CurrentRuneLocale->rl_maplower[i];
More information about the Submit
mailing list