PERFORCE change 144092 for review

Gabor Kovesdan gabor at FreeBSD.org
Wed Jun 25 13:03:26 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=144092

Change 144092 by gabor at gabor_server on 2008/06/25 13:02:50

	- Cleanups [1]
	- Revert a nit, which was incorrect
	
	Obtained from:	NetBSD Project [1]

Affected files ...

.. //depot/projects/soc2008/gabor_textproc/grep/grep.c#48 edit
.. //depot/projects/soc2008/gabor_textproc/grep/grep.h#27 edit

Differences ...

==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#48 (text+ko) ====

@@ -35,7 +35,6 @@
 #endif /* not lint */
 
 #include <sys/limits.h>
-#include <sys/queue.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 
@@ -138,12 +137,6 @@
 int	 tail;		/* lines left to print */
 int	 notfound;	/* file not found */
 
-struct patfile {
-	const char		*pf_file;
-	SLIST_ENTRY(patfile)	 pf_next;
-};
-SLIST_HEAD(, patfile)		 patfilelh;
-
 extern char	*__progname;
 
 static void
@@ -323,25 +316,13 @@
 		len += 14 + extra;
 	} else {
 		pattern[patterns] = grep_malloc(len + 1);
-		strlcpy(pattern[patterns], pat, len);
+		memcpy(pattern[patterns], pat, len);
 		pattern[patterns][len] = '\0';
 	}
 	++patterns;
 }
 
 static void
-add_patterns(char *pats)
-{
-	char	*nl;
-
-	while ((nl = strchr(pats, '\n')) != NULL) {
-		add_pattern(pats, nl - pats);
-		pats = nl + 1;
-	}
-	add_pattern(pats, strlen(pats));
-}
-
-static void
 read_patterns(const char *fn)
 {
 	FILE	*f;
@@ -360,8 +341,7 @@
 int
 main(int argc, char *argv[])
 {
-	int		 c, lastc, prevoptind, newarg, i, needpattern;
-	struct patfile	*patfile, *pf_next;
+	int		 c, lastc, prevoptind, newarg, i;
 	char		*ep;
 	struct stat	*finfo = 0;
 	unsigned long long l;
@@ -372,7 +352,6 @@
 	catalog = catopen("grep", NL_CAT_LOCALE);
 #endif
 
-	SLIST_INIT(&patfilelh);
 	switch (__progname[0]) {
 	case 'e':
 		Eflag++;
@@ -402,7 +381,6 @@
 	lastc = '\0';
 	newarg = 1;
 	prevoptind = 1;
-	needpattern = 1;
 	while ((c = getopt_long(argc, argv, optstr,
 				long_options, NULL)) != -1) {
 		switch (c) {
@@ -459,18 +437,14 @@
 			Eflag++;
 			break;
 		case 'e':
-			add_patterns(optarg);
-			needpattern = 0;
+			add_pattern(optarg, strlen(optarg));
 			break;
 		case 'F':
 			Eflag = Gflag = 0;
 			Fflag++;
 			break;
 		case 'f':
-			patfile = grep_malloc(sizeof(*patfile));
-			patfile->pf_file = optarg;
-			SLIST_INSERT_HEAD(&patfilelh, patfile, pf_next);
-			needpattern = 0;
+			read_patterns(optarg);
 			break;
 		case 'G':
 			Eflag = Fflag = 0;
@@ -600,18 +574,11 @@
 	argc -= optind;
 	argv += optind;
 
-	for (patfile = SLIST_FIRST(&patfilelh); patfile != NULL;
-	    patfile = pf_next) {
-		pf_next = SLIST_NEXT(patfile, pf_next);
-		read_patterns(patfile->pf_file);
-		free(patfile);
-	}
-
-	if (argc == 0 && needpattern)
+	if (argc == 0 && patterns == 0)
 		usage();
 
-	if (argc != 0 && needpattern) {
-		add_patterns(*argv);
+	if (patterns == 0) {
+		add_pattern(*argv, strlen(*argv));
 		--argc;
 		++argv;
 	}

==== //depot/projects/soc2008/gabor_textproc/grep/grep.h#27 (text+ko) ====

@@ -74,17 +74,6 @@
 	char		*dat;
 };
 
-struct fastgrep {
-	unsigned char	*pattern;
-	int		 patternLen;
-	int		 qsBc[UCHAR_MAX + 1];
-	/* flags */
-	int		 bol;
-	int		 eol;
-	int		 wmatch;
-	int		 reversedSearch;
-};
-
 /* Flags passed to regcomp() and regexec() */
 extern int	 cflags, eflags;
 


More information about the p4-projects mailing list