# -*-perl-*-
#/*@@
# @file grdoc_helpers
# @date Sun Apr 21 11:08:21 1996
# @author Paul Walker
# @desc
# Helper routines for the grdoc system
# @enddesc
# @comment
# $Id: grdoc_helpers,v 1.22 1996/04/22 01:14:49 pwalker Exp $
# @endcomment
#@@*/
#/*@@
# @routine html_head
# @date Sun Apr 21 11:09:07 1996
# @author Paul Walker
# @desc
# Prints the head of an html document, including body, navigation etc...
# Prints to OUT because I don't like select...
# @enddesc
# @var title
# @vdesc Title of the page
# @vtype string
# @vio in
# @endvar
# @calledby
#@@*/
sub
html_head
{
local($title)=@_[0];
print OUT "\n
$title\n\n";
print OUT "\n";
print OUT "\n";
print OUT "\n";
print OUT "\n";
print OUT "\n";
}
#/*@@
# @routine html_foot
# @date Sun Apr 21 11:11:05 1996
# @author Paul Walker
# @desc
# Prints the html footer for each page. Also generates the "generated
# on" date if it hasn't been done already.
# @enddesc
# @var code
# @vdesc String to print for code name
# @vtype string
# @vio in
# @endvar
#@@*/
sub
html_foot
{
local($code)=@_[0];
if (!$html_foot_date) {
($s,$m,$h,$md,$mo,$y,$wd,$yd,$isdst) = localtime();
@mo = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec");
$m = "0$m" if ($m < 10);
$html_foot_date = "Created $mo[$mo] $md, 19$y at $h:$m";
$html_foot_date = "$html_foot_date by grdoc";
}
print OUT "
\n";
print OUT "";
print OUT "$code
\n";
print OUT "$html_foot_date
\n";
print OUT "$organization / \n$author\n";
print OUT "\n\n";
}
#/*@@
# @routine strip_dirs
# @date Sun Apr 21 11:12:20 1996
# @author Paul Walker
# @desc
# Strips dirs out of a filename. eg, given foo/bar/hootie, returns hootie.
# @enddesc
#
# @var stripthis
# @vdesc The thing to strip
# @vtype string
# @vio in
# @endvar
#
# @returntype string
# @returndesc
# The stripped string
# @endreturndesc
#@@*/
sub
strip_dirs
{
local($stripthis) = @_[0];
return ($stripthis) unless ($stripthis =~ m:/:);
if ($stripthis =~ /\/$/) {
$stripthis =~ m:/([^/]+)/$:;
$result = $1;
} else {
$stripthis =~ m:/([^/]+)$:;
$result = $1;
}
return ($result);
}
#/*@@
# @routine sub_dir
# @date Sun Apr 21 11:14:17 1996
# @author Paul Walker
# @desc
# Returns the stuff not returned by @seeroutine strip_dirs, eg,
# given foo/bar/hootie returns foo/bar
# @enddesc
# @var stripthis
# @vdesc The thing to extract the subdir from
# @vtype string
# @vio in
# @endvar
# @returntype string
# @returndesc
# The subdir of the file in question
# @endreturndesc
#@@*/
sub
sub_dir
{
local ($stripthis) = @_[0];
$stripthis =~ s:$opt_i::;
$stripthis =~ m:^(.*)/([^/]+)$:;
$result = $1;
$result =~ s:^/::;
return $result;
}
#/*@@
# @routine insert_readme
# @date Sun Apr 21 11:15:43 1996
# @author Paul Walker
# @desc
# Inserts a readme.html into the current OUT if one exists in $dir
# @enddesc
# @var dir
# @vdesc The directory to check!
# @vtype string
# @vio in
# @endvar
#@@*/
sub
insert_readme
{
local ($dir) = @_[0];
if (-e "$dir/README.html") {
open (IN, "<$dir/README.html")||die "$in/README.html: $!\n";
print OUT "
";
while () {
print OUT;
}
print OUT "
";
close IN;
} else {
print OUT "
";
}
}
#/*@@
# @routine insert_header
# @date Sun Apr 21 11:15:43 1996
# @author Paul Walker
# @desc
# Inserts a header.html into the current OUT if one exists in $dir
# @enddesc
# @var dir
# @vdesc The directory to check!
# @vtype string
# @vio in
# @endvar
#@@*/
sub
insert_header
{
local ($dir) = @_[0];
if (-e "$dir/HEADER.html") {
open (IN, "<$dir/HEADER.html")||die "$in/HEADER.html: $!\n";
while () {
print OUT;
}
close IN;
} else {
print OUT "$opt_c
";
}
}
#/*@@
# @routine make_dotdot
# @date Sun Apr 21 11:17:04 1996
# @author Paul Walker
# @desc
# A broken routine which tried to make relative links. This was
# replaced in favor of the third pass (@seeroutine main) which turns
# the GRDOCREPLACEWITHRELATIVEXREF with the correct thing when we're
# done.
# @enddesc
#@@*/
sub
make_dotdot
{
local ($infile) = @_[0];
$result = $infile;
$result =~ s:$opt_o/::;
$result =~ s:$opt_i/::;
$result =~ s:/([^/]+)$:/:;
$result =~ s:([^/])+/:\.\./:g;
return ($result);
}
#/*@@
# @routine navigation
# @date Sun Apr 21 11:18:06 1996
# @author Paul Walker
# @desc
# Prints the navigation bar [ Top | ... to OUT.
# @enddesc
#@@*/
sub
navigation
# prints navigation for the indices to out, centered.
{
print OUT <
[ Top |
Files |
Routines |
Vars |
Pars |
Help
]
EOM
}
#/*@@
# @routine localnav
# @date Sun Apr 21 11:18:48 1996
# @author Paul Walker
# @desc
# Prints the local navigation stuff for a routine of file. This routine
# calls @seeroutine resolve_XRefs to generate the Foo [rich|raw]
# sort of things. Prints to OUT.
# @enddesc
# @calls resolve_XRefs
# @var thing
# @vdesc The file or routine which we want to generate the thing for
# @vtype string
# @vio in
# @endvar
# @var brief
# @vdesc Basically a string which, if defined, will cause a brief listing
# @vtype anything
# @vio in
# @vcomment
# Just a definition check here... A brief listing lacks the [ | ]
# after it.
# @endvar
# @var srcurl
# @vdesc A named link into the other frame for the richdoc
# @vtype string
# @vio in
# @vcomment
# An existance check is done, which sees if it should use this to
# generate the | show] link or not
# @endvar
# @comment Sorry...
# This is a little hairy...
# @endcomment
#@@*/
sub
localnav
# prints navigation for a routine or file to OUT, noncentered
{
local ($thing, $brief, $srcurl) = @_;
local ($msd);
if ($routine_home{$thing}) {
# We're dealing with a routine
$parent = $routine_home{$thing};
$richfile= &resolve_XRefs("\@seefile $parent");
$docfile = &resolve_XRefs("\@seefile $parent", "norich");
$routdoc = &resolve_XRefs("\@seeroutine $thing", "norich");
$rawsrc = $docfile;
$rawsrc =~ s:_File_Doc:_src:;
$rawsrc =~ s:\.html:.html\#$thing:;
$rawsrc =~ s:$opt_t/:$opt_t/PROTECTED/:;
$tree = $routdoc;
$tree =~ s:_Routine_Doc:_Routine_Tree:;
# OK, so now change the text
$richfile =~ s:>$parent:>rich:;
$rawsrc =~ s:>$parent:>raw:;
$tree =~ s:>$thing:>tree:;
# And make the link
print OUT "Routine " if !$brief;
print OUT "$routdoc [$tree";
if (!$brief) {
print OUT "]\n in file ";
$msd = $mysubdir{$parent};
if ($msd =~ m:\S:) {
print OUT "";
print OUT "src/$msd/";
} else {
print OUT "";
print OUT "src/";
}
print OUT "$docfile ";
print OUT "[$richfile | $rawsrc]\n";
} else {
if ($srcurl) {
print OUT " | ";
print OUT "show ]\n";
} else {
print OUT "]\n";
}
}
} elsif ($mysubdir{$thing} || $rootfiles{$thing}) {
# We're dealing with a file
$richfile= &resolve_XRefs("\@seefile $thing");
$docfile = &resolve_XRefs("\@seefile $thing", "norich");
$rawsrc = $docfile;
$rawsrc =~ s:_File_Doc:_src:;
$rawsrc =~ s:$opt_t/:$opt_t/PROTECTED/:;
# OK, so now change the text
$richfile =~ s:>$thing:>rich:;
$rawsrc =~ s:>$thing:>raw:;
# And make the link
print OUT "File " if !$brief;
print OUT "$docfile ";
print OUT "[$richfile | $rawsrc]\n";
if (!$brief) {
print OUT "in ";
$msd = $mysubdir{$thing};
if ($msd =~ m:\S:) {
print OUT "";
print OUT "src/$msd/";
} else {
print OUT "";
print OUT "src/";
}
}
} else {
# We're dealing with an unresolved XRef
print OUT "Unknown " if !$brief;
print OUT "$thing";
print OUT "";
}
}
#/*@@
# @routine html_safe
# @date Sun Apr 21 11:24:39 1996
# @author Paul Walker
# @desc
# Makes stuff safe for inclusion in html (eg, turns < > & into < etc..)
# but still pays attention to img and a href tags, which live!
#
# Note, if an optional second argument is passed, NO html survives!
# @enddesc
#@@*/
sub
html_safe
# Makes lines safe for html folks but protects hrefs, img src, and div.
{
local ($value, $supersafe) = @_;
$value =~ s:\&:\&\;:g;
$value =~ s:<(/a|div|/div|img src=[^>]+|a href=[^>]+)>:\<\;\1\>\;:g
if (!$supersafe);
$value =~ s:<:\<\;:g;
$value =~ s:>:\>\;:g;
if (!$supersafe) {
$value =~ s:\<\;:<:g;
$value =~ s:\>\;:>:g;
}
return $value;
}
#/*@@
# @routine indent
# @date Sun Apr 21 11:25:35 1996
# @author Paul Walker
# @desc
# Makes a table to indent 5%. Love those non-standard uses of html,
# eh?
# @enddesc
# @var dome
# @vdesc The thing to indent!
# @vtype string
# @vio in
# @endvar
# @returntype string
# @returndesc
# Returns $dome put in a 95% aligned table.
# @endreturndesc
# @comment
# Before you complain that I shouldn't use tables for layout, please
# consult the web page, where it says I don't care about what you
# think about how grdoc uses html.
# @endcomment
#@@*/
sub
indent
{
local ($dome) = @_[0];
$str = "
";
return $str;
}
#/*@@
# @routine de_punctualize
# @date Sun Apr 21 11:27:52 1996
# @author Paul Walker
# @desc
# Strips punctuation out of end of a routine. So if we pass foo, we
# get back an array which is ("foo", ",").
# @enddesc
# @var value
# @vdesc The thing to depunct
# @vtype string
# @vio in
# @endvar
# @returntype (string, string)
# @returndesc
# The first string is the depunctualized thing. The second is the
# punctuation which was stripped.
# @endreturndesc
# @comment
# Punctuation is a strange word, so if I misused it, deal!
# @endcomment
#@@*/
sub
de_punctualize
{
local ($value) = @_[0];
local ($nop, $punct);
if ($value =~ m:[\.\,\?\!\)\(]+$:) {
$nop = $value;
$nop =~ s:([\.\,\?\!\)\(]+)$::g;
$punct = $1;
} else {
$nop = $value;
$punct = "";
}
return ($nop, $punct);
}
# ? I love perl. :
1;