<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">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);

# ************************************************************
# Data Section
# ************************************************************

my($mpt)  = 'mpt';

# ************************************************************
# Subroutine Section
# ************************************************************

sub new {
  my($class) = shift;
  my($inc)   = shift;
  my($self)  = Parser::new($class, $inc);

  $self-&gt;{'values'}  = {};
  $self-&gt;{'cindex'}  = 0;
  $self-&gt;{'current'} = [ $self-&gt;{'values'} ];

  return $self;
}


sub parse_line {
  my($self)        = shift;
  my($ih)          = shift;
  my($line)        = shift;
  my($status)      = 1;
  my($errorString) = undef;
  my($current)     = $self-&gt;{'current'};

  if ($line eq '') {
  }
  elsif ($line =~ /^([\w\s]+)\s*{$/) {
    ## Entering a new scope
    my($name) = lc($1);
    $name =~ s/\s+$//;
    if (!defined $$current[$self-&gt;{'cindex'}]-&gt;{$name}) {
      $$current[$self-&gt;{'cindex'}]-&gt;{$name} = {};
    }
    push(@$current, $$current[$self-&gt;{'cindex'}]-&gt;{$name});
    $self-&gt;{'cindex'}++;
  }
  elsif ($line =~ /^}$/) {
    if ($self-&gt;{'cindex'} &gt; 0) {
      pop(@$current);
      $self-&gt;{'cindex'}--;
    }
    else {
      $status = 0;
      $errorString = 'Unmatched curly brace';
    }
  }
  elsif ($line =~ /^(\w+)\s*(\+=|=)\s*(.*)?/) {
    my($name)  = lc($1);
    my($op)    = $2;
    my($value) = $3;

    if (defined $value) {
      $value = $self-&gt;create_array($value);
    }
    else {
      $value = [];
    }

    if ($op eq '+=') {
      if (defined $$current[$self-&gt;{'cindex'}]-&gt;{$name}) {
        push(@{$$current[$self-&gt;{'cindex'}]-&gt;{$name}}, @$value);
      }
      else {
        $$current[$self-&gt;{'cindex'}]-&gt;{$name} = $value;
      }
    }
    else {
      if (!$$current[$self-&gt;{'cindex'}]-&gt;{$name}) {
        $$current[$self-&gt;{'cindex'}]-&gt;{$name} = $value;
      }
      else {
        $status = 0;
        $errorString = "Redifinition of '$name'";
      }
    }
  }
  elsif ($line =~ /^conditional_include\s+"([\w\s\-\+\/\\\.]+)"$/) {
    my($file) = $self-&gt;search_include_path("$1.$mpt");
    if (defined $file) {
      my($ol) = $self-&gt;get_line_number();
      ($status, $errorString) = $self-&gt;read_file($file);
      $self-&gt;set_line_number($ol);
    }
  }
  else {
    $status = 0;
    $errorString = "Unrecognized line: $line";
  }

  return $status, $errorString;
}


sub get_value {
  my($self) = shift;
  my($tag)  = shift;
  return $self-&gt;{'values'}-&gt;{lc($tag)};
}


1;
</pre></body></html>