3 # ************************************************************
4 # Description : A basic parser that requires a parse_line override
5 # Author : Chad Elliott
6 # Create Date : 5/16/2002
7 # ************************************************************
9 # ************************************************************
11 # ************************************************************
21 @ISA = qw(OutputMessage StringProcessor DirectoryManager);
23 # ************************************************************
25 # ************************************************************
29 # ************************************************************
31 # ************************************************************
34 my($class, $inc) = @_;
35 my $self = $class->SUPER::new
();
37 ## Set up the internal data members.
38 $self->{'line_number'} = 0;
39 $self->{'include'} = $inc;
46 my($self, $line) = @_;
48 ## Keep track of our line number
49 ++$self->{'line_number'};
51 ## Remove comments and leading and trailing white-space.
64 return $_[0]->strip_line($_[2]);
69 my($self, $input, $cache) = @_;
70 my $ih = new FileHandle
();
74 $self->{'line_number'} = 0;
75 if (open($ih, $input)) {
76 $self->debug("Open $input");
78 ## If we don't have an array for this file, then start one
79 $filecache{$input} = [] if (!defined $filecache{$input});
82 ## Preprocess the line
83 my $line = $self->preprocess_line($ih, $_);
85 ## Push the line onto the array for this file
86 push(@
{$filecache{$input}}, $line);
89 ($status, $errorString) = $self->parse_line($ih, $line);
91 ## Stop reading the file if we've encountered an error
96 ## We're not caching, so we just preprocess and parse in one call.
98 ($status, $errorString) = $self->parse_line(
99 $ih, $self->preprocess_line($ih, $_));
101 ## Stop reading the file if we've encountered an error
105 $self->debug("Close $input");
109 $errorString = "Unable to open \"$input\" for reading";
113 return $status, $errorString;
117 sub cached_file_read
{
118 my($self, $input) = @_;
119 my $lines = $filecache{$input};
121 if (defined $lines) {
124 $self->{'line_number'} = 0;
125 foreach my $line (@
$lines) {
126 ++$self->{'line_number'};
127 ## Since we're "reading" a cached file, we must pass undef as the
128 ## file handle to parse_line().
129 ($status, $error) = $self->parse_line(undef, $line);
131 ## Stop "reading" the file if we've encountered an error
134 return $status, $error;
137 ## We haven't cached this file yet, read it and cache it.
138 return $self->read_file($input, 1);
142 sub get_line_number
{
143 return $_[0]->{'line_number'};
147 sub set_line_number
{
148 my($self, $number) = @_;
149 $self->{'line_number'} = $number;
153 sub slash_to_backslash
{
154 ## This method is here solely for convenience. It's used to make the
155 ## calling code look cleaner.
156 my($self, $file) = @_;
162 sub get_include_path
{
163 return $_[0]->{'include'};
167 sub search_include_path
{
168 my($self, $file) = @_;
170 foreach my $include ('.', @
{$self->{'include'}}) {
171 return "$include/$file" if (-r
"$include/$file");
178 sub escape_regex_special
{
179 my($self, $name) = @_;
180 $name =~ s/([\+\-\\\$\[\]\(\)\.])/\\$1/g;
185 # ************************************************************
186 # Virtual Methods To Be Overridden
187 # ************************************************************