summaryrefslogtreecommitdiff
path: root/lib/sbin/parameter_parser.pl
blob: b07a37f325520b89c560abbef966a6a1892bd3de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#! /usr/bin/perl

#%implementations = ("flesh", "flesh", "test1", "test1", "test2", "test2");

#%parameter_database = create_parameter_database(%implementations);

#&print_parameter_database(%parameter_database);

#/*@@
#  @routine    create_parameter_database
#  @date       Wed Sep 16 11:45:18 1998
#  @author     Tom Goodale
#  @desc 
#  Creates a database of all the parameters
#  @enddesc 
#  @calls     
#  @calledby   
#  @history 
#
#  @endhistory 
#@@*/

sub create_parameter_database
{
    local(%implementations) = @_;
    local($imp, @indata);
    local(@new_parameter_data);
    local(@parameter_data);

#  Loop through each implementation's parameter file.
    foreach $imp (keys %implementations)
    {
#       Read the data
	@indata = read_file("$implementations{$imp}/param.ccl");
	
#       Get the parameters from it
	@new_parameter_data = &parse_param_ccl($imp, @indata);

#       Add the parameters to the master parameter database
	push (@parameter_data, @new_parameter_data);

    }

    return @parameter_data;
}


#/*@@
#  @routine    read_file
#  @date       Wed Sep 16 11:54:38 1998
#  @author     Tom Goodale
#  @desc 
#  Reads a file deleting comments and blank lines. 
#  @enddesc 
#  @calls     
#  @calledby   
#  @history 
# 
#  @endhistory 
#@@*/

sub read_file
{
    local($file) = @_;
    local(@indata);

    open(IN, "<$file") || die("Can't open $file\n");

    while(<IN>)
    {
	$_ =~ s/\#.*//;
	
	next if(m/^\s+$/);
	
	chop;
	
	push(@indata, $_);
    }

    close IN;

    return @indata;
}


#/*@@
#  @routine    parse_param_ccl
#  @date       Wed Sep 16 11:55:33 1998
#  @author     Tom Goodale
#  @desc 
#  Parses a param.ccl file and generates a database of the values.
#  @enddesc 
#  @calls     
#  @calledby   
#  @history 
#
#  @endhistory 
#@@*/

sub parse_param_ccl
{
    local($implementation, @data) = @_;
    local($linenum, $line, $block, $type, $variable, $description, $nerrors);
    local($current_friend, $new_ranges, $new_desc);
    local($data, %parameter_db);

#   The default block is private.
    $block = "PRIVATE";

    for($linenum = 0; $linenum < @data; $linenum++)
    {
	$line = $data[$linenum];

#       Parse the line
	if($line =~ m/(PUBLIC|PROTECTED|PRIVATE|FRIEND)\s*:(.*)/i)
	{
#           It's a new block.
	    $block = "\U$1\E";
	    if($block eq "FRIEND")
	    {
		$current_friend = $2;
		$current_friend =~ s:\s::;

#               It's a friend block.
		$block .= " \U$current_friend\E";
	    }
	}
	elsif($line =~ m:(EXTENDS )?\s*(INTEGER|REAL|KEYWORD|STRING)\s*([a-zA-Z]+[a-zA-Z0-9_]*) \s*(\"[^\"]*\"):i)
	{

#           This is a parameter definition.
	    $type = "\U$2\E";
	    $variable = $3;
	    $description = $4;

	    if($1 =~ m:EXTENDS:i && $block ne "FRIEND")
	    {
#               Can only extend a friend variable.
		print "Parse error at line $linenum\n";
		$nerrors++;
		$linenum++ while($line[$linenum] !=~ m:\}:);
	    }
	    elsif(! $data[$linenum+1] =~ m:^\s*\{\s*$:)
	    {
#               Since the data should have no blank lines, the next
#               line should have { on it.
		print "Parse error at line $linenum\n";
		$nerrors++;
#               Move past the end of this block.
		$linenum++ while($line[$linenum] !=~ m:\}:);
	    }
	    else
	    {
#               Move past {
		$linenum++;
		$linenum++;

#               Store data about this variable.
		$parameter_db{"\U$implementation $block\E variables"} .= $variable." ";
		$parameter_db{"\U$implementation $variable\E type"} = $type;
		$parameter_db{"\U$implementation $variable\E description"} = $description;
		$parameter_db{"\U$implementation $variable\E ranges"} = 0;

#               Parse the allowed values and their descriptions.
		while(($new_ranges, $new_desc) = $data[$linenum] =~ m/(.*)::(.*)/)
		{
		    $parameter_db{"\U$implementation $variable\E ranges"}++;
		    $parameter_db{"\U$implementation $variable\E range $parameter_db{\"\U$implementation $variable\E ranges\"} range"} = $new_ranges;
		    $parameter_db{"\U$implementation $variable\E range $parameter_db{\"\U$implementation $variable\E ranges\"} description"} = $new_desc;
		    $linenum++;
		}
		if(! $block =~ m:FRIEND:)
		{
		    if($data[$linenum] =~ m:\s*\}\s*(.+):)
		    {
			$parameter_db{"\U$implementation $variable\E default"} = $1;
		    }
		    else
		    {
			print STDERR "Unable to find default for $variable\n";
			$nerrors++;
		    }		
		}
	    }
	}
	else
	{
	    if($line =~ m:\{:)
	    {
		print "...Skipping block with missing keyword....\n";
		$linenum++ until ($data[$linenum] =~ m:\}:);
	    }
	    else
	    {
		print "Unknown line $line!!!\n";
	    }
	}
    }

    return %parameter_db;
}

#/*@@
#  @routine    print_parameter_database
#  @date       Wed Sep 16 14:58:52 1998
#  @author     Tom Goodale
#  @desc 
#  Prints out a parameter database.
#  @enddesc 
#  @calls     
#  @calledby   
#  @history 
#
#  @endhistory 
#@@*/
sub print_parameter_database
{
    local(%parameter_database) = @_;
    local($field);

    foreach $field ( sort keys %parameter_database ){
	print "$field has value $parameter_database{$field}\n";
    }
}

1;