source: main/trunk/greenstone2/bin/script/jdb2txt.pl@ 28402

Last change on this file since 28402 was 28402, checked in by davidb, 11 years ago

Changes to support running these scripts from Cygwin

  • Property svn:executable set to *
File size: 2.8 KB
Line 
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
44BEGIN {
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
50use strict;
51use util;
52
53use File::Basename;
54
55if (scalar(@ARGV)==0) {
56 my ($progname,$dir) = &File::Basename::fileparse($0);
57
58 print STDERR "Usage: $progname file.jdb\n";
59 exit -1;
60}
61
62my $jdbm_jar = &util::filename_cat($ENV{'GSDLHOME'},"lib","java","jdbm.jar");
63my $jdbmwrapper_jar = &util::filename_cat($ENV{'GSDLHOME'},"bin","java","JDBMWrapper.jar");
64
65
66my $classpath = &util::pathname_cat($jdbmwrapper_jar,$jdbm_jar);
67
68if ($^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
80my $cmd = "java -cp \"$classpath\" Jdb2Txt " . join(" ", map {$_ = "\"$_\""} @ARGV);
81
82if (system($cmd)!=0) {
83 print STDERR "Error: Failed to run cmd\n $cmd\n";
84 print STDERR " $!\n";
85 exit -1;
86}
87
88
Note: See TracBrowser for help on using the repository browser.