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 par2script::parameter;
26
27use Cwd;
28use par2script::files;
29use par2script::globals;
30use par2script::systemactions;
31
32############################################
33# Parameter Operations
34############################################
35
36###############################################################################
37# Usage:
38# perl par2script.pl -i ..\wntmsci8.pro\par,o:\SRX645\wntmsci8.pro\par.m24
39# 					@@C:\DOCUMEN~1\is\LOCALS~1\Temp\mk6pd
40# 					-o ..\wntmsci8.pro\bin\osl\setup_osl.inf
41###############################################################################
42
43sub usage
44{
45	print <<Ende;
46
47--------------------------------------------------------------
48$par2script::globals::prog
49The following parameter are needed:
50-i: include paths, comma separated list
51-o: setup script file name
52-v: writing logfile.txt (optional)
53\@\@list: list of all par files
54
55Example:
56 perl par2script.pl -i ..\\wntmsci8\\par\,o\:\\SRX645\\wntmsci8\\par.m24
57 		\@\@C\:\\DOCUMEN\~1\\is\\LOCALS\~1\\Temp\\mk6pd
58 		-o ..\\wntmsci8.pro\\bin\\osl\\setup_osl.inf \[-v\]
59
60--------------------------------------------------------------
61Ende
62	exit(-1);
63}
64
65#####################################
66# Reading parameter
67#####################################
68
69sub getparameter
70{
71	while ( $#ARGV >= 0 )
72	{
73		my $param = shift(@ARGV);
74
75		if ($param eq "-o") { $par2script::globals::scriptname = shift(@ARGV); }
76		elsif ($param eq "-v") { $par2script::globals::logging = 1; }
77		elsif ($param =~ /\@\@/) { $par2script::globals::parfilelistorig = $param; }
78		elsif ($param eq "-i") { $par2script::globals::includepathlist = shift(@ARGV); }
79		elsif (($param =~ /\//) || ($param =~ /\\/))	# another include parameter!
80		{
81			$par2script::globals::includepathlist = $par2script::globals::includepathlist . "," . $param;
82		}
83		else
84		{
85			print("\n*************************************\n");
86			print("Sorry, unknown parameter: $param");
87			print("\n*************************************\n");
88			usage();
89			exit(-1);
90		}
91	}
92}
93
94############################################
95# Controlling  the fundamental parameter
96# (required for every process)
97############################################
98
99sub control_parameter
100{
101	if ($par2script::globals::includepathlist eq "")
102	{
103		print "\n************************************************\n";
104		print "Error: Include paths not set not set (-i)!";
105		print "\n************************************************\n";
106		usage();
107		exit(-1);
108	}
109
110	if ($par2script::globals::scriptname eq "")
111	{
112		print "\n************************************************\n";
113		print "Error: Name of the setup script not set (-o)!";
114		print "\n************************************************\n";
115		usage();
116		exit(-1);
117	}
118
119	if ($par2script::globals::parfilelistorig eq "")
120	{
121		print "\n************************************************\n";
122		print "Error: List of par files not set!";
123		print "\n************************************************\n";
124		usage();
125		exit(-1);
126	}
127
128	# The par file list has to exist
129
130	$par2script::globals::parfilelist = $par2script::globals::parfilelistorig;
131	$par2script::globals::parfilelist =~ s/\@\@//;
132	par2script::files::check_file($par2script::globals::parfilelist);
133}
134
135#####################################
136# Writing parameter to shell
137#####################################
138
139sub outputparameter
140{
141	my $outputline = "\n$par2script::globals::prog -i $par2script::globals::includepathlist $par2script::globals::parfilelistorig -o $par2script::globals::scriptname";
142
143	if ($par2script::globals::logging) { $outputline .= " -v"; }
144
145	$outputline .= "\n";
146
147	print $outputline;
148}
149
1501;
151