summaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
authorGlenn L McGrath2003-10-03 13:15:44 +0000
committerGlenn L McGrath2003-10-03 13:15:44 +0000
commit07cf92676ae70daab83d5aa248f24c003c07001d (patch)
tree3d0ecd1033fb776fc97dc4c65a6c31b699892ea4 /findutils
parent1dc0ccafddf9b5f540008b7cabbf3ab1f4f53ee3 (diff)
downloadbusybox-07cf92676ae70daab83d5aa248f24c003c07001d.zip
busybox-07cf92676ae70daab83d5aa248f24c003c07001d.tar.gz
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')
-rw-r--r--findutils/xargs.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/findutils/xargs.c b/findutils/xargs.c
index 2b18f8f..298c000 100644
--- a/findutils/xargs.c
+++ b/findutils/xargs.c
@@ -20,6 +20,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
+ * BUGS: -p doesnt accept user input
+ *
*/
#include <stdio.h>
@@ -61,28 +63,29 @@ static void xargs_exec(char * const * args)
}
}
+#define OPT_VERBOSE 0x2
+#define OPT_INTERACTIVE 0x4
+#define OPT_NO_EMPTY 0x8
+
int xargs_main(int argc, char **argv)
{
char *file_to_act_on;
char **args;
int i, a;
- char flg_vi; /* verbose |& interactive */
- char flg_no_empty;
+ unsigned long flg;
bb_opt_complementaly = "pt";
- a = bb_getopt_ulflags(argc, argv, "tpr");
- flg_vi = a & 3;
- flg_no_empty = a & 4;
+ flg = bb_getopt_ulflags(argc, argv, "+tpr");
a = argc - optind;
argv += optind;
if(a==0) {
/* default behavior is to echo all the filenames */
- *argv = "/bin/echo";
+ *argv = "echo";
a++;
}
/* allocating pointers for execvp: a*arg, arg from stdin, NULL */
- args = xcalloc(a + 3, sizeof(char *));
+ args = xcalloc(a + 2, sizeof(char *));
/* Store the command to be executed (taken from the command line) */
for (i = 0; i < a; i++)
@@ -91,17 +94,18 @@ int xargs_main(int argc, char **argv)
/* Now, read in one line at a time from stdin, and store this
* line to be used later as an argument to the command */
while ((file_to_act_on = bb_get_chomped_line_from_file(stdin)) != NULL) {
- if(file_to_act_on[0] != 0 || flg_no_empty == 0) {
+ if(file_to_act_on[0] != 0 || (flg & OPT_NO_EMPTY) == 0) {
args[a] = file_to_act_on[0] ? file_to_act_on : NULL;
- if(flg_vi) {
+ if(flg & (OPT_VERBOSE | OPT_INTERACTIVE)) {
for(i=0; args[i]; i++) {
if(i)
fputc(' ', stderr);
fputs(args[i], stderr);
}
- fputs(((flg_vi & 2) ? " ?..." : "\n"), stderr);
+ fputs(((flg & OPT_INTERACTIVE) ? " ?..." : "\n"), stderr);
}
- if((flg_vi & 2) == 0 || bb_ask_confirmation() != 0 ) {
+
+ if((flg & OPT_INTERACTIVE) == 0 || bb_ask_confirmation() != 0 ) {
xargs_exec(args);
}
}