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