/[pcre]/code/tags/pcre-6.6/pcregrep.c
ViewVC logotype

Diff of /code/tags/pcre-6.6/pcregrep.c

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

revision 63 by nigel, Sat Feb 24 21:40:03 2007 UTC revision 75 by nigel, Sat Feb 24 21:40:37 2007 UTC
# Line 4  Line 4 
4    
5  /* This is a grep program that uses the PCRE regular expression library to do  /* This is a grep program that uses the PCRE regular expression library to do
6  its pattern matching. On a Unix or Win32 system it can recurse into  its pattern matching. On a Unix or Win32 system it can recurse into
7  directories. */  directories.
8    
9               Copyright (c) 1997-2004 University of Cambridge
10    
11    -----------------------------------------------------------------------------
12    Redistribution and use in source and binary forms, with or without
13    modification, are permitted provided that the following conditions are met:
14    
15        * Redistributions of source code must retain the above copyright notice,
16          this list of conditions and the following disclaimer.
17    
18        * Redistributions in binary form must reproduce the above copyright
19          notice, this list of conditions and the following disclaimer in the
20          documentation and/or other materials provided with the distribution.
21    
22        * Neither the name of the University of Cambridge nor the names of its
23          contributors may be used to endorse or promote products derived from
24          this software without specific prior written permission.
25    
26    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36    POSSIBILITY OF SUCH DAMAGE.
37    -----------------------------------------------------------------------------
38    */
39    
40  #include <ctype.h>  #include <ctype.h>
41  #include <stdio.h>  #include <stdio.h>
# Line 45  static BOOL whole_lines = FALSE; Line 76  static BOOL whole_lines = FALSE;
76    
77  typedef struct option_item {  typedef struct option_item {
78    int one_char;    int one_char;
79    char *long_name;    const char *long_name;
80    char *help_text;    const char *help_text;
81  } option_item;  } option_item;
82    
83  static option_item optionlist[] = {  static option_item optionlist[] = {
# Line 85  recursion support". */ Line 116  recursion support". */
116    
117  typedef DIR directory_type;  typedef DIR directory_type;
118    
119  int  static int
120  isdirectory(char *filename)  isdirectory(char *filename)
121  {  {
122  struct stat statbuf;  struct stat statbuf;
# Line 94  if (stat(filename, &statbuf) < 0) Line 125  if (stat(filename, &statbuf) < 0)
125  return ((statbuf.st_mode & S_IFMT) == S_IFDIR)? '/' : 0;  return ((statbuf.st_mode & S_IFMT) == S_IFDIR)? '/' : 0;
126  }  }
127    
128  directory_type *  static directory_type *
129  opendirectory(char *filename)  opendirectory(char *filename)
130  {  {
131  return opendir(filename);  return opendir(filename);
132  }  }
133    
134  char *  static char *
135  readdirectory(directory_type *dir)  readdirectory(directory_type *dir)
136  {  {
137  for (;;)  for (;;)
# Line 113  for (;;) Line 144  for (;;)
144  return NULL;   /* Keep compiler happy; never executed */  return NULL;   /* Keep compiler happy; never executed */
145  }  }
146    
147  void  static void
148  closedirectory(directory_type *dir)  closedirectory(directory_type *dir)
149  {  {
150  closedir(dir);  closedir(dir);
# Line 320  return rc; Line 351  return rc;
351  *************************************************/  *************************************************/
352    
353  static int  static int
354  grep_or_recurse(char *filename, BOOL recurse, BOOL show_filenames,  grep_or_recurse(char *filename, BOOL dir_recurse, BOOL show_filenames,
355    BOOL only_one_at_top)    BOOL only_one_at_top)
356  {  {
357  int rc = 1;  int rc = 1;
# Line 330  FILE *in; Line 361  FILE *in;
361  /* If the file is a directory and we are recursing, scan each file within it.  /* If the file is a directory and we are recursing, scan each file within it.
362  The scanning code is localized so it can be made system-specific. */  The scanning code is localized so it can be made system-specific. */
363    
364  if ((sep = isdirectory(filename)) != 0 && recurse)  if ((sep = isdirectory(filename)) != 0 && dir_recurse)
365    {    {
366    char buffer[1024];    char buffer[1024];
367    char *nextfile;    char *nextfile;
# Line 347  if ((sep = isdirectory(filename)) != 0 & Line 378  if ((sep = isdirectory(filename)) != 0 &
378      {      {
379      int frc;      int frc;
380      sprintf(buffer, "%.512s%c%.128s", filename, sep, nextfile);      sprintf(buffer, "%.512s%c%.128s", filename, sep, nextfile);
381      frc = grep_or_recurse(buffer, recurse, TRUE, FALSE);      frc = grep_or_recurse(buffer, dir_recurse, TRUE, FALSE);
382      if (frc == 0 && rc == 1) rc = 0;      if (frc == 0 && rc == 1) rc = 0;
383      }      }
384    
# Line 545  for (i = 1; i < argc; i++) Line 576  for (i = 1; i < argc; i++)
576      }      }
577    }    }
578    
579  pattern_list = malloc(MAX_PATTERN_COUNT * sizeof(pcre *));  pattern_list = (pcre **)malloc(MAX_PATTERN_COUNT * sizeof(pcre *));
580  hints_list = malloc(MAX_PATTERN_COUNT * sizeof(pcre_extra *));  hints_list = (pcre_extra **)malloc(MAX_PATTERN_COUNT * sizeof(pcre_extra *));
581    
582  if (pattern_list == NULL || hints_list == NULL)  if (pattern_list == NULL || hints_list == NULL)
583    {    {

Legend:
Removed from v.63  
changed lines
  Added in v.75

  ViewVC Help
Powered by ViewVC 1.1.5