Subversion Repositories gelsvn

Rev

Rev 198 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
107 bj 1
package TemplateInputReader;
2
 
3
# ************************************************************
4
# Description   : Reads the template input and stores the values
5
# Author        : Chad Elliott
6
# Create Date   : 5/16/2002
7
# ************************************************************
8
 
9
# ************************************************************
10
# Pragmas
11
# ************************************************************
12
 
13
use strict;
14
 
15
use Parser;
16
 
17
use vars qw(@ISA);
18
@ISA = qw(Parser);
19
 
20
# ************************************************************
21
# Data Section
22
# ************************************************************
23
 
24
my($mpt)  = 'mpt';
25
 
26
# ************************************************************
27
# Subroutine Section
28
# ************************************************************
29
 
30
sub new {
31
  my($class) = shift;
32
  my($inc)   = shift;
33
  my($self)  = Parser::new($class, $inc);
34
 
35
  $self->{'values'}    = {};
36
  $self->{'cindex'}    = 0;
37
  $self->{'current'}   = [ $self->{'values'} ];
38
  $self->{'realnames'} = {};
39
 
40
  return $self;
41
}
42
 
43
 
44
sub parse_line {
45
  my($self)        = shift;
46
  my($ih)          = shift;
47
  my($line)        = shift;
48
  my($status)      = 1;
49
  my($errorString) = undef;
50
  my($current)     = $self->{'current'};
51
 
52
  if ($line eq '') {
53
  }
198 bj 54
  elsif ($line =~ /^([\w\s\(\)\.]+)\s*{$/) {
107 bj 55
    ## Entering a new scope
56
    my($rname) = $1;
57
    $rname =~ s/\s+$//;
58
    my($name) = lc($rname);
59
    $self->{'realnames'}->{$name} = $rname;
60
 
61
    if (!defined $$current[$self->{'cindex'}]->{$name}) {
62
      $$current[$self->{'cindex'}]->{$name} = {};
63
    }
64
    push(@$current, $$current[$self->{'cindex'}]->{$name});
65
    $self->{'cindex'}++;
66
  }
67
  elsif ($line =~ /^}$/) {
68
    if ($self->{'cindex'} > 0) {
69
      pop(@$current);
70
      $self->{'cindex'}--;
71
    }
72
    else {
73
      $status = 0;
74
      $errorString = 'Unmatched curly brace';
75
    }
76
  }
77
  elsif ($line =~ /^(\w+)\s*(\+=|=)\s*(.*)?/) {
78
    my($name)  = lc($1);
79
    my($op)    = $2;
80
    my($value) = $3;
81
 
82
    if (defined $value) {
83
      $value = $self->create_array($value);
84
    }
85
    else {
86
      $value = [];
87
    }
88
 
89
    if ($op eq '+=' && defined $$current[$self->{'cindex'}]->{$name}) {
90
      push(@{$$current[$self->{'cindex'}]->{$name}}, @$value);
91
    }
92
    else {
93
      $$current[$self->{'cindex'}]->{$name} = $value;
94
    }
95
  }
96
  elsif ($line =~ /^conditional_include\s+"([\w\s\-\+\/\\\.]+)"$/) {
97
    my($file) = $self->search_include_path("$1.$mpt");
98
    if (defined $file) {
99
      my($ol) = $self->get_line_number();
100
      ($status, $errorString) = $self->read_file($file);
101
      $self->set_line_number($ol);
102
    }
103
  }
104
  else {
105
    $status = 0;
106
    $errorString = "Unrecognized line: $line";
107
  }
108
 
109
  return $status, $errorString;
110
}
111
 
112
 
113
sub get_value {
114
  my($self) = shift;
115
  my($tag)  = shift;
116
  return $self->{'values'}->{lc($tag)};
117
}
118
 
119
 
120
sub get_realname {
121
  my($self) = shift;
122
  my($tag)  = shift;
123
  return $self->{'realnames'}->{lc($tag)};
124
}
125
 
126
 
127
1;