From: Michael D. Lowis Date: Mon, 7 May 2018 03:05:26 +0000 (-0400) Subject: minor refactoring X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=e1a236f95f1032edd749ae097568e24913e6555e;p=projs%2Ftide.git minor refactoring --- diff --git a/lib/job.c b/lib/job.c index b8c7ea6..eda71bf 100644 --- a/lib/job.c +++ b/lib/job.c @@ -9,7 +9,6 @@ #include #include -static void job_process(int fd, int events); static int job_execute(char** cmd, int *fd, int *pid); static void job_finish(Job* job); @@ -18,6 +17,25 @@ static void job_finish(Job* job); static struct pollfd JobFds[MAX_JOBS]; static Job* JobList = NULL; +static void job_process(int fd, int events) { + Job* job = JobList; // Get job by fd + while (job && job->fd != fd) + job = job->next; + if (!job) return; + if (job->readfn && (events & POLLIN)) + job->readfn(job); + if (job->writefn && (events & POLLOUT)) + job->writefn(job); + if (!job->readfn && !job->writefn) + job_finish(job); +} + +static void job_finish(Job* job) { + //close(job->fd); + // delete job + // free(job); +} + bool job_poll(int ms) { int njobs = 0; /* Add jobs from the job list */ @@ -48,33 +66,15 @@ void job_spawn(int fd, jobfn_t readfn, jobfn_t writefn, void* data) { JobList = job; } -void job_create(char** cmd, jobfn_t readfn, jobfn_t writefn, void* data) { - int fd = -1, pid = -1; - if (job_execute(cmd, &fd, &pid) > 0) - job_spawn(fd, readfn, writefn, data); -} - void job_start(char** cmd, char* data, size_t ndata, View* dest) { } -static void job_process(int fd, int events) { - Job* job = JobList; // Get job by fd - while (job && job->fd != fd) - job = job->next; - if (!job) return; - if (job->readfn && (events & POLLIN)) - job->readfn(job); - if (job->writefn && (events & POLLOUT)) - job->writefn(job); - if (!job->readfn && !job->writefn) - job_finish(job); -} - -static void job_finish(Job* job) { - //close(job->fd); - // delete job - // free(job); +#if 0 +void job_create(char** cmd, jobfn_t readfn, jobfn_t writefn, void* data) { + int fd = -1, pid = -1; + if (job_execute(cmd, &fd, &pid) > 0) + job_spawn(fd, readfn, writefn, data); } static int job_execute(char** cmd, int *fd, int *pid) { @@ -99,3 +99,4 @@ static int job_execute(char** cmd, int *fd, int *pid) { } return *pid; } +#endif diff --git a/tide.c b/tide.c index 33725ee..9795c74 100644 --- a/tide.c +++ b/tide.c @@ -56,8 +56,7 @@ static void tag_exec(Tag* tag, char* arg) { static void cmd_exec(char* cmd) { /* parse the command sigils */ char op = '\0', **execcmd = NULL; - if (*cmd == ':' || *cmd == '!' || *cmd == '<' || *cmd == '|' || *cmd == '>') - op = *cmd, cmd++; + if (rissigil(*cmd)) op = *(cmd++); execcmd = (op == ':' ? SedCmd : ShellCmd); execcmd[2] = cmd; @@ -65,7 +64,7 @@ static void cmd_exec(char* cmd) { if (op && op != '<' && op != '!' && !view_selsize(win_view(EDIT))) view_selectall(win_view(EDIT)); char* input = view_getstr(win_view(EDIT)); - size_t len = (input ? strlen(input) : 0); + size_t len = (input ? strlen(input) : 0); View *tags = win_view(TAGS), *edit = win_view(EDIT), *curr = win_view(FOCUSED); /* execute the job */