Annotation of doc/help/texxml2indextex.pl, revision 1.2

1.1       bowersj2    1: #!/usr/bin/perl
                      2: 
                      3: # The LearningOnline Network with CAPA
                      4: # Converts a texxml file into an 'index' file suitable for use as a
                      5: # help file online
                      6: #
                      7: # Copyright Michigan State University Board of Trustees
                      8: #
                      9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                     10: #
                     11: # LON-CAPA is free software; you can redistribute it and/or modify
                     12: # it under the terms of the GNU General Public License as published by
                     13: # the Free Software Foundation; either version 2 of the License, or
                     14: # (at your option) any later version.
                     15: #
                     16: # LON-CAPA is distributed in the hope that it will be useful,
                     17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     19: # GNU General Public License for more details.
                     20: #
                     21: # You should have received a copy of the GNU General Public License
                     22: # along with LON-CAPA; if not, write to the Free Software
                     23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     24: #
                     25: # /home/httpd/html/adm/gpl.txt
                     26: #
                     27: # http://www.lon-capa.org/
                     28: #
                     29: # 7-16-2002 Jeremy Bowers
                     30: 
                     31: use strict;
                     32: use HTML::TokeParser;
                     33: use GDBM_File;
                     34: 
                     35: if (not defined($ARGV[1]))
                     36: {
                     37:     print <<USAGE;
1.2     ! bowersj2   38: Usage: texxml2indextex.pl texxmlfilename
1.1       bowersj2   39: texxml2indextex.pl will create an 'index file' suitable for use as a 
                     40: sort of title page for a given set of help files. The second file will
                     41: be placed at the beginning, verbatim, so it can be used to provide
                     42: context, title, etc, if given.
                     43: USAGE
1.2     ! bowersj2   44: 
        !            45:    exit;
1.1       bowersj2   46: }
                     47: 
1.2     ! bowersj2   48: # accept texxml document on standard in
        !            49: my $p = HTML::TokeParser->new( <$ARGV[1]> );
        !            50: my $dirprefix = "/home/httpd/html/adm/help/tex/";
        !            51: 
        !            52: # there's a TTH error if we put something before a section starts,
        !            53: # so don't display anything that precedes a section. Since that's just
        !            54: # the title page anyhow, no loss.
        !            55: my $inSection = 0;
1.1       bowersj2   56: 
                     57: while (my $token = $p->get_token())
                     58: {
                     59:     my $type = $token->[0];
                     60:     if ($type eq 'S')
                     61:     {
                     62: 	my $tag = $token->[1];
                     63: 	my $attr = $token->[2];
1.2     ! bowersj2   64: 	if ($tag eq 'title')
        !            65: 	{
        !            66: 	    my $title = $attr->{'name'};
        !            67: 	    print "{\\Large Online Access to $title}\n\n";
        !            68: 	}
1.1       bowersj2   69: 	if ($tag eq 'section')
                     70: 	{
1.2     ! bowersj2   71: 	    $inSection = 1;
1.1       bowersj2   72: 	    my $title = $attr->{'name'};
1.2     ! bowersj2   73: 	    print "\\emph{\\textbf{$title}}\n";
        !            74: 	    print "\\begin{itemize}\n\n";
1.1       bowersj2   75: 	}
                     76: 
                     77: 	if ($tag eq 'subsection')
                     78: 	{
                     79: 	    my $title = $attr->{'name'};
                     80: 	    print "\\textbf{$title}\n\n";
1.2     ! bowersj2   81: 	    print "\\begin{itemize}\n\n";
1.1       bowersj2   82: 	}
                     83: 
                     84: 	if ($tag eq 'subsubsection')
                     85: 	{
                     86: 	    my $title = $attr->{'name'};
1.2     ! bowersj2   87: 	    print "\\emph{$title}\n\n";
        !            88: 	    print "\\begin{itemize}\n\n";
1.1       bowersj2   89: 	}
                     90: 
                     91: 	if ($tag eq 'file')
                     92: 	{
                     93: 	    my $file = substr($attr->{'name'}, 0, -4);
                     94: 	    my $title = $file;
                     95: 	    $title =~ s/_/ /g;
1.2     ! bowersj2   96: 	    if ($inSection) {print "\\item \\ref{$file} $title\n\n"};
        !            97: 	}
        !            98:     }
        !            99:     elsif ($type eq 'E')
        !           100:     {
        !           101: 	my $tag = $token->[1];
        !           102: 	if (index($tag, "section") != -1)
        !           103: 	{
        !           104: 	    print "\\end{itemize}\n\n";
1.1       bowersj2  105: 	}
                    106:     }
                    107: }
                    108: 
1.2     ! bowersj2  109: print "\n\n\\end{document}\n\n";

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>