/[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 120 by ph10, Fri Mar 9 15:59:06 2007 UTC revision 121 by ph10, Mon Mar 12 12:12:47 2007 UTC
# Line 119  static char *locale = NULL; Line 119  static char *locale = NULL;
119  static const unsigned char *pcretables = NULL;  static const unsigned char *pcretables = NULL;
120    
121  static int  pattern_count = 0;  static int  pattern_count = 0;
122  static pcre **pattern_list;  static pcre **pattern_list = NULL;
123  static pcre_extra **hints_list;  static pcre_extra **hints_list = NULL;
124    
125  static char *include_pattern = NULL;  static char *include_pattern = NULL;
126  static char *exclude_pattern = NULL;  static char *exclude_pattern = NULL;
# Line 1866  hints_list = (pcre_extra **)malloc(MAX_P Line 1866  hints_list = (pcre_extra **)malloc(MAX_P
1866  if (pattern_list == NULL || hints_list == NULL)  if (pattern_list == NULL || hints_list == NULL)
1867    {    {
1868    fprintf(stderr, "pcregrep: malloc failed\n");    fprintf(stderr, "pcregrep: malloc failed\n");
1869    return 2;    goto EXIT2;
1870    }    }
1871    
1872  /* If no patterns were provided by -e, and there is no file provided by -f,  /* If no patterns were provided by -e, and there is no file provided by -f,
# Line 1885  for (j = 0; j < cmd_pattern_count; j++) Line 1885  for (j = 0; j < cmd_pattern_count; j++)
1885    {    {
1886    if (!compile_pattern(patterns[j], pcre_options, NULL,    if (!compile_pattern(patterns[j], pcre_options, NULL,
1887         (j == 0 && cmd_pattern_count == 1)? 0 : j + 1))         (j == 0 && cmd_pattern_count == 1)? 0 : j + 1))
1888      return 2;      goto EXIT2;
1889    }    }
1890    
1891  /* Compile the regular expressions that are provided in a file. */  /* Compile the regular expressions that are provided in a file. */
# Line 1909  if (pattern_filename != NULL) Line 1909  if (pattern_filename != NULL)
1909        {        {
1910        fprintf(stderr, "pcregrep: Failed to open %s: %s\n", pattern_filename,        fprintf(stderr, "pcregrep: Failed to open %s: %s\n", pattern_filename,
1911          strerror(errno));          strerror(errno));
1912        return 2;        goto EXIT2;
1913        }        }
1914      filename = pattern_filename;      filename = pattern_filename;
1915      }      }
# Line 1922  if (pattern_filename != NULL) Line 1922  if (pattern_filename != NULL)
1922      linenumber++;      linenumber++;
1923      if (buffer[0] == 0) continue;   /* Skip blank lines */      if (buffer[0] == 0) continue;   /* Skip blank lines */
1924      if (!compile_pattern(buffer, pcre_options, filename, linenumber))      if (!compile_pattern(buffer, pcre_options, filename, linenumber))
1925        return 2;        goto EXIT2;
1926      }      }
1927    
1928    if (f != stdin) fclose(f);    if (f != stdin) fclose(f);
# Line 1938  for (j = 0; j < pattern_count; j++) Line 1938  for (j = 0; j < pattern_count; j++)
1938      char s[16];      char s[16];
1939      if (pattern_count == 1) s[0] = 0; else sprintf(s, " number %d", j);      if (pattern_count == 1) s[0] = 0; else sprintf(s, " number %d", j);
1940      fprintf(stderr, "pcregrep: Error while studying regex%s: %s\n", s, error);      fprintf(stderr, "pcregrep: Error while studying regex%s: %s\n", s, error);
1941      return 2;      goto EXIT2;
1942      }      }
1943    }    }
1944    
# Line 1952  if (exclude_pattern != NULL) Line 1952  if (exclude_pattern != NULL)
1952      {      {
1953      fprintf(stderr, "pcregrep: Error in 'exclude' regex at offset %d: %s\n",      fprintf(stderr, "pcregrep: Error in 'exclude' regex at offset %d: %s\n",
1954        errptr, error);        errptr, error);
1955      return 2;      goto EXIT2;
1956      }      }
1957    }    }
1958    
# Line 1964  if (include_pattern != NULL) Line 1964  if (include_pattern != NULL)
1964      {      {
1965      fprintf(stderr, "pcregrep: Error in 'include' regex at offset %d: %s\n",      fprintf(stderr, "pcregrep: Error in 'include' regex at offset %d: %s\n",
1966        errptr, error);        errptr, error);
1967      return 2;      goto EXIT2;
1968      }      }
1969    }    }
1970    
1971  /* If there are no further arguments, do the business on stdin and exit. */  /* If there are no further arguments, do the business on stdin and exit. */
1972    
1973  if (i >= argc)  if (i >= argc)
1974    return pcregrep(stdin, (filenames > FN_DEFAULT)? stdin_name : NULL);    {
1975      rc = pcregrep(stdin, (filenames > FN_DEFAULT)? stdin_name : NULL);
1976      goto EXIT;
1977      }
1978    
1979  /* Otherwise, work through the remaining arguments as files or directories.  /* Otherwise, work through the remaining arguments as files or directories.
1980  Pass in the fact that there is only one argument at top level - this suppresses  Pass in the fact that there is only one argument at top level - this suppresses
# Line 1988  for (; i < argc; i++) Line 1991  for (; i < argc; i++)
1991      else if (frc == 0 && rc == 1) rc = 0;      else if (frc == 0 && rc == 1) rc = 0;
1992    }    }
1993    
1994    EXIT:
1995    if (pattern_list != NULL)
1996      {
1997      for (i = 0; i < pattern_count; i++) free(pattern_list[i]);
1998      free(pattern_list);
1999      }
2000    if (hints_list != NULL)
2001      {
2002      for (i = 0; i < pattern_count; i++) free(hints_list[i]);
2003      free(hints_list);
2004      }
2005  return rc;  return rc;
2006    
2007    EXIT2:
2008    rc = 2;
2009    goto EXIT;
2010  }  }
2011    
2012  /* End of pcregrep */  /* End of pcregrep */

Legend:
Removed from v.120  
changed lines
  Added in v.121

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12