tholm@uvicctr.UUCP (Terrence W. Holm) (10/18/88)
EFTH MINIX report #50 - October 1988 - ctype(3) changes I have changed iscntrl(3), isprint(3), isgraph(3), toupper(3) and tolower(3) to be as defined in POSIX. "man" pages are included. Files changed: /usr/include/ctype.h and minix/lib/libc/ctype.c Details of changes: 1) isprint(3) now includes SPACE. 2) isgraph(3) added. 3) iscntrl(3) now includes all control characters. 4) The old toupper() and tolower() are now called _toupper() and _tolower(). 5) Subroutines were added to perform the correct toupper(3) and tolower(3). 6) Toascii(3) added. ---------------------------------------------------------- echo x - ctype.3 gres '^X' '' > ctype.3 << '/' XSUBROUTINES X ctype(3) - character type tests X XINVOCATION X #include <ctype.h> X X int isalpha( c ) X int c; X XEXPLANATION X There are 12 macros defined in ctype.h which test X whether <c> is within a specified domain. <c> must X be either EOF or an ASCII value from 0 to 127, except X for isascii(3) which accepts any int. X X isalpha(c) A..Z a..z X isupper(c) A..Z X islower(c) a..z X isdigit(c) 0..9 X isxdigit(c) 0..9 A..F a..f X isalnum(c) 0..9 A..Z a..z X isspace(c) HT LF VT FF CR SPACE X ispunct(c) !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ X isprint(c) SPACE..~ X isgraph(c) !..~ X iscntrl(c) NUL..US DEL X isascii(c) NUL..DEL X XRESULTS X <>0 : Test is true. X 0 : Test is false. X XREFERENCES X toascii(3), tolower(3), toupper(3), ascii(4) / echo x - toascii.3 gres '^X' '' > toascii.3 << '/' XSUBROUTINES X toascii(3) - convert to ASCII X XINVOCATION X #include <ctype.h> X X int toascii( c ) X int c; X XEXPLANATION X Toascii(3) maps an int into a value from 0 to 127. X This is necessary for some functions, such as X isupper(3). X XRESULTS X Lower seven bits of <c>. X XREFERENCES X ctype(3), tolower(3), toupper(3) / echo x - tolower.3 gres '^X' '' > tolower.3 << '/' XSUBROUTINES X tolower(3) - convert to lower case X XINVOCATION X #include <ctype.h> X X int tolower( c ) X int c; X X int _tolower( c ) X int c; X XEXPLANATION X These routines convert upper case ASCII characters X into lower case characters. Tolower(3) may be called X with any ASCII value from 0 to 127, if <c> is not an X upper case character then it is returned unchanged. X X _tolower(3) is a macro which can only be used if <c> X is an upper case character. X XRESULTS X Argument converted to lower case. X XREFERENCES X ctype(3), toascii(3), toupper(3) / echo x - toupper.3 gres '^X' '' > toupper.3 << '/' XSUBROUTINES X toupper(3) - convert to upper case X XINVOCATION X #include <ctype.h> X X int toupper( c ) X int c; X X int _toupper( c ) X int c; X XEXPLANATION X These routines convert lower case ASCII characters X into upper case characters. Toupper(3) may be called X with any ASCII value from 0 to 127, if <c> is not a X lower case character then it is returned unchanged. X X _toupper(3) is a macro which can only be used if <c> X is a lower case character. X XRESULTS X Argument converted to upper case. X XREFERENCES X ctype(3), toascii(3), tolower(3) / echo x - ascii.4 gres '^X' '' > ascii.4 << '/' XSTRUCTURES X ascii(4) - the ASCII character set X XEXPLANATION X The following table contains the 128 ASCII characters. X C program '\X' escapes are noted. X X Oct Dec Hex Char Oct Dec Hex Char X X 0 0 0x00 NUL \0 0100 64 0x40 @ X 01 1 0x01 SOH 0101 65 0x41 A X 02 2 0x02 STX 0102 66 0x42 B X 03 3 0x03 ETX 0103 67 0x43 C X 04 4 0x04 EOT 0104 68 0x44 D X 05 5 0x05 ENQ 0105 69 0x45 E X 06 6 0x06 ACK 0106 70 0x46 F X 07 7 0x07 BEL 0107 71 0x47 G X 010 8 0x08 BS \b 0110 72 0x48 H X 011 9 0x09 HT \t 0111 73 0x49 I X 012 10 0x0A LF \n 0112 74 0x4A J X 013 11 0x0B VT 0113 75 0x4B K X 014 12 0x0C FF \f 0114 76 0x4C L X 015 13 0x0D CR \r 0115 77 0x4D M X 016 14 0x0E SO 0116 78 0x4E N X 017 15 0x0F SI 0117 79 0x4F O X 020 16 0x10 DLE 0120 80 0x50 P X 021 17 0x11 DC1 0121 81 0x51 Q X 022 18 0x12 DC2 0122 82 0x52 R X 023 19 0x13 DC3 0123 83 0x53 S X 024 20 0x14 DC4 0124 84 0x54 T X 025 21 0x15 NAK 0125 85 0x55 U X 026 22 0x16 SYN 0126 86 0x56 V X 027 23 0x17 ETB 0127 87 0x57 W X 030 24 0x18 CAN 0130 88 0x58 X X 031 25 0x19 EM 0131 89 0x59 Y X 032 26 0x1A SUB 0132 90 0x5A Z X 033 27 0x1B ESC 0133 91 0x5B [ X 034 28 0x1C FS 0134 92 0x5C \ X 035 29 0x1D GS 0135 93 0x5D ] X 036 30 0x1E RS 0136 94 0x5E ^ X 037 31 0x1F US 0137 95 0x5F _ X 040 32 0x20 SPACE 0140 96 0x60 ` X 041 33 0x21 ! 0141 97 0x61 a X 042 34 0x22 " 0142 98 0x62 b X 043 35 0x23 # 0143 99 0x63 c X 044 36 0x24 $ 0144 100 0x64 d X 045 37 0x25 % 0145 101 0x65 e X 046 38 0x26 & 0146 102 0x66 f X 047 39 0x27 ' 0147 103 0x67 g X 050 40 0x28 ( 0150 104 0x68 h X 051 41 0x29 ) 0151 105 0x69 i X 052 42 0x2A * 0152 106 0x6A j X 053 43 0x2B + 0153 107 0x6B k X 054 44 0x2C , 0154 108 0x6C l X 055 45 0x2D - 0155 109 0x6D m X 056 46 0x2E . 0156 110 0x6E n X 057 47 0x2F / 0157 111 0x6F o X 060 48 0x30 0 0160 112 0x70 p X 061 49 0x31 1 0161 113 0x71 q X 062 50 0x32 2 0162 114 0x72 r X 063 51 0x33 3 0163 115 0x73 s X 064 52 0x34 4 0164 116 0x74 t X 065 53 0x35 5 0165 117 0x75 u X 066 54 0x36 6 0166 118 0x76 v X 067 55 0x37 7 0167 119 0x77 w X 070 56 0x38 8 0170 120 0x78 x X 071 57 0x39 9 0171 121 0x79 y X 072 58 0x3A : 0172 122 0x7A z X 073 59 0x3B ; 0173 123 0x7B { X 074 60 0x3C < 0174 124 0x7C | X 075 61 0x3D = 0175 125 0x7D } X 076 62 0x3E > 0176 126 0x7E ~ X 077 63 0x3F ? 0177 127 0x7F DEL / echo x - ctype.h gres '^X' '' > ctype.h << '/' X/* ctype.h */ X X/* Added isgraph(3) and toascii(3); renamed _toupper(3) */ X/* and _tolower(3) Terrence W. Holm Oct. 1988 */ X Xextern char _ctype_[]; X X#define _U 0001 X#define _L 0002 X#define _N 0004 X#define _S 0010 X#define _P 0020 X#define _C 0040 X#define _X 0100 X#define _SP 0200 X X#define isalpha(c) ((_ctype_+1)[c]&(_U|_L)) X#define isupper(c) ((_ctype_+1)[c]&_U) X#define islower(c) ((_ctype_+1)[c]&_L) X#define isdigit(c) ((_ctype_+1)[c]&_N) X#define isxdigit(c) ((_ctype_+1)[c]&(_N|_X)) X#define isspace(c) ((_ctype_+1)[c]&_S) X#define ispunct(c) ((_ctype_+1)[c]&_P) X#define isalnum(c) ((_ctype_+1)[c]&(_U|_L|_N)) X#define isprint(c) ((_ctype_+1)[c]&(_SP|_P|_U|_L|_N)) X#define isgraph(c) ((_ctype_+1)[c]&(_P|_U|_L|_N)) X#define iscntrl(c) ((_ctype_+1)[c]&_C) X#define isascii(c) ((unsigned)(c)<=0177) X X#define _toupper(c) ((c) - 'a' + 'A') X#define _tolower(c) ((c) - 'A' + 'a') X#define toascii(c) ((c) & 0177) / echo x - ctype.c gres '^X' '' > ctype.c << '/' X/* ctype.c */ X X/* Included ^I..^M in iscntrl(3). Added toupper(3) and */ X/* tolower(3) Terrence W. Holm Oct. 1988 */ X X X#include <ctype.h> X#include <stdio.h> X Xchar _ctype_[] = { X 0, X _C, _C, _C, _C, _C, _C, _C, _C, X _C, _S|_C, _S|_C, _S|_C, _S|_C, _S|_C, _C, _C, X _C, _C, _C, _C, _C, _C, _C, _C, X _C, _C, _C, _C, _C, _C, _C, _C, X _S|_SP, _P, _P, _P, _P, _P, _P, _P, X _P, _P, _P, _P, _P, _P, _P, _P, X _N, _N, _N, _N, _N, _N, _N, _N, X _N, _N, _P, _P, _P, _P, _P, _P, X _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, X _U, _U, _U, _U, _U, _U, _U, _U, X _U, _U, _U, _U, _U, _U, _U, _U, X _U, _U, _U, _P, _P, _P, _P, _P, X _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, X _L, _L, _L, _L, _L, _L, _L, _L, X _L, _L, _L, _L, _L, _L, _L, _L, X _L, _L, _L, _P, _P, _P, _P, _C X}; X X Xtoupper( c ) X int c; X { X return( islower(c) ? _toupper(c) : c ); X } X X Xtolower( c ) X int c; X { X return( isupper(c) ? _tolower(c) : c ); X } / ---------------------------------------------------------- Terrence W. Holm uw-beaver!uvicctr!tholm