Changeset 27730 in webkit for trunk/JavaScriptCore/pcre/dftables.cpp
- Timestamp:
- Nov 12, 2007, 3:04:41 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/pcre/dftables.cpp
r27689 r27730 38 38 */ 39 39 40 41 /* This is a freestanding support program to generate a file containing default 40 /* This is a freestanding support program to generate a file containing 42 41 character tables. The tables are built according to the default C 43 42 locale. */ … … 47 46 #include <ctype.h> 48 47 #include <stdio.h> 48 #include <stdlib.h> 49 49 #include <string.h> 50 50 51 51 #include "pcre_internal.h" 52 52 53 #include "pcre_maketables.cpp"54 55 53 int main(int argc, char **argv) 56 54 { 57 int i;58 FILE *f;59 const unsigned char *tables = pcre_maketables();60 const unsigned char *base_of_tables = tables;61 62 55 if (argc != 2) 63 56 { … … 66 59 } 67 60 68 f = fopen(argv[1], "wb");61 FILE* f = fopen(argv[1], "wb"); 69 62 if (f == NULL) 70 63 { … … 73 66 } 74 67 75 /* There are two fprintf() calls here, because gcc in pedantic mode complains 76 about the very long string otherwise. */ 68 int i; 77 69 78 70 fprintf(f, … … 87 79 "128 (ASCII characters). These tables are used when no external tables are\n" 88 80 "passed to PCRE. */\n\n" 89 "const unsigned char _pcre_default_tables[] = {\n\n" 90 "/* This table is a lower casing table. */\n\n"); 81 "const unsigned char _pcre_default_tables[%d] = {\n\n" 82 "/* This table is a lower casing table. */\n\n", tables_length); 83 84 if (lcc_offset != 0) 85 abort(); 91 86 92 87 fprintf(f, " "); 93 for (i = 0; i < 256; i++)88 for (i = 0; i < 128; i++) 94 89 { 95 90 if ((i & 7) == 0 && i != 0) fprintf(f, "\n "); 96 fprintf(f, " %3d", *tables++);97 if (i != 255) fprintf(f, ",");91 fprintf(f, "0x%02X", tolower(i)); 92 if (i != 127) fprintf(f, ", "); 98 93 } 99 94 fprintf(f, ",\n\n"); … … 101 96 fprintf(f, "/* This table is a case flipping table. */\n\n"); 102 97 98 if (fcc_offset != 128) 99 abort(); 100 103 101 fprintf(f, " "); 104 for (i = 0; i < 256; i++)102 for (i = 0; i < 128; i++) 105 103 { 106 104 if ((i & 7) == 0 && i != 0) fprintf(f, "\n "); 107 fprintf(f, " %3d", *tables++);108 if (i != 255) fprintf(f, ",");105 fprintf(f, "0x%02X", islower(i) ? toupper(i) : tolower(i)); 106 if (i != 127) fprintf(f, ", "); 109 107 } 110 108 fprintf(f, ",\n\n"); … … 113 111 "/* This table contains bit maps for various character classes.\n" 114 112 "Each map is 32 bytes long and the bits run from the least\n" 115 "significant end of each byte. The classes that have their own\n" 116 "maps are: space, xdigit, digit, upper, lower, word, graph\n" 117 "print, punct, and cntrl. Other classes are built from combinations. */\n\n"); 113 "significant end of each byte. The classes are: space, digit, word. */\n\n"); 114 115 if (cbits_offset != fcc_offset + 128) 116 abort(); 117 118 unsigned char cbit_table[cbit_length]; 119 memset(cbit_table, 0, cbit_length); 120 for (i = '0'; i <= '9'; i++) 121 cbit_table[cbit_digit + i / 8] |= 1 << (i & 7); 122 cbit_table[cbit_word + '_' / 8] |= 1 << ('_' & 7); 123 for (i = 0; i < 128; i++) 124 { 125 if (isalnum(i)) cbit_table[cbit_word + i/8] |= 1 << (i & 7); 126 if (isspace(i)) cbit_table[cbit_space + i/8] |= 1 << (i & 7); 127 } 118 128 119 129 fprintf(f, " "); … … 125 135 fprintf(f, "\n "); 126 136 } 127 fprintf(f, "0x%02 x", *tables++);128 if (i != cbit_length - 1) fprintf(f, ", ");137 fprintf(f, "0x%02X", cbit_table[i]); 138 if (i != cbit_length - 1) fprintf(f, ", "); 129 139 } 130 140 fprintf(f, ",\n\n"); … … 137 147 ctype_space, ctype_xdigit, ctype_word); 138 148 149 if (ctypes_offset != cbits_offset + cbit_length) 150 abort(); 151 139 152 fprintf(f, " "); 140 for (i = 0; i < 256; i++)153 for (i = 0; i < 128; i++) 141 154 { 142 if ((i & 7) == 0 && i != 0) 155 int x = 0; 156 if (isspace(i)) x += ctype_space; 157 if (isxdigit(i)) x += ctype_xdigit; 158 if (isalnum(i) || i == '_') x += ctype_word; 159 fprintf(f, "0x%02X", x); 160 if (i != 127) 161 fprintf(f, ", "); 162 else 163 fprintf(f, "};"); 164 if ((i & 7) == 7) 143 165 { 144 166 fprintf(f, " /* "); 145 if (isprint(i-8)) fprintf(f, " %c -", i-8); 146 else fprintf(f, "%3d-", i-8); 147 if (isprint(i-1)) fprintf(f, " %c ", i-1); 148 else fprintf(f, "%3d", i-1); 149 fprintf(f, " */\n "); 167 if (isprint(i - 7)) fprintf(f, " %c -", i - 7); 168 else fprintf(f, "%3d-", i - 7); 169 if (isprint(i)) fprintf(f, " %c ", i); 170 else fprintf(f, "%3d", i); 171 fprintf(f, " */\n"); 172 if (i != 127) 173 fprintf(f, " "); 150 174 } 151 fprintf(f, "0x%02x", *tables++);152 if (i != 255) fprintf(f, ",");153 175 } 154 176 155 fprintf(f, "};/* "); 156 if (isprint(i-8)) fprintf(f, " %c -", i-8); 157 else fprintf(f, "%3d-", i-8); 158 if (isprint(i-1)) fprintf(f, " %c ", i-1); 159 else fprintf(f, "%3d", i-1); 160 fprintf(f, " */\n\n/* End of chartables.c */\n"); 177 if (tables_length != ctypes_offset + 128) 178 abort(); 179 180 fprintf(f, "\n\n/* End of chartables.c */\n"); 161 181 162 182 fclose(f); 163 delete []base_of_tables;164 183 return 0; 165 184 }
Note:
See TracChangeset
for help on using the changeset viewer.