httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug MacEachern <do...@pobox.com>
Subject Re: [PATCH] dbmmanage, command-line arg for use of specific DB libraries.
Date Fri, 05 Mar 1999 18:19:04 GMT
At 12:44 PM 3/3/99 -0800, Brian Behlendorf wrote:
>
>This patch allows for a simple "-f format" argument on the command line,
>which tells dbmmanage what DBM library to use (through Perl).  I'm not the
>worlds best perl programmer, so Doug et al. have a look, particularly on
>the eval() it looks like I needed to add.  The addition of this
>command-line arg removes the need to edit dbmmanage itself to use a
>specific DB library.

I'd suggest the patch below, which avoids eval(), uses Getopt::Std (may
wish to extend more in the future), and cures a precedence bug in the tie()
call. 
You might want to add some sanity checking on $opts{'f'} to make sure it is
a valid %format.

-Doug

--- dbmmanage   1999/01/01 19:05:33     1.13
+++ dbmmanage   1999/03/05 18:18:24
@@ -61,11 +61,22 @@
 # usage: dbmmanage <DBMfile> <command> <key> <value>
 
 package dbmmanage;
-#                               -ldb    -lndbm    -lgdbm
-BEGIN { @AnyDBM_File::ISA = qw(DB_File NDBM_File GDBM_File) }
+
 use strict;
 use Fcntl;
-use AnyDBM_File ();
+use Getopt::Std;
+
+# shorthand-to-real-name lookup
+my %formats = ( "db", "DB_File",
+                "ndbm", "NDBM_File",
+                "gdbm", "GDBM_File" );
+
+my %opts;
+getopt 'f:', \%opts;
+if (my $dbm_class = $formats{$opts{'f'}}) {
+    @AnyDBM_File::ISA = ($dbm_class);
+}
+require AnyDBM_File;
 
 my($file,$command,$key,$crypted_pwd) = @ARGV;
 
@@ -91,7 +102,7 @@
 my($mode, $flags) = $command =~ 
     /^(?:view|check)$/ ? (0644, O_RDONLY) : (0644, O_RDWR|O_CREAT);
 
-tie %DB, "AnyDBM_File", $file, $flags, $mode || die "Can't tie $file: $!";
+tie %DB, "AnyDBM_File", $file, $flags, $mode or die "Can't tie $file: $!";
 dbmc->$command();
 untie %DB;
 


Mime
View raw message