aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-01 21:05:12 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-01 21:05:12 +0000
commitb97c9842a521a54980b247ab8b920f057b128b2e (patch)
tree54731506b0d02a639aa2781412ca3ceab927594f
parentbb119d059a80c85fe844b9f9c770e0c77aeb49e6 (diff)
downloadbusybox-w32-b97c9842a521a54980b247ab8b920f057b128b2e.tar.gz
busybox-w32-b97c9842a521a54980b247ab8b920f057b128b2e.tar.bz2
busybox-w32-b97c9842a521a54980b247ab8b920f057b128b2e.zip
sed: unbreak multiple -e, -f option handling (my fault)
-rw-r--r--coreutils/od.c2
-rw-r--r--editors/sed.c39
-rw-r--r--include/dump.h2
-rw-r--r--libbb/get_line_from_file.c6
4 files changed, 29 insertions, 20 deletions
diff --git a/coreutils/od.c b/coreutils/od.c
index df06dd3ec..60a5174d9 100644
--- a/coreutils/od.c
+++ b/coreutils/od.c
@@ -189,7 +189,7 @@ int od_main(int argc, char **argv)
189 189
190 odoffset(argc, &argv); 190 odoffset(argc, &argv);
191 191
192 return(bb_dump_dump(argv)); 192 return bb_dump_dump(argv);
193} 193}
194 194
195/*- 195/*-
diff --git a/editors/sed.c b/editors/sed.c
index ee910d7ab..229a9feaa 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -1087,8 +1087,8 @@ static void add_cmd_block(char *cmdstr)
1087int sed_main(int argc, char **argv) 1087int sed_main(int argc, char **argv)
1088{ 1088{
1089 unsigned long opt; 1089 unsigned long opt;
1090 char *opt_e, *opt_f; 1090 llist_t *opt_e, *opt_f;
1091 int status = EXIT_SUCCESS, getpat = 1; 1091 int status = EXIT_SUCCESS;
1092 1092
1093 bbg.sed_cmd_tail=&bbg.sed_cmd_head; 1093 bbg.sed_cmd_tail=&bbg.sed_cmd_head;
1094 1094
@@ -1102,6 +1102,8 @@ int sed_main(int argc, char **argv)
1102 } 1102 }
1103 1103
1104 /* do normal option parsing */ 1104 /* do normal option parsing */
1105 opt_e = opt_f = NULL;
1106 bb_opt_complementally = "e::f::"; /* can occur multiple times */
1105 opt = bb_getopt_ulflags(argc, argv, "irne:f:", &opt_e, &opt_f); 1107 opt = bb_getopt_ulflags(argc, argv, "irne:f:", &opt_e, &opt_f);
1106 if (opt & 0x1) { // -i 1108 if (opt & 0x1) { // -i
1107 bbg.in_place++; 1109 bbg.in_place++;
@@ -1110,23 +1112,30 @@ int sed_main(int argc, char **argv)
1110 if (opt & 0x2) bbg.regex_type|=REG_EXTENDED; // -r 1112 if (opt & 0x2) bbg.regex_type|=REG_EXTENDED; // -r
1111 if (opt & 0x4) bbg.be_quiet++; // -n 1113 if (opt & 0x4) bbg.be_quiet++; // -n
1112 if (opt & 0x8) { // -e 1114 if (opt & 0x8) { // -e
1113 add_cmd_block(opt_e); 1115 while (opt_e) {
1114 getpat=0; 1116 llist_t *cur = opt_e;
1117 add_cmd_block(cur->data);
1118 opt_e = cur->link;
1119 free(cur);
1120 }
1115 } 1121 }
1116 if (opt & 0x10) { // -f 1122 if (opt & 0x10) { // -f
1117 FILE *cmdfile; 1123 while (opt_f) {
1118 char *line; 1124 llist_t *cur = opt_f;
1119 cmdfile = xfopen(opt_f, "r"); 1125 FILE *cmdfile;
1120 while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) { 1126 char *line;
1121 add_cmd(line); 1127 cmdfile = xfopen(cur->data, "r");
1122 getpat=0; 1128 while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
1123 free(line); 1129 add_cmd(line);
1130 free(line);
1131 }
1132 xprint_and_close_file(cmdfile);
1133 opt_f = cur->link;
1134 free(cur);
1124 } 1135 }
1125 xprint_and_close_file(cmdfile);
1126 } 1136 }
1127
1128 /* if we didn't get a pattern from -e or -f, use argv[optind] */ 1137 /* if we didn't get a pattern from -e or -f, use argv[optind] */
1129 if(getpat) { 1138 if(!(opt & 0x18)) {
1130 if (argv[optind] == NULL) 1139 if (argv[optind] == NULL)
1131 bb_show_usage(); 1140 bb_show_usage();
1132 else 1141 else
@@ -1136,7 +1145,7 @@ int sed_main(int argc, char **argv)
1136 add_cmd(""); 1145 add_cmd("");
1137 1146
1138 /* By default, we write to stdout */ 1147 /* By default, we write to stdout */
1139 bbg.nonstdout=stdout; 1148 bbg.nonstdout = stdout;
1140 1149
1141 /* argv[(optind)..(argc-1)] should be names of file to process. If no 1150 /* argv[(optind)..(argc-1)] should be names of file to process. If no
1142 * files were specified or '-' was specified, take input from stdin. 1151 * files were specified or '-' was specified, take input from stdin.
diff --git a/include/dump.h b/include/dump.h
index e8a96ef87..7e1715430 100644
--- a/include/dump.h
+++ b/include/dump.h
@@ -40,7 +40,7 @@ typedef struct _fs { /* format strings */
40} FS; 40} FS;
41 41
42extern void bb_dump_add(const char *fmt); 42extern void bb_dump_add(const char *fmt);
43extern int bb_dump_dump (char **argv); 43extern int bb_dump_dump(char **argv);
44extern int bb_dump_size(FS * fs); 44extern int bb_dump_size(FS * fs);
45 45
46extern FS *bb_dump_fshead; /* head of format strings */ 46extern FS *bb_dump_fshead; /* head of format strings */
diff --git a/libbb/get_line_from_file.c b/libbb/get_line_from_file.c
index 68837b20d..de49eb51d 100644
--- a/libbb/get_line_from_file.c
+++ b/libbb/get_line_from_file.c
@@ -16,7 +16,7 @@
16/* get_line_from_file() - This function reads an entire line from a text file, 16/* get_line_from_file() - This function reads an entire line from a text file,
17 * up to a newline or NUL byte. It returns a malloc'ed char * which must be 17 * up to a newline or NUL byte. It returns a malloc'ed char * which must be
18 * stored and free'ed by the caller. If end is null '\n' isn't considered 18 * stored and free'ed by the caller. If end is null '\n' isn't considered
19 * and of line. If end isn't null, length of the chunk read is stored in it. */ 19 * end of line. If end isn't null, length of the chunk read is stored in it. */
20 20
21char *bb_get_chunk_from_file(FILE * file, int *end) 21char *bb_get_chunk_from_file(FILE * file, int *end)
22{ 22{
@@ -46,7 +46,7 @@ char *bb_get_chunk_from_file(FILE * file, int *end)
46 return linebuf; 46 return linebuf;
47} 47}
48 48
49/* Get line, including trailing /n if any */ 49/* Get line, including trailing \n if any */
50char *bb_get_line_from_file(FILE * file) 50char *bb_get_line_from_file(FILE * file)
51{ 51{
52 int i; 52 int i;
@@ -54,7 +54,7 @@ char *bb_get_line_from_file(FILE * file)
54 return bb_get_chunk_from_file(file, &i); 54 return bb_get_chunk_from_file(file, &i);
55} 55}
56 56
57/* Get line. Remove trailing /n */ 57/* Get line. Remove trailing \n */
58char *bb_get_chomped_line_from_file(FILE * file) 58char *bb_get_chomped_line_from_file(FILE * file)
59{ 59{
60 int i; 60 int i;