From owner-perl5-porters@nicoh.com Mon Apr 17 00:01:30 1995 Received: from africa.nicoh.com by metronet.com with SMTP id AA22871 (5.67a/IDA1.5hp); Sun, 16 Apr 1995 19:26:25 -0500 Return-Path: Received: by africa.nicoh.com (1.37.109.15/16.2) id AA171487161; Sun, 16 Apr 1995 20:06:01 -0400 Message-Id: <199504170001.BAA25092@mailhost.pipex.net> From: ian@pipex.net (Ian Phillipps) Date: Mon, 17 Apr 1995 01:01:30 +0100 In-Reply-To: <199504151554.SAA13174@office.elvisti.kiev.ua> X-Mailer: Mail User's Shell (7.2.4 2/2/92) To: perl5-porters@africa.nicoh.com Subject: Re: A few words about DBZ_File module for Perl5 Cc: "Andrew V. Stesin" Sender: owner-perl5-porters@nicoh.com List-Name: perl5-porters Precedence: bulk Status: OR "Andrew V. Stesin" wrote: > Dear Ian, > What I need is a DBZ_File module for Perl5. Ok, here it is (alpha 0.1 version). I've been promising myself that I'd delve into this XS stuff before long, and I just did. All I can say is - amazing! The work you guys have put in to facilitating interfacing C to perl is mind-boggling; I never dreamt it would be this easy. [Andrew - You need to put this into a new directory ext/DBZ_File in your Perl source tree, edit Makefile.PL to point to your dbz.{o,h}, run "perl Makefile.PL; make". Only tested with 5.001+ four first U/O patches] About the only problem I have is that "cc" (SunOS 4.1.3) thinks that if you do "cc -c /foo/bar.c" then the file that comes out is "bar.o", not "/foo/bar.o". MakeMaker's makefile thinks the latter. Maybe an explicit "-o" would be a good idea, since the current assumption isn't portable. Maybe I should use some other way of fetching precompiled object files? My first try (adding the name to the LIBS) didn't work. I've not got the ellipses quite right... they don't mix with the trick (copied from the NDBM_File) of using macros to fool the XS compiler about names and parameters. More CODE: sections, I guess. Tim - please change module state to "alpha". Ian PS - "typemap" doesn't figure below. Copy the NDBM_File's version, which already has a definition for DBZ_File in it. #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # DBZ_File.pm # DBZ_File.xs # MANIFEST # Makefile.PL # DBZ_File.pod # if test -f 'DBZ_File.pm' then echo shar: will not over-write existing file "'DBZ_File.pm'" else echo x - 'DBZ_File.pm' sed 's/^X//' >'DBZ_File.pm' << 'SHAR_EOF' Xpackage DBZ_File; X Xrequire Exporter; Xrequire DynaLoader; Xrequire AutoLoader; X Xuse Carp; X X@ISA = qw(Exporter AutoLoader DynaLoader); X# Items to export into callers namespace by default. Note: do not export X# names by default without a very good reason. Use EXPORT_OK instead. X# Do not simply export all your public functions/methods/constants. X Xbootstrap DBZ_File; X X# Preloaded methods go here. Xsub DELETE { X croak "DBZ_File::DELETE not implemented"; X} Xsub FIRSTKEY { X croak "DBZ_File::FIRSTKEY not implemented"; X} Xsub NEXTKEY { X croak "DBZ_File::NEXTKEY not implemented"; X} X X# Autoload methods go after __END__, and are processed by the autosplit program. X X1; X__END__ SHAR_EOF if test 677 -ne "`wc -c < 'DBZ_File.pm'`" then echo shar: error transmitting "'DBZ_File.pm'" '(should have been 677 characters)' fi fi if test -f 'DBZ_File.xs' then echo shar: will not over-write existing file "'DBZ_File.xs'" else echo x - 'DBZ_File.xs' sed 's/^X//' >'DBZ_File.xs' << 'SHAR_EOF' X#include "EXTERN.h" X#include "perl.h" X#include "XSUB.h" X X#include X Xtypedef char * DBZ_File; /* Actual type is irrelevant */ X#define dbz_FETCH(db,key) dbzfetch(key) X#define dbz_STORE(db,key,value) dbzstore(key,value) X XMODULE = DBZ_File PACKAGE = DBZ_File PREFIX = dbz_ X XDBZ_File Xdbz_TIEHASH(dbtype,filename...) X char * dbtype X char * filename X CODE: X { X RETVAL = (char*)0; X if ( !dbminit( filename ) ) X RETVAL = filename; X } X OUTPUT: X RETVAL X Xdatum Xdbz_FETCH(db,key) X char * db X datum key X Xint Xdbz_STORE(db,key,value...) X char * db X datum key X datum value X int flags X Xvoid Xdbz_DESTROY(db) X char * db X CODE: X dbmclose(); X SHAR_EOF if test 652 -ne "`wc -c < 'DBZ_File.xs'`" then echo shar: error transmitting "'DBZ_File.xs'" '(should have been 652 characters)' fi fi if test -f 'MANIFEST' then echo shar: will not over-write existing file "'MANIFEST'" else echo x - 'MANIFEST' sed 's/^X//' >'MANIFEST' << 'SHAR_EOF' XDBZ_File.pm XDBZ_File.xs XMANIFEST XMakefile.PL XDBZ_File.pod SHAR_EOF if test 58 -ne "`wc -c < 'MANIFEST'`" then echo shar: error transmitting "'MANIFEST'" '(should have been 58 characters)' fi fi if test -f 'Makefile.PL' then echo shar: will not over-write existing file "'Makefile.PL'" else echo x - 'Makefile.PL' sed 's/^X//' >'Makefile.PL' << 'SHAR_EOF' Xuse ExtUtils::MakeMaker; X# See lib/ExtUtils/MakeMaker.pm for details of how to influence X# the contents of the Makefile that is written. XWriteMakefile( X 'NAME' => 'DBZ_File', X 'VERSION' => '0.1', X 'LIBS' => [''], # e.g., '-lm' X 'OBJECT' => 'DBZ_File.o /usr/local/src/inn/1.4/dbz/dbz.o', # e.g., '-lm' X 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' X 'INC' => '-I/usr/local/src/inn/1.4/dbz', # e.g., '-I/usr/include/other' X); SHAR_EOF if test 454 -ne "`wc -c < 'Makefile.PL'`" then echo shar: error transmitting "'Makefile.PL'" '(should have been 454 characters)' fi fi if test -f 'DBZ_File.pod' then echo shar: will not over-write existing file "'DBZ_File.pod'" else echo x - 'DBZ_File.pod' sed 's/^X//' >'DBZ_File.pod' << 'SHAR_EOF' X=head1 NAME X XDBZ_File - Perl5 access to dbz X X=head1 SYNOPSIS X X use DBZ_File ; X X [$X =] tie %hash, DBZ_File, $filename; X X $status = $X->STORE($key, $value ); # !!UNTESTED!! X $offset = $X->FETCH($key ); X $offset = $hash{ $key . "\0" }; X X untie %hash ; X X=head1 DESCRIPTION X XB is a module which provides some access to B files. XAbout the only B file in use is the B file in a Usenet Xnews system. B has many limitations if used for anything else. This Xmodule has all those limitations and more. X XThis version of the module delivers what dbzperl delivers, which is a Xdirect interface to part of the dbz system. The inconvenience this Xoffers is shown by the example. Your dbzperl programs will still run - Xsee the second example. X XThe interface is to dbzfetch and dbzstore, not fetch and store. This is Xprobably what you want. X X=head1 BUGS X XSince B doesn't support DELETE, FIRSTKEY or NEXTKEY, this doesn't, Xeither (doing "keys %hash" on a news history file is pretty dumb, Xanyway :-). STORE is untested. Since B opens the history file and Xkeeps it to itself, we have to open it again. X XYou will need to modify the location of the dbz package in XB. If you have INN 1.4, this must be the unpatched version, Xsince Rich's patched one calls an INN utility routine. X XB can only open one file at a time. X XThe calls to other routines in the B package, notably those Xintended for creating and rebuilding B files, remain unimplemented. X X=head1 EXAMPLE X X use DBZ_File; X X tie %h,DBZ_File,'/usr/lib/news/history' or die $!; X open(H,'/usr/lib/news/history') or die $!; X X $z=$h{''."\0"}; X X if ( length $z ) X { seek(H,unpack('I',$z),0); $_=; print; } X X Xor: X X use AnyDBM_File; use DBZ_File; X unshift( @AnyDBM_File::ISA, DBZ_File ); X X dbmopen( %h, '/usr/lib/news/history', 0000 ) or die $!; X X X=head1 AVAILABILITY X XThis code is available for use under the same terms as B itself. X XThis describes an early alpha release (0.1, would you believe), which is Xavailable from the author, and was sent to the perl5-porters' mailing Xlist. Please do not place this version on public FTP sites: I'd like to Xtrack its use for the moment. X XThe code for dbz is distributed with C news and INN. You should use Xwhichever version of dbz you have in your news system. I used '3.2' to Xtest the code, which came with INN 1.4. If you don't have either of Xthese programs, you probably don't want this module :-) X X=head1 AUTHOR X XThe DBZ_File interface was written by Ian Phillipps . XThe dbz module has many names on it, and is copyright 1988 Jon Zeeff. SHAR_EOF if test 2655 -ne "`wc -c < 'DBZ_File.pod'`" then echo shar: error transmitting "'DBZ_File.pod'" '(should have been 2655 characters)' fi fi echo Done exit 0