diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2007-06-12 22:01:37 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2007-06-12 22:01:37 +0000 |
commit | 505675f2bd03149b189b31a76bc319de379d0e91 (patch) | |
tree | 7d55558af9e00308e10e3349efafa0df9fca0709 | |
parent | f9e374d43151eb96f626adc1b79d6616aaf52e55 (diff) | |
download | zsh-505675f2bd03149b189b31a76bc319de379d0e91.tar.gz zsh-505675f2bd03149b189b31a76bc319de379d0e91.tar.xz zsh-505675f2bd03149b189b31a76bc319de379d0e91.zip |
23554: add $zsh_scheduled_events
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | Doc/Zsh/mod_sched.yo | 19 | ||||
-rw-r--r-- | Doc/Zsh/params.yo | 4 | ||||
-rw-r--r-- | Src/Builtins/sched.c | 83 | ||||
-rw-r--r-- | Src/Builtins/sched.mdd | 1 |
5 files changed, 96 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog index 2a3134595..a40124fe6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,13 @@ +2007-06-12 Peter Stephenson <p.w.stephenson@ntlworld.com> + + * 23554: Doc/Zsh/mod_sched.yo, Doc/Zsh/params.yo, + Src/Builtins/sched.c, Src/Builtins/sched.mdd: + add $zsh_scheduled_events. + 2007-06-12 Clint Adams <clint@zsh.org> * unposted: Completion/Unix/Command/_pkg-config, - Completion/Unix/Command/_unexpand: remove RCS $Id: ChangeLog,v 1.3546 2007/06/12 17:02:38 clint Exp $ + Completion/Unix/Command/_unexpand: remove RCS $Id: ChangeLog,v 1.3547 2007/06/12 22:01:37 pws Exp $ comments. 2007-06-12 Peter Stephenson <pws@csr.com> diff --git a/Doc/Zsh/mod_sched.yo b/Doc/Zsh/mod_sched.yo index 87ee9064c..0e9075841 100644 --- a/Doc/Zsh/mod_sched.yo +++ b/Doc/Zsh/mod_sched.yo @@ -1,7 +1,8 @@ COMMENT(!MOD!zsh/sched A builtin that provides a timed execution facility within the shell. !MOD!) -The tt(zsh/sched) module makes available one builtin command: +The tt(zsh/sched) module makes available one builtin command and one +parameter. startitem() findex(sched) @@ -40,3 +41,19 @@ visible output to the terminal; it is not needed, for example, with output that updates a terminal emulator's title bar. ) enditem() + +startitem() +vindex(zsh_scheduled_events) +item(zsh_scheduled_events)( +A readonly array corresponding to the events scheduled by the +tt(sched) builtin. The indices of the array correspond to the numbers +shown when tt(sched) is run with no arguments (provided that the +tt(KSH_ARRAYS) option is not set). The value of the +corresponding element is the same as the text shown to the right +of the index in the tt(sched) listing. + +The tt(sched) builtin should be used for manipulating the events. Note +that this will have an immediate effect on the contents of the array, +so that indices may become invalid. +) +enditem() diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index f839ec880..147c3a3ed 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -712,6 +712,10 @@ item(tt(ZSH_NAME))( Expands to the basename of the command used to invoke this instance of zsh. ) +item(tt(zsh_scheduled_events))( +See ifzman(the section `The zsh/sched Module' in zmanref(zshmodules))\ +ifnzman(noderef(The zsh/sched Module)). +) vindex(ZSH_VERSION) item(tt(ZSH_VERSION))( The version number of this zsh. diff --git a/Src/Builtins/sched.c b/Src/Builtins/sched.c index 8a26b47f3..1c7c0341f 100644 --- a/Src/Builtins/sched.c +++ b/Src/Builtins/sched.c @@ -145,6 +145,40 @@ checksched(void) } } +/* + * Format event sch. If sn is zero, allocate string on the heap + * and return it; if non-zero, print with that as scheduled event + * number. + */ + +static +char *schedtext(struct schedcmd *sch, int sn) +{ + char *str, tbuf[40], *flagstr, *endstr; + time_t t; + struct tm *tmp; + + t = sch->time; + tmp = localtime(&t); + ztrftime(tbuf, 20, "%a %b %e %k:%M;%S", tmp); + if (sch->flags & SCHEDFLAG_TRASH_ZLE) + flagstr = "-o "; + else + flagstr = ""; + if (*sch->cmd == '-') + endstr = "-- "; + else + endstr = ""; + if (sn) { + printf("%3d %s %s%s%s\n", sn, tbuf, flagstr, endstr, sch->cmd); + return NULL; + } else { + str = (char *)zhalloc(48 + strlen(sch->cmd)); + sprintf(str, "%s %s%s%s", tbuf, flagstr, endstr, sch->cmd); + return str; + } +} + /**/ static int bin_sched(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func)) @@ -204,22 +238,8 @@ bin_sched(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func)) /* given no arguments, display the schedule list */ if (!*argptr) { - char tbuf[40], *flagstr, *endstr; - - for (sn = 1, sch = schedcmds; sch; sch = sch->next, sn++) { - t = sch->time; - tm = localtime(&t); - ztrftime(tbuf, 20, "%a %b %e %k:%M:%S", tm); - if (sch->flags & SCHEDFLAG_TRASH_ZLE) - flagstr = "-o "; - else - flagstr = ""; - if (*sch->cmd == '-') - endstr = "-- "; - else - endstr = ""; - printf("%3d %s %s%s%s\n", sn, tbuf, flagstr, endstr, sch->cmd); - } + for (sn = 1, sch = schedcmds; sch; sch = sch->next, sn++) + (void)schedtext(sch, 1); return 0; } else if (!argptr[1]) { /* other than the two cases above, sched * @@ -332,14 +352,43 @@ bin_sched(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func)) return 0; } + +/**/ +static char ** +schedgetfn(UNUSED(Param pm)) +{ + int i; + struct schedcmd *sch; + char **ret, **aptr; + + for (i = 0, sch = schedcmds; sch; sch = sch->next, i++) + ; + + aptr = ret = zhalloc(sizeof(char **) * (i+1)); + for (sch = schedcmds; sch; sch = sch->next, aptr++) + *aptr = schedtext(sch, 0); + *aptr = NULL; + + return ret; +} + + static struct builtin bintab[] = { BUILTIN("sched", 0, bin_sched, 0, -1, 0, NULL, NULL), }; +static const struct gsu_array sched_gsu = +{ schedgetfn, arrsetfn, stdunsetfn }; + +static struct paramdef partab[] = { + SPECIALPMDEF("zsh_scheduled_events", PM_ARRAY|PM_READONLY, + &sched_gsu, NULL, NULL) +}; + static struct features module_features = { bintab, sizeof(bintab)/sizeof(*bintab), NULL, 0, - NULL, 0, + partab, sizeof(partab)/sizeof(*partab), NULL, 0, 0 }; diff --git a/Src/Builtins/sched.mdd b/Src/Builtins/sched.mdd index 5fa22dddd..f440d6a19 100644 --- a/Src/Builtins/sched.mdd +++ b/Src/Builtins/sched.mdd @@ -3,5 +3,6 @@ link=either load=yes autobins="sched" +autoparams="zsh_scheduled_events" objects="sched.o" |