Subject: Re: isprint() and isblank()
To: None <tech-userlevel@netbsd.org>
From: Jun-ichiro itojun Hagino <itojun@iijlab.net>
List: tech-userlevel
Date: 01/21/2001 02:24:16
> The current NetBSD declaration of C locale (lib/libc/gen/ctype_.c)
> is incorrect about isblank('\t'). i think we should correct it.
> it is very easy, just make isblank('\t') from false to true.
>
> next, if you look at /usr/include/ctype.h, it says like this:
>>#define isprint(c) ((int)((_ctype_ + 1)[(int)(c)] & (_P|_U|_L|_N|_B)))
> _B is the flag bit for isblank. so any value "x" that makes isblank(x)
> to true, will make isprint(x) to true. so isprint('\t') becomes true.
> is it correct? if not, i intend to correct it too.
this is my proposed fix. unfortunately, since ctype.h defines
macros for is*, binaries need to be recompiled to use the new isprint()
declaration. isprint() hardcodes space (' ') so that we do not
change (old) ctype file format.
itojun
Index: lib/libc/gen/ctype_.c
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/gen/ctype_.c,v
retrieving revision 1.14
diff -u -r1.14 ctype_.c
--- lib/libc/gen/ctype_.c 1997/07/13 19:45:45 1.14
+++ lib/libc/gen/ctype_.c 2001/01/20 17:23:01
@@ -55,7 +55,7 @@
const unsigned char _C_ctype_[1 + _CTYPE_NUM_CHARS] = {
0,
_C, _C, _C, _C, _C, _C, _C, _C,
- _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C,
+ _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,
Index: include/ctype.h
===================================================================
RCS file: /cvsroot/basesrc/include/ctype.h,v
retrieving revision 1.18
diff -u -r1.18 ctype.h
--- include/ctype.h 2000/06/13 01:21:52 1.18
+++ include/ctype.h 2001/01/20 17:23:01
@@ -98,7 +98,7 @@
#define isalpha(c) ((int)((_ctype_ + 1)[(int)(c)] & (_U|_L)))
#define isxdigit(c) ((int)((_ctype_ + 1)[(int)(c)] & (_N|_X)))
#define isalnum(c) ((int)((_ctype_ + 1)[(int)(c)] & (_U|_L|_N)))
-#define isprint(c) ((int)((_ctype_ + 1)[(int)(c)] & (_P|_U|_L|_N|_B)))
+#define isprint(c) (isgraph(c) || (c) == ' ')
#define isgraph(c) ((int)((_ctype_ + 1)[(int)(c)] & (_P|_U|_L|_N)))
#define iscntrl(c) ((int)((_ctype_ + 1)[(int)(c)] & _C))
#define tolower(c) ((int)((_tolower_tab_ + 1)[(int)(c)]))