Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* ctype.c */ |
2 | ||
3 | /* This file contains the tables and initialization function for elvis' | |
4 | * version of <ctype.h>. It should be portable. | |
5 | */ | |
6 | ||
7 | #include "config.h" | |
8 | #include "ctype.h" | |
9 | ||
08746e8b AM |
10 | void _ct_init P_((uchar *)); |
11 | ||
15637ed4 RG |
12 | uchar _ct_toupper[256]; |
13 | uchar _ct_tolower[256]; | |
14 | uchar _ct_ctypes[256]; | |
15 | ||
16 | /* This function initializes the tables used by the ctype macros. It should | |
17 | * be called at the start of the program. It can be called again anytime you | |
18 | * wish to change the non-standard "flipcase" list. The "flipcase" list is | |
19 | * a string of characters which are taken to be lowercase/uppercase pairs. | |
20 | * If you don't want to use any special flipcase characters, then pass an | |
21 | * empty string. | |
22 | */ | |
23 | void _ct_init(flipcase) | |
24 | uchar *flipcase; /* list of non-standard lower/upper letter pairs */ | |
25 | { | |
26 | int i; | |
27 | uchar *scan; | |
28 | ||
29 | /* reset all of the tables */ | |
30 | for (i = 0; i < 256; i++) | |
31 | { | |
32 | _ct_toupper[i] = _ct_tolower[i] = i; | |
33 | _ct_ctypes[i] = 0; | |
34 | } | |
35 | ||
36 | /* add the digits */ | |
37 | for (scan = (uchar *)"0123456789"; *scan; scan++) | |
38 | { | |
39 | _ct_ctypes[*scan] |= _CT_DIGIT | _CT_ALNUM; | |
40 | } | |
41 | ||
42 | /* add the whitespace */ | |
43 | for (scan = (uchar *)" \t\n\r\f"; *scan; scan++) | |
44 | { | |
45 | _ct_ctypes[*scan] |= _CT_SPACE; | |
46 | } | |
47 | ||
48 | /* add the standard ASCII letters */ | |
49 | for (scan = (uchar *)"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"; *scan; scan += 2) | |
50 | { | |
51 | _ct_ctypes[scan[0]] |= _CT_LOWER | _CT_ALNUM; | |
52 | _ct_ctypes[scan[1]] |= _CT_UPPER | _CT_ALNUM; | |
53 | _ct_toupper[scan[0]] = scan[1]; | |
54 | _ct_tolower[scan[1]] = scan[0]; | |
55 | } | |
56 | ||
57 | /* add the flipcase letters */ | |
58 | for (scan = flipcase; scan[0] && scan[1]; scan += 2) | |
59 | { | |
60 | _ct_ctypes[scan[0]] |= _CT_LOWER | _CT_ALNUM; | |
61 | _ct_ctypes[scan[1]] |= _CT_UPPER | _CT_ALNUM; | |
62 | _ct_toupper[scan[0]] = scan[1]; | |
63 | _ct_tolower[scan[1]] = scan[0]; | |
64 | } | |
65 | ||
66 | /* include '_' in the isalnum() list */ | |
67 | _ct_ctypes[UCHAR('_')] |= _CT_ALNUM; | |
68 | ||
69 | /* !!! find the control characters in an ASCII-dependent way */ | |
70 | for (i = 0; i < ' '; i++) | |
71 | { | |
72 | _ct_ctypes[i] |= _CT_CNTRL; | |
73 | } | |
74 | _ct_ctypes[127] |= _CT_CNTRL; | |
75 | _ct_ctypes[255] |= _CT_CNTRL; | |
76 | } |