From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15155 invoked from network); 30 Apr 2002 18:53:48 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 30 Apr 2002 18:53:48 -0000 Received: (qmail 14869 invoked by alias); 30 Apr 2002 18:53:39 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 17058 Received: (qmail 14853 invoked from network); 30 Apr 2002 18:53:37 -0000 Date: Tue, 30 Apr 2002 14:52:59 -0400 From: Clint Adams To: zsh-workers@sunsite.dk Subject: PATCH: strftime builtin Message-ID: <20020430185259.GA2825@dman.com> References: <20020219020611.GA15770@dman.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020219020611.GA15770@dman.com> User-Agent: Mutt/1.3.28i > 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 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"