summary refs log tree commit diff
path: root/Src
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 /Src
parent63b336243fdf5e60058472fa456ed11e75280189 (diff)
downloadzsh-e461877f4063348b5c02aae691367c3cb155eeb7.tar.gz
zsh-e461877f4063348b5c02aae691367c3cb155eeb7.tar.xz
zsh-e461877f4063348b5c02aae691367c3cb155eeb7.zip
19389+: fix zmodload -u zsh/datetime, add strftime -s scalar
Diffstat (limited to 'Src')
-rw-r--r--Src/Modules/datetime.c27
1 files changed, 23 insertions, 4 deletions
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;
 }