Author: dylan
Date: 2004-08-07 19:13:49 -0400 (Sat, 07 Aug 2004)
New Revision: 337
Added:
branches/protocol-v4/docs/manual/buildlatex
Log:
added script for building latex documents,
which runs bibtex and latex as needed.
Added: branches/protocol-v4/docs/manual/buildlatex
===================================================================
--- branches/protocol-v4/docs/manual/buildlatex 2004-08-07 19:53:02 UTC (rev
336)
+++ branches/protocol-v4/docs/manual/buildlatex 2004-08-07 23:13:49 UTC (rev
337)
@@ -0,0 +1,83 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Getopt::Long;
+use File::Basename;
+
+sub spoon (&);
+
+my ($latex, @feature, %define, $config, $texfile);
+$latex = "latex";
+$config = "config.m4";
+$texfile = shift or die "Usage: $0 [options] file\n";
+
+Getopt::Long::Configure('gnu_getopt');
+GetOptions(
+ 'latex|l=s' => $latex,
+ 'feature|have|f=s' => [EMAIL PROTECTED],
+ 'define|d|D=s' => \%define,
+ 'config|c=s' => \$config,
+);
+
+my $code = spoon {
+ open STDOUT, ">config.tex" or die "$0: can't open config.tex: $!";
+ my @args;
+
+ foreach my $key (@feature) {
+ push @args, '-D', $key;
+ }
+
+ foreach my $key (keys %define) {
+ push @args, '-D', "$key=$define{$key}";
+ }
+
+ die "Input file not found: $config\n" if not -e $config;
+ exec('m4', @args, $config);
+};
+
+if (defined $code and $code == 0) {
+ my $rerun = 0;
+
+ do {
+ my $pipe;
+ my $pid = open $pipe, '-|', $latex, $texfile or die "Can't
start $latex: $!\n";
+ $rerun = 0;
+
+ while (<$pipe>) {
+ print $_;
+ chomp;
+ next if $rerun;
+
+ if (/No file (.+?)\.bbl\./) {
+ print "Doing bibtex\n";
+ $rerun = 1;
+ system('bibtex', $1);
+ } elsif (/Rerun to get cross-references right/) {
+ print "Rerunning.\n";
+ $rerun = 1;
+ }
+ }
+ close $pipe;
+ } while $rerun;
+
+} else {
+ die "m4 returned bad error code. $code\n";
+}
+
+sub spoon (&) {
+ my $code = shift;
+ my $pid = fork;
+ return undef if not defined $pid;
+
+ if ($pid) {
+ my $result = waitpid($pid, 0);
+ if ($result == -1) {
+ warn "No such pid? $pid";
+ }
+ my $code = $? >> 8;
+ return $code;
+ } else {
+ $code->();
+ exit 0;
+ }
+}
Property changes on: branches/protocol-v4/docs/manual/buildlatex
___________________________________________________________________
Name: svn:executable
+ *