summaryrefslogtreecommitdiff
path: root/biblio/bibtex/utils/bibtools/makebib
blob: edd9ba4144ad45a7b6a68d1ed27f7cf726b6b428 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/csh -f
#
# makebib - make a bib file that has the given citations
#
# usage: 
#    makebib [-n | -d | -u] file.bib... [citekey]...
# Where -n means "no comment", ie, don't include any "comment" fields.
# And -d means "dfk", ie, add attribution to dfk to all comment fields.
# And -u means "unsorted", and comments are still included.
# Output is to subset.bib. If citekey is not given, then all refs in
# the bibfile are included.
#
# dfk 11/24/92: write the subset.aux file directly, skipping latex
# dfk 9/99: add unsorted option

onintr cleanup

if ($#argv < 1) then
	   echo 'usage: makebib [-n|-d] file.bib... [citekey]...'
	   exit 1
endif

if ("$1" == "-n") then
	   set bst=subset-nocomment
	   shift
else
	   if ("$1" == "-d") then
	   	   set bst=subset-dfk
	   	   shift
	   else
		if ("$1" == "-u") then
		    set bst=subset-unsorted
		    shift
		else
		    set bst=subset
		endif
	   endif
endif

if ($#argv < 1) then
	   echo 'usage: makebib [-n|-d|-u] file.bib... [citekey]...'
	   exit 1
endif

set files = $1:r
shift

while ($1:e == bib)
	   set files=($files,$1:r)
	   shift
end

echo creating subset.aux for $files

cat > subset.aux <<EOF
\relax 
\bibstyle{$bst}
\bibdata{$files}
EOF

# an annoying incompatibility in the way "echo" treats backslash...
if (`uname` == Linux) then
    set citation="\\citation"
else
    set citation="\citation"
endif

if ($#argv > 0) then
	   foreach f ($*)
	      echo $citation"{$f}" >> subset.aux
	   end
else
	   echo $citation'{*}' >> subset.aux
endif
rm -f subset.{log,dvi,bbl,blg}

echo bibtex subset
bibtex subset

if (-e makebib.sed.Z) uncompress makebib.sed
if (-e makebib.sed.gz) gunzip makebib.sed

echo ""
echo 'Fixing these lines (might be doing the wrong thing)'
grep '[^\\]%$' subset.bbl
echo end.
echo ""

sed -f makebib.sed subset.bbl > subset.bib

echo ""
echo output is in subset.bib

cleanup:
rm -f subset.{tex,aux,log,dvi,bbl,blg,sed}