X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/c86f62585c172e92377d4a5d58b754ed72094cc3..c5537c6e21da5c92ab74fc567f663becc59d3f07:/src/src/pcre/dftables.c diff --git a/src/src/pcre/dftables.c b/src/src/pcre/dftables.c index 8458c60f1..33183496f 100644 --- a/src/src/pcre/dftables.c +++ b/src/src/pcre/dftables.c @@ -1,14 +1,14 @@ +/* $Cambridge: exim/src/src/pcre/dftables.c,v 1.7 2007/11/12 13:02:19 nm4 Exp $ */ + /************************************************* * Perl-Compatible Regular Expressions * *************************************************/ -/* -PCRE is a library of functions to support regular expressions whose syntax +/* PCRE is a library of functions to support regular expressions whose syntax and semantics are as close as possible to those of the Perl 5 language. -Written by: Philip Hazel - - Copyright (c) 1997-2004 University of Cambridge + Written by Philip Hazel + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -40,56 +40,83 @@ POSSIBILITY OF SUCH DAMAGE. */ -/* This is a support program to generate the file chartables.c, containing -character tables of various kinds. They are built according to the default C -locale and used as the default tables by PCRE. Now that pcre_maketables is -a function visible to the outside world, we make use of its code from here in -order to be consistent. */ +/* This is a freestanding support program to generate a file containing +character tables for PCRE. The tables are built according to the current +locale. Now that pcre_maketables is a function visible to the outside world, we +make use of its code from here in order to be consistent. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include #include #include +#include -#include "internal.h" +#include "pcre_internal.h" -#define DFTABLES /* maketables.c notices this */ -#include "maketables.c" +#define DFTABLES /* pcre_maketables.c notices this */ +#include "pcre_maketables.c" int main(int argc, char **argv) { -int i; FILE *f; -const unsigned char *tables = pcre_maketables(); +int i = 1; +const unsigned char *tables; +const unsigned char *base_of_tables; -if (argc != 2) +/* By default, the default C locale is used rather than what the building user +happens to have set. However, if the -L option is given, set the locale from +the LC_xxx environment variables. */ + +if (argc > 1 && strcmp(argv[1], "-L") == 0) + { + setlocale(LC_ALL, ""); /* Set from environment variables */ + i++; + } + +if (argc < i + 1) { fprintf(stderr, "dftables: one filename argument is required\n"); return 1; } -f = fopen(argv[1], "w"); +tables = pcre_maketables(); +base_of_tables = tables; + +f = fopen(argv[i], "wb"); if (f == NULL) { fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]); return 1; } -/* There are two fprintf() calls here, because gcc in pedantic mode complains -about the very long string otherwise. */ +/* There are several fprintf() calls here, because gcc in pedantic mode +complains about the very long string otherwise. */ fprintf(f, "/*************************************************\n" "* Perl-Compatible Regular Expressions *\n" "*************************************************/\n\n" - "/* This file is automatically written by the dftables auxiliary \n" - "program. If you edit it by hand, you might like to edit the Makefile to \n" - "prevent its ever being regenerated.\n\n"); + "/* This file was automatically written by the dftables auxiliary\n" + "program. It contains character tables that are used when no external\n" + "tables are passed to PCRE by the application that calls it. The tables\n" + "are used only for characters whose code values are less than 256.\n\n"); +fprintf(f, + "The following #includes are present because without them gcc 4.x may remove\n" + "the array definition from the final binary if PCRE is built into a static\n" + "library and dead code stripping is activated. This leads to link errors.\n" + "Pulling in the header ensures that the array gets flagged as \"someone\n" + "outside this compilation unit might reference this\" and so it will always\n" + "be supplied to the linker. */\n\n" + "#ifdef HAVE_CONFIG_H\n" + "#include \"config.h\"\n" + "#endif\n\n" + "#include \"pcre_internal.h\"\n\n"); fprintf(f, - "This file is #included in the compilation of pcre.c to build the default\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" + "const unsigned char _pcre_default_tables[] = {\n\n" "/* This table is a lower casing table. */\n\n"); fprintf(f, " "); @@ -164,9 +191,10 @@ if (isprint(i-8)) fprintf(f, " %c -", i-8); else fprintf(f, "%3d-", i-8); if (isprint(i-1)) fprintf(f, " %c ", i-1); else fprintf(f, "%3d", i-1); -fprintf(f, " */\n\n/* End of chartables.c */\n"); +fprintf(f, " */\n\n/* End of pcre_chartables.c */\n"); fclose(f); +free((void *)base_of_tables); return 0; }