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