/[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 1353 by ph10, Mon Aug 5 16:24:02 2013 UTC revision 1354 by ph10, Mon Aug 12 14:31:07 2013 UTC
# Line 3  Line 3 
3  *************************************************/  *************************************************/
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 Unix-like, Windows, and native z/OS systems it can
7  directories.  recurse into directories, and in z/OS it can handle PDS files.
8    
9             Copyright (c) 1997-2012 University of Cambridge  Note that for native z/OS, in addition to defining the NATIVE_ZOS macro, an
10    additional header is required. That header is not included in the main PCRE
11    distribution because other apparatus is needed to compile pcregrep for z/OS.
12    The header can be found in the special z/OS distribution, which is available
13    from www.zaconsultants.net or from www.cbttape.org.
14    
15               Copyright (c) 1997-2013 University of Cambridge
16    
17  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
18  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 530  while (fn != NULL) Line 536  while (fn != NULL)
536  *            OS-specific functions               *  *            OS-specific functions               *
537  *************************************************/  *************************************************/
538    
539  /* These functions are defined so that they can be made system specific,  /* These functions are defined so that they can be made system specific.
540  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
541    z/OS, and "no support". */
542    
543    
544  /************* Directory scanning in Unix ***********/  /************* Directory scanning Unix-style and z/OS ***********/
545    
546  #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
547  #include <sys/types.h>  #include <sys/types.h>
548  #include <sys/stat.h>  #include <sys/stat.h>
549  #include <dirent.h>  #include <dirent.h>
550    
551    #if defined NATIVE_ZOS
552    /************* Directory and PDS/E scanning for z/OS ***********/
553    /************* z/OS looks mostly like Unix with USS ************/
554    /* However, z/OS needs the #include statements in this header */
555    #include "pcrzosfs.h"
556    /* That header is not included in the main PCRE distribution because
557       other apparatus is needed to compile pcregrep for z/OS. The header
558       can be found in the special z/OS distribution, which is available
559       from www.zaconsultants.net or from www.cbttape.org. */
560    #endif
561    
562  typedef DIR directory_type;  typedef DIR directory_type;
563  #define FILESEP '/'  #define FILESEP '/'
564    
# Line 579  closedir(dir); Line 597  closedir(dir);
597  }  }
598    
599    
600  /************* Test for regular file in Unix **********/  /************* Test for regular file, Unix-style **********/
601    
602  static int  static int
603  isregfile(char *filename)  isregfile(char *filename)
# Line 591  return (statbuf.st_mode & S_IFMT) == S_I Line 609  return (statbuf.st_mode & S_IFMT) == S_I
609  }  }
610    
611    
612  /************* Test for a terminal in Unix **********/  #if defined NATIVE_ZOS
613    /************* Test for a terminal in z/OS **********/
614    /* isatty() does not work in a TSO environment, so always give FALSE.*/
615    
616    static BOOL
617    is_stdout_tty(void)
618    {
619    return FALSE;
620    }
621    
622    static BOOL
623    is_file_tty(FILE *f)
624    {
625    return FALSE;
626    }
627    
628    
629    /************* Test for a terminal, Unix-style **********/
630    
631    #else
632  static BOOL  static BOOL
633  is_stdout_tty(void)  is_stdout_tty(void)
634  {  {
# Line 604  is_file_tty(FILE *f) Line 640  is_file_tty(FILE *f)
640  {  {
641  return isatty(fileno(f));  return isatty(fileno(f));
642  }  }
643    #endif
644    
645    /* End of Unix-style or native z/OS environment functions. */
646    
647    
648  /************* Directory scanning in Win32 ***********/  /************* Directory scanning in Windows ***********/
649    
650  /* 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
651  Lionel Fourquaux. David Burgess added a patch to define INVALID_FILE_ATTRIBUTES  Lionel Fourquaux. David Burgess added a patch to define INVALID_FILE_ATTRIBUTES
# Line 709  free(dir); Line 748  free(dir);
748  }  }
749    
750    
751  /************* Test for regular file in Win32 **********/  /************* Test for regular file in Windows **********/
752    
753  /* 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
754  regular if they are not directories. */  regular if they are not directories. */
# Line 720  return !isdirectory(filename); Line 759  return !isdirectory(filename);
759  }  }
760    
761    
762  /************* Test for a terminal in Win32 **********/  /************* Test for a terminal in Windows **********/
763    
764  /* I don't know how to do this; assume never */  /* I don't know how to do this; assume never */
765    
# Line 736  is_file_tty(FILE *f) Line 775  is_file_tty(FILE *f)
775  return FALSE;  return FALSE;
776  }  }
777    
778    /* End of Windows functions */
779    
780    
781  /************* Directory scanning when we can't do it ***********/  /************* Directory scanning when we can't do it ***********/
782    
# Line 752  char *readdirectory(directory_type *dir) Line 793  char *readdirectory(directory_type *dir)
793  void closedirectory(directory_type *dir) {}  void closedirectory(directory_type *dir) {}
794    
795    
796  /************* Test for regular when we can't do it **********/  /************* Test for regular file when we can't do it **********/
797    
798  /* Assume all files are regular. */  /* Assume all files are regular. */
799    
# Line 773  is_file_tty(FILE *f) Line 814  is_file_tty(FILE *f)
814  return FALSE;  return FALSE;
815  }  }
816    
817  #endif  #endif  /* End of system-specific functions */
818    
819    
820    
# Line 2068  BZFILE *inbz2 = NULL; Line 2109  BZFILE *inbz2 = NULL;
2109  int pathlen;  int pathlen;
2110  #endif  #endif
2111    
2112    #if defined NATIVE_ZOS
2113    int zos_type;
2114    FILE *zos_test_file;
2115    #endif
2116    
2117  /* If the file name is "-" we scan stdin */  /* If the file name is "-" we scan stdin */
2118    
2119  if (strcmp(pathname, "-") == 0)  if (strcmp(pathname, "-") == 0)
# Line 2088  lastcomp = (lastcomp == NULL)? pathname Line 2134  lastcomp = (lastcomp == NULL)? pathname
2134  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
2135  code is localized so it can be made system-specific. */  code is localized so it can be made system-specific. */
2136    
2137    
2138    /* For z/OS, determine the file type. */
2139    
2140    #if defined NATIVE_ZOS
2141    zos_test_file =  fopen(pathname,"rb");
2142    
2143    if (zos_test_file == NULL)
2144       {
2145       if (!silent) fprintf(stderr, "pcregrep: failed to test next file %s\n",
2146         pathname, strerror(errno));
2147       return -1;
2148       }
2149    zos_type = identifyzosfiletype (zos_test_file);
2150    fclose (zos_test_file);
2151    
2152    /* Handle a PDS in separate code */
2153    
2154    if (zos_type == __ZOS_PDS || zos_type == __ZOS_PDSE)
2155       {
2156       rc = travelonpdsdir (pathname, only_one_at_top);
2157       }
2158    
2159    /* Deal with regular files in the normal way below. These types are:
2160       zos_type == __ZOS_PDS_MEMBER
2161       zos_type == __ZOS_PS
2162       zos_type == __ZOS_VSAM_KSDS
2163       zos_type == __ZOS_VSAM_ESDS
2164       zos_type == __ZOS_VSAM_RRDS
2165    */
2166    
2167    /* Handle a z/OS directory using common code. */
2168    
2169    else if (zos_type == __ZOS_HFS)
2170     {
2171    #endif  /* NATIVE_ZOS */
2172    
2173    
2174    /* Handle directories: common code for all OS */
2175    
2176  if (isdirectory(pathname))  if (isdirectory(pathname))
2177    {    {
2178    if (dee_action == dee_SKIP ||    if (dee_action == dee_SKIP ||
# Line 2122  if (isdirectory(pathname)) Line 2207  if (isdirectory(pathname))
2207      }      }
2208    }    }
2209    
2210  /* If the file is not a directory and not a regular file, skip it if that's  #if defined NATIVE_ZOS
2211  been requested. Otherwise, check for explicit include/exclude. */   }
2212    #endif
2213    
2214  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,
2215            !test_incexc(lastcomp, include_patterns, exclude_patterns))  skip it if that's been requested. Otherwise, check for an explicit inclusion or
2216          return -1;  exclusion. */
2217    
2218    else if (
2219    #if defined NATIVE_ZOS
2220            (zos_type == __ZOS_NOFILE && DEE_action == DEE_SKIP) ||
2221    #else  /* all other OS */
2222            (!isregfile(pathname) && DEE_action == DEE_SKIP) ||
2223    #endif
2224            !test_incexc(lastcomp, include_patterns, exclude_patterns))
2225      return -1;  /* File skipped */
2226    
2227  /* 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
2228  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

Legend:
Removed from v.1353  
changed lines
  Added in v.1354

  ViewVC Help
Powered by ViewVC 1.1.5