diff options
-rw-r--r-- | ChangeLog | 21 | ||||
-rwxr-xr-x | devtools/document_template.pl | 296 | ||||
-rwxr-xr-x | devtools/highlight_template.pl (renamed from highlight_template.pl) | 115 | ||||
-rw-r--r-- | docs/templates/common.txt | 17 | ||||
-rw-r--r-- | modules/ProjectCreator.pm | 14 | ||||
-rw-r--r-- | modules/TemplateParser.pm | 14 |
6 files changed, 427 insertions, 50 deletions
@@ -1,3 +1,24 @@ +Thu Aug 3 02:45:12 UTC 2006 Chad Elliott <elliott_c@ociweb.com> + + * docs/templates: + * docs/templates/common.txt: + * devtools/document_template.pl: + + The script can be used to document all template variables found + within a project template (.mpd file). Currently, only the + template variables that are common to most templates are + documented. + + * modules/ProjectCreator.pm: + * modules/TemplateParser.pm: + + Added methods to get keywords for use within the devtools scripts. + + * highlight_template.pl: + * devtools/highlight_template.pl: + + Moved this file into the devtools directory. + Fri Jul 28 15:13:01 UTC 2006 Chad Elliott <elliott_c@ociweb.com> * modules/ProjectCreator.pm: diff --git a/devtools/document_template.pl b/devtools/document_template.pl new file mode 100755 index 00000000..589f197c --- /dev/null +++ b/devtools/document_template.pl @@ -0,0 +1,296 @@ +eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' + & eval 'exec perl -w -S $0 $argv:q' + if 0; + +# ****************************************************************** +# Author: Chad Elliott +# Date: 7/12/2006 +# $Id: document_template.pl,v 1.1 2006/02/16 21:38:47 elliottc Exp $ +# ****************************************************************** + +# ****************************************************************** +# Pragma Section +# ****************************************************************** + +use strict; +use FileHandle; +use FindBin; +use File::Spec; +use File::Basename; + +my($basePath) = $FindBin::Bin; +if ($^O eq 'VMS') { + $basePath = File::Spec->rel2abs(dirname($0)) if ($basePath eq ''); + $basePath = VMS::Filespec::unixify($basePath); +} +$basePath = dirname($basePath); +unshift(@INC, $basePath . '/modules'); + +require ProjectCreator; +require TemplateParser; +require ConfigParser; +require StringProcessor; + +# ****************************************************************** +# Data Section +# ****************************************************************** + +my(%keywords) = (); +my(%arrow_op) = (); +my($doc_ext) = '.txt'; +my($version) = '1.1'; + +# ****************************************************************** +# Subroutine Section +# ****************************************************************** + +sub setup_keywords { + my($language) = shift; + + ## Get the main MPC keywords + my($keywords) = ProjectCreator::getKeywords(); + foreach my $key (keys %$keywords) { + $keywords{$key} = 1; + } + + ## Get the MPC valid components + $keywords = ProjectCreator::getValidComponents($language); + foreach my $key (keys %$keywords) { + $keywords{lc($key)} = 1; + } + + ## Get the pseudo template variables + my($pjc) = new ProjectCreator(); + $keywords = $pjc->get_command_subs(); + foreach my $key (keys %$keywords) { + $keywords{$key} = 1; + } + + ## Get the template function names + $keywords = TemplateParser::getKeywords(); + foreach my $key (keys %$keywords) { + $keywords{$key} = 1; + } + + ## Get the template parser arrow operator keys + $keywords = TemplateParser::getArrowOp(); + foreach my $key (keys %$keywords) { + $arrow_op{$key} = 1; + } +} + + +sub display_template { + my($fh) = shift; + my($cp) = shift; + my($input) = shift; + my($tkeys) = shift; + + print $fh '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">', "\n", + "<head>\n", + " <title>$input</title>\n", + "</head>\n", + "<body>\n", + " <h1>$input</h1>\n", + " <table border=2 cellspacing=1>\n", + " <tr>\n", + " <th>Template Variable</th>\n", + " <th>Default Value</th>\n", + " <th>Description</th>\n", + " </tr>\n"; + foreach my $key (sort keys %$tkeys) { + my($desc) = $cp->get_value($key) || ' '; + my($def) = undef; + if (defined $$tkeys{$key}) { + foreach my $ikey (sort keys %{$$tkeys{$key}}) { + if (defined $def) { + $def .= ' <b>or</b> '; + } + else { + $def = ''; + } + $def .= StringProcessor::process_special(undef, $ikey); + } + } + print $fh " <tr>\n", + " <td>$key</td>\n", + " <td>", (defined $def ? $def : ' '), "</td>\n", + " <td>$desc</td>\n", + " </tr>\n"; + } + print $fh " </table>\n", + "</body>\n"; +} + + +sub usageAndExit { + print "document_template.pl v$version\n", + "Usage: ", basename($0), " <template> [html output [language]]\n\n", + "language can be any of the valid language settings for MPC.\n"; + exit(0); +} + +# ****************************************************************** +# Main Section +# ****************************************************************** + +my($status) = 0; +my($fh) = new FileHandle(); +my($input) = $ARGV[0]; +my($output) = $ARGV[1]; +my($language) = $ARGV[2]; + +if (!defined $input || $input =~ /^-/) { + usageAndExit(); +} + +if (!defined $output) { + $output = $input; + $output =~ s/\.mpd$//; + $output .= '.html'; +} + +if (open($fh, $input)) { + if (!defined $language) { + if (index($input, 'vb') != -1) { + $language = 'vb'; + } + elsif (index($input, 'csharp') != -1) { + $language = 'csharp'; + } + else { + $language = 'cplusplus'; + } + } + + my(%template_keys) = (); + setup_keywords($language); + + my(@foreach) = (); + my($findex) = -1; + while(<$fh>) { + my($len) = length($_); + for(my $start = 0; $start < $len;) { + my($sindex) = index($_, '<%', $start); + if ($sindex >= 0) { + my($eindex) = index($_, '%>', $sindex); + if ($eindex >= $sindex) { + $eindex += 2; + } + else { + $eindex = $len; + } + + my($part) = substr($_, $sindex, $eindex - $sindex); + my($key) = lc(substr($part, 2, length($part) - 4)); + my($name) = $key; + my($tvar) = undef; + my($def) = undef; + if ($key =~ /^([^\(]+)\((.*)\)/) { + $name = $1; + if (defined $keywords{$name}) { + $tvar = 1; + if ($name eq 'foreach') { + ++$findex; + my($vname) = $2; + + my($remove_s) = 1; + if ($vname =~ /([^,]*),(.*)/) { + my($n) = $1; + my($v) = $2; + $n =~ s/^\s+//; + $n =~ s/\s+$//; + $v =~ s/^\s+//; + $v =~ s/\s+$//; + + if ($n =~ /^\d+$/) { + $n = $v; + } + else { + $remove_s = undef; + } + $vname = $n; + } + + $key = $vname; + $name = $vname; + $vname =~ s/s$// if ($remove_s); + + $foreach[$findex] = $vname; + $tvar = undef; + } + } + else { + $def = $2; + } + } + + if (defined $keywords{$key}) { + $tvar = 1; + if ($key eq 'endfor') { + $foreach[$findex] = undef; + --$findex; + } + } + else { + foreach my $ao (keys %arrow_op) { + if ($key =~ /^$ao/) { + $tvar = 1; + last; + } + } + } + + if (!$tvar) { + for(my $index = 0; $index <= $findex; $index++) { + if ($foreach[$index] eq $key) { + $tvar = 1; + last; + } + } + } + + if (!$tvar) { + if (defined $template_keys{$name}) { + if (defined $def) { + $template_keys{$name}->{$def} = 1; + } + } + else { + $template_keys{$name} = {}; + if (defined $def) { + $template_keys{$name}->{$def} = 1; + } + } + } + $start = $eindex; + } + else { + $start += ($len - $start); + } + } + } + close($fh); + + my($cp) = new ConfigParser(); + my($doc) = basename($input); + $doc =~ s/\.[^\.]+$/$doc_ext/; + $cp->read_file("$basePath/docs/templates/common$doc_ext"); + $cp->read_file("$basePath/docs/templates/$doc"); + + if (open($fh, ">$output")) { + display_template($fh, $cp, $input, \%template_keys); + close($fh); + } + else { + print STDERR "ERROR: Unable to open $output for writing\n"; + ++$status; + } +} +else { + print STDERR "ERROR: Unable to open $input for reading\n"; + ++$status; +} + +exit($status); + diff --git a/highlight_template.pl b/devtools/highlight_template.pl index cb13baf7..65b2c6ca 100755 --- a/highlight_template.pl +++ b/devtools/highlight_template.pl @@ -14,61 +14,27 @@ eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' use strict; use FileHandle; +use FindBin; +use File::Spec; use File::Basename; +my($basePath) = $FindBin::Bin; +if ($^O eq 'VMS') { + $basePath = File::Spec->rel2abs(dirname($0)) if ($basePath eq ''); + $basePath = VMS::Filespec::unixify($basePath); +} +$basePath = dirname($basePath); +unshift(@INC, $basePath . '/modules'); + +require ProjectCreator; +require TemplateParser; + # ****************************************************************** # Data Section # ****************************************************************** -my(%keywords) = (## These correspond to those in TemplateParser.pm - 'if' => 1, - 'else' => 1, - 'endif' => 1, - 'noextension' => 0, - 'dirname' => 0, - 'basename' => 0, - 'basenoextension' => 0, - 'foreach' => 2, - 'forfirst' => 2, - 'fornotfirst' => 2, - 'fornotlast' => 2, - 'forlast' => 2, - 'endfor' => 2, - 'eval' => 0, - 'comment' => 0, - 'marker' => 0, - 'uc' => 0, - 'lc' => 0, - 'ucw' => 0, - 'normalize' => 0, - 'flag_overrides' => 0, - 'reverse' => 0, - 'sort' => 0, - 'uniq' => 0, - 'multiple' => 0, - 'starts_with' => 0, - 'ends_with' => 0, - 'contains' => 0, - 'compares' => 0, - 'duplicate_index' => 0, - 'transdir' => 0, - - ## These correspond to those in ProjectCreator.pm - 'cat' => 0, - 'cmp' => 0, - 'cp' => 0, - 'mkdir' => 0, - 'mv' => 0, - 'os' => 0, - 'rm' => 0, - 'nul' => 0, - 'gt' => 0, - 'lt' => 0, - 'and' => 0, - 'or' => 0, - 'quote' => 0, - ); - +my(%keywords) = (); +my(%arrow_op) = (); my($ifmod) = 0; my($formod) = 0; my($cmod) = 50; @@ -76,12 +42,51 @@ my(%keycolors) = (0 => [160, 32, 240], 1 => [255, 50, 50], 2 => [50, 50, 255], ); -my($version) = '1.2'; +my($version) = '1.3'; # ****************************************************************** # Subroutine Section # ****************************************************************** +sub setup_keywords { + ## Get the main MPC keywords + my($keywords) = ProjectCreator::getKeywords(); + foreach my $key (keys %$keywords) { + $keywords{$key} = 0; + } + + ## Get the pseudo template variables + my($pjc) = new ProjectCreator(); + $keywords = $pjc->get_command_subs(); + foreach my $key (keys %$keywords) { + $keywords{$key} = 0; + } + + ## Get the template function names + $keywords = TemplateParser::getKeywords(); + foreach my $key (keys %$keywords) { + $keywords{$key} = 0; + } + + ## Get the template parser arrow operator keys + $keywords = TemplateParser::getArrowOp(); + foreach my $key (keys %$keywords) { + $arrow_op{$key} = 0; + } + + ## These TemplateParser keywords need special values so + ## that the color coding will recognize these as different + ## from the rest of the keywords + foreach my $key ('if', 'else', 'endif') { + $keywords{$key} = 1; + } + foreach my $key ('foreach', 'forfirst', + 'fornotfirst', 'fornotlast', 'forlast', 'endfor') { + $keywords{$key} = 2; + } +} + + sub convert_to_html { my($line) = shift; $line =~ s/&/&/g; @@ -124,6 +129,8 @@ if (!defined $output) { } if (open($fh, $input)) { + setup_keywords(); + my($deftxt) = 'black'; my(@codes) = (); while(<$fh>) { @@ -157,6 +164,14 @@ if (open($fh, $input)) { elsif (defined $keywords{$key}) { @entry = @{$keycolors{$keywords{$key}}}; } + else { + foreach my $ao (keys %arrow_op) { + if ($key =~ /^$ao/) { + @entry = @{$keycolors{$arrow_op{$ao}}}; + last; + } + } + } if (defined $entry[0]) { if ($name eq 'if') { diff --git a/docs/templates/common.txt b/docs/templates/common.txt new file mode 100644 index 00000000..5d8dc51e --- /dev/null +++ b/docs/templates/common.txt @@ -0,0 +1,17 @@ +// +// Document template variables that are common to all or most templates. +// Please try to keep this alphabetically sorted. +// +configurations = This determines build configurations (ex. Debug, Release, etc.) +dll_ext = The dynamic library extension. The value for this depends on the project type. +exe_ext = The executable extension. The value for this depends on the project type. +lib_ext = The static or impl library extension. The value for this depends on the project type. +lib_prefix = The dynamic and static library prefix. The value for this depends on the project type. +libname_prefix = This is a prefix that will be prepended to the actual library name (ex. libXY.so where X is libname_prefix and Y is sharedname). +need_staticflags = This will be true if the project is a static project. +pch_defines = C preprocessor macros that indicate that precompiled headers will be used. +platforms = This determines for which platform the project will be built. +type_is_binary = This will be true is the project is a dynamic library or an executable. +type_is_dynamic = This will be true if the project is a dynamic library. +type_is_static = This will be true if the project is a static project. +win_version = This is a variation of the 'version' project value that has been translated into a value usable on Windows. diff --git a/modules/ProjectCreator.pm b/modules/ProjectCreator.pm index f7be182a..ff9c431e 100644 --- a/modules/ProjectCreator.pm +++ b/modules/ProjectCreator.pm @@ -3912,6 +3912,7 @@ sub write_output_file { print $fh $line; } close($fh); + $self->post_file_creation($name); $self->add_file_written($oname); } else { @@ -4628,6 +4629,19 @@ sub remove_wanted_extension { } # ************************************************************ +# Accessors used by support scripts +# ************************************************************ + +sub getKeywords { + return \%validNames; +} + +sub getValidComponents { + my($language) = shift; + return (defined $language{$language} ? $language{$language}->[0] : undef); +} + +# ************************************************************ # Virtual Methods To Be Overridden # ************************************************************ diff --git a/modules/TemplateParser.pm b/modules/TemplateParser.pm index 6d0dce0e..1e56ba4f 100644 --- a/modules/TemplateParser.pm +++ b/modules/TemplateParser.pm @@ -1863,4 +1863,18 @@ sub get_lines { } +# ************************************************************ +# Accessors used by support scripts +# ************************************************************ + +sub getKeywords { + return \%keywords; +} + + +sub getArrowOp { + return \%arrow_op_ref; +} + + 1; |