Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Add jobdirs association to parameter module (again)
- X-seq: zsh-workers 9008
- From: Felix Rosencrantz <f_rosencrantz@xxxxxxxxx>
- To: zsh-workers <zsh-workers@xxxxxxxxxxxxxx>
- Subject: PATCH: Add jobdirs association to parameter module (again)
- Date: Sun, 12 Dec 1999 22:47:26 -0800 (PST)
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
(Sorry, the patch got messed up, I'll try it as an attachment.)
This proposed patch adds a new association to the parameter module
called jobdirs. This provides an association with job numbers and the
directories in which the jobs were started.
I decided to use the name jobdirs instead of jobpwds since the "jobs"
builtin uses the "-d" to list these directories. Though I could see
that jobpwds might also be appropriate.
It is possible to use the "jobs -d" command to get this same
information with a little processing. Though adding an association
seems to be a cleaner way for zsh functions or scripts to get this
information.
-FR
__________________________________________________
Do You Yahoo!?
Thousands of Stores. Millions of Products. All in one place.
Yahoo! Shopping: http://shopping.yahoo.com
--- old/Src/Modules/parameter.c Mon Dec 6 02:26:32 1999
+++ Src/Modules/parameter.c Sun Dec 12 20:58:25 1999
@@ -1325,6 +1325,83 @@
}
}
+/* Functions for the jobdirs special parameter. */
+
+/**/
+static char *
+pmjobdir(int job)
+{
+ char *ret;
+
+ ret = dupstring(jobtab[job].pwd);
+ return ret;
+}
+
+/**/
+static HashNode
+getpmjobdir(HashTable ht, char *name)
+{
+ Param pm = NULL;
+ int job;
+
+ HEAPALLOC {
+ pm = (Param) zhalloc(sizeof(struct param));
+ pm->nam = dupstring(name);
+ pm->flags = PM_SCALAR | PM_READONLY;
+ pm->sets.cfn = NULL;
+ pm->gets.cfn = strgetfn;
+ pm->unsetfn = NULL;
+ pm->ct = 0;
+ pm->env = NULL;
+ pm->ename = NULL;
+ pm->old = NULL;
+ pm->level = 0;
+
+ if ((job = atoi(name)) >= 1 && job < MAXJOB &&
+ jobtab[job].stat && jobtab[job].procs &&
+ !(jobtab[job].stat & STAT_NOPRINT))
+ pm->u.str = pmjobdir(job);
+ else {
+ pm->u.str = dupstring("");
+ pm->flags |= PM_UNSET;
+ }
+ } LASTALLOC;
+
+ return (HashNode) pm;
+}
+
+/**/
+static void
+scanpmjobdirs(HashTable ht, ScanFunc func, int flags)
+{
+ struct param pm;
+ int job;
+ char buf[40];
+
+ pm.flags = PM_SCALAR | PM_READONLY;
+ pm.sets.cfn = NULL;
+ pm.gets.cfn = strgetfn;
+ pm.unsetfn = NULL;
+ pm.ct = 0;
+ pm.env = NULL;
+ pm.ename = NULL;
+ pm.old = NULL;
+ pm.level = 0;
+
+ for (job = 1; job < MAXJOB; job++) {
+ if (jobtab[job].stat && jobtab[job].procs &&
+ !(jobtab[job].stat & STAT_NOPRINT)) {
+ sprintf(buf, "%d", job);
+ pm.nam = dupstring(buf);
+ if (func != scancountparams &&
+ ((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) ||
+ !(flags & SCANPM_WANTKEYS)))
+ pm.u.str = pmjobdir(job);
+ func((HashNode) &pm, flags);
+ }
+ }
+}
+
/* Functions for the nameddirs special parameter. */
/**/
@@ -1833,6 +1910,9 @@
{ "jobstates", PM_READONLY,
getpmjobstate, scanpmjobstates, hashsetfn,
NULL, NULL, stdunsetfn, NULL },
+ { "jobdirs", PM_READONLY,
+ getpmjobdir, scanpmjobdirs, hashsetfn,
+ NULL, NULL, stdunsetfn, NULL },
{ "nameddirs", 0,
getpmnameddir, scanpmnameddirs, setpmnameddirs,
NULL, NULL, stdunsetfn, NULL },
@@ -1889,8 +1969,7 @@
if (def->hsetfn)
def->pm->sets.hfn = def->hsetfn;
} else {
- if (!(def->pm = createparam(def->name, def->flags | PM_HIDE |
- PM_REMOVABLE)))
+ if (!(def->pm = createparam(def->name, def->flags | PM_HIDE)))
return 1;
def->pm->sets.afn = def->setfn;
def->pm->gets.afn = def->getfn;
--- old/Src/Modules/parameter.mdd Wed Nov 3 03:07:27 1999
+++ Src/Modules/parameter.mdd Fri Dec 10 11:34:25 1999
@@ -1,3 +1,3 @@
-autoparams="parameters commands functions dis_functions funcstack builtins dis_builtins reswords dis_reswords options modules dirstack history historywords jobtexts jobstates nameddirs userdirs aliases dis_aliases galiases dis_galiases"
+autoparams="parameters commands functions dis_functions funcstack builtins dis_builtins reswords dis_reswords options modules dirstack history historywords jobtexts jobdirs jobstates nameddirs userdirs aliases dis_aliases galiases dis_galiases"
objects="parameter.o"
--- old/zsh/Doc/Zsh/mod_parameter.yo Wed Nov 3 03:07:19 1999
+++ Doc/Zsh/mod_parameter.yo Fri Dec 10 11:32:09 1999
@@ -110,6 +110,10 @@
item(tt(historywords))(
A special array containing the words stored in the history.
)
+vindex(jobdirs)
+item(tt(jobdirs))(
+This association maps job numbers to the directories from which the job was started (which may not be the current directory of the job).
+)
vindex(jobtexts)
item(tt(jobtexts))(
This association maps job numbers to the texts of the command lines
Messages sorted by:
Reverse Date,
Date,
Thread,
Author