/[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 75 by nigel, Sat Feb 24 21:40:37 2007 UTC revision 128 by ph10, Tue Mar 20 11:46:50 2007 UTC
# Line 2  Line 2 
2  *      Perl-Compatible Regular Expressions       *  *      Perl-Compatible Regular Expressions       *
3  *************************************************/  *************************************************/
4    
5  /*  /* PCRE is a library of functions to support regular expressions whose syntax
 PCRE is a library of functions to support regular expressions whose syntax  
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8  Written by: Philip Hazel <ph10@cam.ac.uk>                         Written by Philip Hazel
9               Copyright (c) 1997-2007 University of Cambridge
            Copyright (c) 1997-2004 University of Cambridge  
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 40  POSSIBILITY OF SUCH DAMAGE. Line 38  POSSIBILITY OF SUCH DAMAGE.
38  */  */
39    
40    
41  /* This is a support program to generate the file chartables.c, containing  /* This is a freestanding support program to generate a file containing
42  character tables of various kinds. They are built according to the default C  character tables for PCRE. The tables are built according to the current
43  locale and used as the default tables by PCRE. Now that pcre_maketables is  locale. Now that pcre_maketables is a function visible to the outside world, we
44  a function visible to the outside world, we make use of its code from here in  make use of its code from here in order to be consistent. */
 order to be consistent. */  
45    
46  #include <ctype.h>  #include <ctype.h>
47  #include <stdio.h>  #include <stdio.h>
48  #include <string.h>  #include <string.h>
49    #include <locale.h>
50    
51  #include "internal.h"  #include "pcre_internal.h"
52    
53  #define DFTABLES          /* maketables.c notices this */  #define DFTABLES          /* pcre_maketables.c notices this */
54  #include "maketables.c"  #include "pcre_maketables.c"
55    
56    
57  int main(int argc, char **argv)  int main(int argc, char **argv)
58  {  {
 int i;  
59  FILE *f;  FILE *f;
60  const unsigned char *tables = pcre_maketables();  int i = 1;
61    const unsigned char *tables;
62    const unsigned char *base_of_tables;
63    
64    /* By default, the default C locale is used rather than what the building user
65    happens to have set. However, if the -L option is given, set the locale from
66    the LC_xxx environment variables. */
67    
68  if (argc != 2)  if (argc > 1 && strcmp(argv[1], "-L") == 0)
69      {
70      setlocale(LC_ALL, "");        /* Set from environment variables */
71      i++;
72      }
73    
74    if (argc < i + 1)
75    {    {
76    fprintf(stderr, "dftables: one filename argument is required\n");    fprintf(stderr, "dftables: one filename argument is required\n");
77    return 1;    return 1;
78    }    }
79    
80  f = fopen(argv[1], "w");  tables = pcre_maketables();
81    base_of_tables = tables;
82    
83    f = fopen(argv[i], "wb");
84  if (f == NULL)  if (f == NULL)
85    {    {
86    fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]);    fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]);
87    return 1;    return 1;
88    }    }
89    
90  /* There are two fprintf() calls here, because gcc in pedantic mode complains  /* There are several fprintf() calls here, because gcc in pedantic mode
91  about the very long string otherwise. */  complains about the very long string otherwise. */
92    
93  fprintf(f,  fprintf(f,
94    "/*************************************************\n"    "/*************************************************\n"
95    "*      Perl-Compatible Regular Expressions       *\n"    "*      Perl-Compatible Regular Expressions       *\n"
96    "*************************************************/\n\n"    "*************************************************/\n\n"
97    "/* This file is automatically written by the dftables auxiliary \n"    "/* This file was automatically written by the dftables auxiliary\n"
98    "program. If you edit it by hand, you might like to edit the Makefile to \n"    "program. It contains character tables that are used when no external\n"
99    "prevent its ever being regenerated.\n\n");    "tables are passed to PCRE by the application that calls it. The tables\n"
100      "are used only for characters whose code values are less than 256.\n\n");
101    fprintf(f,
102      "The following #include is present because without it gcc 4.x may remove\n"
103      "the array definition from the final binary if PCRE is built into a static\n"
104      "library and dead code stripping is activated. This leads to link errors.\n"
105      "Pulling in the header ensures that the array gets flagged as \"someone\n"
106      "outside this compilation unit might reference this\" and so it will always\n"
107      "be supplied to the linker. */\n\n"
108      "#include \"pcre_internal.h\"\n\n");
109  fprintf(f,  fprintf(f,
110    "This file is #included in the compilation of pcre.c to build the default\n"    "const unsigned char _pcre_default_tables[] = {\n\n"
   "character tables which are used when no tables are passed to the compile\n"  
   "function. */\n\n"  
   "static unsigned char pcre_default_tables[] = {\n\n"  
111    "/* This table is a lower casing table. */\n\n");    "/* This table is a lower casing table. */\n\n");
112    
113  fprintf(f, "  ");  fprintf(f, "  ");
# Line 164  if (isprint(i-8)) fprintf(f, " %c -", i- Line 182  if (isprint(i-8)) fprintf(f, " %c -", i-
182    else fprintf(f, "%3d-", i-8);    else fprintf(f, "%3d-", i-8);
183  if (isprint(i-1)) fprintf(f, " %c ", i-1);  if (isprint(i-1)) fprintf(f, " %c ", i-1);
184    else fprintf(f, "%3d", i-1);    else fprintf(f, "%3d", i-1);
185  fprintf(f, " */\n\n/* End of chartables.c */\n");  fprintf(f, " */\n\n/* End of pcre_chartables.c */\n");
186    
187  fclose(f);  fclose(f);
188    free((void *)base_of_tables);
189  return 0;  return 0;
190  }  }
191    

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

  ViewVC Help
Powered by ViewVC 1.1.5