#!/usr/local/bin/perl # # makedb.pl # # Make a database of all the contributed papers containing # columns # # 1) desired filename for html file for the paper, which # is the name of the source file plus a .html extension. # # 2) filename assigned by latex2html, # # 3) page number for the start of the paper in the book, and # # 4) a guess at the last page number. Really just one less # than the page number for the next paper/part heading, # so could include blank pages. # # The desired filename and starting page number are obtained # from the book.aux file produced by latex, and the latex2html # filename is obtained from the book/labels.pl file produced by # latex2html. The common item is the labels inserted by the # \bookstufflabel commands. # my( $auxfile, $cwd, $end, %end_pages, $l2hfile, %l2h_names, $label, $line, $newlabel, $oldlabel, $start, %start_pages, ); use strict; use Cwd; $cwd = cwd() ; use lib $cwd ; use BOOKSTUFF ; $auxfile = "book.aux" ; $l2hfile = "book/labels.pl" ; # Open the auxfile, and parse for lines containing # "\contentsline {part}" or "bookstuff_". The latter are labels # at the beginning of each paper. Store start and end page # numbers in hashes. # open( AUX, "$auxfile" ) || die "Can't open .aux file $auxfile\n" ; while( defined( $line= ) ) { chop $line; if( $line =~ /bookstuff_/ ) { $newlabel = $' ; $newlabel =~ s/([^}]*)}{{\d+}{(\d+)}}/$1/ ; $start = $2 ; $start_pages{$newlabel} = $start ; if( defined( $oldlabel ) ) { $end = $start-1 ; $end_pages{$oldlabel} = $end ; } $oldlabel = $newlabel ; } elsif ( $line =~ /\\contentsline {part}/ ) { $newlabel = $' ; $newlabel =~ s/{([^}]*)}{(\d+)}/$1/ ; $start = $2 ; if( defined( $oldlabel ) ) { $end = $start-1 ; $end_pages{$oldlabel} = $end ; } undef $oldlabel ; } } close( AUX ) ; open( L2H, $l2hfile ) || die "Can't open labels file $l2hfile\n" ; while( defined( $line= ) ) { if( $line =~ /^\$key = q\/(.*)\/;/ ) { $label = $1 ; } elsif( $line =~ /^\$external_labels.*q\|(.*).html\|;/ ) { $l2h_names{$label} = $1 ; } } open( DB, ">$dbfile" ) || die "Can't open output file $dbfile\n" ; foreach $label (sort keys %start_pages) { print DB "$label\t$l2h_names{$label}\t$start_pages{$label}" . "\t$end_pages{$label}\n" ; }