/[pcre]/code/tags/pcre-2.08a/study.c
ViewVC logotype

Diff of /code/tags/pcre-2.08a/study.c

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

code/trunk/study.c revision 23 by nigel, Sat Feb 24 21:38:41 2007 UTC code/tags/pcre-2.08a/study.c revision 42 by nigel, Sat Feb 24 21:39:19 2007 UTC
# Line 9  the file Tech.Notes for some information Line 9  the file Tech.Notes for some information
9    
10  Written by: Philip Hazel <ph10@cam.ac.uk>  Written by: Philip Hazel <ph10@cam.ac.uk>
11    
12             Copyright (c) 1998 University of Cambridge             Copyright (c) 1997-1999 University of Cambridge
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Permission is granted to anyone to use this software for any purpose on any  Permission is granted to anyone to use this software for any purpose on any
# Line 25  restrictions: Line 25  restrictions:
25    
26  3. Altered versions must be plainly marked as such, and must not be  3. Altered versions must be plainly marked as such, and must not be
27     misrepresented as being the original software.     misrepresented as being the original software.
28    
29    4. If PCRE is embedded in any software that is released under the GNU
30       General Purpose Licence (GPL), then the terms of that licence shall
31       supersede any condition above with which it is incompatible.
32  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
33  */  */
34    
# Line 47  Arguments: Line 51  Arguments:
51    start_bits    points to the bit map    start_bits    points to the bit map
52    c             is the character    c             is the character
53    caseless      the caseless flag    caseless      the caseless flag
54      cd            the block with char table pointers
55    
56  Returns:        nothing  Returns:        nothing
57  */  */
58    
59  static void  static void
60  set_bit(uschar *start_bits, int c, BOOL caseless)  set_bit(uschar *start_bits, int c, BOOL caseless, compile_data *cd)
61  {  {
62  start_bits[c/8] |= (1 << (c&7));  start_bits[c/8] |= (1 << (c&7));
63  if (caseless && (pcre_ctypes[c] & ctype_letter) != 0)  if (caseless && (cd->ctypes[c] & ctype_letter) != 0)
64    start_bits[pcre_fcc[c]/8] |= (1 << (pcre_fcc[c]&7));    start_bits[cd->fcc[c]/8] |= (1 << (cd->fcc[c]&7));
65  }  }
66    
67    
# Line 73  Arguments: Line 78  Arguments:
78    code         points to an expression    code         points to an expression
79    start_bits   points to a 32-byte table, initialized to 0    start_bits   points to a 32-byte table, initialized to 0
80    caseless     the current state of the caseless flag    caseless     the current state of the caseless flag
81      cd           the block with char table pointers
82    
83  Returns:       TRUE if table built, FALSE otherwise  Returns:       TRUE if table built, FALSE otherwise
84  */  */
85    
86  static BOOL  static BOOL
87  set_start_bits(const uschar *code, uschar *start_bits, BOOL caseless)  set_start_bits(const uschar *code, uschar *start_bits, BOOL caseless,
88      compile_data *cd)
89  {  {
90  register int c;  register int c;
91    
92    /* This next statement and the later reference to dummy are here in order to
93    trick the optimizer of the IBM C compiler for OS/2 into generating correct
94    code. Apparently IBM isn't going to fix the problem, and we would rather not
95    disable optimization (in this module it actually makes a big difference, and
96    the pcre module can use all the optimization it can get). */
97    
98    volatile int dummy;
99    
100  do  do
101    {    {
102    const uschar *tcode = code + 3;    const uschar *tcode = code + 3;
# Line 96  do Line 111  do
111    
112      if ((int)*tcode >= OP_BRA || *tcode == OP_ASSERT)      if ((int)*tcode >= OP_BRA || *tcode == OP_ASSERT)
113        {        {
114        if (!set_start_bits(tcode, start_bits, caseless)) return FALSE;        if (!set_start_bits(tcode, start_bits, caseless, cd))
115            return FALSE;
116        }        }
117    
118      else switch(*tcode)      else switch(*tcode)
# Line 126  do Line 142  do
142    
143        case OP_BRAZERO:        case OP_BRAZERO:
144        case OP_BRAMINZERO:        case OP_BRAMINZERO:
145        if (!set_start_bits(++tcode, start_bits, caseless)) return FALSE;        if (!set_start_bits(++tcode, start_bits, caseless, cd))
146            return FALSE;
147          dummy = 1;
148        do tcode += (tcode[1] << 8) + tcode[2]; while (*tcode == OP_ALT);        do tcode += (tcode[1] << 8) + tcode[2]; while (*tcode == OP_ALT);
149        tcode += 3;        tcode += 3;
150        try_next = TRUE;        try_next = TRUE;
# Line 138  do Line 156  do
156        case OP_MINSTAR:        case OP_MINSTAR:
157        case OP_QUERY:        case OP_QUERY:
158        case OP_MINQUERY:        case OP_MINQUERY:
159        set_bit(start_bits, tcode[1], caseless);        set_bit(start_bits, tcode[1], caseless, cd);
160        tcode += 2;        tcode += 2;
161        try_next = TRUE;        try_next = TRUE;
162        break;        break;
# Line 147  do Line 165  do
165    
166        case OP_UPTO:        case OP_UPTO:
167        case OP_MINUPTO:        case OP_MINUPTO:
168        set_bit(start_bits, tcode[3], caseless);        set_bit(start_bits, tcode[3], caseless, cd);
169        tcode += 4;        tcode += 4;
170        try_next = TRUE;        try_next = TRUE;
171        break;        break;
# Line 162  do Line 180  do
180    
181        case OP_PLUS:        case OP_PLUS:
182        case OP_MINPLUS:        case OP_MINPLUS:
183        set_bit(start_bits, tcode[1], caseless);        set_bit(start_bits, tcode[1], caseless, cd);
184        break;        break;
185    
186        /* Single character type sets the bits and stops */        /* Single character type sets the bits and stops */
187    
188        case OP_NOT_DIGIT:        case OP_NOT_DIGIT:
189        for (c = 0; c < 32; c++) start_bits[c] |= ~pcre_cbits[c+cbit_digit];        for (c = 0; c < 32; c++)
190            start_bits[c] |= ~cd->cbits[c+cbit_digit];
191        break;        break;
192    
193        case OP_DIGIT:        case OP_DIGIT:
194        for (c = 0; c < 32; c++) start_bits[c] |= pcre_cbits[c+cbit_digit];        for (c = 0; c < 32; c++)
195            start_bits[c] |= cd->cbits[c+cbit_digit];
196        break;        break;
197    
198        case OP_NOT_WHITESPACE:        case OP_NOT_WHITESPACE:
199        for (c = 0; c < 32; c++) start_bits[c] |= ~pcre_cbits[c+cbit_space];        for (c = 0; c < 32; c++)
200            start_bits[c] |= ~cd->cbits[c+cbit_space];
201        break;        break;
202    
203        case OP_WHITESPACE:        case OP_WHITESPACE:
204        for (c = 0; c < 32; c++) start_bits[c] |= pcre_cbits[c+cbit_space];        for (c = 0; c < 32; c++)
205            start_bits[c] |= cd->cbits[c+cbit_space];
206        break;        break;
207    
208        case OP_NOT_WORDCHAR:        case OP_NOT_WORDCHAR:
209        for (c = 0; c < 32; c++)        for (c = 0; c < 32; c++)
210          start_bits[c] |= ~(pcre_cbits[c] | pcre_cbits[c+cbit_word]);          start_bits[c] |= ~(cd->cbits[c] | cd->cbits[c+cbit_word]);
211        break;        break;
212    
213        case OP_WORDCHAR:        case OP_WORDCHAR:
214        for (c = 0; c < 32; c++)        for (c = 0; c < 32; c++)
215          start_bits[c] |= (pcre_cbits[c] | pcre_cbits[c+cbit_word]);          start_bits[c] |= (cd->cbits[c] | cd->cbits[c+cbit_word]);
216        break;        break;
217    
218        /* One or more character type fudges the pointer and restarts, knowing        /* One or more character type fudges the pointer and restarts, knowing
# Line 221  do Line 243  do
243        switch(tcode[1])        switch(tcode[1])
244          {          {
245          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
246          for (c = 0; c < 32; c++) start_bits[c] |= ~pcre_cbits[c+cbit_digit];          for (c = 0; c < 32; c++)
247              start_bits[c] |= ~cd->cbits[c+cbit_digit];
248          break;          break;
249    
250          case OP_DIGIT:          case OP_DIGIT:
251          for (c = 0; c < 32; c++) start_bits[c] |= pcre_cbits[c+cbit_digit];          for (c = 0; c < 32; c++)
252              start_bits[c] |= cd->cbits[c+cbit_digit];
253          break;          break;
254    
255          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
256          for (c = 0; c < 32; c++) start_bits[c] |= ~pcre_cbits[c+cbit_space];          for (c = 0; c < 32; c++)
257              start_bits[c] |= ~cd->cbits[c+cbit_space];
258          break;          break;
259    
260          case OP_WHITESPACE:          case OP_WHITESPACE:
261          for (c = 0; c < 32; c++) start_bits[c] |= pcre_cbits[c+cbit_space];          for (c = 0; c < 32; c++)
262              start_bits[c] |= cd->cbits[c+cbit_space];
263          break;          break;
264    
265          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
266          for (c = 0; c < 32; c++)          for (c = 0; c < 32; c++)
267            start_bits[c] |= ~(pcre_cbits[c] | pcre_cbits[c+cbit_word]);            start_bits[c] |= ~(cd->cbits[c] | cd->cbits[c+cbit_word]);
268          break;          break;
269    
270          case OP_WORDCHAR:          case OP_WORDCHAR:
271          for (c = 0; c < 32; c++)          for (c = 0; c < 32; c++)
272            start_bits[c] |= (pcre_cbits[c] | pcre_cbits[c+cbit_word]);            start_bits[c] |= (cd->cbits[c] | cd->cbits[c+cbit_word]);
273          break;          break;
274          }          }
275    
# Line 316  pcre_study(const pcre *external_re, int Line 342  pcre_study(const pcre *external_re, int
342  uschar start_bits[32];  uschar start_bits[32];
343  real_pcre_extra *extra;  real_pcre_extra *extra;
344  const real_pcre *re = (const real_pcre *)external_re;  const real_pcre *re = (const real_pcre *)external_re;
345    compile_data compile_block;
346    
347  *errorptr = NULL;  *errorptr = NULL;
348    
# Line 338  present. */ Line 365  present. */
365  if ((re->options & (PCRE_ANCHORED|PCRE_FIRSTSET|PCRE_STARTLINE)) != 0)  if ((re->options & (PCRE_ANCHORED|PCRE_FIRSTSET|PCRE_STARTLINE)) != 0)
366    return NULL;    return NULL;
367    
368    /* Set the character tables in the block which is passed around */
369    
370    compile_block.lcc = re->tables + lcc_offset;
371    compile_block.fcc = re->tables + fcc_offset;
372    compile_block.cbits = re->tables + cbits_offset;
373    compile_block.ctypes = re->tables + ctypes_offset;
374    
375  /* See if we can find a fixed set of initial characters for the pattern. */  /* See if we can find a fixed set of initial characters for the pattern. */
376    
377  memset(start_bits, 0, 32 * sizeof(uschar));  memset(start_bits, 0, 32 * sizeof(uschar));
378  if (!set_start_bits(re->code, start_bits, (re->options & PCRE_CASELESS) != 0))  if (!set_start_bits(re->code, start_bits, (re->options & PCRE_CASELESS) != 0,
379    return NULL;    &compile_block)) return NULL;
380    
381  /* Get an "extra" block and put the information therein. */  /* Get an "extra" block and put the information therein. */
382    

Legend:
Removed from v.23  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.5