svn commit: trunk/busybox: coreutils editors include libbb

vda at busybox.net vda at busybox.net
Sun Oct 1 21:05:13 UTC 2006


Author: vda
Date: 2006-10-01 14:05:12 -0700 (Sun, 01 Oct 2006)
New Revision: 16286

Log:
sed: unbreak multiple -e, -f option handling (my fault)


Modified:
   trunk/busybox/coreutils/od.c
   trunk/busybox/editors/sed.c
   trunk/busybox/include/dump.h
   trunk/busybox/libbb/get_line_from_file.c


Changeset:
Modified: trunk/busybox/coreutils/od.c
===================================================================
--- trunk/busybox/coreutils/od.c	2006-10-01 18:34:45 UTC (rev 16285)
+++ trunk/busybox/coreutils/od.c	2006-10-01 21:05:12 UTC (rev 16286)
@@ -189,7 +189,7 @@
 
 	odoffset(argc, &argv);
 
-	return(bb_dump_dump(argv));
+	return bb_dump_dump(argv);
 }
 
 /*-

Modified: trunk/busybox/editors/sed.c
===================================================================
--- trunk/busybox/editors/sed.c	2006-10-01 18:34:45 UTC (rev 16285)
+++ trunk/busybox/editors/sed.c	2006-10-01 21:05:12 UTC (rev 16286)
@@ -1087,8 +1087,8 @@
 int sed_main(int argc, char **argv)
 {
 	unsigned long opt;
-	char *opt_e, *opt_f;
-	int status = EXIT_SUCCESS, getpat = 1;
+	llist_t *opt_e, *opt_f;
+	int status = EXIT_SUCCESS;
 
 	bbg.sed_cmd_tail=&bbg.sed_cmd_head;
 
@@ -1102,6 +1102,8 @@
 	}
 
 	/* do normal option parsing */
+	opt_e = opt_f = NULL;
+	bb_opt_complementally = "e::f::"; /* can occur multiple times */
 	opt = bb_getopt_ulflags(argc, argv, "irne:f:", &opt_e, &opt_f);
 	if (opt & 0x1) { // -i
 		bbg.in_place++;
@@ -1110,23 +1112,30 @@
 	if (opt & 0x2) bbg.regex_type|=REG_EXTENDED; // -r
 	if (opt & 0x4) bbg.be_quiet++; // -n
 	if (opt & 0x8) { // -e
-		add_cmd_block(opt_e);
-		getpat=0;
+		while (opt_e) {
+			llist_t *cur = opt_e;
+			add_cmd_block(cur->data);
+			opt_e = cur->link;
+			free(cur);
+		}
 	}
 	if (opt & 0x10) { // -f
-		FILE *cmdfile;
-		char *line;
-		cmdfile = xfopen(opt_f, "r");
-		while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
-			add_cmd(line);
-			getpat=0;
-			free(line);
+		while (opt_f) {
+			llist_t *cur = opt_f;
+			FILE *cmdfile;
+			char *line;
+			cmdfile = xfopen(cur->data, "r");
+			while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
+				add_cmd(line);
+				free(line);
+			}
+			xprint_and_close_file(cmdfile);
+			opt_f = cur->link;
+			free(cur);
 		}
-		xprint_and_close_file(cmdfile);
 	}
-
 	/* if we didn't get a pattern from -e or -f, use argv[optind] */
-	if(getpat) {
+	if(!(opt & 0x18)) {
 		if (argv[optind] == NULL)
 			bb_show_usage();
 		else
@@ -1136,7 +1145,7 @@
 	add_cmd("");
 
 	/* By default, we write to stdout */
-	bbg.nonstdout=stdout;
+	bbg.nonstdout = stdout;
 
 	/* argv[(optind)..(argc-1)] should be names of file to process. If no
 	 * files were specified or '-' was specified, take input from stdin.

Modified: trunk/busybox/include/dump.h
===================================================================
--- trunk/busybox/include/dump.h	2006-10-01 18:34:45 UTC (rev 16285)
+++ trunk/busybox/include/dump.h	2006-10-01 21:05:12 UTC (rev 16286)
@@ -40,7 +40,7 @@
 } FS;
 
 extern void bb_dump_add(const char *fmt);
-extern int bb_dump_dump (char **argv);
+extern int bb_dump_dump(char **argv);
 extern int bb_dump_size(FS * fs);
 
 extern FS *bb_dump_fshead;		/* head of format strings */

Modified: trunk/busybox/libbb/get_line_from_file.c
===================================================================
--- trunk/busybox/libbb/get_line_from_file.c	2006-10-01 18:34:45 UTC (rev 16285)
+++ trunk/busybox/libbb/get_line_from_file.c	2006-10-01 21:05:12 UTC (rev 16286)
@@ -16,7 +16,7 @@
 /* get_line_from_file() - This function reads an entire line from a text file,
  * up to a newline or NUL byte.  It returns a malloc'ed char * which must be
  * stored and free'ed  by the caller.  If end is null '\n' isn't considered
- * and of line.  If end isn't null, length of the chunk read is stored in it. */
+ * end of line.  If end isn't null, length of the chunk read is stored in it. */
 
 char *bb_get_chunk_from_file(FILE * file, int *end)
 {
@@ -46,7 +46,7 @@
 	return linebuf;
 }
 
-/* Get line, including trailing /n if any */
+/* Get line, including trailing \n if any */
 char *bb_get_line_from_file(FILE * file)
 {
 	int i;
@@ -54,7 +54,7 @@
 	return bb_get_chunk_from_file(file, &i);
 }
 
-/* Get line.  Remove trailing /n */
+/* Get line.  Remove trailing \n */
 char *bb_get_chomped_line_from_file(FILE * file)
 {
 	int i;




More information about the busybox-cvs mailing list