1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-11 13:01:28 +02:00

users/11818: allow non-numeric keys for job status parameters

This commit is contained in:
Peter Stephenson 2007-09-05 16:16:15 +00:00
parent 8cfe028631
commit f5a6b2a8c9
5 changed files with 43 additions and 11 deletions

View file

@ -1,5 +1,9 @@
2007-09-05 Peter Stephenson <pws@csr.com> 2007-09-05 Peter Stephenson <pws@csr.com>
* users/11818: Doc/Zsh/mod_parameter.yo, Src/jobs.c, Src/utils.c,
Src/Modules/parameter.c: Allow non-numeric lookup of job
status parameters.
* unposted: Functions/Calendar/calendar: make sure there's a * unposted: Functions/Calendar/calendar: make sure there's a
space between a date of a recurring event and the rest of space between a date of a recurring event and the rest of
the line. the line.

View file

@ -124,11 +124,19 @@ vindex(jobdirs)
item(tt(jobdirs))( item(tt(jobdirs))(
This associative array maps job numbers to the directories from which the This associative array maps job numbers to the directories from which the
job was started (which may not be the current directory of the job). job was started (which may not be the current directory of the job).
The keys of the associative arrays are usually valid job numbers,
and these are the values output with, for example, tt(${(k)jobdirs}).
Non-numeric job references may be used when looking up a value;
for example, tt(${jobdirs[%+]}) refers to the current job.
) )
vindex(jobtexts) vindex(jobtexts)
item(tt(jobtexts))( item(tt(jobtexts))(
This associative array maps job numbers to the texts of the command lines This associative array maps job numbers to the texts of the command lines
that were used to start the jobs. that were used to start the jobs.
Handling of the keys of the associative array is as described for
tt(jobdirs) above.
) )
vindex(jobstates) vindex(jobstates)
item(tt(jobstates))( item(tt(jobstates))(
@ -142,6 +150,9 @@ var(job-state) gives the state the whole job is currently in, one of
otherwise. This is followed by one `var(pid)tt(=)var(state)' for every otherwise. This is followed by one `var(pid)tt(=)var(state)' for every
process in the job. The var(pid)s are, of course, the process IDs and process in the job. The var(pid)s are, of course, the process IDs and
the var(state) describes the state of that process. the var(state) describes the state of that process.
Handling of the keys of the associative array is as described for
tt(jobdirs) above.
) )
vindex(nameddirs) vindex(nameddirs)
item(tt(nameddirs))( item(tt(nameddirs))(

View file

@ -1007,13 +1007,18 @@ getpmjobtext(UNUSED(HashTable ht), const char *name)
{ {
Param pm = NULL; Param pm = NULL;
int job; int job;
char *pend;
pm = (Param) hcalloc(sizeof(struct param)); pm = (Param) hcalloc(sizeof(struct param));
pm->node.nam = dupstring(name); pm->node.nam = dupstring(name);
pm->node.flags = PM_SCALAR | PM_READONLY; pm->node.flags = PM_SCALAR | PM_READONLY;
pm->gsu.s = &nullsetscalar_gsu; 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 && jobtab[job].procs &&
!(jobtab[job].stat & STAT_NOPRINT)) !(jobtab[job].stat & STAT_NOPRINT))
pm->u.str = pmjobtext(job); pm->u.str = pmjobtext(job);
@ -1104,13 +1109,17 @@ getpmjobstate(UNUSED(HashTable ht), const char *name)
{ {
Param pm = NULL; Param pm = NULL;
int job; int job;
char *pend;
pm = (Param) hcalloc(sizeof(struct param)); pm = (Param) hcalloc(sizeof(struct param));
pm->node.nam = dupstring(name); pm->node.nam = dupstring(name);
pm->node.flags = PM_SCALAR | PM_READONLY; pm->node.flags = PM_SCALAR | PM_READONLY;
pm->gsu.s = &nullsetscalar_gsu; 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 && jobtab[job].procs &&
!(jobtab[job].stat & STAT_NOPRINT)) !(jobtab[job].stat & STAT_NOPRINT))
pm->u.str = pmjobstate(job); pm->u.str = pmjobstate(job);
@ -1166,13 +1175,17 @@ getpmjobdir(UNUSED(HashTable ht), const char *name)
{ {
Param pm = NULL; Param pm = NULL;
int job; int job;
char *pend;
pm = (Param) hcalloc(sizeof(struct param)); pm = (Param) hcalloc(sizeof(struct param));
pm->node.nam = dupstring(name); pm->node.nam = dupstring(name);
pm->node.flags = PM_SCALAR | PM_READONLY; pm->node.flags = PM_SCALAR | PM_READONLY;
pm->gsu.s = &nullsetscalar_gsu; 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 && jobtab[job].procs &&
!(jobtab[job].stat & STAT_NOPRINT)) !(jobtab[job].stat & STAT_NOPRINT))
pm->u.str = pmjobdir(job); pm->u.str = pmjobdir(job);

View file

@ -1468,8 +1468,8 @@ setcurjob(void)
* to a job number. */ * to a job number. */
/**/ /**/
static int mod_export int
getjob(char *s, char *prog) getjob(const char *s, const char *prog)
{ {
int jobnum, returnval, mymaxjob; int jobnum, returnval, mymaxjob;
Job myjobtab; Job myjobtab;
@ -1489,7 +1489,8 @@ getjob(char *s, char *prog)
/* "%%", "%+" and "%" all represent the current job */ /* "%%", "%+" and "%" all represent the current job */
if (*s == '%' || *s == '+' || !*s) { if (*s == '%' || *s == '+' || !*s) {
if (curjob == -1) { if (curjob == -1) {
zwarnnam(prog, "no current job"); if (prog)
zwarnnam(prog, "no current job");
returnval = -1; returnval = -1;
goto done; goto done;
} }
@ -1499,7 +1500,8 @@ getjob(char *s, char *prog)
/* "%-" represents the previous job */ /* "%-" represents the previous job */
if (*s == '-') { if (*s == '-') {
if (prevjob == -1) { if (prevjob == -1) {
zwarnnam(prog, "no previous job"); if (prog)
zwarnnam(prog, "no previous job");
returnval = -1; returnval = -1;
goto done; goto done;
} }
@ -1521,7 +1523,8 @@ getjob(char *s, char *prog)
returnval = jobnum; returnval = jobnum;
goto done; goto done;
} }
zwarnnam(prog, "%%%s: no such job", s); if (prog)
zwarnnam(prog, "%%%s: no such job", s);
returnval = -1; returnval = -1;
goto done; goto done;
} }
@ -1538,7 +1541,8 @@ getjob(char *s, char *prog)
returnval = jobnum; returnval = jobnum;
goto done; goto done;
} }
zwarnnam(prog, "job not found: %s", s); if (prog)
zwarnnam(prog, "job not found: %s", s);
returnval = -1; returnval = -1;
goto done; goto done;
} }
@ -2299,7 +2303,7 @@ bin_suspend(char *name, UNUSED(char **argv), Options ops, UNUSED(int func))
/**/ /**/
int int
findjobnam(char *s) findjobnam(const char *s)
{ {
int jobnum; int jobnum;

View file

@ -5017,7 +5017,7 @@ getkeystring(char *s, int *len, int how, int *misc)
/**/ /**/
mod_export int mod_export int
strpfx(char *s, char *t) strpfx(const char *s, const char *t)
{ {
while (*s && *s == *t) while (*s && *s == *t)
s++, t++; s++, t++;