/* File : kind.c Author : Richard A. O'Keefe Updated: 09/01/00 Purpose: Implement character classication. */ #ifndef lint static char SCCSid[] = "@(#)00/09/01 kind.c 1.4"; #endif/*lint*/ /* The things we want to know are - is this character a decimal digit? - what is its value as a decimal digit? - is this character a hexadecimal digit? - what is its value as a hexadecimal digit? - is this character a letter? - is this character a letter, digit, or "-_.:" character? - is this character one of ( ) [ ] & | , + * ? > ? - is this character a layout character? This is all handled with a simple code: 0.. 9 '0' .. '9' 10..15 'a' .. 'f'; 'A' .. 'F' 16 other letters 17 "-_.:" 18 "()[]&|,+*?>" 19 " \t\r\n" 20 everything else. This file also handles case mapping. Since this is really an XML parser, it's only meant for recognising reserved words, so BY DESIGN it only maps the letters 'a' to 'z' to upper case, leaving all other letters alone. */ #include "kind.h" char kind[256]; char upcase[256]; void set_up_kind(void) { int i; char const *p; #if UTF8 for (i = 0; i < 128; i++) kind[i] = 20; for (i = 128; i < 256; i++) kind[i] = 16; #else for (i = 0; i < 256; i++) kind[i] = 20; #endif for (i = '0'; i <= '9'; i++) kind[i] = i-'0'; for (i = 'a'; i <= 'f'; i++) kind[i] = i-'a'+10; for (i = 'A'; i <= 'F'; i++) kind[i] = i-'A'+10; for (i = 'g'; i <= 'z'; i++) kind[i] = 16; for (i = 'G'; i <= 'Z'; i++) kind[i] = 16; #ifndef UTF8 for (i = 0xc0; i < 0xff; i++) if (i != 0xd7 && i != 0xf7) kind[i] = 16; #endif for (p = "-_.:"; (i = *p++) != '\0'; ) kind[i] = 17; for (p = "()[]&|,+*?>"; (i = *p++) != '\0'; ) kind[i] = 18; for (p = " \t\r\n"; (i = *p++) != '\0'; ) kind[i] = 19; for (i = 0; i < 256; i++) upcase[i] = i; for (i = 'a'; i <='z'; i++) upcase[i] = i-32; }