aboutsummaryrefslogtreecommitdiff
path: root/contrib/global/htags
diff options
context:
space:
mode:
authorHidetoshi Shimokawa <simokawa@FreeBSD.org>1999-01-18 06:59:18 +0000
committerHidetoshi Shimokawa <simokawa@FreeBSD.org>1999-01-18 06:59:18 +0000
commit6ba7b1c961dd91c80782288f8c79c9c87b7eaa1b (patch)
treefee17e64a8e01d203e68ef96e216386521db1405 /contrib/global/htags
parent60adf819d22e8031d8591d6473b8b86d31840680 (diff)
parent3ba3e2cc4b63fa16707f51e735e751e62dd9526e (diff)
downloadsrc-6ba7b1c961dd91c80782288f8c79c9c87b7eaa1b.tar.gz
src-6ba7b1c961dd91c80782288f8c79c9c87b7eaa1b.zip
This commit was generated by cvs2svn to compensate for changes in r42788,
which included commits to RCS files with non-trunk default branches.
Notes
Notes: svn path=/head/; revision=42789
Diffstat (limited to 'contrib/global/htags')
-rw-r--r--contrib/global/htags/htags.pl915
1 files changed, 624 insertions, 291 deletions
diff --git a/contrib/global/htags/htags.pl b/contrib/global/htags/htags.pl
index e4e6de89d51f..d8488deae6c9 100644
--- a/contrib/global/htags/htags.pl
+++ b/contrib/global/htags/htags.pl
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
-# Copyright (c) 1996, 1997 Shigio Yamaguchi. All rights reserved.
+# Copyright (c) 1996, 1997, 1998 Shigio Yamaguchi. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -29,77 +29,196 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# htags.pl 20-Jan-98
+# htags.pl 10-Nov-98
#
$com = $0;
$com =~ s/.*\///;
-$usage = "usage: $com [-a][-f][-l][-n][-v][-w][-t title][-d tagdir][dir]\n";
+$usage = "usage: $com [-a][-c][-f][-h][-l][-n][-v][-w][-t title][-d tagdir][dir]\n";
+#-------------------------------------------------------------------------
+# COMMAND EXISTENCE CHECK
+#-------------------------------------------------------------------------
+foreach $c ('sort', 'gtags', 'global', 'btreeop') {
+ if (!&'usable($c)) {
+ &'error("'$c' command is required but not found.");
+ }
+}
#-------------------------------------------------------------------------
# CONFIGURATION
#-------------------------------------------------------------------------
-# columns of line number
-$ncol = 4;
-# font
-$comment_begin = '<I><FONT COLOR=green>'; # /* ... */
-$comment_end = '</FONT></I>';
-$sharp_begin = '<FONT COLOR=darkred>'; # #define, #include or so on
-$sharp_end = '</FONT>';
-$brace_begin = '<FONT COLOR=blue>'; # { ... }
-$brace_end = '</FONT>';
-$reserved_begin = '<B>'; # if, while, for or so on
-$reserved_end = '</B>';
-# reserved words
-$reserved_words = "auto|break|case|char|continue|default|do|double|else|extern|float|for|goto|if|int|long|register|return|short|sizeof|static|struct|switch|typedef|union|unsigned|void|while";
# temporary directory
-$tmp = '/tmp';
+$'tmp = '/tmp';
if (defined($ENV{'TMPDIR'}) && -d $ENV{'TMPDIR'}) {
$tmp = $ENV{'TMPDIR'};
}
+$'ncol = 4; # columns of line number
+$'tabs = 8; # tab skip
+$'gzipped_suffix = 'ghtml'; # suffix of gzipped html file
+#
+# font
+#
+$'title_begin = '<FONT COLOR=#cc0000>';
+$'title_end = '</FONT>';
+$'comment_begin = '<I><FONT COLOR=green>'; # /* ... */
+$'comment_end = '</FONT></I>';
+$'sharp_begin = '<FONT COLOR=darkred>'; # #define, #include or so on
+$'sharp_end = '</FONT>';
+$'brace_begin = '<FONT COLOR=blue>'; # { ... }
+$'brace_end = '</FONT>';
+$'reserved_begin = '<B>'; # if, while, for or so on
+$'reserved_end = '</B>';
+#
+# color
+#
+$'body_bgcolor = '';
+$'body_text = '';
+$'body_link = '';
+$'body_vlink = '';
+$'body_alink = '';
+#
+# Reserved words for C and Java are hard coded.
+# (configuration parameter 'reserved_words' was deleted.)
+#
+$'c_reserved_words = "auto,break,case,char,continue,default,do,double,else," .
+ "extern,float,for,goto,if,int,long,register,return," .
+ "short,sizeof,static,struct,switch,typedef,union," .
+ "unsigned,void,while";
+$'java_reserved_words = "abstract,boolean,break,byte,case,catch,char,class," .
+ "const,continue,default,do,double,else,extends,false," .
+ "final,finally,float,for,goto,if,implements,import," .
+ "instanceof,int,interface,long,native,new,null," .
+ "package,private,protected,public,return,short," .
+ "static,super,switch,synchronized,this,throw,throws," .
+ "union,transient,true,try,void,volatile,while";
+$'c_reserved_words =~ s/,/|/g;
+$'java_reserved_words =~ s/,/|/g;
+#
+# read values from global.conf
+#
+chop($config = `gtags --config`);
+if ($config) {
+ if ($var1 = &'getconf('ncol')) {
+ if ($var1 < 1 || $var1 > 10) {
+ print STDERR "Warning: parameter 'ncol' ignored becase the value is too large or too small.\n";
+ } else {
+ $ncol = $var1;
+ }
+ }
+ if ($var1 = &'getconf('tabs')) {
+ if ($var1 < 1 || $var1 > 32) {
+ print STDERR "Warning: parameter 'tabs' ignored becase the value is too large or too small.\n";
+ } else {
+ $tabs = $var1;
+ }
+ }
+ if ($var1 = &'getconf('gzipped_suffix')) {
+ $gzipped_suffix = $var1;
+ }
+ if (($var1 = &'getconf('title_begin')) && ($var2 = &'getconf('title_end'))) {
+ $title_begin = $var1;
+ $title_end = $var2;
+ }
+ if (($var1 = &'getconf('comment_begin')) && ($var2 = &'getconf('comment_end'))) {
+ $comment_begin = $var1;
+ $comment_end = $var2;
+ }
+ if (($var1 = &'getconf('sharp_begin')) && ($var2 = &'getconf('sharp_end'))) {
+ $sharp_begin = $var1;
+ $sharp_end = $var2;
+ }
+ if (($var1 = &'getconf('brace_begin')) && ($var2 = &'getconf('brace_end'))) {
+ $brace_begin = $var1;
+ $brace_end = $var2;
+ }
+ if (($var1 = &'getconf('reserved_begin')) && ($var2 = &'getconf('reserved_end'))) {
+ $reserved_begin = $var1;
+ $reserved_end = $var2;
+ }
+ $body_bgcolor = $var1 if ($var1 = &'getconf('bgcolor'));
+ $body_text = $var1 if ($var1 = &'getconf('text'));
+ $body_link = $var1 if ($var1 = &'getconf('link'));
+ $body_vlink = $var1 if ($var1 = &'getconf('vlink'));
+ $body_alink = $var1 if ($var1 = &'getconf('alink'));
+}
+# HTML tag
+$'begin_html = "<HTML>\n";
+$'end_html = "</HTML>\n";
+$'begin_body = '<BODY';
+$'begin_body .= " BGCOLOR=$body_bgcolor" if ($body_bgcolor);
+$'begin_body .= " TEXT=$body_text" if ($body_text);
+$'begin_body .= " LINK=$body_link" if ($body_link);
+$'begin_body .= " LINK=$body_vlink" if ($body_vlink);
+$'begin_body .= " LINK=$body_alink" if ($body_alink);
+$'begin_body .= '>';
+$'begin_body .= "\n";
+$'end_body = "</BODY>\n";
#-------------------------------------------------------------------------
# DEFINITION
#-------------------------------------------------------------------------
# unit for a path
-$SEP = ' '; # source file path must not include $SEP charactor
-$ESCSEP = &escape($SEP);
-$SRCS = 'S';
-$DEFS = 'D';
-$REFS = 'R';
-$INCS = 'I';
+$'SEP = ' '; # source file path must not include $SEP charactor
+$'ESCSEP = &'escape($SEP);
+$'SRCS = 'S';
+$'DEFS = 'D';
+$'REFS = 'R';
+$'INCS = 'I';
#-------------------------------------------------------------------------
# JAVASCRIPT PARTS
#-------------------------------------------------------------------------
# escaped angle
-$langle = sprintf("unescape('%s')", &escape('<'));
-$rangle = sprintf("unescape('%s')", &escape('>'));
-# frame name
-$f_mains = 'mains'; # for main view
-$f_funcs = 'funcs'; # for function index
-$f_files = 'files'; # for file index
-$begin_script="<SCRIPT LANGUAGE=javascript>\n<!--\n";
-$end_script="<!-- end of script -->\n</SCRIPT>\n";
-$defaultview=
+$'langle = sprintf("unescape('%s')", &'escape('<'));
+$'rangle = sprintf("unescape('%s')", &'escape('>'));
+$'begin_script="<SCRIPT LANGUAGE=javascript>\n<!--\n";
+$'end_script="<!-- end of script -->\n</SCRIPT>\n";
+$'default_view=
"// if your browser doesn't support javascript, write a BASE tag statically.\n" .
"if (parent.frames.length)\n" .
- " document.write($langle+'BASE TARGET=$f_mains'+$rangle)\n";
-$rewrite_href_funcs =
- "if (parent.frames.length && parent.$f_funcs == self) {\n" .
+ " document.write($langle+'BASE TARGET=mains'+$rangle)\n";
+$'rewrite_href_funcs =
+ "if (parent.frames.length && parent.funcs == self) {\n" .
" document.links[0].href = '../funcs.html';\n" .
" document.links[document.links.length - 1].href = '../funcs.html';\n" .
"}\n";
-$rewrite_href_files =
- "if (parent.frames.length && parent.$f_files == self) {\n" .
- " document.links[0].href = '../files.html';\n" .
- " document.links[document.links.length - 1].href = '../files.html';\n" .
+$'rewrite_href_files =
+ "if (parent.frames.length && parent.files == self) {\n" .
+ " document.links[0].href = '../files.html';\n" .
+ " document.links[document.links.length - 1].href = '../files.html';\n" .
"}\n";
+sub set_header {
+ local($display, $title, $script) = @_;
+ local($head) = "<HEAD><TITLE>$title</TITLE>";
+ if ($script || ($'hflag && $display)) {
+ $head .= "\n";
+ $head .= $'begin_script;
+ $head .= $script if ($script);
+ if ($'hflag && $display) {
+ $title = '[' . $title . ']' if ($title);
+ $head .= "if (parent.frames.length && parent.mains == self) {\n";
+ $head .= " parent.title.document.open();\n";
+ $head .= " parent.title.document.write('<H3>$title</H3>');\n";
+ $head .= " parent.title.document.close();\n";
+ $head .= "}\n";
+ }
+ $head .= $'end_script;
+ }
+ $head .= "</HEAD>\n";
+ $head;
+}
#-------------------------------------------------------------------------
# UTIRITIES
#-------------------------------------------------------------------------
-$findcom = "find . \\( -type f -o -type l \\) -name '*.[chysS]' -print";
sub getcwd {
local($dir) = `/bin/pwd`;
chop($dir);
$dir;
}
+sub realpath {
+ local($dir) = @_;
+ local($cwd) = &getcwd;
+ chdir($dir) || &'error("cannot change directory '$dir'.");
+ local($new) = &getcwd;
+ chdir($cwd) || &'error("cannot recover current directory '$cwd'.");
+ $new;
+}
sub date {
local($date) = `date`;
chop($date);
@@ -119,9 +238,9 @@ sub escape {
'%' . sprintf("%x", ord($c));
}
sub usable {
- local($com) = @_;
+ local($command) = @_;
foreach (split(/:/, $ENV{'PATH'})) {
- return 1 if (-x "$_/$com");
+ return 1 if (-x "$_/$command");
}
return 0;
}
@@ -132,25 +251,46 @@ sub copy {
$ret = ($ret == 0) ? 1 : 0;
$ret;
}
+sub getconf {
+ local($name) = @_;
+ local($val);
+ chop($val = `gtags --config $name`);
+ if ($? != 0) { $val = ''; }
+ $val;
+}
+sub path2file {
+ local($path) = @_;
+ $path =~ s/^\.\///;
+ $path =~ s!/!$'SEP!g;
+ $path . '.' . $'HTML;
+}
+sub path2url {
+ local($path) = @_;
+ $path =~ s/^\.\///;
+ $path =~ s!/!$'ESCSEP!g;
+ $path . '.' . $'HTML;
+}
#-------------------------------------------------------------------------
# PROCESS START
#-------------------------------------------------------------------------
#
# options check.
#
-$aflag = $fflag = $lflag = $nflag = $vflag = $wflag = '';
+$'aflag = $'cflag = $'fflag = $'hflag = $'lflag = $'nflag = $'vflag = $'wflag = '';
while ($ARGV[0] =~ /^-/) {
$opt = shift;
- if ($opt =~ /[^-aflnvwtd]/) {
+ if ($opt =~ /[^-acfhlnvwtd]/) {
print STDERR $usage;
exit 1;
}
- if ($opt =~ /a/) { $aflag = 'a'; }
- if ($opt =~ /f/) { $fflag = 'f'; }
- if ($opt =~ /l/) { $lflag = 'l'; }
- if ($opt =~ /n/) { $nflag = 'n'; }
- if ($opt =~ /v/) { $vflag = 'v'; }
- if ($opt =~ /w/) { $wflag = 'w'; }
+ if ($opt =~ /a/) { $'aflag = 'a'; }
+ if ($opt =~ /c/) { $'cflag = 'c'; }
+ if ($opt =~ /f/) { $'fflag = 'f'; }
+ if ($opt =~ /h/) { $'hflag = 'h'; }
+ if ($opt =~ /l/) { $'lflag = 'l'; }
+ if ($opt =~ /n/) { $'nflag = 'n'; }
+ if ($opt =~ /v/) { $'vflag = 'v'; }
+ if ($opt =~ /w/) { $'wflag = 'w'; }
if ($opt =~ /t/) {
$opt = shift;
last if ($opt eq '');
@@ -161,62 +301,61 @@ while ($ARGV[0] =~ /^-/) {
$dbpath = $opt;
}
}
+if ($'cflag && !&'usable('gzip')) {
+ print STDERR "Warning: 'gzip' command not found. -c option ignored.\n";
+ $'cflag = '';
+}
if (!$title) {
- @cwd = split('/', &getcwd);
+ @cwd = split('/', &'getcwd);
$title = $cwd[$#cwd];
}
-$dbpath = &getcwd() if (!$dbpath);
+$dbpath = '.' if (!$dbpath);
unless (-r "$dbpath/GTAGS" && -r "$dbpath/GRTAGS") {
- &error("GTAGS and GRTAGS not found. please type 'gtags[RET]'");
+ &'error("GTAGS and GRTAGS not found. Please make them.");
}
+$dbpath = &'realpath($dbpath);
#
-# recognize format version
-# if version record is not found, it's assumed version 1.
+# for global(1)
#
- $support_version = 1; # I can understand this format version
-#
-open(GTAGS, "btreeop -K ' __.VERSION' $dbpath/GTAGS |") || &error("GTAGS not found.");
-$rec = <GTAGS>;
-close(GTAGS);
-if ($rec =~ /^ __\.VERSION[ \t]+([0-9]+)$/) {
- $format_version = $1;
-} else {
- $format_version = 1;
-}
-if ($format_version != $support_version) {
- &error("GTAGS format version unmatched. Please remake it.");
-}
+$ENV{'GTAGSROOT'} = &'getcwd();
+$ENV{'GTAGSDBPATH'} = $dbpath;
+delete $ENV{'GTAGSLIBPATH'};
#
# check directories
#
-$html = &getcwd() . '/HTML';
+$dist = &'getcwd() . '/HTML';
if ($ARGV[0]) {
- $cwd = &getcwd();
+ $cwd = &'getcwd();
unless (-w $ARGV[0]) {
- &error("'$ARGV[0]' is not writable directory.");
+ &'error("'$ARGV[0]' is not writable directory.");
}
- chdir($ARGV[0]) || &error("directory '$ARGV[0]' not found.");
- $html = &getcwd() . '/HTML';
- chdir($cwd) || &error("cannot return to original directory.");
+ chdir($ARGV[0]) || &'error("directory '$ARGV[0]' not found.");
+ $dist = &'getcwd() . '/HTML';
+ chdir($cwd) || &'error("cannot return to original directory.");
}
#
+# find filter
+#
+$'findcom = "gtags --find";
+#
# check if GTAGS, GRTAGS is the latest.
#
$gtags_ctime = (stat("$dbpath/GTAGS"))[10];
-open(FIND, "$findcom |") || &error("cannot exec find.");
+open(FIND, "$'findcom |") || &'error("cannot fork.");
while (<FIND>) {
chop;
- next if /(y\.tab\.c|y\.tab\.h)$/;
- next if /(\/SCCS\/|\/RCS\/)/;
if ($gtags_ctime < (stat($_))[10]) {
- &error("GTAGS is not the latest one. Please remake it.");
+ &'error("GTAGS is not the latest one. Please remake it.");
}
}
close(FIND);
+if ($?) { &'error("cannot traverse directory."); }
#-------------------------------------------------------------------------
# MAKE FILES
#-------------------------------------------------------------------------
# HTML/cgi-bin/global.cgi ... CGI program (1)
+# HTML/cgi-bin/ghtml.cgi ... unzip script (1)
+# HTML/.htaccess.skel ... skelton of .htaccess (1)
# HTML/help.html ... help file (2)
# HTML/$REFS/* ... referencies (3)
# HTML/$DEFS/* ... definitions (3)
@@ -226,92 +365,110 @@ close(FIND);
# HTML/files/* ... file index (5)
# HTML/index.html ... index file (6)
# HTML/mains.html ... main index (7)
+# HTML/null.html ... main null html (7)
# HTML/$SRCS/ ... source files (8)
# HTML/$INCS/ ... include file index (9)
#-------------------------------------------------------------------------
-print STDERR "[", &date, "] ", "Htags started\n" if ($vflag);
+$'HTML = ($'cflag) ? $gzipped_suffix : 'html';
+print STDERR "[", &'date, "] ", "Htags started\n" if ($'vflag);
#
# (0) make directories
#
-print STDERR "[", &date, "] ", "(0) making directories ...\n" if ($vflag);
-mkdir($html, 0777) || &error("cannot make directory '$html'.") if (! -d $html);
+print STDERR "[", &'date, "] ", "(0) making directories ...\n" if ($'vflag);
+mkdir($dist, 0777) || &'error("cannot make directory '$dist'.") if (! -d $dist);
foreach $d ($SRCS, $INCS, $DEFS, $REFS, files, funcs) {
- mkdir("$html/$d", 0775) || &error("cannot make HTML directory") if (! -d "$html/$d");
+ mkdir("$dist/$d", 0775) || &'error("cannot make HTML directory") if (! -d "$dist/$d");
}
-if ($fflag) {
- mkdir("$html/cgi-bin", 0775) || &error("cannot make cgi-bin directory") if (! -d "$html/cgi-bin");
+if ($'fflag || $'cflag) {
+ mkdir("$dist/cgi-bin", 0775) || &'error("cannot make cgi-bin directory") if (! -d "$dist/cgi-bin");
}
#
# (1) make CGI program
#
-if ($fflag) {
- print STDERR "[", &date, "] ", "(1) making CGI program ...\n" if ($vflag);
- &makeprogram("$html/cgi-bin/global.cgi") || &error("cannot make CGI program.");
- chmod(0755, "$html/cgi-bin/global.cgi") || &error("cannot chmod CGI program.");
- unlink("$html/cgi-bin/GTAGS", "$html/cgi-bin/GRTAGS");
- link("$dbpath/GTAGS", "$html/cgi-bin/GTAGS") || &copy("$dbpath/GTAGS", "$html/cgi-bin/GTAGS") || &error("cannot copy GTAGS.");
- link("$dbpath/GRTAGS", "$html/cgi-bin/GRTAGS") || &copy("$dbpath/GRTAGS", "$html/cgi-bin/GRTAGS") || &error("cannot copy GRTAGS.");
+if ($'fflag) {
+ print STDERR "[", &'date, "] ", "(1) making CGI program ...\n" if ($'vflag);
+ &makeprogram("$dist/cgi-bin/global.cgi") || &'error("cannot make CGI program.");
+ chmod(0755, "$dist/cgi-bin/global.cgi") || &'error("cannot chmod CGI program.");
+ unlink("$dist/cgi-bin/GTAGS", "$dist/cgi-bin/GRTAGS", "$dist/cgi-bin/GPATH");
+ link("$dbpath/GTAGS", "$dist/cgi-bin/GTAGS") || &'copy("$dbpath/GTAGS", "$dist/cgi-bin/GTAGS") || &'error("cannot copy GTAGS.");
+ link("$dbpath/GRTAGS", "$dist/cgi-bin/GRTAGS") || &'copy("$dbpath/GRTAGS", "$dist/cgi-bin/GRTAGS") || &'error("cannot copy GRTAGS.");
+ link("$dbpath/GPATH", "$dist/cgi-bin/GPATH") || &'copy("$dbpath/GPATH", "$dist/cgi-bin/GPATH") || &'error("cannot copy GPATH.");
+}
+if ($'cflag) {
+ &makehtaccess("$dist/.htaccess.skel") || &'error("cannot make .htaccess skelton.");
+ &makeghtml("$dist/cgi-bin/ghtml.cgi") || &'error("cannot make unzip script.");
+ chmod(0755, "$dist/cgi-bin/ghtml.cgi") || &'error("cannot chmod unzip script.");
}
#
# (2) make help file
#
-print STDERR "[", &date, "] ", "(2) making help.html ...\n" if ($vflag);
-&makehelp("$html/help.html");
+print STDERR "[", &'date, "] ", "(2) making help.html ...\n" if ($'vflag);
+&makehelp("$dist/help.html");
#
# (3) make function entries ($DEFS/* and $REFS/*)
# MAKING TAG CACHE
#
-print STDERR "[", &date, "] ", "(3) making duplicate entries ...\n" if ($vflag);
-sub suddenly { &clean(); exit 1}
+print STDERR "[", &'date, "] ", "(3) making duplicate entries ...\n" if ($'vflag);
+sub suddenly { &'clean(); exit 1}
$SIG{'INT'} = 'suddenly';
$SIG{'QUIT'} = 'suddenly';
$SIG{'TERM'} = 'suddenly';
&cache'open(100000);
-$func_total = &makedupindex();
-print STDERR "Total $func_total functions.\n" if ($vflag);
+$func_total = &makedupindex($dist);
+print STDERR "Total $func_total functions.\n" if ($'vflag);
#
# (4) make function index (funcs.html and funcs/*)
# PRODUCE @funcs
#
-print STDERR "[", &date, "] ", "(4) making function index ...\n" if ($vflag);
-$func_total = &makefuncindex("$html/funcs.html", $func_total);
-print STDERR "Total $func_total functions.\n" if ($vflag);
+print STDERR "[", &'date, "] ", "(4) making function index ...\n" if ($'vflag);
+$func_total = &makefuncindex($dist, "$dist/funcs.html", $func_total);
+print STDERR "Total $func_total functions.\n" if ($'vflag);
#
# (5) make file index (files.html and files/*)
# PRODUCE @files %includes
#
-print STDERR "[", &date, "] ", "(5) making file index ...\n" if ($vflag);
-$file_total = &makefileindex("$html/files.html", "$html/$INCS");
-print STDERR "Total $file_total files.\n" if ($vflag);
+print STDERR "[", &'date, "] ", "(5) making file index ...\n" if ($'vflag);
+$file_total = &makefileindex($dist, "$dist/files.html", "$dist/$INCS");
+print STDERR "Total $file_total files.\n" if ($'vflag);
#
# [#] make a common part for mains.html and index.html
# USING @funcs @files
#
-print STDERR "[", &date, "] ", "(#) making a common part ...\n" if ($vflag);
+print STDERR "[", &'date, "] ", "(#) making a common part ...\n" if ($'vflag);
$index = &makecommonpart($title);
#
# (6)make index file (index.html)
#
-print STDERR "[", &date, "] ", "(6) making index file ...\n" if ($vflag);
-&makeindex("$html/index.html", $title, $index);
+print STDERR "[", &'date, "] ", "(6) making index file ...\n" if ($'vflag);
+&makeindex("$dist/index.html", $title, $index);
#
# (7) make main index (mains.html)
#
-print STDERR "[", &date, "] ", "(7) making main index ...\n" if ($vflag);
-&makemainindex("$html/mains.html", $index);
+print STDERR "[", &'date, "] ", "(7) making main index ...\n" if ($'vflag);
+&makemainindex("$dist/mains.html", $index);
+&makenullhtml("$dist/null.html") if ($'hflag);
#
# (#) make anchor database
#
-print STDERR "[", &date, "] ", "(#) making temporary database ...\n" if ($vflag);
+print STDERR "[", &'date, "] ", "(#) making temporary database ...\n" if ($'vflag);
&anchor'create();
#
# (8) make HTML files ($SRCS/*)
# USING TAG CACHE, %includes and anchor database.
#
-print STDERR "[", &date, "] ", "(8) making hypertext from source code ...\n" if ($vflag);
-&makehtml($file_total);
-&clean();
-print STDERR "[", &date, "] ", "Done.\n" if ($vflag);
+print STDERR "[", &'date, "] ", "(8) making hypertext from source code ...\n" if ($'vflag);
+&makehtml($dist, $file_total);
+&'clean();
+print STDERR "[", &'date, "] ", "Done.\n" if ($'vflag);
+if ($'cflag && $'vflag) {
+ print STDERR "\n";
+ print STDERR "[Information]\n";
+ print STDERR "\n";
+ print STDERR " You need to setup http server so that '*.ghtml' are treated\n";
+ print STDERR " as gzipped files. Please see 'HTML/.htaccess.skel'.\n";
+ print STDERR " Good luck!\n";
+ print STDERR "\n";
+}
exit 0;
#-------------------------------------------------------------------------
# SUBROUTINES
@@ -322,7 +479,7 @@ exit 0;
sub makeprogram {
local($file) = @_;
- open(PROGRAM, ">$file") || &error("cannot make CGI program.");
+ open(PROGRAM, ">$file") || &'error("cannot make CGI program.");
$program = <<'END_OF_SCRIPT';
#!/usr/bin/perl
#------------------------------------------------------------------
@@ -332,6 +489,7 @@ sub makeprogram {
# SO THAT THIS SCRIPT CAN BE EXECUTED AS A CGI COMMAND. THANK YOU.
#------------------------------------------------------------------
$SRCS = 'S';
+$HTML = '@HTML@';
$SEP = ' '; # source file path must not include $SEP charactor
$ESCSEP = &escape($SEP);
sub escape {
@@ -339,7 +497,7 @@ sub escape {
'%' . sprintf("%x", ord($c));
}
print "Content-type: text/html\n\n";
-print "<HTML>\n";
+print "<HTML><BODY>\n";
@pairs = split (/&/, $ENV{'QUERY_STRING'});
foreach $p (@pairs) {
($name, $value) = split(/=/, $p);
@@ -349,7 +507,7 @@ foreach $p (@pairs) {
}
if ($form{'pattern'} eq '') {
print "<H3>Pattern not specified. <A HREF=../mains.html>[return]</A></H3>\n";
- print "</HTML>\n";
+ print "</BODY></HTML>\n";
exit 0;
}
$pattern = $form{'pattern'};
@@ -360,7 +518,7 @@ print "Following $words are matched to above pattern.<HR>\n";
$pattern =~ s/'//g; # to shut security hole
unless (open(PIPE, "/usr/bin/global -x$flag '$pattern' |")) {
print "<H3>Cannot execute global. <A HREF=../mains.html>[return]</A></H3>\n";
- print "</HTML>\n";
+ print "</BODY></HTML>\n";
exit 0;
}
$cnt = 0;
@@ -370,14 +528,15 @@ while (<PIPE>) {
local($tag, $lno, $filename) = split;
$filename =~ s/^\.\///;
$filename =~ s/\//$ESCSEP/g;
- s/($tag)/<A HREF=..\/$SRCS\/$filename.html#$lno>$1<\/A>/;
+ s/($tag)/<A HREF=..\/$SRCS\/$filename.$HTML#$lno>$1<\/A>/;
print;
}
+close(PIPE);
print "</PRE>\n";
if ($cnt == 0) {
print "<H3>Pattern not found. <A HREF=../mains.html>[return]</A></H3>\n";
}
-print "</HTML>\n";
+print "</BODY></HTML>\n";
exit 0;
#------------------------------------------------------------------
# SORRY TO HAVE SURPRISED YOU!
@@ -387,17 +546,62 @@ exit 0;
#------------------------------------------------------------------
END_OF_SCRIPT
+ $program =~ s/\@HTML\@/$'HTML/g;
+ print PROGRAM $program;
+ close(PROGRAM);
+}
+#
+# makeghtml: make unzip script
+#
+sub makeghtml {
+ local($file) = @_;
+ open(PROGRAM, ">$file") || &'error("cannot make unzip script.");
+ $program = <<'END_OF_SCRIPT';
+#!/bin/sh
+echo "content-type: text/html"
+echo
+gzip -S @HTML@ -d -c "$PATH_TRANSLATED"
+END_OF_SCRIPT
+
+ $program =~ s/\@HTML\@/$'HTML/g;
print PROGRAM $program;
close(PROGRAM);
}
#
+# makehtaccess: make .htaccess skelton file.
+#
+sub makehtaccess {
+ local($file) = @_;
+ open(SKELTON, ">$file") || &'error("cannot make .htaccess skelton file.");
+ $skelton = <<'END_OF_SCRIPT';
+#
+# Skelton file for .htaccess -- This file was generated by htags(1).
+#
+# Htags have made gzipped hypertext because you specified -c option.
+# You need to setup http server so that these hypertext can be treated
+# as gzipped files.
+# There are many way to do it, but one of the method is to put .htaccess
+# file in 'HTML' directory.
+#
+# Please rewrite XXX to the true value in your web site and rename this
+# file to '.htaccess' and http server read this.
+#
+AddHandler htags-gzipped-html ghtml
+Action htags-gzipped-html /XXX/cgi-bin/ghtml.cgi
+END_OF_SCRIPT
+ print SKELTON $skelton;
+ close(SKELTON);
+}
+#
# makehelp: make help file
#
sub makehelp {
local($file) = @_;
- open(HELP, ">$file") || &error("cannot make help file.");
- print HELP "<HTML>\n<HEAD><TITLE>HELP</TITLE></HEAD>\n<BODY>\n";
+ open(HELP, ">$file") || &'error("cannot make help file.");
+ print HELP $'begin_html;
+ print HELP &'set_header(0, 'HELP');
+ print HELP $'begin_body;
print HELP "<H2>Usage of Links</H2>\n";
print HELP "<PRE>/* [&lt;][&gt;][^][v] [top][bottom][index][help] */</PRE>\n";
print HELP "<DL>\n";
@@ -410,7 +614,8 @@ sub makehelp {
print HELP "<DT>[index]<DD>Return to index page (mains.html).\n";
print HELP "<DT>[help]<DD>You are seeing now.\n";
print HELP "</DL>\n";
- print HELP "</BODY>\n</HTML>\n";
+ print HELP $'end_body;
+ print HELP $'end_html;
close(HELP);
}
#
@@ -425,28 +630,33 @@ sub makeline {
$_[0] =~ s/</&lt;/g;
$_[0] =~ s/>/&gt;/g;
local($tag, $lno, $filename) = split(/[ \t\n]+/, $_[0]);;
- $filename =~ s/\//$ESCSEP/g;
- $_[0] =~ s/^$tag/<A HREF=..\/$SRCS\/$filename.html#$lno>$tag<\/A>/;
+ $filename = &'path2url($filename);
+ $_[0] =~ s/^$tag/<A HREF=..\/$'SRCS\/$filename#$lno>$tag<\/A>/;
}
sub makedupindex {
+ local($dist) = @_;
local($count) = 0;
foreach $db ('GRTAGS', 'GTAGS') {
local($kind) = $db eq 'GTAGS' ? "definitions" : "references";
+ local($option) = $db eq 'GTAGS' ? '' : 'r';
local($prev) = '';
local($first_line);
local($writing) = 0;
$count = 0;
- open(LIST, "btreeop $dbpath/$db | sort +0 -1 +2 -3 +1n -2|") || &error("btreeop $dbpath/$db | sort +0 -1 +2 -3 +1n -2 failed.");
+ local($command) = "global -nx$option '.*' | sort +0 -1 +2 -3 +1n -2";
+ open(LIST, "$command |") || &'error("cannot fork.");
while (<LIST>) {
chop;
local($tag, $lno, $filename) = split;
if ($prev ne $tag) {
$count++;
- print STDERR " [$count] adding $tag $kind.\n" if ($vflag);
+ print STDERR " [$count] adding $tag $kind.\n" if ($'vflag);
if ($writing) {
- print FILE "</PRE>\n</BODY>\n</HTML>\n";
+ print FILE "</PRE>\n";
+ print FILE $'end_body;
+ print FILE $'end_html;
close(FILE);
$writing = 0;
}
@@ -460,10 +670,16 @@ sub makedupindex {
# duplicate entry
if ($first_line) {
&cache'put($db, $tag, '');
- local($type) = ($db eq 'GTAGS') ? $DEFS : $REFS;
- open(FILE, ">$html/$type/$tag.html") || &error("cannot make file '$html/$type/$tag.html'.");
+ local($type) = ($db eq 'GTAGS') ? $'DEFS : $'REFS;
+ if ($'cflag) {
+ open(FILE, "| gzip -c >$dist/$type/$tag.$'HTML") || &'error("cannot make file '$dist/$type/$tag.$'HTML'.");
+ } else {
+ open(FILE, ">$dist/$type/$tag.$'HTML") || &'error("cannot make file '$dist/$type/$tag.$'HTML'.");
+ }
$writing = 1;
- print FILE "<HTML>\n<HEAD><TITLE>$tag</TITLE></HEAD>\n<BODY>\n";
+ print FILE $'begin_html;
+ print FILE &'set_header(0, $tag);
+ print FILE $'begin_body;
print FILE "<PRE>\n";
&makeline($first_line);
print FILE $first_line, "\n";
@@ -474,8 +690,11 @@ sub makedupindex {
}
}
close(LIST);
+ if ($?) { &'error("'$command' failed."); }
if ($writing) {
- print FILE "</PRE>\n</BODY>\n</HTML>\n";
+ print FILE "</PRE>\n";
+ print FILE $'end_body;
+ print FILE $'end_html;
close(FILE);
}
if ($first_line) {
@@ -487,174 +706,228 @@ sub makedupindex {
#
# makefuncindex: make function index (including alphabetic index)
#
+# i) dist distribution directory
# i) file function index file
# i) total functions total
# gi) tag cache
# go) @funcs
#
sub makefuncindex {
- local($file, $total) = @_;
+ local($dist, $file, $total) = @_;
local($count) = 0;
+ local($indexlink) = "../mains.$'HTML";
- open(FUNCTIONS, ">$file") || &error("cannot make function index '$file'.");
- print FUNCTIONS "<HTML>\n<HEAD><TITLE>FUNCTION INDEX</TITLE>\n";
- print FUNCTIONS "$begin_script$defaultview$end_script</HEAD>\n<BODY>\n";
+ open(FUNCTIONS, ">$file") || &'error("cannot make function index '$file'.");
+ print FUNCTIONS $'begin_html;
+ print FUNCTIONS &'set_header(0, 'FUNCTION INDEX', $'default_view);
+ print FUNCTIONS $'begin_body;
print FUNCTIONS "<H2>FUNCTION INDEX</H2>\n";
- print FUNCTIONS "<OL>\n" if (!$aflag);
+ print FUNCTIONS "<OL>\n" if (!$'aflag);
local($old) = select(FUNCTIONS);
- open(TAGS, "btreeop -L $dbpath/GTAGS |") || &error("btreeop -L $dbpath/GTAGS failed.");
- local($alpha) = '';
+ local($command) = "global -c";
+ open(TAGS, "$command |") || &'error("cannot fork.");
+ local($alpha, $alpha_f);
@funcs = (); # [A][B][C]...
while (<TAGS>) {
$count++;
chop;
local($tag) = $_;
- print STDERR " [$count/$total] adding $tag\n" if ($vflag);
- if ($aflag && $alpha ne substr($tag, 0, 1)) {
+ print STDERR " [$count/$total] adding $tag\n" if ($'vflag);
+ if ($'aflag && ($alpha eq '' || $tag !~ /^$alpha/)) {
if ($alpha) {
print ALPHA "</OL>\n";
- print ALPHA "<A HREF=../mains.html TARGET=_self>[index]</A>\n";
- print ALPHA "$begin_script$rewrite_href_funcs$end_script";
- print ALPHA "</BODY>\n</HTML>\n";
+ print ALPHA "<A HREF=$indexlink TARGET=_self>[index]</A>\n";
+ print ALPHA "$'begin_script$'rewrite_href_funcs$'end_script";
+ print ALPHA $'end_body;
+ print ALPHA $'end_html;
close(ALPHA);
}
- $alpha = substr($tag, 0, 1);
- push(@funcs, "<A HREF=funcs/$alpha.html TARGET=_self>[$alpha]</A>\n");
- open(ALPHA, ">$html/funcs/$alpha.html") || &error("cannot make alphabetical function index.");
- print ALPHA "<HTML>\n<HEAD><TITLE>$alpha</TITLE>\n";
- print ALPHA "$begin_script$defaultview$end_script";
- print ALPHA "</HEAD>\n<BODY>\n<H2>[$alpha]</H2>\n";
- print ALPHA "<A HREF=../mains.html TARGET=_self>[index]</A>\n";
+ # for multi-byte code
+ local($c0, $c1);
+ $c0 = substr($tag, 0, 1);
+ if (ord($c0) > 127) {
+ $c1 = substr($tag, 1, 1);
+ $alpha = $c0 . $c1;
+ $alpha_f = "" . ord($c0) . ord($c1);
+ } else {
+ $alpha = $alpha_f = $c0;
+ }
+ push(@funcs, "<A HREF=funcs/$alpha_f.$'HTML TARGET=_self>[$alpha]</A>\n");
+ if ($'cflag) {
+ open(ALPHA, "| gzip -c >$dist/funcs/$alpha_f.$'HTML") || &'error("cannot make alphabetical function index.");
+ } else {
+ open(ALPHA, ">$dist/funcs/$alpha_f.$'HTML") || &'error("cannot make alphabetical function index.");
+ }
+ print ALPHA $'begin_html;
+ print ALPHA &'set_header(0, $alpha, $'default_view);
+ print ALPHA $'begin_body;
+ print ALPHA "<H2>[$alpha]</H2>\n";
+ print ALPHA "<A HREF=$indexlink TARGET=_self>[index]</A>\n";
print ALPHA "<OL>\n";
select(ALPHA);
}
local($line) = &cache'get('GTAGS', $tag);
if (!$line) {
- print "<LI><A HREF=", ($aflag) ? "../" : "", "$DEFS/$tag.html>$tag</A>\n";
+ print "<LI><A HREF=", ($'aflag) ? "../" : "", "$'DEFS/$tag.$'HTML>$tag</A>\n";
} else {
local($tag, $lno, $filename) = split(/[ \t]+/, $line);
- $filename =~ s/^\.\///;
- $filename =~ s/\//$ESCSEP/g;
- print "<LI><A HREF=", ($aflag) ? "../" : "", "$SRCS/$filename.html#$lno>$tag</A>\n";
+ $filename = &'path2url($filename);
+ print "<LI><A HREF=", ($'aflag) ? "../" : "", "$'SRCS/$filename#$lno>$tag</A>\n";
}
}
close(TAGS);
+ if ($?) { &'error("'$command' failed."); }
select($old);
- if ($aflag) {
+ if ($'aflag) {
print ALPHA "</OL>\n";
- print ALPHA "<A HREF=../mains.html TARGET=_self>[index]</A>\n";
- print ALPHA "$begin_script$rewrite_href_funcs$end_script";
- print ALPHA "</BODY>\n</HTML>\n";
+ print ALPHA "<A HREF=$indexlink TARGET=_self>[index]</A>\n";
+ print ALPHA "$'begin_script$'rewrite_href_funcs$'end_script";
+ print ALPHA $'end_body;
+ print ALPHA $'end_html;
close(ALPHA);
print FUNCTIONS @funcs;
}
- print FUNCTIONS "</OL>\n" if (!$aflag);
- print FUNCTIONS "</BODY>\n</HTML>\n";
+ print FUNCTIONS "</OL>\n" if (!$'aflag);
+ print FUNCTIONS $'end_body;
+ print FUNCTIONS $'end_html;
close(FUNCTIONS);
$count;
}
#
# makefileindex: make file index
#
-# i) file name
-# i) $INC directory
+# i) dist distribution directory
+# i) file file name
+# i) $incdir $INC directory
# go) @files
# go) %includes
#
sub makefileindex {
- local($file, $incdir) = @_;
+ local($dist, $file, $incdir) = @_;
local($count) = 0;
-
- open(FILES, ">$file") || &error("cannot make file '$file'.");
- print FILES "<HTML>\n<HEAD><TITLE>FILES</TITLE>\n";
- print FILES "$begin_script$defaultview$end_script";
- print FILES "</HEAD>\n<BODY>\n<H2>FILE INDEX</H2>\n";
+ local($indexlink) = "../mains.$'HTML";
+ local(@dirstack, @fdstack);
+ local($command) = "gtags --find | sort";
+ open(FIND, "$command |") || &'error("cannot fork.");
+ open(FILES, ">$file") || &'error("cannot make file '$file'.");
+ print FILES $'begin_html;
+ print FILES &'set_header(0, 'FILE INDEX', $'default_view);
+ print FILES $'begin_body;
+ print FILES "<H2>FILE INDEX</H2>\n";
print FILES "<OL>\n";
- local($old) = select(FILES);
- open(FIND, "$findcom | sort |") || &error("cannot exec find.");
- local($lastdir) = '';
- @files = ();
- while (<FIND>) {
- next if /(y\.tab\.c|y\.tab\.h)$/;
- next if /(\/SCCS\/|\/RCS\/)/;
+ local($org) = select(FILES);
+ local(@push, @pop, $file);
+
+ while (<FIND>) {
$count++;
chop;
s/^\.\///;
- local($filename) = $_;
- print STDERR " [$count] adding $filename\n" if ($vflag);
- local($dir);
- if (index($filename, '/') >= 0) {
- @split = split('/');
- $dir = $split[0];
- } else {
- $dir = '';
+ print STDERR " [$count] adding $_\n" if ($'vflag);
+ @push = split('/');
+ $file = pop(@push);
+ @pop = @dirstack;
+ while ($push[0] && $pop[0] && $push[0] eq $pop[0]) {
+ shift @push;
+ shift @pop;
}
- #if ($dir && $dir ne $lastdir) {
- if ($dir ne $lastdir) {
- if ($lastdir) {
- print DIR "</OL>\n";
- print DIR "<A HREF=../mains.html TARGET=_self>[index]</A>\n";
- print DIR "$begin_script$rewrite_href_files$end_script";
- print DIR "</BODY>\n</HTML>\n";
- close(DIR);
+ if (@push || @pop) {
+ while (@pop) {
+ pop(@dirstack);
+ local($parent) = (@dirstack) ? &path2url(join('/', @dirstack)) : $indexlink;
+ print "</OL>\n";
+ print "<A HREF=$parent TARGET=_self>[..]</A>\n";
+ print "$'begin_script$'rewrite_href_files$'end_script" if (@dirstack == 0);
+ print $'end_body;
+ print $'end_html;
+ $path = pop(@fdstack);
+ close($path);
+ select($fdstack[$#fdstack]) if (@fdstack);
+ pop(@pop);
}
- if ($dir) {
- push(@files, "<LI><A HREF=files/$dir.html TARGET=_self>$dir/</A>\n");
- open(DIR, ">$html/files/$dir.html") || &error("cannot make directory index.");
- print DIR "<HTML>\n<HEAD><TITLE>$dir/</TITLE>\n";
- print DIR "$begin_script$defaultview$end_script";
- print DIR "</HEAD>\n<BODY>\n<H2>$dir/</H2>\n";
- print DIR "<A HREF=../mains.html TARGET=_self>[index]</A>\n";
- print DIR "<OL>\n";
+ while (@push) {
+ local($parent) = (@dirstack) ? &path2url(join('/', @dirstack)) : $indexlink;
+ push(@dirstack, shift @push);
+ $path = join('/', @dirstack);
+ $cur = "$dist/files/" . &path2file($path);
+ local($li) = "<LI><A HREF=" . (@dirstack == 1 ? 'files/' : '') . &path2url($path) . " TARGET=_self>$path/</A>\n";
+ if (@dirstack == 1) {
+ push(@files, $li);
+ } else {
+ print $li;
+ }
+ if ($'cflag) {
+ open($cur, "| gzip -c >'$cur'") || &'error("cannot make directory index.");
+ } else {
+ open($cur, ">$cur") || &'error("cannot make directory index.");
+ }
+ select($cur);
+ push(@fdstack, $cur);
+ print $'begin_html;
+ print &'set_header(0, "$path", $'default_view);
+ print $'begin_body;
+ print "<H2>$path/</H2>\n";
+ print "<A HREF=$parent TARGET=_self>[..]</A>\n";
+ print "<OL>\n";
}
- $lastdir = $dir;
}
# collect include files.
- if ($filename =~ /.*\.h$/) {
- local($last) = $filename;
- $last =~ s!.*/!!;
- if (! defined $includes{$last}) {
- $includes{$last} = $filename;
+ if (/.*\.h$/) {
+ if (! defined $includes{$file}) {
+ $includes{$file} = $_;
} else {
# duplicate entries
- $includes{$last} = "$includes{$last}\n$filename";
+ $includes{$file} = "$includes{$file}\n$_";
}
}
- local($path) = $filename;
- $path =~ s/\//$ESCSEP/g;
- if ($dir eq '') {
- push(@files, "<LI><A HREF=$SRCS/$path.html>$filename</A>\n");
+ local($url) = &path2url($_);
+ local($li) = "<LI><A HREF=" . (@dirstack == 0 ? '' : '../') . "S/$url>$_</A>\n";
+ if (@dirstack == 0) {
+ push(@files, $li);
} else {
- print DIR "<LI><A HREF=../$SRCS/$path.html>$filename</A>\n";
+ print $li;
}
}
close(FIND);
- select($old);
- if ($lastdir) {
- print DIR "</OL>\n";
- print DIR "<A HREF=../mains.html TARGET=_self>[index]</A>\n";
- print DIR "$begin_script$rewrite_href_files$end_script";
- print DIR "</BODY>\n</HTML>\n";
- close(DIR);
+ while (@dirstack) {
+ pop(@dirstack);
+ local($parent) = (@dirstack) ? &path2url(join('/', @dirstack)) : $indexlink;
+ print "</OL>\n";
+ print "<A HREF=$parent TARGET=_self>[..]</A>\n";
+ print "$'begin_script$'rewrite_href_files$'end_script" if (@dirstack == 0);
+ print $'end_body;
+ print $'end_html;
+ $path = pop(@fdstack);
+ close($path);
+ select($fdstack[$#fdstack]) if (@fdstack);
}
print FILES @files;
print FILES "</OL>\n";
- print FILES "</BODY>\n</HTML>\n";
- close(FILES);
+ print FILES $'end_body;
+ print FILES $'end_html;
+ close(FILES);
+ select($org);
foreach $last (keys %includes) {
local(@incs) = split(/\n/, $includes{$last});
if (@incs > 1) {
- open(INCLUDE, ">$incdir/$last.html") || &error("cannot open file '$incdir/$last.html'.");
- print INCLUDE "<HTML>\n<HEAD><TITLE>$last</TITLE></HEAD>\n<BODY>\n<PRE>\n";
+ if ($'cflag) {
+ open(INCLUDE, "| gzip -c >$incdir/$last.$'HTML") || &'error("cannot open file '$incdir/$last.$'HTML'.");
+ } else {
+ open(INCLUDE, ">$incdir/$last.$'HTML") || &'error("cannot open file '$incdir/$last.$'HTML'.");
+ }
+ print INCLUDE $'begin_html;
+ print INCLUDE &'set_header(0, $last);
+ print INCLUDE $'begin_body;
+ print INCLUDE "<PRE>\n";
foreach $filename (@incs) {
- local($path) = $filename;
- $path =~ s/\//$ESCSEP/g;
- print INCLUDE "<A HREF=../$SRCS/$path.html>$filename</A>\n";
+ local($path) = &'path2url($filename);
+ print INCLUDE "<A HREF=../$'SRCS/$path>$filename</A>\n";
}
- print INCLUDE "</PRE>\n</BODY>\n</HTML>\n";
+ print INCLUDE "</PRE>\n";
+ print INCLUDE $'end_body;
+ print INCLUDE $'end_html;
close(INCLUDE);
# '' means that information already written to file.
$includes{$last} = '';
@@ -672,18 +945,18 @@ sub makecommonpart {
local($title) = @_;
local($index) = '';
- $index .= "<H1><FONT COLOR=#cc0000>$title</FONT></H1>\n";
+ $index .= "<H1>$'title_begin$'title$'title_end</H1>\n";
$index .= "<P ALIGN=right>";
- $index .= "Last updated " . &date . "<BR>\n";
- $index .= "This hypertext was generated by <A HREF=http://wafu.netgate.net/tama/unix/indexe.html#global TARGET=_top>GLOBAL</A>.<BR>\n";
- $index .= "$begin_script";
- $index .= "if (parent.frames.length && parent.$f_mains == self)\n";
- $index .= " document.write($langle+'A HREF=mains.html TARGET=_top'+$rangle+'[No frame version is here.]'+$langle+'/A'+$rangle)\n";
- $index .= "$end_script";
+ $index .= "Last updated " . &'date . "<BR>\n";
+ $index .= "This hypertext was generated by <A HREF=http://wafu.netgate.net/tama/unix/global.html TARGET=_top>GLOBAL</A>.<BR>\n";
+ $index .= $'begin_script;
+ $index .= "if (parent.frames.length && parent.mains == self)\n";
+ $index .= " document.write($'langle+'A HREF=mains.html TARGET=_top'+$'rangle+'[No frame version is here.]'+$'langle+'/A'+$'rangle)\n";
+ $index .= $'end_script;
$index .= "</P>\n<HR>\n";
- if ($fflag) {
+ if ($'fflag) {
$index .= "<H2>FUNCTION SEARCH</H2>\n";
- $index .= "Please input function name and select [Search]. Perl's regular expression is allowed.<P>\n";
+ $index .= "Please input function name and select [Search]. POSIX's regular expression is allowed.<P>\n";
$index .= "<FORM METHOD=GET ACTION=cgi-bin/global.cgi>\n";
$index .= "<INPUT NAME=pattern>\n";
$index .= "<INPUT TYPE=submit VALUE=Search>\n";
@@ -694,18 +967,19 @@ sub makecommonpart {
}
$index .= "<H2>MAINS</H2>\n";
$index .= "<PRE>\n";
- open(PIPE, "btreeop -K main $dbpath/GTAGS | sort +0 -1 +2 -3 +1n -2|") || &error("btreeop -K main $dbpath/GTAGS failed.");
+ local($command) = "global -nx main | sort +0 -1 +2 -3 +1n -2";
+ open(PIPE, "$command |") || &'error("cannot fork.");
while (<PIPE>) {
local($nouse, $lno, $filename) = split;
$nouse = ''; # to make perl quiet
- $filename =~ s/^\.\///;
- $filename =~ s/\//$ESCSEP/g;
- s/(main)/<A HREF=$SRCS\/$filename.html#$lno>$1<\/A>/;
+ $filename = &'path2url($filename);
+ s/(main)/<A HREF=$'SRCS\/$filename#$lno>$1<\/A>/;
$index .= $_;
}
close(PIPE);
+ if ($?) { &'error("'$command' failed."); }
$index .= "</PRE>\n<HR>\n<H2>FUNCTIONS</H2>\n";
- if ($aflag) {
+ if ($'aflag) {
foreach $f (@funcs) {
$index .= $f;
}
@@ -730,17 +1004,25 @@ sub makecommonpart {
sub makeindex {
local($file, $title, $index) = @_;
- open(FRAME, ">$file") || &error("cannot open file '$file'.");
- print FRAME "<HTML>\n<HEAD><TITLE>$title</TITLE></HEAD>\n";
+ open(FRAME, ">$file") || &'error("cannot open file '$file'.");
+ print FRAME $'begin_html;
+ print FRAME "<HEAD><TITLE>$title</TITLE></HEAD>\n";
print FRAME "<FRAMESET COLS='200,*'>\n";
- print FRAME "<NOFRAME>\n$index</NOFRAME>\n";
print FRAME "<FRAMESET ROWS='50%,50%'>\n";
- print FRAME "<FRAME NAME=$f_funcs SRC=funcs.html>\n";
- print FRAME "<FRAME NAME=$f_files SRC=files.html>\n";
+ print FRAME "<FRAME NAME=funcs SRC=funcs.html>\n";
+ print FRAME "<FRAME NAME=files SRC=files.html>\n";
print FRAME "</FRAMESET>\n";
- print FRAME "<FRAME NAME=$f_mains SRC=mains.html>\n";
+ if ($'hflag) {
+ print FRAME "<FRAMESET ROWS='50,*'>\n";
+ print FRAME "<FRAME NAME=title SRC=null.html BORDER=0 SCROLLING=no>\n";
+ print FRAME "<FRAME NAME=mains SRC=mains.html BORDER=0>\n";
+ print FRAME "</FRAMESET>\n";
+ } else {
+ print FRAME "<FRAME NAME=mains SRC=mains.html>\n";
+ }
+ print FRAME "<NOFRAMES>\n$index</NOFRAMES>\n";
print FRAME "</FRAMESET>\n";
- print FRAME "</HTML>\n";
+ print FRAME $'end_html;
close(FRAME);
}
#
@@ -752,34 +1034,48 @@ sub makeindex {
sub makemainindex {
local($file, $index) = @_;
- open(INDEX, ">$file") || &error("cannot create file '$file'.");
- print INDEX "<HTML>\n<HEAD><TITLE>MAINS</TITLE></HEAD>\n";
- print INDEX "<BODY>\n$index</BODY>\n</HTML>\n";
+ open(INDEX, ">$file") || &'error("cannot create file '$file'.");
+ print INDEX $'begin_html;
+ print INDEX &'set_header(1, $title);
+ print INDEX $'begin_body;
+ print INDEX $index;
+ print INDEX $'end_body;
+ print INDEX $'end_html;
close(INDEX);
}
#
+# makenullhtml: make null html
+#
+# i) $file file name
+#
+sub makenullhtml {
+ local($file) = @_;
+
+ open(NULL, ">$file") || &'error("cannot create file '$file'.");
+ print NULL "<HTML><BODY></BODY></HTML>\n";
+ close(NULL);
+}
+#
# makehtml: make html files
#
# i) total number of files.
#
sub makehtml {
- local($total) = @_;
+ local($dist, $total) = @_;
local($count) = 0;
- open(FIND, "$findcom |") || &error("cannot exec find.");
+ open(FIND, "$'findcom |") || &'error("cannot fork.");
while (<FIND>) {
- next if /y\.tab\.c|y\.tab\.h/;
- next if /(\/SCCS\/|\/RCS\/)/;
-
- $count++;
chop;
+ $count++;
local($path) = $_;
$path =~ s/^\.\///;
- print STDERR " [$count/$total] converting $path\n" if ($vflag);
- $path =~ s/\//$SEP/g;
- &convert'src2html($_, "$html/$SRCS/$path.html");
+ print STDERR " [$count/$total] converting $_\n" if ($'vflag);
+ $path = &'path2file($path);
+ &convert'src2html($_, "$dist/$'SRCS/$path");
}
close(FIND);
+ if ($?) { &'error("cannot traverse directory."); }
}
#=========================================================================
# CONVERT PACKAGE
@@ -789,29 +1085,38 @@ package convert;
# src2html: convert source code into HTML
#
# i) $file source file - Read from
-# i) $html HTML file - Write to
+# i) $hfile HTML file - Write to
# gi) %includes
# pairs of include file and the path
#
sub src2html {
- local($file, $html) = @_;
+ local($file, $hfile) = @_;
local($ncol) = $'ncol;
- local($expand) = &'usable('expand') ? 'expand' : 'cat';
+ local($tabs) = $'tabs;
local(%ctab) = ('&', '&amp;', '<', '&lt;', '>', '&gt;');
+ local($expand) = &'usable('expand') ? 'expand' : 'gtags --expand';
+ local($isjava) = ($file =~ /\.java$/) ? 1 : 0;
+ local($reserved_words) = ($isjava) ? $'java_reserved_words : $'c_reserved_words;
- open(HTML, ">$html") || &'error("cannot create file '$html'.");
+ if ($'cflag) {
+ open(HTML, "| gzip -c >'$hfile'") || &'error("cannot create file '$hfile'.");
+ } else {
+ open(HTML, ">$hfile") || &'error("cannot create file '$hfile'.");
+ }
local($old) = select(HTML);
#
# load tags belonging to this file.
#
&anchor'load($file);
- open(C, "$expand '$file' |") || &'error("cannot open file '$file'.");
+ open(SRC, "$expand -$tabs '$file' |") || &'error("cannot fork.");
#
# print the header
#
$file =~ s/^\.\///;
- print "<HTML>\n<HEAD><TITLE>$file</TITLE></HEAD>\n";
- print "<BODY><A NAME=TOP><H2>$file</H2>\n";
+ print $'begin_html;
+ print &'set_header(1, $file);
+ print $'begin_body;
+ print "<A NAME=TOP><H2>$file</H2>\n";
print &link_format(&anchor'getlinks(0));
print "\n<HR>\n";
print "<H2>FUNCTIONS</H2>\n";
@@ -829,24 +1134,23 @@ sub src2html {
print "<PRE>\n";
$INCOMMENT = 0; # initial status is out of comment
local($LNO, $TAG, $TYPE) = &anchor'first();
- while (<C>) {
+ while (<SRC>) {
local($converted);
s/\r$//;
# make link for include file
if (!$INCOMMENT && /^#include/) {
local($last, $sep) = m![</"]([^</"]+)([">])!;
- local($link);
if (defined $'includes{$last}) {
+ local($link, $suffix);
if ($'includes{$last}) {
- $link = $'includes{$last};
- $link =~ s/\//$'ESCSEP/g;
+ $link = &'path2url($'includes{$last});
} else {
- $link = "../$'INCS/$last";
+ $link = "../$'INCS/$last.$'HTML";
}
if ($sep eq '"') {
- s!"(.*$last)"!"<A HREF=$link.html>$1</A>"!;
+ s!"(.*$last)"!"<A HREF=$link>$1</A>"!;
} else {
- s!<(.*$last)>!&lt;<A HREF=$link.html>$1</A>&gt;!;
+ s!<(.*$last)>!&lt;<A HREF=$link>$1</A>&gt;!;
}
$converted = 1;
}
@@ -857,7 +1161,7 @@ sub src2html {
# painting source code
s/({|})/$'brace_begin$1$'brace_end/g;
local($sharp) = s/^(#\w+)// ? $1 : '';
- s/\b($'reserved_words)\b/$'reserved_begin$1$'reserved_end/go if ($sharp ne '#include');
+ s/\b($reserved_words)\b/$'reserved_begin$1$'reserved_end/go if ($sharp ne '#include');
s/^/$'sharp_begin$sharp$'sharp_end/ if ($sharp); # recover macro
local($define_line) = 0;
@@ -882,19 +1186,28 @@ sub src2html {
if ($line) {
local($nouse, $lno, $filename) = split(/[ \t]+/, $line);
$nouse = ''; # to make perl quiet
- $filename =~ s/^\.\///;
- $filename =~ s/\//$'ESCSEP/g;
- $href = "<A HREF=../$'SRCS/$filename.html#$lno>$TAG</A>";
+ $filename = &'path2url($filename);
+ $href = "<A HREF=../$'SRCS/$filename#$lno>$TAG</A>";
} else {
local($dir) = ($TYPE eq 'D') ? $'REFS : $'DEFS;
- $href = "<A HREF=../$dir/$TAG.html>$TAG</A>";
+ $href = "<A HREF=../$dir/$TAG.$'HTML>$TAG</A>";
}
# set tag marks and save hyperlink into @links
- if (s/\b$TAG\b/\005$count\005/ || s/\b_$TAG\b/_\005$count\005/) {
- $count++;
- push(@links, $href);
+ if (ord($TAG) > 127) { # for multi-byte code
+ if (s/([\x00-\x7f])$TAG([ \t]*\()/$1\005$count\005$2/ || s/([\x00-\x7f])$TAG([\x00-\x7f])/$1\005$count\005$2/) {
+ $count++;
+ push(@links, $href);
+ } else {
+ print STDERR "Error: $file $LNO $TAG($TYPE) tag must exist.\n" if ($'wflag);
+ }
} else {
- print STDERR "Error: $file $LNO $TAG($TYPE) tag must exist.\n" if ($'wflag);
+ if (s/\b$TAG([ \t]*\()/\005$count\005$1/ || s/\b$TAG\b/\005$count\005/ || s/\b_$TAG\b/_\005$count\005/)
+ {
+ $count++;
+ push(@links, $href);
+ } else {
+ print STDERR "Error: $file $LNO $TAG($TYPE) tag must exist.\n" if ($'wflag);
+ }
}
} else {
print STDERR "Warning: $file $LNO $TAG($TYPE) found but not referred.\n" if ($'wflag);
@@ -913,7 +1226,7 @@ sub src2html {
printf "%${ncol}d ", $. if ($'nflag);
print;
# print hyperlinks
- if ($define_line && $file !~ /\.h$/) {
+ if ($define_line) {
print ' ' x ($ncol + 1) if ($'nflag);
print &link_format(&anchor'getlinks($define_line));
print "\n";
@@ -924,8 +1237,10 @@ sub src2html {
print "<A NAME=BOTTOM>\n";
print &link_format(&anchor'getlinks(-1));
print "\n";
- print "</BODY>\n</HTML>\n";
- close(C);
+ print $'end_body;
+ print $'end_html;
+ close(SRC);
+ if ($?) { &'error("cannot open file '$file'."); }
close(HTML);
select($old);
@@ -939,6 +1254,7 @@ sub src2html {
# \002 quoted('') char
# \003 quoted string
# \004 comment
+# \005 line comment
# \032 temporary mark
#
sub protect_line {
@@ -975,6 +1291,13 @@ sub protect_line {
last if ($INCOMMENT);
}
}
+ $line_comment = '';
+ if (s!(//.*)$!\005!) {
+ $line_comment = $1;
+ # ^ // /* $
+ # (1) (2) ... (1) invalidate (2).
+ $INCOMMENT = 0;
+ }
}
#
# unprotect_line: recover quoted strings
@@ -984,8 +1307,12 @@ sub protect_line {
sub unprotect_line {
local($s);
+ if ($line_comment) {
+ s/\005/$'comment_begin$line_comment$'comment_end/;
+ }
while (@comments) {
$s = shift @comments;
+ # nested tag can be occured but no problem.
s/\004/$'comment_begin$s$'comment_end/;
}
while (@quoted_strings) {
@@ -1038,12 +1365,15 @@ sub create {
open(ANCH, ">$ANCH") || &'error("cannot create file '$ANCH'.");
close(ANCH);
chmod ($ANCH, 0600);
- open(ANCH, "| btreeop -C $ANCH") || &'error("btreeop -C $ANCH failed.");
+ local($command) = "btreeop -C $ANCH";
+ open(ANCH, "| $command") || &'error("cannot fork.");
local($fcount) = 1;
local($fnumber);
foreach $db ('GTAGS', 'GRTAGS') {
local($type) = ($db eq 'GTAGS') ? 'D' : 'R';
- open(PIPE, "btreeop $'dbpath/$db |") || &'error("btreeop $'dbpath/$db failed.");
+ local($option) = ($db eq 'GTAGS') ? '' : 'r';
+ local($command) = "global -nx$option '.*'";
+ open(PIPE, "$command |") || &'error("cannot fork.");
while (<PIPE>) {
local($tag, $lno, $filename) = split;
$fnumber = $PATHLIST{$filename};
@@ -1053,8 +1383,10 @@ sub create {
print ANCH "$fnumber $lno $tag $type\n";
}
close(PIPE);
+ if ($?) { &'error("'$command' failed."); }
}
close(ANCH);
+ if ($?) { &'error("'$command' failed."); }
}
#
# finish: remove anchors database
@@ -1063,7 +1395,7 @@ sub finish {
unlink("$ANCH") if (defined($ANCH));
}
#
-# load: load anchors in a file from database
+# load: load anchors belonging to specified file.
#
# i) $file source file
# gi) %PATHLIST
@@ -1081,15 +1413,15 @@ sub load {
if (!($fnumber = $PATHLIST{$file})) {
return;
}
- open(ANCH, "btreeop -K $fnumber $ANCH |") || &'error("btreeop -K $file $ANCH failed.");
-$n = 0;
+ local($command) = "btreeop -K $fnumber $ANCH";
+ open(ANCH, "$command |") || &'error("cannot fork.");
while (<ANCH>) {
local($fnumber, $lno, $tag, $type) = split;
local($line);
# don't refer to macros which is defined in other C source.
if ($type eq 'R' && ($line = &cache'get('GTAGS', $tag))) {
local($nouse1, $nouse2, $f, $def) = split(/[ \t]+/, $line);
- if ($f !~ /\.h$/ && $f !~ $file && $def =~ /^#/) {
+ if ($f !~ /\.h$/ && $f ne $file && $def =~ /^#/) {
print STDERR "Information: $file $lno $tag($type) skipped, because this is a macro which is defined in other C source.\n" if ($'wflag);
next;
}
@@ -1097,6 +1429,7 @@ $n = 0;
push(@ANCHORS, "$lno,$tag,$type");
}
close(ANCH);
+ if ($?) {&'error("'$command' failed."); }
local(@keys);
foreach (@ANCHORS) {
push(@keys, (split(/,/))[0]);