/* vi: set sw=4 ts=4: */
/*
 * Mini xargs implementation for busybox
 *
 * Copyright (C) 2000 by Lineo, inc.
 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#include "internal.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>


int xargs_main(int argc, char **argv)
{
	char *in_from_stdin = NULL;
	char *args_from_cmdline = NULL;
	char *cmd_to_be_executed = NULL;
	char traceflag = 0;
	int len_args_from_cmdline, len_cmd_to_be_executed, len, opt;

	while ((opt = getopt(argc, argv, "t")) != EOF) {
		switch (opt) {
		case 't':
			traceflag=1;
			break;
		default:
			fatalError(xargs_usage);
		}
	}

	/* Store the command and arguments to be executed (from the command line) */
	if (optind == argc) {
		len_args_from_cmdline = 6;
		args_from_cmdline = xmalloc(len_args_from_cmdline);
		strcat(args_from_cmdline, "echo ");
	} else {
		opt=strlen(argv[optind]);
		len_args_from_cmdline = (opt > 10)? opt : 10;
		args_from_cmdline = xcalloc(len_args_from_cmdline, sizeof(char));
		for (; optind < argc; optind++) {
			if (strlen(argv[optind]) + strlen(args_from_cmdline) >
				len_args_from_cmdline) {
				len_args_from_cmdline += strlen(argv[optind]);
				args_from_cmdline =
					xrealloc(args_from_cmdline,
							 len_args_from_cmdline+1);
			}
			strcat(args_from_cmdline, argv[optind]);
			strcat(args_from_cmdline, " ");
		}
	}

	/* Set up some space for the command to be executed to be held in */
	len_cmd_to_be_executed=10;
	cmd_to_be_executed = xcalloc(len_cmd_to_be_executed, sizeof(char));
	strcpy(cmd_to_be_executed, args_from_cmdline);
	strcat(cmd_to_be_executed, " ");

	/* Now, read in one line at a time from stdin, and run command+args on it */
	in_from_stdin = get_line_from_file(stdin);
	for (;in_from_stdin!=NULL;) {
		len = strlen(in_from_stdin) + len_args_from_cmdline;
		if ( len > len_cmd_to_be_executed ) {
			len_cmd_to_be_executed=len+3;
			cmd_to_be_executed=xrealloc(cmd_to_be_executed, len_cmd_to_be_executed);
		}
		strcat(cmd_to_be_executed, in_from_stdin);
		strcat(cmd_to_be_executed+strlen(cmd_to_be_executed)-2, " ");
		strcat(cmd_to_be_executed, " ");
	
		free(in_from_stdin);
		in_from_stdin = get_line_from_file(stdin);
	}

	if (traceflag==1)
		fputs(cmd_to_be_executed, stderr);

	if ((system(cmd_to_be_executed) != 0) && (errno != 0))
		fatalError("%s", strerror(errno));


#ifdef BB_FEATURE_CLEAN_UP
	free(args_from_cmdline);
	free(cmd_to_be_executed);
#endif

	return 0;
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/

