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

Diff of /code/trunk/pcregrep.c

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

revision 667 by ph10, Mon Aug 22 14:57:32 2011 UTC revision 685 by ph10, Tue Sep 6 15:02:07 2011 UTC
# Line 168  static int error_count = 0; Line 168  static int error_count = 0;
168  static int filenames = FN_DEFAULT;  static int filenames = FN_DEFAULT;
169  static int only_matching = -1;  static int only_matching = -1;
170  static int process_options = 0;  static int process_options = 0;
171    
172    #ifdef SUPPORT_PCREGREP_JIT
173    static int study_options = PCRE_STUDY_JIT_COMPILE;
174    #else
175  static int study_options = 0;  static int study_options = 0;
176    #endif
177    
178  static unsigned long int match_limit = 0;  static unsigned long int match_limit = 0;
179  static unsigned long int match_limit_recursion = 0;  static unsigned long int match_limit_recursion = 0;
# Line 219  used to identify them. */ Line 224  used to identify them. */
224  #define N_M_LIMIT      (-13)  #define N_M_LIMIT      (-13)
225  #define N_M_LIMIT_REC  (-14)  #define N_M_LIMIT_REC  (-14)
226  #define N_BUFSIZE      (-15)  #define N_BUFSIZE      (-15)
227    #define N_NOJIT        (-16)
228    
229  static option_item optionlist[] = {  static option_item optionlist[] = {
230    { OP_NODATA,     N_NULL,   NULL,              "",              "  terminate options" },    { OP_NODATA,     N_NULL,   NULL,              "",              "  terminate options" },
# Line 239  static option_item optionlist[] = { Line 245  static option_item optionlist[] = {
245    { OP_NODATA,     'H',      NULL,              "with-filename", "force the prefixing filename on output" },    { OP_NODATA,     'H',      NULL,              "with-filename", "force the prefixing filename on output" },
246    { OP_NODATA,     'h',      NULL,              "no-filename",   "suppress the prefixing filename on output" },    { OP_NODATA,     'h',      NULL,              "no-filename",   "suppress the prefixing filename on output" },
247    { OP_NODATA,     'i',      NULL,              "ignore-case",   "ignore case distinctions" },    { OP_NODATA,     'i',      NULL,              "ignore-case",   "ignore case distinctions" },
248    { OP_NODATA,     'j',      NULL,              "jit",           "use JIT compiler if available" },  #ifdef SUPPORT_PCREGREP_JIT
249      { OP_NODATA,     N_NOJIT,  NULL,              "no-jit",        "do not use just-in-time compiler optimization" },
250    #else
251      { OP_NODATA,     N_NOJIT,  NULL,              "no-jit",        "ignored: this pcregrep does not support JIT" },
252    #endif
253    { OP_NODATA,     'l',      NULL,              "files-with-matches", "print only FILE names containing matches" },    { OP_NODATA,     'l',      NULL,              "files-with-matches", "print only FILE names containing matches" },
254    { OP_NODATA,     'L',      NULL,              "files-without-match","print only FILE names not containing matches" },    { OP_NODATA,     'L',      NULL,              "files-without-match","print only FILE names not containing matches" },
255    { OP_STRING,     N_LABEL,  &stdin_name,       "label=name",    "set name for standard input" },    { OP_STRING,     N_LABEL,  &stdin_name,       "label=name",    "set name for standard input" },
# Line 317  pcregrep_exit(int rc) Line 327  pcregrep_exit(int rc)
327  {  {
328  if (resource_error)  if (resource_error)
329    {    {
330    fprintf(stderr, "pcregrep: Error %d or %d means that a resource limit "    fprintf(stderr, "pcregrep: Error %d, %d or %d means that a resource limit "
331      "was exceeded.\n", PCRE_ERROR_MATCHLIMIT, PCRE_ERROR_RECURSIONLIMIT);      "was exceeded.\n", PCRE_ERROR_MATCHLIMIT, PCRE_ERROR_RECURSIONLIMIT,
332        PCRE_ERROR_JIT_STACKLIMIT);
333    fprintf(stderr, "pcregrep: Check your regex for nested unlimited loops.\n");    fprintf(stderr, "pcregrep: Check your regex for nested unlimited loops.\n");
334    }    }
335    
# Line 977  for (i = 0; i < pattern_count; i++) Line 988  for (i = 0; i < pattern_count; i++)
988    fprintf(stderr, "%s", msg);    fprintf(stderr, "%s", msg);
989    FWRITE(matchptr, 1, slen, stderr);   /* In case binary zero included */    FWRITE(matchptr, 1, slen, stderr);   /* In case binary zero included */
990    fprintf(stderr, "\n\n");    fprintf(stderr, "\n\n");
991    if (*mrc == PCRE_ERROR_MATCHLIMIT || *mrc == PCRE_ERROR_RECURSIONLIMIT)    if (*mrc == PCRE_ERROR_MATCHLIMIT || *mrc == PCRE_ERROR_RECURSIONLIMIT ||
992          *mrc == PCRE_ERROR_JIT_STACKLIMIT)
993      resource_error = TRUE;      resource_error = TRUE;
994    if (error_count++ > 20)    if (error_count++ > 20)
995      {      {
# Line 1857  switch(letter) Line 1869  switch(letter)
1869    {    {
1870    case N_FOFFSETS: file_offsets = TRUE; break;    case N_FOFFSETS: file_offsets = TRUE; break;
1871    case N_HELP: help(); pcregrep_exit(0);    case N_HELP: help(); pcregrep_exit(0);
   case N_LOFFSETS: line_offsets = number = TRUE; break;  
1872    case N_LBUFFER: line_buffered = TRUE; break;    case N_LBUFFER: line_buffered = TRUE; break;
1873      case N_LOFFSETS: line_offsets = number = TRUE; break;
1874      case N_NOJIT: study_options &= ~PCRE_STUDY_JIT_COMPILE; break;
1875    case 'c': count_only = TRUE; break;    case 'c': count_only = TRUE; break;
1876    case 'F': process_options |= PO_FIXED_STRINGS; break;    case 'F': process_options |= PO_FIXED_STRINGS; break;
1877    case 'H': filenames = FN_FORCE; break;    case 'H': filenames = FN_FORCE; break;
1878    case 'h': filenames = FN_NONE; break;    case 'h': filenames = FN_NONE; break;
1879    case 'i': options |= PCRE_CASELESS; break;    case 'i': options |= PCRE_CASELESS; break;
   case 'j': study_options |= PCRE_STUDY_JIT_COMPILE; break;  
1880    case 'l': omit_zero_count = TRUE; filenames = FN_MATCH_ONLY; break;    case 'l': omit_zero_count = TRUE; filenames = FN_MATCH_ONLY; break;
1881    case 'L': filenames = FN_NOMATCH_ONLY; break;    case 'L': filenames = FN_NOMATCH_ONLY; break;
1882    case 'M': multiline = TRUE; options |= PCRE_MULTILINE|PCRE_FIRSTLINE; break;    case 'M': multiline = TRUE; options |= PCRE_MULTILINE|PCRE_FIRSTLINE; break;
# Line 2048  char *patterns[MAX_PATTERN_COUNT]; Line 2060  char *patterns[MAX_PATTERN_COUNT];
2060  const char *locale_from = "--locale";  const char *locale_from = "--locale";
2061  const char *error;  const char *error;
2062    
2063    #ifdef SUPPORT_PCREGREP_JIT
2064    pcre_jit_stack *jit_stack = NULL;
2065    #endif
2066    
2067  /* Set the default line ending value from the default in the PCRE library;  /* Set the default line ending value from the default in the PCRE library;
2068  "lf", "cr", "crlf", and "any" are supported. Anything else is treated as "lf".  "lf", "cr", "crlf", and "any" are supported. Anything else is treated as "lf".
2069  Note that the return values from pcre_config(), though derived from the ASCII  Note that the return values from pcre_config(), though derived from the ASCII
# Line 2570  if (pattern_filename != NULL) Line 2586  if (pattern_filename != NULL)
2586    if (f != stdin) fclose(f);    if (f != stdin) fclose(f);
2587    }    }
2588    
2589  /* Study the regular expressions, as we will be running them many times */  /* Study the regular expressions, as we will be running them many times. Unless
2590    JIT has been explicitly disabled, arrange a stack for it to use. */
2591    
2592    #ifdef SUPPORT_PCREGREP_JIT
2593    if ((study_options & PCRE_STUDY_JIT_COMPILE) != 0)
2594      jit_stack = pcre_jit_stack_alloc(32*1024, 1024*1024);
2595    #endif
2596    
2597  for (j = 0; j < pattern_count; j++)  for (j = 0; j < pattern_count; j++)
2598    {    {
2599    hints_list[j] = pcre_study(pattern_list[j], study_options, &error);    hints_list[j] = pcre_study(pattern_list[j], study_options, &error);
# Line 2583  for (j = 0; j < pattern_count; j++) Line 2605  for (j = 0; j < pattern_count; j++)
2605      goto EXIT2;      goto EXIT2;
2606      }      }
2607    hint_count++;    hint_count++;
2608    #ifdef SUPPORT_PCREGREP_JIT
2609      if (jit_stack != NULL && hints_list[j] != NULL)
2610        pcre_assign_jit_stack(hints_list[j], NULL, jit_stack);
2611    #endif
2612    }    }
2613    
2614  /* If --match-limit or --recursion-limit was set, put the value(s) into the  /* If --match-limit or --recursion-limit was set, put the value(s) into the
# Line 2689  for (; i < argc; i++) Line 2715  for (; i < argc; i++)
2715    }    }
2716    
2717  EXIT:  EXIT:
2718    #ifdef SUPPORT_PCREGREP_JIT
2719    if (jit_stack != NULL) pcre_jit_stack_free(jit_stack);
2720    #endif
2721  if (main_buffer != NULL) free(main_buffer);  if (main_buffer != NULL) free(main_buffer);
2722  if (pattern_list != NULL)  if (pattern_list != NULL)
2723    {    {

Legend:
Removed from v.667  
changed lines
  Added in v.685

  ViewVC Help
Powered by ViewVC 1.1.5