mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-01 17:24:50 +01:00
users/11818: allow non-numeric keys for job status parameters
This commit is contained in:
parent
8cfe028631
commit
f5a6b2a8c9
5 changed files with 43 additions and 11 deletions
|
@ -1,5 +1,9 @@
|
|||
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
|
||||
space between a date of a recurring event and the rest of
|
||||
the line.
|
||||
|
|
|
@ -124,11 +124,19 @@ vindex(jobdirs)
|
|||
item(tt(jobdirs))(
|
||||
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).
|
||||
|
||||
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)
|
||||
item(tt(jobtexts))(
|
||||
This associative array maps job numbers to the texts of the command lines
|
||||
that were used to start the jobs.
|
||||
|
||||
Handling of the keys of the associative array is as described for
|
||||
tt(jobdirs) above.
|
||||
)
|
||||
vindex(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
|
||||
process in the job. The var(pid)s are, of course, the process IDs and
|
||||
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)
|
||||
item(tt(nameddirs))(
|
||||
|
|
|
@ -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);
|
||||
|
|
18
Src/jobs.c
18
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;
|
||||
|
||||
|
|
|
@ -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++;
|
||||
|
|
Loading…
Reference in a new issue