- /* 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;) {
- char *tmp;
- opt = strlen(in_from_stdin);
- len = opt + len_args_from_cmdline;
- len_cmd_to_be_executed+=len+3;
- cmd_to_be_executed=xrealloc(cmd_to_be_executed, len_cmd_to_be_executed);
-
- /* Strip out the final \n */
- in_from_stdin[opt-1]=' ';
-
- /* Replace any tabs with spaces */
- while( (tmp = strchr(in_from_stdin, '\t')) != NULL )
- *tmp=' ';
-
- /* Strip out any extra intra-word spaces */
- while( (tmp = strstr(in_from_stdin, " ")) != NULL ) {
- opt = strlen(in_from_stdin);
- memmove(tmp, tmp+1, opt-(tmp-in_from_stdin));
+ /* 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 = get_line_from_file(stdin)) !=NULL) {
+
+ FILE *cmd_output = NULL;
+ char *output_line = NULL;
+ char *execstr = NULL;
+
+ /* eat the newline off the filename. */
+ if (file_to_act_on[strlen(file_to_act_on)-1] == '\n')
+ file_to_act_on[strlen(file_to_act_on)-1] = '\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);