about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--Doc/Zsh/mod_parameter.yo11
-rw-r--r--Src/Modules/parameter.c19
-rw-r--r--Src/jobs.c18
-rw-r--r--Src/utils.c2
5 files changed, 43 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 869f70429..593b053de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/Doc/Zsh/mod_parameter.yo b/Doc/Zsh/mod_parameter.yo
index 529c65d33..434397fbf 100644
--- a/Doc/Zsh/mod_parameter.yo
+++ b/Doc/Zsh/mod_parameter.yo
@@ -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))(
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++;