rokicki@rocky.STANFORD.EDU (Tomas Rokicki) (12/30/87)
---cut here---
intentptr = 0 ;
while ( ( intentptr < numentints * numcites ) )
{ entryints [ intentptr ] = 0 ;
incr ( intentptr ) ;
}
if ( ( numentstrs * numcites > maxentstrs ) )
{ tputi ( cnull , numentstrs * numcites ) ;
tputs ( cnull , " " ) ;
{ tputs ( cnull , "Sorry, you've exceeded BibTeX's total number of string entry-variables " ) ;
tputi ( cnull , maxentstrs ) ;
tputc ( cnull , 10 ) ;
jumpout ( 1 ) ;
}
}
strentptr = 0 ;
while ( ( strentptr < numentstrs * numcites ) )
{ mymalloc ( entrystrs [ strentptr ] , 1 ) ;
entrystrs [ strentptr ] [ 0 ] = 127 ;
incr ( strentptr ) ;
}
citeptr = 0 ;
while ( ( citeptr < numcites ) )
{ typelist [ citeptr ] = 0 ;
sortedcites [ citeptr ] = citeptr ;
incr ( citeptr ) ;
}
bibptr = 0 ;
while ( ( bibptr < numbibfiles ) )
{ tputs ( cnull , "Database file #" ) ;
tputi ( cnull , bibptr + 1 ) ;
tputs ( cnull , ": " ) ;
printbibname () ;
biblinenum = 0 ;
bufptr2 = last ;
while ( ( ! feof ( bibfile [ bibptr ] ) ) ) getbibcommandorentry () ;
aclose ( bibfile [ bibptr ] ) ;
incr ( bibptr ) ;
}
#ifdef TRACE
tputs ( logfile , "finished reading the database file(s)\n" ) ;
#endif
citeptr = 0 ;
while ( ( citeptr < numcites ) )
{ if ( ( typelist [ citeptr ] == 0 ) )
{ tputs ( cnull , "I didn't find a database entry for \\cite key \"" ) ;
printpoolstr ( citelist [ citeptr ] ) ;
tputs ( cnull , "\"--warning\n" ) ;
}
incr ( citeptr ) ;
}
bufptr2 = svptr1 ;
last = svptr2 ;
tmpptr = bufptr2 ;
while ( ( tmpptr < last ) )
{ buffer [ tmpptr ] = svbuffer [ tmpptr ] ;
incr ( tmpptr ) ;
}
lab10 : ;
}
bstreversecommand () { /* 10 */ if ( ( ! readseen ) )
{ tputs ( cnull , "illegal, reverse command before read command" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
{ if ( ( ! eatbstwhitespace () ) )
{ eatbstprint () ;
{ tputs ( cnull , "reverse" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
}
}
{ if ( ( buffer [ bufptr2 ] != 123 ) )
{ bstleftbraceprint () ;
{ tputs ( cnull , "reverse" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
}
incr ( bufptr2 ) ;
}
{ if ( ( ! eatbstwhitespace () ) )
{ eatbstprint () ;
{ tputs ( cnull , "reverse" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
}
}
{ scanidentifier ( 125 , 37 ) ;
if ( ( ( scanresult == 3 ) || ( scanresult == 1 ) ) ) ;
else
{ bstidprint () ;
{ tputs ( cnull , "reverse" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
}
}
#ifdef TRACE
traceprtoken () ;
tputs ( logfile , " is a to be iterated in reverse function\n" ) ;
#endif
lowercase ( buffer , bufptr1 , ( bufptr2 - bufptr1 ) ) ;
fnloc = strlookup ( buffer , bufptr1 , ( bufptr2 - bufptr1 ) , 11 , false
) ;
if ( ( ! hashfound ) )
{ printtoken () ;
{ tputs ( cnull , " is an unknown function" ) ;
bstwarnprint () ;
}
}
else if ( ( ( fntype [ fnloc ] != 0 ) && ( fntype [ fnloc ] != 2 ) ) )
printfunctiontypebst () ;
{ if ( ( ! eatbstwhitespace () ) )
{ eatbstprint () ;
{ tputs ( cnull , "reverse" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
}
}
{ if ( ( buffer [ bufptr2 ] != 125 ) )
{ bstrightbraceprint () ;
{ tputs ( cnull , "reverse" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
}
incr ( bufptr2 ) ;
}
{ initcommandexecution () ;
messwithentries = true ;
if ( ( numcites > 0 ) )
{ sortciteptr = numcites ;
do { decr ( sortciteptr ) ;
citeptr = sortedcites [ sortciteptr ] ;
#ifdef TRACE
traceprpoolstr ( hashtext [ fnloc ] ) ;
tputs ( logfile , " to be iterated in reverse on " ) ;
traceprpoolstr ( citelist [ citeptr ] ) ;
tputc ( logfile , 10 ) ;
#endif
executefn ( fnloc ) ;
checkcommandexecutio () ;
} while ( ! ( ( sortciteptr == 0 ) ) ) ;
}
}
lab10 : ;
}
bstsortcommand () { /* 10 */ if ( ( ! readseen ) )
{ tputs ( cnull , "illegal, sort command before read command" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
{
#ifdef TRACE
tputs ( logfile , "sorting the entries\n" ) ;
#endif
if ( ( numcites > 1 ) ) quicksort ( 0 , numcites - 1 ) ;
#ifdef TRACE
tputs ( logfile , "done sorting\n" ) ;
#endif
}
lab10 : ;
}
bststringscommand () { /* 10 */
{ if ( ( ! eatbstwhitespace () ) )
{ eatbstprint () ;
{ tputs ( cnull , "strings" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
}
}
{ if ( ( buffer [ bufptr2 ] != 123 ) )
{ bstleftbraceprint () ;
{ tputs ( cnull , "strings" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
}
incr ( bufptr2 ) ;
}
{ if ( ( ! eatbstwhitespace () ) )
{ eatbstprint () ;
{ tputs ( cnull , "strings" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
}
}
while ( ( buffer [ bufptr2 ] != 125 ) )
{
{ scanidentifier ( 125 , 37 ) ;
if ( ( ( scanresult == 3 ) || ( scanresult == 1 ) ) ) ;
else
{ bstidprint () ;
{ tputs ( cnull , "strings" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
}
}
#ifdef TRACE
traceprtoken () ;
tputs ( logfile , " is a string global-variable\n" ) ;
#endif
lowercase ( buffer , bufptr1 , ( bufptr2 - bufptr1 ) ) ;
fnloc = strlookup ( buffer , bufptr1 , ( bufptr2 - bufptr1 ) , 11 ,
true ) ;
{ if ( ( hashfound ) )
{ alreadyseenfunctionp ( fnloc ) ;
goto lab10 ;
}
}
fntype [ fnloc ] = 9 ;
ilkinfo [ fnloc ] = numglbstrs ;
mymalloc ( globalstrs [ numglbstrs ] , 1 ) ;
globalstrs [ numglbstrs ] [ 0 ] = 127 ;
if ( ( numglbstrs == maxglobstrs ) )
{ tputs ( cnull , "Sorry, you've exceeded BibTeX's number of string global-variables " ) ;
tputi ( cnull , maxglobstrs ) ;
tputc ( cnull , 10 ) ;
jumpout ( 1 ) ;
}
incr ( numglbstrs ) ;
{ if ( ( ! eatbstwhitespace () ) )
{ eatbstprint () ;
{ tputs ( cnull , "strings" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
}
}
}
incr ( bufptr2 ) ;
lab10 : ;
}
getbstcommandandproc () { /* 10 */ if ( ( ! scanalpha () ) )
{ tputs ( cnull , "\"" ) ;
tputc ( cnull , xchr [ buffer [ bufptr2 ] ] ) ;
tputs ( cnull , "\" can't start a style-file command" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
lowercase ( buffer , bufptr1 , ( bufptr2 - bufptr1 ) ) ;
commandnum = ilkinfo [ strlookup ( buffer , bufptr1 , ( bufptr2 - bufptr1
) , 4 , false ) ] ;
if ( ( ! hashfound ) )
{ printtoken () ;
{ tputs ( cnull , " is an illegal style-file command" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
}
switch ( commandnum )
{ case 0 :
bstentrycommand () ;
break ;
case 1 :
bstexecutecommand () ;
break ;
case 2 :
bstfunctioncommand () ;
break ;
case 3 :
bstintegerscommand () ;
break ;
case 4 :
bstiteratecommand () ;
break ;
case 5 :
bstmacrocommand () ;
break ;
case 6 :
bstreadcommand () ;
break ;
case 7 :
bstreversecommand () ;
break ;
case 8 :
bstsortcommand () ;
break ;
case 9 :
bststringscommand () ;
break ;
default :
{ tputs ( cnull , "this can't happen---unknown style-file command" ) ;
bsterrprintandlookfo () ;
goto lab10 ;
}
break ;
} lab10 : ;
}
initialize () { /* 41 46 */ quarterword i ;
hashloc k ;
quarterword auxnamelength ;
integer c ;
bad = 0 ;
setupenv() ;
if ( ( minprintline < 3 ) ) bad = 1 ;
if ( ( maxprintline < minprintline ) ) bad = 10 * bad + 2 ;
if ( ( maxprintline >= bufsize ) ) bad = 10 * bad + 3 ;
if ( ( maxstrings > 5000 ) ) bad = 10 * bad + 7 ;
if ( ( maxcites > maxstrings ) ) bad = 10 * bad + 8 ;
if ( ( bad > 0 ) )
{ tputi ( stdout , bad ) ;
tputs ( stdout , " is a bad bad\n" ) ;
jumpout ( 0 ) ;
}
for ( i = 0 ; i <= 127 ; i ++ ) xord [ chr ( i ) ] = 127 ;
for ( i = 1 ; i <= 126 ; i ++ ) xord [ xchr [ i ] ] = i ;
for ( i = 0 ; i <= 127 ; i ++ ) lexclass [ i ] = 4 ;
for ( i = 0 ; i <= 31 ; i ++ ) lexclass [ i ] = 0 ;
lexclass [ 127 ] = 0 ;
lexclass [ 9 ] = 1 ;
lexclass [ 32 ] = 1 ;
for ( i = 48 ; i <= 57 ; i ++ ) lexclass [ i ] = 3 ;
for ( i = 65 ; i <= 90 ; i ++ ) lexclass [ i ] = 2 ;
for ( i = 97 ; i <= 122 ; i ++ ) lexclass [ i ] = 2 ;
for ( i = 0 ; i <= 127 ; i ++ ) idclass [ i ] = 1 ;
for ( i = 0 ; i <= 31 ; i ++ ) idclass [ i ] = 0 ;
idclass [ 32 ] = 0 ;
idclass [ 9 ] = 0 ;
idclass [ 34 ] = 0 ;
idclass [ 35 ] = 0 ;
idclass [ 37 ] = 0 ;
idclass [ 39 ] = 0 ;
idclass [ 40 ] = 0 ;
idclass [ 41 ] = 0 ;
idclass [ 44 ] = 0 ;
idclass [ 61 ] = 0 ;
idclass [ 123 ] = 0 ;
idclass [ 125 ] = 0 ;
for ( k = 1 ; k <= 5000 ; k ++ )
{ hashnext [ k ] = 0 ;
hashtext [ k ] = 0 ;
}
hashused = 5001 ;
poolptr = 0 ;
strptr = 1 ;
strstart [ strptr ] = poolptr ;
bibptr = 0 ;
bibseen = false ;
bststr = 0 ;
bstseen = false ;
citeptr = 0 ;
citationseen = false ;
wizdefptr = 0 ;
numglbstrs = 0 ;
numentints = 0 ;
numentstrs = 0 ;
numfields = 0 ;
entryseen = false ;
readseen = false ;
readperformed = false ;
implfnnum = 0 ;
predefine ( ".aux" , 7 ) ;
sauxextension = hashtext [ predefloc ] ;
predefine ( ".bbl" , 7 ) ;
sbblextension = hashtext [ predefloc ] ;
predefine ( ".blg" , 7 ) ;
slogextension = hashtext [ predefloc ] ;
predefine ( ".bst" , 7 ) ;
sbstextension = hashtext [ predefloc ] ;
predefine ( ".bib" , 7 ) ;
sbibextension = hashtext [ predefloc ] ;
predefine ( "\\citation" , 2 ) ;
ilkinfo [ predefloc ] = 2 ;
predefine ( "\\bibdata" , 2 ) ;
ilkinfo [ predefloc ] = 0 ;
predefine ( "\\bibstyle" , 2 ) ;
ilkinfo [ predefloc ] = 1 ;
predefine ( "\\@input" , 2 ) ;
ilkinfo [ predefloc ] = 3 ;
predefine ( "entry" , 4 ) ;
ilkinfo [ predefloc ] = 0 ;
predefine ( "execute" , 4 ) ;
ilkinfo [ predefloc ] = 1 ;
predefine ( "function" , 4 ) ;
ilkinfo [ predefloc ] = 2 ;
predefine ( "integers" , 4 ) ;
ilkinfo [ predefloc ] = 3 ;
predefine ( "iterate" , 4 ) ;
ilkinfo [ predefloc ] = 4 ;
predefine ( "macro" , 4 ) ;
ilkinfo [ predefloc ] = 5 ;
predefine ( "read" , 4 ) ;
ilkinfo [ predefloc ] = 6 ;
predefine ( "reverse" , 4 ) ;
ilkinfo [ predefloc ] = 7 ;
predefine ( "sort" , 4 ) ;
ilkinfo [ predefloc ] = 8 ;
predefine ( "strings" , 4 ) ;
ilkinfo [ predefloc ] = 9 ;
predefine ( "comment" , 12 ) ;
ilkinfo [ predefloc ] = 0 ;
predefine ( "string" , 12 ) ;
ilkinfo [ predefloc ] = 1 ;
bequals = buildin ( "=" , 0 ) ;
bgreaterthan = buildin ( ">" , 1 ) ;
blessthan = buildin ( "<" , 2 ) ;
bplus = buildin ( "+" , 3 ) ;
bminus = buildin ( "-" , 4 ) ;
bconcatenate = buildin ( "*" , 5 ) ;
bgets = buildin ( ":=" , 6 ) ;
baddperiod = buildin ( "add.period$" , 7 ) ;
bcalltype = buildin ( "call.type$" , 8 ) ;
bchangecase = buildin ( "change.case$" , 9 ) ;
bchrtoint = buildin ( "chr.to.int$" , 10 ) ;
bcite = buildin ( "cite$" , 11 ) ;
bduplicate = buildin ( "duplicate$" , 12 ) ;
bformatname = buildin ( "format.name$" , 13 ) ;
bif = buildin ( "if$" , 14 ) ;
binttochr = buildin ( "int.to.chr$" , 15 ) ;
binttostr = buildin ( "int.to.str$" , 16 ) ;
bmissing = buildin ( "missing$" , 17 ) ;
bnewline = buildin ( "newline$" , 18 ) ;
bnumnames = buildin ( "num.names$" , 19 ) ;
bpop = buildin ( "pop$" , 20 ) ;
bpurify = buildin ( "purify$" , 21 ) ;
bquote = buildin ( "quote$" , 22 ) ;
bskip = buildin ( "skip$" , 23 ) ;
bstack = buildin ( "stack$" , 24 ) ;
bsubstring = buildin ( "substring$" , 25 ) ;
bswap = buildin ( "swap$" , 26 ) ;
btopstack = buildin ( "top$" , 27 ) ;
btype = buildin ( "type$" , 28 ) ;
bwhile = buildin ( "while$" , 29 ) ;
bwidth = buildin ( "width$" , 30 ) ;
bwrite = buildin ( "write$" , 31 ) ;
predefine ( "sort.key$" , 11 ) ;
fntype [ predefloc ] = 7 ;
ilkinfo [ predefloc ] = numentstrs ;
sortkeynum = numentstrs ;
incr ( numentstrs ) ;
predefine ( "" , 0 ) ;
snull = hashtext [ predefloc ] ;
fntype [ predefloc ] = 4 ;
predefine ( "default.type" , 0 ) ;
sdefault = hashtext [ predefloc ] ;
fntype [ predefloc ] = 4 ;
bdefault = bskip ;
predefine ( "ul" , 0 ) ;
sul = hashtext [ predefloc ] ;
fntype [ predefloc ] = 4 ;
predefine ( "ll" , 0 ) ;
sll = hashtext [ predefloc ] ;
fntype [ predefloc ] = 4 ;
predefine ( "uu" , 0 ) ;
suu = hashtext [ predefloc ] ;
fntype [ predefloc ] = 4 ;
predefine ( "lu" , 0 ) ;
slu = hashtext [ predefloc ] ;
fntype [ predefloc ] = 4 ;
predefine ( "." , 0 ) ;
speriod = hashtext [ predefloc ] ;
fntype [ predefloc ] = 4 ;
while ( true )
{ if (gchrc > 0) {
auxnamelength = 0 ;
while ( gchrc > 0 )
{ if ( ( auxnamelength == 100 ) )
{ gchrc = 0 ;
{ tputs ( stdout , "file name---" ) ;
nameptr = 1 ;
while ( ( nameptr <= auxnamelength ) )
{ fputc ( nameoffile [ nameptr ] , stdout ) ;
incr ( nameptr ) ;
}
tputs ( stdout , "---is too long\n" ) ;
goto lab46 ;
}
}
incr ( auxnamelength ) ;
nameoffile [ auxnamelength ] = * gargv ++ ;
gchrc -- ;
}
} else {
tputs ( stdout , "Please type input file name (no extension)--" ) ;
auxnamelength = 0 ;
c = getc ( stdin ) ;
while ( ( c != 10 && ! feof ( stdin ) ) )
{ if ( ( auxnamelength == 100 ) )
{ while ( ( c != 10 ) ) c = getc ( stdin ) ;
{ tputs ( stdout , "file name---" ) ;
nameptr = 1 ;
while ( ( nameptr <= auxnamelength ) )
{ fputc ( nameoffile [ nameptr ] , stdout ) ;
incr ( nameptr ) ;
}
tputs ( stdout , "---is too long\n" ) ;
goto lab46 ;
}
}
incr ( auxnamelength ) ;
nameoffile [ auxnamelength ] = c ;
c = getc ( stdin ) ;
} }
if ( ( ( auxnamelength + ( strstart [ sauxextension + 1 ] -
strstart [ sauxextension ] ) > 100 ) || ( auxnamelength + ( strstart
[ slogextension + 1 ] - strstart [ slogextension ] ) > 100 ) || (
auxnamelength + ( strstart [ sbblextension + 1 ] - strstart [
sbblextension ] ) > 100 ) ) )
{ tputs ( stdout , "file name---" ) ;
nameptr = 1 ;
while ( ( nameptr <= auxnamelength ) )
{ fputc ( nameoffile [ nameptr ] , stdout ) ;
incr ( nameptr ) ;
}
tputs ( stdout , "---is too long\n" ) ;
goto lab46 ;
}
namelength = auxnamelength ;
addextension ( sauxextension ) ;
auxptr = 0 ;
if ( ( ! aopenin ( auxfile [ auxptr ] , "." ) ) )
{ tputs ( stdout , "I couldn't open file name---" ) ;
nameptr = 1 ;
while ( ( nameptr <= namelength ) )
{ fputc ( nameoffile [ nameptr ] , stdout ) ;
incr ( nameptr ) ;
}
tputc ( stdout , 10 ) ;
goto lab46 ;
}
namelength = auxnamelength ;
addextension ( slogextension ) ;
if ( ( ! aopenout ( logfile ) ) )
{ tputs ( stdout , "I couldn't open file name---" ) ;
nameptr = 1 ;
while ( ( nameptr <= namelength ) )
{ fputc ( nameoffile [ nameptr ] , stdout ) ;
incr ( nameptr ) ;
}
tputc ( stdout , 10 ) ;
goto lab46 ;
}
namelength = auxnamelength ;
addextension ( sbblextension ) ;
if ( ( ! aopenout ( bblfile ) ) )
{ tputs ( stdout , "I couldn't open file name---" ) ;
nameptr = 1 ;
while ( ( nameptr <= namelength ) )
{ fputc ( nameoffile [ nameptr ] , stdout ) ;
incr ( nameptr ) ;
}
tputc ( stdout , 10 ) ;
goto lab46 ;
}
namelength = auxnamelength ;
addextension ( sauxextension ) ;
nameptr = 1 ;
while ( ( nameptr <= namelength ) )
{ buffer [ nameptr ] = xord [ nameoffile [ nameptr ] ] ;
incr ( nameptr ) ;
}
lowercase ( buffer , 1 , namelength ) ;
toplevstr = hashtext [ strlookup ( buffer , 1 , auxnamelength , 0 ,
true ) ] ;
auxlist [ auxptr ] = hashtext [ strlookup ( buffer , 1 , namelength ,
3 , true ) ] ;
if ( ( hashfound ) )
{ tputs ( cnull , "already encountered auxiliary file " ) ;
printauxname () ;
{ tputs ( cnull , "---this can't happen\n" ) ;
jumpout ( 1 ) ;
}
}
auxlnstack [ auxptr ] = 0 ;
goto lab41 ;
lab46 : ;
}
lab41 : ;
}
main ( argc , argv )
int argc ;
char *argv[] ;
{
if (argc > 1) {
gargv = argv[1] ;
gchrc = strlen(gargv) ;
}
initialize () ;
tputs ( cnull , "This is BibTeX, C Version 0.98i\n" ) ;
tputs ( cnull , "The top-level auxiliary file: " ) ;
printauxname () ;
while ( true )
{ incr ( auxlnstack [ auxptr ] ) ;
if ( ( ! inputln ( auxfile [ auxptr ] ) ) ) {
if ( poptheauxstack () )
goto lab31 ;
}
else getauxcommandandproc () ;
}
lab31 :
#ifdef TRACE
tputs ( logfile , "finished reading the auxiliary file(s)\n" ) ;
#endif
lastcheckforauxerror () ;
if ( ( bststr == 0 ) ) goto lab9932 ;
bstlinenum = 0 ;
bbllinenum = 1 ;
bufptr2 = last ;
while ( true )
{ if ( ( ! eatbstwhitespace () ) ) goto lab32 ;
getbstcommandandproc () ;
}
lab32 : aclose ( bstfile ) ;
lab9932 : aclose ( bblfile ) ;
jumpout ( 1 ) ;
}
---cut here---