#!/usr/bin/env perl 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 # ****************************************************************** # ****************************************************************** # 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.4'; # ****************************************************************** # 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, $common_cp, $template_cp, $input, $tkeys, $oformat) = @_; my $html = ($oformat eq 'html') ? 1 : 0; if ($html) { print $fh '', "\n", "\n", " $input\n", " \n", "\n", "\n", "

$input

\n", " \n", " \n", " \n", " \n", " \n", " \n"; } else { print $fh "//\n// Document template variables for templates $input.\n// Please try to keep this alphabetically sorted.\n//\n"; } foreach my $key (sort keys %$tkeys) { # For text output, we only want to dump out the variables that are only # specific to the template being documented and not the common variables. # So, we check to see if the key has a value in the common config and, if # it does, skip. We can't check to see if it has a value in the template # config because this script may be the thing that's creating the stub # for that template. next if (!$html && $common_cp->get_value($key)); my $desc = ''; if ($html) { $desc = $template_cp->get_value($key) || $common_cp->get_value($key) || ' '; } else { $desc = $common_cp->get_value($key) || ''; } my $def; if (defined $$tkeys{$key}) { foreach my $ikey (sort keys %{$$tkeys{$key}}) { if (defined $def) { $def .= $html ? ' or ' : ' OR '; } else { $def = ''; } $def .= StringProcessor::process_special(undef, $ikey); } } ## Convert < and > to html friendly codes if ($html) { $desc =~ s//>/g; } if ($html) { print $fh " \n", " \n", " \n", " \n", " \n"; } else { print $fh "$key = $desc\n"; } } print $fh "
Template VariableDefault ValueDescription
$key", (defined $def ? $def : ' '), "$desc
\n\n" if ($html); } sub usageAndExit { print "document_template.pl v$version\n", "Usage: ", basename($0), "