aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/sed.c39
1 files changed, 24 insertions, 15 deletions
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.