aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-10-04 05:27:56 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-10-04 05:27:56 +0000
commit42c25735e6be3b4af504ae098cf287d259f6b37c (patch)
treef889e877fb60482717178a0fe12b27b49cd829da
parentfd7bc13557a9b672f7f5ba8ef5677c3317bd12ee (diff)
downloadbusybox-w32-42c25735e6be3b4af504ae098cf287d259f6b37c.tar.gz
busybox-w32-42c25735e6be3b4af504ae098cf287d259f6b37c.tar.bz2
busybox-w32-42c25735e6be3b4af504ae098cf287d259f6b37c.zip
Patch from Rob Landley;
Moving on to building diffutils, busybox sed needs this patch to get past the first problem. (Passing it a multi-line command line argument with -e works, but if you don't use -e it doesn't break up the multiple lines...)
-rw-r--r--editors/sed.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/editors/sed.c b/editors/sed.c
index da06bf485..adf79d4d6 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -344,6 +344,8 @@ static int parse_subst_cmd(sed_cmd_t * const sed_cmd, const char *substr)
344 sed_cmd->which_match=(unsigned short)strtol(substr+idx,&pos,10); 344 sed_cmd->which_match=(unsigned short)strtol(substr+idx,&pos,10);
345 idx=pos-substr; 345 idx=pos-substr;
346 } 346 }
347 /* Skip spaces */
348 if(isspace(substr[idx])) continue;
347 continue; 349 continue;
348 } 350 }
349 switch (substr[idx]) { 351 switch (substr[idx]) {
@@ -366,10 +368,6 @@ static int parse_subst_cmd(sed_cmd_t * const sed_cmd, const char *substr)
366 case 'I': 368 case 'I':
367 cflags |= REG_ICASE; 369 cflags |= REG_ICASE;
368 break; 370 break;
369 /* Skip spaces */
370 case ' ':
371 case '\t':
372 break;
373 case ';': 371 case ';':
374 case '}': 372 case '}':
375 goto out; 373 goto out;
@@ -1043,6 +1041,24 @@ discard_line:
1043 } 1041 }
1044} 1042}
1045 1043
1044/* It is possible to have a command line argument with embedded
1045 newlines. This counts as multiple command lines. */
1046
1047static void add_cmd_block(char *cmdstr)
1048{
1049 int go=1;
1050 char *temp=bb_xstrdup(cmdstr),*temp2=temp;
1051
1052 while(go) {
1053 int len=strcspn(temp2,"\n");
1054 if(!temp2[len]) go=0;
1055 else temp2[len]=0;
1056 add_cmd(temp2);
1057 temp2+=len+1;
1058 }
1059 free(temp);
1060}
1061
1046extern int sed_main(int argc, char **argv) 1062extern int sed_main(int argc, char **argv)
1047{ 1063{
1048 int opt, status = EXIT_SUCCESS; 1064 int opt, status = EXIT_SUCCESS;
@@ -1060,23 +1076,8 @@ extern int sed_main(int argc, char **argv)
1060 be_quiet++; 1076 be_quiet++;
1061 break; 1077 break;
1062 case 'e': 1078 case 'e':
1063 { 1079 add_cmd_block(optarg);
1064 int go=1;
1065 char *temp=bb_xstrdup(optarg),*temp2=temp;
1066
1067 /* It is possible to have a command line argument with embedded
1068 newlines. This counts as a multi-line argument. */
1069
1070 while(go) {
1071 int len=strcspn(temp2,"\n");
1072 if(!temp2[len]) go=0;
1073 else temp2[len]=0;
1074 add_cmd(temp2);
1075 temp2+=len+1;
1076 }
1077 free(temp);
1078 break; 1080 break;
1079 }
1080 case 'f': 1081 case 'f':
1081 { 1082 {
1082 FILE *cmdfile; 1083 FILE *cmdfile;
@@ -1097,8 +1098,6 @@ extern int sed_main(int argc, char **argv)
1097 bb_show_usage(); 1098 bb_show_usage();
1098 } 1099 }
1099 } 1100 }
1100 /* Flush any unfinished commands. */
1101 add_cmd("");
1102 1101
1103 /* if we didn't get a pattern from a -e and no command file was specified, 1102 /* if we didn't get a pattern from a -e and no command file was specified,
1104 * argv[optind] should be the pattern. no pattern, no worky */ 1103 * argv[optind] should be the pattern. no pattern, no worky */
@@ -1106,8 +1105,10 @@ extern int sed_main(int argc, char **argv)
1106 if (argv[optind] == NULL) 1105 if (argv[optind] == NULL)
1107 bb_show_usage(); 1106 bb_show_usage();
1108 else 1107 else
1109 add_cmd(argv[optind++]); 1108 add_cmd_block(argv[optind++]);
1110 } 1109 }
1110 /* Flush any unfinished commands. */
1111 add_cmd("");
1111 1112
1112 /* argv[(optind)..(argc-1)] should be names of file to process. If no 1113 /* argv[(optind)..(argc-1)] should be names of file to process. If no
1113 * files were specified or '-' was specified, take input from stdin. 1114 * files were specified or '-' was specified, take input from stdin.