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
|
package FeatureParser;
# ************************************************************
# Description : Reads the feature files and store the values
# Author : Chad Elliott
# Create Date : 5/21/2003
# ************************************************************
# ************************************************************
# Pragmas
# ************************************************************
use strict;
use Parser;
use vars qw(@ISA);
@ISA = qw(Parser);
# ************************************************************
# Subroutine Section
# ************************************************************
sub new {
my $class = shift;
my $features = shift;
my @files = @_;
my $self = $class->SUPER::new();
## Set the values associative array
$self->{'values'} = {};
## Process each feature file
foreach my $f (@files) {
if (defined $f) {
my($status, $warn) = $self->read_file($f);
if (!$status) {
## We only want to warn the user about problems
## with the feature file.
my $lnumber = $self->get_line_number();
$self->warning($self->mpc_basename($f) . ": line $lnumber: $warn");
}
}
}
## Process each feature definition
foreach my $feature (@$features) {
my($status, $warn) = $self->parse_line(undef, $feature);
## We only want to warn the user about problems
## with the -feature option.
$self->warning("-features parameter: $warn") if (!$status);
}
return $self;
}
sub parse_line {
my($self, $if, $line) = @_;
my $error;
if ($line eq '') {
}
elsif ($line =~ /^(\w+)\s*=\s*(\d+)$/) {
## This is a valid value, so we can store it.
$self->{'values'}->{lc($1)} = $2;
}
else {
$error = "Unrecognized line: $line";
}
return (defined $error ? 0 : 1), $error;
}
sub get_names {
my @names = sort keys %{$_[0]->{'values'}};
return \@names;
}
sub get_value {
## All feature names are case-insensitive.
my($self, $tag) = @_;
return $self->{'values'}->{lc($tag)};
}
1;
|