blob: 3b9a5e2172cc1b0c72c18563aedaf7550d487e82 (
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
|
package TemplateInputReader;
# ************************************************************
# Description : Reads the template input and stores the values
# Author : Chad Elliott
# Create Date : 5/16/2002
# ************************************************************
# ************************************************************
# Pragmas
# ************************************************************
use strict;
use Parser;
use vars qw(@ISA);
@ISA = qw(Parser);
# ************************************************************
# Subroutine Section
# ************************************************************
sub new {
my($class) = shift;
my($self) = Parser::new($class);
$self->{'values'} = {};
$self->{'cindex'} = 0;
$self->{'current'} = [ $self->{'values'} ];
return $self;
}
sub parse_line {
my($self) = shift;
my($ih) = shift;
my($line) = shift;
my($status) = 1;
my($errorString) = '';
my($current) = $self->{'current'};
if ($line eq '') {
}
elsif ($line =~ /^([\w\s]+)\s*{$/) {
## Entering a new scope
my($name) = $1;
$name =~ s/\s+$//;
if (!defined $$current[$self->{'cindex'}]->{$name}) {
$$current[$self->{'cindex'}]->{$name} = {};
}
push(@$current, $$current[$self->{'cindex'}]->{$name});
$self->{'cindex'}++;
}
elsif ($line =~ /^}$/) {
if ($self->{'cindex'} > 0) {
pop(@$current);
$self->{'cindex'}--;
}
else {
$status = 0;
$errorString = 'ERROR: Unmatched curly brace';
}
}
elsif ($line =~ /^(\w+)\s*=\s*(.*)?/) {
my($name) = $1;
my($value) = $2;
if (defined $value) {
$value = $self->create_array($value);
}
else {
$value = '';
}
if (!defined $$current[$self->{'cindex'}]->{$name}) {
$$current[$self->{'cindex'}]->{$name} = $value;
}
else {
$status = 0;
$errorString = "ERROR: Redifinition of '$name'";
}
}
else {
$status = 0;
$errorString = "ERROR: Unrecognized line: $line";
}
return $status, $errorString;
}
sub get_value {
my($self) = shift;
my($tag) = shift;
return $self->{'values'}->{$tag};
}
1;
|