summaryrefslogtreecommitdiff
path: root/lib/sbin/ConfigurationParser.pl
blob: 0aefc1cfb877f979472b1caa50ee6a37bff5870a (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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#! /usr/bin/perl -w

#/*@@
#  @file      ConfigurationParser.pl
#  @date      Tue Feb  8 17:36:48 2000
#  @author    Tom Goodale
#  @desc 
#  Parser for configuration.ccl files
#  @enddesc
#  @version $Header$ 
#@@*/

#/*@@
#  @routine    CreateConfigurationDatabase
#  @date       Tue Feb  8 17:47:26 2000
#  @author     Tom Goodale
#  @desc 
#  
#  @enddesc 
#  @calls     
#  @calledby   
#  @history 
#
#  @endhistory 
#
#@@*/

sub CreateConfigurationDatabase
{
  my(%thorns) = @_;
  my($thorn, @indata);
  my(%configuration_data) = ();
  my($filename);

  #  Loop through each  thorn's interface file.
  foreach $thorn (keys %thorns)
  {
    #       Get the arrangement name for the thorn
    $thorns{$thorn} =~ m:.*/arrangements/([^/]*)/[^/]*:;
    $arrangement = $1;

    $filename = "$thorns{$thorn}/configuration.ccl";

    if(-r $filename)
    { 
      print "   $thorn\n";

      #       Read the data
      @indata = &read_file($filename);

      #       Get the configuration data from it
      &ParseConfigurationCCL($arrangement,$thorn, \%configuration_data, \@indata);
      
      &PrintConfigurationStatistics($thorn, \%configuration_data);
    }
  }
  
  return \%configuration_data;
}


#/*@@
#  @routine    ParseConfigurationCCL
#  @date       Tue Feb  8 19:23:18 2000
#  @author     Tom Goodale
#  @desc 
#  Parses a configuration.ccl file and generates a database of the values
#  @enddesc 
#  @calls     
#  @calledby   
#  @history 
#
#  @endhistory 
#
#@@*/
sub ParseConfigurationCCL
{
  my($arrangement, $thorn, $rh_configuration_db, $ra_data) = @_;
  my($line_number, $line);
  my($provides, $script, $lang);
  my($optional, $define);

  # Initialise some stuff to prevent perl -w from complaining.

  $rh_configuration_db->{"\U$thorn PROVIDES\E"} = "";
  $rh_configuration_db->{"\U$thorn REQUIRES\E"} = "";
  $rh_configuration_db->{"\U$thorn OPTIONAL\E"} = "";
  $rh_configuration_db->{"\U$thorn OPTIONS\E"}  = "";
  

  for($line_number = 0; $line_number < @$ra_data; $line_number++)
  {
    $line = $ra_data->[$line_number];
    
    #       Parse the line

    if($line =~ m/^\s*PROVIDES\s*/i)
    {
      ($provides, $script, $lang, $line_number) = &ParseProvidesBlock($line_number, $ra_data);
      $rh_configuration_db->{"\U$thorn PROVIDES\E"} .= "$provides";
      $rh_configuration_db->{"\U$thorn PROVIDES $provides\E SCRIPT"} = "$script";
      $rh_configuration_db->{"\U$thorn PROVIDES $provides\E LANG"} = "$lang";
      next;
    }
    elsif($line =~ m/^\s*REQUIRES\s*(.*)/i)
    {
      $rh_configuration_db->{"\U$thorn REQUIRES\E"} .= "$1";
    }
    elsif($line =~ m/^\s*OPTIONAL\s*/i)
    {
      ($optional, $define, $line_number) = &ParseOptionalBlock($line_number, $ra_data);
      $rh_configuration_db->{"\U$thorn OPTIONAL\E"} .= "$provides";
      $rh_configuration_db->{"\U$thorn OPTIONAL $optional\E DEFINE"} = "$define";
    }
    elsif($line =~ m/^\s*NO_SOURCE\s*/i)
    {
      $rh_configuration_db->{"\U$thorn OPTIONS\E"} .= "NO_SOURCE";
    }
    else
    {
      print STDERR "Error: Unrecognised line in configure.ccl '$line' \n";
      $CST_errors++;
    }

  }

  return;
}

#/*@@
#  @routine    ParseProvidesBlock
#  @date       Mon May  8 15:52:40 2000
#  @author     Tom Goodale
#  @desc 
#  Parses the PROVIDES block in a configuration.ccl file.
#  @enddesc 
#  @calls     
#  @calledby   
#  @history 
#
#  @endhistory 
#
#@@*/
sub ParseProvidesBlock
{
  my ($line_number, $ra_data) = @_;
  my ($provides, $script, $lang);

  $provides = "";
  $script   = "";
  $lang     = "";

  $ra_data->[$line_number] =~ m/^\s*PROVIDES\s*(.*)/i;
  
  $provides = $1;

  $line_number++;
  if($ra_data->[$line_number] !~ m/^\s*\{\s*$/)
  {
    print STDERR "Error parsing provides block line '$ra_data->[$line_number]'\n";
    print STDERR "Missing { at start of block\n";
    $CST_errors++;
    $line_number++ while($ra_data[$line_number] !~ m:\s*\}\s*:);
  }
  else
  {
    while($ra_data->[$line_number] !~ m:\s*\}\s*:)
    {
      $line_number++;
      if($ra_data->[$line_number] =~ m/^\s*SCRIPT\s*(.*)$/i)
      {
	$script = $1;
	next;
      }
      elsif($ra_data->[$line_number] =~ m/^\s*LANG[^\s]*\s*(.*)$/i)
      {
	$lang = $1;
	next;
      }
      elsif($ra_data->[$line_number] =~ m:\s*\}\s*:)
      {
	# do nothing.
      }
      else
      {
	print STDERR "Error parsing provides block line '$ra_data->[$line_number]'\n";
	print STDERR "Unrecognised statement\n";
	$CST_errors++;
      }	
    }
  }


  return ($provides, $script, $lang, $line_number);
}

#/*@@
#  @routine    ParseProvidesBlock
#  @date       Mon May  8 15:52:40 2000
#  @author     Tom Goodale
#  @desc 
#  Parses the OPTIONAL block in a configuration.ccl file.
#  @enddesc 
#  @calls     
#  @calledby   
#  @history 
#
#  @endhistory 
#
#@@*/
sub ParseOptionalBlock
{
  my ($line_number, $ra_data) = @_;
  my ($optional, $define);

  $ra_data->[$line_number] =~ m/^\s*OPTIONAL\s*(.*)/i;
  
  $optional = $1;

  $define = "";

  $line_number++;

  if($ra_data->[$line_number] !~ m/^\s*\{\s*$/)
  {
    print STDERR "Error parsing optional block line '$ra_data->[$line_number]'\n";
    print STDERR "Missing { at start of block\n";
    $CST_errors++;
    $line_number++ while($ra_data->[$line_number] !~ m:\s*\}\s*:);
  }
  else
  {
    while($ra_data->[$line_number] !~ m:\s*\}\s*:)
    {
      $line_number++;
      if($ra_data->[$line_number] =~ m/^\s*DEFINE\s*(.*)$/i)
      {
	if($define eq "")
	{
	  $define = $1;
	  next;
	}
	else
	{
	  print STDERR "Error parsing optional block line '$ra_data->[$line_number]'\n";
	  print STDERR "Only one define allowed\n";
	  $CST_errors++;
	}
      }
      elsif($ra_data->[$line_number] =~ m:\s*\}\s*:)
      {
	# do nothing.
      }
      else
      {
	print STDERR "Error parsing provides block line '$ra_data->[$line_number]'\n";
	print STDERR "Unrecognised statement\n";
	$CST_errors++;
      }	
    }
  }

  return ($optional, $define, $line_number);
}

#/*@@
#  @routine    PrintConfigurationDatabase
#  @date       Mon May  8 15:53:23 2000
#  @author     Tom Goodale
#  @desc 
#  Prints out the configuration database.
#  @enddesc 
#  @calls     
#  @calledby   
#  @history 
#
#  @endhistory 
#
#@@*/
sub PrintConfigurationDatabase
{
  my($configuration_data) = @_;
  my($field);
  
  foreach $field ( sort keys %$configuration_data)
  {
    print "$field has value $configuration_data->{$field}\n";
  }
}

#/*@@
#  @routine    PrintConfigurationStatistics
#  @date       Mon May  8 15:53:23 2000
#  @author     Tom Goodale
#  @desc 
#  Prints out the configuration statistics.
#  @enddesc 
#  @calls     
#  @calledby   
#  @history 
#
#  @endhistory 
#
#@@*/
sub PrintConfigurationStatistics
{
  my($thorn, $configuration_data) = @_;

  print "          " . "Provides: " . $configuration_data->{"\U$thorn\E PROVIDES"} . ".\n";

  return;
}

1;