Cleaned up use of substring$
[latex-mlastyle.git] / mlastyle.bst
1 % BibTeX bibliography style `mlastyle'
2 % Based on BibTeX standard bibliography style `plain'
3         % version 0.99a for BibTeX versions 0.99a or later, LaTeX version 2.09.
4         % Copyright (C) 1985, all rights reserved.
5         % Copying of this file is authorized only if either
6         % (1) you make absolutely no changes to your copy, including name, or
7         % (2) if you do make changes, you name it something other than
8         % btxbst.doc, plain.bst, unsrt.bst, alpha.bst, and abbrv.bst.
9         % This restriction helps ensure that all standard styles are identical.
10         % The file btxbst.doc has the documentation for this style.
11
12 ENTRY
13   { address
14     author
15     booktitle
16     chapter
17     edition
18     editor
19     howpublished
20     institution
21     journal
22     key
23     month
24     note
25     number
26     organization
27     pages
28     publisher
29     school
30     series
31     title
32     type
33     volume
34     year
35     % New fields
36     url
37     accessdate
38     urlpath
39     version
40   }
41   { author.duplicate author.shared }
42   { label }
43
44 INTEGERS { output.state before.all mid.sentence after.sentence after.block after.title author.different author.last author.flast citealp.used url.used }
45
46 STRINGS { s t u empty.title }
47
48 % Rearranged such that true values require capital letters
49 FUNCTION {init.consts}
50 { #-1 'after.title :=
51   #0 'mid.sentence :=
52   #1 'before.all :=
53   #2 'after.sentence :=
54   #3 'after.block :=
55
56   #0 'author.different :=
57   #1 'author.last :=
58   #2 'author.flast :=
59   %#3 'author.firstlast :=
60
61   #0 'citealp.used :=
62   #0 'url.used :=
63   " \ \ \ \ \unskip\unskip\unskip\unskip\unskip " 'empty.title :=
64 }
65
66 FUNCTION {not}
67 {   { #0 }
68     { #1 }
69   if$
70 }
71
72 FUNCTION {and}
73 {   'skip$
74     { pop$ #0 }
75   if$
76 }
77
78 FUNCTION {or}
79 {   { pop$ #1 }
80     'skip$
81   if$
82 }
83
84 INTEGERS {chars i j}
85
86 % text.length$ does not include braces
87 % ...this is probably unnecessary
88 FUNCTION {num.chars}
89 {
90   #0 'chars :=
91     { duplicate$ duplicate$ #1 chars substring$ = not }
92     { duplicate$ duplicate$ text.length$ swap$ #1 chars
93     substring$ text.length$ - chars + #1 + 'chars := }
94   while$
95     { duplicate$ duplicate$ #1 chars #1 - substring$ = }
96     { chars #1 - 'chars := }
97   while$
98   pop$ chars
99 }
100
101 % Puts the period inside any quotes
102 FUNCTION {do.period}
103 {
104   duplicate$ #-1 #2 substring$ "''" =
105     { #2 'i :=
106         { duplicate$ #-1 i - #11 substring$ "'\thinspace" = }
107         { i #11 + 'i := }
108       while$
109       duplicate$ #-1 i - global.max$ substring$
110       add.period$ swap$ #-1 i substring$ *
111     }
112     {
113       duplicate$ #-1 #3 substring$ "''}" =
114         { #3 'i :=
115             { duplicate$ #-1 i - #11 substring$ "'\thinspace" = }
116             { i #11 + 'i := }
117           while$
118           duplicate$ #-1 i - global.max$ substring$
119           add.period$ swap$ #-1 i substring$ *
120         }
121         { add.period$ }
122       if$
123     }
124   if$
125 }
126
127 % Switched to do.period and added after.title
128 FUNCTION {output.nonnull}
129 { 's :=
130   output.state mid.sentence =
131     { ", " * write$ }
132     { output.state after.block =
133         { do.period write$
134           newline$
135           "\newblock " write$
136         }
137         { output.state before.all =
138             'write$
139             { output.state after.title =
140                 { " " * write$ }
141                 { do.period " " * write$ }
142               if$
143             }
144           if$
145         }
146       if$
147       mid.sentence 'output.state :=
148     }
149   if$
150   s
151 }
152
153 FUNCTION {output}
154 { duplicate$ empty$
155     'pop$
156     'output.nonnull
157   if$
158 }
159
160 FUNCTION {output.check}
161 { 't :=
162   duplicate$ empty$
163     { pop$ "empty " t * " in " * cite$ * warning$ }
164     'output.nonnull
165   if$
166 }
167
168 % Switched to do.period
169 FUNCTION {fin.entry}
170 { do.period
171   write$
172   newline$
173 }
174
175 FUNCTION {new.block}
176 { output.state before.all =
177     'skip$
178     { after.block 'output.state := }
179   if$
180 }
181
182 FUNCTION {new.sentence}
183 { output.state after.block =
184     'skip$
185     { output.state before.all =
186         'skip$
187         { after.sentence 'output.state := }
188       if$
189     }
190   if$
191 }
192
193 %FUNCTION {no.comma}
194 %{ output.state after.block =
195 %    'skip$
196 %    { output.state before.all =
197 %       'skip$
198 %       { after.title 'output.state := }
199 %      if$
200 %    }
201 %  if$
202 %}
203
204 FUNCTION {new.block.checka}
205 { empty$
206     'skip$
207     'new.block
208   if$
209 }
210
211 FUNCTION {new.block.checkb}
212 { empty$
213   swap$ empty$
214   and
215     'skip$
216     'new.block
217   if$
218 }
219
220 FUNCTION {new.sentence.checka}
221 { empty$
222     'skip$
223     'new.sentence
224   if$
225 }
226
227 FUNCTION {new.sentence.checkb}
228 { empty$
229   swap$ empty$
230   and
231     'skip$
232     'new.sentence
233   if$
234 }
235
236 FUNCTION {field.or.null}
237 { duplicate$ empty$
238     { pop$ "" }
239     'skip$
240   if$
241 }
242
243 FUNCTION {emphasize}
244 { duplicate$ empty$
245     { pop$ "" }
246     { "\emph{" swap$ * "}" * }
247   if$
248 }
249
250 FUNCTION {enquote}
251 { duplicate$ empty$
252     { pop$ "" }
253     {
254       #1 'i :=
255       #0 'j :=
256         { duplicate$ i #1 substring$ "" = not }
257         { duplicate$ i #1 substring$ quote$ =
258             { duplicate$ #1 i #1 - substring$ swap$
259               i #1 + global.max$ substring$
260               j
261                 { swap$ duplicate$ #-1 #1 substring$ "'" =
262                     { swap$ "\thinspace'" }
263                     { swap$ "'" }
264                   if$
265                    #0 'j :=
266                 }
267                 { duplicate$ #1 #1 substring$ "`" =
268                     { "`\thinspace" }
269                     { "`" }
270                   if$
271                 #1 'j :=
272                 }
273               if$
274               swap$ * *
275             }
276             'skip$
277           if$
278           i #1 + 'i :=
279         }
280       while$
281       duplicate$ #1 #1 substring$ "`" =
282         { "``\thinspace" swap$ * }
283         { "``" swap$ *}
284       if$
285       duplicate$ #-1 #1 substring$ "'" =
286         { "\thinspace''" * }
287         { "''" *}
288       if$
289     }
290   if$
291 }
292
293 INTEGERS { nameptr namesleft numnames }
294
295 FUNCTION {format.names.custom}
296 { 'u :=
297   's :=
298   #1 'nameptr :=
299   s num.names$ 'numnames :=
300   numnames 'namesleft :=
301     { namesleft #0 > }
302     { s nameptr u format.name$ 't :=
303       nameptr #1 >
304         { namesleft #1 >
305             { ", " * t * }
306             { numnames #2 >
307                 { "," * }
308                 'skip$
309               if$
310               t "others" =
311                 { " et~al." * }
312                 { " and " * t * }
313               if$
314             }
315           if$
316         }
317         't
318       if$
319       nameptr #1 + 'nameptr :=
320       namesleft #1 - 'namesleft :=
321     }
322   while$
323 }
324
325 FUNCTION {format.names}
326 { "{ff~}{vv~}{ll}{, jj}" format.names.custom }
327
328 % Changed first author to last name first
329 FUNCTION {format.names.beginning}
330 { 's :=
331   #1 'nameptr :=
332   s num.names$ 'numnames :=
333   numnames 'namesleft :=
334     { namesleft #0 > }
335     { nameptr #1 =
336         { s nameptr "{vv~}{ll}{, ff}{, jj}" format.name$
337           duplicate$ #1 #1 substring$ "u" change.case$ swap$
338           #2 global.max$ substring$ * 't := }
339         { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't := }
340       if$
341       nameptr #1 >
342         { namesleft #1 >
343             { ", " * t * }
344             { numnames #2 >
345                 { "," * }
346                 'skip$
347               if$
348               t "others" =
349                 { " et~al." * }
350                 { " and " * t * }
351               if$
352             }
353           if$
354         }
355         't
356       if$
357       nameptr #1 + 'nameptr :=
358       namesleft #1 - 'namesleft :=
359     }
360   while$
361 }
362
363 % Added check for duplicate authors
364 FUNCTION {format.authors}
365 { author empty$
366     { "" }
367     { author.duplicate #1 =
368         { "-{}-{}-" }
369         { author format.names.beginning }
370       if$
371     }
372   if$
373 }
374
375 % Changed to MLA editor abbreviations
376 % author.duplicate also applies
377 FUNCTION {format.editors}
378 { editor empty$
379     { "" }
380     { author empty$ author.duplicate #1 = and
381         { "-{}-{}-" }
382         { editor format.names.beginning }
383       if$
384       editor num.names$ #1 >
385         { ", eds." * }
386         { ", ed." * }
387       if$
388     }
389   if$
390 }
391
392 FUNCTION {format.editors.mid}
393 { editor empty$
394     { "" }
395     {
396       editor num.names$ #1 >
397         { "Eds.\ " }
398         { "Ed.\ " }
399       if$
400       editor format.names *
401     }
402   if$
403 }
404
405 % Formats the address and publisher
406 FUNCTION {format.publisher}
407 { address empty$
408     { publisher }
409     { address ": " * publisher * }
410   if$
411 }
412
413 % Changed to preserve case and use quotes
414 FUNCTION {format.title}
415 { title enquote
416 }
417
418 FUNCTION {n.dashify}
419 { 't :=
420   ""
421     { t empty$ not }
422     { t #1 #1 substring$ "-" =
423         { t #1 #2 substring$ "--" = not
424             { "--" *
425               t #2 global.max$ substring$ 't :=
426             }
427             {   { t #1 #1 substring$ "-" = }
428                 { "-" *
429                   t #2 global.max$ substring$ 't :=
430                 }
431               while$
432             }
433           if$
434         }
435         { t #1 #1 substring$ *
436           t #2 global.max$ substring$ 't :=
437         }
438       if$
439     }
440   while$
441 }
442
443 FUNCTION {format.date}
444 { year empty$
445     { month empty$
446         { "" }
447         { "there's a month but no year in " cite$ * warning$
448           month
449         }
450       if$
451     }
452     { month empty$
453         'year
454         { month "~" * year * }
455       if$
456     }
457   if$
458 }
459
460 INTEGERS {xx}
461 FUNCTION {format.btitle}
462 { title emphasize
463   %title num.chars int.to.str$ top$
464   %#0 'xx :=
465   %{ xx title num.chars < }
466   %{ title xx #1 + duplicate$ 'xx := #1 substring$ top$ } while$
467 }
468
469 FUNCTION {tie.or.space.connect}
470 { duplicate$ text.length$ #3 <
471     { "~" }
472     { "\ " }
473   if$
474   swap$ * *
475 }
476
477 FUNCTION {either.or.check}
478 { empty$
479     'pop$
480     { "can't use both " swap$ * " fields in " * cite$ * warning$ }
481   if$
482 }
483
484 FUNCTION {format.bvolume.or.num.series}
485 { volume empty$
486     { number empty$
487         { series field.or.null }
488         { 
489           series empty$
490             { number "there's a number but no series in " cite$ * warning$ }
491             { series
492           %output.state mid.sentence =
493             %{ " Sers." * }
494             %{ "Sers." * }
495           %if$
496           number tie.or.space.connect
497           }
498           if$
499         }
500       if$
501     }
502     { "Vol." volume tie.or.space.connect
503       series empty$
504         'skip$
505         { " of " * series emphasize * add.period$ }
506       if$
507       number empty$
508         'skip$
509         { number * " vols." * }
510       if$
511       %"volume and number" number either.or.check
512     }
513   if$
514 }
515
516 FUNCTION {format.number.series}
517 { volume empty$
518     { "" }
519     { "" }
520   if$
521 }
522
523 % Changed edition to MLA abbreviation
524 FUNCTION {format.edition}
525 { edition empty$
526     { version empty$
527         { "" }
528         { "Vers.~" version *}
529       if$
530     }
531     { edition "l" change.case$ 's := edition 't :=
532       ""
533       "10th" "tenth" "9th" "ninth" "8th" "eighth" "7th" "seventh" "6th" "sixth"
534       "5th" "fifth" "4th" "fourth" "3rd" "third" "2nd" "second" "1st" "first"
535       {duplicate$ empty$ { pop$ #0 }{ #1 } if$ }{ s = { 't := }{ pop$ } if$ }
536       while$
537       t " ed." *
538       "edition and version" version either.or.check
539     }
540   if$
541 }
542
543 INTEGERS { multiresult }
544
545 FUNCTION {multi.page.check}
546 { 't :=
547   #0 'multiresult :=
548     { multiresult not
549       t empty$ not
550       and
551     }
552     { t #1 #1 substring$
553       duplicate$ "-" =
554       swap$ duplicate$ "," =
555       swap$ "+" =
556       or or
557         { #1 'multiresult := }
558         { t #2 global.max$ substring$ 't := }
559       if$
560     }
561   while$
562   multiresult
563 }
564
565 FUNCTION {format.pages}
566 { pages empty$
567     { "" }
568     { %pages multi.page.check
569 %       { "pages" pages n.dashify tie.or.space.connect }
570 %       { "page" pages tie.or.space.connect }
571 %      if$
572     pages n.dashify
573     }
574   if$
575 }
576
577 FUNCTION {format.vol.num.year.pages}
578 { volume empty$
579     { number empty$
580         'skip$
581         { "there's a number but no volume in " cite$ * warning$ }
582       if$
583       format.date
584     }
585     { volume
586       number empty$
587         'skip$
588         { "." * number * }
589       if$
590       " (" * format.date * ")" *
591     }
592   if$
593   edition empty$
594     'skip$
595     { ", " * format.edition * }
596   if$
597   pages empty$
598     'skip$
599     { ": " * pages n.dashify * }
600   if$
601 }
602
603
604 FUNCTION {format.vol.num.pages}
605 { volume field.or.null
606   number empty$
607     'skip$
608     { "(" number * ")" * *
609       volume empty$
610         { "there's a number but no volume in " cite$ * warning$ }
611         'skip$
612       if$
613     }
614   if$
615   pages empty$
616     'skip$
617     { duplicate$ empty$
618         { pop$ format.pages }
619         { ":" * pages n.dashify * }
620       if$
621     }
622   if$
623 }
624
625 % chapter might be useful if type is set to "pars."
626 FUNCTION {format.chapter.pages}
627 { chapter empty$
628     'format.pages
629     { type empty$
630         { "Chapter" }
631         { type "t" change.case$ }
632       if$
633       chapter n.dashify tie.or.space.connect
634       pages empty$
635         'skip$
636         { ", " * format.pages * }
637       if$
638     }
639   if$
640 }
641
642 FUNCTION {format.in.ed.booktitle}
643 { booktitle empty$
644     { "" }
645     { editor empty$
646         { "In " booktitle emphasize * }
647         { booktitle emphasize add.period$ format.editors.mid * }
648       if$
649     }
650   if$
651 }
652
653 FUNCTION {empty.misc.check}
654 { author empty$ title empty$ howpublished empty$
655   month empty$ year empty$ note empty$
656   and and and and and
657   key empty$ not and
658     { "all relevant fields are empty in " cite$ * warning$ }
659     'skip$
660   if$
661 }
662
663 FUNCTION {format.thesis.type}
664 { type empty$
665     'skip$
666     { pop$
667       type "t" change.case$
668     }
669   if$
670 }
671
672 FUNCTION {format.tr.number}
673 { type empty$
674     { "Technical Report" }
675     'type
676   if$
677   number empty$
678     { "t" change.case$ }
679     { number tie.or.space.connect }
680   if$
681 }
682
683 FUNCTION {format.url}
684 { url empty$
685     { "" }
686     { accessdate empty$
687         { "There's a url but no accessdate in " cite$ * warning$ "" }
688         { accessdate " " * }
689       if$
690       "$<$\url{" * url * "}$>$" *
691       urlpath empty$
692         'skip$
693         { do.period " Path: " * urlpath * }
694       if$
695     }
696   if$
697 }
698
699 FUNCTION {format.article.crossref}
700 { %key empty$
701     %{ journal empty$
702         %{ "need key or journal for " cite$ * " to crossref " * crossref *
703         %  warning$
704         %  ""
705         %}
706         %{ "In {\em " journal * "\/}" * }
707       %if$
708     %}
709     %{ "In " key * }
710   %if$
711   pages empty$ { "\citealp" } { "\citealp[" format.chapter.pages * "]" * } if$
712   "{" * crossref * "}" *
713 }
714
715 FUNCTION {format.crossref.editor}
716 { editor #1 "{vv~}{ll}" format.name$
717   editor num.names$ duplicate$
718   #2 >
719     { pop$ " et~al." * }
720     { #2 <
721         'skip$
722         { editor #2 "{ff }{vv }{ll}{, jj}" format.name$ "others" =
723             { " et~al." * }
724             { " and " * editor #2 "{vv~}{ll}" format.name$ * }
725           if$
726         }
727       if$
728     }
729   if$
730 }
731
732 FUNCTION {format.book.crossref}
733 {% volume empty$
734 %    { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
735 %      "In "
736 %    }
737 %    { "Vol." volume tie.or.space.connect add.period$
738 %    }
739 %  if$
740 %  editor empty$
741 %  editor field.or.null author field.or.null =
742 %  or
743 %    { key empty$
744 %       { series empty$
745             %{ "need editor, key, or series for " cite$ * " to crossref " *
746             %  crossref * warning$
747             %  "" *
748             %}
749             %{ "{\em " * series * "\/}" * }
750           %if$
751 %       }
752 %       { key * }
753 %      if$
754 %    }
755 %    { format.crossref.editor * }
756 %  if$
757   pages empty$ { "\citealp" } { "\citealp[" format.chapter.pages * "]" * } if$
758   "{" * crossref * "}" *
759 }
760
761 FUNCTION {format.incoll.inproc.crossref}
762 {% editor empty$
763 %  editor field.or.null author field.or.null =
764 %  or
765 %    { key empty$
766 %       { booktitle empty$
767 %           { "need editor, key, or booktitle for " cite$ * " to crossref " *
768 %             crossref * warning$
769 %             ""
770 %           }
771 %           { "In {\em " booktitle * "\/}" * }
772 %         if$
773 %       }
774 %       { "In " key * }
775 %      if$
776 %    }
777 %    { "In " format.crossref.editor * }
778 %  if$
779   pages empty$ { "\citealp" } { "\citealp[" format.chapter.pages * "]" * } if$
780   "{" * crossref * "}" *
781 }
782
783 FUNCTION {cite.title}
784 { title empty$ journal empty$ not and
785     { key empty$ { journal }{ key } if$ emphasize }
786     { title empty$ key empty$ and
787         { "empty title and key in " cite$ * warning$ "" }
788         { key empty$ {title}{key} if$
789           type$ "book" =
790           type$ "inbook" =
791           type$ "manual" =
792           type$ "phdthesis" =
793           type$ "proceedings" =
794           or or or or
795             { emphasize }
796             { type$ "article" =
797               %type$ "booklet" =
798               type$ "incollection" =
799               type$ "inproceedings" =
800               type$ "mastersthesis" =
801               type$ "misc" =
802               type$ "techreport" =
803               type$ "unpublished" =
804               or or or or or or
805                 { enquote }
806                 {}
807               if$
808             }
809           if$
810         }
811       if$
812     }
813   if$
814 }
815
816 FUNCTION {cite.label}
817 {
818   %author empty$
819   %  { editor empty$ { organization field.or.null 'a := }{ editor 'a :=} if$}
820   %  { author 'a := }
821   %if$
822   %abbr empty$ {
823   author empty$
824     { editor empty$
825         { "" }
826         { editor }
827       if$
828     }
829     { author }
830   if$
831   duplicate$ empty$
832     { cite.title *
833     "(" * empty.title * ")" * }
834     { duplicate$
835       author.shared author.different =
836         { "{vv~}{ll}" format.names.custom 's := }
837         { author.shared author.last =
838             { "{f.~}{vv~}{ll}{, jj}" format.names.custom 's := }
839             { author.shared author.flast =
840                 { "{ff~}{vv~}{ll}{, jj}" format.names.custom 's := }
841                 { "{vv~}{ll}" format.names.custom ", " * cite.title * 's := "WTF" warning$ }
842               if$
843             }
844           if$
845         }
846       if$
847       s
848       "(" * empty.title *
849       author.duplicate { cite.title * }{} if$
850       ")" * swap$ "{ff~}{vv~}{ll}{, jj}" format.names.custom *
851     }
852   if$
853       %}
854       %if$
855     %}
856     %{}% abbr }
857  % if$
858 }
859
860 % TODO
861 FUNCTION {output.bibitem}
862 { newline$
863   "\bibitem[" write$
864   cite.label write$
865   "]{" write$
866   cite$ write$
867   "}" write$
868   newline$
869   ""
870   before.all 'output.state :=
871 }
872
873 FUNCTION {article}
874 { output.bibitem
875   format.authors "author" output.check
876   new.block
877   format.title "title" output.check
878   new.block
879   crossref missing$
880     { journal emphasize "journal" output.check after.title 'output.state :=
881       address empty$ skip$ { "[" address * "]" * output } if$
882       %format.date "year" output.check
883       %edition output
884       format.vol.num.year.pages output
885     }
886     { format.article.crossref output.nonnull
887       %format.pages output
888     }
889   if$
890   new.block
891   format.url output
892   new.block
893   note output
894   fin.entry
895 }
896
897 FUNCTION {book}
898 { output.bibitem
899   author empty$
900     { format.editors "author and editor" output.check }
901     { format.authors output.nonnull }
902   if$
903   new.block
904   format.btitle "title" output.check
905   new.block
906   crossref missing$
907     { author empty$ 'skip$ { format.editors.mid output new.block } if$
908       format.edition output
909       new.sentence
910       format.bvolume.or.num.series output
911       new.block
912       format.publisher "publisher" output.check
913       format.date "year" output.check
914     }
915     {% format.date "year" output
916       new.block
917       format.book.crossref output.nonnull
918     }
919   if$
920   new.block
921   format.url output
922   new.block
923   note output
924   fin.entry
925 }
926
927 FUNCTION {booklet}
928 { output.bibitem
929   format.authors output
930   new.block
931   format.title "title" output.check
932   howpublished address new.block.checkb
933   howpublished output
934   address output
935   format.date output
936   new.block
937   note output
938   fin.entry
939 }
940
941 FUNCTION {inbook}
942 { output.bibitem
943   author empty$
944     { format.editors "author and editor" output.check }
945     { format.authors output.nonnull }
946   if$
947   new.block
948   format.btitle "title" output.check
949   new.block
950   crossref missing$
951     { author empty$ 'skip$ { format.editors.mid output new.block } if$
952       format.edition output
953       new.sentence
954       format.bvolume.or.num.series output
955       new.block
956       format.publisher "publisher" output.check
957       format.date "year" output.check
958       new.sentence
959       format.chapter.pages "chapter and pages" output.check
960       %address output
961     }
962     {% format.chapter.pages "chapter and pages" output.check
963       new.block
964       format.book.crossref output.nonnull
965     }
966   if$
967   new.block
968   format.url output
969   note output
970   fin.entry
971 }
972
973 FUNCTION {incollection}
974 { output.bibitem
975   format.authors "author" output.check
976   chapter empty$
977     { new.block type output }
978     {}
979   if$
980   new.block
981   format.title "title" output.check
982   new.block
983   crossref missing$
984     { 
985       booktitle emphasize "booktitle" output.check
986       new.block
987       format.editors.mid "editor" output.check
988       new.block
989       format.edition output
990       new.sentence
991       format.bvolume.or.num.series output
992       new.block
993       format.publisher "publisher" output.check
994       %address output
995       format.date "year" output.check
996       new.sentence
997       format.chapter.pages output
998     }
999     { format.incoll.inproc.crossref output.nonnull
1000       %format.chapter.pages output
1001     }
1002   if$
1003   new.block
1004   format.url output
1005   new.block
1006   note output
1007   fin.entry
1008 }
1009
1010 FUNCTION {inproceedings}
1011 { output.bibitem
1012   format.authors "author" output.check
1013   new.block
1014   format.title "title" output.check
1015   new.block
1016   crossref missing$
1017     { %format.in.ed.booktitle "booktitle" output.check
1018       booktitle "booktitle" output.check
1019       new.sentence
1020       format.editors.mid output
1021       new.block
1022       format.edition output
1023       new.sentence
1024       format.bvolume.or.num.series output
1025       new.block
1026       format.edition output
1027       new.sentence
1028       format.publisher output
1029       format.date "year" output.check
1030       %address empty$
1031         %{ organization publisher new.sentence.checkb
1032          % organization output
1033          % publisher output
1034          % format.date "year" output.check
1035         %}
1036         %{ address output.nonnull
1037          % format.date "year" output.check
1038          % new.sentence
1039          % organization output
1040          % publisher output
1041         %}
1042       %if$
1043       new.sentence
1044       format.pages output
1045     }
1046     { format.incoll.inproc.crossref output.nonnull
1047       %format.pages output
1048     }
1049   if$
1050   new.block
1051   format.url output
1052   new.block
1053   note output
1054   fin.entry
1055 }
1056
1057 FUNCTION {conference} { inproceedings }
1058
1059 FUNCTION {manual}
1060 { output.bibitem
1061   author empty$
1062     { organization empty$
1063         'skip$
1064         { organization output.nonnull
1065           address output
1066         }
1067       if$
1068     }
1069     { format.authors output.nonnull }
1070   if$
1071   new.block
1072   format.btitle "title" output.check
1073   new.block
1074   format.edition output
1075   new.sentence
1076   author empty$
1077     { organization empty$
1078         { address new.block.checka
1079           address output
1080         }
1081         'skip$
1082       if$
1083     }
1084     { organization address new.block.checkb
1085       organization output
1086       address output
1087     }
1088   if$
1089   format.date output
1090   new.block
1091   format.url output
1092   new.block
1093   note output
1094   fin.entry
1095 }
1096
1097 FUNCTION {mastersthesis}
1098 { output.bibitem
1099   format.authors "author" output.check
1100   new.block
1101   format.title "title" output.check
1102   new.block
1103   "Diss." format.thesis.type do.period output.nonnull
1104   after.title 'output.state :=
1105   school "school" output.check
1106   address output
1107   format.date "year" output.check
1108   new.block
1109   format.url output
1110   new.block
1111   note output
1112   fin.entry
1113 }
1114
1115 FUNCTION {misc}
1116 { output.bibitem
1117   format.authors output
1118   title howpublished new.block.checkb
1119   format.title output
1120   new.block
1121   %howpublished new.block.checka
1122   howpublished output
1123   format.date output
1124   new.block
1125   format.url output
1126   new.block
1127   note output
1128   fin.entry
1129   empty.misc.check
1130 }
1131
1132 FUNCTION {phdthesis}
1133 { output.bibitem
1134   format.authors "author" output.check
1135   new.block
1136   format.btitle "title" output.check
1137   new.block
1138   "Diss." format.thesis.type do.period output.nonnull
1139   after.title 'output.state :=
1140   school "school" output.check
1141   address output
1142   format.date "year" output.check
1143   new.block
1144   format.url output
1145   new.block
1146   note output
1147   fin.entry
1148 }
1149
1150 FUNCTION {proceedings}
1151 { output.bibitem
1152   editor empty$
1153     { organization output }
1154     { format.editors output.nonnull }
1155   if$
1156   new.block
1157   format.btitle "title" output.check
1158   new.sentence
1159   format.bvolume.or.num.series output
1160   address empty$
1161     { editor empty$
1162         { publisher new.sentence.checka }
1163         { organization publisher new.sentence.checkb
1164           organization output
1165         }
1166       if$
1167       publisher output
1168       format.date "year" output.check
1169     }
1170     { address output.nonnull
1171       format.date "year" output.check
1172       new.sentence
1173       editor empty$
1174         'skip$
1175         { organization output }
1176       if$
1177       publisher output
1178     }
1179   if$
1180   new.block
1181   format.url output
1182   new.block
1183   note output
1184   fin.entry
1185 }
1186
1187 FUNCTION {techreport}
1188 { output.bibitem
1189   format.authors "author" output.check
1190   new.block
1191   format.title "title" output.check
1192   new.block
1193   format.tr.number output.nonnull
1194   institution "institution" output.check
1195   address output
1196   format.date "year" output.check
1197   new.block
1198   note output
1199   fin.entry
1200 }
1201
1202 FUNCTION {unpublished}
1203 { output.bibitem
1204   format.authors "author" output.check
1205   new.block
1206   format.title "title" output.check
1207   new.block
1208   format.url output
1209   new.block
1210   note "note" output.check
1211   format.date output
1212   fin.entry
1213 }
1214
1215 FUNCTION {default.type} { misc }
1216
1217 MACRO {jan} {"Jan."}
1218
1219 MACRO {feb} {"Feb."}
1220
1221 MACRO {mar} {"Mar."}
1222
1223 MACRO {apr} {"Apr."}
1224
1225 MACRO {may} {"May"}
1226
1227 MACRO {jun} {"June"}
1228
1229 MACRO {jul} {"July"}
1230
1231 MACRO {aug} {"Aug."}
1232
1233 MACRO {sep} {"Sept."}
1234
1235 MACRO {oct} {"Oct."}
1236
1237 MACRO {nov} {"Nov."}
1238
1239 MACRO {dec} {"Dec."}
1240
1241 MACRO {acmcs} {"ACM Computing Surveys"}
1242
1243 MACRO {acta} {"Acta Informatica"}
1244
1245 MACRO {cacm} {"Communications of the ACM"}
1246
1247 MACRO {ibmjrd} {"IBM Journal of Research and Development"}
1248
1249 MACRO {ibmsj} {"IBM Systems Journal"}
1250
1251 MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
1252
1253 MACRO {ieeetc} {"IEEE Transactions on Computers"}
1254
1255 MACRO {ieeetcad}
1256  {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
1257
1258 MACRO {ipl} {"Information Processing Letters"}
1259
1260 MACRO {jacm} {"Journal of the ACM"}
1261
1262 MACRO {jcss} {"Journal of Computer and System Sciences"}
1263
1264 MACRO {scp} {"Science of Computer Programming"}
1265
1266 MACRO {sicomp} {"SIAM Journal on Computing"}
1267
1268 MACRO {tocs} {"ACM Transactions on Computer Systems"}
1269
1270 MACRO {tods} {"ACM Transactions on Database Systems"}
1271
1272 MACRO {tog} {"ACM Transactions on Graphics"}
1273
1274 MACRO {toms} {"ACM Transactions on Mathematical Software"}
1275
1276 MACRO {toois} {"ACM Transactions on Office Information Systems"}
1277
1278 MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
1279
1280 MACRO {tcs} {"Theoretical Computer Science"}
1281
1282 READ
1283
1284 FUNCTION {sortify}
1285 { purify$
1286   "l" change.case$
1287 }
1288
1289 INTEGERS { len }
1290
1291 FUNCTION {chop.word}
1292 { 's :=
1293   'len :=
1294   s #1 len substring$ =
1295     { s len #1 + global.max$ substring$ }
1296     's
1297   if$
1298 }
1299
1300 FUNCTION {sort.format.names}
1301 { 's :=
1302   #1 'nameptr :=
1303   ""
1304   s num.names$ 'numnames :=
1305   numnames 'namesleft :=
1306     { namesleft #0 > }
1307     { nameptr #1 >
1308         { "   " * }
1309         'skip$
1310       if$
1311       s nameptr "{vv{ } }{ll{ }}{  ff{ }}{  jj{ }}" format.name$ 't :=
1312       nameptr numnames = t "others" = and
1313         { "et al" * }
1314         { t sortify * }
1315       if$
1316       nameptr #1 + 'nameptr :=
1317       namesleft #1 - 'namesleft :=
1318     }
1319   while$
1320 }
1321
1322 FUNCTION {sort.format.title}
1323 { 't :=
1324   "A " #2
1325     "An " #3
1326       "The " #4 t chop.word
1327     chop.word
1328   chop.word
1329   sortify
1330   #1 global.max$ substring$
1331 }
1332
1333 FUNCTION {author.sort}
1334 { author empty$
1335     { key empty$
1336         { "to sort, need author or key in " cite$ * warning$
1337           ""
1338         }
1339         { key sortify }
1340       if$
1341     }
1342     { author sort.format.names }
1343   if$
1344 }
1345
1346 FUNCTION {author.editor.sort}
1347 { author empty$
1348     { editor empty$
1349         { key empty$
1350             { "to sort, need author, editor, or key in " cite$ * warning$
1351               ""
1352             }
1353             { key sortify }
1354           if$
1355         }
1356         { editor sort.format.names }
1357       if$
1358     }
1359     { author sort.format.names }
1360   if$
1361 }
1362
1363 FUNCTION {author.organization.sort}
1364 { author empty$
1365     { organization empty$
1366         { key empty$
1367             { "to sort, need author, organization, or key in " cite$ * warning$
1368               ""
1369             }
1370             { key sortify }
1371           if$
1372         }
1373         { "The " #4 organization chop.word sortify }
1374       if$
1375     }
1376     { author sort.format.names }
1377   if$
1378 }
1379
1380 FUNCTION {editor.organization.sort}
1381 { editor empty$
1382     { organization empty$
1383         { key empty$
1384             { "to sort, need editor, organization, or key in " cite$ * warning$
1385               ""
1386             }
1387             { key sortify }
1388           if$
1389         }
1390         { "The " #4 organization chop.word sortify }
1391       if$
1392     }
1393     { editor sort.format.names }
1394   if$
1395 }
1396
1397 FUNCTION {presort}
1398 { type$ "book" =
1399   type$ "inbook" =
1400   or
1401     'author.editor.sort
1402     { type$ "proceedings" =
1403         'editor.organization.sort
1404         { type$ "manual" =
1405             'author.organization.sort
1406             'author.sort
1407           if$
1408         }
1409       if$
1410     }
1411   if$
1412   duplicate$ empty$ 'skip$ { "    " * } if$
1413   key empty$
1414     { title field.or.null sort.format.title * "    " * booktitle field.or.null sort.format.title * }
1415     { key sortify * }
1416   if$
1417   "    "
1418   *
1419   year field.or.null sortify
1420   *
1421   #1 entry.max$ substring$
1422   'sort.key$ :=
1423 }
1424
1425 ITERATE {presort}
1426
1427 SORT
1428
1429 STRINGS {a b}
1430
1431 FUNCTION {init.vars}
1432 { #0 int.to.chr$ 'a :=
1433   #0 int.to.chr$ 'b :=
1434   #0 'i :=
1435   #0 'j :=
1436 }
1437
1438 FUNCTION {forward.author.dup.check}
1439 {
1440   url empty$ 'skip$ { url.used #1 + 'url.used := } if$
1441   crossref empty$ 'skip$ { citealp.used #1 + 'citealp.used := } if$
1442   author empty$
1443     { editor empty$ { organization field.or.null 'a := }{ editor 'a :=} if$}
1444     { author 'a := }
1445   if$
1446   %'a :=
1447   a empty$
1448     'skip$
1449     { b "{ff~}{vv~}{ll}{, jj}" format.names.custom purify$
1450       a "{ff~}{vv~}{ll}{, jj}" format.names.custom purify$ =
1451         { #1 'author.duplicate := }
1452         { #0 'author.duplicate := }
1453       if$
1454       a 'b :=
1455     }
1456   if$
1457 }
1458
1459 FUNCTION {forward.author.share.check}
1460 %
1461 % Pass through all entries, comparing current author to last one.
1462 %
1463 { author.duplicate author empty$ or
1464   { author.duplicate { i 'author.shared := }{} if$}
1465   { b "{f.~}{vv~}{ll}{, jj}" format.names.custom purify$
1466     author field.or.null "{f.~}{vv~}{ll}{, jj}" format.names.custom purify$ =
1467     { author.flast 'author.shared := }
1468     { b "{vv~}{ll}" format.names.custom purify$
1469       author field.or.null "{vv~}{ll}" format.names.custom purify$ =
1470       { author.last 'author.shared := }
1471       { author.different 'author.shared := }
1472       if$
1473     }
1474     if$
1475     author.shared 'i :=
1476     author field.or.null 'b :=
1477   }
1478   if$
1479 }
1480
1481 FUNCTION {reverse.author}
1482
1483   author.duplicate
1484   { author.shared i <
1485       { i 'author.shared := }
1486       {}
1487     if$
1488   }
1489   { author.shared i <
1490       { author.shared i 'author.shared := 'i := }
1491       { author.shared 'i := }
1492     if$
1493   }
1494   if$
1495   j #1 = author.duplicate not and { #2 'author.duplicate := } {} if$
1496   author.duplicate 'j :=
1497 }
1498
1499 EXECUTE {init.consts}
1500
1501 EXECUTE {init.vars}
1502 ITERATE {forward.author.dup.check}
1503
1504 EXECUTE {init.vars}
1505 ITERATE {forward.author.share.check}
1506
1507 EXECUTE {init.vars}
1508 REVERSE {reverse.author}
1509
1510 %INTEGERS { number.label longest.label.width }
1511
1512 %FUNCTION {initialize.longest.label}
1513 %{ "" 'longest.label :=
1514 %  #1 'number.label :=
1515 %  #0 'longest.label.width :=
1516 %}
1517
1518 %FUNCTION {longest.label.pass}
1519 %{ number.label int.to.str$ 'label :=
1520 %  number.label #1 + 'number.label :=
1521 %  label width$ longest.label.width >
1522 %    { label 'longest.label :=
1523 %      label width$ 'longest.label.width :=
1524 %    }
1525 %    'skip$
1526 %  if$
1527 %}
1528
1529 %EXECUTE {initialize.longest.label}
1530
1531 %ITERATE {longest.label.pass}
1532
1533 FUNCTION {begin.bib}
1534 {
1535   citealp.used
1536     { "\expandafter\ifx\csname citealp\endcsname\relax\let\citealp\cite\fi"
1537       write$ newline$ }
1538     'skip$
1539   if$
1540   url.used
1541     { "\expandafter\ifx\csname citealp\endcsname\relax\url\let\url\relax\fi"
1542       write$ newline$ }
1543     'skip$
1544   if$
1545   preamble$ empty$
1546     'skip$
1547     { preamble$ write$ newline$ }
1548   if$
1549   "\begin{thebibliography}{\rule{.5in}{0pt}}" write$ newline$
1550 }
1551
1552 EXECUTE {begin.bib}
1553
1554 ITERATE {call.type$}
1555
1556 FUNCTION {end.bib}
1557 { newline$
1558   "\end{thebibliography}" write$ newline$
1559 }
1560
1561 EXECUTE {end.bib}