diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2007-09-05 16:16:15 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2007-09-05 16:16:15 +0000 |
commit | f5a6b2a8c93a4f30e32f59280d91c7495b6879ef (patch) | |
tree | c00a4f9974e2a5197e8aa268d1b926fbf81096d9 /Src | |
parent | 8cfe028631f509b2a9ecb8dddc2ab435dd6e5b59 (diff) | |
download | zsh-f5a6b2a8c93a4f30e32f59280d91c7495b6879ef.tar.gz zsh-f5a6b2a8c93a4f30e32f59280d91c7495b6879ef.tar.xz zsh-f5a6b2a8c93a4f30e32f59280d91c7495b6879ef.zip |
users/11818: allow non-numeric keys for job status parameters
Diffstat (limited to 'Src')
-rw-r--r-- | Src/Modules/parameter.c | 19 | ||||
-rw-r--r-- | Src/jobs.c | 18 | ||||
-rw-r--r-- | Src/utils.c | 2 |
3 files changed, 28 insertions, 11 deletions
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c index 3c7264a09..efb22fafd 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -1007,13 +1007,18 @@ getpmjobtext(UNUSED(HashTable ht), const char *name) { Param pm = NULL; int job; + char *pend; pm = (Param) hcalloc(sizeof(struct param)); pm->node.nam = dupstring(name); pm->node.flags = PM_SCALAR | PM_READONLY; pm->gsu.s = &nullsetscalar_gsu; - if ((job = atoi(name)) >= 1 && job <= maxjob && + job = strtod(name, &pend); + /* Non-numeric keys are looked up by job name */ + if (*pend) + job = getjob(name, NULL); + if (job >= 1 && job <= maxjob && jobtab[job].stat && jobtab[job].procs && !(jobtab[job].stat & STAT_NOPRINT)) pm->u.str = pmjobtext(job); @@ -1104,13 +1109,17 @@ getpmjobstate(UNUSED(HashTable ht), const char *name) { Param pm = NULL; int job; + char *pend; pm = (Param) hcalloc(sizeof(struct param)); pm->node.nam = dupstring(name); pm->node.flags = PM_SCALAR | PM_READONLY; pm->gsu.s = &nullsetscalar_gsu; - if ((job = atoi(name)) >= 1 && job <= maxjob && + job = strtod(name, &pend); + if (*pend) + job = getjob(name, NULL); + if (job >= 1 && job <= maxjob && jobtab[job].stat && jobtab[job].procs && !(jobtab[job].stat & STAT_NOPRINT)) pm->u.str = pmjobstate(job); @@ -1166,13 +1175,17 @@ getpmjobdir(UNUSED(HashTable ht), const char *name) { Param pm = NULL; int job; + char *pend; pm = (Param) hcalloc(sizeof(struct param)); pm->node.nam = dupstring(name); pm->node.flags = PM_SCALAR | PM_READONLY; pm->gsu.s = &nullsetscalar_gsu; - if ((job = atoi(name)) >= 1 && job <= maxjob && + job = strtod(name, &pend); + if (*pend) + job = getjob(name, NULL); + if (job >= 1 && job <= maxjob && jobtab[job].stat && jobtab[job].procs && !(jobtab[job].stat & STAT_NOPRINT)) pm->u.str = pmjobdir(job); diff --git a/Src/jobs.c b/Src/jobs.c index e50a235f3..95acf8eb1 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -1468,8 +1468,8 @@ setcurjob(void) * to a job number. */ /**/ -static int -getjob(char *s, char *prog) +mod_export int +getjob(const char *s, const char *prog) { int jobnum, returnval, mymaxjob; Job myjobtab; @@ -1489,7 +1489,8 @@ getjob(char *s, char *prog) /* "%%", "%+" and "%" all represent the current job */ if (*s == '%' || *s == '+' || !*s) { if (curjob == -1) { - zwarnnam(prog, "no current job"); + if (prog) + zwarnnam(prog, "no current job"); returnval = -1; goto done; } @@ -1499,7 +1500,8 @@ getjob(char *s, char *prog) /* "%-" represents the previous job */ if (*s == '-') { if (prevjob == -1) { - zwarnnam(prog, "no previous job"); + if (prog) + zwarnnam(prog, "no previous job"); returnval = -1; goto done; } @@ -1521,7 +1523,8 @@ getjob(char *s, char *prog) returnval = jobnum; goto done; } - zwarnnam(prog, "%%%s: no such job", s); + if (prog) + zwarnnam(prog, "%%%s: no such job", s); returnval = -1; goto done; } @@ -1538,7 +1541,8 @@ getjob(char *s, char *prog) returnval = jobnum; goto done; } - zwarnnam(prog, "job not found: %s", s); + if (prog) + zwarnnam(prog, "job not found: %s", s); returnval = -1; goto done; } @@ -2299,7 +2303,7 @@ bin_suspend(char *name, UNUSED(char **argv), Options ops, UNUSED(int func)) /**/ int -findjobnam(char *s) +findjobnam(const char *s) { int jobnum; diff --git a/Src/utils.c b/Src/utils.c index c0081f8e1..bc04c3ec6 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -5017,7 +5017,7 @@ getkeystring(char *s, int *len, int how, int *misc) /**/ mod_export int -strpfx(char *s, char *t) +strpfx(const char *s, const char *t) { while (*s && *s == *t) s++, t++; |