(file) Return to chowto_scan.perl CVS log (file) (dir) Up to [HallC] / Documents / Howtos

File: [HallC] / Documents / Howtos / chowto_scan.perl (download)
Revision: 1.9, Fri Mar 18 20:17:44 2005 UTC (19 years, 6 months ago) by saw
Branch: MAIN
CVS Tags: mar2005
Branch point for: hks05
Changes since 1.8: +16 -8 lines
Add support for experiment specific branches

: # feed this into perl *-*-perl-*-*
    eval 'exec perl $0 "$@"'
    if $running_under_some_shell;

#
# chowto_scan.perl:
#   Scan though all of the Howto documents to produce various
#   automatically maintained files such as:
#         bibtex database of howto files
#         Web index of howto files
#
# howto_scan.pl <Directory with .tex files> <Base URL>
#
# $Log: chowto_scan.perl,v $
# Revision 1.9  2005/03/18 20:17:44  saw
# Add support for experiment specific branches
#
# Revision 1.8  2003/06/19 18:29:41  saw
# Multiline titles, links to other Hall C documentation
#
# Revision 1.7  2003/04/11 14:29:05  saw
# Add Sos and Electronics to possible howto categories
#
# Revision 1.6  2003/04/04 14:28:38  saw
# Prohibit off site access to vendor manuals
#
# Revision 1.5  2003/03/31 18:33:00  saw
# Correct error in howtolist.text file.
#
# Revision 1.4  2003/03/19 21:28:22  saw
# Uses working directory to find files.  Looks in ../VendorManuals for a
# BibTeX database to append to chowto-auto.bib.
#
# Revision 1.3  2003/03/11 21:54:36  saw
# Generate the index.html file with this script
#
# Revision 1.2  2003/03/08 04:38:40  saw
# Add links to postscript files on howtolist.html
#
# Revision 1.1  2003/03/06 20:21:57  saw
# Initial Checkin
#

$URLBASE = $ARGV[0];

%cattab = (
    "general","General",
    "daq","DAQ",
    "hms","HMS",
    "sos","SOS",
    "magnet", "Magnets",
    "beamline", "Beamline",
    "electronics", "Electronics"
    );

if(-s "EXPERIMENT") {
    chomp($EXPERIMENT=`head -1 EXPERIMENT`);
} else {
    $EXPERIMENT="Hall C";
}

open(BIBDB, ">chowto-auto.bib");
print BIBDB "% chowto-auto.bib\n";
print BIBDB "% This file is automatically generated, do not edit\n\n";

open(HTML, ">index.html");
open(TEXT, ">howtolist.text");

print HTML qq{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>${EXPERIMENT} Howto and Reference Documents</title>
</head>
<body>
<h1>Table of ${EXPERIMENT} Howtos</h1>
The following is a table of ${EXPERIMENT} howtos and references.
To sort the listing, click on column heading for the column
that you would like to sort on.

To contribute a howto or reference, please read the
<a href="howtohowto/">Howto Howto</a> for instructions.  To obtain the
latest version of the template, bibliography database and style files,
please download <a href="chowto.tgz">chowto.tgz</a>.  Mail any howtos that
you write to <a href="mailto:saw@jlab.org">Steve Wood</a> who will
post them to this listing.
<p>
Other Hall C Documentation:
<ol>
<li><a href="http://www.jlab.org/~smithg/target/Hall_C_Cryotarget.html">Cryogenic Target System</a>
<li><a href="http://www.jlab.org/Hall-C/document/manuals.html">Operating Procedures and Manuals</a>
<li><a href="../vendor_manuals/">Vendor Supplied Manuals</a>
</ol>
<p>
To read a howto online, click on the title for that howto.  To download a
postscript file suitable for printing, click on the appropriate link in
the "PS" column.
<p>
<table border cellpadding=3 cellspacing=0>
};
print HTML qq{<tr><th><a href="howtolist.php?sortby=Filename&reverse=1">Filename</a></th><th><a href="howtolist.php?sortby=Category">Category</a></th><th><a href="howtolist.php?sortby=Type">Type</a></th><th><a href="howtolist.php?sortby=Author">Author</a></th><th><a href="howtolist.php?sortby=Title">Title</a></th><th>PS</th>};
print TEXT "Filename|Category|Type|Author|Title|HTML|PS\n";

foreach $texfilename (glob("*.tex")) {
    open(TEXFILE,"<$texfilename");
    ($barefilename) = $texfilename=~ /([^\/]+).tex$/;
    %info = {};
    while(<TEXFILE>) {
	chomp;
	if(/^\\howtotype{(.*)}/) {
	    $info{howtotype} = $1;
	} elsif (/^\\author{(.*)}/) {
	    $info{author} = $1;
	    $info{author}=~s/\s*,\s*/ and /;
	} elsif (/^\\title{([^%]*)/) { # Allow multi line titles
	    $line = $1;
	    print "$line\n";
	    $info{title} = '';
	    while(not $line=~/}\s*(%.*)?$/) {
		$info{title} .= $line." ";
		print "$info{title}\n";
		$line=<TEXFILE>;
		chomp($line);
		print "Newline = $line\n";
	    }
	    $line =~ /^([^%]*)}\s*(%.*)?$/;
            $info{title} .= $1;
	    $info{title}=~s/\\\\//g;
            print "$info{title}\n";
        } elsif (/^\\category{(.*)}/) {
	    $info{category} = $cattab{$1};
	} elsif (/^\\maintainer{(.*)}/) {
	    $info{maintainer} = $1;
	} elsif (/^\\date{(.*)}/) {
	    $info{date} = $1;
	}
    }

    print BIBDB "\@Misc\{howto:$barefilename,\n";
    print BIBDB "  author = {$info{author}},\n";
    print BIBDB "  editor = {$info{maintainer}},\n" if ($info{maintainer});
    print BIBDB "  title = {$info{title}},\n";
    if($info{howtotype} eq "user") {
	print BIBDB "  note = {${EXPERIMENT} User Howto},\n";
    } elsif($info{howtotype} eq "expert") {
	print BIBDB "  note = {${EXPERIMENT} Expert Howto},\n";
    } elsif($info{howtotype} eq "reference") {
	print BIBDB "  note = {${EXPERIMENT} Reference},\n";
    }
    print BIBDB "  url = {$URLBASE/$barefilename/}\n}\n\n";
    print "$barefilename\n";

    $howtotypeuc = ucfirst($info{howtotype});
    print HTML "<tr><td>$barefilename</td><td>$info{category}</td><td>$howtotypeuc</td>
<td>$info{author}</td><td><a href=\"$URLBASE/$barefilename/\">$info{title}</a></td>
<td><a href=\"$URLBASE/$barefilename.ps\">PS</a></td></tr>\n";
    print TEXT "$barefilename|$info{category}|$howtotypeuc|$info{author}|$info{title}|$URLBASE/$barefilename/|$URLBASE/$barefilename.ps\n";

    close(TEXFILE);
}

print HTML "</table>\n";
@time = localtime;
@months = qw(January February March April May June July August
	     September October November December);
$month =  $months[$time[4]];
$day = $days[$time[6]];
$year = $time[5]+1900;
print HTML "<p>Last modified $month $time[3], $year\n";
print HTML "</body></html>\n";
close(BIBDB);

$vendorbibfile = "../VendorManuals/VendorManuals.bib";
if(-r $vendorbibfile) {
    `cat $vendorbibfile >> chowto-auto.bib`;
}

close(HTML);
close(TEXT);


Analyzer/Replay: Mark Jones, Documents: Stephen Wood
Powered by
ViewCVS 0.9.2-cvsgraph-1.4.0