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
00040
00041
00042
00043
00044
00045
00046 #ifdef HAVE_CONFIG_H
00047 #include "config.h"
00048 #endif
00049
00050 #include <ctype.h>
00051 #include <stdio.h>
00052 #include <string.h>
00053 #include <locale.h>
00054
00055 #include "pcre_internal.h"
00056
00057 #define DFTABLES
00058 #include "pcre_maketables.c"
00059
00060
00061 int main(int argc, char **argv)
00062 {
00063 FILE *f;
00064 int i = 1;
00065 const unsigned char *tables;
00066 const unsigned char *base_of_tables;
00067
00068
00069
00070
00071
00072 if (argc > 1 && strcmp(argv[1], "-L") == 0)
00073 {
00074 setlocale(LC_ALL, "");
00075 i++;
00076 }
00077
00078 if (argc < i + 1)
00079 {
00080 fprintf(stderr, "dftables: one filename argument is required\n");
00081 return 1;
00082 }
00083
00084 tables = pcre_maketables();
00085 base_of_tables = tables;
00086
00087 f = fopen(argv[i], "wb");
00088 if (f == NULL)
00089 {
00090 fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]);
00091 return 1;
00092 }
00093
00094
00095
00096
00097 fprintf(f,
00098 "/*************************************************\n"
00099 "* Perl-Compatible Regular Expressions *\n"
00100 "*************************************************/\n\n"
00101 "/* This file was automatically written by the dftables auxiliary\n"
00102 "program. It contains character tables that are used when no external\n"
00103 "tables are passed to PCRE by the application that calls it. The tables\n"
00104 "are used only for characters whose code values are less than 256.\n\n");
00105 fprintf(f,
00106 "The following #includes are present because without them gcc 4.x may remove\n"
00107 "the array definition from the final binary if PCRE is built into a static\n"
00108 "library and dead code stripping is activated. This leads to link errors.\n"
00109 "Pulling in the header ensures that the array gets flagged as \"someone\n"
00110 "outside this compilation unit might reference this\" and so it will always\n"
00111 "be supplied to the linker. */\n\n"
00112 "#ifdef HAVE_CONFIG_H\n"
00113 "#include \"config.h\"\n"
00114 "#endif\n\n"
00115 "#include \"pcre_internal.h\"\n\n");
00116 fprintf(f,
00117 "const unsigned char _pcre_default_tables[] = {\n\n"
00118 "/* This table is a lower casing table. */\n\n");
00119
00120 fprintf(f, " ");
00121 for (i = 0; i < 256; i++)
00122 {
00123 if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
00124 fprintf(f, "%3d", *tables++);
00125 if (i != 255) fprintf(f, ",");
00126 }
00127 fprintf(f, ",\n\n");
00128
00129 fprintf(f, "/* This table is a case flipping table. */\n\n");
00130
00131 fprintf(f, " ");
00132 for (i = 0; i < 256; i++)
00133 {
00134 if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
00135 fprintf(f, "%3d", *tables++);
00136 if (i != 255) fprintf(f, ",");
00137 }
00138 fprintf(f, ",\n\n");
00139
00140 fprintf(f,
00141 "/* This table contains bit maps for various character classes.\n"
00142 "Each map is 32 bytes long and the bits run from the least\n"
00143 "significant end of each byte. The classes that have their own\n"
00144 "maps are: space, xdigit, digit, upper, lower, word, graph\n"
00145 "print, punct, and cntrl. Other classes are built from combinations. */\n\n");
00146
00147 fprintf(f, " ");
00148 for (i = 0; i < cbit_length; i++)
00149 {
00150 if ((i & 7) == 0 && i != 0)
00151 {
00152 if ((i & 31) == 0) fprintf(f, "\n");
00153 fprintf(f, "\n ");
00154 }
00155 fprintf(f, "0x%02x", *tables++);
00156 if (i != cbit_length - 1) fprintf(f, ",");
00157 }
00158 fprintf(f, ",\n\n");
00159
00160 fprintf(f,
00161 "/* This table identifies various classes of character by individual bits:\n"
00162 " 0x%02x white space character\n"
00163 " 0x%02x letter\n"
00164 " 0x%02x decimal digit\n"
00165 " 0x%02x hexadecimal digit\n"
00166 " 0x%02x alphanumeric or '_'\n"
00167 " 0x%02x regular expression metacharacter or binary zero\n*/\n\n",
00168 ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word,
00169 ctype_meta);
00170
00171 fprintf(f, " ");
00172 for (i = 0; i < 256; i++)
00173 {
00174 if ((i & 7) == 0 && i != 0)
00175 {
00176 fprintf(f, " /* ");
00177 if (isprint(i-8)) fprintf(f, " %c -", i-8);
00178 else fprintf(f, "%3d-", i-8);
00179 if (isprint(i-1)) fprintf(f, " %c ", i-1);
00180 else fprintf(f, "%3d", i-1);
00181 fprintf(f, " */\n ");
00182 }
00183 fprintf(f, "0x%02x", *tables++);
00184 if (i != 255) fprintf(f, ",");
00185 }
00186
00187 fprintf(f, "};/* ");
00188 if (isprint(i-8)) fprintf(f, " %c -", i-8);
00189 else fprintf(f, "%3d-", i-8);
00190 if (isprint(i-1)) fprintf(f, " %c ", i-1);
00191 else fprintf(f, "%3d", i-1);
00192 fprintf(f, " */\n\n/* End of pcre_chartables.c */\n");
00193
00194 fclose(f);
00195 free((void *)base_of_tables);
00196 return 0;
00197 }
00198
00199