/* Command Executions
*****************************************************************************/
bool exec_reap(void);
-void exec_job(char** cmd, char* data, size_t ndata, View* dest, void (*donefn)(int));
+void exec_job(char** cmd, char* data, size_t ndata, View* dest);
int exec_cmd(char** cmd, char* text, char** out, char** err);
int exec_spawn(char** cmd, int* in, int* out);
Rcvr err_rcvr; /* reciever for the error output of the job */
Rcvr out_rcvr; /* receiver for the normal output of the job */
View* dest; /* destination view where output will be placed */
- void (*donefn)(int); /* function called with return status of the job */
};
static Job* JobList = NULL;
rcvr_finish(&(job->out_rcvr));
rcvr_finish(&(job->err_rcvr));
waitpid(job->proc.pid, &status, WNOHANG);
- if (job->donefn) job->donefn(status);
job = job_finish(job);
} else {
job = job->next;
return (JobList != NULL);
}
-void exec_job(char** cmd, char* data, size_t ndata, View* dest, void (*donefn)(int)) {
+void exec_job(char** cmd, char* data, size_t ndata, View* dest) {
Job* job = calloc(1, sizeof(Job));
job->proc.pid = execute(cmd, &(job->proc));
if (job->proc.pid < 0) {
job->nwrite = 0;
job->data = data;
job->next = JobList;
- job->donefn = donefn;
if (JobList) JobList->prev = job;
JobList = job;
/* register watch events for file descriptors */
close(inpipe[PIPE_READ]);
close(outpipe[PIPE_WRITE]);
close(errpipe[PIPE_WRITE]);
- proc->in = inpipe[PIPE_WRITE];
- proc->out = outpipe[PIPE_READ];
- proc->err = errpipe[PIPE_READ];
+ proc->in = inpipe[PIPE_WRITE];
+ proc->out = outpipe[PIPE_READ];
+ proc->err = errpipe[PIPE_READ];
}
return proc->pid;
}
if (Selections[CLIPBOARD].text) {
char* text = Selections[CLIPBOARD].text;
size_t len = strlen(text);
- exec_job((char*[]){ "xcpd", NULL }, text, len, NULL, NULL);
+ exec_job((char*[]){ "xcpd", NULL }, text, len, NULL);
while (event_poll(100));
}
}
/* execute the job */
if (op == '!')
- free(input), exec_job(execcmd, NULL, 0, NULL, NULL);
+ free(input), exec_job(execcmd, NULL, 0, NULL);
else if (op == '>')
- exec_job(execcmd, input, len, tags, NULL);
+ exec_job(execcmd, input, len, tags);
else if (op == '|' || op == ':')
- exec_job(execcmd, input, len, edit, NULL);
+ exec_job(execcmd, input, len, edit);
else
- exec_job(execcmd, input, len, (op != '<' ? curr : edit), NULL);
+ exec_job(execcmd, input, len, (op != '<' ? curr : edit));
}
static void cmd_execwitharg(char* cmd, char* arg) {