- while (gets(inlin) != NULL) {
- inlen = strlen(inlin);
- if (maxlin <= (outlen + inlen)) {
- if (outlen == startlen) {
- fprintf(stderr, "%s: Line length too short to process '%s'\n",
- av[0], inlin);
- exit(3);
- }
- if (ending) strcat(outlin, ending);
- if (traceflag) fputs(outlin,stderr);
- errno = 0;
- if (0 != system(outlin)) {
- if (errno != 0) perror("xargs");
- exit(1);
- }
- strcpy(outlin, startlin);
- outlen = startlen;
- }
- strcat(outlin, inlin);
- strcat(outlin, " ");
- outlen = outlen + inlen + 1;
- }
- if (outlen != startlen) {
- if (ending) strcat(outlin, ending);
- if (traceflag) fputs(outlin,stderr);
- errno = 0;
- if (0 != system(outlin)) {
- if (errno != 0) perror("xargs");
- exit(1);
- }
- }
- return 0;
+ /* eat blank lines */
+ if (strlen(file_to_act_on) == 0)
+ continue;
+
+ /* assemble the command and execute it */
+ execstr = xcalloc(strlen(cmd_to_be_executed) +
+ strlen(file_to_act_on) + 1, sizeof(char));
+ strcat(execstr, cmd_to_be_executed);
+ strcat(execstr, file_to_act_on);
+ cmd_output = popen(execstr, "r");
+ if (cmd_output == NULL) {
+ perror("popen");
+ exit(1);
+ }
+
+ /* harvest the output */
+ while ((output_line = get_line_from_file(cmd_output)) != NULL) {
+ fputs(output_line, stdout);
+ free(output_line);
+ }
+
+ /* clean up */
+ pclose(cmd_output);
+ free(execstr);
+ free(file_to_act_on);
+ }
+
+#ifdef BB_FEATURE_CLEAN_UP
+ free(cmd_to_be_executed);
+#endif
+
+ return 0;