This file is indexed.

/usr/bin/runbib is in refdb-clients 1.0.2-3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
#!/bin/bash
# runbib - creates bibliography files from SGML/XML, LaTeX  or RTF files
# Markus Hoenicka <markus@mhoenicka.de> 2001-05-10

# OPTIONS: -d (database) -h (invoke help), -S bibliography-style,
#          -t type (db31|db31x|db50x|teix|tei5x|bibtex|rtf)
# relies on these external programs: (open)jade (db31)
#                                    xsltproc (db31x,db50x,teix,tei5x)
#                                    textutils (bibtex)
# use the configuration file runbibrc to alter the settings

### start user-customizable section
# the commands used to extract the IDs from the document sources
myjade="/usr/bin/openjade"
myxsltproc="/usr/bin/xsltproc"

# the textutils commands
mysort=sort
myuniq=uniq

# some refdb commands
myrefdbib=refdbib
myrtfcitations=rtfcitations
myrefdbrtf=refdbrtf

# the SGML and XML declarations
sgmldecl="/usr/share/refdb/declarations/docbook.dcl"
xmldecl="/usr/share/refdb/declarations/xml.dcl"

### end user-customizable section

# default stylesheets. Override them in runbibrc
citlist="/usr/share/refdb/dsssl/citations.dsl"
makecss="/usr/share/refdb/dsssl/makecss.dsl"
citlistx="/usr/share/refdb/xsl/citations.xsl"
citlistxraw="/usr/share/refdb/xsl/citationsraw.xsl"
db2teix="/usr/share/refdb/xsl/bibdb2tei.xsl"
makecssx="/usr/share/refdb/xsl/makecss.xsl"
makecssxns="/usr/share/refdb/xsl/makecss-ns.xsl"
teihtml="/usr/share/refdb/xsl/tei-refdb-xsl/tei-html/tei-refdb-html.xsl"
teifo="/usr/share/refdb/xsl/tei-refdb-xsl/tei-fo/tei-refdb-fo.xsl"
tei5html="/usr/share/refdb/xsl/tei-refdb-xsl/tei-html/tei-refdb-html-ns.xsl"
tei5fo="/usr/share/refdb/xsl/tei-refdb-xsl/tei-fo/tei-refdb-fo-ns.xsl"
docbkhtml="/usr/share/refdb/xsl/docbk-refdb-xsl/docbk-html/docbk-refdb-html.xsl"
docbkxhtml="/usr/share/refdb/xsl/docbk-refdb-xsl/docbk-xhtml/docbk-refdb-xhtml.xsl"
docbkfo="/usr/share/refdb/xsl/docbk-refdb-xsl/docbk-fo/docbk-refdb-fo.xsl"
docbk5html="/usr/share/refdb/xsl/docbk-refdb-xsl/docbk-html/docbk-refdb-html-ns.xsl"
docbk5xhtml="/usr/share/refdb/xsl/docbk-refdb-xsl/docbk-xhtml/docbk-refdb-xhtml-ns.xsl"
docbk5fo="/usr/share/refdb/xsl/docbk-refdb-xsl/docbk-fo/docbk-refdb-fo-ns.xsl"

# some initialization
databaseopt=""
encodingopt=""
outformat=db31
username=""
useropt=""
passwd=""
passwdopt=""
portarg=""
skip_id=""
startnumber="1"
numopt=""
cssfile=""
raw="f"
myfo=""
myhtml=""
myxhtml=""

# this allows to include or ignore marked sections in the SGML file
jadeincludearg=""

# this allows to pass additional options to (open)jade
jadeargs=""

# this allows to pass additional options to xsltproc
xsltprocargs=""

# the server IP address is passed to refdbib
iparg=""

# functions
fixdoctype ()
{
# Arguments: $1: filename of a jade-generated xml file
#
# jade and openjade erroneously forget a space in the doctype line
# this problem is *only* fixed in OpenJade 1.3.1, but this function
# will not alter this version's correct output so it is safe to run it
# unconditionally
    sed 's/\(<?.*\)\"\"\(.*\)/\1\" \"\2/' < $1 > $1.$$

    if [ $? -ne 0 ]; then
        echo "error while post-processing id file"
        exit 1
    fi
	
    mv $1.$$ $1
}

manglexsl ()
{
# Arguments: $1: filename of the refdbd-created driver file
#            $2: string denoting the document type (see outformats.h)
#
# refdbd sends us a generic xsl stylesheet. We need to create
# one html stylesheet and one fo stylesheet by importing the proper
# refdb xsl stylesheets. DocBook gets an additional xhtml stylesheet
# we'll also create a CSS file for all (x)html output
    local basename=${1%.*}

    if [ $2 = "REFTEIX5" ] || [ $2 = "REFDOCBKX5" ]; then
	$myxsltproc $makecssxns $1 > $basename.css
    else
	$myxsltproc $makecssx $1 > $basename.css
    fi


# todo: test whether $cssfile is an url
    if [ -n "$cssfile" ] && [ "$cssfile" != "$basename.css" ]; then
	# custom css file
	if [ $2 = "REFTEIX" ]; then
	    if [ "X$myfo" != "X" ]; then
		teifo=$myfo
	    fi
	    if [ "X$myhtml" != "X" ]; then
		teihtml=$myhtml
	    fi
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$teihtml\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&<xsl:param name=\"html.stylesheet\">$cssfile</xsl:param>&' < $1 > $basename.html.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$teifo\"/>& ; s&<!--CSSFILE/-->&&' < $1 > $basename.fo.xsl" | sh
	elif [ $2 = "REFTEIX5" ]; then
	    if [ "X$myfo" != "X" ]; then
		tei5fo=$myfo
	    fi
	    if [ "X$myhtml" != "X" ]; then
		tei5html=$myhtml
	    fi
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$tei5html\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&<xsl:param name=\"html.stylesheet\">$cssfile</xsl:param>&' < $1 > $basename.html.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$tei5fo\"/>& ; s&<!--CSSFILE/-->&&' < $1 > $basename.fo.xsl" | sh
	elif [ $2 = "REFDOCBKX" ]; then
	    if [ "X$myfo" != "X" ]; then
		docbkfo=$myfo
	    fi
	    if [ "X$myhtml" != "X" ]; then
		docbkhtml=$myhtml
	    fi
	    if [ "X$myxhtml" != "X" ]; then
		docbkxhtml=$myxhtml
	    fi
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbkhtml\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&<xsl:param name=\"html.stylesheet\">$cssfile</xsl:param>&' < $1 > $basename.html.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbkxhtml\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&<xsl:param name=\"html.stylesheet\">$cssfile</xsl:param>&' < $1 > $basename.xhtml.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbkfo\"/>& ; s&<!--CSSFILE/-->&&' < $1 > $basename.fo.xsl" | sh
	elif [ $2 = "REFDOCBKX5" ]; then
	    if [ "X$myfo" != "X" ]; then
		docbk5fo=$myfo
	    fi
	    if [ "X$myhtml" != "X" ]; then
		docbk5html=$myhtml
	    fi
	    if [ "X$myxhtml" != "X" ]; then
		docbk5xhtml=$myxhtml
	    fi
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbk5html\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&<xsl:param name=\"html.stylesheet\">$cssfile</xsl:param>&' < $1 > $basename.html.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbk5xhtml\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&<xsl:param name=\"html.stylesheet\">$cssfile</xsl:param>&' < $1 > $basename.xhtml.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbk5fo\"/>& ; s&<!--CSSFILE/-->&&' < $1 > $basename.fo.xsl" | sh
	fi
    elif [ -s "$basename.css" ]; then
	# default css file
	if [ $2 = "REFTEIX" ]; then
	    if [ "X$myfo" != "X" ]; then
		teifo=$myfo
	    fi
	    if [ "X$myhtml" != "X" ]; then
		teihtml=$myhtml
	    fi
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$teihtml\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&<xsl:param name=\"html.stylesheet\">$basename.css</xsl:param>&' < $1 > $basename.html.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$teifo\"/>& ; s&<!--CSSFILE/-->&&' < $1 > $basename.fo.xsl" | sh
	elif [ $2 = "REFTEIX5" ]; then
	    if [ "X$myfo" != "X" ]; then
		tei5fo=$myfo
	    fi
	    if [ "X$myhtml" != "X" ]; then
		tei5html=$myhtml
	    fi
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$tei5html\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&<xsl:param name=\"html.stylesheet\">$basename.css</xsl:param>&' < $1 > $basename.html.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$tei5fo\"/>& ; s&<!--CSSFILE/-->&&' < $1 > $basename.fo.xsl" | sh
	elif [ $2 = "REFDOCBKX" ]; then
	    if [ "X$myfo" != "X" ]; then
		docbkfo=$myfo
	    fi
	    if [ "X$myhtml" != "X" ]; then
		docbkhtml=$myhtml
	    fi
	    if [ "X$myxhtml" != "X" ]; then
		docbkxhtml=$myxhtml
	    fi
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbkhtml\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&<xsl:param name=\"html.stylesheet\">$basename.css</xsl:param>&' < $1 > $basename.html.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbkxhtml\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&<xsl:param name=\"html.stylesheet\">$basename.css</xsl:param>&' < $1 > $basename.xhtml.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbkfo\"/>& ; s&<!--CSSFILE/-->&&' < $1 > $basename.fo.xsl" | sh
	elif [ $2 = "REFDOCBKX5" ]; then
	    if [ "X$myfo" != "X" ]; then
		docbk5fo=$myfo
	    fi
	    if [ "X$myhtml" != "X" ]; then
		docbk5html=$myhtml
	    fi
	    if [ "X$myxhtml" != "X" ]; then
		docbk5xhtml=$myxhtml
	    fi
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbk5html\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&<xsl:param name=\"html.stylesheet\">$basename.css</xsl:param>&' < $1 > $basename.html.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbk5xhtml\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&<xsl:param name=\"html.stylesheet\">$basename.css</xsl:param>&' < $1 > $basename.xhtml.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbk5fo\"/>& ; s&<!--CSSFILE/-->&&' < $1 > $basename.fo.xsl" | sh
	fi
    else
	# no css file
	if [ $2 = "REFTEIX" ]; then
	    if [ "X$myfo" != "X" ]; then
		teifo=$myfo
	    fi
	    if [ "X$myhtml" != "X" ]; then
		teihtml=$myhtml
	    fi
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$teihtml\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&&' < $1 > $basename.html.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$teifo\"/>& ; s&<!--CSSFILE/-->&&' < $1 > $basename.fo.xsl" | sh
	elif [ $2 = "REFTEIX5" ]; then
	    if [ "X$myfo" != "X" ]; then
		tei5fo=$myfo
	    fi
	    if [ "X$myhtml" != "X" ]; then
		tei5html=$myhtml
	    fi
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$tei5html\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&&' < $1 > $basename.html.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$tei5fo\"/>& ; s&<!--CSSFILE/-->&&' < $1 > $basename.fo.xsl" | sh
	elif [ $2 = "REFDOCBK" ]; then
	    if [ "X$myfo" != "X" ]; then
		docbkfo=$myfo
	    fi
	    if [ "X$myhtml" != "X" ]; then
		docbkhtml=$myhtml
	    fi
	    if [ "X$myxhtml" != "X" ]; then
		docbkxhtml=$myxhtml
	    fi
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbkhtml\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&&' < $1 > $basename.html.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbkxhtml\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&&' < $1 > $basename.xhtml.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbkfo\"/>& ; s&<!--CSSFILE/-->&&' < $1 > $basename.fo.xsl" | sh
	elif [ $2 = "REFDOCBKX5" ]; then
	    if [ "X$myfo" != "X" ]; then
		docbk5fo=$myfo
	    fi
	    if [ "X$myhtml" != "X" ]; then
		docbk5html=$myhtml
	    fi
	    if [ "X$myxhtml" != "X" ]; then
		docbk5xhtml=$myxhtml
	    fi
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbk5html\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&&' < $1 > $basename.html.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbk5xhtml\"/>& ; s&<!-- REFDBBIBSTYLE -->.*<!-- /REFDBBIBSTYLE -->&& ; s&<!--CSSFILE/-->&&' < $1 > $basename.xhtml.xsl" | sh
	    echo "sed 's&<!-- REFDBSTYLESHEET -->.*<!-- /REFDBSTYLESHEET -->&<xsl:import href=\"$docbk5fo\"/>& ; s&<!--CSSFILE/-->&&' < $1 > $basename.fo.xsl" | sh
	fi
    fi

    rm $1
}

mangledsssl ()
{
# refdb sends us a dsssl stylesheet. We need to create
# a CSS file for all (x)html output. We first send the driver file through
# a dsssl script to isolate the html section (otherwise we'd get another
# definition for each variable from the print section), then grep for the
# definitions, and convert them to css
    local basename=${1%.*}

    $myjade -t sgml -d $makecss $1 | grep "(define refdb-" | sed 's/(define refdb-text-indent \(.*\))/p.BIBLIOMIXED {text-indent: \1;}/ ;  s/(define refdb-start-indent \(.*\))/p.BIBLIOMIXED {margin-left: \1;}/ ; s/(define refdb-font-size \(.*\))/p.BIBLIOMIXED {font-size: \1;}/' > $basename.css

    if [ -n "$cssfile" ] && [ "$cssfile" != "$basename.css" ]; then
	    echo "sed 's&(define %stylesheet% #f)&(define %stylesheet% \"$cssfile\")&' < $1 > $basename.dsl$$" | sh
	    mv $basename.dsl$$ $basename.dsl
    elif [ -s "$basename.css" ]; then
	    echo "sed 's&(define %stylesheet% #f)&(define %stylesheet% \"$basename.css\")&' < $1 > $basename.dsl$$" | sh
	    mv $basename.dsl$$ $basename.dsl
    fi
}

# the path of the global configuration file
globalconfig="/etc/refdb/runbibrc"

# determine configuration files
if [ ! -r "$globalconfig" ] && [ -n "$REFDBLIB" ]; then
    globalconfig=$REFDBLIB/runbibrc
fi
userconfig=$HOME/.runbibrc

if [ -n "$globalconfig" ] && [ -r "$globalconfig" ]; then
    allconfigs=$globalconfig
fi

if [ -r "$userconfig" ]; then
    allconfigs=$allconfigs" "$userconfig
fi

# read the settings in the configure file(s)
for config in $allconfigs; do
    while read refdbvar refdbval; do
	if [ -n "$refdbvar" ]; then
	    if [ $refdbvar = jade_args ]; then
		jadeargs=$refdbval
	    fi
	    if [ $refdbvar = jade_includearg ]; then
		jadeincludearg=$jadeincludearg" -i "$refdbval
	    fi
	    if [ $refdbvar = outformat ]; then
		outformat=$refdbval
	    fi
	    if [ $refdbvar = xsltproc_args ]; then
		xsltprocargs=$refdbval
	    fi
	fi
    done < $config
done

# read the command line options
while getopts ":a:b:c:d:E:G:hi:I:j:N:p:rsS:t:u:w:" opt; do
  case $opt in
    a  ) myfo=$OPTARG;;
    b  ) myhtml=$OPTARG;;
    c  ) myxhtml=$OPTARG;;
    d  ) databaseopt="-d "$OPTARG;;
    E  ) encodingopt="-E "$OPTARG;;
    G  ) cssfile=$OPTARG;;
    h  ) echo "creates refdb bibliographies from SGML, XML, Latex, or RTF documents"
	 echo 'usage: runbib [-a fo-driver] [-b html-driver] [-c xhtml-driver] [-d database] [-E encoding] [-G cssfile] [-h] [-i server-ip] [-I name] [-j jade-args] [-N number] [r] [s] [-S style] [-t type] [-u username] [-w password] file1 [file2...]'
	 echo "Options: -a select custom fo driver file"
	 echo "         -b select custom html driver file"
	 echo "         -c select custom xhtml driver file"
	 echo "         -d select default database"
	 echo "         -E set output character encoding"
	 echo "         -G set the path or URL of a CSS file for (x)html output"
	 echo "         -h print this help and exit"
	 echo "         -i set server IP address"
	 echo "         -I set name of INCLUDE section in OpenJade"
	 echo "         -j additional command-line options for OpenJade"
	 echo "         -N set start of reference numbering"
	 echo "         -r create raw instead of cooked bibliography"
	 echo "         -s skip ID extraction (provide your own IDs)"
	 echo "         -S select bibliography style"
	 echo "         -t select output type (db31|db31x|db50x|teix|tei5x|bibtex|rtf)"
	 echo "         -u set username"
	 echo "         -w set password"
	 exit 0 ;;
    i  ) iparg=" -i "$OPTARG;;
    I  ) jadeincludearg=$jadeincludearg" -i "$OPTARG;;
    j  ) jadeargs=$OPTARG;;
    N  ) startnumber=$OPTARG;;
    p  ) portarg=" -p $OPTARG";;
    r  ) raw="t";;
    s  ) skip_id="t";;
    S  ) style=$OPTARG;;
    t  ) outformat=$OPTARG;;
    u  ) username=$OPTARG;;
    w  ) passwd=$OPTARG;;
    \? ) echo 'usage: runbib [-a fo-driver] [-b html-driver] [-c xhtml-driver] [-d database] [-E encoding] [-G cssfile] [-h] [-i server-ip] [-I name] [-j jade-args] [-N number] [-r] [s] [-S style] [-t type] [-u username] [-w password] file1 [file2...]'
	 echo 'type runbib -h to invoke help'
	 exit 1;;
  esac
done

# correct the index so the filename argument is always $1
shift $(($OPTIND - 1))

# check arguments
if [ $outformat != "db31" ] && [ $outformat != "bibtex" ] && 
    [ $outformat != "db31x" ] && [ $outformat != "teix" ] && 
    [ $outformat != "db50x" ] && [ $outformat != "tei5x" ] &&
    [ $outformat != "rtf" ]; then
    echo "invalid output type"
    exit 1
fi

if [ -n "$username" ]; then
    useropt=" -u $username"
fi

if [ -n "$passwd" ]; then
    passwdopt=" -w $passwd"
fi

if [ -n "$startnumber" ]; then
    numopt=" -N $startnumber"
fi

for filename in $*; do
    # extract the basename from the argument
    basename=${filename%.*}

### DocBook SGML
    if [ $outformat = "db31" ]; then
	# create a dummy bibliography file to get rid of the error msg
	if [ ! -f "$basename.bib.sgml" ]; then
	    touch $basename.bib.sgml
	fi

	if [ ! -n "$skip_id" ]; then
	    # first we run (open)jade with the citations.dsl stylesheet
            # to extract a list of citations from the source document

	    $myjade $jadeincludearg $jadeargs -t xml -d $citlist $sgmldecl $filename > $basename.id.xml
	    # this command will return an error if the bibliography does
	    # not exist yet. Therefore we can't test for an error condition
	    # here
	    #if [ $? -ne 0 ]; then
	        #exit 1
	    #fi

	    # due to a bug in both jade and openjade we need to doctor the
	    # doctype line to get a well-formed document
	    fixdoctype $basename.id.xml

	fi

	# then we run refdbib with the intermediate xml file to retrieve
	# the bibliography file and the style specification file
	
	$myrefdbib $databaseopt $encodingopt $useropt $passwdopt $numopt $portarg $iparg -S $style -D "." -t db31 $basename.id.xml > $basename.bib.sgml
	if [ $? -ne 0 ]; then
	    # move the output to error files so we can use the script
	    # in makefiles
	    mv $basename.bib.sgml $basename.bib.sgml.err
	    mv ${style%.}.dsl ${style%.}.dsl.err
	    exit 1
	fi

	# need to create the css file
	mangledsssl ${style%.}.dsl

### DocBook XML V4
    elif [ $outformat = "db31x" ]; then
	# create a dummy bibliography file to get rid of the error msg
	if [ ! -f "$basename.bib.xml" ]; then
	    touch $basename.bib.xml
	fi

	if [ ! -n "$skip_id" ]; then
	    # extract IDs with xsltproc
	    if [ $raw = "t" ]; then
		$myxsltproc --catalogs $citlistxraw $filename > $basename.id.xml
	    else
		$myxsltproc --catalogs $citlistx $filename > $basename.id.xml
	    fi
	fi

	if [ $raw = "t" ]; then
	    $myrefdbib $databaseopt $encodingopt $useropt $passwdopt $numopt $portarg $iparg -r -t db31x $basename.id.xml > $basename.bib.xml
	    if [ $? -ne 0 ]; then
	    # move the output to error files so we can use the script
	    # in makefiles
		mv $basename.bib.xml $basename.bib.xml.err
		exit 1
	    fi
	else # cooked bib including driver file
	    $myrefdbib $databaseopt $encodingopt $useropt $passwdopt $numopt $portarg $iparg -S $style -D "." -t db31x $basename.id.xml > $basename.bib.xml
	    if [ $? -ne 0 ]; then
	        # move the output to error files so we can use the script
	        # in makefiles
		mv $basename.bib.xml $basename.bib.xml.err
		mv ${style%.}.xsl ${style%.}.xsl.err
		exit 1
	    fi

	    # need to create three (html/xhtml/fo) xsl stylesheets
	    manglexsl ${style%.}.xsl "REFDOCBKX"
	fi

### DocBook XML V5
    elif [ $outformat = "db50x" ]; then
	# create a dummy bibliography file to get rid of the error msg
	if [ ! -f "$basename.bib.xml" ]; then
	    touch $basename.bib.xml
	fi

	if [ ! -n "$skip_id" ]; then
	    # extract IDs with xsltproc
	    if [ $raw = "t" ]; then
		$myxsltproc --catalogs $citlistxraw $filename > $basename.id.xml
	    else
		$myxsltproc --catalogs $citlistx $filename > $basename.id.xml
	    fi
	fi

	if [ $raw = "t" ]; then
	    $myrefdbib $databaseopt $encodingopt $useropt $passwdopt $numopt $portarg $iparg -r -n d -t db50x $basename.id.xml > $basename.bib.xml
	    if [ $? -ne 0 ]; then
	    # move the output to error files so we can use the script
	    # in makefiles
		mv $basename.bib.xml $basename.bib.xml.err
		exit 1
	    fi
	else # cooked bib including driver file
	    $myrefdbib $databaseopt $encodingopt $useropt $passwdopt $numopt $portarg $iparg -S $style -D "." -n d -t db50x $basename.id.xml > $basename.bib.xml
	    if [ $? -ne 0 ]; then
	        # move the output to error files so we can use the script
	        # in makefiles
		mv $basename.bib.xml $basename.bib.xml.err
		mv ${style%.}.xsl ${style%.}.xsl.err
		exit 1
	    fi

	    # need to create three (html/xhtml/fo) xsl stylesheets
	    manglexsl ${style%.}.xsl "REFDOCBKX5"
	fi

### TEI P4 XML
    elif [ $outformat = "teix" ]; then
	# same procedure as above, but for TEI P4 xml documents
	# create a dummy bibliography file to get rid of the error msg
	if [ ! -f "$basename.bib.xml" ]; then
	    touch $basename.bib.xml
	fi

	if [ ! -n "$skip_id" ]; then
	    # extract IDs with xsltproc
	    if [ $raw = "t" ]; then
		$myxsltproc --catalogs $citlistxraw $filename > $basename.id.xml
	    else
		$myxsltproc --catalogs $citlistx $filename > $basename.id.xml
	    fi
	fi

	if [ $raw = "t" ]; then
	    $myrefdbib $databaseopt $encodingopt $useropt $passwdopt $numopt $portarg $iparg -r -t teix $basename.id.xml > $basename.bib.xml
	    if [ $? -ne 0 ]; then
	        # move the output to error files so we can use the script
	        # in makefiles
		mv $basename.bib.xml $basename.bib.xml.err
		exit 1
	    fi

	    # the bibliography carries its own prolog, comment it out
#	    sed 's/\(<?xml.*\)/<!-- \1 -->/ ; s/\(<!DOCTYPE.*\)/<!-- \1 -->/' < $basename.bib.xml.$$ > $basename.bib.xml
#	    rm $basename.bib.xml.$$

	else # cooked bibliography including driver file
	    $myrefdbib $databaseopt $encodingopt $useropt $passwdopt $numopt $portarg $iparg -S $style -D "." -t teix $basename.id.xml > $basename.bib.xml
	    if [ $? -ne 0 ]; then
	        # move the output to error files so we can use the script
	        # in makefiles
		mv $basename.bib.xml $basename.bib.xml.err
		mv ${style%.}.xsl ${style%.}.xsl.err
		exit 1
	    fi

	    # the bibliography is in DocBook notation, transform to TEI
	    $myxsltproc --catalogs $db2teix $basename.bib.xml > $basename.bib.xml.$$
	    if [ $? -ne 0 ]; then
		mv $basename.bib.xml.$$ $basename.bib.xml.err
		mv ${style%.}.xsl ${style%.}.xsl.err
		exit 1
	    fi

	    # the bibliography carries its own prolog, comment it out
	    sed 's/\(<?xml.*\)/<!-- \1 -->/ ; s/\(<!DOCTYPE.*\)/<!-- \1 -->/' < $basename.bib.xml.$$ > $basename.bib.xml
	    rm $basename.bib.xml.$$

	    manglexsl ${style%.}.xsl "REFTEIX"
	fi

### TEI P5 XML
    elif [ $outformat = "tei5x" ]; then
	# same procedure as above, but for TEI P5 xml documents
	# create a dummy bibliography file to get rid of the error msg
	if [ ! -f "$basename.bib.xml" ]; then
	    touch $basename.bib.xml
	fi

	if [ ! -n "$skip_id" ]; then
	    # extract IDs with xsltproc
	    if [ $raw = "t" ]; then
		$myxsltproc --catalogs $citlistxraw $filename > $basename.id.xml
	    else
		$myxsltproc --catalogs $citlistx $filename > $basename.id.xml
	    fi
	fi

	if [ $raw = "t" ]; then
	    $myrefdbib $databaseopt $encodingopt $useropt $passwdopt $numopt $portarg $iparg -r -n tei -t tei5x $basename.id.xml > $basename.bib.xml
	    if [ $? -ne 0 ]; then
	        # move the output to error files so we can use the script
	        # in makefiles
		mv $basename.bib.xml $basename.bib.xml.err
		exit 1
	    fi

	else # cooked bibliography including driver file
	    $myrefdbib $databaseopt $encodingopt $useropt $passwdopt $numopt $portarg $iparg -S $style -D "." -n tei -t tei5x $basename.id.xml > $basename.bib.xml
	    if [ $? -ne 0 ]; then
	        # move the output to error files so we can use the script
	        # in makefiles
		mv $basename.bib.xml $basename.bib.xml.err
		mv ${style%.}.xsl ${style%.}.xsl.err
		exit 1
	    fi

	    manglexsl ${style%.}.xsl "REFTEIX5"
	fi

### BibTeX
    elif [ $outformat = "bibtex" ]; then
	if [ ! -r "$filename" ]; then
	    filename=$filename.aux
	    if [ ! -r "$filename" ]; then
		echo "cannot read input file"
		exit 1
            fi
        fi

	$mysort $filename | $myuniq | $myrefdbib $databaseopt $encodingopt $useropt $passwdopt $portarg $iparg -S $style -t bibtex > $basename.bib
	if [ $? -ne 0 ]; then
	    echo "No references retrieved from $filename"
	fi
### RTF
    else # RTF output
	if [ ! -n "$skip_id" ]; then
	    # extract IDs with rtfcitations
	    $myrtfcitations $filename > $basename.id.xml
	fi

	$myrefdbib $databaseopt $encodingopt $useropt $passwdopt $numopt $portarg $iparg -S $style -D "." -t rtf $basename.id.xml > $basename.bib.rtf
	if [ $? -ne 0 ]; then
	    # move the output to error files so we can use the script
	    # in makefiles
	    mv $basename.bib.xml $basename.bib.xml.err
	    mv ${style%.}.xsl ${style%.}.xsl.err
	    exit 1
	fi
    fi
done

exit 0