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

Diff of /code/trunk/pcretest.c

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

revision 1387 by ph10, Sat Oct 12 15:49:48 2013 UTC revision 1388 by ph10, Tue Nov 5 15:24:45 2013 UTC
# Line 2823  return 0; Line 2823  return 0;
2823    
2824    
2825  /*************************************************  /*************************************************
2826  *         Check newline indicator                *  *         Check multicharacter option            *
2827  *************************************************/  *************************************************/
2828    
2829  /* This is used both at compile and run-time to check for <xxx> escapes. Print  /* This is used both at compile and run-time to check for <xxx> escapes. Print
# Line 2832  a message and return 0 if there is no ma Line 2832  a message and return 0 if there is no ma
2832  Arguments:  Arguments:
2833    p           points after the leading '<'    p           points after the leading '<'
2834    f           file for error message    f           file for error message
2835      nl          TRUE to check only for newline settings
2836      stype       "modifier" or "escape sequence"
2837    
2838  Returns:      appropriate PCRE_NEWLINE_xxx flags, or 0  Returns:      appropriate PCRE_NEWLINE_xxx flags, or 0
2839  */  */
2840    
2841  static int  static int
2842  check_newline(pcre_uint8 *p, FILE *f)  check_mc_option(pcre_uint8 *p, FILE *f, BOOL nl, const char *stype)
2843  {  {
2844  if (strncmpic(p, (pcre_uint8 *)"cr>", 3) == 0) return PCRE_NEWLINE_CR;  if (strncmpic(p, (pcre_uint8 *)"cr>", 3) == 0) return PCRE_NEWLINE_CR;
2845  if (strncmpic(p, (pcre_uint8 *)"lf>", 3) == 0) return PCRE_NEWLINE_LF;  if (strncmpic(p, (pcre_uint8 *)"lf>", 3) == 0) return PCRE_NEWLINE_LF;
# Line 2846  if (strncmpic(p, (pcre_uint8 *)"anycrlf> Line 2848  if (strncmpic(p, (pcre_uint8 *)"anycrlf>
2848  if (strncmpic(p, (pcre_uint8 *)"any>", 4) == 0) return PCRE_NEWLINE_ANY;  if (strncmpic(p, (pcre_uint8 *)"any>", 4) == 0) return PCRE_NEWLINE_ANY;
2849  if (strncmpic(p, (pcre_uint8 *)"bsr_anycrlf>", 12) == 0) return PCRE_BSR_ANYCRLF;  if (strncmpic(p, (pcre_uint8 *)"bsr_anycrlf>", 12) == 0) return PCRE_BSR_ANYCRLF;
2850  if (strncmpic(p, (pcre_uint8 *)"bsr_unicode>", 12) == 0) return PCRE_BSR_UNICODE;  if (strncmpic(p, (pcre_uint8 *)"bsr_unicode>", 12) == 0) return PCRE_BSR_UNICODE;
2851  fprintf(f, "Unknown newline type at: <%s\n", p);  
2852    if (!nl)
2853      {
2854      if (strncmpic(p, (pcre_uint8 *)"JS>", 3) == 0) return PCRE_JAVASCRIPT_COMPAT;
2855      }
2856    
2857    fprintf(f, "Unknown %s at: <%s\n", stype, p);
2858  return 0;  return 0;
2859  }  }
2860    
# Line 2951  int verify_jit = 0; Line 2959  int verify_jit = 0;
2959  int yield = 0;  int yield = 0;
2960  int stack_size;  int stack_size;
2961  pcre_uint8 *dbuffer = NULL;  pcre_uint8 *dbuffer = NULL;
2962    pcre_uint8 lockout[24] = { 0 };
2963  size_t dbuffer_size = 1u << 14;  size_t dbuffer_size = 1u << 14;
2964  clock_t total_compile_time = 0;  clock_t total_compile_time = 0;
2965  clock_t total_study_time = 0;  clock_t total_study_time = 0;
# Line 3385  pcre32_stack_malloc = stack_malloc; Line 3394  pcre32_stack_malloc = stack_malloc;
3394  pcre32_stack_free = stack_free;  pcre32_stack_free = stack_free;
3395  #endif  #endif
3396    
3397  /* Heading line unless quiet, then prompt for first regex if stdin */  /* Heading line unless quiet */
3398    
3399  if (!quiet) fprintf(outfile, "PCRE version %s\n\n", version);  if (!quiet) fprintf(outfile, "PCRE version %s\n\n", version);
3400    
# Line 3436  while (!done) Line 3445  while (!done)
3445    p = buffer;    p = buffer;
3446    while (isspace(*p)) p++;    while (isspace(*p)) p++;
3447    if (*p == 0) continue;    if (*p == 0) continue;
3448    
3449      /* Handle option lock-out setting */
3450    
3451      if (*p == '<' && p[1] == ' ')
3452        {
3453        p += 2;
3454        while (isspace(*p)) p++;
3455        if (strncmp((char *)p, "forbid ", 7) == 0)
3456          {
3457          p += 7;
3458          while (isspace(*p)) p++;
3459          pp = lockout;
3460          while (!isspace(*p) && pp < lockout + sizeof(lockout) - 1)
3461            *pp++ = *p++;
3462          *pp = 0;
3463          }
3464        else
3465          {
3466          fprintf(outfile, "** Unrecognized special command '%s'\n", p);
3467          yield = 1;
3468          goto EXIT;
3469          }
3470        continue;
3471        }
3472    
3473    /* See if the pattern is to be loaded pre-compiled from a file. */    /* See if the pattern is to be loaded pre-compiled from a file. */
3474    
# Line 3616  while (!done) Line 3649  while (!done)
3649    *pp++ = 0;    *pp++ = 0;
3650    strcpy((char *)pbuffer, (char *)p);    strcpy((char *)pbuffer, (char *)p);
3651    
3652    /* Look for options after final delimiter */    /* Look for modifiers and options after the final delimiter. */
3653    
3654    options = default_options;    options = default_options;
3655    study_options = force_study_options;    study_options = force_study_options;
# Line 3624  while (!done) Line 3657  while (!done)
3657    
3658    while (*pp != 0)    while (*pp != 0)
3659      {      {
3660        /* Check to see whether this modifier has been locked out for this file.
3661        This is complicated for the multi-character options that begin with '<'.
3662        If there is no '>' in the lockout string, all multi-character modifiers are
3663        locked out. */
3664    
3665        if (strchr((char *)lockout, *pp) != NULL)
3666          {
3667          if (*pp == '<' && strchr((char *)lockout, '>') != NULL)
3668            {
3669            int x = check_mc_option(pp+1, outfile, FALSE, "modifier");
3670            if (x == 0) goto SKIP_DATA;
3671    
3672            for (ppp = lockout; *ppp != 0; ppp++)
3673              {
3674              if (*ppp == '<')
3675                {
3676                int y = check_mc_option(ppp+1, outfile, FALSE, "modifier");
3677                if (y == 0)
3678                  {
3679                  fprintf(outfile,
3680                    "** Error in modifier forbid data - giving up.\n");
3681                  yield = 1;
3682                  goto EXIT;
3683                  }
3684                if (x == y)
3685                  {
3686                  ppp = pp;
3687                  while (*ppp != '>') ppp++;
3688                  fprintf(outfile, "** The %.*s modifier is locked out - "
3689                    "giving up.\n", ppp - pp + 1, pp);
3690                  yield = 1;
3691                  goto EXIT;
3692                  }
3693                }
3694              }
3695            }
3696    
3697          /* The single-character modifiers are straightforward. */
3698    
3699          else
3700            {
3701            fprintf(outfile, "** The /%c modifier is locked out - giving up.\n", *pp);
3702            yield = 1;
3703            goto EXIT;
3704            }
3705          }
3706    
3707        /* The modifier is not locked out; handle it. */
3708    
3709      switch (*pp++)      switch (*pp++)
3710        {        {
3711        case 'f': options |= PCRE_FIRSTLINE; break;        case 'f': options |= PCRE_FIRSTLINE; break;
# Line 3748  while (!done) Line 3830  while (!done)
3830    
3831        case '<':        case '<':
3832          {          {
3833          if (strncmpic(pp, (pcre_uint8 *)"JS>", 3) == 0)          int x = check_mc_option(pp, outfile, FALSE, "modifier");
3834            {          if (x == 0) goto SKIP_DATA;
3835            options |= PCRE_JAVASCRIPT_COMPAT;          options |= x;
3836            pp += 3;          while (*pp++ != '>');
           }  
         else  
           {  
           int x = check_newline(pp, outfile);  
           if (x == 0) goto SKIP_DATA;  
           options |= x;  
           while (*pp++ != '>');  
           }  
3837          }          }
3838        break;        break;
3839    
# Line 3769  while (!done) Line 3843  while (!done)
3843        break;        break;
3844    
3845        default:        default:
3846        fprintf(outfile, "** Unknown option '%c'\n", pp[-1]);        fprintf(outfile, "** Unknown modifier '%c'\n", pp[-1]);
3847        goto SKIP_DATA;        goto SKIP_DATA;
3848        }        }
3849      }      }
# Line 4757  while (!done) Line 4831  while (!done)
4831    
4832          case '<':          case '<':
4833            {            {
4834            int x = check_newline(p, outfile);            int x = check_mc_option(p, outfile, TRUE, "escape sequence");
4835            if (x == 0) goto NEXT_DATA;            if (x == 0) goto NEXT_DATA;
4836            options |= x;            options |= x;
4837            while (*p++ != '>');            while (*p++ != '>');

Legend:
Removed from v.1387  
changed lines
  Added in v.1388

  ViewVC Help
Powered by ViewVC 1.1.5