summaryrefslogtreecommitdiff
path: root/lib/sbin/ConfigScriptParser.pl
blob: a2a23ff2b821e294741b94a5a92c1c0fa5f3564a (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
#! /usr/bin/perl -s
#/*@@
#  @file      ConfigScriptParser
#  @date      Thu Mar 25 14:25:13 2004
#  @author    Yaakoub El-Khamra
#  @desc
#             Parses the Config Script Output
#  @enddesc
#  @version   $Header$
#@@*/

#/*@@
#  @routine   ParseConfigScript
#  @date      Thu Mar 25 14:25:13 2004
#  @author    Yaakoub El-Khamra
#  @desc
#  Parses the Config Script Ouput
#  @enddesc
#@@*/
sub ParseConfigScript
{
  my($config_dir, $provides, $lang, $script, $thorn, $cfg, $thorns, $filename)=@_;
  my($line_number, $line, $temp);
  my($exit_value, $signal_num, $dumped_core);

  my $start_dir = `pwd`;
  chdir $config_dir;

  # Run the configuration script in the config_dir folder
  if ($lang ne '' && $script ne '')
  {
    @data=`$lang $thorns{$thorn}/$script`;
  }
  $exit_value  = $? >> 8;
  $signal_num  = $? & 127;
  $dumped_core = $? & 128;

  for($line_number = 0; $line_number < @data; $line_number++)
  {
    $line = $data[$line_number];
    # Parse the line
    if($line =~ m/^\s*BEGIN\s+DEFINE\s*/i)
    {
      $line_number++;
      $line = $data[$line_number];
      while($line !~ m/^\s*END\s+DEFINE\s*/i)
      {
        $cfg->{"\U$thorn $provides\E DEFINE"} .= $line;
        $line_number++;
        $line = $data[$line_number];
      }
    }
    elsif($line =~ m/^\s*BEGIN\s+ERROR\s*/i)
    {
      $line_number++;
      $line = $data[$line_number];
      while($line !~ m/^\s*END\s+ERROR\s*/i)
      {
        $cfg->{"\U$thorn $provides\E ERROR"} .= $line;
        $line_number++;
        $line = $data[$line_number];
      }
    }
    elsif($line =~ m/^\s*BEGIN\s+MESSAGE\s*/i)
    {
      $line_number++;
      $line = $data[$line_number];
      while($line !~ m/^\s*END\s+MESSAGE\s*/i)
      {
        $cfg->{"\U$thorn $provides\E MESSAGE"} .= $line;
        $line_number++;
        $line = $data[$line_number];
      }
    }
    elsif($line =~ m/^\s*BEGIN\s+DEFINITION\s*/i)
    {
      $line_number++;
      $line = $data[$line_number];
      while($line !~ m/^\s*END\s+DEFINITION\s*/i)
      {
        $cfg->{"\U$thorn $provides\E DEFINITION"} .= $line;
        $line_number++;
        $line = $data[$line_number];
      }
    }
    elsif($line =~ m/^\s*BEGIN\s+DEPENDENCY\s*/i)
    {
      $line_number++;
      $line = $data[$line_number];
      while($line !~ m/^\s*END\s+DEPENDENCY\s*/i)
      {
        $cfg->{"\U$thorn $provides\E DEPENDENCY"} .= $line;
        $line_number++;
        $line = $data[$line_number];
      }
    }
    elsif($line =~ m/^\s*INCLUDE_DIRECTORY[^\s]*\s*(.*)$/i)
    {
      $cfg->{"\U$thorn $provides\E INCLUDE_DIRECTORY"} .=' ' . $1;
    }
    elsif($line =~ m/^\s*LIBRARY_DIRECTORY[^\s]*\s*(.*)$/i)
    {
      $cfg->{"\U$thorn $provides\E LIBRARY_DIRECTORY"} .= ' ' . $1;
    }
    elsif($line =~ m/^\s*LIBRARY[^\s]*\s*(.*)$/i)
    {
      $cfg->{"\U$thorn $provides\E LIBRARY"} .= ' ' . $1;
    }
     else
    {
      &CST_error (0, "Unrecognised line in ConfigScriptParser.ccl '$line'");
    }
  }

  chomp ($error_msg = $cfg->{"\U$thorn $provides\E ERROR"});
  $error_msg = $error_msg ? "     Error message: '$error_msg'" : 
                            '     (no error message)';

  $msg = "Configuration script for thorn $thorn ";
  &CST_error (0, $msg . "returned exit code $exit_value\n$error_msg")
    if ($exit_value);
  &CST_error (0, $msg . "received signal $signal_num\n$error_msg")
    if ($signal_num);
  &CST_error (0, $msg . "dumped core\n$error_msg")
    if ($dumped_core);

  return ($cfg);
}

1;