source: main/trunk/greenstone2/bin/script/txt2jdb.pl@ 30499

Last change on this file since 30499 was 28663, checked in by ak19, 10 years ago

Fixing it up so the number of commandline arguments and the way they're handled match txt2db (gdb version).

  • Property svn:executable set to *
File size: 2.7 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# This script complements jdb2txt.pl by performing the reverse
34
35# Save you having to type in the mouthful:
36# (cat file.txt |) java -cp $GSDLHOME/lib/java/jdbm.jar:$GSDLHOME/bin/java/JDBMWrapper.jar Txt2Jdb jdbm-file.jdb
37#
38# for Unix, or
39#
40# (type file.txt |) java -cp %GSDLHOME%\lib\java\jdbm.jar;$GSDLHOME\bin\java/\DBMWrapper.jar Txt2Jdb jdbm-file.jdb
41#
42# for Windows.
43
44
45
46BEGIN {
47 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
48 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
49 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
50}
51
52use strict;
53use util;
54
55use File::Basename;
56
57if (scalar(@ARGV) != 1) {
58 my ($progname,$dir) = &File::Basename::fileparse($0);
59
60 print STDERR "Usage: $progname infile.txt outfile.jdb\n";
61 exit -1;
62}
63
64my $jdbm_jar = &util::filename_cat($ENV{'GSDLHOME'},"lib","java","jdbm.jar");
65my $jdbmwrapper_jar = &util::filename_cat($ENV{'GSDLHOME'},"bin","java","JDBMWrapper.jar");
66
67
68my $classpath = &util::pathname_cat($jdbmwrapper_jar,$jdbm_jar);
69
70if ($^O eq "cygwin") {
71 # Away to run a java program, using a binary that is native to Windows, so need
72 # Windows directory and path separators
73
74 $classpath = `cygpath -wp "$classpath"`;
75 chomp($classpath);
76 $classpath =~ s%\\%\\\\%g;
77}
78
79my $cmd = "java -cp \"$classpath\" Txt2Jdb ".$ARGV[0];
80
81if (system($cmd)!=0) {
82 print STDERR "Error: Failed to run cmd\n $cmd\n";
83 print STDERR " $!\n";
84 exit -1;
85}
86
87
Note: See TracBrowser for help on using the repository browser.