| 1 |
# |
| 2 |
# This file is part of the LibreOffice project. |
| 3 |
# |
| 4 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 5 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 7 |
# |
| 8 |
# This file incorporates work covered by the following license notice: |
| 9 |
# |
| 10 |
# Licensed to the Apache Software Foundation (ASF) under one or more |
| 11 |
# contributor license agreements. See the NOTICE file distributed |
| 12 |
# with this work for additional information regarding copyright |
| 13 |
# ownership. The ASF licenses this file to you under the Apache |
| 14 |
# License, Version 2.0 (the "License"); you may not use this file |
| 15 |
# except in compliance with the License. You may obtain a copy of |
| 16 |
# the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 17 |
# |
| 18 |
|
| 19 |
|
| 20 |
package pre2par::parameter; |
| 21 |
|
| 22 |
use Cwd; |
| 23 |
use pre2par::globals; |
| 24 |
use pre2par::systemactions; |
| 25 |
|
| 26 |
############################################ |
| 27 |
# Parameter Operations |
| 28 |
############################################ |
| 29 |
|
| 30 |
sub usage |
| 31 |
{ |
| 32 |
print <<End; |
| 33 |
--------------------------------------------------------- |
| 34 |
$pre2par::globals::prog |
| 35 |
The following parameter are needed: |
| 36 |
-s: path to the pre file |
| 37 |
-o: path to the par file |
| 38 |
-l: path to the ulf file (mlf or jlf file) |
| 39 |
-v: log process (optional) |
| 40 |
|
| 41 |
Example: |
| 42 |
|
| 43 |
perl pre2par.pl -l test.mlf -s readme.pre -o readme.par -v |
| 44 |
|
| 45 |
--------------------------------------------------------- |
| 46 |
End |
| 47 |
exit(-1); |
| 48 |
} |
| 49 |
|
| 50 |
##################################### |
| 51 |
# Reading parameter |
| 52 |
##################################### |
| 53 |
|
| 54 |
sub getparameter |
| 55 |
{ |
| 56 |
while ( $#ARGV >= 0 ) |
| 57 |
{ |
| 58 |
my $param = shift(@ARGV); |
| 59 |
|
| 60 |
if ($param eq "-s") { $pre2par::globals::prefilename = shift(@ARGV); } |
| 61 |
elsif ($param eq "-o") { $pre2par::globals::parfilename = shift(@ARGV); } |
| 62 |
elsif ($param eq "-l") { $pre2par::globals::langfilename = shift(@ARGV); } |
| 63 |
elsif ($param eq "-v") { $pre2par::globals::logging = 1; } |
| 64 |
else |
| 65 |
{ |
| 66 |
print("\n*************************************\n"); |
| 67 |
print("Sorry, unknown parameter: $param"); |
| 68 |
print("\n*************************************\n"); |
| 69 |
usage(); |
| 70 |
exit(-1); |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
############################################ |
| 76 |
# Controlling the fundamental parameter |
| 77 |
# (required for every process) |
| 78 |
############################################ |
| 79 |
|
| 80 |
sub control_parameter |
| 81 |
{ |
| 82 |
if ($pre2par::globals::prefilename eq "") |
| 83 |
{ |
| 84 |
print "\n************************************************\n"; |
| 85 |
print "Error: Name of the input file not set (-s)!"; |
| 86 |
print "\n************************************************\n"; |
| 87 |
usage(); |
| 88 |
exit(-1); |
| 89 |
} |
| 90 |
|
| 91 |
if (!(-f $pre2par::globals::prefilename)) |
| 92 |
{ |
| 93 |
print "\n************************************************\n"; |
| 94 |
print "Error: Input file does not exist!"; |
| 95 |
print "\n************************************************\n"; |
| 96 |
usage(); |
| 97 |
exit(-1); |
| 98 |
} |
| 99 |
|
| 100 |
if ($pre2par::globals::parfilename eq "") |
| 101 |
{ |
| 102 |
print "\n************************************************\n"; |
| 103 |
print "Error: Name of the output file not set (-o)!"; |
| 104 |
print "\n************************************************\n"; |
| 105 |
usage(); |
| 106 |
exit(-1); |
| 107 |
} |
| 108 |
|
| 109 |
if (!($pre2par::globals::prefilename =~ /\.pre\s*$/)) |
| 110 |
{ |
| 111 |
print "\n************************************************\n"; |
| 112 |
print "Error: Input file is no .pre file!"; |
| 113 |
print "\n************************************************\n"; |
| 114 |
usage(); |
| 115 |
exit(-1); |
| 116 |
} |
| 117 |
|
| 118 |
if (!($pre2par::globals::parfilename =~ /\.par\s*$/)) |
| 119 |
{ |
| 120 |
print "\n************************************************\n"; |
| 121 |
print "Error: Output file is no .par file!"; |
| 122 |
print "\n************************************************\n"; |
| 123 |
usage(); |
| 124 |
exit(-1); |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
##################################### |
| 129 |
# Writing parameter to shell |
| 130 |
##################################### |
| 131 |
|
| 132 |
sub outputparameter |
| 133 |
{ |
| 134 |
$pre2par::globals::logging ? ($logoption = " -v") : ($logoption = ""); |
| 135 |
print "\n$pre2par::globals::prog -l $pre2par::globals::langfilename -s $pre2par::globals::prefilename -o $pre2par::globals::parfilename$logoption\n"; |
| 136 |
|
| 137 |
# print "\n********************************************************\n"; |
| 138 |
# print "This is $pre2par::globals::prog, version 1.0\n"; |
| 139 |
# print "Input file: $pre2par::globals::prefilename\n"; |
| 140 |
# print "Output file: $pre2par::globals::parfilename\n"; |
| 141 |
# print "********************************************************\n"; |
| 142 |
} |
| 143 |
|
| 144 |
1; |