zsh-workers
 help / color / mirror / code / Atom feed
* Re: db module
@ 2002-10-07 13:58 Oliver Kiddle
  0 siblings, 0 replies; 11+ messages in thread
From: Oliver Kiddle @ 2002-10-07 13:58 UTC (permalink / raw)
  To: zsh-workers

 --- Bart Schaefer <schaefer@brasslantern.com> wrote:
> It would seem to me that all of this stuff can be accomplished by the
> equivalent of ksh discipline functions (plus, in the DB case, a
> module

It could be useful and more efficient to allow modules to control a
special which doesn't have a fixed name. This last idea of using
functions looks to me exactly like ksh disclipline functions except
the syntax is differnt.

ksh style discipline functions have the big problem that they don't
unambiguously map functions to variables because of the lack of
scoped functions. ksh now solves this by not allowing local variables
to
have disciplines.

> to do the actual database access).  Rather than implementing each of
> these things as different typeset variants, we should work on
> adding discipline functions.

There is a lot else besides that we could do with getting right before
adding discipline functions.

> (Was it Andrej who's working on a parameter code rewerite?)

I thought it was me. And I am working on it - slowly but surely.

> One can also envision cases where it would be nice if a function
> could
> return text instead of an exit code, so that you could "inline" the
> function call in a larger print statement or in a here-document or
> the

To do this, one way might be to allow function calls inside (( ... )).
There is nothing about ((...)) which means it can only ever be used for
math functions and inside it we could pass around objects by references
to struct params instead of by expanding them to strings. But something
like this is way off in the future.

Oliver

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: db module
  2002-10-06 17:31           ` Clint Adams
@ 2002-10-06 20:19             ` Bart Schaefer
  0 siblings, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2002-10-06 20:19 UTC (permalink / raw)
  To: Zsh workers

On Oct 6,  1:31pm, Clint Adams wrote:
}
} So, if a function with a name ending in .{get,set,unset} is defined,
} param.{gets,sets,unsetfn} should be modified accordingly, and restored
} upon unfunction.  When param.{gets,sets,unsetfn} are invoked,
} .sh.{name,subscript} and sometimes .sh.value need to be set to the
} appropriate strings.

Yes, except that zsh's parser currently can't deal with dots in parameter
names, and zsh doesn't support the concept of the ".sh" namespace, and so
on.  There are a lot of other changes upon which this one depends.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: db module
  2002-10-06 17:14         ` Bart Schaefer
@ 2002-10-06 17:31           ` Clint Adams
  2002-10-06 20:19             ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Clint Adams @ 2002-10-06 17:31 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh workers

> Yes, except that, like e.g. the stat module's -A and -H options, I was
> thinking that the name of the parameter to which to assign would be an
> argument to the db_get function so that the $(...) would not be needed.

Well, that should be the simplest part to implement.

So, if a function with a name ending in .{get,set,unset} is defined,
param.{gets,sets,unsetfn} should be modified accordingly, and restored
upon unfunction.  When param.{gets,sets,unsetfn} are invoked,
.sh.{name,subscript} and sometimes .sh.value need to be set to the
appropriate strings.

I don't think I understand how adding more discipline functions via
ksh's builtin builtin works, so I don't know if it would be useful to
keep in mind.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: db module
  2002-10-06 17:03       ` Clint Adams
@ 2002-10-06 17:14         ` Bart Schaefer
  2002-10-06 17:31           ` Clint Adams
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2002-10-06 17:14 UTC (permalink / raw)
  To: Zsh workers

On Oct 6,  1:03pm, Clint Adams wrote:
}
} So, if I grasp the concept correctly, one could do something like
} 
} db.get() { .sh.value=$(db_get thisdb "$.sh.subscript"); }

Yes, except that, like e.g. the stat module's -A and -H options, I was
thinking that the name of the parameter to which to assign would be an
argument to the db_get function so that the $(...) would not be needed.

Either that, or db_get would always assign to .sh.value and would thus
only be callable from a discipline function.

} > } f() { [ "$2" ] && echo $2 > $1; cat $1 }
} > 
} > I confess to having no idea what that's supposed to mean.
} 
} I think he's trying to say that var[5]=xyz would call $(f 5 xyz).

Ah.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: db module
  2002-10-06 16:46     ` Bart Schaefer
@ 2002-10-06 17:03       ` Clint Adams
  2002-10-06 17:14         ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Clint Adams @ 2002-10-06 17:03 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh workers

> It would seem to me that all of this stuff can be accomplished by the
> equivalent of ksh discipline functions (plus, in the DB case, a module
> to do the actual database access).  Rather than implementing each of
> these things as different typeset variants, we should work on adding
> discipline functions.

So, if I grasp the concept correctly, one could do something like

db.get() { .sh.value=$(db_get thisdb "$.sh.subscript"); }
print $db[key]

> (Was it Andrej who's working on a parameter code rewerite?)

Oliver, I thought.  Maybe both of them.

> You mean "print $twice[2]", yes?

Yes.

> On Oct 6,  8:24am, Hans Dieter Pearcey wrote:
> } Subject: Re: db module
> }
> } However, if the function got an extra argument when an element was
> } assigned to, it could be pretty neat, e.g.:
> } 
> } f() { [ "$2" ] && echo $2 > $1; cat $1 }
> 
> I confess to having no idea what that's supposed to mean.

I think he's trying to say that var[5]=xyz would call $(f 5 xyz).
Only I don't know what the cat's about.

Using var.set() would seem much cleaner.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: db module
  2002-10-06 12:24   ` Hans Dieter Pearcey
@ 2002-10-06 16:46     ` Bart Schaefer
  2002-10-06 17:03       ` Clint Adams
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2002-10-06 16:46 UTC (permalink / raw)
  To: Zsh workers

On Sep 30,  3:39pm, Oliver Kiddle wrote:
} Subject: Re: db module
}
} On Thu, 12 Sep 2002, Clint wrote:
} 
} > This allows one to "tie" a Berkeley DB to an associative array (or is
} > that the other way around?)
} 
} It's a nice idea. Could be an interesting way to do completion caching.
} Thinking of it from the perspective of cached variables, it is actually
} quite similar to mapfile. The mapfile module could easily have been
} implemented with a builtin.

On Oct 6,  1:32am, Clint Adams wrote:
} Subject: Re: db module
}
} Someone suggested tying assocs to functions

It would seem to me that all of this stuff can be accomplished by the
equivalent of ksh discipline functions (plus, in the DB case, a module
to do the actual database access).  Rather than implementing each of
these things as different typeset variants, we should work on adding
discipline functions.

(Was it Andrej who's working on a parameter code rewerite?)

} f() { print $(( $1 * 2 )) }
} typeset -A twice -S function -f f
} print $f[2]

You mean "print $twice[2]", yes?

Obviously you'd not put a "print" inside the function.  Instead it would
be something like

	f() { REPLY=$(($1 * 2)) }

where the typeset magic would do twice[2]=$REPLY upon successful return
from the function, all of which would happen before the parameter code
finally expands the value of $twice[2].

} I'm not sure that there are any useful applications for this though.

Consider the case where you have some arbitrarily complex function such
as a big quadratic equation which you want to refer to in some other
expression.  Instead of

	quadratic() {
	  # Do hairy computation and assign to REPLY
	  print $REPLY
	}

	(( foo = bar * $(quadratic $foo) ))

which requires forking an external process and reading back its output,
you can just write

	quadratic_f() {
	  # Do hairy computation and assign to REPLY
	}
	typeset quadratic ...

	(( foo = bar * $quadratic[$foo] ))

One can also envision cases where it would be nice if a function could
return text instead of an exit code, so that you could "inline" the
function call in a larger print statement or in a here-document or the
like, again without forking.  It's making the shell more perl-like.

On Oct 6,  8:24am, Hans Dieter Pearcey wrote:
} Subject: Re: db module
}
} However, if the function got an extra argument when an element was
} assigned to, it could be pretty neat, e.g.:
} 
} f() { [ "$2" ] && echo $2 > $1; cat $1 }

I confess to having no idea what that's supposed to mean.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: db module
  2002-10-06  5:32 ` Clint Adams
@ 2002-10-06 12:24   ` Hans Dieter Pearcey
  2002-10-06 16:46     ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Hans Dieter Pearcey @ 2002-10-06 12:24 UTC (permalink / raw)
  To: Zsh workers

On Sun, Oct 06, 2002 at 01:32:29AM -0400, Clint Adams wrote:
> > typeset -A things -S db -f /tmp/newdb
> > typeset string -S mapfile -f /tmp/file
> 
> Someone suggested tying assocs to functions, so we could add something
> like
> 
> f() { print $(( $1 * 2 )) }
> typeset -A twice -S function -f f
> print $f[2]
> 
> I'm not sure that there are any useful applications for this though.

As demonstrated above, I can't see how it's any better than calling f()
directly.  However, if the function got an extra argument when an element was
assigned to, it could be pretty neat, e.g.:

f() { [ "$2" ] && echo $2 > $1; cat $1 }

hdp.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: db module
  2002-09-30 14:39 Oliver Kiddle
  2002-10-02  7:37 ` Clint Adams
@ 2002-10-06  5:32 ` Clint Adams
  2002-10-06 12:24   ` Hans Dieter Pearcey
  1 sibling, 1 reply; 11+ messages in thread
From: Clint Adams @ 2002-10-06  5:32 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh workers

> typeset -A things -S db -f /tmp/newdb
> typeset string -S mapfile -f /tmp/file

Someone suggested tying assocs to functions, so we could add something
like

f() { print $(( $1 * 2 )) }
typeset -A twice -S function -f f
print $f[2]

I'm not sure that there are any useful applications for this though.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: db module
  2002-09-30 14:39 Oliver Kiddle
@ 2002-10-02  7:37 ` Clint Adams
  2002-10-06  5:32 ` Clint Adams
  1 sibling, 0 replies; 11+ messages in thread
From: Clint Adams @ 2002-10-02  7:37 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh workers

> Instead of using pm->u.str to store a string value, I think you could
> use the u.data field to point to that db handle and then use your own
> function instead of strgetfn().

Well, that certainly sounds like a better idea.

> How hard would it be to modify 16845 as suggested in 16878 so that we
> at least have a short term solution.

At the bottom of this message; the include solution is definitely
cleaner and more efficient and reliable.  Maybe it's worth having
configure test whether or not $(MAKE) can handle 'include'.

> > zdb_open -c things /tmp/newdb.db
> 
> I would use -A instead because it is what we tend to use for
> associations and we might plausibly tie a database to other types in
> the future.

Well, -c means "create a new file"; it's not taking the parameter name
as an argument.

> typeset -A things -S db -f /tmp/newdb
> typeset string -S mapfile -f /tmp/file

I like this concept a lot.


Index: zshconfig.ac
===================================================================
RCS file: /cvsroot/zsh/zsh/zshconfig.ac,v
retrieving revision 1.28
diff -u -r1.28 zshconfig.ac
--- zshconfig.ac	6 May 2002 14:50:11 -0000	1.28
+++ zshconfig.ac	2 Oct 2002 07:35:02 -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 langinfo.h)
+		 netinet/in_systm.h langinfo.h)
 if test $dynamic = yes; then
   AC_CHECK_HEADERS(dlfcn.h)
   AC_CHECK_HEADERS(dl.h)
@@ -655,9 +655,6 @@
 
 AC_CHECK_LIB(socket, socket)
 
-dnl pcre-config should probably be employed here
-AC_SEARCH_LIBS(pcre_compile, pcre)
-
 dnl ---------------------
 dnl CHECK TERMCAP LIBRARY
 dnl ---------------------
@@ -949,7 +946,6 @@
 	       brk sbrk \
 	       pathconf sysconf \
 	       tgetent tigetflag tigetnum tigetstr setupterm \
-	       pcre_compile pcre_study pcre_exec \
 	       nl_langinfo \
 	       erand48 open_memstream)
 AC_FUNC_STRCOLL
Index: Src/Makefile.in
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Makefile.in,v
retrieving revision 1.12
diff -u -r1.12 Makefile.in
--- Src/Makefile.in	20 Dec 2001 23:48:39 -0000	1.12
+++ Src/Makefile.in	2 Oct 2002 07:35:05 -0000
@@ -120,6 +120,7 @@
 	cd $(dir_top) && \
 	    $(SHELL) $$top_srcdir/$(subdir)/mkmakemod.sh $(subdir) Makemod
 	@$(MAKE) -f Makemod $(MAKEDEFS) prep || rm -f Makemod
+	@$(MAKE) -C Modules $(MAKEDEFS) regenerate || rm -f Makemod
 .PHONY: prep
 
 FORCE:
Index: Src/Makemod.in.in
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Makemod.in.in,v
retrieving revision 1.5
diff -u -r1.5 Makemod.in.in
--- Src/Makemod.in.in	20 Dec 2001 23:48:39 -0000	1.5
+++ Src/Makemod.in.in	2 Oct 2002 07:35:06 -0000
@@ -149,7 +149,8 @@
 .PHONY: mostlyclean-here
 
 clean-here:
-	rm -f *.o.c *.syms *.pro *.epro *.mdh *.mdhi *.mdhs *.mdh.tmp
+	rm -f *.o.c *.syms *.pro *.epro *.mdh *.mdhi *.mdhs *.mdh.tmp \
+	*.configure *.ach config.cache config.status config.log *.rules
 .PHONY: clean-here
 
 distclean-here:
Index: Src/mkmakemod.sh
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/mkmakemod.sh,v
retrieving revision 1.12
diff -u -r1.12 mkmakemod.sh
--- Src/mkmakemod.sh	6 Jun 2001 08:37:22 -0000	1.12
+++ Src/mkmakemod.sh	2 Oct 2002 07:35:07 -0000
@@ -55,6 +55,7 @@
 # in Makemod.in.in, but some of the macros that it creates are needed in the
 # later rules.
 #
+set -e
 
 # sed script to normalise a pathname
 sed_normalise='
@@ -192,7 +193,7 @@
 
 	unset name moddeps nozshdep alwayslink hasexport
 	unset autobins autoinfixconds autoprefixconds autoparams automathfuncs
-	unset objects proto headers hdrdeps otherincs
+	unset objects proto headers hdrdeps otherincs autoconf achfile
 	. $top_srcdir/$the_subdir/${mddname}.mdd
 	q_name=`echo $name | sed 's,Q,Qq,g;s,_,Qu,g;s,/,Qs,g'`
 	test -n "${moddeps+set}" || moddeps=
@@ -314,6 +315,24 @@
 	echo "modobjs.${mddname}: \$(MODOBJS_${mddname})"
 	echo "	echo '' \$(MODOBJS_${mddname}) $modobjs_sed>> \$(dir_src)/stamp-modobjs.tmp"
 	echo
+	if test -n "$autoconf"; then
+#	    echo "include ${mddname}.rules"
+	    if test -r Src/Modules/${mddname}.rules; then
+		cat Src/Modules/${mddname}.rules
+	    else
+		regenerate="$regenerate ${mddname}.rules"
+	    fi
+	    echo
+	    echo "${mddname}.ach ${mddname}.rules: ${mddname}.configure"
+	    echo "	./${mddname}.configure"
+	    echo
+	    echo "${mddname}.configure: ${mddname}.configure.in ${mddname}.ach.in"
+	    echo "	autoheader ${mddname}.configure.in >${mddname}.ach.in"
+	    echo "	autoconf ${mddname}.configure.in >${mddname}.configure"
+	    echo "	chmod +x ${mddname}.configure"
+	    achfile="${mddname}.ach"
+	fi
+
 	if test -z "$alwayslink"; then
 	    case " $all_modules" in *" ${mddname}."*)
 		echo "install.modules-here: install.modules.${mddname}"
@@ -330,7 +349,7 @@
 	    echo
 	    echo "${mddname}.\$(DL_EXT): \$(MODDOBJS_${mddname}) ${mddname}.export $exportdeps \$(@LINKMODS@_${mddname})"
 	    echo '	rm -f $@'
-	    echo "	\$(DLLINK) \$(@E@XPIMP_$mddname) \$(@E@NTRYOPT) \$(MODDOBJS_${mddname}) \$(@LINKMODS@_${mddname}) \$(LIBS) "
+	    echo "	\$(DLLINK) \$(@E@XPIMP_$mddname) \$(@E@NTRYOPT) \$(MODDOBJS_${mddname}) \$(@LINKMODS@_${mddname}) \$(LIBS) \$(EXTRALIBS_${mddname})"
 	    echo
 	fi
 	echo "${mddname}.mdhi: ${mddname}.mdhs \$(INCS_${mddname})"
@@ -416,7 +435,7 @@
 	echo "	    echo '#endif /* !have_${q_name}_module */'; \\"
 	echo "	) > \$@"
 	echo
-	echo "\$(MODOBJS_${mddname}) \$(MODDOBJS_${mddname}): ${mddname}.mdh"
+	echo "\$(MODOBJS_${mddname}) \$(MODDOBJS_${mddname}): ${mddname}.mdh $achfile"
 	sed -e '/^ *: *<< *\\Make *$/,/^Make$/!d' \
 	    -e 's/^ *: *<< *\\Make *$//; /^Make$/d' \
 	    < $top_srcdir/$the_subdir/${mddname}.mdd
@@ -458,6 +477,14 @@
 	    echo
 	fi
     fi
+
+    echo "regenerate: $regenerate"
+    if test -n "$regenerate"; then
+	    echo "	rm -f ../Makemod Makefile.in Makefile"
+	    echo "	make -C .. Makemod"
+    fi
+    echo ".PHONY: regenerate"
+
 
     echo "##### End of ${the_makefile}.in"
 
Index: Src/Modules/.cvsignore
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/.cvsignore,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 .cvsignore
--- Src/Modules/.cvsignore	1 Dec 1999 18:36:06 -0000	1.1.1.4
+++ Src/Modules/.cvsignore	2 Oct 2002 07:35:07 -0000
@@ -12,3 +12,4 @@
 *.mdhi
 *.mdhs
 *.mdh.tmp
+*.rules
Index: Src/Modules/pcre.ach.in
===================================================================
RCS file: Src/Modules/pcre.ach.in
diff -N Src/Modules/pcre.ach.in
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Src/Modules/pcre.ach.in	2 Oct 2002 07:35:07 -0000
@@ -0,0 +1,58 @@
+/* pcre.ach.in.  Generated from pcre.configure.in by autoheader.  */
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the `pcre_compile' function. */
+#undef HAVE_PCRE_COMPILE
+
+/* Define to 1 if you have the `pcre_exec' function. */
+#undef HAVE_PCRE_EXEC
+
+/* Define to 1 if you have the <pcre.h> header file. */
+#undef HAVE_PCRE_H
+
+/* Define to 1 if you have the `pcre_study' function. */
+#undef HAVE_PCRE_STUDY
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
Index: Src/Modules/pcre.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/pcre.c,v
retrieving revision 1.5
diff -u -r1.5 pcre.c
--- Src/Modules/pcre.c	27 Aug 2002 21:10:34 -0000	1.5
+++ Src/Modules/pcre.c	2 Oct 2002 07:35:07 -0000
@@ -30,6 +30,7 @@
 
 #include "pcre.mdh"
 #include "pcre.pro"
+#include "pcre.ach"
 
 /**/
 #if defined(HAVE_PCRE_COMPILE) && defined(HAVE_PCRE_EXEC)
Index: Src/Modules/pcre.configure.in
===================================================================
RCS file: Src/Modules/pcre.configure.in
diff -N Src/Modules/pcre.configure.in
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Src/Modules/pcre.configure.in	2 Oct 2002 07:35:07 -0000
@@ -0,0 +1,38 @@
+dnl
+dnl  pcre.ac: Configure template for zsh/pcre module.
+dnl  Process this file with autoconf to produce a configure script.
+dnl
+dnl  Copyright (c) 2002 Peter Stephenson
+dnl
+dnl  Permission is hereby granted, without written agreement and without
+dnl  license or royalty fees, to use, copy, modify, and distribute this
+dnl  software and to distribute modified versions of this software for any
+dnl  purpose, provided that the above copyright notice and the following
+dnl  two paragraphs appear in all copies of this software.
+dnl
+dnl  In no event shall Peter Stephenson or the Zsh Development Group be liable
+dnl  to any party for direct, indirect, special, incidental, or consequential
+dnl  damages arising out of the use of this software and its documentation,
+dnl  even if Richard Coleman and the Zsh Development Group have been advised of
+dnl  the possibility of such damage.
+dnl
+dnl  Peter Stephenson and the Zsh Development Group specifically disclaim any
+dnl  warranties, including, but not limited to, the implied warranties of
+dnl  merchantability and fitness for a particular purpose.  The software
+dnl  provided hereunder is on an "as is" basis, and Peter Stephenson and the
+dnl  Zsh Development Group have no obligation to provide maintenance,
+dnl  support, updates, enhancements, or modifications.
+dnl
+
+AC_INIT(pcre.c)
+AC_PREREQ(2.13)
+
+AC_CONFIG_HEADER(pcre.ach)
+
+AC_CHECK_HEADERS(pcre.h)
+
+dnl pcre-config should probably be employed here
+AC_SEARCH_LIBS(pcre_compile, pcre)
+AC_CHECK_FUNCS(pcre_compile pcre_study pcre_exec)
+
+AC_OUTPUT(pcre.rules)
Index: Src/Modules/pcre.mdd
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/pcre.mdd,v
retrieving revision 1.2
diff -u -r1.2 pcre.mdd
--- Src/Modules/pcre.mdd	6 Jul 2001 08:32:16 -0000	1.2
+++ Src/Modules/pcre.mdd	2 Oct 2002 07:35:07 -0000
@@ -5,3 +5,5 @@
 autobins="pcre_compile pcre_study pcre_match"
 
 objects="pcre.o"
+
+autoconf=yes
Index: Src/Modules/pcre.rules.in
===================================================================
RCS file: Src/Modules/pcre.rules.in
diff -N Src/Modules/pcre.rules.in
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Src/Modules/pcre.rules.in	2 Oct 2002 07:35:07 -0000
@@ -0,0 +1 @@
+EXTRALIBS_pcre = @LIBS@


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: db module
@ 2002-09-30 14:39 Oliver Kiddle
  2002-10-02  7:37 ` Clint Adams
  2002-10-06  5:32 ` Clint Adams
  0 siblings, 2 replies; 11+ messages in thread
From: Oliver Kiddle @ 2002-09-30 14:39 UTC (permalink / raw)
  To: Zsh workers

On Thu, 12 Sep 2002, Clint wrote:

> This allows one to "tie" a Berkeley DB to an associative array (or is
> that the other way around?)
> 
> I'm using two hacks.  The 'extradata' field in struct hashtable holds the
> db handle for that assoc array.  Unfortunately, this doesn't seem to be
> available from the set and unset functions for the individual elements,
> so I had to use a static variable.  That means that the last DB to be
> opened is the only one that be modified.  How can this be handled
> sanely?

Instead of using pm->u.str to store a string value, I think you could
use the u.data field to point to that db handle and then use your own
function instead of strgetfn().

However, this is the sort of thing I'm trying to address with the
replacement parameter code. I dug it out and made some progress over
the weekend.

> Other notes:
> 
> This adds yet another library to be linked against all the modules.

How hard would it be to modify 16845 as suggested in 16878 so that we
at least have a short term solution.

> Examples:
> 
> zdb_open -c things /tmp/newdb.db

I would use -A instead because it is what we tend to use for
associations and we might plausibly tie a database to other types in
the future.

It's a nice idea. Could be an interesting way to do completion caching.
Thinking of it from the perspective of cached variables, it is actually
quite similar to mapfile. The mapfile module could easily have been
implemented with a builtin. e.g:

zmapfile -c file /tmp/file

where $file would then be a scalar. And this might go on further with
other similar modules. This makes me think that perhaps we could add a
hook to typeset so all these things can be declared something like this:

e.g:
typeset -A things -S db -f /tmp/newdb
typeset string -S mapfile -f /tmp/file

Oliver

This e-mail and any attachment is for authorised use by the intended recipient(s) only.  It may contain proprietary material, confidential information and/or be subject to legal privilege.  It should not be copied, disclosed to, retained or used by, any other party.  If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender.  Thank you.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* db module
@ 2002-09-12  5:19 Clint Adams
  0 siblings, 0 replies; 11+ messages in thread
From: Clint Adams @ 2002-09-12  5:19 UTC (permalink / raw)
  To: zsh-workers

This allows one to "tie" a Berkeley DB to an associative array (or is
that the other way around?)

I'm using two hacks.  The 'extradata' field in struct hashtable holds the
db handle for that assoc array.  Unfortunately, this doesn't seem to be
available from the set and unset functions for the individual elements,
so I had to use a static variable.  That means that the last DB to be
opened is the only one that be modified.  How can this be handled
sanely?

Other notes:

configure only checks for DB 4.0, and only as libdb-4.
There is not yet an option to set db type, so one is stuck with Hash.
On the other hand, it will happily read existing BTree, Recno, Queue.
Values can only be strings.
Records are deleted by unsetting the element.
The DB is closed by unsetting the assoc. array.
If HAVE_DB_H isn't defined, the compile will break.
This adds yet another library to be linked against all the modules.

Examples:

zdb_open -c things /tmp/newdb.db
things[one]=alpha
things[two]=beta
things[three]=gamma
unset "things[two]"
unset things
print ${(kv)things}
zdb_open things /tmp/newdb.db
print ${(kv)things}


zdb_open spamwords ~/.bogofilter/spamlist.db
print ${(kv)spamwords}
unset spamwords


Index: zshconfig.ac
===================================================================
RCS file: /cvsroot/zsh/zsh/zshconfig.ac,v
retrieving revision 1.28
diff -u -r1.28 zshconfig.ac
--- zshconfig.ac	6 May 2002 14:50:11 -0000	1.28
+++ zshconfig.ac	12 Sep 2002 04:55:45 -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 langinfo.h)
+		 netinet/in_systm.h pcre.h langinfo.h db.h)
 if test $dynamic = yes; then
   AC_CHECK_HEADERS(dlfcn.h)
   AC_CHECK_HEADERS(dl.h)
@@ -657,6 +657,7 @@
 
 dnl pcre-config should probably be employed here
 AC_SEARCH_LIBS(pcre_compile, pcre)
+AC_SEARCH_LIBS(db_create_4000, db-4)
 
 dnl ---------------------
 dnl CHECK TERMCAP LIBRARY
Index: Src/zsh.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v
retrieving revision 1.42
diff -u -r1.42 zsh.h
--- Src/zsh.h	3 Sep 2002 09:33:37 -0000	1.42
+++ Src/zsh.h	12 Sep 2002 04:55:50 -0000
@@ -825,6 +825,8 @@
     ScanFunc printnode;		/* pointer to function to print a node        */
     ScanTabFunc scantab;	/* pointer to function to scan table          */
 
+    void *extradata;
+
 #ifdef HASHTABLE_INTERNAL_MEMBERS
     HASHTABLE_INTERNAL_MEMBERS	/* internal use in hashtable.c                */
 #endif
Index: Src/Modules/db.c
===================================================================
RCS file: Src/Modules/db.c
diff -N Src/Modules/db.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Src/Modules/db.c	12 Sep 2002 04:55:51 -0000
@@ -0,0 +1,326 @@
+/*
+ * db.c - associative array interface to Berkeley DB
+ *
+ * This file is part of zsh, the Z shell.
+ *
+ * Copyright (c) 2002 by 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 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 Clint Adams and the Zsh Development Group have been advised of
+ * the possibility of such damage.
+ *
+ * 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 Clint Adams and the
+ * Zsh Development Group have no obligation to provide maintenance,
+ * support, updates, enhancements, or modifications. 
+ *
+ */
+
+#include "db.mdh"
+#include "db.pro"
+
+static char db_nam[] = "db";
+
+#ifdef HAVE_DB_H
+
+#include <db.h>
+static DB *kludge = NULL;
+
+/* Empty dummy function for special hash parameters. */
+
+/**/
+static void
+shempty(void)
+{
+}
+
+/* Create the special hash parameter. */
+
+static Param
+createdbhashvar(char *param_name, DB *h)
+{
+    Param pm;
+    HashTable ht;
+
+    unsetparam(param_name);
+
+    if (!(pm = createparam(param_name, 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 = setdbentries;
+    pm->unsetfn = dbunsetfn;
+    pm->u.hash = ht = newhashtable(7, param_name, NULL);
+
+    ht->hash        = hasher;
+    ht->emptytable  = (TableFunc) shempty;
+    ht->filltable   = NULL;
+    ht->addnode     = (AddNodeFunc) shempty;
+    ht->getnode     = ht->getnode2 = getdbentry;
+    ht->removenode  = (RemoveNodeFunc) shempty;
+    ht->disablenode = NULL;
+    ht->enablenode  = NULL;
+    ht->freenode    = (FreeNodeFunc) shempty;
+    ht->printnode   = printparamnode;
+    ht->scantab     = scandatabase;
+    ht->extradata   = (void *)h;
+    kludge = h;
+
+    return pm;
+}
+
+/* Functions for the options special parameter. */
+
+/**/
+static void
+setdbentries(Param pm, HashTable ht)
+{
+    int i;
+    HashNode hn;
+
+    if (!ht)
+	return;
+
+    if (!(pm->flags & PM_READONLY))
+	for (i = 0; i < ht->hsize; i++)
+	    for (hn = ht->nodes[i]; hn; hn = hn->next) {
+		struct value v;
+
+		v.isarr = v.inv = v.start = 0;
+		v.end = -1;
+		v.arr = NULL;
+		v.pm = (Param) hn;
+
+		setdbentry(v.pm, ztrdup(getstrvalue(&v)));
+	    }
+    deleteparamtable(ht);
+}
+
+/**/
+static void
+unsetdbentry(Param pm, int exp)
+{
+    DB *h;
+    DBT key;
+    int ret;
+    char *fieldname = ztrdup(pm->nam);
+
+    h = kludge;
+
+    unmetafy(fieldname, &ret);
+
+    memset(&key, 0, sizeof(DBT));
+
+    key.data = fieldname;
+    key.size = strlen(fieldname) + 1;
+
+    if ((ret = h->del(h, NULL, &key, 0)))
+	h->err(h, ret, "db unset: %s", fieldname);
+
+    free(fieldname);
+    pm->flags |= PM_UNSET;
+}
+
+/**/
+static HashNode
+getdbentry(HashTable ht, char *name)
+{
+    DB *h;
+    DBT key;
+    DBT val;
+    int ret;
+
+    Param pm = NULL;
+
+    h = (DB *)ht->extradata;
+
+    pm = (Param) zhalloc(sizeof(struct param));
+    pm->nam = dupstring(name);
+    pm->flags = PM_SCALAR;
+    pm->sets.cfn = setdbentry;
+    pm->gets.cfn = strgetfn;
+    pm->unsetfn = unsetdbentry;
+    pm->ct = 0;
+    pm->env = NULL;
+    pm->ename = NULL;
+    pm->old = NULL;
+    pm->level = 0;
+
+    memset(&key, 0, sizeof(DBT));
+    memset(&val, 0, sizeof(DBT));
+
+    key.data = name;
+    key.size = strlen(name);
+
+    ret = h->get(h, NULL, &key, &val, 0);
+
+    if (ret == 0) {
+	pm->u.str = (char *)val.data;
+    }
+    else {
+	pm->u.str = "";
+	pm->flags |= PM_UNSET;
+	if (ret != DB_NOTFOUND) { h->err(h, ret, "db get: %s", name); }
+    }
+
+    return (HashNode) pm;
+}
+
+/**/
+static void
+setdbentry(Param pm, char *value)
+{
+    DB *h;
+    DBT key;
+    DBT val;
+    int ret;
+
+    h = kludge;
+
+    memset(&key, 0, sizeof(DBT));
+    memset(&val, 0, sizeof(DBT));
+
+    key.data = pm->nam;
+    key.size = strlen(pm->nam) + 1;
+
+    val.data = value;
+    val.size = strlen(value) + 1;
+
+    ret = h->put(h, NULL, &key, &val, 0);
+
+}
+
+/**/
+static void
+scandatabase(HashTable ht, ScanFunc func, int flags)
+{
+    struct param pm;
+
+    DB *h;
+    DBC *cursor;
+    DBT key, value;
+    int ret;
+
+    pm.flags = PM_SCALAR;
+    pm.sets.cfn = setdbentry;
+    pm.gets.cfn = strgetfn;
+    pm.unsetfn = unsetdbentry;
+    pm.ct = 0;
+    pm.env = NULL;
+    pm.ename = NULL;
+    pm.old = NULL;
+    pm.level = 0;
+
+    h = (DB *)ht->extradata;
+
+    if ((ret = h->cursor(h, NULL, &cursor, 0))) {
+	return;
+    }
+
+    memset(&key, 0, sizeof(DBT));
+    memset(&value, 0, sizeof(DBT));
+
+    while ((ret = cursor->c_get (cursor, &key, &value, DB_NEXT)) == 0) {
+	pm.nam = dupstring((char *)key.data);
+	pm.u.str = dupstring((char *)value.data);
+	func((HashNode) &pm, flags);
+    }
+
+}
+
+/**/
+mod_export void
+dbunsetfn(Param pm, int exp)
+{
+    DB *h;
+
+    h = (DB *)pm->u.hash->extradata;
+
+    h->close(h, 0);
+    pm->flags |= PM_UNSET;
+}
+
+static int
+bin_zdb_open(char *nam, char **args, Options ops, int func)
+{
+    DB *h;
+    DBTYPE type = DB_UNKNOWN;
+    u_int32_t flags = 0;
+    int ret, mode = 0;
+    char *assoc, *filename;
+
+    assoc = args[0];
+    filename = args[1];
+
+    if (db_create(&h, NULL, 0)) {
+	zwarnnam(nam, "strange db error", NULL, 0);
+	return 1; 
+    }
+
+    if (OPT_ISSET(ops,'c')) {
+	    type = DB_HASH;
+	    flags = DB_CREATE;
+    }
+
+    if (OPT_ISSET(ops,'r')) {
+	    flags = DB_RDONLY;
+    }
+
+    if (OPT_HASARG(ops,'m')) {
+	    mode = (int)strtol(OPT_ARG(ops,'m'), NULL, 8);
+    }
+
+    ret = h->open(h, filename, NULL, type, flags, mode);
+    if (ret || !createdbhashvar(assoc, h))
+	return 1;
+
+}
+
+#endif /* HAVE_DB_H */
+
+static struct builtin bintab[] = {
+	    BUILTIN("zdb_open", 0, bin_zdb_open, 2, 2, 0, "cm:r", 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/db.mdd
===================================================================
RCS file: Src/Modules/db.mdd
diff -N Src/Modules/db.mdd
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Src/Modules/db.mdd	12 Sep 2002 04:55:51 -0000
@@ -0,0 +1,7 @@
+name=zsh/db
+link=dynamic
+load=no
+
+autoparams="zdb_open"
+
+objects="db.o"


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2002-10-07 13:59 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-07 13:58 db module Oliver Kiddle
  -- strict thread matches above, loose matches on Subject: below --
2002-09-30 14:39 Oliver Kiddle
2002-10-02  7:37 ` Clint Adams
2002-10-06  5:32 ` Clint Adams
2002-10-06 12:24   ` Hans Dieter Pearcey
2002-10-06 16:46     ` Bart Schaefer
2002-10-06 17:03       ` Clint Adams
2002-10-06 17:14         ` Bart Schaefer
2002-10-06 17:31           ` Clint Adams
2002-10-06 20:19             ` Bart Schaefer
2002-09-12  5:19 Clint Adams

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).