Merge remote-tracking branch 'upstream/master'
[ach-master.git] / src / alphalink.bst
1 % Derived from BibTeX standard bibliography style `alpha'
2 % version 0.99a for BibTeX versions 0.99a or later, LaTeX version 2.09.
3 % Copyright (C) 1985, all rights reserved.
4 % Copying of this file is authorized only if either
5 % (1) you make absolutely no changes to your copy, including name, or
6 % (2) if you do make changes, you name it something other than
7 % btxbst.doc, plain.bst, unsrt.bst, alpha.bst, and abbrv.bst.
8 % This restriction helps ensure that all standard styles are identical.
9 % The file btxbst.doc has the documentation for this style.
10
11 % Now recognize url field. If present produce a hyperref on the
12 % bibliography label with a link to url.
13
14 ENTRY
15   { address
16     author
17     booktitle
18     chapter
19     edition
20     editor
21     howpublished
22     institution
23     journal
24     key
25     month
26     note
27     number
28     organization
29     pages
30     publisher
31     school
32     series
33     title
34     type
35     url
36     volume
37     year
38   }
39   {}
40   { label extra.label sort.label }
41
42 INTEGERS { output.state before.all mid.sentence after.sentence after.block }
43
44 FUNCTION {init.state.consts}
45 { #0 'before.all :=
46   #1 'mid.sentence :=
47   #2 'after.sentence :=
48   #3 'after.block :=
49 }
50
51 STRINGS { s t }
52
53 FUNCTION {output.nonnull}
54 { 's :=
55   output.state mid.sentence =
56     { ", " * write$ }
57     { output.state after.block =
58         { add.period$ write$
59           newline$
60           "\newblock " write$
61         }
62         { output.state before.all =
63             'write$
64             { add.period$ " " * write$ }
65           if$
66         }
67       if$
68       mid.sentence 'output.state :=
69     }
70   if$
71   s
72 }
73 FUNCTION {output}
74 { duplicate$ empty$
75     'pop$
76     'output.nonnull
77   if$
78 }
79
80 FUNCTION {output.check}
81 { 't :=
82   duplicate$ empty$
83     { pop$ "empty " t * " in " * cite$ * warning$ }
84     'output.nonnull
85   if$
86 }
87
88 FUNCTION {output.bibitem}
89 { newline$
90   "\bibitem[" write$
91   url empty$
92       { label write$ }
93       { "\xbiblabel{" write$
94         url write$
95         "%" write$
96         newline$
97         "}{}{}{" write$
98         label write$
99         "}" write$
100       }
101   if$
102   "]{" write$
103   cite$ write$
104   "}" write$
105   newline$
106   ""
107   before.all 'output.state :=
108 }
109
110 FUNCTION {new.block}
111 { output.state before.all =
112     'skip$
113     { after.block 'output.state := }
114   if$
115 }
116
117 FUNCTION {output.url}
118 { url empty$
119     'skip$
120     { new.block
121       "\url{" write$
122       url write$
123       "}" write$
124       newline$
125     }
126   if$
127 }
128
129 FUNCTION {fin.entry}
130 { add.period$
131   write$
132   newline$
133   output.url
134 }
135
136 FUNCTION {new.sentence}
137 { output.state after.block =
138     'skip$
139     { output.state before.all =
140         'skip$
141         { after.sentence 'output.state := }
142       if$
143     }
144   if$
145 }
146
147 FUNCTION {not}
148 {   { #0 }
149     { #1 }
150   if$
151 }
152
153 FUNCTION {and}
154 {   'skip$
155     { pop$ #0 }
156   if$
157 }
158
159 FUNCTION {or}
160 {   { pop$ #1 }
161     'skip$
162   if$
163 }
164
165 FUNCTION {new.block.checka}
166 { empty$
167     'skip$
168     'new.block
169   if$
170 }
171
172 FUNCTION {new.block.checkb}
173 { empty$
174   swap$ empty$
175   and
176     'skip$
177     'new.block
178   if$
179 }
180
181 FUNCTION {new.sentence.checka}
182 { empty$
183     'skip$
184     'new.sentence
185   if$
186 }
187
188 FUNCTION {new.sentence.checkb}
189 { empty$
190   swap$ empty$
191   and
192     'skip$
193     'new.sentence
194   if$
195 }
196
197 FUNCTION {field.or.null}
198 { duplicate$ empty$
199     { pop$ "" }
200     'skip$
201   if$
202 }
203
204 FUNCTION {emphasize}
205 { duplicate$ empty$
206     { pop$ "" }
207     { "{\em " swap$ * "}" * }
208   if$
209 }
210
211 INTEGERS { nameptr namesleft numnames }
212
213 FUNCTION {format.names}
214 { 's :=
215   #1 'nameptr :=
216   s num.names$ 'numnames :=
217   numnames 'namesleft :=
218     { namesleft #0 > }
219     { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=
220       nameptr #1 >
221         { namesleft #1 >
222             { ", " * t * }
223             { numnames #2 >
224                 { "," * }
225                 'skip$
226               if$
227               t "others" =
228                 { " et~al." * }
229                 { " and " * t * }
230               if$
231             }
232           if$
233         }
234         't
235       if$
236       nameptr #1 + 'nameptr :=
237       namesleft #1 - 'namesleft :=
238     }
239   while$
240 }
241
242 FUNCTION {format.authors}
243 { author empty$
244     { "" }
245     { author format.names }
246   if$
247 }
248
249 FUNCTION {format.editors}
250 { editor empty$
251     { "" }
252     { editor format.names
253       editor num.names$ #1 >
254         { ", editors" * }
255         { ", editor" * }
256       if$
257     }
258   if$
259 }
260
261 FUNCTION {format.title}
262 { title empty$
263     { "" }
264     { title "t" change.case$ }
265   if$
266 }
267
268 FUNCTION {n.dashify}
269 { 't :=
270   ""
271     { t empty$ not }
272     { t #1 #1 substring$ "-" =
273         { t #1 #2 substring$ "--" = not
274             { "--" *
275               t #2 global.max$ substring$ 't :=
276             }
277             {   { t #1 #1 substring$ "-" = }
278                 { "-" *
279                   t #2 global.max$ substring$ 't :=
280                 }
281               while$
282             }
283           if$
284         }
285         { t #1 #1 substring$ *
286           t #2 global.max$ substring$ 't :=
287         }
288       if$
289     }
290   while$
291 }
292
293 FUNCTION {format.date}
294 { year empty$
295     { month empty$
296         { "" }
297         { "there's a month but no year in " cite$ * warning$
298           month
299         }
300       if$
301     }
302     { month empty$
303         'year
304         { month " " * year * }
305       if$
306     }
307   if$
308 }
309
310 FUNCTION {format.btitle}
311 { title emphasize
312 }
313
314 FUNCTION {tie.or.space.connect}
315 { duplicate$ text.length$ #3 <
316     { "~" }
317     { " " }
318   if$
319   swap$ * *
320 }
321
322 FUNCTION {either.or.check}
323 { empty$
324     'pop$
325     { "can't use both " swap$ * " fields in " * cite$ * warning$ }
326   if$
327 }
328
329 FUNCTION {format.bvolume}
330 { volume empty$
331     { "" }
332     { "volume" volume tie.or.space.connect
333       series empty$
334         'skip$
335         { " of " * series emphasize * }
336       if$
337       "volume and number" number either.or.check
338     }
339   if$
340 }
341
342 FUNCTION {format.number.series}
343 { volume empty$
344     { number empty$
345         { series field.or.null }
346         { output.state mid.sentence =
347             { "number" }
348             { "Number" }
349           if$
350           number tie.or.space.connect
351           series empty$
352             { "there's a number but no series in " cite$ * warning$ }
353             { " in " * series * }
354           if$
355         }
356       if$
357     }
358     { "" }
359   if$
360 }
361
362 FUNCTION {format.edition}
363 { edition empty$
364     { "" }
365     { output.state mid.sentence =
366         { edition "l" change.case$ " edition" * }
367         { edition "t" change.case$ " edition" * }
368       if$
369     }
370   if$
371 }
372
373 INTEGERS { multiresult }
374
375 FUNCTION {multi.page.check}
376 { 't :=
377   #0 'multiresult :=
378     { multiresult not
379       t empty$ not
380       and
381     }
382     { t #1 #1 substring$
383       duplicate$ "-" =
384       swap$ duplicate$ "," =
385       swap$ "+" =
386       or or
387         { #1 'multiresult := }
388         { t #2 global.max$ substring$ 't := }
389       if$
390     }
391   while$
392   multiresult
393 }
394
395 FUNCTION {format.pages}
396 { pages empty$
397     { "" }
398     { pages multi.page.check
399         { "pages" pages n.dashify tie.or.space.connect }
400         { "page" pages tie.or.space.connect }
401       if$
402     }
403   if$
404 }
405
406 FUNCTION {format.vol.num.pages}
407 { volume field.or.null
408   number empty$
409     'skip$
410     { "(" number * ")" * *
411       volume empty$
412         { "there's a number but no volume in " cite$ * warning$ }
413         'skip$
414       if$
415     }
416   if$
417   pages empty$
418     'skip$
419     { duplicate$ empty$
420         { pop$ format.pages }
421         { ":" * pages n.dashify * }
422       if$
423     }
424   if$
425 }
426
427 FUNCTION {format.chapter.pages}
428 { chapter empty$
429     'format.pages
430     { type empty$
431         { "chapter" }
432         { type "l" change.case$ }
433       if$
434       chapter tie.or.space.connect
435       pages empty$
436         'skip$
437         { ", " * format.pages * }
438       if$
439     }
440   if$
441 }
442
443 FUNCTION {format.in.ed.booktitle}
444 { booktitle empty$
445     { "" }
446     { editor empty$
447         { "In " booktitle emphasize * }
448         { "In " format.editors * ", " * booktitle emphasize * }
449       if$
450     }
451   if$
452 }
453
454 FUNCTION {empty.misc.check}
455 { author empty$ title empty$ howpublished empty$
456   month empty$ year empty$ note empty$
457   and and and and and
458   key empty$ not and
459     { "all relevant fields are empty in " cite$ * warning$ }
460     'skip$
461   if$
462 }
463
464 FUNCTION {format.thesis.type}
465 { type empty$
466     'skip$
467     { pop$
468       type "t" change.case$
469     }
470   if$
471 }
472
473 FUNCTION {format.tr.number}
474 { type empty$
475     { "Technical Report" }
476     'type
477   if$
478   number empty$
479     { "t" change.case$ }
480     { number tie.or.space.connect }
481   if$
482 }
483
484 FUNCTION {format.article.crossref}
485 { key empty$
486     { journal empty$
487         { "need key or journal for " cite$ * " to crossref " * crossref *
488           warning$
489           ""
490         }
491         { "In {\em " journal * "\/}" * }
492       if$
493     }
494     { "In " key * }
495   if$
496   " \cite{" * crossref * "}" *
497 }
498
499 FUNCTION {format.crossref.editor}
500 { editor #1 "{vv~}{ll}" format.name$
501   editor num.names$ duplicate$
502   #2 >
503     { pop$ " et~al." * }
504     { #2 <
505         'skip$
506         { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
507             { " et~al." * }
508             { " and " * editor #2 "{vv~}{ll}" format.name$ * }
509           if$
510         }
511       if$
512     }
513   if$
514 }
515
516 FUNCTION {format.book.crossref}
517 { volume empty$
518     { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
519       "In "
520     }
521     { "Volume" volume tie.or.space.connect
522       " of " *
523     }
524   if$
525   editor empty$
526   editor field.or.null author field.or.null =
527   or
528     { key empty$
529         { series empty$
530             { "need editor, key, or series for " cite$ * " to crossref " *
531               crossref * warning$
532               "" *
533             }
534             { "{\em " * series * "\/}" * }
535           if$
536         }
537         { key * }
538       if$
539     }
540     { format.crossref.editor * }
541   if$
542   " \cite{" * crossref * "}" *
543 }
544
545 FUNCTION {format.incoll.inproc.crossref}
546 { editor empty$
547   editor field.or.null author field.or.null =
548   or
549     { key empty$
550         { booktitle empty$
551             { "need editor, key, or booktitle for " cite$ * " to crossref " *
552               crossref * warning$
553               ""
554             }
555             { "In {\em " booktitle * "\/}" * }
556           if$
557         }
558         { "In " key * }
559       if$
560     }
561     { "In " format.crossref.editor * }
562   if$
563   " \cite{" * crossref * "}" *
564 }
565
566 FUNCTION {article}
567 { output.bibitem
568   format.authors "author" output.check
569   new.block
570   format.title "title" output.check
571   new.block
572   crossref missing$
573     { journal emphasize "journal" output.check
574       format.vol.num.pages output
575       format.date "year" output.check
576     }
577     { format.article.crossref output.nonnull
578       format.pages output
579     }
580   if$
581   new.block
582   note output
583   fin.entry
584 }
585
586 FUNCTION {book}
587 { output.bibitem
588   author empty$
589     { format.editors "author and editor" output.check }
590     { format.authors output.nonnull
591       crossref missing$
592         { "author and editor" editor either.or.check }
593         'skip$
594       if$
595     }
596   if$
597   new.block
598   format.btitle "title" output.check
599   crossref missing$
600     { format.bvolume output
601       new.block
602       format.number.series output
603       new.sentence
604       publisher "publisher" output.check
605       address output
606     }
607     { new.block
608       format.book.crossref output.nonnull
609     }
610   if$
611   format.edition output
612   format.date "year" output.check
613   new.block
614   note output
615   fin.entry
616 }
617
618 FUNCTION {booklet}
619 { output.bibitem
620   format.authors output
621   new.block
622   format.title "title" output.check
623   howpublished address new.block.checkb
624   howpublished output
625   address output
626   format.date output
627   new.block
628   note output
629   fin.entry
630 }
631
632 FUNCTION {inbook}
633 { output.bibitem
634   author empty$
635     { format.editors "author and editor" output.check }
636     { format.authors output.nonnull
637       crossref missing$
638         { "author and editor" editor either.or.check }
639         'skip$
640       if$
641     }
642   if$
643   new.block
644   format.btitle "title" output.check
645   crossref missing$
646     { format.bvolume output
647       format.chapter.pages "chapter and pages" output.check
648       new.block
649       format.number.series output
650       new.sentence
651       publisher "publisher" output.check
652       address output
653     }
654     { format.chapter.pages "chapter and pages" output.check
655       new.block
656       format.book.crossref output.nonnull
657     }
658   if$
659   format.edition output
660   format.date "year" output.check
661   new.block
662   note output
663   fin.entry
664 }
665
666 FUNCTION {incollection}
667 { output.bibitem
668   format.authors "author" output.check
669   new.block
670   format.title "title" output.check
671   new.block
672   crossref missing$
673     { format.in.ed.booktitle "booktitle" output.check
674       format.bvolume output
675       format.number.series output
676       format.chapter.pages output
677       new.sentence
678       publisher "publisher" output.check
679       address output
680       format.edition output
681       format.date "year" output.check
682     }
683     { format.incoll.inproc.crossref output.nonnull
684       format.chapter.pages output
685     }
686   if$
687   new.block
688   note output
689   fin.entry
690 }
691
692 FUNCTION {inproceedings}
693 { output.bibitem
694   format.authors "author" output.check
695   new.block
696   format.title "title" output.check
697   new.block
698   crossref missing$
699     { format.in.ed.booktitle "booktitle" output.check
700       format.bvolume output
701       format.number.series output
702       format.pages output
703       address empty$
704         { organization publisher new.sentence.checkb
705           organization output
706           publisher output
707           format.date "year" output.check
708         }
709         { address output.nonnull
710           format.date "year" output.check
711           new.sentence
712           organization output
713           publisher output
714         }
715       if$
716     }
717     { format.incoll.inproc.crossref output.nonnull
718       format.pages output
719     }
720   if$
721   new.block
722   note output
723   fin.entry
724 }
725
726 FUNCTION {conference} { inproceedings }
727
728 FUNCTION {manual}
729 { output.bibitem
730   author empty$
731     { organization empty$
732         'skip$
733         { organization output.nonnull
734           address output
735         }
736       if$
737     }
738     { format.authors output.nonnull }
739   if$
740   new.block
741   format.btitle "title" output.check
742   author empty$
743     { organization empty$
744         { address new.block.checka
745           address output
746         }
747         'skip$
748       if$
749     }
750     { organization address new.block.checkb
751       organization output
752       address output
753     }
754   if$
755   format.edition output
756   format.date output
757   new.block
758   note output
759   fin.entry
760 }
761
762 FUNCTION {mastersthesis}
763 { output.bibitem
764   format.authors "author" output.check
765   new.block
766   format.title "title" output.check
767   new.block
768   "Master's thesis" format.thesis.type output.nonnull
769   school "school" output.check
770   address output
771   format.date "year" output.check
772   new.block
773   note output
774   fin.entry
775 }
776
777 FUNCTION {misc}
778 { output.bibitem
779   format.authors output
780   title howpublished new.block.checkb
781   format.title output
782   howpublished new.block.checka
783   howpublished output
784   format.date output
785   new.block
786   note output
787   fin.entry
788   empty.misc.check
789 }
790
791 FUNCTION {phdthesis}
792 { output.bibitem
793   format.authors "author" output.check
794   new.block
795   format.btitle "title" output.check
796   new.block
797   "PhD thesis" format.thesis.type output.nonnull
798   school "school" output.check
799   address output
800   format.date "year" output.check
801   new.block
802   note output
803   fin.entry
804 }
805
806 FUNCTION {proceedings}
807 { output.bibitem
808   editor empty$
809     { organization output }
810     { format.editors output.nonnull }
811   if$
812   new.block
813   format.btitle "title" output.check
814   format.bvolume output
815   format.number.series output
816   address empty$
817     { editor empty$
818         { publisher new.sentence.checka }
819         { organization publisher new.sentence.checkb
820           organization output
821         }
822       if$
823       publisher output
824       format.date "year" output.check
825     }
826     { address output.nonnull
827       format.date "year" output.check
828       new.sentence
829       editor empty$
830         'skip$
831         { organization output }
832       if$
833       publisher output
834     }
835   if$
836   new.block
837   note output
838   fin.entry
839 }
840
841 FUNCTION {techreport}
842 { output.bibitem
843   format.authors "author" output.check
844   new.block
845   format.title "title" output.check
846   new.block
847   format.tr.number output.nonnull
848   institution "institution" output.check
849   address output
850   format.date "year" output.check
851   new.block
852   note output
853   fin.entry
854 }
855
856 FUNCTION {unpublished}
857 { output.bibitem
858   format.authors "author" output.check
859   new.block
860   format.title "title" output.check
861   new.block
862   note "note" output.check
863   format.date output
864   fin.entry
865 }
866
867 FUNCTION {default.type} { misc }
868
869 MACRO {jan} {"January"}
870
871 MACRO {feb} {"February"}
872
873 MACRO {mar} {"March"}
874
875 MACRO {apr} {"April"}
876
877 MACRO {may} {"May"}
878
879 MACRO {jun} {"June"}
880
881 MACRO {jul} {"July"}
882
883 MACRO {aug} {"August"}
884
885 MACRO {sep} {"September"}
886
887 MACRO {oct} {"October"}
888
889 MACRO {nov} {"November"}
890
891 MACRO {dec} {"December"}
892
893 MACRO {acmcs} {"ACM Computing Surveys"}
894
895 MACRO {acta} {"Acta Informatica"}
896
897 MACRO {cacm} {"Communications of the ACM"}
898
899 MACRO {ibmjrd} {"IBM Journal of Research and Development"}
900
901 MACRO {ibmsj} {"IBM Systems Journal"}
902
903 MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
904
905 MACRO {ieeetc} {"IEEE Transactions on Computers"}
906
907 MACRO {ieeetcad}
908  {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
909
910 MACRO {ipl} {"Information Processing Letters"}
911
912 MACRO {jacm} {"Journal of the ACM"}
913
914 MACRO {jcss} {"Journal of Computer and System Sciences"}
915
916 MACRO {scp} {"Science of Computer Programming"}
917
918 MACRO {sicomp} {"SIAM Journal on Computing"}
919
920 MACRO {tocs} {"ACM Transactions on Computer Systems"}
921
922 MACRO {tods} {"ACM Transactions on Database Systems"}
923
924 MACRO {tog} {"ACM Transactions on Graphics"}
925
926 MACRO {toms} {"ACM Transactions on Mathematical Software"}
927
928 MACRO {toois} {"ACM Transactions on Office Information Systems"}
929
930 MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
931
932 MACRO {tcs} {"Theoretical Computer Science"}
933
934 READ
935
936 FUNCTION {sortify}
937 { purify$
938   "l" change.case$
939 }
940
941 INTEGERS { len }
942
943 FUNCTION {chop.word}
944 { 's :=
945   'len :=
946   s #1 len substring$ =
947     { s len #1 + global.max$ substring$ }
948     's
949   if$
950 }
951
952 INTEGERS { et.al.char.used }
953
954 FUNCTION {initialize.et.al.char.used}
955 { #0 'et.al.char.used :=
956 }
957
958 EXECUTE {initialize.et.al.char.used}
959
960 FUNCTION {format.lab.names}
961 { 's :=
962   s num.names$ 'numnames :=
963   numnames #1 >
964     { numnames #4 >
965         { #3 'namesleft := }
966         { numnames 'namesleft := }
967       if$
968       #1 'nameptr :=
969       ""
970         { namesleft #0 > }
971         { nameptr numnames =
972             { s nameptr "{ff }{vv }{ll}{ jj}" format.name$ "others" =
973                 { "{\etalchar{+}}" *
974                   #1 'et.al.char.used :=
975                 }
976                 { s nameptr "{v{}}{l{}}" format.name$ * }
977               if$
978             }
979             { s nameptr "{v{}}{l{}}" format.name$ * }
980           if$
981           nameptr #1 + 'nameptr :=
982           namesleft #1 - 'namesleft :=
983         }
984       while$
985       numnames #4 >
986         { "{\etalchar{+}}" *
987           #1 'et.al.char.used :=
988         }
989         'skip$
990       if$
991     }
992     { s #1 "{v{}}{l{}}" format.name$
993       duplicate$ text.length$ #2 <
994         { pop$ s #1 "{ll}" format.name$ #3 text.prefix$ }
995         'skip$
996       if$
997     }
998   if$
999 }
1000
1001 FUNCTION {author.key.label}
1002 { author empty$
1003     { key empty$
1004         { cite$ #1 #3 substring$ }
1005         { key #3 text.prefix$ }
1006       if$
1007     }
1008     { author format.lab.names }
1009   if$
1010 }
1011
1012 FUNCTION {author.editor.key.label}
1013 { author empty$
1014     { editor empty$
1015         { key empty$
1016             { cite$ #1 #3 substring$ }
1017             { key #3 text.prefix$ }
1018           if$
1019         }
1020         { editor format.lab.names }
1021       if$
1022     }
1023     { author format.lab.names }
1024   if$
1025 }
1026
1027 FUNCTION {author.key.organization.label}
1028 { author empty$
1029     { key empty$
1030         { organization empty$
1031             { cite$ #1 #3 substring$ }
1032             { "The " #4 organization chop.word #3 text.prefix$ }
1033           if$
1034         }
1035         { key #3 text.prefix$ }
1036       if$
1037     }
1038     { author format.lab.names }
1039   if$
1040 }
1041
1042 FUNCTION {editor.key.organization.label}
1043 { editor empty$
1044     { key empty$
1045         { organization empty$
1046             { cite$ #1 #3 substring$ }
1047             { "The " #4 organization chop.word #3 text.prefix$ }
1048           if$
1049         }
1050         { key #3 text.prefix$ }
1051       if$
1052     }
1053     { editor format.lab.names }
1054   if$
1055 }
1056
1057 FUNCTION {calc.label}
1058 { type$ "book" =
1059   type$ "inbook" =
1060   or
1061     'author.editor.key.label
1062     { type$ "proceedings" =
1063         'editor.key.organization.label
1064         { type$ "manual" =
1065             'author.key.organization.label
1066             'author.key.label
1067           if$
1068         }
1069       if$
1070     }
1071   if$
1072   duplicate$
1073   year field.or.null purify$ #-1 #2 substring$
1074   *
1075   'label :=
1076   year field.or.null purify$ #-1 #4 substring$
1077   *
1078   sortify 'sort.label :=
1079 }
1080
1081 FUNCTION {sort.format.names}
1082 { 's :=
1083   #1 'nameptr :=
1084   ""
1085   s num.names$ 'numnames :=
1086   numnames 'namesleft :=
1087     { namesleft #0 > }
1088     { nameptr #1 >
1089         { "   " * }
1090         'skip$
1091       if$
1092       s nameptr "{vv{ } }{ll{ }}{  ff{ }}{  jj{ }}" format.name$ 't :=
1093       nameptr numnames = t "others" = and
1094         { "et al" * }
1095         { t sortify * }
1096       if$
1097       nameptr #1 + 'nameptr :=
1098       namesleft #1 - 'namesleft :=
1099     }
1100   while$
1101 }
1102
1103 FUNCTION {sort.format.title}
1104 { 't :=
1105   "A " #2
1106     "An " #3
1107       "The " #4 t chop.word
1108     chop.word
1109   chop.word
1110   sortify
1111   #1 global.max$ substring$
1112 }
1113
1114 FUNCTION {author.sort}
1115 { author empty$
1116     { key empty$
1117         { "to sort, need author or key in " cite$ * warning$
1118           ""
1119         }
1120         { key sortify }
1121       if$
1122     }
1123     { author sort.format.names }
1124   if$
1125 }
1126
1127 FUNCTION {author.editor.sort}
1128 { author empty$
1129     { editor empty$
1130         { key empty$
1131             { "to sort, need author, editor, or key in " cite$ * warning$
1132               ""
1133             }
1134             { key sortify }
1135           if$
1136         }
1137         { editor sort.format.names }
1138       if$
1139     }
1140     { author sort.format.names }
1141   if$
1142 }
1143
1144 FUNCTION {author.organization.sort}
1145 { author empty$
1146     { organization empty$
1147         { key empty$
1148             { "to sort, need author, organization, or key in " cite$ * warning$
1149               ""
1150             }
1151             { key sortify }
1152           if$
1153         }
1154         { "The " #4 organization chop.word sortify }
1155       if$
1156     }
1157     { author sort.format.names }
1158   if$
1159 }
1160
1161 FUNCTION {editor.organization.sort}
1162 { editor empty$
1163     { organization empty$
1164         { key empty$
1165             { "to sort, need editor, organization, or key in " cite$ * warning$
1166               ""
1167             }
1168             { key sortify }
1169           if$
1170         }
1171         { "The " #4 organization chop.word sortify }
1172       if$
1173     }
1174     { editor sort.format.names }
1175   if$
1176 }
1177
1178 FUNCTION {presort}
1179 { calc.label
1180   sort.label
1181   "    "
1182   *
1183   type$ "book" =
1184   type$ "inbook" =
1185   or
1186     'author.editor.sort
1187     { type$ "proceedings" =
1188         'editor.organization.sort
1189         { type$ "manual" =
1190             'author.organization.sort
1191             'author.sort
1192           if$
1193         }
1194       if$
1195     }
1196   if$
1197   *
1198   "    "
1199   *
1200   year field.or.null sortify
1201   *
1202   "    "
1203   *
1204   title field.or.null
1205   sort.format.title
1206   *
1207   #1 entry.max$ substring$
1208   'sort.key$ :=
1209 }
1210
1211 ITERATE {presort}
1212
1213 SORT
1214
1215 STRINGS { longest.label last.sort.label next.extra }
1216
1217 INTEGERS { longest.label.width last.extra.num }
1218
1219 FUNCTION {initialize.longest.label}
1220 { "" 'longest.label :=
1221   #0 int.to.chr$ 'last.sort.label :=
1222   "" 'next.extra :=
1223   #0 'longest.label.width :=
1224   #0 'last.extra.num :=
1225 }
1226
1227 FUNCTION {forward.pass}
1228 { last.sort.label sort.label =
1229     { last.extra.num #1 + 'last.extra.num :=
1230       last.extra.num int.to.chr$ 'extra.label :=
1231     }
1232     { "a" chr.to.int$ 'last.extra.num :=
1233       "" 'extra.label :=
1234       sort.label 'last.sort.label :=
1235     }
1236   if$
1237 }
1238
1239 FUNCTION {reverse.pass}
1240 { next.extra "b" =
1241     { "a" 'extra.label := }
1242     'skip$
1243   if$
1244   label extra.label * 'label :=
1245   label width$ longest.label.width >
1246     { label 'longest.label :=
1247       label width$ 'longest.label.width :=
1248     }
1249     'skip$
1250   if$
1251   extra.label 'next.extra :=
1252 }
1253
1254 EXECUTE {initialize.longest.label}
1255
1256 ITERATE {forward.pass}
1257
1258 REVERSE {reverse.pass}
1259
1260 FUNCTION {begin.bib}
1261 { et.al.char.used
1262     { "\newcommand{\etalchar}[1]{$^{#1}$}" write$ newline$ }
1263     'skip$
1264   if$
1265   "\makeatletter" write$ newline$
1266   "\@ifundefined{xbiblabel}{\newcommand{\xbiblabel}[4]{#4}}{}" write$ newline$
1267   "\let\@oldbiblabel\@biblabel" write$ newline$
1268   "\renewcommand{\@biblabel}[1]%" write$ newline$
1269   " {{\def\xbiblabel##1##2##3##4{\hyperref{##1}{##2}{##3}{##4}}%"
1270   write$ newline$
1271   "   \@oldbiblabel{#1}}}" write$ newline$
1272   "\makeatother"  write$ newline$
1273   newline$
1274
1275   preamble$ empty$
1276     'skip$
1277     { preamble$ write$ newline$ }
1278   if$
1279   "\begin{thebibliography}{"  longest.label  * "}" * write$ newline$
1280 }
1281
1282 EXECUTE {begin.bib}
1283
1284 EXECUTE {init.state.consts}
1285
1286 ITERATE {call.type$}
1287
1288 FUNCTION {end.bib}
1289 { newline$
1290   "\end{thebibliography}" write$ newline$
1291 }
1292
1293 EXECUTE {end.bib}