⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 projectcreator.pm

📁 ACE源码
💻 PM
📖 第 1 页 / 共 5 页
字号:
    }
  }
}


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

  if (!$pchhdef || !$pchcdef) {
    my($pname)     = $self->escape_regex_special(
                             $self->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->{'valid_components'}->{'header_files'}}) {
            if ($file =~ /(.*_pch$ext)$/) {
              $self->process_assignment('pch_header', $1);
              ++$hcount;
              if ($file =~ /$pname/) {
                $hmatching = $file;
              }
              last;
            }
          }
        }
        if (!$pchcdef) {
          foreach my $ext (@{$self->{'valid_components'}->{'source_files'}}) {
            if ($file =~ /(.*_pch$ext)$/) {
              $self->process_assignment('pch_source', $1);
              ++$ccount;
              if ($file =~ /$pname/) {
                $cmatching = $file;
              }
              last;
            }
          }
        }
      }
    }
    if (!$pchhdef && $hcount > 1 && defined $hmatching) {
      $self->process_assignment('pch_header', $hmatching);
    }
    if (!$pchcdef && $ccount > 1 && defined $cmatching) {
      $self->process_assignment('pch_source', $cmatching);
    }
  }
}


sub fix_pch_filenames {
  my($self) = shift;
  foreach my $type ('pch_header', 'pch_source') {
    my($pch) = $self->get_assignment($type);
    if (defined $pch && $pch eq '') {
      $self->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 <= $#pchs; ++$j) {
    my($pch) = $self->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->{'convert_slashes'}) {
        $pch =~ s/\\/\//g;
      }

      ## Find out which files are duplicated
      my($names) = $self->{$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 < $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(@saved) = ();
  my($ec)    = $self->{'exclude_components'};

  foreach my $file (@$files) {
    foreach my $ext (@$exts) {
      ## Always exclude the precompiled header and cpp
      if ($file =~ /$ext$/ && (!defined $pchh || $file ne $pchh) &&
                              (!defined $pchc || $file ne $pchc)) {
        my($exclude) = 0;
        if (defined $$ec{$tag}) {
          foreach my $exc (@{$$ec{$tag}}) {
            if ($file =~ /$exc$/) {
              $exclude = 1;
              last;
            }
          }
        }
        elsif ($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 && !$self->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->transform_file_name(
                               $self->get_assignment('project_name'));
      my($pjname)    = $self->escape_regex_special($unescaped);
      foreach my $save (@saved) {
        my($file) = $self->escape_regex_special($save);
        if ($unescaped =~ /$file/ || $save =~ /$pjname/) {
          if (!$self->already_added($array, $save)) {
            push(@$array, $save);
          }
        }
      }
    }
  }
}


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

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

        if (!defined $specialComponents{$tag}) {
          $self->sift_files($files, $exts, $pchh, $pchc, $tag, $array);
          if ($tag eq 'source_files') {
            foreach my $gentype (keys %{$self->{'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(@exts)  = $self->generated_extensions($gentype, $tag);

              $self->{'defaulted'}->{$tag} = 1;
              @$array = ();
              foreach my $file (@copy) {
                my($found) = 0;
                foreach my $ext (@exts) {
                  if ($file =~ /$ext$/) {
                    ## No need to check for previously added files
                    ## here since there are none.
                    push(@front, $file);
                    $found = 1;
                    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->{$dest};
  my(@slist)  = $self->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}->{$key};
      my($count) = scalar(@$array);
      for(my $i = 0; $i < $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_extensions {
  my($self) = shift;
  my($name) = shift;
  my($tag)  = shift;
  my(@exts) = ();
  my($gen)  = $self->{'generated_exts'}->{$name};

  if (defined $gen->{$tag}) {
    foreach my $pe (@{$gen->{'pre_extension'}}) {
      foreach my $ext (@{$gen->{$tag}}) {
        push(@exts, "$pe$ext");
      }
    }
  }
  return @exts;
}


sub generated_source_listed {
  my($self)  = shift;
  my($gent)  = shift;
  my($tag)   = shift;
  my($arr)   = shift;
  my($names) = $self->{$tag};
  my(@gen)   = $self->generated_extensions($gent, $tag);

  ## Find out which generated source files are listed
  foreach my $name (keys %$names) {
    my($comps) = $$names{$name};
    foreach my $key (keys %$comps) {
      my($array) = $$comps{$key};
      foreach my $val (@$array) {
        foreach my $ext (@gen) {
          foreach my $i (@$arr) {
            my($ifile) = $self->escape_regex_special($i);
            if ($val =~ /$ifile$ext$/) {
              return 1;
            }
          }
        }
      }
    }
  }

  return 0;
}


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

  if ($self->{'generated_exts'}->{$gentype}->{'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->{$gentype}) {
      ## Build up the list of files
      my(@arr)    = ();
      my($wanted) = $self->{'valid_components'}->{$gentype}->[0];
      my($names)  = $self->{$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->generated_source_listed($gentype, $type, \@arr)) {
          $self->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->{'valid_components'}->{$gentype}}) {
    my($e) = $ext;
    $e =~ s/\\//g;
    $key = "$ofile$e";
    if (defined $self->{'flag_overrides'}->{$gentype}->{$key}) {
      last;
    }
    else {
      $key = undef;
    }
  }

  if (defined $key) {
    foreach my $ma (@{$self->{'matching_assignments'}->{$gentype}}) {
      if ($ma eq 'gendir') {
        if (defined $self->{'flag_overrides'}->{$gentype}->{$key}->{$ma}) {
          return "$self->{'flag_overrides'}->{$gentype}->{$key}->{$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;

  if (defined $self->{'generated_exts'}->{$gentype}->{$tag}) {
    my(@genexts) = $self->generated_extensions($gentype, $tag);

    $file = $self->escape_regex_special($file);

    foreach my $gen ($self->get_component_list($gentype, 1)) {
      ## Remove the extension
      my($start) = $gen;
      foreach my $ext (@{$self->{'valid_components'}->{$gentype}}) {
        $gen =~ s/$ext$//;
        if ($gen ne $start) {
          last;
        }
      }

      ## See if we need to add the file
      foreach my $pf (@{$self->{'generated_exts'}->{$gentype}->{'pre_filename'}}) {
        foreach my $genext (@genexts) {
          if ("$pf$gen$genext" =~ /$file(.*)?$/) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -