diff options
author | elliott_c <ocielliottc@users.noreply.github.com> | 2006-08-03 02:47:45 +0000 |
---|---|---|
committer | elliott_c <ocielliottc@users.noreply.github.com> | 2006-08-03 02:47:45 +0000 |
commit | 09e54097d4098e9ef4d9a0996fff321435dd05dc (patch) | |
tree | 741a50f942ca4c4ca4029d7c359637e54b41377e /devtools | |
parent | 4a6770cf9dd4b8e144760511983514cd724e378c (diff) | |
download | MPC-09e54097d4098e9ef4d9a0996fff321435dd05dc.tar.gz |
ChangeLogTag: Thu Aug 3 02:45:12 UTC 2006 Chad Elliott <elliott_c@ociweb.com>
Diffstat (limited to 'devtools')
-rwxr-xr-x | devtools/document_template.pl | 296 | ||||
-rwxr-xr-x | devtools/highlight_template.pl | 243 |
2 files changed, 539 insertions, 0 deletions
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/devtools/highlight_template.pl b/devtools/highlight_template.pl new file mode 100755 index 00000000..65b2c6ca --- /dev/null +++ b/devtools/highlight_template.pl @@ -0,0 +1,243 @@ +eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' + & eval 'exec perl -w -S $0 $argv:q' + if 0; + +# ****************************************************************** +# Author: Chad Elliott +# Date: 2/16/2006 +# $Id$ +# ****************************************************************** + +# ****************************************************************** +# 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; + +# ****************************************************************** +# Data Section +# ****************************************************************** + +my(%keywords) = (); +my(%arrow_op) = (); +my($ifmod) = 0; +my($formod) = 0; +my($cmod) = 50; +my(%keycolors) = (0 => [160, 32, 240], + 1 => [255, 50, 50], + 2 => [50, 50, 255], + ); +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; + $line =~ s/</</g; + $line =~ s/>/>/g; + $line =~ s/"/"/g; + $line =~ s/ / /g; + $line =~ s/\t/ /g; + $line =~ s/\n/<br>/; + return $line; +} + + +sub usageAndExit { + print "highlight_template.pl v$version\n", + "Usage: ", basename($0), " <template> [html output]\n\n", + "This script will color highlight the template provided using\n", + "varying colors for the different keywords, variables and text.\n", + "Nested if's and foreach's will have slightly different colors.\n"; + exit(0); +} + +# ****************************************************************** +# Main Section +# ****************************************************************** + +my($status) = 0; +my($fh) = new FileHandle(); +my($input) = $ARGV[0]; +my($output) = $ARGV[1]; + +if (!defined $input || $input =~ /^-/) { + usageAndExit(); +} + +if (!defined $output) { + $output = $input; + $output =~ s/\.mpd$//; + $output .= '.html'; +} + +if (open($fh, $input)) { + setup_keywords(); + + my($deftxt) = 'black'; + my(@codes) = (); + while(<$fh>) { + my($len) = length($_); + for(my $start = 0; $start < $len;) { + my($sindex) = index($_, '<%', $start); + if ($sindex >= 0) { + my($left) = substr($_, $start, $sindex - $start); + if ($left ne '') { + push(@codes, [$deftxt, $left]); + } + my($eindex) = index($_, '%>', $sindex); + if ($eindex >= $sindex) { + $eindex += 2; + } + else { + $eindex = $len; + } + + my($part) = substr($_, $sindex, $eindex - $sindex); + my($key) = substr($part, 2, length($part) - 4); + my($name) = $key; + my($color) = 'green'; + my(@entry) = (); + if ($key =~ /^([^\(]+)\(.*\)/) { + $name = $1; + if (defined $keywords{$name}) { + @entry = @{$keycolors{$keywords{$1}}}; + } + } + 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') { + $ifmod++; + $entry[0] -= ($cmod * ($ifmod - 1)); + } + elsif ($name eq 'endif') { + $entry[0] -= ($cmod * ($ifmod - 1)); + $ifmod-- if ($ifmod > 0); + } + elsif (defined $keywords{$name} && + $keywords{$name} == $keywords{'if'}) { + $entry[0] -= ($cmod * ($ifmod - 1)); + } + elsif ($name eq 'foreach') { + $formod++; + $entry[2] -= ($cmod * ($formod - 1)); + } + elsif ($name eq 'endfor') { + $entry[2] -= ($cmod * ($formod - 1)); + $formod-- if ($formod > 0); + } + elsif (defined $keywords{$name} && + $keywords{$name} == $keywords{'foreach'}) { + $entry[2] -= ($cmod * ($formod - 1)); + } + foreach my $entry (@entry) { + $entry = 0 if ($entry < 0); + } + $color = '#' . sprintf("%02x%02x%02x", @entry); + } + + push(@codes, [$color, $part]); + $start = $eindex; + } + else { + my($part) = substr($_, $start, $len - $start); + push(@codes, [$deftxt, $part]); + $start += ($len - $start); + } + } + } + close($fh); + + if (open($fh, ">$output")) { + print $fh "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n", + "<html><head><title>", basename($input), "</title></head>\n", + "<body>\n"; + foreach my $code (@codes) { + $$code[1] = convert_to_html($$code[1]); + my($newline) = ($$code[1] =~ s/<br>//); + print $fh ($$code[1] ne '' ? + "<font color=\"$$code[0]\">$$code[1]</font>" : ''), + ($newline ? "<br>\n" : ''); + } + print $fh "</body></html>\n"; + } + 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); + |