summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2004-01-22 17:51:05 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2004-01-22 17:51:05 +0000
commite461877f4063348b5c02aae691367c3cb155eeb7 (patch)
tree6298a06dda2f1ae870052d6a07f4713b7a85db4d
parent63b336243fdf5e60058472fa456ed11e75280189 (diff)
downloadzsh-e461877f4063348b5c02aae691367c3cb155eeb7.tar.gz
zsh-e461877f4063348b5c02aae691367c3cb155eeb7.zip
19389+: fix zmodload -u zsh/datetime, add strftime -s scalar
-rw-r--r--ChangeLog7
-rw-r--r--Doc/Zsh/mod_datetime.yo5
-rw-r--r--Src/Modules/datetime.c27
3 files changed, 34 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index fe8a15206..93190cf0b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-01-22 Peter Stephenson <pws@csr.com>
+
+ * 19389 plus added stdunsetfn to EPOCHSECONDS:
+ Src/Modules/datetime.c, Doc/Zsh/mod_datetime.yo: add -s scalar
+ option to strftime, remove EPOCHSECONDS cleanly when module
+ unloaded.
+
2004-01-21 Oliver Kiddle <opk@zsh.org>
* 19387: Completion/...: add (-.) glob qualifiers to many globs
diff --git a/Doc/Zsh/mod_datetime.yo b/Doc/Zsh/mod_datetime.yo
index cf5ca4379..b006baf89 100644
--- a/Doc/Zsh/mod_datetime.yo
+++ b/Doc/Zsh/mod_datetime.yo
@@ -6,9 +6,12 @@ The tt(zsh/datetime) module makes available one builtin command:
startitem()
findex(strftime)
cindex(date string, printing)
-item(tt(strftime) var(format) var(epochtime) )(
+item(tt(strftime) [ tt(-s) var(scalar) ] var(format) var(epochtime) )(
Output the date denoted by var(epochtime) in the var(format)
specified.
+
+If tt(-s) var(scalar) is given, assign the date to var(scalar) instead
+of printing it.
)
enditem()
diff --git a/Src/Modules/datetime.c b/Src/Modules/datetime.c
index b80f6e3c6..5877b8490 100644
--- a/Src/Modules/datetime.c
+++ b/Src/Modules/datetime.c
@@ -35,10 +35,18 @@ static int
bin_strftime(char *nam, char **argv, Options ops, int func)
{
int bufsize, x;
- char *endptr = NULL, *buffer;
+ char *endptr = NULL, *scalar = NULL, *buffer;
time_t secs;
struct tm *t;
+ if (OPT_ISSET(ops,'s')) {
+ scalar = OPT_ARG(ops, 's');
+ if (!isident(scalar)) {
+ zwarnnam(nam, "not an identifier: %s", scalar, 0);
+ return 1;
+ }
+ }
+
secs = (time_t)strtoul(argv[1], &endptr, 10);
if (secs == ULONG_MAX) {
zwarnnam(nam, "%s: %e", argv[1], errno);
@@ -58,7 +66,11 @@ bin_strftime(char *nam, char **argv, Options ops, int func)
buffer = zrealloc(buffer, bufsize *= 2);
}
- printf("%s\n", buffer);
+ if (scalar) {
+ setsparam(scalar, ztrdup(buffer));
+ } else {
+ printf("%s\n", buffer);
+ }
zfree(buffer, bufsize);
return 0;
@@ -71,12 +83,12 @@ getcurrentsecs()
}
static struct builtin bintab[] = {
- BUILTIN("strftime", 0, bin_strftime, 2, 2, 0, NULL, NULL),
+ BUILTIN("strftime", 0, bin_strftime, 2, 2, 0, "s:", NULL),
};
static struct paramdef patab[] = {
PARAMDEF("EPOCHSECONDS", PM_INTEGER|PM_SPECIAL|PM_READONLY,
- NULL, NULL, &getcurrentsecs, NULL),
+ NULL, NULL, &getcurrentsecs, stdunsetfn),
};
/**/
@@ -99,7 +111,14 @@ boot_(Module m)
int
cleanup_(Module m)
{
+ Param pm;
+
deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
+ pm = (Param) paramtab->getnode(paramtab, "EPOCHSECONDS");
+ if (pm && (pm->flags & PM_SPECIAL)) {
+ pm->flags &= ~PM_READONLY;
+ unsetparam_pm(pm, 0, 1);
+ }
return 0;
}