From: Clint Adams <clint@zsh.org>
To: zsh-workers@sunsite.dk
Subject: PATCH: strftime builtin
Date: Tue, 30 Apr 2002 14:52:59 -0400 [thread overview]
Message-ID: <20020430185259.GA2825@dman.com> (raw)
In-Reply-To: <20020219020611.GA15770@dman.com>
> The strftime formats are probably pretty useless without a strftime
> builtin.
This probably doesn't belong in the zsh/langinfo module.
Should it get its own module?
interim documentation: strftime format secs_since_epoch
Index: Src/Modules/langinfo.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/langinfo.c,v
retrieving revision 1.1
diff -u -r1.1 langinfo.c
--- Src/Modules/langinfo.c 19 Feb 2002 02:14:09 -0000 1.1
+++ Src/Modules/langinfo.c 30 Apr 2002 18:45:47 -0000
@@ -29,6 +29,7 @@
#include "langinfo.mdh"
#include "langinfo.pro"
+#include <time.h>
static char langinfo_nam[] = "langinfo";
@@ -513,6 +514,42 @@
/**/
#endif /* HAVE_NL_LANGINFO */
+static int
+bin_strftime(char *nam, char **argv, char *ops, int func)
+{
+ int ret = 0, bufsize, x;
+ char *endptr = NULL, *buffer = NULL;
+ time_t secs;
+ struct tm *t;
+ size_t size;
+
+ secs = (time_t)strtoul(argv[1], &endptr, 10);
+ if (secs == ULONG_MAX) {
+ zwarnnam(nam, "%s: %e", argv[1], errno);
+ return 1;
+ } else if (*endptr != '\0') {
+ zwarnnam(nam, "%s: invalid decimal number", argv[1], 0);
+ return 1;
+ }
+
+ t = localtime(&secs);
+ bufsize = strlen(argv[0]) * 2;
+
+ for (x=1;x<4;x++) {
+ buffer = zrealloc(buffer, bufsize * x);
+ size = strftime(buffer, bufsize * x, argv[0], t);
+ if (size) x = 4;
+ }
+
+ printf("%s\n", buffer);
+
+ return 0;
+}
+
+static struct builtin bintab[] = {
+ BUILTIN("strftime", 0, bin_strftime, 2, 2, 0, NULL, NULL),
+};
+
/**/
int
setup_(Module m)
@@ -530,7 +567,8 @@
#else
unsetparam(langinfo_nam);
#endif
- return 0;
+ return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
+/* return 0; */
}
/**/
@@ -546,6 +584,7 @@
unsetparam_pm(pm, 0, 1);
}
#endif
+ deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
return 0;
}
Index: Src/Modules/langinfo.mdd
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/langinfo.mdd,v
retrieving revision 1.1
diff -u -r1.1 langinfo.mdd
--- Src/Modules/langinfo.mdd 19 Feb 2002 02:14:09 -0000 1.1
+++ Src/Modules/langinfo.mdd 30 Apr 2002 18:45:47 -0000
@@ -4,5 +4,6 @@
load=no
autoparams="langinfo"
+autobins="strftime"
objects="langinfo.o"
next prev parent reply other threads:[~2002-04-30 18:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-02-19 2:06 PATCH: langinfo module Clint Adams
2002-04-30 18:52 ` Clint Adams [this message]
2002-05-01 9:38 ` PATCH: strftime builtin Peter Stephenson
2002-05-26 21:58 ` Clint Adams
2002-05-27 5:05 ` Borsenkow Andrej
[not found] ` <23146.1064741224@athlon>
2003-09-28 16:19 ` PATCH: $SECS Clint Adams
2003-09-28 17:30 ` Bart Schaefer
2003-09-28 18:05 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020430185259.GA2825@dman.com \
--to=clint@zsh.org \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).