1*9780544fSAndrew Rist#************************************************************** 2*9780544fSAndrew Rist# 3*9780544fSAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 4*9780544fSAndrew Rist# or more contributor license agreements. See the NOTICE file 5*9780544fSAndrew Rist# distributed with this work for additional information 6*9780544fSAndrew Rist# regarding copyright ownership. The ASF licenses this file 7*9780544fSAndrew Rist# to you under the Apache License, Version 2.0 (the 8*9780544fSAndrew Rist# "License"); you may not use this file except in compliance 9*9780544fSAndrew Rist# with the License. You may obtain a copy of the License at 10*9780544fSAndrew Rist# 11*9780544fSAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 12*9780544fSAndrew Rist# 13*9780544fSAndrew Rist# Unless required by applicable law or agreed to in writing, 14*9780544fSAndrew Rist# software distributed under the License is distributed on an 15*9780544fSAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9780544fSAndrew Rist# KIND, either express or implied. See the License for the 17*9780544fSAndrew Rist# specific language governing permissions and limitations 18*9780544fSAndrew Rist# under the License. 19*9780544fSAndrew Rist# 20*9780544fSAndrew Rist#************************************************************** 21*9780544fSAndrew Rist 22*9780544fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir 25cdf0e10cSrcweirpackage pre2par::parameter; 26cdf0e10cSrcweir 27cdf0e10cSrcweiruse Cwd; 28cdf0e10cSrcweiruse pre2par::files; 29cdf0e10cSrcweiruse pre2par::globals; 30cdf0e10cSrcweiruse pre2par::systemactions; 31cdf0e10cSrcweir 32cdf0e10cSrcweir############################################ 33cdf0e10cSrcweir# Parameter Operations 34cdf0e10cSrcweir############################################ 35cdf0e10cSrcweir 36cdf0e10cSrcweirsub usage 37cdf0e10cSrcweir{ 38cdf0e10cSrcweir print <<Ende; 39cdf0e10cSrcweir--------------------------------------------------------- 40cdf0e10cSrcweir$pre2par::globals::prog 41cdf0e10cSrcweirThe following parameter are needed: 42cdf0e10cSrcweir-s: path to the pre file 43cdf0e10cSrcweir-o: path to the par file 44cdf0e10cSrcweir-l: path to the ulf file (mlf or jlf file) 45cdf0e10cSrcweir-v: log process (optional) 46cdf0e10cSrcweir 47cdf0e10cSrcweirExample: 48cdf0e10cSrcweir 49cdf0e10cSrcweirperl pre2par.pl -l test.mlf -s readme.pre -o readme.par -v 50cdf0e10cSrcweir 51cdf0e10cSrcweir--------------------------------------------------------- 52cdf0e10cSrcweirEnde 53cdf0e10cSrcweir exit(-1); 54cdf0e10cSrcweir} 55cdf0e10cSrcweir 56cdf0e10cSrcweir##################################### 57cdf0e10cSrcweir# Reading parameter 58cdf0e10cSrcweir##################################### 59cdf0e10cSrcweir 60cdf0e10cSrcweirsub getparameter 61cdf0e10cSrcweir{ 62cdf0e10cSrcweir while ( $#ARGV >= 0 ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir my $param = shift(@ARGV); 65cdf0e10cSrcweir 66cdf0e10cSrcweir if ($param eq "-s") { $pre2par::globals::prefilename = shift(@ARGV); } 67cdf0e10cSrcweir elsif ($param eq "-o") { $pre2par::globals::parfilename = shift(@ARGV); } 68cdf0e10cSrcweir elsif ($param eq "-l") { $pre2par::globals::langfilename = shift(@ARGV); } 69cdf0e10cSrcweir elsif ($param eq "-v") { $pre2par::globals::logging = 1; } 70cdf0e10cSrcweir else 71cdf0e10cSrcweir { 72cdf0e10cSrcweir print("\n*************************************\n"); 73cdf0e10cSrcweir print("Sorry, unknown parameter: $param"); 74cdf0e10cSrcweir print("\n*************************************\n"); 75cdf0e10cSrcweir usage(); 76cdf0e10cSrcweir exit(-1); 77cdf0e10cSrcweir } 78cdf0e10cSrcweir } 79cdf0e10cSrcweir} 80cdf0e10cSrcweir 81cdf0e10cSrcweir############################################ 82cdf0e10cSrcweir# Controlling the fundamental parameter 83cdf0e10cSrcweir# (required for every process) 84cdf0e10cSrcweir############################################ 85cdf0e10cSrcweir 86cdf0e10cSrcweirsub control_parameter 87cdf0e10cSrcweir{ 88cdf0e10cSrcweir if ($pre2par::globals::prefilename eq "") 89cdf0e10cSrcweir { 90cdf0e10cSrcweir print "\n************************************************\n"; 91cdf0e10cSrcweir print "Error: Name of the input file not set (-s)!"; 92cdf0e10cSrcweir print "\n************************************************\n"; 93cdf0e10cSrcweir usage(); 94cdf0e10cSrcweir exit(-1); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir if ($pre2par::globals::parfilename eq "") 98cdf0e10cSrcweir { 99cdf0e10cSrcweir print "\n************************************************\n"; 100cdf0e10cSrcweir print "Error: Name of the output file not set (-o)!"; 101cdf0e10cSrcweir print "\n************************************************\n"; 102cdf0e10cSrcweir usage(); 103cdf0e10cSrcweir exit(-1); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir if (!($pre2par::globals::prefilename =~ /\.pre\s*$/)) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir print "\n************************************************\n"; 109cdf0e10cSrcweir print "Error: Input file is no .pre file!"; 110cdf0e10cSrcweir print "\n************************************************\n"; 111cdf0e10cSrcweir usage(); 112cdf0e10cSrcweir exit(-1); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir if (!($pre2par::globals::parfilename =~ /\.par\s*$/)) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir print "\n************************************************\n"; 118cdf0e10cSrcweir print "Error: Output file is no .par file!"; 119cdf0e10cSrcweir print "\n************************************************\n"; 120cdf0e10cSrcweir usage(); 121cdf0e10cSrcweir exit(-1); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir # The input file has to exist 125cdf0e10cSrcweir 126cdf0e10cSrcweir pre2par::files::check_file($pre2par::globals::prefilename); 127cdf0e10cSrcweir} 128cdf0e10cSrcweir 129cdf0e10cSrcweir########################################################## 130cdf0e10cSrcweir# The path parameters can be relative or absolute. 131cdf0e10cSrcweir# This function creates absolute pathes. 132cdf0e10cSrcweir########################################################## 133cdf0e10cSrcweir 134cdf0e10cSrcweirsub make_path_absolute 135cdf0e10cSrcweir{ 136cdf0e10cSrcweir my ($pathref) = @_; 137cdf0e10cSrcweir 138cdf0e10cSrcweir if ( $pre2par::globals::isunix ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir if (!($$pathref =~ /^\s*\//)) # this is a relative unix path 141cdf0e10cSrcweir { 142cdf0e10cSrcweir $$pathref = cwd() . $pre2par::globals::separator . $$pathref; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir if ( $pre2par::globals::iswin ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir if (!($$pathref =~ /^\s*\w\:/)) # this is a relative windows path 149cdf0e10cSrcweir { 150cdf0e10cSrcweir $$pathref = cwd() . $pre2par::globals::separator . $$pathref; 151cdf0e10cSrcweir $$pathref =~ s/\//\\/g; 152cdf0e10cSrcweir } 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir $$pathref =~ s/\Q$pre2par::globals::separator\E\s*$//; # removing ending slashes 156cdf0e10cSrcweir} 157cdf0e10cSrcweir 158cdf0e10cSrcweir##################################### 159cdf0e10cSrcweir# Writing parameter to shell 160cdf0e10cSrcweir##################################### 161cdf0e10cSrcweir 162cdf0e10cSrcweirsub outputparameter 163cdf0e10cSrcweir{ 164cdf0e10cSrcweir $pre2par::globals::logging ? ($logoption = " -v") : ($logoption = ""); 165cdf0e10cSrcweir print "\n$pre2par::globals::prog -l $pre2par::globals::langfilename -s $pre2par::globals::prefilename -o $pre2par::globals::parfilename$logoption\n"; 166cdf0e10cSrcweir 167cdf0e10cSrcweir# print "\n********************************************************\n"; 168cdf0e10cSrcweir# print "This is $pre2par::globals::prog, version 1.0\n"; 169cdf0e10cSrcweir# print "Input file: $pre2par::globals::prefilename\n"; 170cdf0e10cSrcweir# print "Output file: $pre2par::globals::parfilename\n"; 171cdf0e10cSrcweir# print "********************************************************\n"; 172cdf0e10cSrcweir} 173cdf0e10cSrcweir 174cdf0e10cSrcweir1; 175