diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-06-22 22:24:14 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-06-22 22:24:14 +0000 |
commit | bd8b23be6dad41c95dcda6d063d6268c316438fa (patch) | |
tree | a573c4e58cd1072d198a3397a276d52a30b249d4 /usr.bin/grep | |
parent | d20a3745bfce380a9c5ecb3bc30b0e75679db3a8 (diff) |
-DNOZ flag to be used by install media for removing z*grep support, if
needed. (and knf)
Diffstat (limited to 'usr.bin/grep')
-rw-r--r-- | usr.bin/grep/binary.c | 6 | ||||
-rw-r--r-- | usr.bin/grep/file.c | 44 | ||||
-rw-r--r-- | usr.bin/grep/grep.c | 36 | ||||
-rw-r--r-- | usr.bin/grep/mmfile.c | 10 | ||||
-rw-r--r-- | usr.bin/grep/queue.c | 2 | ||||
-rw-r--r-- | usr.bin/grep/util.c | 12 |
6 files changed, 71 insertions, 39 deletions
diff --git a/usr.bin/grep/binary.c b/usr.bin/grep/binary.c index 462a4c0013d..d18731e2ceb 100644 --- a/usr.bin/grep/binary.c +++ b/usr.bin/grep/binary.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: binary.c,v 1.2 2003/06/22 22:21:50 deraadt Exp $ + * $Id: binary.c,v 1.3 2003/06/22 22:24:13 deraadt Exp $ */ #include <ctype.h> @@ -54,6 +54,7 @@ bin_file(FILE *f) return 0; } +#ifndef NOZ int gzbin_file(gzFile *f) { @@ -73,12 +74,13 @@ gzbin_file(gzFile *f) gzrewind(f); return 0; } +#endif int mmbin_file(mmf_t *f) { int i; - + /* XXX knows too much about mmf internals */ for (i = 0; i < BUFFER_SIZE && i < f->len; i++) if (!isprint(f->base[i])) diff --git a/usr.bin/grep/file.c b/usr.bin/grep/file.c index a58a2c1bac2..f50fd02060a 100644 --- a/usr.bin/grep/file.c +++ b/usr.bin/grep/file.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: file.c,v 1.1 2003/06/22 22:20:07 deraadt Exp $ + * $Id: file.c,v 1.2 2003/06/22 22:24:13 deraadt Exp $ */ #include <sys/param.h> @@ -37,7 +37,7 @@ static char fname[MAXPATHLEN]; static char *lnbuf; -static int lnbuflen; +static size_t lnbuflen; #define FILE_STDIO 0 #define FILE_MMAP 1 @@ -50,6 +50,7 @@ struct file { gzFile *gzf; }; +#ifndef NOZ static char * gzfgetln(gzFile *f, size_t *len) { @@ -64,7 +65,7 @@ gzfgetln(gzFile *f, size_t *len) if (gzeof(f)) break; - + gzerrstr = gzerror(f, &gzerr); if (gzerr == Z_ERRNO) err(1, "%s", fname); @@ -85,6 +86,7 @@ gzfgetln(gzFile *f, size_t *len) *len = n; return lnbuf; } +#endif file_t * grep_fdopen(int fd, char *mode) @@ -92,22 +94,25 @@ grep_fdopen(int fd, char *mode) file_t *f; if (fd == 0) - sprintf(fname, "(standard input)"); + snprintf(fname, sizeof fname, "(standard input)"); else - sprintf(fname, "(fd %d)", fd); - + snprintf(fname, sizeof fname, "(fd %d)", fd); + f = grep_malloc(sizeof *f); - + +#ifndef NOZ if (Zflag) { f->type = FILE_GZIP; if ((f->gzf = gzdopen(fd, mode)) != NULL) return f; - } else { + } else +#endif + { f->type = FILE_STDIO; if ((f->f = fdopen(fd, mode)) != NULL) return f; } - + free(f); return NULL; } @@ -117,15 +122,18 @@ grep_open(char *path, char *mode) { file_t *f; - snprintf(fname, MAXPATHLEN, "%s", path); - + snprintf(fname, sizeof fname, "%s", path); + f = grep_malloc(sizeof *f); - + +#ifndef NOZ if (Zflag) { f->type = FILE_GZIP; if ((f->gzf = gzopen(fname, mode)) != NULL) return f; - } else { + } else +#endif + { /* try mmap first; if it fails, try stdio */ if ((f->mmf = mmopen(fname, mode)) != NULL) { f->type = FILE_MMAP; @@ -135,7 +143,7 @@ grep_open(char *path, char *mode) if ((f->f = fopen(path, mode)) != NULL) return f; } - + free(f); return NULL; } @@ -148,8 +156,10 @@ grep_bin_file(file_t *f) return bin_file(f->f); case FILE_MMAP: return mmbin_file(f->mmf); +#ifndef NOZ case FILE_GZIP: return gzbin_file(f->gzf); +#endif default: /* can't happen */ errx(1, "invalid file type"); @@ -164,8 +174,10 @@ grep_tell(file_t *f) return ftell(f->f); case FILE_MMAP: return mmtell(f->mmf); +#ifndef NOZ case FILE_GZIP: return gztell(f->gzf); +#endif default: /* can't happen */ errx(1, "invalid file type"); @@ -180,8 +192,10 @@ grep_fgetln(file_t *f, size_t *l) return fgetln(f->f, l); case FILE_MMAP: return mmfgetln(f->mmf, l); +#ifndef NOZ case FILE_GZIP: return gzfgetln(f->gzf, l); +#endif default: /* can't happen */ errx(1, "invalid file type"); @@ -198,9 +212,11 @@ grep_close(file_t *f) case FILE_MMAP: mmclose(f->mmf); break; +#ifndef NOZ case FILE_GZIP: gzclose(f->gzf); break; +#endif default: /* can't happen */ errx(1, "invalid file type"); diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index f868066db09..c17420ddee2 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: grep.c,v 1.4 2003/06/22 22:23:06 deraadt Exp $ + * $Id: grep.c,v 1.5 2003/06/22 22:24:13 deraadt Exp $ */ #include <sys/types.h> @@ -64,7 +64,9 @@ int Pflag; /* -P: if -R, no symlinks are followed */ int Rflag; /* -R: recursively search directory trees */ int Sflag; /* -S: if -R, follow all symlinks */ int Vflag; /* -V: display version information */ +#ifndef NOZ int Zflag; /* -Z: decompress input before processing */ +#endif int aflag; /* -a: only search ascii files */ int bflag; /* -b: show block numbers for each match */ int cflag; /* -c: only show a count of matching lines */ @@ -89,16 +91,23 @@ char *progname; static void usage(void) { - fprintf(stderr, "usage: %s %s %s\n", - progname, - "[-[AB] num] [-CEFGHLPRSVZabchilnoqsvwx]", - "[-e patttern] [-f file]"); + fprintf(stderr, +#ifdef NOZ + "usage: %s [-[AB] num] [-CEFGHLPRSVabchilnoqsvwx]" +#else + "usage: %s [-[AB] num] [-CEFGHLPRSVZabchilnoqsvwx]" +#endif + " [-e patttern] [-f file]\n", progname); exit(2); } +#ifdef NOZ +static char *optstr = "0123456789A:B:CEFGHLPSRUVabce:f:hilnoqrsuvwxy"; +#else static char *optstr = "0123456789A:B:CEFGHLPSRUVZabce:f:hilnoqrsuvwxy"; +#endif -struct option long_options[] = +struct option long_options[] = { {"basic-regexp", no_argument, NULL, 'G'}, {"extended-regexp", no_argument, NULL, 'E'}, @@ -126,8 +135,9 @@ struct option long_options[] = {"line-regexp", no_argument, NULL, 'x'}, {"binary", no_argument, NULL, 'U'}, {"unix-byte-offsets", no_argument, NULL, 'u'}, +#ifndef NOZ {"decompress", no_argument, NULL, 'Z'}, - +#endif {NULL, no_argument, NULL, 0} }; @@ -190,7 +200,7 @@ main(int argc, char *argv[]) else progname = *argv; - while ((c = getopt_long(argc, argv, optstr, + while ((c = getopt_long(argc, argv, optstr, long_options, (int *)NULL)) != -1) { switch (c) { case '0': case '1': case '2': case '3': case '4': @@ -208,7 +218,7 @@ main(int argc, char *argv[]) Bflag = strtol(optarg, (char **)NULL, 10); break; case 'C': - if (optarg == NULL) + if (optarg == NULL) Aflag = Bflag = 2; else Aflag = Bflag = strtol(optarg, (char **)NULL, 10); @@ -249,9 +259,11 @@ main(int argc, char *argv[]) fprintf(stderr, argv[0]); usage(); break; +#ifndef NOZ case 'Z': Zflag++; break; +#endif case 'a': aflag = 1; break; @@ -317,7 +329,7 @@ main(int argc, char *argv[]) --argc; ++argv; } - + switch (*progname) { case 'e': Eflag++; @@ -328,6 +340,7 @@ main(int argc, char *argv[]) case 'g': Gflag++; break; +#ifndef NOZ case 'z': Zflag++; switch(progname[1]) { @@ -342,6 +355,7 @@ main(int argc, char *argv[]) break; } break; +#endif } cflags |= Eflag ? REG_EXTENDED : REG_BASIC; @@ -358,7 +372,7 @@ main(int argc, char *argv[]) if (argc == 0) exit(!procfile(NULL)); - + if (Rflag) c = grep_tree(argv); else diff --git a/usr.bin/grep/mmfile.c b/usr.bin/grep/mmfile.c index 045ad7b4d49..cea54b8797e 100644 --- a/usr.bin/grep/mmfile.c +++ b/usr.bin/grep/mmfile.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: mmfile.c,v 1.1 2003/06/22 22:20:07 deraadt Exp $ + * $Id: mmfile.c,v 1.2 2003/06/22 22:24:13 deraadt Exp $ */ #include <sys/param.h> @@ -47,18 +47,18 @@ mmopen(char *fn, char *mode) /* XXX ignore mode for now */ mode = mode; - - mmf = grep_malloc(sizeof *mmf); + + mmf = grep_malloc(sizeof *mmf); if ((mmf->fd = open(fn, O_RDONLY)) == -1) goto ouch1; if (fstat(mmf->fd, &st) == -1) goto ouch2; - if (st.st_size > SIZE_T_MAX) /* too big to mmap */ + if (st.st_size > SIZE_T_MAX) /* too big to mmap */ goto ouch2; if ((st.st_mode & S_IFREG) == 0) /* only mmap regular files */ goto ouch2; mmf->len = (size_t)st.st_size; - mmf->base = mmap(NULL, mmf->len, PROT_READ, MAP_PRIVATE, mmf->fd, 0); + mmf->base = mmap(NULL, mmf->len, PROT_READ, MAP_PRIVATE, mmf->fd, (off_t)0); if (mmf->base == NULL) goto ouch2; mmf->ptr = mmf->base; diff --git a/usr.bin/grep/queue.c b/usr.bin/grep/queue.c index 1b93c615a36..0dd35039a73 100644 --- a/usr.bin/grep/queue.c +++ b/usr.bin/grep/queue.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: queue.c,v 1.1 2003/06/22 22:20:07 deraadt Exp $ + * $Id: queue.c,v 1.2 2003/06/22 22:24:13 deraadt Exp $ */ /* diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index 2b8bc1d5a0a..9d04b29aa07 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: util.c,v 1.1 2003/06/22 22:20:07 deraadt Exp $ + * $Id: util.c,v 1.2 2003/06/22 22:24:13 deraadt Exp $ */ #include <sys/types.h> @@ -49,7 +49,7 @@ static int linesqueued; static int procline(str_t *l); -int +int grep_tree(char **argv) { FTS *fts; @@ -126,7 +126,7 @@ procfile(char *fn) ln.line_no++; z = tail; - + if ((t = procline(&ln)) == 0 && Bflag > 0 && z == 0) { enqueue(&ln); linesqueued++; @@ -166,7 +166,7 @@ procline(str_t *l) c = !vflag; goto print; } - + t = vflag ? REG_NOMATCH : 0; pmatch.rm_so = 0; pmatch.rm_eo = l->len; @@ -190,7 +190,7 @@ procline(str_t *l) break; } } - + print: if ((tail > 0 || c) && !cflag && !qflag) { if (c) { @@ -232,7 +232,7 @@ void printline(str_t *line, int sep) { int n; - + n = 0; if (!hflag) { fputs(line->file, stdout); |