1*cdf0e10cSrcweir#************************************************************************* 2*cdf0e10cSrcweir# 3*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir# 5*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir# 7*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir# 9*cdf0e10cSrcweir# This file is part of OpenOffice.org. 10*cdf0e10cSrcweir# 11*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir# only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir# 15*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir# 21*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir# version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir# <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir# for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir# 26*cdf0e10cSrcweir#************************************************************************* 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir 29*cdf0e10cSrcweirpackage pre2par::parameter; 30*cdf0e10cSrcweir 31*cdf0e10cSrcweiruse Cwd; 32*cdf0e10cSrcweiruse pre2par::files; 33*cdf0e10cSrcweiruse pre2par::globals; 34*cdf0e10cSrcweiruse pre2par::systemactions; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir############################################ 37*cdf0e10cSrcweir# Parameter Operations 38*cdf0e10cSrcweir############################################ 39*cdf0e10cSrcweir 40*cdf0e10cSrcweirsub usage 41*cdf0e10cSrcweir{ 42*cdf0e10cSrcweir print <<Ende; 43*cdf0e10cSrcweir--------------------------------------------------------- 44*cdf0e10cSrcweir$pre2par::globals::prog 45*cdf0e10cSrcweirThe following parameter are needed: 46*cdf0e10cSrcweir-s: path to the pre file 47*cdf0e10cSrcweir-o: path to the par file 48*cdf0e10cSrcweir-l: path to the ulf file (mlf or jlf file) 49*cdf0e10cSrcweir-v: log process (optional) 50*cdf0e10cSrcweir 51*cdf0e10cSrcweirExample: 52*cdf0e10cSrcweir 53*cdf0e10cSrcweirperl pre2par.pl -l test.mlf -s readme.pre -o readme.par -v 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir--------------------------------------------------------- 56*cdf0e10cSrcweirEnde 57*cdf0e10cSrcweir exit(-1); 58*cdf0e10cSrcweir} 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir##################################### 61*cdf0e10cSrcweir# Reading parameter 62*cdf0e10cSrcweir##################################### 63*cdf0e10cSrcweir 64*cdf0e10cSrcweirsub getparameter 65*cdf0e10cSrcweir{ 66*cdf0e10cSrcweir while ( $#ARGV >= 0 ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir my $param = shift(@ARGV); 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir if ($param eq "-s") { $pre2par::globals::prefilename = shift(@ARGV); } 71*cdf0e10cSrcweir elsif ($param eq "-o") { $pre2par::globals::parfilename = shift(@ARGV); } 72*cdf0e10cSrcweir elsif ($param eq "-l") { $pre2par::globals::langfilename = shift(@ARGV); } 73*cdf0e10cSrcweir elsif ($param eq "-v") { $pre2par::globals::logging = 1; } 74*cdf0e10cSrcweir else 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir print("\n*************************************\n"); 77*cdf0e10cSrcweir print("Sorry, unknown parameter: $param"); 78*cdf0e10cSrcweir print("\n*************************************\n"); 79*cdf0e10cSrcweir usage(); 80*cdf0e10cSrcweir exit(-1); 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir} 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir############################################ 86*cdf0e10cSrcweir# Controlling the fundamental parameter 87*cdf0e10cSrcweir# (required for every process) 88*cdf0e10cSrcweir############################################ 89*cdf0e10cSrcweir 90*cdf0e10cSrcweirsub control_parameter 91*cdf0e10cSrcweir{ 92*cdf0e10cSrcweir if ($pre2par::globals::prefilename eq "") 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir print "\n************************************************\n"; 95*cdf0e10cSrcweir print "Error: Name of the input file not set (-s)!"; 96*cdf0e10cSrcweir print "\n************************************************\n"; 97*cdf0e10cSrcweir usage(); 98*cdf0e10cSrcweir exit(-1); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir if ($pre2par::globals::parfilename eq "") 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir print "\n************************************************\n"; 104*cdf0e10cSrcweir print "Error: Name of the output file not set (-o)!"; 105*cdf0e10cSrcweir print "\n************************************************\n"; 106*cdf0e10cSrcweir usage(); 107*cdf0e10cSrcweir exit(-1); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir if (!($pre2par::globals::prefilename =~ /\.pre\s*$/)) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir print "\n************************************************\n"; 113*cdf0e10cSrcweir print "Error: Input file is no .pre file!"; 114*cdf0e10cSrcweir print "\n************************************************\n"; 115*cdf0e10cSrcweir usage(); 116*cdf0e10cSrcweir exit(-1); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir if (!($pre2par::globals::parfilename =~ /\.par\s*$/)) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir print "\n************************************************\n"; 122*cdf0e10cSrcweir print "Error: Output file is no .par file!"; 123*cdf0e10cSrcweir print "\n************************************************\n"; 124*cdf0e10cSrcweir usage(); 125*cdf0e10cSrcweir exit(-1); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir # The input file has to exist 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir pre2par::files::check_file($pre2par::globals::prefilename); 131*cdf0e10cSrcweir} 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir########################################################## 134*cdf0e10cSrcweir# The path parameters can be relative or absolute. 135*cdf0e10cSrcweir# This function creates absolute pathes. 136*cdf0e10cSrcweir########################################################## 137*cdf0e10cSrcweir 138*cdf0e10cSrcweirsub make_path_absolute 139*cdf0e10cSrcweir{ 140*cdf0e10cSrcweir my ($pathref) = @_; 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir if ( $pre2par::globals::isunix ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir if (!($$pathref =~ /^\s*\//)) # this is a relative unix path 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir $$pathref = cwd() . $pre2par::globals::separator . $$pathref; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir if ( $pre2par::globals::iswin ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir if (!($$pathref =~ /^\s*\w\:/)) # this is a relative windows path 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir $$pathref = cwd() . $pre2par::globals::separator . $$pathref; 155*cdf0e10cSrcweir $$pathref =~ s/\//\\/g; 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir $$pathref =~ s/\Q$pre2par::globals::separator\E\s*$//; # removing ending slashes 160*cdf0e10cSrcweir} 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir##################################### 163*cdf0e10cSrcweir# Writing parameter to shell 164*cdf0e10cSrcweir##################################### 165*cdf0e10cSrcweir 166*cdf0e10cSrcweirsub outputparameter 167*cdf0e10cSrcweir{ 168*cdf0e10cSrcweir $pre2par::globals::logging ? ($logoption = " -v") : ($logoption = ""); 169*cdf0e10cSrcweir print "\n$pre2par::globals::prog -l $pre2par::globals::langfilename -s $pre2par::globals::prefilename -o $pre2par::globals::parfilename$logoption\n"; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir# print "\n********************************************************\n"; 172*cdf0e10cSrcweir# print "This is $pre2par::globals::prog, version 1.0\n"; 173*cdf0e10cSrcweir# print "Input file: $pre2par::globals::prefilename\n"; 174*cdf0e10cSrcweir# print "Output file: $pre2par::globals::parfilename\n"; 175*cdf0e10cSrcweir# print "********************************************************\n"; 176*cdf0e10cSrcweir} 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir1; 179