diff options
| author | Mark Murray <markm@FreeBSD.org> | 1998-09-09 07:00:04 +0000 | 
|---|---|---|
| committer | Mark Murray <markm@FreeBSD.org> | 1998-09-09 07:00:04 +0000 | 
| commit | ff6b7ba98e8d4aab04cbe2bfdffdfc9171c1812b (patch) | |
| tree | 58b20e81687d6d5931f120b50802ed21225bf440 /contrib/perl5/ext/GDBM_File | |
Diffstat (limited to 'contrib/perl5/ext/GDBM_File')
| -rw-r--r-- | contrib/perl5/ext/GDBM_File/GDBM_File.pm | 87 | ||||
| -rw-r--r-- | contrib/perl5/ext/GDBM_File/GDBM_File.xs | 243 | ||||
| -rw-r--r-- | contrib/perl5/ext/GDBM_File/Makefile.PL | 8 | ||||
| -rw-r--r-- | contrib/perl5/ext/GDBM_File/typemap | 27 | 
4 files changed, 365 insertions, 0 deletions
| diff --git a/contrib/perl5/ext/GDBM_File/GDBM_File.pm b/contrib/perl5/ext/GDBM_File/GDBM_File.pm new file mode 100644 index 0000000000000..09df4373fb658 --- /dev/null +++ b/contrib/perl5/ext/GDBM_File/GDBM_File.pm @@ -0,0 +1,87 @@ +# GDBM_File.pm -- Perl 5 interface to GNU gdbm library. + +=head1 NAME + +GDBM_File - Perl5 access to the gdbm library. + +=head1 SYNOPSIS + +    use GDBM_File ; +    tie %hash, 'GDBM_File', $filename, &GDBM_WRCREAT, 0640; +    # Use the %hash array. +    untie %hash ; + +=head1 DESCRIPTION + +B<GDBM_File> is a module which allows Perl programs to make use of the +facilities provided by the GNU gdbm library.  If you intend to use this +module you should really have a copy of the gdbm manualpage at hand. + +Most of the libgdbm.a functions are available through the GDBM_File +interface. + +=head1 AVAILABILITY + +Gdbm is available from any GNU archive.  The master site is +C<prep.ai.mit.edu>, but your are strongly urged to use one of the many +mirrors.   You can obtain a list of mirror sites by issuing the +command	C<finger fsf@prep.ai.mit.edu>. + +=head1 BUGS + +The available functions and the gdbm/perl interface need to be documented. + +=head1 SEE ALSO + +L<perl(1)>, L<DB_File(3)>.  + +=cut + +package GDBM_File; + +use strict; +use vars qw($VERSION @ISA @EXPORT $AUTOLOAD); + +require Carp; +require Tie::Hash; +require Exporter; +use AutoLoader; +require DynaLoader; +@ISA = qw(Tie::Hash Exporter DynaLoader); +@EXPORT = qw( +	GDBM_CACHESIZE +	GDBM_FAST +	GDBM_INSERT +	GDBM_NEWDB +	GDBM_READER +	GDBM_REPLACE +	GDBM_WRCREAT +	GDBM_WRITER +); + +$VERSION = "1.00"; + +sub AUTOLOAD { +    my($constname); +    ($constname = $AUTOLOAD) =~ s/.*:://; +    my $val = constant($constname, @_ ? $_[0] : 0); +    if ($! != 0) { +	if ($! =~ /Invalid/) { +	    $AutoLoader::AUTOLOAD = $AUTOLOAD; +	    goto &AutoLoader::AUTOLOAD; +	} +	else { +	    Carp::croak("Your vendor has not defined GDBM_File macro $constname, used"); +	} +    } +    eval "sub $AUTOLOAD { $val }"; +    goto &$AUTOLOAD; +} + +bootstrap GDBM_File $VERSION; + +# Preloaded methods go here.  Autoload methods go after __END__, and are +# processed by the autosplit program. + +1; +__END__ diff --git a/contrib/perl5/ext/GDBM_File/GDBM_File.xs b/contrib/perl5/ext/GDBM_File/GDBM_File.xs new file mode 100644 index 0000000000000..ac1ca8c68d9b4 --- /dev/null +++ b/contrib/perl5/ext/GDBM_File/GDBM_File.xs @@ -0,0 +1,243 @@ +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +#include <gdbm.h> +#include <fcntl.h> + +typedef GDBM_FILE GDBM_File; + +#define GDBM_BLOCKSIZE 0 /* gdbm defaults to stat blocksize */ +#define gdbm_TIEHASH(dbtype, name, read_write, mode, fatal_func) \ +	gdbm_open(name, GDBM_BLOCKSIZE, read_write, mode, fatal_func) + +#define gdbm_FETCH(db,key)			gdbm_fetch(db,key) +#define gdbm_STORE(db,key,value,flags)		gdbm_store(db,key,value,flags) +#define gdbm_DELETE(db,key)			gdbm_delete(db,key) +#define gdbm_FIRSTKEY(db)			gdbm_firstkey(db) +#define gdbm_NEXTKEY(db,key)			gdbm_nextkey(db,key) +#define gdbm_EXISTS(db,key)			gdbm_exists(db,key) + +typedef datum gdatum; + +typedef void (*FATALFUNC)(); + +static int +not_here(char *s) +{ +    croak("GDBM_File::%s not implemented on this architecture", s); +    return -1; +} + +/* Versions of gdbm prior to 1.7x might not have the gdbm_sync, +   gdbm_exists, and gdbm_setopt functions.  Apparently Slackware +   (Linux) 2.1 contains gdbm-1.5 (which dates back to 1991). +*/ +#ifndef GDBM_FAST +#define gdbm_exists(db,key) not_here("gdbm_exists") +#define gdbm_sync(db) (void) not_here("gdbm_sync") +#define gdbm_setopt(db,optflag,optval,optlen) not_here("gdbm_setopt") +#endif + +static double +constant(char *name, int arg) +{ +    errno = 0; +    switch (*name) { +    case 'A': +	break; +    case 'B': +	break; +    case 'C': +	break; +    case 'D': +	break; +    case 'E': +	break; +    case 'F': +	break; +    case 'G': +	if (strEQ(name, "GDBM_CACHESIZE")) +#ifdef GDBM_CACHESIZE +	    return GDBM_CACHESIZE; +#else +	    goto not_there; +#endif +	if (strEQ(name, "GDBM_FAST")) +#ifdef GDBM_FAST +	    return GDBM_FAST; +#else +	    goto not_there; +#endif +	if (strEQ(name, "GDBM_FASTMODE")) +#ifdef GDBM_FASTMODE +	    return GDBM_FASTMODE; +#else +	    goto not_there; +#endif +	if (strEQ(name, "GDBM_INSERT")) +#ifdef GDBM_INSERT +	    return GDBM_INSERT; +#else +	    goto not_there; +#endif +	if (strEQ(name, "GDBM_NEWDB")) +#ifdef GDBM_NEWDB +	    return GDBM_NEWDB; +#else +	    goto not_there; +#endif +	if (strEQ(name, "GDBM_READER")) +#ifdef GDBM_READER +	    return GDBM_READER; +#else +	    goto not_there; +#endif +	if (strEQ(name, "GDBM_REPLACE")) +#ifdef GDBM_REPLACE +	    return GDBM_REPLACE; +#else +	    goto not_there; +#endif +	if (strEQ(name, "GDBM_WRCREAT")) +#ifdef GDBM_WRCREAT +	    return GDBM_WRCREAT; +#else +	    goto not_there; +#endif +	if (strEQ(name, "GDBM_WRITER")) +#ifdef GDBM_WRITER +	    return GDBM_WRITER; +#else +	    goto not_there; +#endif +	break; +    case 'H': +	break; +    case 'I': +	break; +    case 'J': +	break; +    case 'K': +	break; +    case 'L': +	break; +    case 'M': +	break; +    case 'N': +	break; +    case 'O': +	break; +    case 'P': +	break; +    case 'Q': +	break; +    case 'R': +	break; +    case 'S': +	break; +    case 'T': +	break; +    case 'U': +	break; +    case 'V': +	break; +    case 'W': +	break; +    case 'X': +	break; +    case 'Y': +	break; +    case 'Z': +	break; +    } +    errno = EINVAL; +    return 0; + +not_there: +    errno = ENOENT; +    return 0; +} + +MODULE = GDBM_File	PACKAGE = GDBM_File	PREFIX = gdbm_ + +double +constant(name,arg) +	char *		name +	int		arg + + +GDBM_File +gdbm_TIEHASH(dbtype, name, read_write, mode, fatal_func = (FATALFUNC)croak) +	char *		dbtype +	char *		name +	int		read_write +	int		mode +	FATALFUNC	fatal_func + +void +gdbm_close(db) +	GDBM_File	db +	CLEANUP: + +void +gdbm_DESTROY(db) +	GDBM_File	db +	CODE: +	gdbm_close(db); + +gdatum +gdbm_FETCH(db, key) +	GDBM_File	db +	datum		key + +int +gdbm_STORE(db, key, value, flags = GDBM_REPLACE) +	GDBM_File	db +	datum		key +	datum		value +	int		flags +    CLEANUP: +	if (RETVAL) { +	    if (RETVAL < 0 && errno == EPERM) +		croak("No write permission to gdbm file"); +	    croak("gdbm store returned %d, errno %d, key \"%.*s\"", +			RETVAL,errno,key.dsize,key.dptr); +	    /* gdbm_clearerr(db); */ +	} + +int +gdbm_DELETE(db, key) +	GDBM_File	db +	datum		key + +gdatum +gdbm_FIRSTKEY(db) +	GDBM_File	db + +gdatum +gdbm_NEXTKEY(db, key) +	GDBM_File	db +	datum		key + +int +gdbm_reorganize(db) +	GDBM_File	db + + +void +gdbm_sync(db) +	GDBM_File	db + +int +gdbm_EXISTS(db, key) +	GDBM_File	db +	datum		key + +int +gdbm_setopt (db, optflag, optval, optlen) +	GDBM_File	db +	int		optflag +	int		&optval +	int		optlen + diff --git a/contrib/perl5/ext/GDBM_File/Makefile.PL b/contrib/perl5/ext/GDBM_File/Makefile.PL new file mode 100644 index 0000000000000..d24461350b615 --- /dev/null +++ b/contrib/perl5/ext/GDBM_File/Makefile.PL @@ -0,0 +1,8 @@ +use ExtUtils::MakeMaker; +WriteMakefile( +    NAME => 'GDBM_File', +    LIBS => ["-L/usr/local/lib -lgdbm", "-ldbm"], +    MAN3PODS 	=> ' ', 	# Pods will be built by installman. +    XSPROTOARG => '-noprototypes', 		# XXX remove later? +    VERSION_FROM => 'GDBM_File.pm', +); diff --git a/contrib/perl5/ext/GDBM_File/typemap b/contrib/perl5/ext/GDBM_File/typemap new file mode 100644 index 0000000000000..317a8f3886cb6 --- /dev/null +++ b/contrib/perl5/ext/GDBM_File/typemap @@ -0,0 +1,27 @@ +# +#################################### DBM SECTION +# + +datum			T_DATUM +gdatum			T_GDATUM +NDBM_File		T_PTROBJ +GDBM_File		T_PTROBJ +SDBM_File		T_PTROBJ +ODBM_File		T_PTROBJ +DB_File			T_PTROBJ +DBZ_File		T_PTROBJ +FATALFUNC		T_OPAQUEPTR + +INPUT +T_DATUM +	$var.dptr = SvPV($arg, PL_na); +	$var.dsize = (int)PL_na; +T_GDATUM +	UNIMPLEMENTED +OUTPUT +T_DATUM +	sv_setpvn($arg, $var.dptr, $var.dsize); +T_GDATUM +	sv_usepvn($arg, $var.dptr, $var.dsize); +T_PTROBJ +        sv_setref_pv($arg, dbtype, (void*)$var); | 
