/[pcre]/code/trunk/dftables.c
ViewVC logotype

Diff of /code/trunk/dftables.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 53 by nigel, Sat Feb 24 21:39:42 2007 UTC revision 75 by nigel, Sat Feb 24 21:40:37 2007 UTC
# Line 8  and semantics are as close as possible t Line 8  and semantics are as close as possible t
8    
9  Written by: Philip Hazel <ph10@cam.ac.uk>  Written by: Philip Hazel <ph10@cam.ac.uk>
10    
11             Copyright (c) 1997-2001 University of Cambridge             Copyright (c) 1997-2004 University of Cambridge
12    
13  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
14  Permission is granted to anyone to use this software for any purpose on any  Redistribution and use in source and binary forms, with or without
15  computer system, and to redistribute it freely, subject to the following  modification, are permitted provided that the following conditions are met:
16  restrictions:  
17        * Redistributions of source code must retain the above copyright notice,
18  1. This software is distributed in the hope that it will be useful,        this list of conditions and the following disclaimer.
    but WITHOUT ANY WARRANTY; without even the implied warranty of  
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
   
 2. The origin of this software must not be misrepresented, either by  
    explicit claim or by omission.  
   
 3. Altered versions must be plainly marked as such, and must not be  
    misrepresented as being the original software.  
   
 4. If PCRE is embedded in any software that is released under the GNU  
    General Purpose Licence (GPL), then the terms of that licence shall  
    supersede any condition above with which it is incompatible.  
 -----------------------------------------------------------------------------  
19    
20  See the file Tech.Notes for some information on the internals.      * Redistributions in binary form must reproduce the above copyright
21          notice, this list of conditions and the following disclaimer in the
22          documentation and/or other materials provided with the distribution.
23    
24        * Neither the name of the University of Cambridge nor the names of its
25          contributors may be used to endorse or promote products derived from
26          this software without specific prior written permission.
27    
28    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38    POSSIBILITY OF SUCH DAMAGE.
39    -----------------------------------------------------------------------------
40  */  */
41    
42    
# Line 50  order to be consistent. */ Line 56  order to be consistent. */
56  #include "maketables.c"  #include "maketables.c"
57    
58    
59  int main(void)  int main(int argc, char **argv)
60  {  {
61  int i;  int i;
62    FILE *f;
63  const unsigned char *tables = pcre_maketables();  const unsigned char *tables = pcre_maketables();
64    
65  printf(  if (argc != 2)
66      {
67      fprintf(stderr, "dftables: one filename argument is required\n");
68      return 1;
69      }
70    
71    f = fopen(argv[1], "w");
72    if (f == NULL)
73      {
74      fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]);
75      return 1;
76      }
77    
78    /* There are two fprintf() calls here, because gcc in pedantic mode complains
79    about the very long string otherwise. */
80    
81    fprintf(f,
82    "/*************************************************\n"    "/*************************************************\n"
83    "*      Perl-Compatible Regular Expressions       *\n"    "*      Perl-Compatible Regular Expressions       *\n"
84    "*************************************************/\n\n"    "*************************************************/\n\n"
85    "/* This file is automatically written by the dftables auxiliary \n"    "/* This file is automatically written by the dftables auxiliary \n"
86    "program. If you edit it by hand, you might like to edit the Makefile to \n"    "program. If you edit it by hand, you might like to edit the Makefile to \n"
87    "prevent its ever being regenerated.\n\n"    "prevent its ever being regenerated.\n\n");
88    fprintf(f,
89    "This file is #included in the compilation of pcre.c to build the default\n"    "This file is #included in the compilation of pcre.c to build the default\n"
90    "character tables which are used when no tables are passed to the compile\n"    "character tables which are used when no tables are passed to the compile\n"
91    "function. */\n\n"    "function. */\n\n"
92    "static unsigned char pcre_default_tables[] = {\n\n"    "static unsigned char pcre_default_tables[] = {\n\n"
93    "/* This table is a lower casing table. */\n\n");    "/* This table is a lower casing table. */\n\n");
94    
95  printf("  ");  fprintf(f, "  ");
96  for (i = 0; i < 256; i++)  for (i = 0; i < 256; i++)
97    {    {
98    if ((i & 7) == 0 && i != 0) printf("\n  ");    if ((i & 7) == 0 && i != 0) fprintf(f, "\n  ");
99    printf("%3d", *tables++);    fprintf(f, "%3d", *tables++);
100    if (i != 255) printf(",");    if (i != 255) fprintf(f, ",");
101    }    }
102  printf(",\n\n");  fprintf(f, ",\n\n");
103    
104  printf("/* This table is a case flipping table. */\n\n");  fprintf(f, "/* This table is a case flipping table. */\n\n");
105    
106  printf("  ");  fprintf(f, "  ");
107  for (i = 0; i < 256; i++)  for (i = 0; i < 256; i++)
108    {    {
109    if ((i & 7) == 0 && i != 0) printf("\n  ");    if ((i & 7) == 0 && i != 0) fprintf(f, "\n  ");
110    printf("%3d", *tables++);    fprintf(f, "%3d", *tables++);
111    if (i != 255) printf(",");    if (i != 255) fprintf(f, ",");
112    }    }
113  printf(",\n\n");  fprintf(f, ",\n\n");
114    
115  printf(  fprintf(f,
116    "/* This table contains bit maps for various character classes.\n"    "/* This table contains bit maps for various character classes.\n"
117    "Each map is 32 bytes long and the bits run from the least\n"    "Each map is 32 bytes long and the bits run from the least\n"
118    "significant end of each byte. The classes that have their own\n"    "significant end of each byte. The classes that have their own\n"
119    "maps are: space, xdigit, digit, upper, lower, word, graph\n"    "maps are: space, xdigit, digit, upper, lower, word, graph\n"
120    "print, punct, and cntrl. Other classes are built from combinations. */\n\n");    "print, punct, and cntrl. Other classes are built from combinations. */\n\n");
121    
122  printf("  ");  fprintf(f, "  ");
123  for (i = 0; i < cbit_length; i++)  for (i = 0; i < cbit_length; i++)
124    {    {
125    if ((i & 7) == 0 && i != 0)    if ((i & 7) == 0 && i != 0)
126      {      {
127      if ((i & 31) == 0) printf("\n");      if ((i & 31) == 0) fprintf(f, "\n");
128      printf("\n  ");      fprintf(f, "\n  ");
129      }      }
130    printf("0x%02x", *tables++);    fprintf(f, "0x%02x", *tables++);
131    if (i != cbit_length - 1) printf(",");    if (i != cbit_length - 1) fprintf(f, ",");
132    }    }
133  printf(",\n\n");  fprintf(f, ",\n\n");
134    
135  printf(  fprintf(f,
136    "/* This table identifies various classes of character by individual bits:\n"    "/* This table identifies various classes of character by individual bits:\n"
137    "  0x%02x   white space character\n"    "  0x%02x   white space character\n"
138    "  0x%02x   letter\n"    "  0x%02x   letter\n"
# Line 119  printf( Line 143  printf(
143    ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word,    ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word,
144    ctype_meta);    ctype_meta);
145    
146  printf("  ");  fprintf(f, "  ");
147  for (i = 0; i < 256; i++)  for (i = 0; i < 256; i++)
148    {    {
149    if ((i & 7) == 0 && i != 0)    if ((i & 7) == 0 && i != 0)
150      {      {
151      printf(" /* ");      fprintf(f, " /* ");
152      if (isprint(i-8)) printf(" %c -", i-8);      if (isprint(i-8)) fprintf(f, " %c -", i-8);
153        else printf("%3d-", i-8);        else fprintf(f, "%3d-", i-8);
154      if (isprint(i-1)) printf(" %c ", i-1);      if (isprint(i-1)) fprintf(f, " %c ", i-1);
155        else printf("%3d", i-1);        else fprintf(f, "%3d", i-1);
156      printf(" */\n  ");      fprintf(f, " */\n  ");
157      }      }
158    printf("0x%02x", *tables++);    fprintf(f, "0x%02x", *tables++);
159    if (i != 255) printf(",");    if (i != 255) fprintf(f, ",");
160    }    }
161    
162  printf("};/* ");  fprintf(f, "};/* ");
163  if (isprint(i-8)) printf(" %c -", i-8);  if (isprint(i-8)) fprintf(f, " %c -", i-8);
164    else printf("%3d-", i-8);    else fprintf(f, "%3d-", i-8);
165  if (isprint(i-1)) printf(" %c ", i-1);  if (isprint(i-1)) fprintf(f, " %c ", i-1);
166    else printf("%3d", i-1);    else fprintf(f, "%3d", i-1);
167  printf(" */\n\n/* End of chartables.c */\n");  fprintf(f, " */\n\n/* End of chartables.c */\n");
168    
169    fclose(f);
170  return 0;  return 0;
171  }  }
172    

Legend:
Removed from v.53  
changed lines
  Added in v.75

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12