/
bibget
executable file
·219 lines (160 loc) · 5.9 KB
/
bibget
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
version=2.0
# Written by Andrew Comech, comech@math.tamu.edu
# Thanks to Jakob Kellner for warning us about MathSciNet including &???; into the TeX code:
# TITLE = {Two cardinal invariants of the continuum {$(\germ d<\germ a)$} ....
# We will try to strip some of these off...
# Set debug to 1 or greater to see the debugging output
# Alternatively, add the option '--debug'
debug=0
#debug=1
# My host which allows ssh login, which has bibget installed, and which is subscribed to MathSciNet:
REMOTEHOST=x
# If I am at a home computer, use ssh:
# Below is an example of how you should NOT write scripts.
# Will use either wget or lynx or curl (in this order), whatever is available.
WGET="`which wget`"
if [ "$WGET" != "" ]; then
WGETOPTS="-q -nv -O -"
else
WGET="`which lynx`"
if [ "$WGET" != "" ]; then
WGETOPTS="-source"
else
WGET="`which curl`"
if [ "$WGET" != "" ]; then
WGETOPTS="-s -o -"
else
echo "
bibget may use either `wget' or `lynx' or `curl' as its back-end, but neither seems unavailable.
Please make sure either `wget' or `lynx' or `curl' are in the search path.
"
exit 1
fi
fi
fi
[ "$debug" -ge 1 ] && echo WGET=$WGET
[ "$debug" -ge 1 ] && echo WGETOPTS=$WGETOPTS
mirror0=www.ams.org
mirror1=ams.rice.edu
mirror2=ams.impa.br
mirror3=ams.math.uni-bielefeld.de
mirror4=ams.mpim-bonn.mpg.de
mirror5=ams.u-strasbg.fr
mathscisite=$mirror0
tmpfile="/tmp/bibget.$(date +%N).tmp"
bibinputs=""
if [ "$BIBINPUTS" != "" ]; then
for i in `echo $BIBINPUTS |sed 's/:/ /'`; do
bibinputs="`echo $i|grep $HOME|sed 's/[/]*$//'`"
[ "$bibinputs" != "" ] && break
done
fi
if [ "$2" = "" -a "$1" = "-m" -o "$1" = "-l" -o "$1" = "--list" ]; then
echo "
Some available MathSciNet mirrors:
$mirror0
$mirror1
$mirror2
$mirror3
$mirror4
$mirror5
Default is $mathscisite
Use with the \`-m' option: bibget -m $mirror1 ...
"
echo "Also checking http://www.ams.org/errors/msn-mirrors.html for more..."
$WGET $WGETOPTS http://www.ams.org/errors/msn-mirrors.html|grep http | grep mathscinet\
| sed 's/^.*http...//; s/.mathscinet.*//'
exit 0
fi
usage () {
echo "bibget, version $version: Command-line front-end for MathSciNet index.
GENERAL SEARCH: bibget [ [ k=]keyword ] [ a=author ] [ t=title ] [ j=journal ]
EXAMPLES: bibget a=gilkey t=invariance book 1984
bibget r=MR783634 >> books.bib
OTHER OPTIONS:
[ -m mirror | --mirror mirror ] use alternative MathSciNet mirror
[ -d | --debug ] debugging
OTHER USAGE:
bibget [ r=MRnumber | -r MRnumber ] grab a reference with given MRnumber
bibget [ -m | -l | --list ] list of some MathSciNet mirrors
bibget [ -doi <DOI> | doi=<DOi> ] extract bibsource from doi.org
bibget [ -h | --help ] this help
EXAMPLE OF SSH TUNNELING (via the institution subscribed to MathSciNet):
...no longer works. Try this instead:
ssh fourier.math.tamu.edu \"bibget a=gilkey t=invariance book 1984\" 2>/dev/null
(C) Andrew Comech, 2008--2018. GNU General Public License.
BIBTEX extraction from DOI is borrowed from Pavel Panchekha,
https://gist.github.com/pavpanchekha/f42c11807e3e8033f10f
"
}
if [ "$1" = "" -o "$1" = "-h" -o "$1" = "--help" ]; then
usage;
exit 0
fi
if [ "$1" = "-doi" -o "`echo $1| grep ^doi=`" != "" ]; then
[ "$debug" -ge 1 ] && echo DOI MODE
if [ "$1" = "-doi" ]; then
DOI="$2"
[ "$debug" -ge 1 ] && echo DOI2=$DOI
else
DOI="`echo $1|sed 's/^doi=//'`"
[ "$debug" -ge 1 ] && echo DOI1=$DOI
fi
# echo curl -LH "Accept: text/bibliography; style=bibtex" "http://dx.doi.org/$DOI"
curl -LH "Accept: text/bibliography; style=bibtex" http://dx.doi.org/$DOI
exit
fi
if [ `hostname` == "Kaa" -o `hostname` == "Sobaka" ]; then
ssh $REMOTEHOST "bibget $@" 2>/dev/null
fi
filter () {
sed 's/.refmr.*.endrefmr//; s/^.*endrefmr//' | sed 's/;[ ].*.refmr.*$//; s/.refmr.*$//' | grep -v "MRNUMBER.="
}
input0="^$1^$2^$3^$4^$5^$6^$7^$8^$9^"
[ "$debug" -ge 1 ] && echo input0=$input0
input=`echo $input0 | sed 's/\^--debug//g;s/\^-d//g;s/--debug\^//g;s/-d\^//g'`
if [ "$input0" != "$input" ]; then
debug=1
fi
[ "$debug" -ge 1 ] && echo input0=$input0
[ "$debug" -ge 1 ] && echo WGET=$WGET, WGETOPTS=\"$WGETOPTS\"
[ "$debug" -ge 1 ] && echo input1=$input
input=`echo $input|sed 's/-m\^/m=/g;s/--mirror\^/m=/g;s/-r\^/r=/g;s/-k\^/k=/g;s/-j\^/j=/g;s/-a\^/a=/g;s/-t\^/t=/g'`
[ "$debug" -ge 1 ] && echo corrected input1="$input"
suggestedmirror=`echo $input|sed 's/^.*\^m=//'|cut -f1 -d'^'`
[ "$debug" -ge 1 ] && echo suggestedmirror="$suggestedmirror"
if [ "$suggestedmirror" != "" ]; then
mathscisite="$suggestedmirror"
fi
input=`echo $input|sed 's/\^m=[^\^]*\^/^/g'`
input="`echo $input|sed 's/[\^]*$//'`"
[ "$debug" -ge 1 ] && echo input2=$input
fish="`echo $input|cut -d'_' -f1| sed 's/, /,%20/; s/,%20./&'*'/'`"
output=""
if [ "`echo $input|grep '._.'`" != "" ]; then
output="`echo $input|sed 's/$/.bib/; s/\.bib\.bib/.bib/'|cut -d'_' -f2`"
fi
fish="`echo $fish|sed 's/\^/^k=/g'`"
[ "$debug" -ge 1 ] && echo fish0=$fish
fish="`echo $fish|sed 's/\^k=a=/\&pg\^AUCN\&s\^/g' |sed 's/\^k=t=/\&pg\^TI\&s\^/g'|\
sed 's/\^k=k=/\&pg\^ALLF\&s\^/g'|sed 's/\^k=r=/\&pg\^MR\&s\^/g'|sed 's/\^k=j=/\&pg\^JOUR\&s\^/g'|sed 's/\^k=/\&pg\^ALLF\&s\^/g' `"
[ "$debug" -ge 1 ] && echo fish1=$fish
fish="`echo $fish|sed 's/^\^//'`"
for i in 1 2 3 4 5 6 7 8 9; do
fish="`echo $fish | sed "s/\^/$i=/" | sed "s/\^/$i=/"`"
done
fish="$fish&extend=1"
[ "$debug" -ge 1 ] && echo fish2=$fish
prefix="$mathscisite"/msnmain?fn=130\&fmt=bibtex\&l=100
[ "$debug" -ge 1 ] && echo prefix=$prefix
if [ "$debug" -ge 1 ]; then
echo "Trying the following command:"
echo $WGET $WGETOPTS http://"$prefix""$fish"|sed 's/&/\\&/g'
echo " * * * Debugging mode (debug=$debug); will not filter the output! * * *"
$WGET $WGETOPTS http://"$prefix""$fish"
else
$WGET $WGETOPTS http://"$prefix""$fish" | sed '1,/<pre>/d; /<\/pre>/,/<pre>/d; /<\/pre>/,$ d' | \
sed 's/</</g;s/>/>/g'
fi
exit