svn commit: trunk/busybox: editors findutils testsuite

vda at busybox.net vda at busybox.net
Sat Jun 7 05:19:32 UTC 2008


Author: vda
Date: 2008-06-06 22:19:31 -0700 (Fri, 06 Jun 2008)
New Revision: 22253

Log:
grep: make "-f -" work (+ testsuite)
diff: small code shrink

function                                             old     new   delta
grep_main                                            722     714      -8
diffreg                                             1825    1793     -32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-40)             Total: -40 bytes



Modified:
   trunk/busybox/editors/diff.c
   trunk/busybox/findutils/grep.c
   trunk/busybox/testsuite/grep.tests


Changeset:
Modified: trunk/busybox/editors/diff.c
===================================================================
--- trunk/busybox/editors/diff.c	2008-06-06 16:11:12 UTC (rev 22252)
+++ trunk/busybox/editors/diff.c	2008-06-07 05:19:31 UTC (rev 22253)
@@ -1021,11 +1021,12 @@
 	rval = D_SAME;
 
 	if (flags & D_EMPTY1)
-		f1 = xfopen(bb_dev_null, "r");
+		/* can't be stdin, but xfopen_stdin() is smaller code */
+		f1 = xfopen_stdin(bb_dev_null);
 	else
 		f1 = xfopen_stdin(file1);
 	if (flags & D_EMPTY2)
-		f2 = xfopen(bb_dev_null, "r");
+		f2 = xfopen_stdin(bb_dev_null);
 	else
 		f2 = xfopen_stdin(file2);
 

Modified: trunk/busybox/findutils/grep.c
===================================================================
--- trunk/busybox/findutils/grep.c	2008-06-06 16:11:12 UTC (rev 22252)
+++ trunk/busybox/findutils/grep.c	2008-06-07 05:19:31 UTC (rev 22253)
@@ -126,7 +126,7 @@
 typedef struct grep_list_data_t {
 	char *pattern;
 	regex_t preg;
-#define PATTERN_MEM_A 1
+#define ALLOCATED 1
 #define COMPILED 2
 	int flg_mem_alocated_compiled;
 } grep_list_data_t;
@@ -363,10 +363,10 @@
 
 		fopt = cur->link;
 		free(cur);
-		f = xfopen(ffile, "r");
+		f = xfopen_stdin(ffile);
 		while ((line = xmalloc_fgetline(f)) != NULL) {
 			llist_add_to(&pattern_head,
-				new_grep_list_data(line, PATTERN_MEM_A));
+				new_grep_list_data(line, ALLOCATED));
 		}
 	}
 }
@@ -486,7 +486,7 @@
 		argc--;
 	}
 
-	/* argv[(optind)..(argc-1)] should be names of file to grep through. If
+	/* argv[0..(argc-1)] should be names of file to grep through. If
 	 * there is more than one file to grep, we will print the filenames. */
 	if (argc > 1)
 		print_filename = 1;
@@ -535,9 +535,9 @@
 			grep_list_data_t *gl = (grep_list_data_t *)pattern_head_ptr->data;
 
 			pattern_head = pattern_head->link;
-			if ((gl->flg_mem_alocated_compiled & PATTERN_MEM_A))
+			if (gl->flg_mem_alocated_compiled & ALLOCATED)
 				free(gl->pattern);
-			if ((gl->flg_mem_alocated_compiled & COMPILED))
+			if (gl->flg_mem_alocated_compiled & COMPILED)
 				regfree(&(gl->preg));
 			free(gl);
 			free(pattern_head_ptr);

Modified: trunk/busybox/testsuite/grep.tests
===================================================================
--- trunk/busybox/testsuite/grep.tests	2008-06-06 16:11:12 UTC (rev 22252)
+++ trunk/busybox/testsuite/grep.tests	2008-06-07 05:19:31 UTC (rev 22253)
@@ -78,6 +78,10 @@
 testing "grep -F handles multiple expessions" "grep -F -e one -e two input ; echo \$?" \
 	"one\ntwo\n0\n" "one\ntwo\n" ""
 
+# -f file/-
+testing "grep can read regexps from stdin" "grep -f - input ; echo \$?" \
+	"two\nthree\n0\n" "tw\ntwo\nthree\n" "tw.\nthr\n"
+
 optional FEATURE_GREP_EGREP_ALIAS
 testing "grep -E supports extended regexps" "grep -E fo+" "foo\n" "" \
 	"b\ar\nfoo\nbaz"




More information about the busybox-cvs mailing list