| 1 |
#!/usr/local/bin/perl -s |
| 2 |
# |
| 3 |
# take a latex AUX file and change the bibstyle to subset or subset-nocomment |
| 4 |
# depending on if the -c flag was given (-c means use comments), then rename |
| 5 |
# the modified file to references.aux, run bibtex on it, rename the file |
| 6 |
# references.bbl to references.bib and delete references.{aux,blg}. This |
| 7 |
# results in a BibTeX file which can be shipped with the latex source of the |
| 8 |
# paper. The \bibliography{} command in the latex file will need to be changed |
| 9 |
# to use the newly generated bibliography. |
| 10 |
# |
| 11 |
# assumes subset.bst and subset-nocomment.bst are in the input path |
| 12 |
# |
| 13 |
# V. Khera 07-AUG-1992 |
| 14 |
# [email protected] |
| 15 |
|
| 16 |
$tmpfile = "refs$$"; |
| 17 |
$outfile = "references.bib"; |
| 18 |
|
| 19 |
$SIG{'INT'} = 'handler'; |
| 20 |
$SIG{'QUIT'} = 'handler'; |
| 21 |
$SIG{'TERM'} = 'handler'; |
| 22 |
$| = 1; # make sure output is flushed after print. |
| 23 |
|
| 24 |
sub handler { |
| 25 |
local($sig) = @_; |
| 26 |
print "Got a SIG$sig -- cleaning up\n"; |
| 27 |
&cleanup; |
| 28 |
exit 1; |
| 29 |
} |
| 30 |
|
| 31 |
sub cleanup { |
| 32 |
unlink <$tmpfile.*>; |
| 33 |
} |
| 34 |
|
| 35 |
$bibstyle = defined($c) ? "subset" : "subset-nocomment"; |
| 36 |
|
| 37 |
die "usage: $0 [-c] <auxfile>\n" unless $#ARGV == 0; |
| 38 |
|
| 39 |
$infile = shift; |
| 40 |
|
| 41 |
# canonicalize the name to end i .aux. assumes file is in current directory, |
| 42 |
# even though a path may have been specified. tough noogies, i say! |
| 43 |
$infile =~ s#(.*/)?([^.]*).*#\2.aux#; |
| 44 |
|
| 45 |
die "No such file $infile\n" unless -f $infile; |
| 46 |
|
| 47 |
open(INF,$infile) || die "Cannot read $infile\n"; |
| 48 |
@auxdata = <INF>; # slurp the whole file in |
| 49 |
close(INF); |
| 50 |
|
| 51 |
# create a new AUX file with subset bibstyle specified. |
| 52 |
@result = grep(m/(\\citation|\\bibdata).*/ , @auxdata); |
| 53 |
die "No citations or data files specified in $infile\n" unless @result; |
| 54 |
push(@result,"\\bibstyle{$bibstyle}\n"); |
| 55 |
|
| 56 |
open (OUTF,">$tmpfile.aux") || die "Cannot create temp file\n"; |
| 57 |
print OUTF @result; |
| 58 |
close(OUTF); |
| 59 |
|
| 60 |
print "Running bibtex...\n"; |
| 61 |
|
| 62 |
$result = system "bibtex $tmpfile"; |
| 63 |
die "Error running bibtex\n" unless ($result >> 8) == 0; |
| 64 |
rename ("$tmpfile.bbl", $outfile); |
| 65 |
|
| 66 |
print "Output is in $outfile\n"; |
| 67 |
|
| 68 |
&cleanup; |