📄 projectcreator.pm
字号:
my($comps) = $$names{$name};
foreach my $comp (keys %$comps) {
push(@all, @{$$comps{$comp}});
}
}
}
## We need to cross-check the idl files. But we need to remove
## the idl extension first.
my(@idl) = $self->get_component_list('idl_files');
for(my $i = 0; $i <= $#idl; $i++) {
$idl[$i] =~ s/\.idl$//;
}
## for each cpp file, we add a corresponding header or inline file
## if it exists and is not already in the list of headers
my($names) = $self->{$tag};
foreach my $name (keys %$names) {
my($comps) = $$names{$name};
foreach my $comp (keys %$comps) {
my($array) = $$comps{$comp};
foreach my $cpp (@all) {
my($found) = 0;
my($c) = $cpp;
$c =~ s/\.[^\.]+$//;
foreach my $file (@$array) {
my($added) = $c;
if ($file =~ /(\.[^\.]+)$/) {
$added .= $1;
}
if ($added eq $file) {
$found = 1;
last;
}
}
if (!$found) {
my($added) = 0;
foreach my $e (@{$$vc{$tag}}) {
my($ext) = $e;
$ext =~ s/\\//g;
## If the file is readable
my($file) = "$c$ext";
if (-r $file) {
if (!$self->already_added($array, $file)) {
push(@$array, $file);
}
$added = 1;
last;
}
}
if (!$added) {
## If we did not add the file in the above loop,
## we must check to see if the file *would be* generated
## from idl. If so, we will add the file with the default
## (i.e. first) file extension.
foreach my $idlfile (@idl) {
my($idl) = $self->escape_regex_special($idlfile);
if ($c =~ /^$idl/) {
foreach my $ending (@{$self->{'skeleton_endings'}}) {
if ($c =~ /^$idl$ending$/) {
my($ext) = $$vc{$tag}->[0];
$ext =~ s/\\//g;
my($file) = "$c$ext";
if (!$self->already_added($array, $file)) {
push(@$array, $file);
}
$added = 1;
last;
}
}
}
last;
}
}
}
}
}
}
}
sub generate_defaults {
my($self) = shift;
my($base) = $self->base_directory();
## Generate default project name
if (!defined $self->get_assignment('project_name')) {
$self->process_assignment('project_name', $base);
}
$self->generate_default_target_names($base);
my(@files) = $self->generate_default_file_list();
$self->generate_default_pch_filenames(\@files);
## Generate default components, but @specialComponents
## are skipped in the initial default components generation
$self->generate_default_components(\@files);
## Generate the default idl generated list of source files
## only if we defaulted the idl file list
$self->generate_default_idl_generated(['source_files']);
## Add @specialComponents files based on the
## source_components (i.e. .h and .i or .inl based on .cpp)
foreach my $tag (@specialComponents) {
$self->add_source_corresponding_component_files($tag);
}
## Now, if the @specialComponents are still empty
## then take any file that matches the components extension
foreach my $tag (@specialComponents) {
my($names) = $self->{$tag};
if (defined $names) {
foreach my $name (keys %$names) {
my($comps) = $$names{$name};
foreach my $comp (keys %$comps) {
my($array) = $$comps{$comp};
if (!defined $$array[0] || $self->{'source_defaulted'}) {
$self->generate_default_components(\@files, $tag);
}
}
}
}
}
}
sub project_name {
my($self) = shift;
return $self->get_assignment('project_name');
}
sub lib_target {
my($self) = shift;
return (defined $self->get_assignment('sharedname') ||
defined $self->get_assignment('staticname'));
}
sub exe_target {
my($self) = shift;
return (defined $self->get_assignment('exename'));
}
sub get_assignment {
my($self) = shift;
my($name) = shift;
my($tag) = ($self->{'reading_global'} ? 'global_assign' : 'assign');
return $self->{$tag}->{$name};
}
sub get_component_list {
my($self) = shift;
my($tag) = shift;
my($names) = $self->{$tag};
my(@list) = ();
foreach my $name (keys %$names) {
my($comps) = $$names{$name};
foreach my $key (sort keys %$comps) {
my($array) = $$comps{$key};
push(@list, @$array);
}
}
if ($self->convert_slashes()) {
for(my $i = 0; $i <= $#list; $i++) {
$list[$i] = $self->slash_to_backslash($list[$i]);
}
}
if ($self->sort_files()) {
@list = sort { $self->file_sorter($a, $b) } @list;
}
return @list;
}
sub write_output_file {
my($self) = shift;
my($name) = shift;
my($status) = 0;
my($error) = '';
my($dir) = dirname($name);
my($fh) = new FileHandle();
my($tover) = $self->get_template_override();
my($template) = (defined $tover ? $tover : $self->get_template()) .
".$TemplateExtension";
my($tfile) = $self->search_include_path($template);
if (defined $tfile) {
if ($dir ne '.') {
mkpath($dir, 0, 0777);
}
## Read in the template values for the
## specific target and project type
($status, $error) = $self->read_template_input();
if ($status) {
my($tp) = new TemplateParser($self);
## Set the project_file assignment for the template parser
$self->process_assignment('project_file', $name);
($status, $error) = $tp->parse_file($tfile);
if ($status) {
if (open($fh, ">$name")) {
my($lines) = $tp->get_lines();
foreach my $line (@$lines) {
print $fh $line;
}
close($fh);
my($fw) = $self->{'files_written'};
push(@$fw, $name);
}
else {
$error = "ERROR: Unable to open $name for output.";
$status = 0;
}
}
}
}
else {
$error = "ERROR: Unable to locate the template file: $template.";
$status = 0;
}
return $status, $error;
}
sub write_project {
my($self) = shift;
my($status) = 1;
my($error) = '';
my($name) = $self->transform_file_name($self->project_file_name());
my($prjname) = $self->get_assignment('project_name');
my($progress) = $self->get_progress_callback();
if (defined $progress) {
&$progress();
}
## Writing the non-static file so set it to 0
if ($self->{'want_dynamic_projects'}) {
$self->{'writing_type'} = 0;
$self->process_assignment('project_name',
$prjname . $self->get_type_append());
($status, $error) = $self->write_output_file($name);
}
if ($status && $self->{'want_static_projects'} &&
$self->separate_static_project()) {
## Set the project name back to what it originally was
$self->process_assignment('project_name', $prjname);
$name = $self->transform_file_name($self->static_project_file_name());
## Writing the static file so set it to 1
$self->{'writing_type'} = 1;
$self->process_assignment('project_name',
$prjname . $self->get_type_append());
($status, $error) = $self->write_output_file($name);
}
if (!$status) {
print STDERR "$error\n";
}
return $status;
}
sub get_files_written {
my($self) = shift;
return $self->{'files_written'};
}
sub get_project_info {
my($self) = shift;
return $self->{'project_info'};
}
sub get_writing_type {
my($self) = shift;
return $self->{'writing_type'};
}
sub set_component_extensions {
my($self) = shift;
my($vc) = $self->{'valid_components'};
my($ec) = $self->{'exclude_components'};
foreach my $key (keys %$vc) {
my($ov) = $self->override_valid_component_extensions($key);
if (defined $ov) {
$$vc{$key} = $ov;
}
}
foreach my $key (keys %$ec) {
my($ov) = $self->override_exclude_component_extensions($key);
if (defined $ov) {
$$ec{$key} = $ov;
}
}
}
sub reset_values {
my($self) = shift;
$self->{'files_written'} = [];
$self->{'project_info'} = [];
}
sub get_template_input {
my($self) = shift;
if ($self->lib_target()) {
if ($self->{'writing_type'} == 1) {
return $self->{'lib_template_input'};
}
else {
return $self->{'dll_template_input'};
}
}
if ($self->{'writing_type'} == 1) {
return $self->{'lexe_template_input'};
}
else {
return $self->{'dexe_template_input'};
}
}
sub update_project_info {
my($self) = shift;
my($tparser) = shift;
my($append) = shift;
my($names) = shift;
my($sep) = shift;
my($pi) = $self->get_project_info();
my($value) = '';
my($arr) = ($append && defined $$pi[0] ? pop(@$pi) : []);
## Set up the hash table when we are starting a new project_info
if ($append == 0) {
$self->{'project_info_hash_table'} = {};
}
## Append the values of all names into one string
my(@narr) = @$names;
for(my $i = 0; $i <= $#narr; $i++) {
my($key) = $narr[$i];
$value .= $self->translate_value($key,
$tparser->get_value_with_default($key)) .
(defined $sep && $i != $#narr ? $sep : '');
}
## If we haven't seen this value yet, put it on the array
if (!defined $self->{'project_info_hash_table'}->{"@narr $value"}) {
$self->{'project_info_hash_table'}->{"@narr $value"} = 1;
$self->save_project_value("@narr", $value);
push(@$arr, $value);
}
## Always push the array back onto the project_info
push(@$pi, $arr);
return $value;
}
sub get_verbatim {
my($self) = shift;
my($marker) = shift;
my($type) = lc(substr("$self", 0, 3)); ## This number corresponds to
## signif in Driver.pm
my($str) = undef;
my($thash) = $self->{'verbatim'}->{$type};
if (defined $thash) {
if (defined $thash->{$marker}) {
my($crlf) = $self->crlf();
foreach my $line (@{$thash->{$marker}}) {
if (!defined $str) {
$str = '';
}
$str .= $self->process_special($line) . $crlf;
}
if (defined $str) {
$str .= $crlf;
}
}
}
return $str;
}
# ************************************************************
# Virtual Methods To Be Overridden
# ************************************************************
sub specific_lookup {
#my($self) = shift;
#my($key) = shift;
return undef;
}
sub save_project_value {
#my($self) = shift;
#my($name) = shift;
#my($value) = shift;
}
sub get_type_append {
#my($self) = shift;
return '';
}
sub translate_value {
my($self) = shift;
my($key) = shift;
my($val) = shift;
return $val;
}
sub convert_slashes {
#my($self) = shift;
return 1;
}
sub fill_value {
#my($self) = shift;
#my($name) = shift;
return undef;
}
sub separate_static_project {
#my($self) = shift;
return 0;
}
sub project_file_name {
#my($self) = shift;
return undef;
}
sub static_project_file_name {
#my($self) = 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_dll_exe_template_input_file {
#my($self) = shift;
return undef;
}
sub get_lib_exe_template_input_file {
#my($self) = shift;
return undef;
}
sub get_lib_template_input_file {
#my($self) = shift;
return undef;
}
sub get_dll_template_input_file {
#my($self) = shift;
return undef;
}
sub get_template {
#my($self) = shift;
return undef;
}
1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -