00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "ircd_chattr.h"
00040 #include <cstdio>
00041 #include <cctype>
00042 #include <cassert>
00043 #include <climits>
00044
00045 using std::numeric_limits;
00046
00047 static void zeroTables(void);
00048 static void markString(int macro, char const* s);
00049 static void unMarkString(int macro, char const* s);
00050 static void markRange(int macro, char from, char to);
00051 static void moveMacro(int from, int to);
00052 static void setLowHi(char const firstlow, char const lastlow, char const firsthi);
00053
00054 char NTL_tolower_tab[1 + CHAR_MAX - CHAR_MIN];
00055 char NTL_toupper_tab[1 + CHAR_MAX - CHAR_MIN];
00056 int NTL_char_attrib[1 + + CHAR_MAX - CHAR_MIN];
00057
00058
00059
00060
00061
00062
00063 static void makeTables(void)
00064 {
00065
00066 zeroTables();
00067
00068
00069 markRange(NTL_LOWER, 'a', 'z');
00070 markString(NTL_LOWER, "{|}~");
00071
00072 markRange(NTL_UPPER, 'A', 'Z');
00073 markString(NTL_UPPER, "[\\]^");
00074
00075 markRange(NTL_DIGIT, '0', '9');
00076
00077 markRange(NTL_CNTRL, '\000', '\037');
00078
00079 markString(NTL_PUNCT, "!\"#$%&'()*+,-./:;<=>?@_`");
00080
00081 markString(NTL_SPACE, "\011\012\013\014\015\040");
00082
00083
00084
00085
00086
00087 moveMacro(NTL_LOWER | NTL_UPPER, NTL_ALPHA);
00088 moveMacro(NTL_ALPHA | NTL_DIGIT, NTL_ALNUM);
00089 moveMacro(NTL_ALNUM | NTL_PUNCT, NTL_GRAPH);
00090
00091 moveMacro(NTL_GRAPH, NTL_PRINT);
00092 markString(NTL_PRINT, " ");
00093
00094 markRange(NTL_IRCCH, '\041', static_cast<char>(UCHAR_MAX));
00095 unMarkString(NTL_IRCCH, "\054\240");
00096
00097 markRange(NTL_IRCCL, '\300', '\326');
00098 markRange(NTL_IRCCL, '\330', '\336');
00099
00100 moveMacro(NTL_ALNUM, NTL_IRCHN);
00101 markString(NTL_IRCHN, "-_.");
00102
00103 moveMacro(NTL_DIGIT, NTL_IRCIP);
00104 markString(NTL_IRCIP, ".");
00105
00106 moveMacro(NTL_DIGIT, NTL_IRCIP6);
00107 markString(NTL_IRCIP6, ":.ABCDEFabcdef");
00108
00109 moveMacro(NTL_DIGIT | NTL_ALPHA, NTL_IRCNK);
00110 markString(NTL_IRCNK, "-_`");
00111
00112 moveMacro(NTL_ALNUM, NTL_IRCUI);
00113 markRange(NTL_IRCUI, '\xe0', '\xf6');
00114 markRange(NTL_IRCUI, '\xf8', '\xfe');
00115 markRange(NTL_IRCUI, '\xc0', '\xd6');
00116 markRange(NTL_IRCUI, '\xd8', '\xde');
00117 markString(NTL_IRCUI, ".-_^'`~");
00118 markString(NTL_EOL, "\n\r");
00119 markString(NTL_CHPFX, "#&");
00120 markString(NTL_KTIME, " ,-0123456789");
00121
00122
00123
00124 setLowHi('a', 'z', 'A');
00125 setLowHi('\xe0', '\xf6', '\xc0');
00126 setLowHi('\xf8', '\xfe', '\xd8');
00127 setLowHi('{', '~', '[');
00128 }
00129
00130
00131
00132
00133
00134
00135 static void dumphw(int* p, int beg);
00136 static void dumphb(char* p, int beg);
00137
00138 int main(void)
00139 {
00140 int i;
00141
00142
00143 makeTables();
00144
00145
00146 printf("//\n// Automatically Generated Tables - DO NOT EDIT\n//\n");
00147 printf("#include <climits>\n");
00148 printf("#include \"ircd_chattr.h\"\n");
00149
00150
00151 printf("char const ToLowerTab_8859_1[] = {\n");
00152 printf("#if (CHAR_MIN<0)\n");
00153 i = static_cast<int>(static_cast<char>(SCHAR_MIN));
00154 dumphb(NTL_tolower_tab, i);
00155 printf(" ,\n");
00156 printf("#endif // (CHAR_MIN<0)\n");
00157 i = 0;
00158 dumphb(NTL_tolower_tab, i);
00159 printf("#if (!(CHAR_MIN<0))\n");
00160 printf(" ,\n");
00161 i = static_cast<int>(static_cast<char>(SCHAR_MIN));
00162 dumphb(NTL_tolower_tab, i);
00163 printf("#endif // (!(CHAR_MIN<0))\n");
00164 printf(" };\n\n");
00165
00166
00167 printf("char const ToUpperTab_8859_1[] = {\n");
00168 printf("#if (CHAR_MIN<0)\n");
00169 i = static_cast<int>(static_cast<char>(SCHAR_MIN));
00170 dumphb(NTL_toupper_tab, i);
00171 printf(" ,\n");
00172 printf("#endif // (CHAR_MIN<0)\n");
00173 i = 0;
00174 dumphb(NTL_toupper_tab, i);
00175 printf("#if (!(CHAR_MIN<0))\n");
00176 printf(" ,\n");
00177 i = static_cast<int>(static_cast<char>(SCHAR_MIN));
00178 dumphb(NTL_toupper_tab, i);
00179 printf("#endif // (!(CHAR_MIN<0))\n");
00180 printf(" };\n\n");
00181
00182
00183 printf("ntl_type const IRCD_CharAttrTab[] = {\n");
00184 printf("#if (CHAR_MIN<0)\n");
00185 i = static_cast<int>(static_cast<char>(SCHAR_MIN));
00186 dumphw(NTL_char_attrib, i);
00187 printf(" ,\n");
00188 printf("#endif // (CHAR_MIN<0)\n");
00189 i = 0;
00190 dumphw(NTL_char_attrib, i);
00191 printf("#if (!(CHAR_MIN<0))\n");
00192 printf(" ,\n");
00193 i = static_cast<int>(static_cast<char>(SCHAR_MIN));
00194 dumphw(NTL_char_attrib, i);
00195 printf("#endif // (!(CHAR_MIN<0))\n");
00196 printf(" };\n\n");
00197
00198 return 0;
00199 }
00200
00201
00202
00203 static void zeroTables(void)
00204 {
00205 for (int i = CHAR_MIN; i <= CHAR_MAX; ++i)
00206 {
00207 NTL_tolower_tab[i - CHAR_MIN] = static_cast<char>(i);
00208 NTL_toupper_tab[i - CHAR_MIN] = static_cast<char>(i);
00209 NTL_char_attrib[i - CHAR_MIN] = 0;
00210 }
00211 }
00212
00213 static void markString(int macro, char const* s)
00214 {
00215 while (*s)
00216 NTL_char_attrib[*(s++) - CHAR_MIN] |= macro;
00217 }
00218
00219 static void unMarkString(int macro, char const* s)
00220 {
00221 while (*s)
00222 NTL_char_attrib[*(s++) - CHAR_MIN] &= ~macro;
00223 }
00224
00225 static void markRange(int macro, char from, char to)
00226 {
00227 assert(static_cast<unsigned char>(from) < static_cast<unsigned char>(to));
00228 for (int i = CHAR_MIN; i <= CHAR_MAX; ++i)
00229 if (static_cast<unsigned char>(i) >= static_cast<unsigned char>(from) &&
00230 static_cast<unsigned char>(i) <= static_cast<unsigned char>(to))
00231 NTL_char_attrib[i - CHAR_MIN] |= macro;
00232 }
00233
00234 static void moveMacro(int from, int to)
00235 {
00236 for (int i = CHAR_MIN; i <= CHAR_MAX; ++i)
00237 if ((NTL_char_attrib[i - CHAR_MIN] & from))
00238 NTL_char_attrib[i - CHAR_MIN] |= to;
00239 }
00240
00241 static void setLowHi(char const firstlow, char const lastlow, char const firsthi)
00242 {
00243 assert(static_cast<unsigned char>(firstlow) < static_cast<unsigned char>(lastlow));
00244 for (int i = CHAR_MIN; i <= CHAR_MAX; ++i)
00245 if (static_cast<unsigned char>(i) >= static_cast<unsigned char>(firstlow) &&
00246 static_cast<unsigned char>(i) <= static_cast<unsigned char>(lastlow))
00247 {
00248 int j = static_cast<char>(i + static_cast<int>(firsthi - firstlow));
00249 NTL_tolower_tab[j - CHAR_MIN] = static_cast<char>(i);
00250 NTL_toupper_tab[i - CHAR_MIN] = static_cast<char>(j);
00251 }
00252 }
00253
00254
00255
00256
00257 int const ROWSIZE = 8;
00258
00259 static void dumphb(char* tbl, int beg)
00260 {
00261 char* const p = &tbl[beg - CHAR_MIN];
00262 for (int i = 0; i <= SCHAR_MAX; i += ROWSIZE)
00263 {
00264 int k = i + ROWSIZE - 1;
00265 if (k > SCHAR_MAX)
00266 k = SCHAR_MAX;
00267
00268 unsigned char c = static_cast<unsigned char>(beg + i);
00269 printf("/*");
00270 if ((c > 0) && (c < SCHAR_MAX) && (std::isprint(c)) && (c != '\\')
00271 && (c != '\''))
00272 printf(" '%c'", c);
00273 else
00274 printf(" x%02x", ((int)c));
00275
00276 c = static_cast<unsigned char>(beg + k);
00277 printf("-");
00278 if ((c > 0) && (c < SCHAR_MAX) && (std::isprint(c)) && (c != '\\')
00279 && (c != '\''))
00280 printf("'%c'", c);
00281 else
00282 printf("x%02x", ((int)c));
00283 printf(" */");
00284
00285 for (int j = i; j <= k; ++j)
00286 {
00287 c = p[j];
00288 if ((c > 0) && (c < SCHAR_MAX) && (std::isprint(c)) && (c != '\\')
00289 && (c != '\''))
00290 printf(" '%c'", c);
00291 else
00292 printf(" '\\x%02x'", ((int)c));
00293 if (j < SCHAR_MAX)
00294 printf(",");
00295 }
00296 printf("\n");
00297 }
00298 }
00299
00300 static void dumphw(int* tbl, int beg)
00301 {
00302 int* p = &tbl[beg - CHAR_MIN];
00303 for (int i = 0; i <= SCHAR_MAX; i += ROWSIZE)
00304 {
00305 int k = i + ROWSIZE - 1;
00306 if (k > SCHAR_MAX)
00307 k = SCHAR_MAX;
00308
00309 unsigned char c = static_cast<unsigned char>(beg + i);
00310 printf("/*");
00311 if ((c > 0) && (c < SCHAR_MAX) && (std::isprint(c)) && (c != '\\')
00312 && (c != '\''))
00313 printf(" '%c'", c);
00314 else
00315 printf(" x%02x", ((int)c));
00316
00317 c = static_cast<unsigned char>(beg + k);
00318 printf("-");
00319 if ((c > 0) && (c < SCHAR_MAX) && (std::isprint(c)) && (c != '\\')
00320 && (c != '\''))
00321 printf("'%c'", c);
00322 else
00323 printf("x%02x", ((int)c));
00324 printf(" */");
00325
00326 for (int j = i; j <= k; ++j)
00327 {
00328 printf(" 0x%04x", p[j] & 0xffffffff);
00329 if (j < SCHAR_MAX)
00330 printf(",");
00331 }
00332 printf("\n");
00333 }
00334 }
00335