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

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

Adding a script that does the reverse of jdb2txt.pl. Needed for using diffcol on GS3 model collections

  • Property svn:executable set to *
File size: 2.9 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
79#&util::envvar_prepend("CLASSPATH",$jdbm_jar);
80#&util::envvar_prepend("CLASSPATH",$jdbmwrapper_jar);
81
82my $cmd = ($ENV{'GSDLOS'} =~ m/windows/) ? "type" : "cat";
83$cmd .= " $ARGV[0] | java -cp \"$classpath\" Txt2Jdb ".$ARGV[1];
84
85if (system($cmd)!=0) {
86 print STDERR "Error: Failed to run cmd\n $cmd\n";
87 print STDERR " $!\n";
88 exit -1;
89}
90
91
Note: See TracBrowser for help on using the repository browser.