diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-09-24 02:40:56 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-09-24 02:40:56 +0000 |
commit | 6f283c2f772c32635fbf61f5b6c0a9a37cc50eed (patch) | |
tree | 8080773a73c3ecbf78b96a8c8ec6e6f109adb6dd /findutils/xargs.c | |
parent | 9ae38386575513dfed2a7eba4eb53869d17dca2d (diff) | |
download | busybox-w32-6f283c2f772c32635fbf61f5b6c0a9a37cc50eed.tar.gz busybox-w32-6f283c2f772c32635fbf61f5b6c0a9a37cc50eed.tar.bz2 busybox-w32-6f283c2f772c32635fbf61f5b6c0a9a37cc50eed.zip |
Fix up xargs so that things like 'cat cat.c | xargs echo' will
work properly.
-Erik
Diffstat (limited to 'findutils/xargs.c')
-rw-r--r-- | findutils/xargs.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/findutils/xargs.c b/findutils/xargs.c index a6f8058fc..478e0ee6d 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <string.h> | 27 | #include <string.h> |
28 | #include <errno.h> | 28 | #include <errno.h> |
29 | #include <getopt.h> | 29 | #include <getopt.h> |
30 | #include <ctype.h> | ||
30 | 31 | ||
31 | 32 | ||
32 | int xargs_main(int argc, char **argv) | 33 | int xargs_main(int argc, char **argv) |
@@ -78,27 +79,49 @@ int xargs_main(int argc, char **argv) | |||
78 | len_cmd_to_be_executed=10; | 79 | len_cmd_to_be_executed=10; |
79 | cmd_to_be_executed = xcalloc(len_cmd_to_be_executed, sizeof(char)); | 80 | cmd_to_be_executed = xcalloc(len_cmd_to_be_executed, sizeof(char)); |
80 | strcpy(cmd_to_be_executed, args_from_cmdline); | 81 | strcpy(cmd_to_be_executed, args_from_cmdline); |
81 | strcat(cmd_to_be_executed, " "); | 82 | strcat(cmd_to_be_executed, " \""); |
82 | 83 | ||
83 | /* Now, read in one line at a time from stdin, and run command+args on it */ | 84 | /* Now, read in one line at a time from stdin, and run command+args on it */ |
84 | in_from_stdin = get_line_from_file(stdin); | 85 | in_from_stdin = get_line_from_file(stdin); |
85 | for (;in_from_stdin!=NULL;) { | 86 | for (;in_from_stdin!=NULL;) { |
86 | char *tmp; | 87 | char *tmp; |
87 | len = strlen(in_from_stdin) + len_args_from_cmdline; | 88 | opt = strlen(in_from_stdin); |
89 | len = opt + len_args_from_cmdline; | ||
88 | len_cmd_to_be_executed+=len+3; | 90 | len_cmd_to_be_executed+=len+3; |
89 | cmd_to_be_executed=xrealloc(cmd_to_be_executed, len_cmd_to_be_executed); | 91 | cmd_to_be_executed=xrealloc(cmd_to_be_executed, len_cmd_to_be_executed); |
90 | 92 | ||
91 | /* Strip out any \n's, so we just get one command to run */ | 93 | /* Strip out the final \n */ |
92 | while( (tmp = strchr(in_from_stdin, '\n')) != NULL ) | 94 | in_from_stdin[opt-1]=' '; |
95 | |||
96 | /* Replace any tabs with spaces */ | ||
97 | while( (tmp = strchr(in_from_stdin, '\t')) != NULL ) | ||
93 | *tmp=' '; | 98 | *tmp=' '; |
94 | 99 | ||
95 | strcat(cmd_to_be_executed, in_from_stdin); | 100 | /* Strip out any extra intra-word spaces */ |
101 | while( (tmp = strstr(in_from_stdin, " ")) != NULL ) { | ||
102 | opt = strlen(in_from_stdin); | ||
103 | memmove(tmp, tmp+1, opt-(tmp-in_from_stdin)); | ||
104 | } | ||
105 | |||
106 | /* trim trailing whitespace */ | ||
107 | opt = strlen(in_from_stdin) - 1; | ||
108 | while (isspace(in_from_stdin[opt])) | ||
109 | opt--; | ||
110 | in_from_stdin[++opt] = 0; | ||
111 | |||
112 | /* Strip out any leading whitespace */ | ||
113 | tmp=in_from_stdin; | ||
114 | while(isspace(*tmp)) | ||
115 | tmp++; | ||
116 | |||
117 | strcat(cmd_to_be_executed, tmp); | ||
96 | strcat(cmd_to_be_executed, " "); | 118 | strcat(cmd_to_be_executed, " "); |
97 | 119 | ||
98 | free(in_from_stdin); | 120 | free(in_from_stdin); |
99 | in_from_stdin = get_line_from_file(stdin); | 121 | in_from_stdin = get_line_from_file(stdin); |
100 | } | 122 | } |
101 | 123 | ||
124 | strcat(cmd_to_be_executed, "\""); | ||
102 | if (traceflag==1) | 125 | if (traceflag==1) |
103 | fputs(cmd_to_be_executed, stderr); | 126 | fputs(cmd_to_be_executed, stderr); |
104 | 127 | ||