Diff for /embedaddon/pcre/pcregrep.c between versions 1.1.1.4 and 1.1.1.5

version 1.1.1.4, 2013/07/22 08:25:55 version 1.1.1.5, 2014/06/15 19:46:03
Line 3 Line 3
 *************************************************/  *************************************************/
   
 /* 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
its pattern matching. On a Unix or Win32 system it can recurse intoits pattern matching. On Unix-like, Windows, and native z/OS systems it can
directories.recurse into directories, and in z/OS it can handle PDS files.
   
           Copyright (c) 1997-2012 University of CambridgeNote that for native z/OS, in addition to defining the NATIVE_ZOS macro, an
 additional header is required. That header is not included in the main PCRE
 distribution because other apparatus is needed to compile pcregrep for z/OS.
 The header can be found in the special z/OS distribution, which is available
 from www.zaconsultants.net or from www.cbttape.org.
   
              Copyright (c) 1997-2013 University of Cambridge
   
 -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:  modification, are permitted provided that the following conditions are met:
Line 530  while (fn != NULL) Line 536  while (fn != NULL)
 *            OS-specific functions               *  *            OS-specific functions               *
 *************************************************/  *************************************************/
   
/* These functions are defined so that they can be made system specific,/* These functions are defined so that they can be made system specific.
although at present the only ones are for Unix, Win32, and for "no support". */At present there are versions for Unix-style environments, Windows, native
 z/OS, and "no support". */
   
   
/************* Directory scanning in Unix ***********//************* Directory scanning Unix-style and z/OS ***********/
   
#if defined HAVE_SYS_STAT_H && defined HAVE_DIRENT_H && defined HAVE_SYS_TYPES_H#if (defined HAVE_SYS_STAT_H && defined HAVE_DIRENT_H && defined HAVE_SYS_TYPES_H) || defined NATIVE_ZOS
 #include <sys/types.h>  #include <sys/types.h>
 #include <sys/stat.h>  #include <sys/stat.h>
 #include <dirent.h>  #include <dirent.h>
   
   #if defined NATIVE_ZOS
   /************* Directory and PDS/E scanning for z/OS ***********/
   /************* z/OS looks mostly like Unix with USS ************/
   /* However, z/OS needs the #include statements in this header */
   #include "pcrzosfs.h"
   /* That header is not included in the main PCRE distribution because
      other apparatus is needed to compile pcregrep for z/OS. The header
      can be found in the special z/OS distribution, which is available
      from www.zaconsultants.net or from www.cbttape.org. */
   #endif
   
 typedef DIR directory_type;  typedef DIR directory_type;
 #define FILESEP '/'  #define FILESEP '/'
   
Line 579  closedir(dir); Line 597  closedir(dir);
 }  }
   
   
/************* Test for regular file in Unix **********//************* Test for regular file, Unix-style **********/
   
 static int  static int
 isregfile(char *filename)  isregfile(char *filename)
Line 591  return (statbuf.st_mode & S_IFMT) == S_IFREG; Line 609  return (statbuf.st_mode & S_IFMT) == S_IFREG;
 }  }
   
   
/************* Test for a terminal in Unix **********/#if defined NATIVE_ZOS
 /************* Test for a terminal in z/OS **********/
 /* isatty() does not work in a TSO environment, so always give FALSE.*/
   
 static BOOL  static BOOL
 is_stdout_tty(void)  is_stdout_tty(void)
 {  {
   return FALSE;
   }
   
   static BOOL
   is_file_tty(FILE *f)
   {
   return FALSE;
   }
   
   
   /************* Test for a terminal, Unix-style **********/
   
   #else
   static BOOL
   is_stdout_tty(void)
   {
 return isatty(fileno(stdout));  return isatty(fileno(stdout));
 }  }
   
Line 604  is_file_tty(FILE *f) Line 640  is_file_tty(FILE *f)
 {  {
 return isatty(fileno(f));  return isatty(fileno(f));
 }  }
   #endif
   
   /* End of Unix-style or native z/OS environment functions. */
   
 /************* Directory scanning in Win32 ***********/  
   
   /************* Directory scanning in Windows ***********/
   
 /* I (Philip Hazel) have no means of testing this code. It was contributed by  /* I (Philip Hazel) have no means of testing this code. It was contributed by
 Lionel Fourquaux. David Burgess added a patch to define INVALID_FILE_ATTRIBUTES  Lionel Fourquaux. David Burgess added a patch to define INVALID_FILE_ATTRIBUTES
 when it did not exist. David Byron added a patch that moved the #include of  when it did not exist. David Byron added a patch that moved the #include of
Line 709  free(dir); Line 748  free(dir);
 }  }
   
   
/************* Test for regular file in Win32 **********//************* Test for regular file in Windows **********/
   
 /* I don't know how to do this, or if it can be done; assume all paths are  /* I don't know how to do this, or if it can be done; assume all paths are
 regular if they are not directories. */  regular if they are not directories. */
Line 720  return !isdirectory(filename); Line 759  return !isdirectory(filename);
 }  }
   
   
/************* Test for a terminal in Win32 **********//************* Test for a terminal in Windows **********/
   
 /* I don't know how to do this; assume never */  /* I don't know how to do this; assume never */
   
Line 736  is_file_tty(FILE *f) Line 775  is_file_tty(FILE *f)
 return FALSE;  return FALSE;
 }  }
   
   /* End of Windows functions */
   
   
 /************* Directory scanning when we can't do it ***********/  /************* Directory scanning when we can't do it ***********/
   
 /* The type is void, and apart from isdirectory(), the functions do nothing. */  /* The type is void, and apart from isdirectory(), the functions do nothing. */
Line 752  char *readdirectory(directory_type *dir) { return (cha Line 793  char *readdirectory(directory_type *dir) { return (cha
 void closedirectory(directory_type *dir) {}  void closedirectory(directory_type *dir) {}
   
   
/************* Test for regular when we can't do it **********//************* Test for regular file when we can't do it **********/
   
 /* Assume all files are regular. */  /* Assume all files are regular. */
   
Line 773  is_file_tty(FILE *f) Line 814  is_file_tty(FILE *f)
 return FALSE;  return FALSE;
 }  }
   
#endif#endif  /* End of system-specific functions */
   
   
   
Line 1835  while (ptr < endptr) Line 1876  while (ptr < endptr)
         {          {
         char *endmatch = ptr + offsets[1];          char *endmatch = ptr + offsets[1];
         t = ptr;          t = ptr;
        while (t < endmatch)        while (t <= endmatch)
           {            {
           t = end_of_line(t, endptr, &endlinelength);            t = end_of_line(t, endptr, &endlinelength);
           if (t < endmatch) linenumber++; else break;            if (t < endmatch) linenumber++; else break;
Line 2068  BZFILE *inbz2 = NULL; Line 2109  BZFILE *inbz2 = NULL;
 int pathlen;  int pathlen;
 #endif  #endif
   
   #if defined NATIVE_ZOS
   int zos_type;
   FILE *zos_test_file;
   #endif
   
 /* If the file name is "-" we scan stdin */  /* If the file name is "-" we scan stdin */
   
 if (strcmp(pathname, "-") == 0)  if (strcmp(pathname, "-") == 0)
Line 2088  lastcomp = (lastcomp == NULL)? pathname : lastcomp + 1 Line 2134  lastcomp = (lastcomp == NULL)? pathname : lastcomp + 1
 Otherwise, scan the directory and recurse for each path within it. The scanning  Otherwise, scan the directory and recurse for each path within it. The scanning
 code is localized so it can be made system-specific. */  code is localized so it can be made system-specific. */
   
   
   /* For z/OS, determine the file type. */
   
   #if defined NATIVE_ZOS
   zos_test_file =  fopen(pathname,"rb");
   
   if (zos_test_file == NULL)
      {
      if (!silent) fprintf(stderr, "pcregrep: failed to test next file %s\n",
        pathname, strerror(errno));
      return -1;
      }
   zos_type = identifyzosfiletype (zos_test_file);
   fclose (zos_test_file);
   
   /* Handle a PDS in separate code */
   
   if (zos_type == __ZOS_PDS || zos_type == __ZOS_PDSE)
      {
      return travelonpdsdir (pathname, only_one_at_top);
      }
   
   /* Deal with regular files in the normal way below. These types are:
      zos_type == __ZOS_PDS_MEMBER
      zos_type == __ZOS_PS
      zos_type == __ZOS_VSAM_KSDS
      zos_type == __ZOS_VSAM_ESDS
      zos_type == __ZOS_VSAM_RRDS
   */
   
   /* Handle a z/OS directory using common code. */
   
   else if (zos_type == __ZOS_HFS)
    {
   #endif  /* NATIVE_ZOS */
   
   
   /* Handle directories: common code for all OS */
   
 if (isdirectory(pathname))  if (isdirectory(pathname))
   {    {
   if (dee_action == dee_SKIP ||    if (dee_action == dee_SKIP ||
Line 2122  if (isdirectory(pathname)) Line 2207  if (isdirectory(pathname))
     }      }
   }    }
   
/* If the file is not a directory and not a regular file, skip it if that's#if defined NATIVE_ZOS
been requested. Otherwise, check for explicit include/exclude. */ }
 #endif
   
else if ((!isregfile(pathname) && DEE_action == DEE_SKIP) ||/* If the file is not a directory, check for a regular file, and if it is not,
          !test_incexc(lastcomp, include_patterns, exclude_patterns))skip it if that's been requested. Otherwise, check for an explicit inclusion or
        return -1;exclusion. */
 
 else if (
 #if defined NATIVE_ZOS
         (zos_type == __ZOS_NOFILE && DEE_action == DEE_SKIP) ||
 #else  /* all other OS */
         (!isregfile(pathname) && DEE_action == DEE_SKIP) ||
 #endif
         !test_incexc(lastcomp, include_patterns, exclude_patterns))
   return -1;  /* File skipped */
   
 /* Control reaches here if we have a regular file, or if we have a directory  /* Control reaches here if we have a regular file, or if we have a directory
 and recursion or skipping was not requested, or if we have anything else and  and recursion or skipping was not requested, or if we have anything else and

Removed from v.1.1.1.4  
changed lines
  Added in v.1.1.1.5


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>