* PATCH: langinfo module
@ 2002-02-19 2:06 Clint Adams
2002-04-30 18:52 ` PATCH: strftime builtin Clint Adams
0 siblings, 1 reply; 8+ messages in thread
From: Clint Adams @ 2002-02-19 2:06 UTC (permalink / raw)
To: zsh-workers
With this, one can do $langinfo[MON_8] instead of
`date -d "01 August 2001" +%B` to get the localized
version of August, or
((i=8008)); printf "%d%s%d\n" $((i/1000)) $langinfo[THOUSEP] $((i % 1000))
to get the localized version of 8,008.
The strftime formats are probably pretty useless without a strftime
builtin.
It might be nice to have some way for read -q to use YESEXPR too.
Index: zshconfig.ac
===================================================================
RCS file: /cvsroot/zsh/zsh/zshconfig.ac,v
retrieving revision 1.24
diff -u -r1.24 zshconfig.ac
--- zshconfig.ac 20 Dec 2001 23:48:38 -0000 1.24
+++ zshconfig.ac 19 Feb 2002 01:41:28 -0000
@@ -487,7 +487,7 @@
limits.h fcntl.h libc.h sys/utsname.h sys/resource.h \
locale.h errno.h stdio.h stdlib.h unistd.h sys/capability.h \
utmp.h utmpx.h sys/types.h pwd.h grp.h poll.h sys/mman.h \
- netinet/in_systm.h pcre.h)
+ netinet/in_systm.h pcre.h langinfo.h)
if test $dynamic = yes; then
AC_CHECK_HEADERS(dlfcn.h)
AC_CHECK_HEADERS(dl.h)
@@ -950,6 +950,7 @@
pathconf sysconf \
tgetent tigetflag tigetnum tigetstr setupterm \
pcre_compile pcre_study pcre_exec \
+ nl_langinfo \
erand48)
AC_FUNC_STRCOLL
Index: Doc/Zsh/.distfiles
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/.distfiles,v
retrieving revision 1.7
diff -u -r1.7 .distfiles
--- Doc/Zsh/.distfiles 27 Sep 2001 12:03:04 -0000 1.7
+++ Doc/Zsh/.distfiles 19 Feb 2002 01:41:28 -0000
@@ -4,7 +4,7 @@
cond.yo exec.yo expn.yo filelist.yo files.yo func.yo grammar.yo
index.yo intro.yo invoke.yo jobs.yo manual.yo metafaq.yo mod_cap.yo
mod_clone.yo mod_compctl.yo mod_complete.yo mod_complist.yo
- mod_computil.yo mod_deltochar.yo mod_example.yo mod_files.yo
+ mod_computil.yo mod_deltochar.yo mod_example.yo mod_files.yo mod_langinfo.yo
mod_mapfile.yo mod_mathfunc.yo mod_parameter.yo mod_pcre.yo mod_sched.yo
mod_stat.yo mod_tcp.yo mod_termcap.yo mod_terminfo.yo mod_zftp.yo mod_zle.yo
mod_zleparameter.yo mod_zutil.yo mod_zprof.yo mod_zpty.yo
Index: Doc/Zsh/mod_langinfo.yo
===================================================================
RCS file: Doc/Zsh/mod_langinfo.yo
diff -N Doc/Zsh/mod_langinfo.yo
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Doc/Zsh/mod_langinfo.yo 19 Feb 2002 01:41:28 -0000
@@ -0,0 +1,37 @@
+COMMENT(!MOD!zsh/langinfo
+Interface to locale information.
+!MOD!)
+The tt(zsh/langinfo) module makes available one parameter:
+
+startitem()
+vindex(langinfo)
+item(tt(langinfo))(
+An associative array that maps langinfo elements to
+their values.
+
+Your implementation may support a number of the following keys:
+
+tt(CODESET),
+tt(D_T_FMT),
+tt(D_FMT),
+tt(T_FMT),
+tt(RADIXCHAR),
+tt(THOUSEP),
+tt(YESEXPR),
+tt(NOEXPR),
+tt(CRNCYSTR),
+tt(ABDAY_{1..7}),
+tt(DAY_{1..7}),
+tt(ABMON_{1..12}),
+tt(MON_{1..12}),
+tt(T_FMT_AMPM),
+tt(AM_STR),
+tt(PM_STR),
+tt(ERA),
+tt(ERA_D_FMT),
+tt(ERA_D_T_FMT),
+tt(ERA_T_FMT),
+tt(ALT_DIGITS)
+
+)
+enditem()
Index: Src/Modules/.distfiles
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/.distfiles,v
retrieving revision 1.4
diff -u -r1.4 .distfiles
--- Src/Modules/.distfiles 3 Jul 2001 14:19:15 -0000 1.4
+++ Src/Modules/.distfiles 19 Feb 2002 01:41:28 -0000
@@ -4,6 +4,7 @@
clone.mdd clone.c
example.mdd example.c
files.mdd files.c
+ langinfo.mdd langinfo.c
mapfile.mdd mapfile.c
mathfunc.mdd mathfunc.c
parameter.mdd parameter.c
Index: Src/Modules/langinfo.c
===================================================================
RCS file: Src/Modules/langinfo.c
diff -N Src/Modules/langinfo.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Src/Modules/langinfo.c 19 Feb 2002 01:41:28 -0000
@@ -0,0 +1,557 @@
+/*
+ * langinfo.c - parameter interface to langinfo via curses
+ *
+ * This file is part of zsh, the Z shell.
+ *
+ * Copyright (c) 2002 Peter Stephenson, Clint Adams
+ * All rights reserved.
+ *
+ * Permission is hereby granted, without written agreement and without
+ * license or royalty fees, to use, copy, modify, and distribute this
+ * software and to distribute modified versions of this software for any
+ * purpose, provided that the above copyright notice and the following
+ * two paragraphs appear in all copies of this software.
+ *
+ * In no event shall Peter Stephenson, Clint Adams or the Zsh Development Group
+ * be liable to any party for direct, indirect, special, incidental, or
+ * consequential damages arising out of the use of this software and its
+ * documentation, even if Sven Wishnowsky, Clint Adams and the Zsh
+ * Development Group have been advised of the possibility of such damage.
+ *
+ * Peter Stephenson, Clint Adams and the Zsh Development Group specifically
+ * disclaim any warranties, including, but not limited to, the implied
+ * warranties of merchantability and fitness for a particular purpose.
+ * The software provided hereunder is on an "as is" basis, and Peter
+ * Stephenson, Clint Adams and the Zsh Development Group have no obligation
+ * to provide maintenance, support, updates, enhancements, or modifications.
+ *
+ */
+
+#include "langinfo.mdh"
+#include "langinfo.pro"
+
+static char langinfo_nam[] = "langinfo";
+
+#ifdef HAVE_LANGINFO_H
+# include <langinfo.h>
+#endif
+
+static Param langinfo_pm;
+
+/**/
+#ifdef HAVE_NL_LANGINFO
+
+static char *nl_names[] = {
+#ifdef CODESET
+ "CODESET",
+#endif /* CODESET */
+#ifdef D_T_FMT
+ "D_T_FMT",
+#endif /* D_T_FMT */
+#ifdef D_FMT
+ "D_FMT",
+#endif /* D_FMT */
+#ifdef T_FMT
+ "T_FMT",
+#endif /* T_FMT */
+#ifdef RADIXCHAR
+ "RADIXCHAR",
+#endif /* RADIXCHAR */
+#ifdef THOUSEP
+ "THOUSEP",
+#endif /* THOUSEP */
+#ifdef YESEXPR
+ "YESEXPR",
+#endif /* YESEXPR */
+#ifdef NOEXPR
+ "NOEXPR",
+#endif /* NOEXPR */
+#ifdef CRNCYSTR
+ "CRNCYSTR",
+#endif /* CRNCYSTR */
+#ifdef ABDAY_1
+ "ABDAY_1",
+#endif /* ABDAY_1 */
+#ifdef ABDAY_2
+ "ABDAY_2",
+#endif /* ABDAY_2 */
+#ifdef ABDAY_3
+ "ABDAY_3",
+#endif /* ABDAY_3 */
+#ifdef ABDAY_4
+ "ABDAY_4",
+#endif /* ABDAY_4 */
+#ifdef ABDAY_5
+ "ABDAY_5",
+#endif /* ABDAY_5 */
+#ifdef ABDAY_6
+ "ABDAY_6",
+#endif /* ABDAY_6 */
+#ifdef ABDAY_7
+ "ABDAY_7",
+#endif /* ABDAY_7 */
+#ifdef DAY_1
+ "DAY_1",
+#endif /* DAY_1 */
+#ifdef DAY_2
+ "DAY_2",
+#endif /* DAY_2 */
+#ifdef DAY_3
+ "DAY_3",
+#endif /* DAY_3 */
+#ifdef DAY_4
+ "DAY_4",
+#endif /* DAY_4 */
+#ifdef DAY_5
+ "DAY_5",
+#endif /* DAY_5 */
+#ifdef DAY_6
+ "DAY_6",
+#endif /* DAY_6 */
+#ifdef DAY_7
+ "DAY_7",
+#endif /* DAY_7 */
+#ifdef ABMON_1
+ "ABMON_1",
+#endif /* ABMON_1 */
+#ifdef ABMON_2
+ "ABMON_2",
+#endif /* ABMON_2 */
+#ifdef ABMON_3
+ "ABMON_3",
+#endif /* ABMON_3 */
+#ifdef ABMON_4
+ "ABMON_4",
+#endif /* ABMON_4 */
+#ifdef ABMON_5
+ "ABMON_5",
+#endif /* ABMON_5 */
+#ifdef ABMON_6
+ "ABMON_6",
+#endif /* ABMON_6 */
+#ifdef ABMON_7
+ "ABMON_7",
+#endif /* ABMON_7 */
+#ifdef ABMON_8
+ "ABMON_8",
+#endif /* ABMON_8 */
+#ifdef ABMON_9
+ "ABMON_9",
+#endif /* ABMON_9 */
+#ifdef ABMON_10
+ "ABMON_10",
+#endif /* ABMON_10 */
+#ifdef ABMON_11
+ "ABMON_11",
+#endif /* ABMON_11 */
+#ifdef ABMON_12
+ "ABMON_12",
+#endif /* ABMON_12 */
+#ifdef MON_1
+ "MON_1",
+#endif /* MON_1 */
+#ifdef MON_2
+ "MON_2",
+#endif /* MON_2 */
+#ifdef MON_3
+ "MON_3",
+#endif /* MON_3 */
+#ifdef MON_4
+ "MON_4",
+#endif /* MON_4 */
+#ifdef MON_5
+ "MON_5",
+#endif /* MON_5 */
+#ifdef MON_6
+ "MON_6",
+#endif /* MON_6 */
+#ifdef MON_7
+ "MON_7",
+#endif /* MON_7 */
+#ifdef MON_8
+ "MON_8",
+#endif /* MON_8 */
+#ifdef MON_9
+ "MON_9",
+#endif /* MON_9 */
+#ifdef MON_10
+ "MON_10",
+#endif /* MON_10 */
+#ifdef MON_11
+ "MON_11",
+#endif /* MON_11 */
+#ifdef MON_12
+ "MON_12",
+#endif /* MON_12 */
+#ifdef T_FMT_AMPM
+ "T_FMT_AMPM",
+#endif /* T_FMT_AMPM */
+#ifdef AM_STR
+ "AM_STR",
+#endif /* AM_STR */
+#ifdef PM_STR
+ "PM_STR",
+#endif /* PM_STR */
+#ifdef ERA
+ "ERA",
+#endif /* ERA */
+#ifdef ERA_D_FMT
+ "ERA_D_FMT",
+#endif /* ERA_D_FMT */
+#ifdef ERA_D_T_FMT
+ "ERA_D_T_FMT",
+#endif /* ERA_D_T_FMT */
+#ifdef ERA_T_FMT
+ "ERA_T_FMT",
+#endif /* ERA_T_FMT */
+#ifdef ALT_DIGITS
+ "ALT_DIGITS",
+#endif /* ALT_DIGITS */
+ NULL
+};
+
+static nl_item nl_vals[] = {
+#ifdef CODESET
+ CODESET,
+#endif /* CODESET */
+#ifdef D_T_FMT
+ D_T_FMT,
+#endif /* D_T_FMT */
+#ifdef D_FMT
+ D_FMT,
+#endif /* D_FMT */
+#ifdef T_FMT
+ T_FMT,
+#endif /* T_FMT */
+#ifdef RADIXCHAR
+ RADIXCHAR,
+#endif /* RADIXCHAR */
+#ifdef THOUSEP
+ THOUSEP,
+#endif /* THOUSEP */
+#ifdef YESEXPR
+ YESEXPR,
+#endif /* YESEXPR */
+#ifdef NOEXPR
+ NOEXPR,
+#endif /* NOEXPR */
+#ifdef CRNCYSTR
+ CRNCYSTR,
+#endif /* CRNCYSTR */
+#ifdef ABDAY_1
+ ABDAY_1,
+#endif /* ABDAY_1 */
+#ifdef ABDAY_2
+ ABDAY_2,
+#endif /* ABDAY_2 */
+#ifdef ABDAY_3
+ ABDAY_3,
+#endif /* ABDAY_3 */
+#ifdef ABDAY_4
+ ABDAY_4,
+#endif /* ABDAY_4 */
+#ifdef ABDAY_5
+ ABDAY_5,
+#endif /* ABDAY_5 */
+#ifdef ABDAY_6
+ ABDAY_6,
+#endif /* ABDAY_6 */
+#ifdef ABDAY_7
+ ABDAY_7,
+#endif /* ABDAY_7 */
+#ifdef DAY_1
+ DAY_1,
+#endif /* DAY_1 */
+#ifdef DAY_2
+ DAY_2,
+#endif /* DAY_2 */
+#ifdef DAY_3
+ DAY_3,
+#endif /* DAY_3 */
+#ifdef DAY_4
+ DAY_4,
+#endif /* DAY_4 */
+#ifdef DAY_5
+ DAY_5,
+#endif /* DAY_5 */
+#ifdef DAY_6
+ DAY_6,
+#endif /* DAY_6 */
+#ifdef DAY_7
+ DAY_7,
+#endif /* DAY_7 */
+#ifdef ABMON_1
+ ABMON_1,
+#endif /* ABMON_1 */
+#ifdef ABMON_2
+ ABMON_2,
+#endif /* ABMON_2 */
+#ifdef ABMON_3
+ ABMON_3,
+#endif /* ABMON_3 */
+#ifdef ABMON_4
+ ABMON_4,
+#endif /* ABMON_4 */
+#ifdef ABMON_5
+ ABMON_5,
+#endif /* ABMON_5 */
+#ifdef ABMON_6
+ ABMON_6,
+#endif /* ABMON_6 */
+#ifdef ABMON_7
+ ABMON_7,
+#endif /* ABMON_7 */
+#ifdef ABMON_8
+ ABMON_8,
+#endif /* ABMON_8 */
+#ifdef ABMON_9
+ ABMON_9,
+#endif /* ABMON_9 */
+#ifdef ABMON_10
+ ABMON_10,
+#endif /* ABMON_10 */
+#ifdef ABMON_11
+ ABMON_11,
+#endif /* ABMON_11 */
+#ifdef ABMON_12
+ ABMON_12,
+#endif /* ABMON_12 */
+#ifdef MON_1
+ MON_1,
+#endif /* MON_1 */
+#ifdef MON_2
+ MON_2,
+#endif /* MON_2 */
+#ifdef MON_3
+ MON_3,
+#endif /* MON_3 */
+#ifdef MON_4
+ MON_4,
+#endif /* MON_4 */
+#ifdef MON_5
+ MON_5,
+#endif /* MON_5 */
+#ifdef MON_6
+ MON_6,
+#endif /* MON_6 */
+#ifdef MON_7
+ MON_7,
+#endif /* MON_7 */
+#ifdef MON_8
+ MON_8,
+#endif /* MON_8 */
+#ifdef MON_9
+ MON_9,
+#endif /* MON_9 */
+#ifdef MON_10
+ MON_10,
+#endif /* MON_10 */
+#ifdef MON_11
+ MON_11,
+#endif /* MON_11 */
+#ifdef MON_12
+ MON_12,
+#endif /* MON_12 */
+#ifdef T_FMT_AMPM
+ T_FMT_AMPM,
+#endif /* T_FMT_AMPM */
+#ifdef AM_STR
+ AM_STR,
+#endif /* AM_STR */
+#ifdef PM_STR
+ PM_STR,
+#endif /* PM_STR */
+#ifdef ERA
+ ERA,
+#endif /* ERA */
+#ifdef ERA_D_FMT
+ ERA_D_FMT,
+#endif /* ERA_D_FMT */
+#ifdef ERA_D_T_FMT
+ ERA_D_T_FMT,
+#endif /* ERA_D_T_FMT */
+#ifdef ERA_T_FMT
+ ERA_T_FMT,
+#endif /* ERA_T_FMT */
+#ifdef ALT_DIGITS
+ ALT_DIGITS,
+#endif /* ALT_DIGITS */
+ 0
+};
+
+static nl_item *
+liitem(char *name)
+{
+ char **element;
+ nl_item *nlcode;
+
+ nlcode = &nl_vals[0];
+
+ for (element = (char **)nl_names; *element; element++, nlcode++) {
+ if ((!strncmp(*element, name, strlen(*element))))
+ return nlcode;
+ }
+
+ return NULL;
+}
+
+/**/
+static void
+shempty(void)
+{
+}
+
+/* Create a simple special hash parameter. */
+
+/**/
+static Param
+createlihash()
+{
+ Param pm;
+ HashTable ht;
+
+ unsetparam(langinfo_nam);
+
+ if (!(pm = createparam(langinfo_nam, PM_SPECIAL|PM_HIDE|PM_HIDEVAL|
+ PM_REMOVABLE|PM_HASHED)))
+ return NULL;
+
+ pm->level = pm->old ? locallevel : 0;
+ pm->gets.hfn = hashgetfn;
+ pm->sets.hfn = hashsetfn;
+ pm->unsetfn = stdunsetfn;
+ pm->u.hash = ht = newhashtable(7, langinfo_nam, NULL);
+
+ ht->hash = hasher;
+ ht->emptytable = (TableFunc) shempty;
+ ht->filltable = NULL;
+ ht->addnode = (AddNodeFunc) shempty;
+ ht->getnode = ht->getnode2 = getlanginfo;
+ ht->removenode = (RemoveNodeFunc) shempty;
+ ht->disablenode = NULL;
+ ht->enablenode = NULL;
+ ht->freenode = (FreeNodeFunc) shempty;
+ ht->printnode = printparamnode;
+ ht->scantab = scanlanginfo;
+
+ return (langinfo_pm = pm);
+}
+
+/**/
+static HashNode
+getlanginfo(HashTable ht, char *name)
+{
+ int len, *elem;
+ char *listr;
+ Param pm = NULL;
+
+ unmetafy(name, &len);
+
+ pm = (Param) zhalloc(sizeof(struct param));
+ pm->nam = dupstring(name);
+ pm->flags = PM_READONLY | PM_SCALAR;
+ pm->sets.cfn = NULL;
+ pm->gets.cfn = strgetfn;
+ pm->sets.ifn = NULL;
+ pm->gets.ifn = intgetfn;
+ pm->unsetfn = NULL;
+ pm->ct = 0;
+ pm->env = NULL;
+ pm->ename = NULL;
+ pm->old = NULL;
+ pm->level = 0;
+
+ if(name)
+ elem = liitem(name);
+ else
+ elem = NULL;
+
+ if (elem && (listr = nl_langinfo(*elem))) {
+ pm->u.str = dupstring(listr);
+ }
+ else
+ {
+ /* zwarn("no such lang info: %s", name, 0); */
+ pm->u.str = dupstring("");
+ pm->flags |= PM_UNSET;
+ }
+ return (HashNode) pm;
+}
+
+/**/
+static void
+scanlanginfo(HashTable ht, ScanFunc func, int flags)
+{
+ Param pm = NULL;
+ char **element, *langstr;
+ nl_item *nlcode;
+
+ pm = (Param) zhalloc(sizeof(struct param));
+ pm->sets.cfn = NULL;
+ pm->gets.cfn = strgetfn;
+ pm->sets.ifn = NULL;
+ pm->gets.ifn = intgetfn;
+ pm->unsetfn = NULL;
+ pm->ct = 0;
+ pm->env = NULL;
+ pm->ename = NULL;
+ pm->old = NULL;
+
+ pm->flags = PM_READONLY | PM_SCALAR;
+
+ nlcode = &nl_vals[0];
+ for (element = (char **)nl_names; *element; element++, nlcode++) {
+ if ((langstr = nl_langinfo(*nlcode)) != NULL) {
+ pm->u.str = dupstring(langstr);
+ pm->nam = dupstring(*element);
+ func((HashNode) pm, flags);
+ }
+ }
+
+}
+
+/**/
+#endif /* HAVE_NL_LANGINFO */
+
+/**/
+int
+setup_(Module m)
+{
+ return 0;
+}
+
+/**/
+int
+boot_(Module m)
+{
+#ifdef HAVE_NL_LANGINFO
+ if (!createlihash())
+ return 1;
+#else
+ unsetparam(langinfo_nam);
+#endif
+ return 0;
+}
+
+/**/
+int
+cleanup_(Module m)
+{
+#ifdef HAVE_NL_LANGINFO
+ Param pm;
+
+ if ((pm = (Param) paramtab->getnode(paramtab, langinfo_nam)) &&
+ pm == langinfo_pm) {
+ pm->flags &= ~PM_READONLY;
+ unsetparam_pm(pm, 0, 1);
+ }
+#endif
+ return 0;
+}
+
+/**/
+int
+finish_(Module m)
+{
+ return 0;
+}
Index: Src/Modules/langinfo.mdd
===================================================================
RCS file: Src/Modules/langinfo.mdd
diff -N Src/Modules/langinfo.mdd
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Src/Modules/langinfo.mdd 19 Feb 2002 01:41:28 -0000
@@ -0,0 +1,8 @@
+name=zsh/langinfo
+
+link=either
+load=no
+
+autoparams="langinfo"
+
+objects="langinfo.o"
^ permalink raw reply [flat|nested] 8+ messages in thread
* PATCH: strftime builtin
2002-02-19 2:06 PATCH: langinfo module Clint Adams
@ 2002-04-30 18:52 ` Clint Adams
2002-05-01 9:38 ` Peter Stephenson
0 siblings, 1 reply; 8+ messages in thread
From: Clint Adams @ 2002-04-30 18:52 UTC (permalink / raw)
To: zsh-workers
> 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"
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: strftime builtin
2002-04-30 18:52 ` PATCH: strftime builtin Clint Adams
@ 2002-05-01 9:38 ` Peter Stephenson
2002-05-26 21:58 ` Clint Adams
0 siblings, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2002-05-01 9:38 UTC (permalink / raw)
To: Zsh hackers list
Clint Adams wrote:
> > 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
You should probably use zsh's own function ztrftime (in utils.c), which
calls strftime if that's available, else does some of the simpler formats,
and makes a couple of extra formats available. If that doesn't seem
appropriate for some reason, at least test for HAVE_STRFTIME which is
already handled by configure.
I suppose it would be better in its own module, or else a module
timeutils or stringutils if there's any more stuff that can usefully be
collected.
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070
**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential
and/or privileged material.
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited.
If you received this in error, please contact the sender and
delete the material from any computer.
**********************************************************************
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: strftime builtin
2002-05-01 9:38 ` Peter Stephenson
@ 2002-05-26 21:58 ` Clint Adams
2002-05-27 5:05 ` Borsenkow Andrej
[not found] ` <23146.1064741224@athlon>
0 siblings, 2 replies; 8+ messages in thread
From: Clint Adams @ 2002-05-26 21:58 UTC (permalink / raw)
To: Peter Stephenson; +Cc: Zsh hackers list
> You should probably use zsh's own function ztrftime (in utils.c), which
> calls strftime if that's available, else does some of the simpler formats,
> and makes a couple of extra formats available. If that doesn't seem
Module renamed to datetime, using ztrftime.
Index: Src/Modules/datetime.c
===================================================================
RCS file: Src/Modules/datetime.c
diff -N Src/Modules/datetime.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Src/Modules/datetime.c 26 May 2002 21:32:00 -0000
@@ -0,0 +1,99 @@
+/*
+ * datetime.c - parameter interface to langinfo via curses
+ *
+ * This file is part of zsh, the Z shell.
+ *
+ * Copyright (c) 2002 Peter Stephenson, Clint Adams
+ * All rights reserved.
+ *
+ * Permission is hereby granted, without written agreement and without
+ * license or royalty fees, to use, copy, modify, and distribute this
+ * software and to distribute modified versions of this software for any
+ * purpose, provided that the above copyright notice and the following
+ * two paragraphs appear in all copies of this software.
+ *
+ * In no event shall Peter Stephenson, Clint Adams or the Zsh Development Group
+ * be liable to any party for direct, indirect, special, incidental, or
+ * consequential damages arising out of the use of this software and its
+ * documentation, even if Peter Stephenson, Clint Adams and the Zsh
+ * Development Group have been advised of the possibility of such damage.
+ *
+ * Peter Stephenson, Clint Adams and the Zsh Development Group specifically
+ * disclaim any warranties, including, but not limited to, the implied
+ * warranties of merchantability and fitness for a particular purpose.
+ * The software provided hereunder is on an "as is" basis, and Peter
+ * Stephenson, Clint Adams and the Zsh Development Group have no obligation
+ * to provide maintenance, support, updates, enhancements, or modifications.
+ *
+ */
+
+#include "datetime.mdh"
+#include "datetime.pro"
+#include <time.h>
+
+static char datetime_nam[] = "datetime";
+
+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;
+ int 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 = ztrftime(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)
+{
+ return 0;
+}
+
+/**/
+int
+boot_(Module m)
+{
+ return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
+}
+
+/**/
+int
+cleanup_(Module m)
+{
+ deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
+ return 0;
+}
+
+/**/
+int
+finish_(Module m)
+{
+ return 0;
+}
Index: Src/Modules/datetime.mdd
===================================================================
RCS file: Src/Modules/datetime.mdd
diff -N Src/Modules/datetime.mdd
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Src/Modules/datetime.mdd 26 May 2002 21:32:00 -0000
@@ -0,0 +1,8 @@
+name=zsh/datetime
+
+link=either
+load=no
+
+autobins="strftime"
+
+objects="datetime.o"
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: PATCH: strftime builtin
2002-05-26 21:58 ` Clint Adams
@ 2002-05-27 5:05 ` Borsenkow Andrej
[not found] ` <23146.1064741224@athlon>
1 sibling, 0 replies; 8+ messages in thread
From: Borsenkow Andrej @ 2002-05-27 5:05 UTC (permalink / raw)
To: 'Clint Adams'; +Cc: 'Zsh hackers list'
> + * datetime.c - parameter interface to langinfo via curses
^^^^^^^^ really?
-andrej
^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <23146.1064741224@athlon>]
* PATCH: $SECS
[not found] ` <23146.1064741224@athlon>
@ 2003-09-28 16:19 ` Clint Adams
2003-09-28 17:30 ` Bart Schaefer
2003-09-28 18:05 ` Peter Stephenson
0 siblings, 2 replies; 8+ messages in thread
From: Clint Adams @ 2003-09-28 16:19 UTC (permalink / raw)
To: zsh-workers
> Any chance we could have some documentation for this? I take it that the
> first argument is the strftime format and the second is the number of
> seconds since the epoch. Would be nice if the second argument was
> optional and defaulted to the current time.
With the following patch, you can do
strftime "%d-%m-%y" $SECS
Is it worth having the second argument be optional? Is SECS too generic
a name?
Index: Src/Modules/datetime.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/datetime.c,v
retrieving revision 1.3
diff -u -r1.3 datetime.c
--- Src/Modules/datetime.c 27 Aug 2002 21:10:34 -0000 1.3
+++ Src/Modules/datetime.c 28 Sep 2003 16:16:56 -0000
@@ -63,10 +63,21 @@
return 0;
}
+static zlong
+getcurrentsecs()
+{
+ return (zlong) time(NULL);
+}
+
static struct builtin bintab[] = {
BUILTIN("strftime", 0, bin_strftime, 2, 2, 0, NULL, NULL),
};
+static struct paramdef patab[] = {
+ PARAMDEF("SECS", PM_INTEGER|PM_SPECIAL|PM_READONLY,
+ NULL, NULL, &getcurrentsecs, NULL),
+};
+
/**/
int
setup_(Module m)
@@ -78,7 +89,9 @@
int
boot_(Module m)
{
- return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
+ return !(addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)) |
+ addparamdefs(m->nam, patab, sizeof(patab)/sizeof(*patab))
+ );
}
/**/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: $SECS
2003-09-28 16:19 ` PATCH: $SECS Clint Adams
@ 2003-09-28 17:30 ` Bart Schaefer
2003-09-28 18:05 ` Peter Stephenson
1 sibling, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2003-09-28 17:30 UTC (permalink / raw)
To: zsh-workers
On Sep 28, 12:19pm, Clint Adams wrote:
}
} strftime "%d-%m-%y" $SECS
}
} Is it worth having the second argument be optional? Is SECS too generic
} a name?
It's not too generic, but I think it's too easily confused with $SECONDS.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: $SECS
2003-09-28 16:19 ` PATCH: $SECS Clint Adams
2003-09-28 17:30 ` Bart Schaefer
@ 2003-09-28 18:05 ` Peter Stephenson
1 sibling, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 2003-09-28 18:05 UTC (permalink / raw)
To: zsh-workers
Clint Adams wrote:
> With the following patch, you can do
>
> strftime "%d-%m-%y" $SECS
>
> Is it worth having the second argument be optional?
I think that would be reasonable.
> Is SECS too generic a name?
More than that, I think it's too close to the existing SECONDS, and
doesn't give you enough of a hint about seconds since when. Something
with a vague note that it gives seconds since the epoch would be good.
It's not going to be used on the command line much, so it doesn't have
to be short. How about CALTIME (since it's tied to time()), CALSECONDS,
EPOCHTIME, EPOCHSECONDS, ...?
By the way, I'm away for a week from tomorrow.
--
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2003-09-28 18:04 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-19 2:06 PATCH: langinfo module Clint Adams
2002-04-30 18:52 ` PATCH: strftime builtin Clint Adams
2002-05-01 9:38 ` 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
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).