maketables.c
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:4k
源码类别:

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: maketables.c,v $
  4.  * PRODUCTION Revision 1000.0  2003/10/29 16:01:50  gouriano
  5.  * PRODUCTION PRODUCTION: IMPORTED [ORIGINAL] Dev-tree R1.1
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. /*************************************************
  10. *      Perl-Compatible Regular Expressions       *
  11. *************************************************/
  12. /*
  13. PCRE is a library of functions to support regular expressions whose syntax
  14. and semantics are as close as possible to those of the Perl 5 language.
  15. Written by: Philip Hazel <ph10@cam.ac.uk>
  16.            Copyright (c) 1997-2001 University of Cambridge
  17. -----------------------------------------------------------------------------
  18. Permission is granted to anyone to use this software for any purpose on any
  19. computer system, and to redistribute it freely, subject to the following
  20. restrictions:
  21. 1. This software is distributed in the hope that it will be useful,
  22.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  23.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  24. 2. The origin of this software must not be misrepresented, either by
  25.    explicit claim or by omission.
  26. 3. Altered versions must be plainly marked as such, and must not be
  27.    misrepresented as being the original software.
  28. 4. If PCRE is embedded in any software that is released under the GNU
  29.    General Purpose Licence (GPL), then the terms of that licence shall
  30.    supersede any condition above with which it is incompatible.
  31. -----------------------------------------------------------------------------
  32. See the file Tech.Notes for some information on the internals.
  33. */
  34. /* This file is compiled on its own as part of the PCRE library. However,
  35. it is also included in the compilation of dftables.c, in which case the macro
  36. DFTABLES is defined. */
  37. #ifndef DFTABLES
  38. #include "internal.h"
  39. #endif
  40. /*************************************************
  41. *           Create PCRE character tables         *
  42. *************************************************/
  43. /* This function builds a set of character tables for use by PCRE and returns
  44. a pointer to them. They are build using the ctype functions, and consequently
  45. their contents will depend upon the current locale setting. When compiled as
  46. part of the library, the store is obtained via pcre_malloc(), but when compiled
  47. inside dftables, use malloc().
  48. Arguments:   none
  49. Returns:     pointer to the contiguous block of data
  50. */
  51. const unsigned char *
  52. pcre_maketables(void)
  53. {
  54. unsigned char *yield, *p;
  55. int i;
  56. #ifndef DFTABLES
  57. yield = (unsigned char*)(pcre_malloc)(tables_length);
  58. #else
  59. yield = (unsigned char*)malloc(tables_length);
  60. #endif
  61. if (yield == NULL) return NULL;
  62. p = yield;
  63. /* First comes the lower casing table */
  64. for (i = 0; i < 256; i++) *p++ = tolower(i);
  65. /* Next the case-flipping table */
  66. for (i = 0; i < 256; i++) *p++ = islower(i)? toupper(i) : tolower(i);
  67. /* Then the character class tables. Don't try to be clever and save effort
  68. on exclusive ones - in some locales things may be different. */
  69. memset(p, 0, cbit_length);
  70. for (i = 0; i < 256; i++)
  71.   {
  72.   if (isdigit(i))
  73.     {
  74.     p[cbit_digit  + i/8] |= 1 << (i&7);
  75.     p[cbit_word   + i/8] |= 1 << (i&7);
  76.     }
  77.   if (isupper(i))
  78.     {
  79.     p[cbit_upper  + i/8] |= 1 << (i&7);
  80.     p[cbit_word   + i/8] |= 1 << (i&7);
  81.     }
  82.   if (islower(i))
  83.     {
  84.     p[cbit_lower  + i/8] |= 1 << (i&7);
  85.     p[cbit_word   + i/8] |= 1 << (i&7);
  86.     }
  87.   if (i == '_')   p[cbit_word   + i/8] |= 1 << (i&7);
  88.   if (isspace(i)) p[cbit_space  + i/8] |= 1 << (i&7);
  89.   if (isxdigit(i))p[cbit_xdigit + i/8] |= 1 << (i&7);
  90.   if (isgraph(i)) p[cbit_graph  + i/8] |= 1 << (i&7);
  91.   if (isprint(i)) p[cbit_print  + i/8] |= 1 << (i&7);
  92.   if (ispunct(i)) p[cbit_punct  + i/8] |= 1 << (i&7);
  93.   if (iscntrl(i)) p[cbit_cntrl  + i/8] |= 1 << (i&7);
  94.   }
  95. p += cbit_length;
  96. /* Finally, the character type table */
  97. for (i = 0; i < 256; i++)
  98.   {
  99.   int x = 0;
  100.   if (isspace(i)) x += ctype_space;
  101.   if (isalpha(i)) x += ctype_letter;
  102.   if (isdigit(i)) x += ctype_digit;
  103.   if (isxdigit(i)) x += ctype_xdigit;
  104.   if (isalnum(i) || i == '_') x += ctype_word;
  105.   if (strchr("*+?{^.$|()[", i) != 0) x += ctype_meta;
  106.   *p++ = x;
  107.   }
  108. return yield;
  109. }
  110. /* End of maketables.c */