[BusyBox] One more sed glitch...
Rob Landley
rob at landley.net
Sat Oct 4 04:28:12 UTC 2003
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...)
(The space thing at the beginning is orthogonal, I can split it out if you
like. Fix I did 5 minutes after generating the big patch days ago, which I
forgot was still in my tree. Space and tab aren't necessarily the whole of
isspace()...)
Rob
--- busybox/editors/sed.c 2003-10-01 05:26:23.000000000 -0500
+++ busybox-new/editors/sed.c 2003-10-03 14:01:41.224231160 -0500
@@ -346,6 +346,8 @@
}
continue;
}
+ /* Skip spaces */
+ if(isspace(substr[idx])) continue;
switch (substr[idx]) {
/* Replace all occurrences */
case 'g':
@@ -366,10 +368,6 @@
case 'I':
cflags |= REG_ICASE;
break;
- /* Skip spaces */
- case ' ':
- case '\t':
- break;
case ';':
case '}':
goto out;
@@ -1043,6 +1041,27 @@
}
}
+/* It is possible to have a command line argument with embedded
+ newlines. This counts as multiple command lines. */
+
+static void add_cmd_block(char *cmdstr)
+{
+ int go=1;
+ char *temp=bb_xstrdup(cmdstr),*temp2=temp;
+
+ while(go) {
+ int len=strcspn(temp2,"\n");
+ if(!temp2[len]) go=0;
+ else temp2[len]=0;
+ add_cmd(temp2);
+ temp2+=len+1;
+ }
+ free(temp);
+}
+
extern int sed_main(int argc, char **argv)
{
int opt, status = EXIT_SUCCESS;
@@ -1060,23 +1079,8 @@
be_quiet++;
break;
case 'e':
- {
- int go=1;
- char *temp=bb_xstrdup(optarg),*temp2=temp;
-
- /* It is possible to have a command line argument with embedded
- newlines. This counts as a multi-line argument. */
-
- while(go) {
- int len=strcspn(temp2,"\n");
- if(!temp2[len]) go=0;
- else temp2[len]=0;
- add_cmd(temp2);
- temp2+=len+1;
- }
- free(temp);
+ add_cmd_block(optarg);
break;
- }
case 'f':
{
FILE *cmdfile;
@@ -1097,8 +1101,6 @@
bb_show_usage();
}
}
- /* Flush any unfinished commands. */
- add_cmd("");
/* if we didn't get a pattern from a -e and no command file was specified,
* argv[optind] should be the pattern. no pattern, no worky */
@@ -1106,8 +1108,11 @@
if (argv[optind] == NULL)
bb_show_usage();
else
- add_cmd(argv[optind++]);
+ add_cmd_block(argv[optind++]);
}
+ /* Flush any unfinished commands. */
+ add_cmd("");
+
/* argv[(optind)..(argc-1)] should be names of file to process. If no
* files were specified or '-' was specified, take input from stdin.
More information about the busybox
mailing list