aboutsummaryrefslogtreecommitdiff
path: root/findutils/xargs.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-10-03 13:15:44 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-10-03 13:15:44 +0000
commit07cf92676ae70daab83d5aa248f24c003c07001d (patch)
tree3d0ecd1033fb776fc97dc4c65a6c31b699892ea4 /findutils/xargs.c
parent1dc0ccafddf9b5f540008b7cabbf3ab1f4f53ee3 (diff)
downloadbusybox-w32-07cf92676ae70daab83d5aa248f24c003c07001d.tar.gz
busybox-w32-07cf92676ae70daab83d5aa248f24c003c07001d.tar.bz2
busybox-w32-07cf92676ae70daab83d5aa248f24c003c07001d.zip
Dont mix xarg options with utility option, fixes example of
`echo "README" | xargs ls -al` Dont specify a path for the default behaviour of echo args allocated space for an extra ptr Use defines for the different options
Diffstat (limited to 'findutils/xargs.c')
-rw-r--r--findutils/xargs.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/findutils/xargs.c b/findutils/xargs.c
index 2b18f8f28..298c000dc 100644
--- a/findutils/xargs.c
+++ b/findutils/xargs.c
@@ -20,6 +20,8 @@
20 * along with this program; if not, write to the Free Software 20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * 22 *
23 * BUGS: -p doesnt accept user input
24 *
23 */ 25 */
24 26
25#include <stdio.h> 27#include <stdio.h>
@@ -61,28 +63,29 @@ static void xargs_exec(char * const * args)
61 } 63 }
62} 64}
63 65
66#define OPT_VERBOSE 0x2
67#define OPT_INTERACTIVE 0x4
68#define OPT_NO_EMPTY 0x8
69
64int xargs_main(int argc, char **argv) 70int xargs_main(int argc, char **argv)
65{ 71{
66 char *file_to_act_on; 72 char *file_to_act_on;
67 char **args; 73 char **args;
68 int i, a; 74 int i, a;
69 char flg_vi; /* verbose |& interactive */ 75 unsigned long flg;
70 char flg_no_empty;
71 76
72 bb_opt_complementaly = "pt"; 77 bb_opt_complementaly = "pt";
73 a = bb_getopt_ulflags(argc, argv, "tpr"); 78 flg = bb_getopt_ulflags(argc, argv, "+tpr");
74 flg_vi = a & 3;
75 flg_no_empty = a & 4;
76 79
77 a = argc - optind; 80 a = argc - optind;
78 argv += optind; 81 argv += optind;
79 if(a==0) { 82 if(a==0) {
80 /* default behavior is to echo all the filenames */ 83 /* default behavior is to echo all the filenames */
81 *argv = "/bin/echo"; 84 *argv = "echo";
82 a++; 85 a++;
83 } 86 }
84 /* allocating pointers for execvp: a*arg, arg from stdin, NULL */ 87 /* allocating pointers for execvp: a*arg, arg from stdin, NULL */
85 args = xcalloc(a + 3, sizeof(char *)); 88 args = xcalloc(a + 2, sizeof(char *));
86 89
87 /* Store the command to be executed (taken from the command line) */ 90 /* Store the command to be executed (taken from the command line) */
88 for (i = 0; i < a; i++) 91 for (i = 0; i < a; i++)
@@ -91,17 +94,18 @@ int xargs_main(int argc, char **argv)
91 /* Now, read in one line at a time from stdin, and store this 94 /* Now, read in one line at a time from stdin, and store this
92 * line to be used later as an argument to the command */ 95 * line to be used later as an argument to the command */
93 while ((file_to_act_on = bb_get_chomped_line_from_file(stdin)) != NULL) { 96 while ((file_to_act_on = bb_get_chomped_line_from_file(stdin)) != NULL) {
94 if(file_to_act_on[0] != 0 || flg_no_empty == 0) { 97 if(file_to_act_on[0] != 0 || (flg & OPT_NO_EMPTY) == 0) {
95 args[a] = file_to_act_on[0] ? file_to_act_on : NULL; 98 args[a] = file_to_act_on[0] ? file_to_act_on : NULL;
96 if(flg_vi) { 99 if(flg & (OPT_VERBOSE | OPT_INTERACTIVE)) {
97 for(i=0; args[i]; i++) { 100 for(i=0; args[i]; i++) {
98 if(i) 101 if(i)
99 fputc(' ', stderr); 102 fputc(' ', stderr);
100 fputs(args[i], stderr); 103 fputs(args[i], stderr);
101 } 104 }
102 fputs(((flg_vi & 2) ? " ?..." : "\n"), stderr); 105 fputs(((flg & OPT_INTERACTIVE) ? " ?..." : "\n"), stderr);
103 } 106 }
104 if((flg_vi & 2) == 0 || bb_ask_confirmation() != 0 ) { 107
108 if((flg & OPT_INTERACTIVE) == 0 || bb_ask_confirmation() != 0 ) {
105 xargs_exec(args); 109 xargs_exec(args);
106 } 110 }
107 } 111 }