1 | #!/usr/bin/perl -w
|
---|
2 |
|
---|
3 | ###########################################################################
|
---|
4 | #
|
---|
5 | # jdb2txt.pl -- convenience script to access JDBM datbases produced by Greenstone
|
---|
6 | #
|
---|
7 | # A component of the Greenstone digital library software
|
---|
8 | # from the New Zealand Digital Library Project at the
|
---|
9 | # University of Waikato, New Zealand.
|
---|
10 | #
|
---|
11 | # Copyright (C) 2012 New Zealand Digital Library Project
|
---|
12 | #
|
---|
13 | # This program is free software; you can redistribute it and/or modify
|
---|
14 | # it under the terms of the GNU General Public License as published by
|
---|
15 | # the Free Software Foundation; either version 2 of the License, or
|
---|
16 | # (at your option) any later version.
|
---|
17 | #
|
---|
18 | # This program is distributed in the hope that it will be useful,
|
---|
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
21 | # GNU General Public License for more details.
|
---|
22 | #
|
---|
23 | # You should have received a copy of the GNU General Public License
|
---|
24 | # along with this program; if not, write to the Free Software
|
---|
25 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
26 | #
|
---|
27 | ###########################################################################
|
---|
28 |
|
---|
29 |
|
---|
30 | # Wrapper script that gives similar command-line functionality to the
|
---|
31 | # db2txt and txt2db scripts available for GDBM databases
|
---|
32 |
|
---|
33 | # Save you having to type in the mouthful:
|
---|
34 | # java -cp $GSDLHOME/lib/java/jdbm.jar:$GSDLHOME/bin/java/JDBMWrapper.jar Jdb2Txt jdbm-file.jdb
|
---|
35 | #
|
---|
36 | # for Unix, or
|
---|
37 | #
|
---|
38 | # java -cp %GSDLHOME%\lib\java\jdbm.jar;$GSDLHOME\bin\java/\DBMWrapper.jar Jdb2Txt jdbm-file.jdb
|
---|
39 | #
|
---|
40 | # for Windows.
|
---|
41 |
|
---|
42 |
|
---|
43 |
|
---|
44 | BEGIN {
|
---|
45 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
46 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
47 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
48 | }
|
---|
49 |
|
---|
50 | use strict;
|
---|
51 | use util;
|
---|
52 |
|
---|
53 | use File::Basename;
|
---|
54 |
|
---|
55 | if (scalar(@ARGV) < 1 || scalar(@ARGV) > 2 || (scalar(@ARGV) == 2 && $ARGV[0] ne "-sort")) {
|
---|
56 | my ($progname,$dir) = &File::Basename::fileparse($0);
|
---|
57 |
|
---|
58 | print STDERR "Usage: $progname [-sort] file.jdb\n";
|
---|
59 | exit -1;
|
---|
60 | }
|
---|
61 |
|
---|
62 | my $jdbm_jar = &util::filename_cat($ENV{'GSDLHOME'},"lib","java","jdbm.jar");
|
---|
63 | my $jdbmwrapper_jar = &util::filename_cat($ENV{'GSDLHOME'},"bin","java","JDBMWrapper.jar");
|
---|
64 |
|
---|
65 |
|
---|
66 | my $classpath = &util::pathname_cat($jdbmwrapper_jar,$jdbm_jar);
|
---|
67 |
|
---|
68 | if ($^O eq "cygwin") {
|
---|
69 | # Away to run a java program, using a binary that is native to Windows, so need
|
---|
70 | # Windows directory and path separators
|
---|
71 |
|
---|
72 | $classpath = `cygpath -wp "$classpath"`;
|
---|
73 | chomp($classpath);
|
---|
74 | $classpath =~ s%\\%\\\\%g;
|
---|
75 | }
|
---|
76 |
|
---|
77 | #&util::envvar_prepend("CLASSPATH",$jdbm_jar);
|
---|
78 | #&util::envvar_prepend("CLASSPATH",$jdbmwrapper_jar);
|
---|
79 |
|
---|
80 | my $cmd = "java -cp \"$classpath\" Jdb2Txt " . join(" ", map {$_ = "\"$_\""} @ARGV);
|
---|
81 |
|
---|
82 | if (system($cmd)!=0) {
|
---|
83 | print STDERR "Error: Failed to run cmd\n $cmd\n";
|
---|
84 | print STDERR " $!\n";
|
---|
85 | exit -1;
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|