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