<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package ProjectCreator;

# ************************************************************
# Description   : Base class for all project creators
# Author        : Chad Elliott
# Create Date   : 3/13/2002
# ************************************************************

# ************************************************************
# Pragmas
# ************************************************************

use strict;
use FileHandle;
use File::Path;
use File::Compare;
use File::Basename;

use Creator;
use TemplateInputReader;
use TemplateParser;
use FeatureParser;

use vars qw(@ISA);
@ISA = qw(Creator);

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

my($BaseClassExtension)      = 'mpb';
my($ProjectCreatorExtension) = 'mpc';
my($TemplateExtension)       = 'mpd';
my($TemplateInputExtension)  = 'mpt';

## Valid names for assignments within a project
## 1 means preserve the order for additions
## 0 means order is not preserved, it is inverted.
my(%validNames) = ('exename'         =&gt; 1,
                   'sharedname'      =&gt; 1,
                   'staticname'      =&gt; 1,
                   'libpaths'        =&gt; 1,
                   'install'         =&gt; 1,
                   'includes'        =&gt; 1,
                   'after'           =&gt; 1,
                   'libs'            =&gt; 0,
                   'lit_libs'        =&gt; 0,
                   'pure_libs'       =&gt; 0,
                   'pch_header'      =&gt; 1,
                   'pch_source'      =&gt; 1,
                   'dllout'          =&gt; 1,
                   'libout'          =&gt; 1,
                   'dynamicflags'    =&gt; 1,
                   'staticflags'     =&gt; 1,
                   'version'         =&gt; 1,
                   'recurse'         =&gt; 1,
                   'requires'        =&gt; 1,
                   'avoids'          =&gt; 1,
                   'tagname'         =&gt; 1,
                   'tagchecks'       =&gt; 1,
                   'macros'          =&gt; 1,
                  );

## Custom definitions only
## Bit  Meaning
## 0    Value is always an array
## 1    Value is an array and name gets 'outputext' converted to 'files'
## 2    Value is always scalar
## 3    Name can also be used in an 'optional' clause
## 4    Needs &lt;%...%&gt; conversion
my(%customDefined) = ('automatic'                   =&gt; 0x04,
                      'dependent'                   =&gt; 0x04,
                      'command'                     =&gt; 0x14,
                      'commandflags'                =&gt; 0x14,
                      'postcommand'                 =&gt; 0x14,
                      'inputext'                    =&gt; 0x01,
                      'libpath'                     =&gt; 0x04,
                      'output_option'               =&gt; 0x14,
                      'pch_postrule'                =&gt; 0x04,
                      'pre_extension'               =&gt; 0x08,
                      'source_pre_extension'        =&gt; 0x08,
                      'template_pre_extension'      =&gt; 0x08,
                      'header_pre_extension'        =&gt; 0x08,
                      'inline_pre_extension'        =&gt; 0x08,
                      'documentation_pre_extension' =&gt; 0x08,
                      'resource_pre_extension'      =&gt; 0x08,
                      'pre_filename'                =&gt; 0x08,
                      'source_pre_filename'         =&gt; 0x08,
                      'template_pre_filename'       =&gt; 0x08,
                      'header_pre_filename'         =&gt; 0x08,
                      'inline_pre_filename'         =&gt; 0x08,
                      'documentation_pre_filename'  =&gt; 0x08,
                      'resource_pre_filename'       =&gt; 0x08,
                      'source_outputext'            =&gt; 0x0a,
                      'template_outputext'          =&gt; 0x0a,
                      'header_outputext'            =&gt; 0x0a,
                      'inline_outputext'            =&gt; 0x0a,
                      'documentation_outputext'     =&gt; 0x0a,
                      'resource_outputext'          =&gt; 0x0a,
                      'generic_outputext'           =&gt; 0x0a,
                     );

## Custom sections as well as definitions
my(%custom) = ('commandflags'  =&gt; 1,
               'gendir'        =&gt; 1,
              );

## All matching assignment arrays will get these keywords
my(@default_matching_assignments) = ('recurse',
                                    );

## Deal with these components in a special way
my(%specialComponents) = ('header_files' =&gt; 1,
                          'inline_files' =&gt; 1,
                         );
my(%sourceComponents)  = ('source_files'   =&gt; 1,
                          'template_files' =&gt; 1,
                         );

## Valid component names within a project along with the valid file extensions
my(%vc) = ('source_files'        =&gt; [ "\\.cpp", "\\.cxx", "\\.cc", "\\.c", "\\.C", ],
           'template_files'      =&gt; [ "_T\\.cpp", "_T\\.cxx", "_T\\.cc", "_T\\.c", "_T\\.C", ],
           'header_files'        =&gt; [ "\\.h", "\\.hpp", "\\.hxx", "\\.hh", ],
           'inline_files'        =&gt; [ "\\.i", "\\.inl", ],
           'documentation_files' =&gt; [ "README", "readme", "\\.doc", "\\.txt", "\\.html" ],
           'resource_files'      =&gt; [ "\\.rc", ],
          );

## Exclude these extensions when auto generating the component values
my(%ec) = ('source_files' =&gt; $vc{'template_files'},
          );

## Match up assignments with the valid components
my(%ma) = ();

my(%genext) = ();

my($grouped_key) = 'grouped_';

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

sub new {
  my($class)     = shift;
  my($global)    = shift;
  my($inc)       = shift;
  my($template)  = shift;
  my($ti)        = shift;
  my($dynamic)   = shift;
  my($static)    = shift;
  my($relative)  = shift;
  my($addtemp)   = shift;
  my($addproj)   = shift;
  my($progress)  = shift;
  my($toplevel)  = shift;
  my($baseprojs) = shift;
  my($gfeature)  = shift;
  my($feature)   = shift;
  my($hierarchy) = shift;
  my($exclude)   = shift;
  my($makeco)    = shift;
  my($nmod)      = shift;
  my($applypj)   = shift;
  my($genins)    = shift;
  my($into)      = shift;
  my($self)      = $class-&gt;SUPER::new($global, $inc,
                                      $template, $ti, $dynamic, $static,
                                      $relative, $addtemp, $addproj,
                                      $progress, $toplevel, $baseprojs,
                                      $feature, $hierarchy, $nmod, $applypj,
                                      $into,
                                      'project');

  $self-&gt;{$self-&gt;{'type_check'}}   = 0;
  $self-&gt;{'feature_defined'}       = 0;
  $self-&gt;{'project_info'}          = [];
  $self-&gt;{'reading_parent'}        = [];
  $self-&gt;{'dexe_template_input'}   = undef;
  $self-&gt;{'lexe_template_input'}   = undef;
  $self-&gt;{'lib_template_input'}    = undef;
  $self-&gt;{'dll_template_input'}    = undef;
  $self-&gt;{'flag_overrides'}        = {};
  $self-&gt;{'special_supplied'}      = {};
  $self-&gt;{'pctype'}                = $self-&gt;extractType("$self");
  $self-&gt;{'verbatim'}              = {};
  $self-&gt;{'verbatim_accessed'}     = {$self-&gt;{'pctype'} =&gt; {}};
  $self-&gt;{'defaulted'}             = {};
  $self-&gt;{'custom_types'}          = {};
  $self-&gt;{'parents_read'}          = {};
  $self-&gt;{'inheritance_tree'}      = {};
  $self-&gt;{'remove_files'}          = {};
  $self-&gt;{'feature_parser'}        = new FeatureParser($gfeature, $feature);
  $self-&gt;{'convert_slashes'}       = $self-&gt;convert_slashes();
  $self-&gt;{'sort_files'}            = $self-&gt;sort_files();
  $self-&gt;{'source_callback'}       = undef;
  $self-&gt;{'dollar_special'}        = $self-&gt;dollar_special();
  $self-&gt;{'generate_ins'}          = $genins;
  $self-&gt;{'addtemp_state'}         = undef;
  $self-&gt;{'command_subs'}          = $self-&gt;get_command_subs();

  $self-&gt;add_default_matching_assignments();
  $self-&gt;reset_generating_types();

  return $self;
}


sub read_global_configuration {
  my($self)   = shift;
  my($input)  = $self-&gt;get_global_cfg();
  my($status) = 1;

  if (defined $input) {
    $self-&gt;{'reading_global'} = 1;
    $status = $self-&gt;parse_file($input);
    $self-&gt;{'reading_global'} = 0;
  }

  return $status;
}


sub process_assignment {
  my($self)   = shift;
  my($name)   = shift;
  my($value)  = shift;
  my($assign) = shift;

  ## Support the '*' mechanism as in the project name, to allow
  ## the user to correctly depend on another project within the same
  ## directory.
  if ($name eq 'after' &amp;&amp; $value =~ /\*/) {
    $value = $self-&gt;fill_type_name($value,
                                   $self-&gt;get_default_project_name());
  }
  if (defined $value &amp;&amp; !$self-&gt;{'dollar_special'} &amp;&amp; $value =~ /\$\$/) {
    $value =~ s/\$\$/\$/g;
  }
  $self-&gt;SUPER::process_assignment($name, $value, $assign);

  ## Support keyword mapping here only at the project level scope. The
  ## scoped keyword mapping is done through the parse_scoped_assignment()
  ## method.
  if (!defined $assign) {
    my($mapped) = $self-&gt;{'valid_names'}-&gt;{$name};
    if (defined $mapped &amp;&amp; UNIVERSAL::isa($mapped, 'ARRAY')) {
      $self-&gt;parse_scoped_assignment($$mapped[0], 'assignment',
                                     $$mapped[1], $value,
                                     $self-&gt;{'generated_exts'}-&gt;{$$mapped[0]});
    }
  }
}


sub get_assignment_for_modification {
  my($self)        = shift;
  my($name)        = shift;
  my($assign)      = shift;
  my($subtraction) = shift;

  ## If we weren't passed an assignment hash, then we need to
  ## look one up that may possibly correctly deal with keyword mappings
  if (!defined $assign) {
    my($mapped) = $self-&gt;{'valid_names'}-&gt;{$name};

    if (defined $mapped &amp;&amp; UNIVERSAL::isa($mapped, 'ARRAY')) {
      $name   = $$mapped[1];
      $assign = $self-&gt;{'generated_exts'}-&gt;{$$mapped[0]};
    }
  }

  ## Get the assignment value
  my($value) = $self-&gt;get_assignment($name, $assign);

  ## If we are involved in a subtraction, we get back a value and
  ## it's a scoped or mapped assignment, then we need to possibly
  ## expand any template variables.  Otherwise, the subtractions
  ## may not work correctly.
  if ($subtraction &amp;&amp; defined $value &amp;&amp; defined $assign) {
    $value = $self-&gt;relative($value, 1);
  }

  return $value;
}


sub begin_project {
  my($self)    = shift;
  my($parents) = shift;
  my($status)  = 1;
  my($error)   = undef;

  ## Deal with the inheritance hiearchy first
  ## Add in the base projects from the command line
  if (!$self-&gt;{'reading_global'} &amp;&amp;
      !defined $self-&gt;{'reading_parent'}-&gt;[0]) {
    my($baseprojs) = $self-&gt;get_baseprojs();

    if (defined $parents) {
      foreach my $base (@$baseprojs) {
        my($found) = 0;
        foreach my $parent (@$parents) {
          if ($base eq $parent) {
            $found = 1;
            last;
          }
        }
        if (!$found) {
          push(@$parents, $base);
        }
      }
    }
    else {
      $parents = $baseprojs;
    }
  }

  if (defined $parents) {
    foreach my $parent (@$parents) {
      ## Read in the parent onto ourself
      my($file) = $self-&gt;search_include_path(
                           "$parent.$BaseClassExtension");
      if (!defined $file) {
        $file = $self-&gt;search_include_path(
                             "$parent.$ProjectCreatorExtension");
      }

      if (defined $file) {
        if (defined $self-&gt;{'reading_parent'}-&gt;[0]) {
          foreach my $currently (@{$self-&gt;{'reading_parent'}}) {
            if ($currently eq $file) {
              $status = 0;
              $error = 'Cyclic inheritance detected: ' .
                       $parent;
            }
          }
        }

        if ($status) {
          if (!defined $self-&gt;{'parents_read'}-&gt;{$file}) {
            $self-&gt;{'parents_read'}-&gt;{$file} = 1;

            ## Push the base project file onto the parent stack
            push(@{$self-&gt;{'reading_parent'}}, $file);

            ## Collect up some information about the inheritance tree
            my($tree) = $self-&gt;{'current_input'};
            if (!defined $self-&gt;{'inheritance_tree'}-&gt;{$tree}) {
              $self-&gt;{'inheritance_tree'}-&gt;{$tree} = {};
            }
            my($hash) = $self-&gt;{'inheritance_tree'}-&gt;{$tree};
            foreach my $p (@{$self-&gt;{'reading_parent'}}) {
              if (!defined $$hash{$p}) {
                $$hash{$p} = {};
              }
              $hash = $$hash{$p};
            }

            ## Begin reading the parent
            $status = $self-&gt;parse_file($file);

            ## Take the base project file off of the parent stack
            pop(@{$self-&gt;{'reading_parent'}});

            if (!$status) {
              $error = "Invalid parent: $parent";
            }
          }
          else {
            ## The base project has already been read.  So, if
            ## we are reading the original project (not a parent base
            ## project), then the current base project is redundant.
            if (!defined $self-&gt;{'reading_parent'}-&gt;[0]) {
              $file =~ s/\.[^\.]+$//;
              $self-&gt;information('Inheriting from \'' . basename($file) .
                                 '\' in ' . $self-&gt;{'current_input'} .
                                 ' is redundant at line ' .
                                 $self-&gt;get_line_number() . '.');
            }
          }
        }
      }
      else {
        $status = 0;
        $error = "Unable to locate parent: $parent";
      }
    }
  }

  ## Copy each value from global_assign into assign
  if (!$self-&gt;{'reading_global'}) {
    foreach my $key (keys %{$self-&gt;{'global_assign'}}) {
      if (!defined $self-&gt;{'assign'}-&gt;{$key}) {
        $self-&gt;{'assign'}-&gt;{$key} = $self-&gt;{'global_assign'}-&gt;{$key};
      }
    }
  }

  return $status, $error;
}


sub parse_line {
  my($self)   = shift;
  my($ih)     = shift;
  my($line)   = shift;
  my($status,
     $errorString,
     @values) = $self-&gt;parse_known($line);

  ## parse_known() passes back an array of values
  ## that make up the contents of the line parsed.
  ## The array can have 0 to 3 items.  The first,
  ## if defined, is always an identifier of some
  ## sort.

  if ($status &amp;&amp; defined $values[0]) {
    if ($values[0] eq $self-&gt;{'grammar_type'}) {
      my($name)      = $values[1];
      my($typecheck) = $self-&gt;{'type_check'};
      if (defined $name &amp;&amp; $name eq '}') {
        ## Project Ending
        my($rp) = $self-&gt;{'reading_parent'};
        if (!defined $$rp[0] &amp;&amp; !$self-&gt;{'reading_global'}) {
          ## Fill in all the default values
          $self-&gt;generate_defaults();

          ## Perform any additions, subtractions
          ## or overrides for the project values.
          my($addproj) = $self-&gt;get_addproj();
          foreach my $ap (keys %$addproj) {
            if (defined $self-&gt;{'valid_names'}-&gt;{$ap}) {
              my($val) = $$addproj{$ap};
              if ($$val[0] &gt; 0) {
                $self-&gt;process_assignment_add($ap, $$val[1]);
              }
              elsif ($$val[0] &lt; 0) {
                $self-&gt;process_assignment_sub($ap, $$val[1]);
              }
              else {
                $self-&gt;process_assignment($ap, $$val[1]);
              }
            }
            else {
              $errorString = 'Invalid ' .
                             "assignment modification name: $ap";
              $status = 0;
            }
          }

          if ($status) {
            ## End of project; Write out the file.
            ($status, $errorString) = $self-&gt;write_project();

            ## write_project() can return 0 for error, 1 for project
            ## was written and 2 for project was skipped
            if ($status == 1) {
              ## Check for unused verbatim markers
              foreach my $key (keys %{$self-&gt;{'verbatim'}}) {
                if (defined $self-&gt;{'verbatim_accessed'}-&gt;{$key}) {
                  foreach my $ikey (keys %{$self-&gt;{'verbatim'}-&gt;{$key}}) {
                    if (!defined $self-&gt;{'verbatim_accessed'}-&gt;{$key}-&gt;{$ikey}) {
                      $self-&gt;warning("Marker $ikey does not exist.");
                    }
                  }
                }
              }
            }

            ## Reset all of the project specific data
            foreach my $key (keys %{$self-&gt;{'valid_components'}}) {
              delete $self-&gt;{$key};
              $self-&gt;{'defaulted'}-&gt;{$key} = 0;
            }
            if (defined $self-&gt;{'addtemp_state'}) {
              $self-&gt;restore_state($self-&gt;{'addtemp_state'}, 'addtemp');
              $self-&gt;{'addtemp_state'} = undef;
            }
            $self-&gt;{'assign'}               = {};
            $self-&gt;{'verbatim'}             = {};
            $self-&gt;{'verbatim_accessed'}    = {$self-&gt;{'pctype'} =&gt; {}};
            $self-&gt;{'special_supplied'}     = {};
            $self-&gt;{'flag_overrides'}       = {};
            $self-&gt;{'parents_read'}         = {};
            $self-&gt;{'inheritance_tree'}     = {};
            $self-&gt;{'remove_files'}         = {};
            $self-&gt;reset_generating_types();
          }
        }
        $self-&gt;{$typecheck} = 0;
      }
      else {
        ## Project Beginning
        ($status, $errorString) = $self-&gt;begin_project($values[2]);

        ## Set up the default project name
        if ($status) {
          if (defined $name) {
            if ($name =~ /[\/\\]/) {
              $status = 0;
              $errorString = 'Projects can not have a slash ' .
                             'or a back slash in the name';
            }
            else {
              ## We should only set the project name if we are not
              ## reading in a parent project.
              if (!defined $self-&gt;{'reading_parent'}-&gt;[0]) {
                $name =~ s/^\(\s*//;
                $name =~ s/\s*\)$//;
                $name = $self-&gt;transform_file_name($name);

                ## Replace any *'s with the default name
                $name = $self-&gt;fill_type_name(
                                    $name,
                                    $self-&gt;get_default_project_name());

                $self-&gt;set_project_name($name);
              }
              else {
                $self-&gt;warning("Ignoring project name in a base project.");
              }
            }
          }
        }

        if ($status) {
          ## Signify that we have a valid project
          $self-&gt;{$typecheck} = 1;
        }
      }
    }
    elsif ($values[0] eq 'assignment') {
      my($name)  = $values[1];
      my($value) = $values[2];
      if (defined $self-&gt;{'valid_names'}-&gt;{$name}) {
        $self-&gt;process_assignment($name, $value);
      }
      else {
        $errorString = "Invalid assignment name: $name";
        $status = 0;
      }
    }
    elsif ($values[0] eq 'assign_add') {
      my($name)  = $values[1];
      my($value) = $values[2];
      if (defined $self-&gt;{'valid_names'}-&gt;{$name}) {
        $self-&gt;process_assignment_add($name, $value);
      }
      else {
        $errorString = "Invalid addition name: $name";
        $status = 0;
      }
    }
    elsif ($values[0] eq 'assign_sub') {
      my($name)  = $values[1];
      my($value) = $values[2];
      if (defined $self-&gt;{'valid_names'}-&gt;{$name}) {
        $self-&gt;process_assignment_sub($name, $value);
      }
      else {
        $errorString = "Invalid subtraction name: $name";
        $status = 0;
      }
    }
    elsif ($values[0] eq 'component') {
      my($comp) = $values[1];
      my($name) = $values[2];
      if (defined $name) {
        $name =~ s/^\(\s*//;
        $name =~ s/\s*\)$//;
      }
      else {
        $name = $self-&gt;get_default_component_name();
      }

      my($vc) = $self-&gt;{'valid_components'};
      if (defined $$vc{$comp}) {
        if (!$self-&gt;parse_components($ih, $comp, $name)) {
          $errorString = "Unable to process $comp";
          $status = 0;
        }
      }
      else {
        if ($comp eq 'verbatim') {
          my($type, $loc) = split(/\s*,\s*/, $name);
          if (!$self-&gt;parse_verbatim($ih, $type, $loc)) {
            $errorString = "Unable to process $comp";
            $status = 0;
          }
        }
        elsif ($comp eq 'specific') {
          my($scope_parsed) = 0;
          my($defcomp) = $self-&gt;get_default_component_name();
          foreach my $type (split(/\s*,\s*/, $name)) {
            if ($type eq $self-&gt;{'pctype'} || $type eq $defcomp) {
              ($status, $errorString) = $self-&gt;parse_scope(
                                          $ih, $values[1], $type,
                                          $self-&gt;{'valid_names'},
                                          $self-&gt;get_assignment_hash());
              $scope_parsed = 1;
              last;
            }
          }
          if (!$scope_parsed) {
            ## We still need to parse the scope, but we will be
            ## throwing away whatever is processed.  However, it
            ## could still be invalid code that will cause an error.
            ($status, $errorString) = $self-&gt;parse_scope(
                                        $ih, $values[1], undef,
                                        $self-&gt;{'valid_names'});
          }
        }
        elsif ($comp eq 'define_custom') {
          ($status, $errorString) = $self-&gt;parse_define_custom($ih, $name);
        }
        else {
          $errorString = "Invalid component name: $comp";
          $status = 0;
        }
      }
    }
    elsif ($values[0] eq 'feature') {
      $self-&gt;{'feature_defined'} = 1;
      $self-&gt;process_feature($ih, $values[1], $values[2]);
      if ($self-&gt;{'feature_defined'}) {
        $errorString = "Did not find the end of the feature";
        $status = 0;
      }
    }
    else {
      $errorString = "Unrecognized line: $line";
      $status = 0;
    }
  }
  elsif ($status == -1) {
    $status = 0;
  }

  return $status, $errorString;
}


sub parse_scoped_assignment {
  my($self)   = shift;
  my($tag)    = shift;
  my($type)   = shift;
  my($name)   = shift;
  my($value)  = shift;
  my($flags)  = shift;
  my($over)   = {};
  my($status) = 0;

  ## Map the assignment name on a scoped assignment
  my($mapped) = $self-&gt;{'valid_names'}-&gt;{$name};
  if (defined $mapped &amp;&amp; UNIVERSAL::isa($mapped, 'ARRAY')) {
    $name = $$mapped[1];
  }

  if (defined $self-&gt;{'matching_assignments'}-&gt;{$tag}) {
    foreach my $possible (@{$self-&gt;{'matching_assignments'}-&gt;{$tag}}) {
      if ($possible eq $name) {
        $status = 1;
        last;
      }
    }
  }

  if ($status) {
    if (defined $self-&gt;{'flag_overrides'}-&gt;{$tag}) {
      $over = $self-&gt;{'flag_overrides'}-&gt;{$tag};
    }
    else {
      $self-&gt;{'flag_overrides'}-&gt;{$tag} = $over;
    }

    if ($type eq 'assignment') {
      $self-&gt;process_assignment($name, $value, $flags);
    }
    elsif ($type eq 'assign_add') {
      ## If there is no value in $$flags, then we need to get
      ## the outer scope value and put it in there.
      if (!defined $self-&gt;get_assignment($name, $flags)) {
        my($outer) = $self-&gt;get_assignment($name);
        $self-&gt;process_assignment($name, $outer, $flags);
      }
      $self-&gt;process_assignment_add($name, $value, $flags);
    }
    elsif ($type eq 'assign_sub') {
      ## If there is no value in $$flags, then we need to get
      ## the outer scope value and put it in there.
      if (!defined $self-&gt;get_assignment($name, $flags)) {
        my($outer) = $self-&gt;get_assignment($name);
        $self-&gt;process_assignment($name, $outer, $flags);
      }
      $self-&gt;process_assignment_sub($name, $value, $flags);
    }
  }
  return $status;
}


sub handle_unknown_assignment {
  my($self)   = shift;
  my($type)   = shift;
  my(@values) = @_;

  ## Unknown assignments within a 'specific' section are handled as
  ## template value modifications.  These are handled exactly as the
  ## -value_template option in Options.pm.

  ## If $type is not defined, then we are skipping this section
  if (defined $type) {
    ## If the template override has already been set, then
    ## we will ignore this and keep the original value.
    if (!defined $self-&gt;get_addtemp()-&gt;{$values[1]}) {
      ## Save the addtemp state if we haven't done so before
      if (!defined $self-&gt;{'addtemp_state'}) {
        my(%state) = $self-&gt;save_state('addtemp');
        $self-&gt;{'addtemp_state'} = \%state;
      }

      ## Now modify the addtemp values
      $self-&gt;information("'$values[1]' was used as a template modifier.");
      if ($values[0] eq 'assign_add') {
        $values[0] = 1;
      }
      elsif ($values[0] eq 'assign_sub') {
        $values[0] = -1;
      }
      else {
        $values[0] = 0;
      }
      $self-&gt;get_addtemp()-&gt;{$values[1]} = [$values[0], $values[2]];
    }
    else {
      $self-&gt;information("'$values[1]' was used as a template modifier. " .
                         "It has been set previously and will be ignored.");
    }
  }

  return 1, undef;
}


sub parse_components {
  my($self)    = shift;
  my($fh)      = shift;
  my($tag)     = shift;
  my($name)    = shift;
  my($current) = $self-&gt;get_default_element_name();
  my($status)  = 1;
  my($names)   = {};
  my($comps)   = {};
  my($set)     = 0;
  my(%flags)   = ();
  my(%exclude) = ();
  my($custom)  = defined $self-&gt;{'generated_exts'}-&gt;{$tag};
  my($grtag)   = $grouped_key . $tag;
  my($grname)  = undef;

  if ($custom) {
    ## For the custom scoped assignments, we want to put a copy of
    ## the original custom defined values in our flags associative array.
    foreach my $key (keys %custom) {
      if (defined $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;{$key}) {
        $flags{$key} = $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;{$key};
      }
    }
  }

  if (defined $self-&gt;{$tag}) {
    $names = $self-&gt;{$tag};
  }
  else {
    $self-&gt;{$tag} = $names;
  }
  if (defined $$names{$name}) {
    $comps = $$names{$name};
  }
  else {
    $$names{$name} = $comps;
  }
  if (!defined $$comps{$current}) {
    $$comps{$current} = [];
  }

  my($count) = 0;
  if (defined $specialComponents{$tag}) {
    $self-&gt;{'special_supplied'}-&gt;{$tag} = 1;
  }

  while(&lt;$fh&gt;) {
    my($line) = $self-&gt;preprocess_line($fh, $_);

    if ($line eq '') {
    }
    elsif ($line =~ /^(\w+)\s*{$/) {
      if (!defined $current || !$set) {
        if (defined $current) {
          if (!defined $$comps{$current}-&gt;[0]) {
            ## The default components name was never used
            ## so we remove it from the components
            delete $$comps{$current};
          }
          else {
            ## It was used, so we need to add that name to
            ## the set of group names
            $self-&gt;process_assignment_add($grtag, $current);
          }
        }
        $current = $1;
        $set = 1;
        if (!defined $$comps{$current}) {
          $$comps{$current} = [];
          $self-&gt;process_assignment_add($grtag, $current);
        }
      }
      else {
        $status = 0;
        last;
      }
    }
    elsif ($line =~ /^}/) {
      if (defined $current &amp;&amp; $set) {
        $current = undef;
      }
      else {
        ## This is not an error,
        ## this is the end of the components
        last;
      }
    }
    elsif (defined $current) {
      my(@values) = ();
      ## If this returns true, then we've found an assignment
      if ($self-&gt;parse_assignment($line, \@values)) {
        $status = $self-&gt;parse_scoped_assignment($tag, @values, \%flags);
        if (!$status) {
          last;
        }
      }
      else {
        ## If we successfully remove a '!' from the front, then
        ## the file(s) listed are to be excluded
        my($rem) = ($line =~ s/^\^//);
        my($exc) = $rem || ($line =~ s/^!//);

        ## Convert any $(...) in this line before we process any
        ## wildcard characters.  If we do not, scoped assignments will
        ## not work nor will we get the correct wildcarded file list.
        $line = $self-&gt;relative($line, 0, 1);

        ## Set up the files array.  If the line contains a wildcard
        ## character use CORE::glob() to get the files specified.
        my(@files) = ();
        if ($line =~ /^"([^"]+)"$/) {
          push(@files, $1);
        }
        elsif ($line =~ /[\?\*\[\]]/) {
          @files = glob($line);
        }
        else {
          push(@files, $line);
        }

        ## If we want to remove these files at the end too, then
        ## add them to our remove_files hash array.
        if ($rem) {
          if (!defined $self-&gt;{'remove_files'}-&gt;{$tag}) {
            $self-&gt;{'remove_files'}-&gt;{$tag} = {};
          }
          foreach my $file (@files) {
            $self-&gt;{'remove_files'}-&gt;{$tag}-&gt;{$file} = 1;
          }
        }

        ## If we're excluding these files, then put them in the hash
        if ($exc) {
          $grname = $current;
          @exclude{@files} = (@files);
        }
        else {
          ## Set the flag overrides for each file
          my($over) = $self-&gt;{'flag_overrides'}-&gt;{$tag};
          if (defined $over) {
            foreach my $file (@files) {
              $$over{$file} = \%flags;
            }
          }

          foreach my $file (@files) {
            ## Add the file if we're not excluding it
            if (!defined $exclude{$file}) {
              push(@{$$comps{$current}}, $file);
            }

            ## The user listed a file explicitly, whether we
            ## excluded it or not.
            ++$count;
          }
        }
      }
    }
    else {
      $status = 0;
      last;
    }
  }

  ## If we didn't encounter an error, didn't have any files explicitly
  ## listed and we attempted to exclude files, then we need to find the
  ## set of files that don't match the excluded files and add them.
  if ($status &amp;&amp; $count == 0 &amp;&amp; defined $grname) {
    my(@exc)    = keys %exclude;
    my($alldir) = $self-&gt;get_assignment('recurse') || $flags{'recurse'};
    my(@files)  = $self-&gt;generate_default_file_list('.', \@exc, $alldir);
    $self-&gt;sift_files(\@files,
                      $self-&gt;{'valid_components'}-&gt;{$tag},
                      $self-&gt;get_assignment('pch_header'),
                      $self-&gt;get_assignment('pch_source'),
                      $tag,
                      $$comps{$grname});
  }

  return $status;
}


sub parse_verbatim {
  my($self)    = shift;
  my($fh)      = shift;
  my($type)    = shift;
  my($loc)     = shift;

  ## All types are lowercase
  $type = lc($type);

  if (!defined $self-&gt;{'verbatim'}-&gt;{$type}) {
    $self-&gt;{'verbatim'}-&gt;{$type} = {};
  }
  $self-&gt;{'verbatim'}-&gt;{$type}-&gt;{$loc} = [];
  my($array) = $self-&gt;{'verbatim'}-&gt;{$type}-&gt;{$loc};

  while(&lt;$fh&gt;) {
    my($line) = $self-&gt;preprocess_line($fh, $_);

    if ($line =~ /^}/) {
      ## This is not an error,
      ## this is the end of the verbatim
      last;
    }
    else {
      push(@$array, $line);
    }
  }

  return 1;
}


sub process_feature {
  my($self)    = shift;
  my($fh)      = shift;
  my($names)   = shift;
  my($parents) = shift;
  my($status)  = 1;
  my($error)   = undef;

  my($requires) = '';
  my($avoids)   = '';
  foreach my $name (@$names) {
    if ($name =~ /^!\s*(.*)$/) {
      if ($avoids ne '') {
        $avoids .= ' ';
      }
      $avoids .= $1;
    }
    else {
      if ($requires ne '') {
        $requires .= ' ';
      }
      $requires .= $name;
    }
  }

  if ($self-&gt;check_features($requires, $avoids)) {
    ## The required features are enabled, so we say that
    ## a project has been defined and we allow the parser to
    ## find the data held within the feature.
    ($status, $error) = $self-&gt;begin_project($parents);
    if ($status) {
      $self-&gt;{'feature_defined'} = 0;
      $self-&gt;{$self-&gt;{'type_check'}} = 1;
    }
  }
  else {
    ## Otherwise, we read in all the lines until we find the
    ## closing brace for the feature and it appears to the parser
    ## that nothing was defined.
    my($curly) = 1;
    while(&lt;$fh&gt;) {
      my($line) = $self-&gt;preprocess_line($fh, $_);

      ## This is a very simplistic way of finding the end of
      ## the feature definition.  It will work as long as no spurious
      ## open curly braces are counted.
      if ($line =~ /{$/) {
        ++$curly;
      }
      elsif ($line =~ /^}$/) {
        --$curly;
      }
      if ($curly == 0) {
        $self-&gt;{'feature_defined'} = 0;
        last;
      }
    }
  }

  return $status, $error;
}


sub process_array_assignment {
  my($self)  = shift;
  my($aref)  = shift;
  my($type)  = shift;
  my($array) = shift;

  if (!defined $$aref || $type eq 'assignment') {
    if ($type ne 'assign_sub') {
      $$aref = $array;
    }
  }
  else {
    if ($type eq 'assign_add') {
      push(@{$$aref}, @$array);
    }
    elsif ($type eq 'assign_sub') {
      my($count) = scalar(@{$$aref});
      for(my $i = 0; $i &lt; $count; ++$i) {
        foreach my $val (@$array) {
          if ($$aref-&gt;[$i] eq $val) {
            splice(@{$$aref}, $i, 1);
            --$i;
            --$count;
            last;
          }
        }
      }
    }
  }
}


sub parse_define_custom {
  my($self)        = shift;
  my($fh)          = shift;
  my($tag)         = shift;
  my($status)      = 0;
  my($errorString) = "Unable to process $tag";

  ## Make the tag something _files
  $tag = lc($tag) . '_files';

  if (defined $self-&gt;{'valid_components'}-&gt;{$tag}) {
    $errorString = "$tag has already been defined";
  }
  else {
    ## Update the custom_types assignment
    $self-&gt;process_assignment_add('custom_types', $tag);

    if (!defined $self-&gt;{'matching_assignments'}-&gt;{$tag}) {
      my(@keys) = keys %custom;
      push(@keys, @default_matching_assignments);
      $self-&gt;{'matching_assignments'}-&gt;{$tag} = \@keys;
    }

    ## Set up the 'optional' hash table
    $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;{'optional'} = {};

    my($optname) = undef;
    my($inscope) = 0;
    while(&lt;$fh&gt;) {
      my($line) = $self-&gt;preprocess_line($fh, $_);

      if ($line eq '') {
      }
      elsif ($line =~ /optional\s*\(([^\)]+)\)\s*{/) {
        $optname = $1;
        $optname =~ s/^\s+//;
        $optname =~ s/\s+$//;
        if (defined $customDefined{$optname} &amp;&amp;
            ($customDefined{$optname} &amp; 0x08) != 0) {
          ++$inscope;
          if ($inscope != 1) {
            $status = 0;
            $errorString = 'Can not nest \'optional\' sections';
            last;
          }
        }
        else {
          $status = 0;
          $errorString = "Invalid optional name: $optname";
          last;
        }
      }
      elsif ($inscope) {
        if ($line =~ /^}/) {
          $optname = undef;
          --$inscope;
        }
        else {
          if ($line =~ /(\w+)\s*\(([^\)]+)\)\s*\+=\s*(.*)/) {
            my($name) = lc($1);
            my($opt)  = $2;
            my(@val)  = split(/\s*,\s*/, $3);

            if (!defined $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;
                                {'optional'}-&gt;{$optname}) {
              $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;
                     {'optional'}-&gt;{$optname} = {};
            }
            if (!defined $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;
                                {'optional'}-&gt;{$optname}-&gt;{$name}) {
              $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;
                     {'optional'}-&gt;{$optname}-&gt;{$name} = {};
            }
            if (!defined $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;
                                {'optional'}-&gt;{$optname}-&gt;{$name}-&gt;{$opt}) {
              $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;
                     {'optional'}-&gt;{$optname}-&gt;{$name}-&gt;{$opt} = [];
            }
            push(@{$self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;{'optional'}-&gt;
                    {$optname}-&gt;{$name}-&gt;{$opt}}, @val);
          }
        }
      }
      elsif ($line =~ /^}/) {
        $status = 1;
        $errorString = undef;

        ## Propagate the custom defined values into the mapped values
        foreach my $key (keys %{$self-&gt;{'valid_names'}}) {
          my($mapped) = $self-&gt;{'valid_names'}-&gt;{$key};
          if (UNIVERSAL::isa($mapped, 'ARRAY')) {
            my($value) = $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;{$$mapped[1]};
            if (defined $value) {
              ## Bypass the process_assignment() defined in this class
              ## to avoid unwanted keyword mapping.
              $self-&gt;SUPER::process_assignment($key, $value);
            }
          }
        }

        ## Set some defaults (if they haven't already been set)
        if (!defined $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;{'pre_filename'}) {
          $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;{'pre_filename'} = [ '' ];
        }
        if (!defined $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;{'pre_extension'}) {
          $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;{'pre_extension'} = [ '' ];
        }
        if (!defined $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;{'automatic'}) {
          $self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;{'automatic'} = 1;
        }
        last;
      }
      else {
        my(@values) = ();
        ## If this returns true, then we've found an assignment
        if ($self-&gt;parse_assignment($line, \@values)) {
          my($type)  = $values[0];
          my($name)  = $values[1];
          my($value) = $values[2];
          if (defined $customDefined{$name}) {
            if (($customDefined{$name} &amp; 0x01) != 0) {
              $value = $self-&gt;escape_regex_special($value);
              my(@array) = split(/\s*,\s*/, $value);
              $self-&gt;process_array_assignment(
                        \$self-&gt;{'valid_components'}-&gt;{$tag}, $type, \@array);
            }
            else {
              if (!defined $self-&gt;{'generated_exts'}-&gt;{$tag}) {
                $self-&gt;{'generated_exts'}-&gt;{$tag} = {};
              }
              ## First try to convert the value into a relative path
              $value = $self-&gt;relative($value, 0, 1);

              ## If that didn't work, try to convert it to the
              ## right environment variable form.
              if ($value =~ /\$\(.*\)/) {
                my($envstart, $envend) = $self-&gt;get_env_accessor();
                if (defined $envstart) {
                  if (!defined $envend) {
                    $envend = '';
                  }
                  $value =~ s/\$\(([^\)]+)\)/$envstart$1$envend/g;
                }
              }
              if (($customDefined{$name} &amp; 0x04) != 0) {
                if ($type eq 'assignment') {
                  $self-&gt;process_assignment(
                                     $name, $value,
                                     $self-&gt;{'generated_exts'}-&gt;{$tag});
                }
                elsif ($type eq 'assign_add') {
                  $self-&gt;process_assignment_add(
                                     $name, $value,
                                     $self-&gt;{'generated_exts'}-&gt;{$tag});
                }
                elsif ($type eq 'assign_sub') {
                  $self-&gt;process_assignment_sub(
                                     $name, $value,
                                     $self-&gt;{'generated_exts'}-&gt;{$tag});
                }
              }
              else {
                if (($customDefined{$name} &amp; 0x02) != 0) {
                  ## Transform the name from something outputext to
                  ## something files.  We expect this to match the
                  ## names of valid_assignments.
                  $name =~ s/outputext/files/g;
                }

                ## Get it ready for regular expressions
                $value = $self-&gt;escape_regex_special($value);

                ## Process the array assignment
                my(@array) = split(/\s*,\s*/, $value);
                $self-&gt;process_array_assignment(
                            \$self-&gt;{'generated_exts'}-&gt;{$tag}-&gt;{$name},
                            $type, \@array);
              }
            }
          }
          else {
            $status = 0;
            $errorString = "Invalid assignment name: $name";
            last;
          }
        }
        elsif ($line =~ /^(\w+)\s+(\w+)(\s*=\s*(\w+)?)?/) {
          ## Check for keyword mapping here
          my($keyword) = $1;
          my($newkey)  = $2;
          my($mapkey)  = $4;
          if ($keyword eq 'keyword') {
            if (defined $self-&gt;{'valid_names'}-&gt;{$newkey}) {
              $status = 0;
              $errorString = "Cannot map $newkey onto an " .
                             "existing keyword";
              last;
            }
            elsif (!defined $mapkey) {
              $self-&gt;{'valid_names'}-&gt;{$newkey} = 1;
            }
            elsif ($newkey ne $mapkey) {
              if (defined $customDefined{$mapkey}) {
                $self-&gt;{'valid_names'}-&gt;{$newkey} = [ $tag, $mapkey ];
              }
              else {
                $status = 0;
                $errorString = "Cannot map $newkey to an " .
                               "undefined custom keyword: $mapkey";
                last;
              }
            }
            else {
              $status = 0;
              $errorString = "Cannot map $newkey to $mapkey";
              last;
            }
          }
          else {
            $status = 0;
            $errorString = "Unrecognized line: $line";
            last;
          }
        }
        else {
          $status = 0;
          $errorString = "Unrecognized line: $line";
          last;
        }
      }
    }
  }

  return $status, $errorString;
}


sub remove_duplicate_addition {
  my($self)    = shift;
  my($name)    = shift;
  my($value)   = shift;
  my($nval)    = shift;

  ## If we are modifying the libs, libpaths or includes assignment with
  ## either addition or subtraction, we are going to
  ## perform a little fix on the value to avoid multiple
  ## libraries and to try to insure the correct linking order
  if ($name eq 'libpaths' || $name eq 'includes' || $name =~ /libs$/) {
    if (defined $nval) {
      my($allowed) = '';
      my(%parts)   = ();

      ## Convert the array into keys for a hash table
      @parts{@{$self-&gt;create_array($nval)}} = ();

      foreach my $val (@{$self-&gt;create_array($value)}) {
        if (!exists $parts{$val}) {
          $allowed .= $val . ' ';
        }
      }
      $allowed =~ s/\s+$//;
      return $allowed;
    }
  }

  return $value;
}


sub read_template_input {
  my($self)        = shift;
  my($status)      = 1;
  my($errorString) = undef;
  my($file)        = undef;
  my($tag)         = undef;
  my($ti)          = $self-&gt;get_ti_override();
  my($override)    = undef;

  if ($self-&gt;exe_target()) {
    if ($self-&gt;get_static() == 1) {
      $tag = 'lexe_template_input';
      if (!defined $self-&gt;{$tag}) {
        if (defined $$ti{'lib_exe'}) {
          $file = $$ti{'lib_exe'};
          $override = 1;
        }
        else {
          $file = $self-&gt;get_lib_exe_template_input_file();
        }
      }
    }
    else {
      $tag = 'dexe_template_input';
      if (!defined $self-&gt;{$tag}) {
        if (defined $$ti{'dll_exe'}) {
          $file = $$ti{'dll_exe'};
          $override = 1;
        }
        else {
          $file = $self-&gt;get_dll_exe_template_input_file();
        }
      }
    }
  }
  else {
    if ($self-&gt;get_static() == 1) {
      $tag = 'lib_template_input';
      if (!defined $self-&gt;{$tag}) {
        if (defined $$ti{'lib'}) {
          $file = $$ti{'lib'};
          $override = 1;
        }
        else {
          $file = $self-&gt;get_lib_template_input_file();
        }
      }
    }
    else {
      $tag = 'dll_template_input';
      if (!defined $self-&gt;{$tag}) {
        if (defined $$ti{'dll'}) {
          $file = $$ti{'dll'};
          $override = 1;
        }
        else {
          $file = $self-&gt;get_dll_template_input_file();
        }
      }
    }
  }

  if (defined $file) {
    my($file) = $self-&gt;search_include_path("$file.$TemplateInputExtension");
    if (defined $file) {
      $self-&gt;{$tag} = new TemplateInputReader($self-&gt;get_include_path());
      ($status, $errorString) = $self-&gt;{$tag}-&gt;read_file($file);
    }
    else {
      if ($override) {
        $status = 0;
        $errorString = 'Unable to locate template input file.';
      }
    }
  }

  return $status, $errorString;
}


sub already_added {
  my($self)  = shift;
  my($array) = shift;
  my($name)  = shift;

  foreach my $file (@$array) {
    if ($file eq $name) {
      return 1;
    }
  }

  ## If we haven't matched the name yet and the name
  ## begins with ./, we will remove it and try again.
  if ($name =~ s/^\.\///) {
    return $self-&gt;already_added($array, $name);
  }

  return 0;
}


sub get_applied_custom_keyword {
  my($self)  = shift;
  my($name)  = shift;
  my($type)  = shift;
  my($file)  = shift;
  my($value) = undef;

  if (defined $self-&gt;{'flag_overrides'}-&gt;{$type}-&gt;{$file}-&gt;{$name}) {
    $value = $self-&gt;{'flag_overrides'}-&gt;{$type}-&gt;{$file}-&gt;{$name};
  }
  else {
    $value = $self-&gt;get_assignment($name,
                                   $self-&gt;{'generated_exts'}-&gt;{$type});
  }
  return $self-&gt;relative($value, 1);
}


sub add_optional_filename_portion {
  my($self)    = shift;
  my($gentype) = shift;
  my($tag)     = shift;
  my($file)    = shift;
  my($array)   = shift;

  foreach my $name (keys %{$self-&gt;{'generated_exts'}-&gt;{$gentype}-&gt;{'optional'}-&gt;{$tag}}) {
    foreach my $opt (keys %{$self-&gt;{'generated_exts'}-&gt;{$gentype}-&gt;{'optional'}-&gt;{$tag}-&gt;{$name}}) {
      my($ok)    = undef;
      my($value) = $self-&gt;get_applied_custom_keyword($name,
                                                     $gentype, $file);
      if (defined $value) {
        if ($opt =~ /^!\s*(.*)/) {
          $ok = (index($value, $1) == -1);
        }
        else {
          $ok = (index($value, $opt) &gt;= 0);
        }
        if ($ok) {
          ## Add the optional portion
          push(@$array, @{$self-&gt;{'generated_exts'}-&gt;{$gentype}-&gt;{'optional'}-&gt;{$tag}-&gt;{$name}-&gt;{$opt}});
        }
      }
    }
  }
}


sub get_pre_keyword_array {
  my($self)    = shift;
  my($keyword) = shift;
  my($gentype) = shift;
  my($tag)     = shift;
  my($file)    = shift;

  ## Get the general pre extension array
  my(@array) = @{$self-&gt;{'generated_exts'}-&gt;{$gentype}-&gt;{$keyword}};

  ## Add the component specific pre extension array
  my(@additional) = ();
  $tag =~ s/files$/$keyword/;
  if (defined $self-&gt;{'generated_exts'}-&gt;{$gentype}-&gt;{$tag}) {
    push(@additional, @{$self-&gt;{'generated_exts'}-&gt;{$gentype}-&gt;{$tag}});
  }

  ## Add in any optional portion to the array
  foreach my $itag ($keyword, $tag) {
    $self-&gt;add_optional_filename_portion($gentype, $itag,
                                         $file, \@additional);
  }

  ## If the current array only has the default,
  ## then we need to remove it
  if ($#array == 0 &amp;&amp; $array[0] eq '' &amp;&amp; $#additional &gt;= 0) {
    pop(@array);
  }
  push(@array, @additional);

  return @array;
}


sub generated_filename_arrays {
  my($self)  = shift;
  my($part)  = shift;
  my($type)  = shift;
  my($tag)   = shift;
  my($file)  = shift;
  my($rmesc) = shift;
  my($noext) = shift;
  my(@array) = ();
  my(@pearr) = $self-&gt;get_pre_keyword_array('pre_extension',
                                            $type, $tag, $file);
  my(@pfarr) = $self-&gt;get_pre_keyword_array('pre_filename',
                                            $type, $tag, $file);
  my(@exts)  = (defined $self-&gt;{'generated_exts'}-&gt;{$type}-&gt;{$tag} ?
                  @{$self-&gt;{'generated_exts'}-&gt;{$type}-&gt;{$tag}} : ());

  if ($#exts == -1) {
    my($backtag) = $tag;
    if ($backtag =~ s/files$/outputext/) {
      $self-&gt;add_optional_filename_portion($type, $backtag,
                                           $file, \@exts);
    }
  }

  if ($#pearr == 0 &amp;&amp; $#pfarr == 0 &amp;&amp; $#exts == -1 &amp;&amp;
      $pearr[0] eq '' &amp;&amp; $pfarr[0] eq '') {
    ## If both arrays are defined to be the defaults, then there
    ## is nothing for us to do.
  }
  else {
    my($dir)  = '';
    my($base) = undef;

    ## Correctly deal with pre filename and directories
    if ($part =~ /(.*[\/\\])([^\/\\]+)$/) {
      $dir = $1;
      $base = $2;
    }
    else {
      $base = $part;
    }

    ## Loop through creating all of the possible file names
    foreach my $pe (@pearr) {
      push(@array, []);
      foreach my $pf (@pfarr) {
        if ($noext) {
          push(@{$array[$#array]}, "$dir$pf$base$pe");
        }
        else {
          foreach my $ext (@exts) {
            if ($rmesc) {
              $ext =~ s/\\\././g;
            }
            push(@{$array[$#array]}, "$dir$pf$base$pe$ext");
          }
        }
      }
    }
  }

  return @array;
}


sub generated_filenames {
  my($self)  = shift;
  my($part)  = shift;
  my($type)  = shift;
  my($tag)   = shift;
  my($file)  = shift;
  my($rmesc) = shift;
  my($noext) = shift;
  my(@files) = ();
  my(@array) = $self-&gt;generated_filename_arrays($part, $type, $tag,
                                                $file, $rmesc, $noext);

  foreach my $array (@array) {
    push(@files, @$array);
  }

  return @files;
}


sub add_generated_files {
  my($self)    = shift;
  my($gentype) = shift;
  my($tag)     = shift;
  my($arr)     = shift;
  my($wanted)  = $self-&gt;{'valid_components'}-&gt;{$gentype}-&gt;[0];

  ## Remove the escape sequences for the wanted extension
  $wanted =~ s/\\//g;

  ## Get the generated filenames
  my(@added) = ();
  foreach my $file (@$arr) {
    foreach my $gen ($self-&gt;generated_filenames($file, $gentype, $tag,
                                                "$file$wanted", 0, 1)) {
      $self-&gt;list_generated_file($gentype, $tag, \@added, $gen, $file);
    }
  }

  if ($#added &gt;= 0) {
    my($names) = $self-&gt;{$tag};

    ## Get all files in one list and save the directory
    ## and component group in a hashed array.
    my(@all) = ();
    my(%dircomp) = ();
    foreach my $name (keys %$names) {
      foreach my $key (keys %{$$names{$name}}) {
        push(@all, @{$$names{$name}-&gt;{$key}});
        foreach my $file (@{$$names{$name}-&gt;{$key}}) {
          $dircomp{dirname($file)} = $key;
        }
      }
    }

    ## Create a small array of only the files we want to add.
    ## We put them all together so we can keep them in order when
    ## we put them at the front of the main file list.
    my(@oktoadd) = ();
    foreach my $file (@added) {
      if (!$self-&gt;already_added(\@all, $file)) {
        push(@oktoadd, $file);
      }
    }

    ## If we have files to add, make sure we add them to a group
    ## that has the same directory location as the files we're adding.
    if ($#oktoadd &gt;= 0) {
      my($key) = $dircomp{dirname($oktoadd[0])};
      if (!defined $key) {
        $key = $self-&gt;get_default_element_name();
      }
      foreach my $name (keys %$names) {
        unshift(@{$$names{$name}-&gt;{$key}}, @oktoadd);
      }
    }
  }
}


sub generate_default_target_names {
  my($self) = shift;

  if (!$self-&gt;exe_target()) {
    my($sharedname) = $self-&gt;get_assignment('sharedname');
    if (defined $sharedname &amp;&amp;
        !defined $self-&gt;get_assignment('staticname')) {
      $self-&gt;process_assignment('staticname', $sharedname);
    }
    my($staticname) = $self-&gt;get_assignment('staticname');
    if (defined $staticname &amp;&amp;
        !defined $self-&gt;get_assignment('sharedname')) {
      $self-&gt;process_assignment('sharedname', $staticname);
      $sharedname = $staticname;
    }

    ## If it's neither an exe or library target, we will search
    ## through the source files for a main()
    if (!$self-&gt;lib_target()) {
      my($fh)      = new FileHandle();
      my($exename) = undef;
      my(@sources) = $self-&gt;get_component_list('source_files', 1);
      foreach my $file (@sources) {
        if (open($fh, $file)) {
          while(&lt;$fh&gt;) {
            ## Remove c++ comments (ignore c style comments for now)
            $_ =~ s/\/\/.*//;

            ## Check for main
            if (/(main|ACE_MAIN|ACE_WMAIN|ACE_TMAIN)\s*\(/) {
              ## If we found a main, set the exename to the basename
              ## of the cpp file with the extension removed
              $exename = basename($file);
              $exename =~ s/\.[^\.]+$//;
              last;
            }
          }
          close($fh);
        }

        ## Set the exename assignment
        if (defined $exename) {
          $self-&gt;process_assignment('exename', $exename);
          last;
        }
      }

      ## If we still don't have a project type, then we will
      ## default to a library if there are source files
      if (!$self-&gt;exe_target() &amp;&amp; $#sources &gt;= 0) {
        my($base) = $self-&gt;get_assignment('project_name');
        $self-&gt;process_assignment('sharedname', $base);
        $self-&gt;process_assignment('staticname', $base);
      }
    }
  }

  ## If we are generating only static projects, then we need to
  ## unset the sharedname, so that we can insure that projects of
  ## various types only generate static targets.
  if ($self-&gt;get_static() == 1) {
    my($sharedname) = $self-&gt;get_assignment('sharedname');
    if (defined $sharedname) {
      $self-&gt;process_assignment('sharedname', undef);
    }
  }
}


sub generate_default_pch_filenames {
  my($self)    = shift;
  my($files)   = shift;
  my($pchhdef) = (defined $self-&gt;get_assignment('pch_header'));
  my($pchcdef) = (defined $self-&gt;get_assignment('pch_source'));

  if (!$pchhdef || !$pchcdef) {
    my($pname)     = $self-&gt;escape_regex_special(
                             $self-&gt;get_assignment('project_name'));
    my($hcount)    = 0;
    my($ccount)    = 0;
    my($hmatching) = undef;
    my($cmatching) = undef;
    foreach my $file (@$files) {
      ## If the file doesn't even contain _pch, then there's no point
      ## in looping through all of the extensions
      if ($file =~ /_pch/) {
        if (!$pchhdef) {
          foreach my $ext (@{$self-&gt;{'valid_components'}-&gt;{'header_files'}}) {
            if ($file =~ /(.*_pch$ext)$/) {
              $self-&gt;process_assignment('pch_header', $1);
              ++$hcount;
              if ($file =~ /$pname/) {
                $hmatching = $file;
              }
              last;
            }
          }
        }
        if (!$pchcdef) {
          foreach my $ext (@{$self-&gt;{'valid_components'}-&gt;{'source_files'}}) {
            if ($file =~ /(.*_pch$ext)$/) {
              $self-&gt;process_assignment('pch_source', $1);
              ++$ccount;
              if ($file =~ /$pname/) {
                $cmatching = $file;
              }
              last;
            }
          }
        }
      }
    }
    if (!$pchhdef &amp;&amp; $hcount &gt; 1 &amp;&amp; defined $hmatching) {
      $self-&gt;process_assignment('pch_header', $hmatching);
    }
    if (!$pchcdef &amp;&amp; $ccount &gt; 1 &amp;&amp; defined $cmatching) {
      $self-&gt;process_assignment('pch_source', $cmatching);
    }
  }
}


sub fix_pch_filenames {
  my($self) = shift;
  foreach my $type ('pch_header', 'pch_source') {
    my($pch) = $self-&gt;get_assignment($type);
    if (defined $pch &amp;&amp; $pch eq '') {
      $self-&gt;process_assignment($type, undef);
    }
  }
}


sub remove_extra_pch_listings {
  my($self) = shift;
  my(@pchs) = ('pch_header', 'pch_source');
  my(@tags) = ('header_files', 'source_files');

  for(my $j = 0; $j &lt;= $#pchs; ++$j) {
    my($pch) = $self-&gt;get_assignment($pchs[$j]);

    if (defined $pch) {
      ## If we are converting slashes, then we need to
      ## convert the pch file back to forward slashes
      if ($self-&gt;{'convert_slashes'}) {
        $pch =~ s/\\/\//g;
      }

      ## Find out which files are duplicated
      my($names) = $self-&gt;{$tags[$j]};
      foreach my $name (keys %$names) {
        my($comps) = $$names{$name};
        foreach my $key (keys %$comps) {
          my($array) = $$comps{$key};
          my($count) = scalar(@$array);
          for(my $i = 0; $i &lt; $count; ++$i) {
            if ($pch eq $$array[$i]) {
              splice(@$array, $i, 1);
              --$count;
            }
          }
        }
      }
    }
  }
}


sub sift_files {
  my($self)   = shift;
  my($files)  = shift;
  my($exts)   = shift;
  my($pchh)   = shift;
  my($pchc)   = shift;
  my($tag)    = shift;
  my($array)  = shift;
  my($alldir) = shift;
  my(@saved)  = ();
  my($ec)     = $self-&gt;{'exclude_components'};

  foreach my $file (@$files) {
    foreach my $ext (@$exts) {
      ## Always exclude the precompiled header and cpp
      if ($file =~ /$ext$/ &amp;&amp; (!defined $pchh || $file ne $pchh) &amp;&amp;
                              (!defined $pchc || $file ne $pchc)) {
        my($exclude) = 0;
        if (defined $$ec{$tag}) {
          foreach my $exc (@{$$ec{$tag}}) {
            if ($file =~ /$exc$/) {
              $exclude = 1;
              last;
            }
          }
        }
        elsif (!$alldir &amp;&amp; $tag eq 'resource_files') {
          ## Save these files for later.  There may
          ## be more than one and we want to try and
          ## find the one that corresponds to this project
          $exclude = 1;
          push(@saved, $file);
        }

        if (!$exclude &amp;&amp; !$self-&gt;already_added($array, $file)) {
          push(@$array, $file);
        }
        last;
      }
    }
  }

  ## Now deal with the saved files
  if (defined $saved[0]) {
    if ($#saved == 0) {
      ## Theres only one rc file, take it
      push(@$array, $saved[0]);
    }
    else {
      my($unescaped) = $self-&gt;transform_file_name(
                               $self-&gt;get_assignment('project_name'));
      my($pjname)    = $self-&gt;escape_regex_special($unescaped);
      foreach my $save (@saved) {
        my($file) = $self-&gt;escape_regex_special($save);
        if ($unescaped =~ /$file/ || $save =~ /$pjname/) {
          if (!$self-&gt;already_added($array, $save)) {
            push(@$array, $save);
          }
        }
      }
    }
  }
}


sub generate_default_components {
  my($self)    = shift;
  my($files)   = shift;
  my($passed)  = shift;
  my($vc)      = $self-&gt;{'valid_components'};
  my(@tags)    = (defined $passed ? $passed : keys %$vc);
  my($pchh)    = $self-&gt;get_assignment('pch_header');
  my($pchc)    = $self-&gt;get_assignment('pch_source');
  my($recurse) = $self-&gt;get_assignment('recurse');

  foreach my $tag (@tags) {
    my($exts) = $$vc{$tag};
    if (defined $$exts[0]) {
      if (defined $self-&gt;{$tag}) {
        ## If the tag is defined, then process directories
        my($names) = $self-&gt;{$tag};
        foreach my $name (keys %$names) {
          my($comps) = $$names{$name};
          foreach my $comp (keys %$comps) {
            my($array) = $$comps{$comp};
            if (defined $passed) {
              $self-&gt;sift_files($files, $exts, $pchh, $pchc, $tag, $array);
            }
            else {
              my(@built) = ();
              foreach my $file (@$array) {
                if (-d $file) {
                  my($alldir) = $recurse ||
                      $self-&gt;{'flag_overrides'}-&gt;{$tag}-&gt;{$file}-&gt;{'recurse'};
                  my(@gen) = $self-&gt;generate_default_file_list(
                                      $file, [], $alldir);
                  $self-&gt;sift_files(\@gen, $exts, $pchh,
                                    $pchc, $tag, \@built, $alldir);
                }
                else {
                  if (!$self-&gt;already_added(\@built, $file)) {
                    push(@built, $file);
                  }
                }
              }
              $$comps{$comp} = \@built;
            }
          }
        }
      }
      else {
        ## Generate default values for undefined tags
        my($defcomp) = $self-&gt;get_default_element_name();
        my($names) = {};
        $self-&gt;{$tag} = $names;
        my($comps) = {};
        $$names{$self-&gt;get_default_component_name()} = $comps;
        $$comps{$defcomp} = [];
        my($array) = $$comps{$defcomp};

        $self-&gt;{'defaulted'}-&gt;{$tag} = 1;

        if (!defined $specialComponents{$tag}) {
          $self-&gt;sift_files($files, $exts, $pchh, $pchc, $tag, $array);
          if (defined $sourceComponents{$tag}) {
            foreach my $gentype (keys %{$self-&gt;{'generated_exts'}}) {
              ## If we are auto-generating the source_files, then
              ## we need to make sure that any generated source
              ## files that are added are put at the front of the list.
              my(@front)  = ();
              my(@copy)   = @$array;
              my(@input)  = $self-&gt;get_component_list($gentype, 1);
              my($wanted) = $self-&gt;{'valid_components'}-&gt;{$gentype}-&gt;[0];

              @$array = ();
              foreach my $file (@copy) {
                my($found) = 0;
                foreach my $input (@input) {
                  my($part) = $input;
                  $part =~ s/$wanted$//;
                  $part = $self-&gt;escape_regex_special($part);
                  foreach my $re ($self-&gt;generated_filenames($part, $gentype,
                                                             $tag, $input,
                                                             0)) {
                    if ($file =~ /$re$/) {
                      ## No need to check for previously added files
                      ## here since there are none.
                      push(@front, $file);
                      $found = 1;
                      last;
                    }
                  }
                  if ($found) {
                    last;
                  }
                }
                if (!$found) {
                  ## No need to check for previously added files
                  ## here since there are none.
                  push(@$array, $file);
                }
              }

              if (defined $front[0]) {
                unshift(@$array, @front);
              }
            }
          }
        }
      }
    }
  }
}


sub remove_duplicated_files {
  my($self)   = shift;
  my($dest)   = shift;
  my($source) = shift;
  my($names)  = $self-&gt;{$dest};
  my(@slist)  = $self-&gt;get_component_list($source, 1);
  my(%shash)  = ();

  ## Convert the array into keys for a hash table
  @shash{@slist} = ();

  ## Find out which source files are listed
  foreach my $name (keys %$names) {
    foreach my $key (keys %{$$names{$name}}) {
      my($array) = $$names{$name}-&gt;{$key};
      my($count) = scalar(@$array);
      for(my $i = 0; $i &lt; $count; ++$i) {
        ## Is the source file in the component array?
        if (exists $shash{$$array[$i]}) {
          ## Remove the element and fix the index and count
          splice(@$array, $i, 1);
          --$count;
          --$i;
        }
      }
    }
  }
}


sub generated_source_listed {
  my($self)  = shift;
  my($gent)  = shift;
  my($tag)   = shift;
  my($arr)   = shift;
  my($sext)  = shift;
  my($names) = $self-&gt;{$tag};

  ## Find out which generated source files are listed
  foreach my $name (keys %$names) {
    my($comps) = $$names{$name};
    foreach my $key (keys %$comps) {
      foreach my $val (@{$$comps{$key}}) {
        foreach my $i (@$arr) {
          my($ifile) = $self-&gt;escape_regex_special($i);
          foreach my $wanted (@$sext) {
            ## Remove any escape characters from the extension
            my($oext) = $wanted;
            $oext =~ s/\\//g;
            foreach my $re ($self-&gt;generated_filenames($ifile, $gent,
                                                       $tag, "$i$oext", 0)) {
              if ($val =~ /$re$/) {
                return 1;
              }
            }
          }
        }
      }
    }
  }

  return 0;
}


sub list_default_generated {
  my($self)    = shift;
  my($gentype) = shift;
  my($tags)    = shift;

  if ($self-&gt;{'generated_exts'}-&gt;{$gentype}-&gt;{'automatic'}) {
    ## After all source and headers have been defaulted, see if we
    ## need to add the generated .h, .i and .cpp files
    if (defined $self-&gt;{$gentype}) {
      ## Build up the list of files
      my(@arr)    = ();
      my($wanted) = $self-&gt;{'valid_components'}-&gt;{$gentype}-&gt;[0];
      my($names)  = $self-&gt;{$gentype};
      foreach my $name (keys %$names) {
        my($comps) = $$names{$name};
        foreach my $key (keys %$comps) {
          my($array) = $$comps{$key};
          foreach my $val (@$array) {
            my($f) = $val;
            $f =~ s/$wanted$//;
            push(@arr, $f);
          }
        }
      }

      foreach my $type (@$tags) {
        if (!$self-&gt;generated_source_listed(
                              $gentype, $type, \@arr,
                              $self-&gt;{'valid_components'}-&gt;{$gentype})) {
          $self-&gt;add_generated_files($gentype, $type, \@arr);
        }
      }
    }
  }
}


sub prepend_gendir {
  my($self)    = shift;
  my($created) = shift;
  my($ofile)   = shift;
  my($gentype) = shift;
  my($key)     = undef;

  foreach my $ext (@{$self-&gt;{'valid_components'}-&gt;{$gentype}}) {
    my($e) = $ext;
    $e =~ s/\\//g;
    $key = "$ofile$e";
    if (defined $self-&gt;{'flag_overrides'}-&gt;{$gentype}-&gt;{$key}) {
      last;
    }
    else {
      $key = undef;
    }
  }

  if (defined $key) {
    foreach my $ma (@{$self-&gt;{'matching_assignments'}-&gt;{$gentype}}) {
      if ($ma eq 'gendir') {
        if (defined $self-&gt;{'flag_overrides'}-&gt;{$gentype}-&gt;{$key}-&gt;{$ma}) {
          return "$self-&gt;{'flag_overrides'}-&gt;{$gentype}-&gt;{$key}-&gt;{$ma}/" .
                 basename($created);
        }
      }
    }
  }

  return $created;
}


sub list_generated_file {
  my($self)    = shift;
  my($gentype) = shift;
  my($tag)     = shift;
  my($array)   = shift;
  my($file)    = shift;
  my($ofile)   = shift;

  $file = $self-&gt;escape_regex_special($file);

  foreach my $gen ($self-&gt;get_component_list($gentype, 1)) {
    my($input) = $gen;
    foreach my $ext (@{$self-&gt;{'valid_components'}-&gt;{$gentype}}) {
      ## Remove the extension.
      ## If it works, then we can exit this loop.
      if ($gen =~ s/$ext$//) {
        last;
      }
    }

    ## See if we need to add the file
    foreach my $re ($self-&gt;generated_filenames($gen, $gentype, $tag, $input, 1)) {
      if ($re =~ /$file(.*)?$/) {
        my($created) = "$file$1";
        $created =~ s/\\//g;
        if (defined $ofile) {
          $created = $self-&gt;prepend_gendir($created, $ofile, $gentype);
        }
        if (!$self-&gt;already_added($array, $created)) {
          push(@$array, $created);
        }
        last;
      }
    }
  }
}


sub add_corresponding_component_files {
  my($self)   = shift;
  my($ftags)  = shift;
  my($tag)    = shift;
  my($names)  = undef;
  my($grname) = $grouped_key . $tag;
  my($defel)  = $self-&gt;get_default_element_name();

  ## Collect up all of the files that have already been listed
  ## with the extension removed.
  my(%filecomp) = ();
  foreach my $filetag (@$ftags) {
    $names = $self-&gt;{$filetag};
    foreach my $name (keys %$names) {
      foreach my $comp (keys %{$$names{$name}}) {
        foreach my $sfile (@{$$names{$name}-&gt;{$comp}}) {
          my($mod) = $sfile;
          $mod =~ s/\.[^\.]+$//;
          $filecomp{$mod} = $comp;
        }
      }
    }
  }

  ## Create a hash array keyed off of the existing files of the type
  ## that we plan on adding.
  my(%scfiles) = ();
  $names = $self-&gt;{$tag};
  foreach my $name (keys %$names) {
    foreach my $comp (keys %{$$names{$name}}) {
      @scfiles{@{$$names{$name}-&gt;{$comp}}} = ();
    }
  }

  ## Create an array of extensions for the files we want to add
  my(@exts) = ();
  foreach my $ext (@{$self-&gt;{'valid_components'}-&gt;{$tag}}) {
    push(@exts, $ext);
    $exts[$#exts] =~ s/\\//g;
  }

  ## Check each file against a possible new file addition
  my($adddefaultgroup) = 0;
  my($oktoadddefault)  = 0;
  foreach my $sfile (keys %filecomp) {
    my($found) = 0;
    foreach my $ext (@exts) {
      if (exists $scfiles{"$sfile$ext"}) {
        $found = 1;
        last;
      }
    }

    if (!$found) {
      ## Get the array of files for the selected component name
      my($array) = [];
      my($comp)  = $filecomp{$sfile};
      foreach my $name (keys %$names) {
        $array = $$names{$name}-&gt;{$comp};
      }

      ## First check to see if the file exists
      foreach my $ext (@exts) {
        if (-r "$sfile$ext") {
          push(@$array, "$sfile$ext");
          $found = 1;
          last;
        }
      }

      ## If it doesn't exist, see if it will be generated
      if (!$found) {
        foreach my $gentype (keys %{$self-&gt;{'generated_exts'}}) {
          $self-&gt;list_generated_file($gentype, $tag, $array, $sfile);
        }
      }

      ## If we have any files at all in the component array, check
      ## to see if we need to add a new group name
      if (defined $$array[0]) {
        my($compexists) = undef;
        my($grval)      = $self-&gt;get_assignment($grname);
        if (defined $grval) {
          foreach my $grkey (@{$self-&gt;create_array($grval)}) {
            if ($grkey eq $comp) {
              $compexists = 1;
              last;
            }
          }
        }

        if (!$compexists) {
          if ($comp eq $defel) {
            $adddefaultgroup = 1;
          }
          else {
            $self-&gt;process_assignment_add($grname, $comp);
            $oktoadddefault = 1;
          }
        }

        ## Put the array back into the component list
        foreach my $name (keys %$names) {
          $$names{$name}-&gt;{$comp} = $array;
        }
      }
    }
  }

  ## We only need to add the default group name if we wanted to
  ## add the default group when adding new files and we added a group
  ## by some other name.  Otherwise, defaulted files would always be
  ## in a group, which is not what we want.
  if ($adddefaultgroup &amp;&amp; $oktoadddefault) {
    $self-&gt;process_assignment_add($grname, $defel);
  }
}


sub get_default_project_name {
  my($self) = shift;
  my($name) = $self-&gt;{'current_input'};

  if ($name eq '') {
    $name = $self-&gt;transform_file_name($self-&gt;base_directory());
  }
  else {
    ## Since files on UNIX can have back slashes, we transform them
    ## into underscores.
    $name =~ s/\\/_/g;

    ## Convert then name to a usable name
    $name = $self-&gt;transform_file_name($name);

    ## Take off the extension
    $name =~ s/\.[^\.]+$//;
  }

  return $name;
}


sub remove_excluded {
  my($self) = shift;
  my(@tags) = @_;

  ## Process each file type and remove the excluded files
  foreach my $tag (@tags) {
    my($names) = $self-&gt;{$tag};
    foreach my $name (keys %$names) {
      foreach my $comp (keys %{$$names{$name}}) {
        my($count) = scalar(@{$$names{$name}-&gt;{$comp}});
        for(my $i = 0; $i &lt; $count; ++$i) {
          my($file) = $$names{$name}-&gt;{$comp}-&gt;[$i];
          if (defined $self-&gt;{'remove_files'}-&gt;{$tag}-&gt;{$file}) {
            splice(@{$$names{$name}-&gt;{$comp}}, $i, 1);
            --$i;
            --$count;
          }
        }
      }
    }
    delete $self-&gt;{'remove_files'}-&gt;{$tag};
  }
}

sub generate_defaults {
  my($self) = shift;

  ## Generate default project name
  if (!defined $self-&gt;get_assignment('project_name')) {
    $self-&gt;set_project_name($self-&gt;get_default_project_name());
  }

  ## Generate the default pch file names (if needed)
  my(@files) = $self-&gt;generate_default_file_list(
                                 '.', [], $self-&gt;get_assignment('recurse'));
  $self-&gt;generate_default_pch_filenames(\@files);

  ## If the pch file names are empty strings then we need to fix that
  $self-&gt;fix_pch_filenames();

  ## Generate default components, but %specialComponents
  ## are skipped in the initial default components generation
  $self-&gt;generate_default_components(\@files);

  ## This needs to be sorted in order to be used with the
  ## remove_duplicated_files method.
  my(@scomp) = sort keys %sourceComponents;

  ## Remove source files that are also listed in the template files
  ## If we do not do this, then generated projects can be invalid.
  $self-&gt;remove_duplicated_files(@scomp);

  ## If pch files are listed in header_files or source_files more than
  ## once, we need to remove the extras
  $self-&gt;remove_extra_pch_listings();

  ## Generate the default generated list of source files
  ## only if we defaulted the generated file list
  foreach my $gentype (keys %{$self-&gt;{'generated_exts'}}) {
    $self-&gt;list_default_generated($gentype, \@scomp);
  }

  ## Now that all of the source files have been added
  ## we need to remove those that have need to be removed
  $self-&gt;remove_excluded('source_files');

  ## Add %specialComponents files based on the
  ## source_components (i.e. .h and .i or .inl based on .cpp)
  foreach my $tag (keys %specialComponents) {
    $self-&gt;add_corresponding_component_files(\@scomp, $tag);
  }

  ## Now, if the %specialComponents are still empty
  ## then take any file that matches the components extension
  foreach my $tag (keys %specialComponents) {
    if (!$self-&gt;{'special_supplied'}-&gt;{$tag}) {
      my($names) = $self-&gt;{$tag};
      if (defined $names) {
        ## We only want to generate default components if we have
        ## defaulted the source files or we have no files listed
        ## in the current special component.
        my($ok) = $self-&gt;{'defaulted'}-&gt;{'source_files'};
        if (!$ok) {
          my(@all) = ();
          foreach my $name (keys %$names) {
            foreach my $key (keys %{$$names{$name}}) {
              push(@all, @{$$names{$name}-&gt;{$key}});
            }
          }
          $ok = ($#all == -1);
        }
        if ($ok) {
          $self-&gt;generate_default_components(\@files, $tag);
        }
      }
    }
  }

  ## Now that all of the other files have been added
  ## we need to remove those that have need to be removed
  my(@rmkeys) = keys %{$self-&gt;{'remove_files'}};
  if ($#rmkeys != -1) {
    $self-&gt;remove_excluded(@rmkeys);
  }

  ## Generate default target names after all source files are added
  $self-&gt;generate_default_target_names();
}


sub set_project_name {
  my($self) = shift;
  my($name) = shift;

  if ($self-&gt;get_apply_project()) {
    my($nmod) = $self-&gt;get_name_modifier();

    if (defined $nmod) {
      $nmod =~ s/\*/$name/g;
      $name = $nmod;
    }
  }

  $self-&gt;process_assignment('project_name', $name);
}


sub project_name {
  my($self) = shift;
  return $self-&gt;get_assignment('project_name');
}


sub lib_target {
  my($self) = shift;
  return (defined $self-&gt;get_assignment('sharedname') ||
          defined $self-&gt;get_assignment('staticname'));
}


sub exe_target {
  my($self) = shift;
  return (defined $self-&gt;get_assignment('exename'));
}


sub get_component_list {
  my($self)      = shift;
  my($tag)       = shift;
  my($noconvert) = shift;
  my($names)     = $self-&gt;{$tag};
  my(@list)      = ();

  foreach my $name (keys %$names) {
    foreach my $key (keys %{$$names{$name}}) {
      push(@list, @{$$names{$name}-&gt;{$key}});
    }
  }

  ## By default, if 'convert_slashes' is true, then we convert slashes
  ## to backslashes.  There are cases where we do not want to convert
  ## the slashes, in that case get_component_list() was called with
  ## an additional parameter indicating this.
  if (!$noconvert &amp;&amp; $self-&gt;{'convert_slashes'}) {
    for(my $i = 0; $i &lt;= $#list; $i++) {
      $list[$i] = $self-&gt;slash_to_backslash($list[$i]);
    }
  }

  if ($self-&gt;{'sort_files'}) {
    @list = sort { $self-&gt;file_sorter($a, $b) } @list;
  }

  return @list;
}


sub check_custom_output {
  my($self)    = shift;
  my($based)   = shift;
  my($cinput)  = shift;
  my($ainput)  = shift;
  my($type)    = shift;
  my($comps)   = shift;
  my(@outputs) = ();

  foreach my $array ($self-&gt;generated_filename_arrays($cinput, $based,
                                                      $type, $ainput, 1)) {
    foreach my $built (@$array) {
      if (@$comps == 0) {
        push(@outputs, $built);
        last;
      }
      elsif (defined $specialComponents{$type} &amp;&amp;
             !$self-&gt;{'special_supplied'}-&gt;{$type}) {
        push(@outputs, $built);
        last;
      }
      else {
        my($base) = $built;
        if ($self-&gt;{'convert_slashes'}) {
          $base =~ s/\\/\//g;
        }
        my($re) = $self-&gt;escape_regex_special(basename($base));
        foreach my $c (@$comps) {
          ## We only match if the built file name matches from
          ## beginning to end or from a slash to the end.
          if ($c =~ /^$re$/ || $c =~ /[\/\\]$re$/) {
            push(@outputs, $built);
            last;
          }
        }
      }
    }
  }

  return @outputs;
}


sub get_special_value {
  my($self)   = shift;
  my($type)   = shift;
  my($cmd)    = shift;
  my($based)  = shift;
  my(@params) = @_;

  if ($type =~ /^custom_type/) {
    return $self-&gt;get_custom_value($cmd, $based, @params);
  }
  elsif ($type =~ /^grouped_/) {
    return $self-&gt;get_grouped_value($type, $cmd, $based);
  }

  return undef;
}


sub get_grouped_value {
  my($self)  = shift;
  my($type)  = shift;
  my($cmd)   = shift;
  my($based) = shift;
  my($value) = undef;

  ## Make it all lowercase
  $type = lc($type);

  ## Remove the grouped_ part
  $type =~ s/^$grouped_key//;

  ## Add the s if it isn't there
  if ($type !~ /s$/) {
    $type .= 's';
  }

  my($names) = $self-&gt;{$type};
  if ($cmd eq 'files') {
    foreach my $name (keys %$names) {
      my($comps) = $$names{$name};
      foreach my $comp (keys %$comps) {
        if ($comp eq $based) {
          if ($self-&gt;{'convert_slashes'}) {
            my(@converted) = ();
            foreach my $file (@{$$comps{$comp}}) {
              push(@converted, $self-&gt;slash_to_backslash($file));
            }
            $value = \@converted;
          }
          else {
            $value = $$comps{$comp};
          }
          if ($self-&gt;{'sort_files'}) {
            my(@sorted) = sort { $self-&gt;file_sorter($a, $b) } @$value;
            $value = \@sorted;
          }
          last;
        }
      }
    }
  }
  elsif ($cmd eq 'component_name') {
    ## If there is more than one name, then we will need
    ## to deal with that at a later time.
    foreach my $name (keys %$names) {
      $value = $name;
    }
  }

  return $value;
}


sub get_command_subs {
  my($self)  = shift;
  my(%valid) = ();

  ## Add the built-in OS compatibility commands
  if ($self-&gt;{'convert_slashes'}) {
    $valid{'cat'} = 'type';
    $valid{'cp'}  = 'copy /y';
    $valid{'mv'}  = 'move /y';
    $valid{'rm'}  = 'del /f/s/q';
    $valid{'nul'} = 'nul';
  }
  else {
    $valid{'cat'} = 'cat';
    $valid{'cp'}  = 'cp -f';
    $valid{'mv'}  = 'mv -f';
    $valid{'rm'}  = 'rm -rf';
    $valid{'nul'} = '/dev/null';
  }

  ## Add the project specific compatibility commands
  $valid{'gt'}  = $self-&gt;get_gt_symbol();
  $valid{'lt'}  = $self-&gt;get_lt_symbol();
  $valid{'and'} = $self-&gt;get_and_symbol();
  $valid{'or'}  = $self-&gt;get_or_symbol();

  return \%valid;
}


sub convert_command_parameters {
  my($self)   = shift;
  my($str)    = shift;
  my($input)  = shift;
  my($output) = shift;
  my(%nowarn) = ();
  my(%valid)  = %{$self-&gt;{'command_subs'}};

  ## Add in the values that change for every call to this function
  $valid{'input'}     = $input;
  $valid{'output'}    = $output;
  $valid{'temporary'} = 'temp.$$$$.' . int(rand(0xffffffff));

  ## Add in the specific types of output files
  if (defined $output) {
    foreach my $type (keys %{$self-&gt;{'valid_components'}}) {
      my($key) = $type;
      $key =~ s/s$//gi;
      $nowarn{$key} = 1;
      foreach my $ext (@{$self-&gt;{'valid_components'}-&gt;{$type}}) {
        if ($output =~ /$ext$/) {
          $valid{$key} = $output;
        }
      }
    }
  }

  while ($str =~ /&lt;%(\w+)(\(\w+\))?%&gt;/) {
    my($name)     = $1;
    my($modifier) = $2;
    if (defined $modifier) {
      my($tmp) = $name;
      $name = $modifier;
      $name =~ s/[\(\)]//g;
      $modifier = $tmp;
    }

    if (exists $valid{$name}) {
      if (defined $valid{$name}) {
        my($replace) = $valid{$name};
        if (defined $modifier) {
          if ($modifier eq 'noextension') {
            $replace =~ s/\.[^\.]+$//;
          }
          else {
            $self-&gt;warning("Uknown postcommand " .
                           "parameter modifier $modifier.");
          }
        }
        $str =~ s/&lt;%\w+(\(\w+\))?%&gt;/$replace/;
      }
      else {
        $str =~ s/&lt;%\w+(\(\w+\))?%&gt;//;
      }
    }
    else {
      $str =~ s/&lt;%\w+(\(\w+\))?%&gt;//;

      ## We only want to warn the user that we did not recognize the
      ## pseudo template parameter if there was an input and an output
      ## file passed to this function.  If the 'postcommand' was used
      ## without the parenthesis (as in an if statement), then we don't
      ## want to warn the user.
      if (defined $input &amp;&amp; defined $output) {
        if (!defined $nowarn{$name}) {
          $self-&gt;warning("&lt;%$name%&gt; was not recognized in the postcommand.");
        }

        ## If we didn't recognize the pseudo template parameter then
        ## we don't want to return anything back.
        return undef;
      }
    }
  }

  return $str;
}


sub get_custom_value {
  my($self)   = shift;
  my($cmd)    = shift;
  my($based)  = shift;
  my(@params) = @_;
  my($value)  = undef;

  if ($cmd eq 'input_files') {
    my($generic) = 'generic_files';  ## Matches with generic_outputext
    my(@array) = $self-&gt;get_component_list($based);
    $value = \@array;

    $self-&gt;{'custom_output_files'} = {};
    my(%vcomps) = ();
    foreach my $vc (keys %{$self-&gt;{'valid_components'}}, $generic) {
      my(@comps) = $self-&gt;get_component_list($vc);
      $vcomps{$vc} = \@comps;
    }
    foreach my $input (@array) {
      my(@outputs) = ();
      my($ainput)  = $input;
      my($cinput)  = $input;

      ## Remove the extension
      $cinput =~ s/\.[^\.]+$//;

      ## If we are converting slashes,
      ## change them back for this parameter
      if ($self-&gt;{'convert_slashes'}) {
        $ainput =~ s/\\/\//g;
      }

      foreach my $vc (keys %{$self-&gt;{'valid_components'}}, $generic) {
        push(@outputs,
             $self-&gt;check_custom_output($based, $cinput,
                                        $ainput, $vc, $vcomps{$vc}));
      }
      $self-&gt;{'custom_output_files'}-&gt;{$input} = \@outputs;
    }
  }
  elsif ($cmd eq 'output_files') {
    # Generate output files based on $based
    if (defined $self-&gt;{'custom_output_files'}) {
      $value = $self-&gt;{'custom_output_files'}-&gt;{$based};
    }
  }
  elsif ($cmd eq 'source_output_files') {
    # Generate source output files based on $based
    if (defined $self-&gt;{'custom_output_files'}) {
      $value = [];
      foreach my $file (@{$self-&gt;{'custom_output_files'}-&gt;{$based}}) {
        foreach my $ext (@{$self-&gt;{'valid_components'}-&gt;{'source_files'}}) {
          if ($file =~ /$ext$/) {
            push(@$value, $file);
            last;
          }
        }
      }
    }
  }
  elsif ($cmd eq 'non_source_output_files') {
    # Generate non source output files based on $based
    if (defined $self-&gt;{'custom_output_files'}) {
      $value = [];
      foreach my $file (@{$self-&gt;{'custom_output_files'}-&gt;{$based}}) {
        my($source) = 0;
        foreach my $ext (@{$self-&gt;{'valid_components'}-&gt;{'source_files'}}) {
          if ($file =~ /$ext$/) {
            $source = 1;
            last;
          }
        }
        if (!$source) {
          push(@$value, $file);
        }
      }
    }
  }
  elsif ($cmd eq 'inputexts') {
    my(@array) = @{$self-&gt;{'valid_components'}-&gt;{$based}};
    foreach my $val (@array) {
      $val =~ s/\\\.//g;
    }
    $value = \@array;
  }
  elsif (defined $customDefined{$cmd} &amp;&amp;
         ($customDefined{$cmd} &amp; 0x04) != 0) {
    $value = $self-&gt;get_assignment($cmd,
                                   $self-&gt;{'generated_exts'}-&gt;{$based});
    if (defined $value &amp;&amp; ($customDefined{$cmd} &amp; 0x10) != 0) {
      $value = $self-&gt;convert_command_parameters($value, @params);
    }
  }
  elsif (defined $custom{$cmd}) {
    $value = $self-&gt;get_assignment($cmd,
                                   $self-&gt;{'generated_exts'}-&gt;{$based});
  }

  return $value;
}


sub check_features {
  my($self)     = shift;
  my($requires) = shift;
  my($avoids)   = shift;
  my($info)     = shift;
  my($status)   = 1;
  my($why)      = undef;

  if (defined $requires) {
    foreach my $require (split(/\s+/, $requires)) {
      my($fval) = $self-&gt;{'feature_parser'}-&gt;get_value($require);

      ## By default, if the feature is not listed, then it is enabled.
      if (defined $fval &amp;&amp; !$fval) {
        $why = "requires $require";
        $status = 0;
        last;
      }
    }
  }

  ## If it passes the requires, then check the avoids
  if ($status) {
    if (defined $avoids) {
      foreach my $avoid (split(/\s+/, $avoids)) {
        my($fval) = $self-&gt;{'feature_parser'}-&gt;get_value($avoid);

        ## By default, if the feature is not listed, then it is enabled.
        if (!defined $fval || $fval) {
          $why = "avoids $avoid";
          $status = 0;
          last;
        }
      }
    }
  }

  if ($info &amp;&amp; !$status) {
    $self-&gt;diagnostic("Skipping " . $self-&gt;get_assignment('project_name') .
                      " ($self-&gt;{'current_input'}), it $why.");
  }

  return $status;
}


sub need_to_write_project {
  my($self) = shift;

  foreach my $key ('source_files', keys %{$self-&gt;{'generated_exts'}}) {
    my($names) = $self-&gt;{$key};
    foreach my $name (keys %$names) {
      foreach my $key (keys %{$names-&gt;{$name}}) {
        if (defined $names-&gt;{$name}-&gt;{$key}-&gt;[0]) {
          return 1;
        }
      }
    }
  }

  return 0;
}


sub write_output_file {
  my($self)     = shift;
  my($name)     = shift;
  my($status)   = 0;
  my($error)    = undef;
  my($tover)    = $self-&gt;get_template_override();
  my($template) = (defined $tover ? $tover : $self-&gt;get_template());

  ## If the template files does not end in the template extension
  ## then we will add it on.
  if ($template !~ /$TemplateExtension$/) {
    $template = $template . ".$TemplateExtension";
  }

  ## If the template file does not contain a full path, then we
  ## will search through the include paths for it.
  my($tfile) = undef;
  if ($template =~ /^([a-z]:)?[\/\\]/i) {
    $tfile = $template;
  }
  else {
    $tfile = $self-&gt;search_include_path($template);
  }

  if (defined $tfile) {
    ## Read in the template values for the
    ## specific target and project type
    ($status, $error) = $self-&gt;read_template_input();

    if ($status) {
      my($tp) = new TemplateParser($self);

      ## Set the project_file assignment for the template parser
      $self-&gt;process_assignment('project_file', $name);

      ($status, $error) = $tp-&gt;parse_file($tfile);

      if ($status) {
        if (defined $self-&gt;{'source_callback'}) {
          my($cb)     = $self-&gt;{'source_callback'};
          my($pjname) = $self-&gt;get_assignment('project_name');
          my(@list)   = $self-&gt;get_component_list('source_files');
          if (UNIVERSAL::isa($cb, 'ARRAY')) {
            my(@copy) = @$cb;
            my($s) = shift(@copy);
            &amp;$s(@copy, $name, $pjname, @list);
          }
          elsif (UNIVERSAL::isa($cb, 'CODE')) {
            &amp;$cb($name, $pjname, @list);
          }
          else {
            $self-&gt;warning("Ignoring callback: $cb.");
          }
        }

        if ($self-&gt;get_toplevel()) {
          my($into)   = $self-&gt;get_into();
          my($outdir) = '.';
          my($oname)  = $name;

          if (defined $into) {
            $outdir = $self-&gt;getcwd();
            my($re) = $self-&gt;escape_regex_special($self-&gt;getstartdir());
            $outdir =~ s/^$re//;
            $outdir = $into . $outdir;
            $name = "$outdir/$name";
          }

          my($fh)  = new FileHandle();
          my($dir) = dirname($name);

          if ($dir ne '.') {
            mkpath($dir, 0, 0777);
          }

          if ($self-&gt;compare_output()) {
            ## First write the output to a temporary file
            my($tmp) = "$outdir/MPC$&gt;.$$";
            my($different) = 1;
            if (open($fh, "&gt;$tmp")) {
              my($lines) = $tp-&gt;get_lines();
              foreach my $line (@$lines) {
                print $fh $line;
              }
              close($fh);

              if (-r $name &amp;&amp;
                  -s $tmp == -s $name &amp;&amp; compare($tmp, $name) == 0) {
                $different = 0;
              }
            }
            else {
              $error = "Unable to open $tmp for output.";
              $status = 0;
            }

            if ($status) {
              ## If they are different, then rename the temporary file
              if ($different) {
                unlink($name);
                if (rename($tmp, $name)) {
                  $self-&gt;add_file_written($oname);
                }
                else {
                  $error = "Unable to open $name for output.";
                  $status = 0;
                }
              }
              else {
                ## We will pretend that we wrote the file
                unlink($tmp);
                $self-&gt;add_file_written($oname);
              }
            }
          }
          else {
            if (open($fh, "&gt;$name")) {
              my($lines) = $tp-&gt;get_lines();
              foreach my $line (@$lines) {
                print $fh $line;
              }
              close($fh);
              $self-&gt;add_file_written($oname);
            }
            else {
              $error = "Unable to open $name for output.";
              $status = 0;
            }
          }
        }
      }
    }
  }
  else {
    $error = "Unable to locate the template file: $template.";
    $status = 0;
  }

  return $status, $error;
}


sub write_install_file {
  my($self)    = shift;
  my($fh)      = new FileHandle();
  my($insfile) = $self-&gt;transform_file_name(
                           $self-&gt;get_assignment('project_name')) .
                 '.ins';
  my($into)    = $self-&gt;get_into();

  if (defined $into) {
    my($outdir) = $self-&gt;getcwd();
    my($re)     = $self-&gt;escape_regex_special($self-&gt;getstartdir());
    $outdir =~ s/^$re//;
    $outdir = $into . $outdir;
    $insfile = $outdir . '/' . $insfile;
  }

  unlink($insfile);
  if (open($fh, "&gt;$insfile")) {
    foreach my $vc (keys %{$self-&gt;{'valid_components'}}) {
      my($names) = $self-&gt;{$vc};
      foreach my $name (keys %$names) {
        foreach my $key (keys %{$$names{$name}}) {
          my($array) = $$names{$name}-&gt;{$key};
          if (defined $$array[0]) {
            print $fh "$vc:\n";
            foreach my $file (@$array) {
              print $fh "$file\n";
            }
            print $fh "\n";
          }
        }
      }
    }
    if ($self-&gt;exe_target()) {
      my($install) = $self-&gt;get_assignment('install');
      print $fh "exe_output:\n",
                (defined $install ? $self-&gt;relative($install) : ''),
                ' ', $self-&gt;get_assignment('exename'), "\n";
    }
    elsif ($self-&gt;lib_target()) {
      my($shared) = $self-&gt;get_assignment('sharedname');
      my($static) = $self-&gt;get_assignment('staticname');
      my($dllout) = $self-&gt;relative($self-&gt;get_assignment('dllout'));
      my($libout) = $self-&gt;relative($self-&gt;get_assignment('libout'));

      print $fh "lib_output:\n";

      if (defined $shared &amp;&amp; $shared ne '') {
        print $fh (defined $dllout ? $dllout : $libout), " $shared\n";
      }
      if ((defined $static &amp;&amp; $static ne '') &amp;&amp;
          (defined $dllout || !defined $shared ||
               (defined $shared &amp;&amp; $shared ne $static))) {
        print $fh "$libout $static\n";
      }
    }

    close($fh);
    return 1, undef;
  }

  return 0, 'Unable write to ' . $insfile;
}


sub write_project {
  my($self)      = shift;
  my($status)    = 1;
  my($error)     = undef;
  my($progress)  = $self-&gt;get_progress_callback();

  if (defined $progress) {
    &amp;$progress();
  }

  if ($self-&gt;check_features($self-&gt;get_assignment('requires'),
                            $self-&gt;get_assignment('avoids'),
                            1)) {
    if ($self-&gt;need_to_write_project()) {
      ($status, $error) = $self-&gt;write_output_file(
                                   $self-&gt;transform_file_name(
                                            $self-&gt;project_file_name()));
      if ($self-&gt;{'generate_ins'} &amp;&amp; $status) {
        ($status, $error) = $self-&gt;write_install_file();
      }
    }
  }
  else {
    $status = 2;
  }

  return $status, $error;
}


sub get_project_info {
  my($self) = shift;
  return $self-&gt;{'project_info'};
}


sub get_inheritance_tree {
  my($self) = shift;
  return $self-&gt;{'inheritance_tree'};
}


sub set_component_extensions {
  my($self) = shift;
  my($vc)   = $self-&gt;{'valid_components'};
  my($ec)   = $self-&gt;{'exclude_components'};

  foreach my $key (keys %$vc) {
    my($ov) = $self-&gt;override_valid_component_extensions($key);
    if (defined $ov) {
      $$vc{$key} = $ov;
    }
  }

  foreach my $key (keys %$ec) {
    my($ov) = $self-&gt;override_exclude_component_extensions($key);
    if (defined $ov) {
      $$ec{$key} = $ov;
    }
  }
}


sub set_source_listing_callback {
  my($self) = shift;
  my($cb)   = shift;
  $self-&gt;{'source_callback'} = $cb;
}


sub reset_values {
  my($self) = shift;
  $self-&gt;{'project_info'} = [];
}


sub add_default_matching_assignments {
  #my($self) = shift;
  foreach my $key (keys %vc) {
    if (!defined $ma{$key}) {
      $ma{$key} = [];
      foreach my $keyword (@default_matching_assignments) {
        push(@{$ma{$key}}, $keyword);
      }
    }
  }
}


sub reset_generating_types {
  my($self)  = shift;
  my(%reset) = ('matching_assignments' =&gt; \%ma,
                'valid_components'     =&gt; \%vc,
                'generated_exts'       =&gt; \%genext,
                'exclude_components'   =&gt; \%ec,
                'valid_names'          =&gt; \%validNames,
               );

  foreach my $r (keys %reset) {
    $self-&gt;{$r} = {};
    foreach my $key (keys %{$reset{$r}}) {
      $self-&gt;{$r}-&gt;{$key} = $reset{$r}-&gt;{$key};
    }
  }

  $self-&gt;{'custom_types'} = {};

  ## Allow subclasses to override the default extensions
  $self-&gt;set_component_extensions();
}


sub get_template_input {
  my($self) = shift;

  ## This follows along the same logic as read_template_input() by
  ## checking for exe target and then defaulting to a lib target
  if ($self-&gt;exe_target()) {
    if ($self-&gt;get_static() == 1) {
      return $self-&gt;{'lexe_template_input'};
    }
    else {
      return $self-&gt;{'dexe_template_input'};
    }
  }

  if ($self-&gt;get_static() == 1) {
    return $self-&gt;{'lib_template_input'};
  }
  else {
    return $self-&gt;{'dll_template_input'};
  }
}


sub update_project_info {
  my($self)    = shift;
  my($tparser) = shift;
  my($append)  = shift;
  my($names)   = shift;
  my($sep)     = shift;
  my($pi)      = $self-&gt;get_project_info();
  my($value)   = '';
  my($arr)     = ($append &amp;&amp; defined $$pi[0] ? pop(@$pi) : []);

  ## Set up the hash table when we are starting a new project_info
  if ($append == 0) {
    $self-&gt;{'project_info_hash_table'} = {};
  }

  ## Append the values of all names into one string
  my(@narr) = @$names;
  for(my $i = 0; $i &lt;= $#narr; $i++) {
    my($key) = $narr[$i];
    $value .= $self-&gt;translate_value($key,
                                     $tparser-&gt;get_value_with_default($key)) .
              (defined $sep &amp;&amp; $i != $#narr ? $sep : '');
  }

  ## If we haven't seen this value yet, put it on the array
  if (!defined $self-&gt;{'project_info_hash_table'}-&gt;{"@narr $value"}) {
    $self-&gt;{'project_info_hash_table'}-&gt;{"@narr $value"} = 1;
    #$self-&gt;save_project_value("@narr", $value);
    push(@$arr, $value);
  }

  ## Always push the array back onto the project_info
  push(@$pi, $arr);

  return $value;
}


sub adjust_value {
  my($self)  = shift;
  my($name)  = shift;
  my($value) = shift;

  ## Perform any additions, subtractions
  ## or overrides for the template values.
  if (defined $self-&gt;get_addtemp()-&gt;{lc($name)}) {
    my($val) = $self-&gt;get_addtemp()-&gt;{lc($name)};
    my($arr) = $self-&gt;create_array($$val[1]);
    if ($$val[0] &gt; 0) {
      if (UNIVERSAL::isa($value, 'ARRAY')) {
        ## We need to make $value a new array reference ($arr)
        ## to avoid modifying the array reference pointed to by $value
        unshift(@$arr, @$value);
        $value = $arr;
      }
      else {
        $value .= " $$val[1]";
      }
    }
    elsif ($$val[0] &lt; 0) {
      my($parts) = undef;
      if (UNIVERSAL::isa($value, 'ARRAY')) {
        $parts = $value;
      }
      else {
        $parts = $self-&gt;create_array($value);
      }

      $value = [];
      foreach my $part (@$parts) {
        if ($part ne '') {
          my($found) = 0;
          foreach my $ae (@$arr) {
            if ($part eq $ae) {
              $found = 1;
              last;
            }
          }
          if (!$found) {
            push(@$value, $part);
          }
        }
      }
    }
    else {
      $value = $arr;
    }
  }

  return $value;
}


sub relative {
  my($self)            = shift;
  my($value)           = shift;
  my($expand_template) = shift;
  my($expand_env)      = shift;

  if (defined $value) {
    if (UNIVERSAL::isa($value, 'ARRAY')) {
      my(@built) = ();
      foreach my $val (@$value) {
        push(@built, $self-&gt;relative($val, $expand_template, $expand_env));
      }
      $value = \@built;
    }
    elsif ($value =~ /\$/) {
      my($rel)  = $self-&gt;get_relative();
      my(@keys) = keys %$rel;

      if (defined $keys[0]) {
        my($cwd)   = $self-&gt;getcwd();
        my($start) = 0;

        while(substr($value, $start) =~ /(\$\(([^)]+)\))/) {
          my($whole)  = $1;
          my($name)   = $2;
          my($val)    = $$rel{$name};

          if (defined $val) {
            ## Fix up the value for Windows switch the \\'s to /
            if ($self-&gt;{'convert_slashes'}) {
              $val =~ s/\\/\//g;
            }

            ## Here we make an assumption that if we convert slashes to
            ## back-slashes, we also have a case-insensitive file system.
            my($icwd) = ($self-&gt;{'convert_slashes'} ? lc($cwd) : $cwd);
            my($ival) = ($self-&gt;{'convert_slashes'} ? lc($val) : $val);
            my($iclen) = length($icwd);
            my($ivlen) = length($ival);

            ## If the relative value contains the current working
            ## directory plus additional subdirectories, we must pull
            ## off the additional directories into a temporary where
            ## it can be put back after the relative replacement is done.
            my($append) = undef;
            if (index($ival, $icwd) == 0 &amp;&amp; $iclen != $ivlen &amp;&amp;
                substr($ival, $iclen, 1) eq '/') {
              my($diff) = $ivlen - $iclen;
              $append = substr($ival, $iclen);
              substr($ival, $iclen, $diff) = '';
              $ivlen -= $diff;
            }

            if (index($icwd, $ival) == 0 &amp;&amp;
                ($iclen == $ivlen || substr($icwd, $ivlen, 1) eq '/')) {
              my($current) = $icwd;
              substr($current, 0, $ivlen) = '';

              my($dircount) = ($current =~ tr/\///);
              if ($dircount == 0) {
                $ival = '.';
              }
              else {
                $ival = '../' x $dircount;
                $ival =~ s/\/$//;
              }
              if (defined $append) {
                $ival .= $append;
              }
              if ($self-&gt;{'convert_slashes'}) {
                $ival = $self-&gt;slash_to_backslash($ival);
              }
              substr($value, $start) =~ s/\$\([^)]+\)/$ival/;
              $whole = $ival;
            }
            else {
              if ($expand_env &amp;&amp; $self-&gt;convert_macros_to_env()) {
                my($envstart, $envend) = $self-&gt;get_env_accessor();
                if (defined $envstart) {
                  if (!defined $envend) {
                    $envend = '';
                  }
                  substr($value, $start) =~ s/\$\(([^\)]+)\)/$envstart$1$envend/g;
                  $whole = "$envstart$1$envend";
                }
              }
            }
          }
          elsif ($expand_template ||
                 $self-&gt;expand_variables_from_template_values()) {
            my($ti) = $self-&gt;get_template_input();
            if (defined $ti) {
              $val = $ti-&gt;get_value($name);
            }
            my($arr) = $self-&gt;adjust_value($name, (defined $val ? $val : []));
            if (defined $$arr[0]) {
              $val = "@$arr";
              if ($self-&gt;{'convert_slashes'}) {
                $val = $self-&gt;slash_to_backslash($val);
              }
              substr($value, $start) =~ s/\$\([^)]+\)/$val/;

              ## We have replaced the template value, but that template
              ## value may contain a $() construct that may need to get
              ## replaced too.
              $whole = '';
            }
          }
          $start += length($whole);
        }
      }
    }
  }

  return $value;
}


sub reverse_relative {
  my($self)  = shift;
  my($value) = shift;

  if (defined $value) {
    if (UNIVERSAL::isa($value, 'ARRAY')) {
      my(@built) = ();
      foreach my $val (@$value) {
        push(@built, $self-&gt;reverse_relative($val));
      }
      $value = \@built;
    }
    else {
      my($rel) = $self-&gt;get_relative();

      foreach my $key (keys %$rel) {
        ## Get the relative replacement value and convert back-slashes
        my($val) = $$rel{$key};
        $val =~ s/\\/\//g;

        ## We only need to check for reverse replacement if the length
        ## of the string is less than or equal to the length of our
        ## replacement value or the string has a slash at the position
        ## of the length of the replacement value
        my($vlen) = length($val);
        if (length($value) &lt;= $vlen || substr($value, $vlen, 1) eq '/') {
          ## Cut the string down by the length of the replacement value
          my($lval) = substr($value, 0, $vlen);

          ## Here we make an assumption that if we convert slashes to
          ## back-slashes, we also have a case-insensitive file system.
          if ($self-&gt;{'convert_slashes'}) {
            if (lc($lval) eq lc($val)) {
              substr($value, 0, length($val)) = "\$($key)";
              last;
            }
          }
          else {
            if ($lval eq $val) {
              substr($value, 0, length($val)) = "\$($key)";
              last;
            }
          }
        }
      }
    }
  }
  return $value;
}


sub get_verbatim {
  my($self)   = shift;
  my($marker) = shift;
  my($str)    = undef;
  my($thash)  = $self-&gt;{'verbatim'}-&gt;{$self-&gt;{'pctype'}};

  if (defined $thash) {
    if (defined $thash-&gt;{$marker}) {
      my($crlf) = $self-&gt;crlf();
      foreach my $line (@{$thash-&gt;{$marker}}) {
        if (!defined $str) {
          $str = '';
        }
        $str .= $self-&gt;process_special($line) . $crlf;
      }
      if (defined $str) {
        $str .= $crlf;
        $self-&gt;{'verbatim_accessed'}-&gt;{$self-&gt;{'pctype'}}-&gt;{$marker} = 1;
      }
    }
  }

  return $str;
}


sub generate_recursive_input_list {
  my($self)    = shift;
  my($dir)     = shift;
  my($exclude) = shift;
  return $self-&gt;extension_recursive_input_list($dir,
                                               $exclude,
                                               $ProjectCreatorExtension);
}


sub get_default_element_name {
  #my($self) = shift;
  return 'default_group';
}


sub get_modified_project_file_name {
  my($self) = shift;
  my($name) = shift;
  my($ext)  = shift;
  my($nmod) = $self-&gt;get_name_modifier();

  if (defined $nmod &amp;&amp; !$self-&gt;get_apply_project()) {
    $nmod =~ s/\*/$name/g;
    $name = $nmod;
  }
  return "$name$ext";
}


sub preserve_assignment_order {
  my($self) = shift;
  my($name) = shift;
  my($mapped) = $self-&gt;{'valid_names'}-&gt;{$name};

  ## Only return the value stored in the valid_names hash map if it's
  ## defined and it's not an array reference.  The array reference is
  ## a keyword mapping and all mapped keywords should have preserved
  ## assignment order.
  if (defined $mapped &amp;&amp; !UNIVERSAL::isa($mapped, 'ARRAY')) {
    return $mapped;
  }

  return 1;
}


sub dependency_combined_static_library {
  #my($self) = shift;
  return defined $ENV{MPC_DEPENDENCY_COMBINED_STATIC_LIBRARY};
}

# ************************************************************
# Virtual Methods To Be Overridden
# ************************************************************

sub get_gt_symbol {
  #my($self) = shift;
  return '&gt;';
}


sub get_lt_symbol {
  #my($self) = shift;
  return '&lt;';
}


sub get_and_symbol {
  #my($self) = shift;
  return '&amp;&amp;';
}


sub get_or_symbol {
  #my($self) = shift;
  return '||';
}


sub convert_macros_to_env {
  #my($self) = shift;
  return 0;
}


sub dollar_special {
  #my($self) = shift;
  return 0;
}


sub expand_variables_from_template_values {
  #my($self) = shift;
  return 1;
}


sub translate_value {
  my($self) = shift;
  my($key)  = shift;
  my($val)  = shift;

  if ($key eq 'after' &amp;&amp; $val ne '') {
    my($arr) = $self-&gt;create_array($val);
    $val = '';
    foreach my $entry (@$arr) {
      $val .= '"' . $self-&gt;project_file_name($entry) . '" ';
    }
    $val =~ s/\s+$//;
  }
  return $val;
}


sub fill_value {
  #my($self) = shift;
  #my($name) = shift;
  return undef;
}


sub project_file_name {
  #my($self) = shift;
  #my($name) = shift;
  return undef;
}


sub override_valid_component_extensions {
  #my($self) = shift;
  #my($comp) = shift;
  return undef;
}


sub override_exclude_component_extensions {
  #my($self) = shift;
  #my($comp) = shift;
  return undef;
}


sub get_env_accessor {
  #my($self) = shift;
  return ();
}

sub get_dll_exe_template_input_file {
  #my($self) = shift;
  return undef;
}


sub get_lib_exe_template_input_file {
  my($self) = shift;
  return $self-&gt;get_dll_exe_template_input_file();
}


sub get_lib_template_input_file {
  my($self) = shift;
  return $self-&gt;get_dll_template_input_file();
}


sub get_dll_template_input_file {
  #my($self) = shift;
  return undef;
}


sub get_template {
  #my($self) = shift;
  return undef;
}


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