From owner-p4-projects@FreeBSD.ORG Tue Jun 24 09:03:01 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9945410656AE; Tue, 24 Jun 2008 09:03:01 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 59919106567F for ; Tue, 24 Jun 2008 09:03:01 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 450C08FC23 for ; Tue, 24 Jun 2008 09:03:01 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m5O92uaj035933 for ; Tue, 24 Jun 2008 09:02:56 GMT (envelope-from gabor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m5O92uWt035931 for perforce@freebsd.org; Tue, 24 Jun 2008 09:02:56 GMT (envelope-from gabor@freebsd.org) Date: Tue, 24 Jun 2008 09:02:56 GMT Message-Id: <200806240902.m5O92uWt035931@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gabor@freebsd.org using -f From: Gabor Kovesdan To: Perforce Change Reviews Cc: Subject: PERFORCE change 144014 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Jun 2008 09:03:01 -0000 http://perforce.freebsd.org/chv.cgi?CH=144014 Change 144014 by gabor@gabor_server on 2008/06/24 09:02:45 - Use an easier to understand and cleaner layout for device, directory and link actions Inspired by: NetBSD Project Affected files ... .. //depot/projects/soc2008/gabor_textproc/grep/grep.c#38 edit .. //depot/projects/soc2008/gabor_textproc/grep/grep.h#20 edit .. //depot/projects/soc2008/gabor_textproc/grep/util.c#34 edit Differences ... ==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#38 (text+ko) ==== @@ -90,20 +90,15 @@ /* Command-line flags */ unsigned long long Aflag; /* -A x: print x lines trailing each match */ unsigned long long 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 */ int Hflag; /* -H: always print file name */ int Jflag; /* -J: grep in bzipped file */ int Lflag; /* -L: only show names of files with no matches */ -int Oflag; /* -O: if -R, follow explicitly listed symlinks */ -int Pflag; /* -P: if -R, no symlinks are followed */ -int Rflag; /* -R: recursively search directory trees */ int Zflag; /* -Z: grep in gzipped file */ int bflag; /* -b: show block numbers for each match */ int cflag; /* -c: only show a count of matching lines */ -int dflag; /* -d: skip reading of directories */ int hflag; /* -h: don't print filename headers */ int iflag; /* -i: ignore case */ int lflag; /* -l: only show names of files with matches */ @@ -121,7 +116,10 @@ char *color; /* --color */ unsigned long long mcount; /* count for -m */ -int binbehave = BIN_FILE_BIN; +int binbehave = BIN_FILE_BIN; +int devbehave = DEV_GREP; +int dirbehave = DIR_GREP; +int linkbehave = LINK_GREP; enum { BIN_OPT = CHAR_MAX + 1, @@ -443,14 +441,14 @@ break; case 'D': if (strcmp(optarg, "skip") == 0) - Dflag = 1; + devbehave = DEV_SKIP; break; case 'd': if (strcmp("recurse", optarg) == 0) { Hflag++; - Rflag++; + dirbehave = DIR_RECURSE; } else if (strcmp("skip", optarg) == 0) - dflag++; + dirbehave = DIR_SKIP; else if (strcmp("read", optarg) != 0) usage(); break; @@ -513,23 +511,23 @@ nflag = 1; break; case 'O': - Oflag++; + linkbehave = LINK_EXPLICIT; break; case 'o': oflag++; break; case 'P': - Pflag++; + linkbehave = LINK_SKIP; break; case 'q': qflag = 1; break; case 'S': - Pflag = 0; + linkbehave = LINK_GREP; break; case 'R': case 'r': - Rflag++; + dirbehave = DIR_RECURSE; Hflag++; break; case 's': @@ -645,11 +643,11 @@ if (argc == 0) exit(!procfile(NULL)); - if (Rflag) + if (dirbehave == DIR_RECURSE) c = grep_tree(argv); else for (c = 0; argc--; ++argv) { - if (Dflag) { + if (devbehave == DEV_SKIP) { if (!(finfo = malloc(sizeof(struct stat)))) err(2, NULL); if (stat(*argv, finfo) == -1) ==== //depot/projects/soc2008/gabor_textproc/grep/grep.h#20 (text+ko) ==== @@ -49,6 +49,17 @@ #define BIN_FILE_SKIP 1 #define BIN_FILE_TEXT 2 +#define DIR_GREP 0 +#define DIR_SKIP 1 +#define DIR_RECURSE 2 + +#define DEV_GREP 0 +#define DEV_SKIP 1 + +#define LINK_GREP 0 +#define LINK_EXPLICIT 1 +#define LINK_SKIP 2 + struct str { size_t len; int line_no; @@ -72,13 +83,12 @@ extern int cflags, eflags; /* Command line flags */ -extern int Dflag, Eflag, Fflag, Gflag, Hflag, Jflag, - Lflag, Oflag, Pflag, Rflag, Zflag, - bflag, cflag, dflag, hflag, iflag, lflag, mflag, nflag, oflag, +extern int Eflag, Fflag, Gflag, Hflag, Jflag, Lflag, Zflag, + bflag, cflag, hflag, iflag, lflag, mflag, nflag, oflag, qflag, sflag, vflag, wflag, xflag, nullflag; extern unsigned long long Aflag, Bflag, mcount; extern char *color, *label; -extern int binbehave; +extern int binbehave, devbehave, dirbehave, linkbehave; extern int first, prev, matchall, patterns, tail, notfound; extern char **pattern; ==== //depot/projects/soc2008/gabor_textproc/grep/util.c#34 (text+ko) ==== @@ -69,9 +69,9 @@ c = fts_flags = 0; - if (Oflag) + if (linkbehave == LINK_EXPLICIT) fts_flags = FTS_COMFOLLOW; - if (Pflag) + if (linkbehave == LINK_SKIP) fts_flags = FTS_PHYSICAL; else fts_flags = FTS_LOGICAL; @@ -90,7 +90,7 @@ case FTS_DP: break; default: - if (Dflag || Rflag || dflag) { + if ((devbehave == DEV_SKIP) || (dirbehave == DIR_RECURSE) || (dirbehave == DIR_SKIP)) { struct stat *finfo; if (!(finfo = malloc(sizeof(struct stat)))) @@ -98,14 +98,14 @@ if (stat(p->fts_path, finfo) == -1) err(2, NULL); - if (Dflag && (S_ISBLK(finfo->st_mode) || + if ((devbehave == DEV_SKIP) && (S_ISBLK(finfo->st_mode) || S_ISCHR(finfo->st_mode) || S_ISFIFO(finfo->st_mode) || S_ISSOCK(finfo->st_mode))) { free(finfo); break; } - if ((Rflag || dflag) && S_ISDIR(finfo->st_mode)) { + if (((dirbehave == DIR_RECURSE) || (dirbehave == DIR_SKIP)) && S_ISDIR(finfo->st_mode)) { free(finfo); break; }