/[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 1491 by ph10, Thu Apr 3 16:51:41 2014 UTC revision 1492 by ph10, Tue Jul 8 16:16:14 2014 UTC
# Line 455  Arguments: Line 455  Arguments:
455    s          pattern string to add    s          pattern string to add
456    after      if not NULL points to item to insert after    after      if not NULL points to item to insert after
457    
458  Returns:     new pattern block  Returns:     new pattern block or NULL on error
459  */  */
460    
461  static patstr *  static patstr *
# Line 471  if (strlen(s) > MAXPATLEN) Line 471  if (strlen(s) > MAXPATLEN)
471    {    {
472    fprintf(stderr, "pcregrep: pattern is too long (limit is %d bytes)\n",    fprintf(stderr, "pcregrep: pattern is too long (limit is %d bytes)\n",
473      MAXPATLEN);      MAXPATLEN);
474      free(p);
475    return NULL;    return NULL;
476    }    }
477  p->next = NULL;  p->next = NULL;
# Line 2549  while (fgets(buffer, PATBUFSIZE, f) != N Line 2550  while (fgets(buffer, PATBUFSIZE, f) != N
2550    afterwards, as a precaution against any later code trying to use it. */    afterwards, as a precaution against any later code trying to use it. */
2551    
2552    *patlastptr = add_pattern(buffer, *patlastptr);    *patlastptr = add_pattern(buffer, *patlastptr);
2553    if (*patlastptr == NULL) return FALSE;    if (*patlastptr == NULL)
2554        {
2555        if (f != stdin) fclose(f);
2556        return FALSE;
2557        }
2558    if (*patptr == NULL) *patptr = *patlastptr;    if (*patptr == NULL) *patptr = *patlastptr;
2559    
2560    /* This loop is needed because compiling a "pattern" when -F is set may add    /* This loop is needed because compiling a "pattern" when -F is set may add
# Line 2561  while (fgets(buffer, PATBUFSIZE, f) != N Line 2566  while (fgets(buffer, PATBUFSIZE, f) != N
2566      {      {
2567      if (!compile_pattern(*patlastptr, pcre_options, popts, TRUE, filename,      if (!compile_pattern(*patlastptr, pcre_options, popts, TRUE, filename,
2568          linenumber))          linenumber))
2569          {
2570          if (f != stdin) fclose(f);
2571        return FALSE;        return FALSE;
2572          }
2573      (*patlastptr)->string = NULL;            /* Insurance */      (*patlastptr)->string = NULL;            /* Insurance */
2574      if ((*patlastptr)->next == NULL) break;      if ((*patlastptr)->next == NULL) break;
2575      *patlastptr = (*patlastptr)->next;      *patlastptr = (*patlastptr)->next;
# Line 2962  if (locale == NULL) Line 2970  if (locale == NULL)
2970    locale_from = "LC_CTYPE";    locale_from = "LC_CTYPE";
2971    }    }
2972    
2973  /* If a locale has been provided, set it, and generate the tables the PCRE  /* If a locale is set, use it to generate the tables the PCRE needs. Otherwise,
2974  needs. Otherwise, pcretables==NULL, which causes the use of default tables. */  pcretables==NULL, which causes the use of default tables. */
2975    
2976  if (locale != NULL)  if (locale != NULL)
2977    {    {
# Line 2971  if (locale != NULL) Line 2979  if (locale != NULL)
2979      {      {
2980      fprintf(stderr, "pcregrep: Failed to set locale %s (obtained from %s)\n",      fprintf(stderr, "pcregrep: Failed to set locale %s (obtained from %s)\n",
2981        locale, locale_from);        locale, locale_from);
2982      return 2;      goto EXIT2;
2983      }      }
2984    pcretables = pcre_maketables();    pcretables = pcre_maketables();
2985    }    }
# Line 2986  if (colour_option != NULL && strcmp(colo Line 2994  if (colour_option != NULL && strcmp(colo
2994      {      {
2995      fprintf(stderr, "pcregrep: Unknown colour setting \"%s\"\n",      fprintf(stderr, "pcregrep: Unknown colour setting \"%s\"\n",
2996        colour_option);        colour_option);
2997      return 2;      goto EXIT2;
2998      }      }
2999    if (do_colour)    if (do_colour)
3000      {      {
# Line 3026  else if (strcmp(newline, "anycrlf") == 0 Line 3034  else if (strcmp(newline, "anycrlf") == 0
3034  else  else
3035    {    {
3036    fprintf(stderr, "pcregrep: Invalid newline specifier \"%s\"\n", newline);    fprintf(stderr, "pcregrep: Invalid newline specifier \"%s\"\n", newline);
3037    return 2;    goto EXIT2;
3038    }    }
3039    
3040  /* Interpret the text values for -d and -D */  /* Interpret the text values for -d and -D */
# Line 3039  if (dee_option != NULL) Line 3047  if (dee_option != NULL)
3047    else    else
3048      {      {
3049      fprintf(stderr, "pcregrep: Invalid value \"%s\" for -d\n", dee_option);      fprintf(stderr, "pcregrep: Invalid value \"%s\" for -d\n", dee_option);
3050      return 2;      goto EXIT2;
3051      }      }
3052    }    }
3053    
# Line 3050  if (DEE_option != NULL) Line 3058  if (DEE_option != NULL)
3058    else    else
3059      {      {
3060      fprintf(stderr, "pcregrep: Invalid value \"%s\" for -D\n", DEE_option);      fprintf(stderr, "pcregrep: Invalid value \"%s\" for -D\n", DEE_option);
3061      return 2;      goto EXIT2;
3062      }      }
3063    }    }
3064    
# Line 3251  EXIT: Line 3259  EXIT:
3259  if (jit_stack != NULL) pcre_jit_stack_free(jit_stack);  if (jit_stack != NULL) pcre_jit_stack_free(jit_stack);
3260  #endif  #endif
3261    
3262  if (main_buffer != NULL) free(main_buffer);  free(main_buffer);
3263    free((void *)pcretables);
3264    
3265  free_pattern_chain(patterns);  free_pattern_chain(patterns);
3266  free_pattern_chain(include_patterns);  free_pattern_chain(include_patterns);

Legend:
Removed from v.1491  
changed lines
  Added in v.1492

  ViewVC Help
Powered by ViewVC 1.1.5