- {"null", no_argument, NULL, '0'},
- {"eof", optional_argument, NULL, 'e'},
- {"replace", optional_argument, NULL, 'i'},
- {"max-lines", optional_argument, NULL, 'l'},
- {"max-args", required_argument, NULL, 'n'},
- {"interactive", no_argument, NULL, 'p'},
- {"no-run-if-empty", no_argument, NULL, 'r'},
- {"max-chars", required_argument, NULL, 's'},
- {"verbose", no_argument, NULL, 't'},
- {"exit", no_argument, NULL, 'x'},
- {"max-procs", required_argument, NULL, 'P'},
- {"help", no_argument, NULL, 'h'},
- {NULL, no_argument, NULL, 0}
-};
-
-static int read_line P_ ((void));
-static int read_string P_ ((void));
-static void do_insert P_ ((char *arg, size_t arglen, size_t lblen));
-static void push_arg P_ ((char *arg, size_t len));
-static boolean print_args P_ ((boolean ask));
-static void do_exec P_ ((void));
-static void add_proc P_ ((pid_t pid));
-static void wait_for_proc P_ ((boolean all));
-static long parse_num P_ ((char *str, int option, long min, long max));
-static long env_size P_ ((char **envp));
-
-int xargs_main (argc, argv)
- int argc;
- char **argv;
-{
- int optc;
- int always_run_command = 1;
- long orig_arg_max;
- char *default_cmd = "/bin/echo";
- int (*read_args) P_ ((void)) = read_line;
-
- program_name = argv[0];
-
- orig_arg_max = ARG_MAX;
- if (orig_arg_max == -1)
- orig_arg_max = LONG_MAX;
- orig_arg_max -= 2048; /* POSIX.2 requires subtracting 2048. */
- arg_max = orig_arg_max;
-
- /* Sanity check for systems with huge ARG_MAX defines (e.g., Suns which
- have it at 1 meg). Things will work fine with a large ARG_MAX but it
- will probably hurt the system more than it needs to; an array of this
- size is allocated. */
- if (arg_max > 20 * 1024)
- arg_max = 20 * 1024;
-
- /* Take the size of the environment into account. */
- arg_max -= env_size (environ);
- if (arg_max <= 0)
- fatalError("environment is too large for exec");
-
- while ((optc = getopt_long (argc, argv, "+0e::i::l::n:prs:txP:",
- longopts, (int *) 0)) != -1)
- {
- switch (optc)
- {
- case '0':
- read_args = read_string;
- break;
-
- case 'e':
- if (optarg)
- eof_str = optarg;
- else
- eof_str = 0;
- break;
-
- case 'h':
- usage (xargs_usage);
-
- case 'i':
- if (optarg)
- replace_pat = optarg;
- else
- replace_pat = "{}";
- /* -i excludes -n -l. */
- args_per_exec = 0;
- lines_per_exec = 0;
- break;
-
- case 'l':
- if (optarg)
- lines_per_exec = parse_num (optarg, 'l', 1L, -1L);
- else
- lines_per_exec = 1;
- /* -l excludes -i -n. */
- args_per_exec = 0;
- replace_pat = NULL;
- break;
-
- case 'n':
- args_per_exec = parse_num (optarg, 'n', 1L, -1L);
- /* -n excludes -i -l. */
- lines_per_exec = 0;
- replace_pat = NULL;
- break;
-
- case 's':
- arg_max = parse_num (optarg, 's', 1L, orig_arg_max);
- break;
-
- case 't':
- print_command = true;
- break;
-
- case 'x':
- exit_if_size_exceeded = true;
- break;
-
- case 'p':
- query_before_executing = true;
- print_command = true;
- break;
-
- case 'r':
- always_run_command = 0;
- break;
-
- case 'P':
- proc_max = parse_num (optarg, 'P', 0L, -1L);
- break;
-
- default:
- usage (xargs_usage);