Date: Wed, 7 May 2008 21:27:24 GMT From: Gabor Kovesdan <gabor@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 141303 for review Message-ID: <200805072127.m47LROoS073335@repoman.freebsd.org>
index | next in thread | raw e-mail
http://perforce.freebsd.org/chv.cgi?CH=141303 Change 141303 by gabor@gabor_server on 2008/05/07 21:27:21 - Implement -D / --devices Affected files ... .. //depot/projects/soc2008/gabor_textproc/grep/grep.c#8 edit .. //depot/projects/soc2008/gabor_textproc/grep/grep.h#8 edit .. //depot/projects/soc2008/gabor_textproc/grep/util.c#10 edit Differences ... ==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#8 (text+ko) ==== @@ -67,6 +67,7 @@ /* Command-line flags */ int Aflag; /* -A x: print x lines trailing each match */ int Bflag; /* -B x: print x lines leading each match */ +int Dflag; /* -D: do not process device files if optarg is passed */ int Eflag; /* -E: interpret pattern as extended regexp */ int Fflag; /* -F: interpret pattern as list of fixed strings */ int Gflag; /* -G: interpret pattern as basic regexp */ @@ -119,13 +120,13 @@ usage(void) { fprintf(stderr, - "usage: %s [-abcEFGHhIiLlnoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n" + "usage: %s [-abcDEFGHhIiLlnoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n" "\t[-e pattern] [-f file] [--binary-files=value] [--context[=num]]\n" "\t[--line-buffered] [--null] [pattern] [file ...]\n", __progname); exit(2); } -static char *optstr = "0123456789A:B:CEFGHILPSRUVZabce:f:hilnoqrsuvwxy"; +static char *optstr = "0123456789A:B:CD:EFGHILPSRUVZabce:f:hilnoqrsuvwxy"; struct option long_options[] = { @@ -144,8 +145,8 @@ {"byte-offset", no_argument, NULL, 'b'}, {"context", optional_argument, NULL, 'C'}, {"count", no_argument, NULL, 'c'}, -/* XXX: UNDOCUMENTED {"devices", required_argument, NULL, 'D'}, +/* XXX: UNIMPLEMENTED {"directories", required_argument, NULL, 'd'}, */ {"extended-regexp", no_argument, NULL, 'E'}, {"regexp", required_argument, NULL, 'e'}, @@ -248,10 +249,11 @@ int main(int argc, char *argv[]) { - int c, lastc, prevoptind, newarg, i, needpattern; - struct patfile *patfile, *pf_next; - long l; - char *ep; + int c, lastc, prevoptind, newarg, i, needpattern; + struct patfile *patfile, *pf_next; + long l; + char *ep; + struct stat *finfo = 0; SLIST_INIT(&patfilelh); switch (__progname[0]) { @@ -326,6 +328,10 @@ case 'c': cflag = 1; break; + case 'D': + if (strcmp(optarg, "skip") == 0) + Dflag = 1; + break; case 'E': Fflag = Gflag = 0; Eflag++; @@ -495,8 +501,22 @@ if (Rflag) c = grep_tree(argv); else - for (c = 0; argc--; ++argv) - c += procfile(*argv); - + for (c = 0; argc--; ++argv) { + if (Dflag) { + if (!(finfo = malloc(sizeof(struct stat)))) + err(2, NULL); + if (stat(*argv, finfo) == -1) + err(2, NULL); + if (S_ISBLK(finfo->st_mode) || + S_ISCHR(finfo->st_mode) || + S_ISFIFO(finfo->st_mode) || + S_ISSOCK(finfo->st_mode)) { + free(finfo); + continue; + } else + free(finfo); + } + c+= procfile(*argv); + } exit(!c); } ==== //depot/projects/soc2008/gabor_textproc/grep/grep.h#8 (text+ko) ==== @@ -60,7 +60,7 @@ extern int cflags, eflags; /* Command line flags */ -extern int Aflag, Bflag, Eflag, Fflag, Gflag, Hflag, Lflag, Pflag, +extern int Aflag, Bflag, Dflag, Eflag, Fflag, Gflag, Hflag, Lflag, Pflag, Sflag, Rflag, Zflag, bflag, cflag, hflag, iflag, lflag, nflag, oflag, qflag, sflag, vflag, wflag, xflag, ==== //depot/projects/soc2008/gabor_textproc/grep/util.c#10 (text+ko) ==== @@ -63,9 +63,10 @@ int grep_tree(char **argv) { - FTS *fts; - FTSENT *p; - int c, fts_flags; + FTS *fts; + FTSENT *p; + int c, fts_flags; + struct stat *finfo = 0; c = fts_flags = 0; @@ -90,6 +91,20 @@ case FTS_DP: break; default: + if (Dflag) { + if (!(finfo = malloc(sizeof(struct stat)))) + err(2, NULL); + if (stat(p->fts_path, finfo) == -1) + err(2, NULL); + if (S_ISBLK(finfo->st_mode) || + S_ISCHR(finfo->st_mode) || + S_ISFIFO(finfo->st_mode) || + S_ISSOCK(finfo->st_mode)) { + free(finfo); + break; + } else + free(finfo); + } c += procfile(p->fts_path); break; }help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200805072127.m47LROoS073335>
