SIGCOMM paper template
[pingpong.git] / papers / SIGCOMM2018_IoT-SP / ACM-Reference-Format.bst
1 %%% -*-BibTeX-*-
2 %%% ====================================================================
3 %%%  @BibTeX-style-file{
4 %%%     author          = "Nelson H. F. Beebe, Boris Veytsman and Gerald Murray",
5 %%%     version         = "2.1",
6 %%%     date            = "14 June 2017",
7 %%%     filename        = "ACM-Reference-Format.bst",
8 %%%     email           = "borisv@lk.net, boris@varphi.com",
9 %%%     codetable       = "ISO/ASCII",
10 %%%     keywords        = "ACM Transactions bibliography style; BibTeX",
11 %%%     license         = "public domain",
12 %%%     supported       = "yes",
13 %%%     abstract        = "",
14 %%%  }
15 %%% ====================================================================
16
17 %%% Revision history:  see source in git
18
19 ENTRY
20   { address
21     advisor
22     archiveprefix
23     author
24     booktitle
25     chapter
26     city
27     date
28     edition
29     editor
30     eprint
31     eprinttype
32     eprintclass
33     howpublished
34     institution
35     journal
36     key
37     month
38     note
39     number
40     organization
41     pages
42     primaryclass
43     publisher
44     school
45     series
46     title
47     type
48     volume
49     year
50         % New keys recognized
51         issue         % UTAH: used in, e.g., ACM SIGSAM Bulletin and ACM Communications in Computer Algebra
52         articleno
53         eid
54         day           % UTAH: needed for newspapers, weeklies, bi-weeklies
55         doi           % UTAH
56         url           % UTAH
57         bookpages     % UTAH
58         numpages
59         lastaccessed  % UTAH: used only for @Misc{...}
60         coden         % UTAH
61         isbn          % UTAH
62         isbn-13       % UTAH
63         issn          % UTAH
64         lccn          % UTAH
65   }
66   {}
67   { label.year extra.label sort.year sort.label basic.label.year}
68
69 INTEGERS { output.state before.all mid.sentence after.sentence after.block }
70
71 INTEGERS { show-isbn-10-and-13 }  % initialized below in begin.bib
72
73 INTEGERS { nameptr namesleft numnames }
74
75 INTEGERS { multiresult }
76
77 INTEGERS { len }
78
79 INTEGERS { last.extra.num }
80
81 STRINGS { s t t.org u }
82
83 STRINGS { last.label next.extra }
84
85 STRINGS { p1 p2 p3 page.count }
86
87
88 FUNCTION { not }
89 {
90     { #0 }
91     { #1 }
92   if$
93 }
94
95 FUNCTION { and }
96 {
97     'skip$
98     { pop$ #0 }
99   if$
100 }
101
102 FUNCTION { or }
103 {
104    { pop$ #1 }
105     'skip$
106   if$
107 }
108
109
110 FUNCTION { dump.stack.1 }
111 {
112     duplicate$ "STACK[top] = [" swap$ * "]" * warning$
113 }
114
115 FUNCTION { dump.stack.2 }
116 {
117     duplicate$ "STACK[top  ] = [" swap$ * "]" * warning$
118     swap$
119     duplicate$ "STACK[top-1] = [" swap$ * "]" * warning$
120     swap$
121 }
122
123 FUNCTION { empty.or.unknown }
124 {
125   %% Examine the top stack entry, and push 1 if it is empty, or
126   %% consists only of whitespace, or is a string beginning with two
127   %% queries (??), and otherwise, push 0.
128   %%
129   %% This function provides a replacement for empty$, with the
130   %% convenient feature that unknown values marked by two leading
131   %% queries are treated the same as missing values, and thus, do not
132   %% appear in the output .bbl file, and yet, their presence in .bib
133   %% file(s) serves to mark values which are temporarily missing, but
134   %% are expected to be filled in eventually once more data is
135   %% obtained.  The TeX User Group and BibNet bibliography archives
136   %% make extensive use of this practice.
137   %%
138   %% An empty string cannot serve the same purpose, because just as in
139   %% statistics data processing, an unknown value is not the same as an
140   %% empty value.
141   %%
142   %% At entry: stack = ... top:[string]
143   %% At exit:  stack = ... top:[0 or 1]
144
145   duplicate$ empty$
146     { pop$ #1 }
147     { #1 #2 substring$ "??" = }
148   if$
149 }
150
151 FUNCTION { writeln }
152 {
153   %% In BibTeX style files, the sequences
154   %%
155   %%     ... "one" "two" output
156   %%     ... "one" "two" output.xxx
157   %%
158   %% ship "one" to the output file, possibly following by punctuation,
159   %% leaving the stack with
160   %%
161   %%     ... "two"
162   %%
163   %% There is thus a one-string lag in output processing that must be
164   %% carefully handled to avoid duplicating a string in the output
165   %% file.  Unless otherwise noted, all output.xxx functions leave
166   %% just one new string on the stack, and that model should be born
167   %% in mind when reading or writing function code.
168   %%
169   %% BibTeX's asynchronous buffering of output from strings from the
170   %% stack is confusing because newline$ bypasses the buffer.  It
171   %% would have been so much easier for newline to be a character
172   %% rather than a state of the output-in-progress.
173   %%
174   %% The documentation in btxhak.dvi is WRONG:  it says
175   %%
176   %%    newline$ Writes onto the bbl file what's accumulated in the
177   %%             output buffer. It writes a blank line if and only
178   %%             if the output buffer is empty. Since write$ does
179   %%             reasonable line breaking, you should use this
180   %%             function only when you want a blank line or an
181   %%             explicit line break.
182   %%
183   %%    write$   Pops the top (string) literal and writes it on the
184   %%             output buffer (which will result in stuff being
185   %%             written onto the bbl file when the buffer fills
186   %%             up).
187   %%
188   %% Examination of the BibTeX source code shows that write$ does
189   %% indeed behave as claimed, but newline$ sends a newline character
190   %% directly to the output file, leaving the stack unchanged.  The
191   %% first line "Writes onto ... buffer." is therefore wrong.
192   %%
193   %% The original BibTeX style files almost always use "write$ newline$"
194   %% in that order, so it makes sense to hide that pair in a private
195   %% function like this one, named after a statement in Pascal,
196   %% the programming language embedded in the BibTeX Web program.
197
198   write$                % output top-of-stack string
199   newline$              % immediate write of newline (not via stack)
200 }
201
202 FUNCTION { init.state.consts }
203 {
204   #0 'before.all :=
205   #1 'mid.sentence :=
206   #2 'after.sentence :=
207   #3 'after.block :=
208 }
209
210 FUNCTION { output.nonnull }
211 { % Stack in: ... R S T  Stack out: ... R T   File out: S<comma><space>
212   's :=
213   output.state mid.sentence =
214     {
215       ", " * write$
216     }
217     {
218       output.state after.block =
219         {
220           add.period$ writeln
221           "\newblock " write$
222         }
223         {
224           output.state before.all =
225             {
226               write$
227             }
228             {
229               add.period$ " " * write$
230             }
231           if$
232         }
233       if$
234       mid.sentence 'output.state :=
235     }
236   if$
237   s
238 }
239
240 FUNCTION { output.nonnull.dot.space }
241 { % Stack in: ... R S T  Stack out: ... R T   File out: S<dot><space>
242   's :=
243   output.state mid.sentence =           % { "<DEBUG output.nonnull.dot.space>. " * write$ }
244     {
245       ". " * write$
246     }
247     {
248       output.state after.block =
249         {
250           add.period$ writeln "\newblock " write$
251         }
252         {
253           output.state before.all =
254             {
255               write$
256             }
257             {
258               add.period$ " " * write$
259             }
260           if$
261         }
262       if$
263       mid.sentence 'output.state :=
264     }
265   if$
266   s
267 }
268
269 FUNCTION { output.nonnull.remove }
270 { % Stack in: ... R S T  Stack out: ... R T   File out: S<space>
271   's :=
272   output.state mid.sentence =
273     {
274       " " * write$
275     }
276     {
277       output.state after.block =
278         {
279           add.period$ writeln "\newblock " write$
280         }
281         {
282           output.state before.all =
283             {
284               write$
285             }
286             {
287               add.period$ " " * write$
288             }
289           if$
290         }
291       if$
292       mid.sentence 'output.state :=
293     }
294   if$
295   s
296 }
297
298 FUNCTION { output.nonnull.removenospace }
299 { % Stack in: ... R S T  Stack out: ... R T   File out: S
300   's :=
301   output.state mid.sentence =
302     {
303       "" * write$
304     }
305     {
306       output.state after.block =
307         {
308           add.period$ writeln "\newblock " write$
309         }
310         {
311           output.state before.all =
312             {
313               write$
314             }
315             {
316               add.period$ " " * write$
317             }
318           if$
319         }
320       if$
321       mid.sentence 'output.state :=
322     }
323   if$
324   s
325 }
326
327 FUNCTION { output }
328 { % discard top token if empty, else like output.nonnull
329   duplicate$ empty.or.unknown
330     'pop$
331     'output.nonnull
332   if$
333 }
334
335 FUNCTION { output.dot.space }
336 { % discard top token if empty, else like output.nonnull.dot.space
337   duplicate$ empty.or.unknown
338     'pop$
339     'output.nonnull.dot.space
340   if$
341 }
342
343 FUNCTION { output.removenospace }
344 { % discard top token if empty, else like output.nonnull.removenospace
345   duplicate$ empty.or.unknown
346     'pop$
347     'output.nonnull.removenospace
348   if$
349 }
350
351 FUNCTION { output.check }
352 { % like output, but warn if key name on top-of-stack is not set
353   't :=
354   duplicate$ empty.or.unknown
355     { pop$ "empty " t * " in " * cite$ * warning$ }
356     'output.nonnull
357   if$
358 }
359
360 FUNCTION { bibinfo.output.check }
361 { % like output.check, adding bibinfo field
362   't :=
363   duplicate$ empty.or.unknown
364     { pop$ "empty " t * " in " * cite$ * warning$ }
365     { "\bibinfo{" t "}{" * * swap$ * "}" *
366       output.nonnull }
367   if$
368 }
369
370 FUNCTION { output.check.dot.space }
371 { % like output.dot.space, but warn if key name on top-of-stack is not set
372   't :=
373   duplicate$ empty.or.unknown
374     { pop$ "empty " t * " in " * cite$ * warning$ }
375     'output.nonnull.dot.space
376   if$
377 }
378
379 FUNCTION { fin.block }
380 { % functionally, but not logically, identical to fin.entry
381    add.period$
382    writeln
383 }
384
385 FUNCTION { fin.entry }
386 {
387    add.period$
388    writeln
389 }
390
391 FUNCTION { new.sentence }
392 { % update sentence state, with neither output nor stack change
393   output.state after.block =
394     'skip$
395     {
396       output.state before.all =
397         'skip$
398         { after.sentence 'output.state := }
399       if$
400     }
401   if$
402 }
403
404 FUNCTION { fin.sentence }
405 {
406    add.period$
407    write$
408    new.sentence
409    ""
410 }
411
412 FUNCTION { new.block }
413 {
414   output.state before.all =
415     'skip$
416     { after.block 'output.state := }
417   if$
418 }
419
420 FUNCTION { output.coden }       % UTAH
421 { % output non-empty CODEN as one-line sentence (stack untouched)
422   coden empty.or.unknown
423     { }
424     { "\showCODEN{" coden * "}" * writeln }
425   if$
426 }
427
428 FUNCTION { format.articleno }
429 {
430   articleno empty.or.unknown not eid empty.or.unknown not and
431      { "Both articleno and eid are defined for " cite$ * warning$ }
432      'skip$
433   if$
434   articleno empty.or.unknown eid empty.or.unknown and
435      { "" }
436      {
437         numpages empty.or.unknown
438           { "articleno or eid field, but no numpages field, in "
439             cite$ * warning$ }
440           { }
441         if$
442         eid empty.or.unknown
443           { "Article \bibinfo{articleno}{" articleno * "}" * }
444           { "Article \bibinfo{articleno}{" eid * "}" * }
445         if$
446      }
447   if$
448 }
449
450 FUNCTION { format.year }
451 { % push year string or "[n. d.]" onto output stack
452   %% Because year is a mandatory field, we always force SOMETHING
453   %% to be output
454   "\bibinfo{year}{"
455   year empty.or.unknown
456     { "[n. d.]" }
457     { year }
458   if$
459   *  "}" *
460 }
461
462 FUNCTION { format.day.month }
463 { % push "day month " or "month " or "" onto output stack
464   day empty.or.unknown
465     {
466       month empty.or.unknown
467         { "" }
468         { "\bibinfo{date}{" month * "} " *}
469       if$
470     }
471     {
472       month empty.or.unknown
473         { "" }
474         { "\bibinfo{date}{" day * " " * month * "} " *}
475       if$
476     }
477   if$
478 }
479
480 FUNCTION { format.day.month.year }     % UTAH
481 { % if month is empty, push "" else push "(MON.)" or "(DD MON.)"
482   % Needed for frequent periodicals: 2008. ... New York Times C-1, C-2, C-17 (23 Oct.)
483   % acm-*.bst addition: prefix parenthesized date string with
484   % ", Article nnn "
485   articleno empty.or.unknown eid empty.or.unknown and
486     { "" }
487     { output.state after.block =
488        {", " format.articleno * }
489        { format.articleno  }
490       if$
491     }
492   if$
493   " (" * format.day.month * format.year * ")" *
494 }
495
496 FUNCTION { output.day.month.year }     % UTAH
497 { % if month is empty value, do nothing; else output stack top and
498   % leave with new top string "(MON.)" or "(DD MON.)"
499   % Needed for frequent periodicals: 2008. ... New York Times C-1, C-2, C-17 (23 Oct.)
500   format.day.month.year
501   output.nonnull.remove
502 }
503
504 FUNCTION { strip.doi } % UTAH
505 { % Strip any Web address prefix to recover the bare DOI, leaving the
506   % result on the output stack, as recommended by CrossRef DOI
507   % documentation.
508   % For example, reduce "http://doi.acm.org/10.1145/1534530.1534545" to
509   % "10.1145/1534530.1534545".  That is later typeset and displayed as
510   % doi:10.1145/1534530.1534545 as the LAST item in the reference list
511   % entry.  Publisher Web sites wrap this with a suitable link to a real
512   % URL to resolve the DOI, and the master https://doi.org/ address is
513   % preferred, since publisher-specific URLs can disappear in response
514   % to economic events.  All journals are encouraged by the DOI
515   % authorities to use that typeset format and link procedures for
516   % uniformity across all publications that include DOIs in reference
517   % lists.
518   % The numeric prefix is guaranteed to start with "10.", so we use
519   % that as a test.
520   % 2017-02-04 Added stripping of https:// (Boris)
521   doi #1 #3 substring$ "10." =
522     { doi }
523     {
524       doi 't :=  % get modifiable copy of DOI
525
526       % Change https:// to http:// to strip both prefixes (BV)
527
528       t #1 #8 substring$ "https://" =
529         { "http://"  t #9 t text.length$ #8 - substring$ * 't := }
530         { }
531       if$
532
533       t #1 #7 substring$ "http://" =
534         {
535             t #8 t text.length$ #7 - substring$ 't :=
536
537             "INTERNAL STYLE-FILE ERROR" 's :=
538
539             % search for next "/" and assign its suffix to s
540
541             { t text.length$ }
542             {
543               t #1 #1 substring$ "/" =
544                 {
545                   % save rest of string as true DOI (should be 10.xxxx/yyyy)
546                   t #2 t text.length$ #1 - substring$ 's :=
547                   "" 't :=    % empty string t terminates the loop
548                 }
549                 {
550                   % discard first character and continue loop: t <= substring(t,2,last)
551                   t #2 t text.length$ #1 - substring$ 't :=
552                 }
553               if$
554             }
555             while$
556
557             % check for valid DOI (should be 10.xxxx/yyyy)
558             s #1 #3 substring$ "10." =
559               { }
560               { "unrecognized DOI substring " s * " in DOI value [" * doi * "]" * warning$ }
561             if$
562
563             s   % push the stripped DOI on the output stack
564
565         }
566         {
567           "unrecognized DOI value [" doi * "]" * warning$
568           doi   % push the unrecognized original DOI on the output stack
569         }
570       if$
571     }
572   if$
573 }
574
575 %
576 % Change by BV: added standard prefix to URL
577 %
578 FUNCTION { output.doi } % UTAH
579 { % output non-empty DOI as one-line sentence (stack untouched)
580   doi empty.or.unknown
581     { }
582     {
583       %% Use \urldef here for the same reason it is used in output.url,
584       %% see output.url for further discussion.
585       "\urldef\tempurl%" writeln
586       "\url{https://doi.org/" strip.doi * "}" * writeln
587       "\showDOI{\tempurl}" writeln
588     }
589   if$
590 }
591
592 FUNCTION { output.isbn }                % UTAH
593 { % output non-empty ISBN-10 and/or ISBN-13 as one-line sentences (stack untouched)
594   show-isbn-10-and-13
595     {
596       %% show both 10- and 13-digit ISBNs
597       isbn empty.or.unknown
598         { }
599         {
600           "\showISBNx{" isbn * "}" * writeln
601         }
602       if$
603       isbn-13 empty.or.unknown
604         { }
605         {
606           "\showISBNxiii{" isbn-13 * "}" * writeln
607         }
608       if$
609     }
610     {
611       %% show 10-digit ISBNs only if 13-digit ISBNs not available
612       isbn-13 empty.or.unknown
613         {
614           isbn empty.or.unknown
615             { }
616             {
617               "\showISBNx{" isbn * "}" * writeln
618             }
619           if$
620         }
621         {
622           "\showISBNxiii{" isbn-13 * "}" * writeln
623         }
624       if$
625     }
626   if$
627 }
628
629 FUNCTION { output.issn } % UTAH
630 { % output non-empty ISSN as one-line sentence (stack untouched)
631   issn empty.or.unknown
632     { }
633     { "\showISSN{" issn * "}" * writeln }
634   if$
635 }
636
637 FUNCTION { output.issue }
638 { % output non-empty issue number as a one-line sentence (stack untouched)
639   issue empty.or.unknown
640     { }
641     { "Issue " issue * "." * writeln }
642   if$
643 }
644
645 FUNCTION { output.lccn } % UTAH
646 { % return with stack untouched
647   lccn empty.or.unknown
648     { }
649     { "\showLCCN{" lccn * "}" * writeln }
650   if$
651 }
652
653 FUNCTION { output.note } % UTAH
654 { % return with stack empty
655   note empty.or.unknown
656     { }
657     { "\shownote{" note add.period$ * "}" * writeln }
658   if$
659 }
660
661 FUNCTION { output.note.check } % UTAH
662 { % return with stack empty
663   note empty.or.unknown
664     { "empty note in " cite$ * warning$ }
665     { "\shownote{" note add.period$ * "}" * writeln }
666   if$
667 }
668
669 FUNCTION { output.eprint } %
670 { % return with stack empty
671   eprint empty.or.unknown
672     { }
673     { "\showeprint"
674          archiveprefix empty.or.unknown
675            { eprinttype empty.or.unknown
676                { }
677                { "[" eprinttype "]" * * * }
678              if$
679            }
680            { "[" archiveprefix "l" change.case$ "]" * * * }
681          if$
682          "{" *
683          primaryclass empty.or.unknown
684            { eprintclass empty.or.unknown
685              { }
686              { eprintclass "/" * * }
687              if$
688            }
689            { primaryclass "/" * * }
690          if$
691          eprint "}" * *
692          writeln
693     }
694   if$
695 }
696
697
698 %
699 % Changes by BV 2011/04/15.  Do not output
700 % url if doi is defined
701 %
702 FUNCTION { output.url } % UTAH
703 { % return with stack untouched
704   % output URL and associated lastaccessed fields
705   doi empty.or.unknown
706   {
707     url empty.or.unknown
708       { }
709       {
710           %% Use \urldef, outside \showURL, so that %nn, #, etc in URLs work
711           %% correctly.  Put the actual URL on its own line to reduce the
712           %% likelihood of BibTeX's nasty line wrapping after column 79.
713           %% \url{} can undo this, but if that doesn't work for some reason
714           %% the .bbl file would have to be repaired manually.
715           "\urldef\tempurl%" writeln
716           "\url{" url * "}" * writeln
717
718           "\showURL{%" writeln
719           lastaccessed empty.or.unknown
720             { "" }
721             { "Retrieved " lastaccessed * " from " * }
722           if$
723           "\tempurl}" * writeln
724       }
725       if$
726   }
727   { }
728   if$
729 }
730
731 FUNCTION { output.year.check }
732 { % warn if year empty, output top string and leave " YEAR<label>" on stack in mid-sentence
733   year empty.or.unknown
734      { "empty year in " cite$ * warning$
735        write$
736        " \bibinfo{year}{[n. d.]}"
737        "\natexlab{" extra.label * "}" * *
738        mid.sentence 'output.state :=
739      }
740      { write$
741        " \bibinfo{year}{" year * "}"  *
742        "\natexlab{" extra.label * "}" * *
743        mid.sentence 'output.state :=
744      }
745   if$
746 }
747
748
749 FUNCTION { le }
750 {
751   %% test whether first number is less than or equal to second number
752   %% stack in:  n1 n2
753   %% stack out: if n1 <= n2 then 1 else 0
754
755   %% "DEBUG: le " cite$ * warning$
756   > { #0 } { #1 } if$
757 }
758
759 FUNCTION { ge }
760 {
761   %% test whether first number is greater than or equal to second number
762   %% stack in:  n1 n2
763   %% stack out: if n1 >= n2 then 1 else 0
764
765   %% "DEBUG: ge " cite$ * warning$
766   < { #0 } { #1 } if$
767 }
768
769 FUNCTION { is.leading.digit }
770 {
771   %% test whether first character of string is a digit
772   %% stack in:  string
773   %% stack out: if first-char-is-digit then 1 else 0
774
775   #1 #1 substring$                      % replace string by string[1:1]
776   duplicate$                            % string[1:1] string[1:1]
777   chr.to.int$
778   "0" chr.to.int$ swap$ le              % "0" <= string[1:1] --> 0-or-1
779   swap$                                 % 0-or-1 string[1:1]
780   chr.to.int$
781   "9" chr.to.int$ le                    % string[1:1} <= "9" --> 0-or-1
782   and
783 }
784
785 FUNCTION { skip.digits }
786 {
787   %% skip over leading digits in string
788   %% stack in:  string
789   %% stack out: rest-of-string leading-digits
790
791   %% "DEBUG: enter skip.digits " cite$ * warning$
792
793   %% dump.stack.1
794
795   duplicate$
796   't :=
797   't.org :=
798   "" 'u :=
799
800   { t text.length$ }
801   {
802     %% "=================DEBUG: skip.digits   t = [" t * "]" * warning$
803     t is.leading.digit
804       { t #2 t text.length$ #1 - substring$ }
805       {
806         t 'u :=
807         ""
808       }
809     if$
810     't :=
811   }
812   while$
813
814   u                                                             % rest of string
815   t.org #1 t.org text.length$ u text.length$ - substring$       % leading digits
816
817   %% "DEBUG: t.org = [" t.org * "]" * warning$
818   %% "DEBUG: u     = [" u * "]" * warning$
819
820   %% dump.stack.2
821
822   %% "DEBUG: leave skip.digits " cite$ * warning$
823 }
824
825 FUNCTION { skip.nondigits }
826 {
827   %% skip over leading nondigits in string
828   %% stack in:  string
829   %% stack out: rest-of-string
830
831   %% "DEBUG: enter skip.nondigits " cite$ * warning$
832
833   't :=
834   "" 'u :=
835
836   { t text.length$ }
837   {
838     %% "=================DEBUG: skip.nondigits   t = [" t * "]" * warning$
839     t is.leading.digit
840       {
841         t 'u :=
842         ""
843       }
844       { t #2 t text.length$ #1 - substring$ }
845     if$
846     't :=
847   }
848   while$
849
850   u                     % rest of string
851
852   %% dump.stack.1
853   %% "DEBUG: leave skip.nondigits " cite$ * warning$
854 }
855
856 FUNCTION { parse.next.number }
857 {
858   %% stack in:  string
859   %% stack out: rest-of-string next-numeric-part-of-string
860   %% Example:
861   %% stack in:  "123:1--123:59"
862   %% stack out: ":1--123:59" "123"
863
864   's :=
865   s skip.nondigits 's :=
866   s skip.digits
867 }
868
869 FUNCTION { reduce.pages.to.page.count }
870 {
871   %% Stack in:  arbitrary-and-unused
872   %% Stack out: unchanged
873   %%
874   %% For the new-style pagination with article number and numpages or
875   %% pages, we expect to have BibTeX entries containing something like
876   %%     articleno = "17",
877   %%     pages     = "1--23",
878   %% with output "Article 17, 23 pages",
879   %% or
880   %%     articleno = "17",
881   %%     numpages  = "23",
882   %% with output "Article 17, 23 pages",
883   %% or
884   %%     articleno = "17",
885   %%     pages     = "17:1--17:23",
886   %% with output "Article 17, 23 pages",
887   %%
888   %% If articleno is missing or empty, then we should output "1--23",
889   %% "23" (with a warning of a missing articleno), or "17:1--17:23",
890   %% respectively.
891
892   %% "DEBUG: enter reduce.pages.to.page.count " cite$ * warning$
893
894   %% "DEBUG: pages = [" pages * "]" * warning$
895
896   pages
897   parse.next.number 'p1 :=
898   parse.next.number 'p2 :=
899   parse.next.number 'p3 :=
900   parse.next.number 'page.count :=
901
902   duplicate$
903   empty.or.unknown
904     {  }
905     {
906       duplicate$ "unexpected trailing garbage [" swap$ *
907       "] after n:p1--n:p2 in pages = [" *
908       pages *
909       "] in " *
910       cite$ *
911       warning$
912     }
913   if$
914
915   pop$
916
917   %% "DEBUG: reduce.pages.to.page.count: "
918   %% " p1 = " p1 * *
919   %% " p2 = " p2 * *
920   %% " p3 = " p3 * *
921   %% " p4 = " page.count * *
922   %% " in " cite$ * * warning$
923
924   p1 p3 =   p2 "1" =   and   numpages empty.or.unknown   and
925     { "INFO: reduced pages = [" pages * "] to numpages = [" * page.count * "]" * warning$ }
926     {
927       numpages empty.or.unknown
928         { pages }
929         { numpages }
930       if$
931       'page.count :=
932     }
933   if$
934
935   p1 "1" =   p3 empty.or.unknown   and   numpages empty.or.unknown   and
936     {
937       p2 'page.count :=
938       "INFO: reduced pages = [" pages * "] to numpages = [" * page.count * "]" * warning$
939     }
940     {
941       numpages empty.or.unknown
942         { pages }
943         { numpages }
944       if$
945       'page.count :=
946     }
947   if$
948
949   %% "DEBUG: leave reduce.pages.to.page.count " cite$ * warning$
950 }
951
952 FUNCTION { new.block.checkb }
953 { % issue a new.block only if at least one of top two stack strings is not empty
954   empty.or.unknown
955   swap$ empty.or.unknown
956   and
957     'skip$
958     'new.block
959   if$
960 }
961
962 FUNCTION { field.or.null }
963 { % convert empty value to null string, else return value
964   duplicate$ empty.or.unknown
965     { pop$ "" }
966     'skip$
967   if$
968 }
969
970
971
972 FUNCTION { emphasize }
973 { % emphasize a non-empty top string on the stack
974   duplicate$ empty.or.unknown
975     { pop$ "" }
976     { "\emph{" swap$ * "}" * }
977   if$
978 }
979
980 FUNCTION { comma }
981 { % convert empty string to null string, or brace string and add trailing comma
982   duplicate$ empty.or.unknown
983     { pop$ "" }
984     { "{" swap$ * "}," * }
985   if$
986 }
987
988 FUNCTION { format.names }
989 {
990   % Format bibliographical entries with the first author last name first,
991   % and subsequent authors with initials followed by last name.
992   % All names are formatted in this routine.
993
994   's :=
995   #1 'nameptr :=               % nameptr = 1;
996   s num.names$ 'numnames :=    % numnames = num.name$(s);
997   numnames 'namesleft :=
998     { namesleft #0 > }
999     { nameptr #1 =
1000         %NO: BAD ORDER: {"{" s nameptr "{ff~}{ll}{, jj}{, vv}" format.name$ * "}" * 't := }
1001         %NO: BAD ORDER: {"{" s nameptr "{ff~}{ll}{, jj}{, vv}" format.name$ * "}" * 't := }
1002         {"\bibinfo{person}{" s nameptr "{ff }{vv }{ll}{, jj}" format.name$ * "}" * 't := }
1003         {"\bibinfo{person}{" s nameptr "{ff }{vv }{ll}{, jj}" format.name$ * "}" * 't := }
1004       if$
1005       nameptr #1 >
1006         {
1007           namesleft #1 >
1008             { ", " * t * }
1009             {
1010               numnames #2 >
1011                 { "," * }
1012                 'skip$
1013               if$
1014               t "\bibinfo{person}{others}" =
1015                 { " {et~al\mbox{.}}" * } % jrh: avoid spacing problems
1016                 { " {and} " * t * } % from Chicago Manual of Style
1017               if$
1018             }
1019           if$
1020         }
1021         't
1022       if$
1023       nameptr #1 + 'nameptr :=          % nameptr += 1;
1024       namesleft #1 - 'namesleft :=      % namesleft =- 1;
1025     }
1026   while$
1027 }
1028
1029 FUNCTION { my.full.label }
1030 {
1031   's :=
1032   #1 'nameptr :=               % nameptr = 1;
1033   s num.names$ 'numnames :=    % numnames = num.name$(s);
1034   numnames 'namesleft :=
1035     { namesleft #0 > }
1036
1037     { s nameptr "{vv~}{ll}" format.name$ 't :=  % get the next name
1038       nameptr #1 >
1039         {
1040           namesleft #1 >
1041             { ", " * t * }
1042             {
1043               numnames #2 >
1044                 { "," * }
1045                 'skip$
1046               if$
1047               t "others" =
1048                 { " et~al\mbox{.}" * } % jrh: avoid spacing problems
1049                 { " and " * t * } % from Chicago Manual of Style
1050               if$
1051             }
1052           if$
1053         }
1054         't
1055       if$
1056       nameptr #1 + 'nameptr :=          % nameptr += 1;
1057       namesleft #1 - 'namesleft :=      % namesleft =- 1;
1058     }
1059   while$
1060
1061 }
1062
1063 FUNCTION { format.names.fml }
1064 {
1065   % Format names in "familiar" format, with first initial followed by
1066   % last name. Like format.names, ALL names are formatted.
1067   % jtb: The names are NOT put in small caps
1068
1069   's :=
1070   #1 'nameptr :=               % nameptr = 1;
1071   s num.names$ 'numnames :=    % numnames = num.name$(s);
1072   numnames 'namesleft :=
1073     { namesleft #0 > }
1074
1075     {
1076       "\bibinfo{person}{" s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ * "}" * 't :=
1077
1078       nameptr #1 >
1079         {
1080           namesleft #1 >
1081             { ", " * t * }
1082             {
1083               numnames #2 >
1084                 { "," * }
1085                 'skip$
1086               if$
1087               t "\bibinfo{person}{others}" =
1088                 { " {et~al\mbox{.}}" * }
1089                 { " {and} " * t * }
1090               if$
1091             }
1092           if$
1093         }
1094         't
1095       if$
1096       nameptr #1 + 'nameptr :=          % nameptr += 1;
1097       namesleft #1 - 'namesleft :=      % namesleft =- 1;
1098     }
1099   while$
1100 }
1101
1102 FUNCTION { format.authors }
1103 {
1104   author empty.or.unknown
1105     { "" }
1106     {
1107       "\bibfield{author}{"
1108       author format.names add.period$ * "}" *} % jtb: add period if none before
1109   if$
1110 }
1111
1112 FUNCTION { format.key }
1113 {
1114   empty.or.unknown
1115     { key field.or.null }
1116     { "" }
1117   if$
1118 }
1119
1120 FUNCTION { format.no.key }
1121 {
1122   empty.or.unknown
1123     { "" }
1124     { "" }
1125   if$
1126 }
1127
1128 FUNCTION { format.editors.fml }
1129 {
1130   % Format editor names for use in the "in" types: inbook, incollection,
1131   % inproceedings: first initial, then last names. When editors are the
1132   % LABEL for an entry, then format.editor is used which lists editors
1133   % by last name first.
1134
1135   editor empty.or.unknown
1136     { "" }
1137     {
1138       "\bibfield{editor}{"
1139       editor format.names.fml
1140       *  "}" *
1141       editor num.names$ #1 >
1142         { " (Eds.)" * }
1143         { " (Ed.)" * }
1144       if$
1145     }
1146   if$
1147 }
1148
1149 FUNCTION { format.editors }
1150 { % format editor names for use in labels, last names first.
1151   editor empty.or.unknown
1152     { "" }
1153     {
1154       "\bibfield{editor}{"
1155       editor format.names
1156       *  "}" *
1157       editor num.names$ #1 >
1158         { " (Eds.)." * }
1159         { " (Ed.)." * }
1160       if$
1161     }
1162   if$
1163 }
1164
1165 FUNCTION { format.articletitle }
1166 {
1167   title empty.or.unknown
1168     { "" }
1169     % Use this to preserve lettercase in titles:
1170     { "\showarticletitle{" title * "}" * }
1171     % Use this for downcase title style:
1172     % { \showarticletitle{" title "t" change.case$ * "}" * }
1173   if$
1174 }
1175
1176 FUNCTION { format.title }
1177 {
1178   title empty.or.unknown
1179     { "" }
1180     % Use this to preserve lettercase in titles:
1181     { "\bibinfo{title}{" title * "}" * }
1182     % Use this for downcase title style:
1183     % { title "t" change.case$ }
1184   if$
1185 }
1186
1187 FUNCTION { n.dashify }
1188 {
1189   't :=
1190   ""
1191     { t empty.or.unknown not }
1192     {
1193       t #1 #1 substring$ "-" =
1194         {
1195           t #1 #2 substring$ "--" = not
1196             { "--" *
1197               t #2 global.max$ substring$ 't :=
1198             }
1199             {
1200               { t #1 #1 substring$ "-" = }
1201               {
1202                 "-" *
1203                 t #2 global.max$ substring$ 't :=
1204               }
1205               while$
1206             }
1207           if$
1208         }
1209         {
1210           t #1 #1 substring$ *
1211           t #2 global.max$ substring$ 't :=
1212         }
1213       if$
1214     }
1215   while$
1216 }
1217
1218 FUNCTION { format.a.title.with.edition }
1219 {
1220   "\bibinfo{booktitle}{"
1221   swap$ emphasize *
1222   edition empty.or.unknown
1223     'skip$
1224     { " (\bibinfo{edition}{" * edition "l" change.case$ *
1225       "} ed.)" * } % jtb: no parens for ed.
1226   if$
1227   "}" *
1228 }
1229
1230 FUNCTION { format.btitle }
1231 { title format.a.title.with.edition }
1232
1233 FUNCTION { format.emphasize.booktitle }
1234 { booktitle format.a.title.with.edition }
1235
1236 FUNCTION { format.city }
1237 {
1238   % jtb: if the preceding string (the title of the conference) is non-empty,
1239   % jtb: append the location, otherwise leave empty (so as to trigger the
1240   % jtb: error message in output.check
1241
1242   duplicate$ empty.or.unknown
1243     { }
1244     {
1245       city empty.or.unknown
1246         {
1247           date empty.or.unknown
1248             { }
1249             { " (" * date * ")" * }
1250           if$
1251         }
1252         {
1253           date empty.or.unknown
1254             { " (" * city * ")" * }
1255             { " (" * city * ", " * date * ")" * }
1256           if$
1257         }
1258       if$
1259     }
1260   if$
1261 }
1262
1263 FUNCTION { tie.or.space.connect }
1264 {
1265   duplicate$ text.length$ #3 <
1266     { "~" }
1267     { " " }
1268   if$
1269   swap$ * *
1270 }
1271
1272 FUNCTION { either.or.check }
1273 {
1274   empty.or.unknown
1275     'pop$
1276     { "can't use both " swap$ * " fields in " * cite$ * warning$ }
1277   if$
1278 }
1279
1280 FUNCTION { format.bvolume }
1281 {
1282   % jtb: If there is a series, this is added and the volume trails after it.
1283   % jtb: Otherwise, "Vol" is Capitalized.
1284
1285   volume empty.or.unknown
1286     { "" }
1287     {
1288       series empty.or.unknown
1289         { "Vol.~\bibinfo{volume}{" volume "}" * *}
1290         { "\bibinfo{series}{" series "}, " * *
1291           "Vol.~\bibinfo{volume}{" volume "}" * * *}
1292       if$
1293       "volume and number" number either.or.check
1294     }
1295   if$
1296 }
1297
1298 FUNCTION { format.bvolume.noseries }
1299 {
1300   volume empty.or.unknown
1301     { "" }
1302     { "Vol.~\bibinfo{volume}{" volume "}" * *
1303       "volume and number" number either.or.check
1304     }
1305   if$
1306 }
1307
1308 FUNCTION { format.series }
1309 {
1310   series empty.or.unknown
1311     {""}
1312     {" \emph{(\bibinfo{series}{" * series "})}" *}
1313   if$
1314 }
1315
1316 FUNCTION { format.number.series }
1317 {
1318   volume empty.or.unknown
1319     {
1320       number empty.or.unknown
1321         {
1322           volume empty.or.unknown
1323           { "" }
1324           {
1325             series empty.or.unknown
1326               { "" }
1327               { " (\bibinfo{series}{" series * "})" * }
1328             if$
1329           }
1330           if$
1331         }                                       %    { series field.or.null }
1332         {
1333           output.state mid.sentence =
1334             { "Number" }                        % gnp - changed to mixed case always
1335             { "Number" }
1336           if$
1337           number tie.or.space.connect series empty.or.unknown
1338             { "there's a number but no series in " cite$ * warning$ }
1339             { " in \bibinfo{series}{" * series * "}" * }
1340           if$
1341         }
1342       if$
1343     }
1344     {
1345       ""
1346     }
1347   if$
1348 }
1349
1350 FUNCTION { multi.page.check }
1351 {
1352   't :=
1353   #0 'multiresult :=
1354     { multiresult not
1355       t empty.or.unknown not
1356       and
1357     }
1358     { t #1 #1 substring$
1359       duplicate$ "-" =
1360       swap$ duplicate$ "," =
1361       swap$ "+" =
1362       or or
1363     { #1 'multiresult := }
1364     { t #2 global.max$ substring$ 't := }
1365       if$
1366     }
1367   while$
1368   multiresult
1369 }
1370
1371 FUNCTION { format.pages }
1372 {
1373   pages empty.or.unknown
1374     { "" }
1375     { "\bibinfo{pages}{"
1376       pages multi.page.check
1377         { pages n.dashify } % gnp - removed () % jtb: removed pp.
1378         { pages }
1379       if$
1380       * "}" *
1381     }
1382   if$
1383 }
1384
1385 FUNCTION { format.pages.check.without.articleno }
1386 { %% format pages field only if articleno is absent
1387   %% Stack out: pages-specification
1388   numpages missing$ pages missing$ and
1389     { "page numbers missing in both pages and numpages fields in " cite$ * warning$ }
1390     { }
1391   if$
1392
1393   articleno empty.or.unknown eid empty.or.unknown and
1394     {
1395       pages missing$
1396         { numpages }
1397         { format.pages }
1398       if$
1399     }
1400     { "" }
1401   if$
1402 }
1403
1404 FUNCTION { format.pages.check }
1405 {
1406   pages empty.or.unknown
1407     { "page numbers missing in " cite$ * warning$ "" }
1408     { pages n.dashify }
1409   if$
1410 }
1411
1412 FUNCTION { format.bookpages }
1413 {
1414   bookpages empty.or.unknown
1415     { "" }
1416     { bookpages "book pages" tie.or.space.connect }
1417   if$
1418 }
1419
1420 FUNCTION { format.named.pages }
1421 {
1422   pages empty.or.unknown
1423     { "" }
1424     { format.pages "pages" tie.or.space.connect }
1425   if$
1426 }
1427
1428 %
1429 % Changed by Boris Veytsman, 2011-03-13
1430 % Now the word "pages" is printed even if
1431 % there field pages is not empty.
1432 %
1433
1434 FUNCTION { format.page.count }
1435 {
1436   page.count empty.or.unknown
1437     { "" }
1438     { "\bibinfo{numpages}{" page.count * "}~pages" * }
1439   if$
1440 }
1441
1442 FUNCTION { format.articleno.numpages }
1443 {
1444   %% There are seven possible outputs, depending on which fields are set.
1445   %%
1446   %% These four are handled here:
1447   %%
1448   %%     articleno, numpages, pages     -> "Article articleno-value, numpages-value pages"
1449   %%     articleno, numpages            -> "Article articleno-value, numpages-value pages"
1450   %%     articleno, pages               -> "Article articleno-value, reduced-pages-value pages"
1451   %%     articleno                      -> "Article articleno-value" and warn about missing numpages
1452   %%
1453   %% The remaining three have already been handled by
1454   %% format.pages.check.without.articleno:
1455   %%
1456   %%     numpages, pages                -> "pages-value"
1457   %%     numpages                       -> "numpages-value"
1458   %%     pages                          -> "pages-value"
1459
1460   articleno empty.or.unknown eid empty.or.unknown and
1461     {
1462       numpages empty.or.unknown
1463         { }
1464         { "numpages field, but no articleno or eid field, in "
1465           cite$ * warning$ }
1466       if$
1467       ""
1468     }
1469     {
1470       numpages empty.or.unknown
1471         {
1472           pages empty.or.unknown
1473             {
1474               "articleno or eid, but no pages or numpages field in "
1475                  cite$ * warning$
1476               "" 'page.count :=
1477             }
1478             { reduce.pages.to.page.count }
1479           if$
1480         }
1481         { numpages 'page.count := }
1482       if$
1483
1484       %% The Article number is now handled in format.day.month.year because
1485       %% ACM prefers the style "Digital Libraries 12, 3, Article 5 (July 2008)"
1486       %% over "Digital Libraries 12, 3 (July 2008), Article 5"
1487       %% format.articleno output
1488       format.page.count
1489     }
1490   if$
1491 }
1492
1493 FUNCTION {calc.format.page.count}
1494 {
1495   numpages empty.or.unknown
1496    {
1497      pages empty.or.unknown
1498         {
1499         "" 'page.count :=
1500         }
1501         { reduce.pages.to.page.count }
1502      if$
1503    }
1504    { numpages 'page.count := }
1505   if$
1506   format.page.count
1507 }
1508
1509
1510 FUNCTION { journal.canon.abbrev }
1511 {
1512   % Returns a canonical abbreviation for 'journal', or else 'journal'
1513   % unchanged.
1514   journal "ACM Computing Surveys"                                                                       = { "Comput. Surveys"                                 } {
1515   journal "{ACM} Computing Surveys"                                                                     = { "Comput. Surveys"                                 } {
1516   journal "ACM Transactions on Mathematical Software"                                                   = { "ACM Trans. Math. Software"                       } {
1517   journal "{ACM} Transactions on Mathematical Software"                                                 = { "ACM Trans. Math. Software"                       } {
1518   journal "ACM SIGNUM Newsletter"                                                                       = { "ACM SIGNUM Newslett."                            } {
1519   journal "ACM {SIGNUM} Newsletter"                                                                     = { "ACM SIGNUM Newslett."                            } {
1520   journal "{ACM} SIGNUM Newsletter"                                                                     = { "ACM SIGNUM Newslett."                            } {
1521   journal "{ACM} {SIGNUM} Newsletter"                                                                   = { "ACM SIGNUM Newslett."                            } {
1522   journal "American Journal of Sociology"                                                               = { "Amer. J. Sociology"                              } {
1523   journal "American Mathematical Monthly"                                                               = { "Amer. Math. Monthly"                             } {
1524   journal "American Mathematical Society Translations"                                                  = { "Amer. Math. Soc. Transl."                        } {
1525   journal "Applied Mathematics and Computation"                                                         = { "Appl. Math. Comput."                             } {
1526   journal "British Journal of Mathematical and Statistical Psychology"                                  = { "Brit. J. Math. Statist. Psych."                  } {
1527   journal "Bulletin of the American Mathematical Society"                                               = { "Bull. Amer. Math. Soc."                          } {
1528   journal "Canadian Mathematical Bulletin"                                                              = { "Canad. Math. Bull."                              } {
1529   journal "Communications of the ACM"                                                                   = { "Commun. ACM"                                     } {
1530   journal "Communications of the {ACM}"                                                                 = { "Commun. ACM"                                     } {
1531   journal "Computers and Structures"                                                                    = { "Comput. \& Structures"                           } {
1532   journal "Contemporary Mathematics"                                                                    = { "Contemp. Math."                                  } {
1533   journal "Crelle's Journal"                                                                            = { "Crelle's J."                                     } {
1534   journal "Giornale di Mathematiche"                                                                    = { "Giorn. Mat."                                     } {
1535   journal "IEEE Transactions on Aerospace and Electronic Systems"                                       = { "IEEE Trans. Aerospace Electron. Systems"         } {
1536   journal "{IEEE} Transactions on Aerospace and Electronic Systems"                                     = { "IEEE Trans. Aerospace Electron. Systems"         } {
1537   journal "IEEE Transactions on Automatic Control"                                                      = { "IEEE Trans. Automat. Control"                    } {
1538   journal "{IEEE} Transactions on Automatic Control"                                                    = { "IEEE Trans. Automat. Control"                    } {
1539   journal "IEEE Transactions on Computers"                                                              = { "IEEE Trans. Comput."                             } {
1540   journal "{IEEE} Transactions on Computers"                                                            = { "IEEE Trans. Comput."                             } {
1541   journal "IMA Journal of Numerical Analysis"                                                           = { "IMA J. Numer. Anal."                             } {
1542   journal "{IMA} Journal of Numerical Analysis"                                                         = { "IMA J. Numer. Anal."                             } {
1543   journal "Information Processing Letters"                                                              = { "Inform. Process. Lett."                          } {
1544   journal "International Journal for Numerical Methods in Engineering"                                  = { "Internat. J. Numer. Methods Engrg."              } {
1545   journal "International Journal of Control"                                                            = { "Internat. J. Control"                            } {
1546   journal "International Journal of Supercomputing Applications"                                        = { "Internat. J. Supercomputing Applic."             } {
1547   journal "Journal of Computational Physics"                                                            = { "J. Comput. Phys."                                } {
1548   journal "Journal of Computational and Applied Mathematics"                                            = { "J. Comput. Appl. Math."                          } {
1549   journal "Journal of Computer and System Sciences"                                                     = { "J. Comput. System Sci."                          } {
1550   journal "Journal of Mathematical Analysis and Applications"                                           = { "J. Math. Anal. Appl."                            } {
1551   journal "Journal of Mathematical Physics"                                                             = { "J. Math. Phys."                                  } {
1552   journal "Journal of Parallel and Distributed Computing"                                               = { "J. Parallel and Distrib. Comput."                } {
1553   journal "Journal of Research of the National Bureau of Standards"                                     = { "J. Res. Nat. Bur. Standards"                     } {
1554   journal "Journal of VLSI and Computer Systems"                                                        = { "J. VLSI Comput. Syst."                           } {
1555   journal "Journal of {VLSI} and Computer Systems"                                                      = { "J. VLSI Comput. Syst."                           } {
1556   journal "Journal of the ACM"                                                                          = { "J. ACM"                                          } {
1557   journal "Journal of the American Statistical Association"                                             = { "J. Amer. Statist. Assoc."                        } {
1558   journal "Journal of the Institute of Mathematics and its Applications"                                = { "J. Inst. Math. Appl."                            } {
1559   journal "Journal of the Society for Industrial and Applied Mathematics"                               = { "J. Soc. Indust. Appl. Math."                     } {
1560   journal "Journal of the Society for Industrial and Applied Mathematics, Series B, Numerical Analysis" = { "J. Soc. Indust. Appl. Math. Ser. B Numer. Anal." } {
1561   journal "Linear Algebra and its Applications"                                                         = { "Linear Algebra Appl."                            } {
1562   journal "Mathematica Scandinavica"                                                                    = { "Math. Scand."                                    } {
1563   journal "Mathematical Tables and Other Aids to Computation"                                           = { "Math. Tables Aids Comput."                       } {
1564   journal "Mathematics of Computation"                                                                  = { "Math. Comp."                                     } {
1565   journal "Mathematische Annalen"                                                                       = { "Math. Ann."                                      } {
1566   journal "Numerische Mathematik"                                                                       = { "Numer. Math."                                    } {
1567   journal "Pacific Journal of Mathematics"                                                              = { "Pacific J. Math."                                } {
1568   journal "Parallel Computing"                                                                          = { "Parallel Comput."                                } {
1569   journal "Philosophical Magazine"                                                                      = { "Philos. Mag."                                    } {
1570   journal "Proceedings of the American Mathematical Society"                                            = { "Proc. Amer. Math. Soc."                          } {
1571   journal "Proceedings of the IEEE"                                                                     = { "Proc. IEEE"                                      } {
1572   journal "Proceedings of the {IEEE}"                                                                   = { "Proc. IEEE"                                      } {
1573   journal "Proceedings of the National Academy of Sciences of the USA"                                  = { "Proc. Nat. Acad. Sci. U. S. A."                  } {
1574   journal "Quarterly Journal of Mathematics, Oxford, Series (2)"                                        = { "Quart. J. Math. Oxford Ser. (2)"                 } {
1575   journal "Quarterly of Applied Mathematics"                                                            = { "Quart. Appl. Math."                              } {
1576   journal "Review of the International Statisical Institute"                                            = { "Rev. Inst. Internat. Statist."                   } {
1577   journal "SIAM Journal on Algebraic and Discrete Methods"                                              = { "SIAM J. Algebraic Discrete Methods"              } {
1578   journal "{SIAM} Journal on Algebraic and Discrete Methods"                                            = { "SIAM J. Algebraic Discrete Methods"              } {
1579   journal "SIAM Journal on Applied Mathematics"                                                         = { "SIAM J. Appl. Math."                             } {
1580   journal "{SIAM} Journal on Applied Mathematics"                                                       = { "SIAM J. Appl. Math."                             } {
1581   journal "SIAM Journal on Computing"                                                                   = { "SIAM J. Comput."                                 } {
1582   journal "{SIAM} Journal on Computing"                                                                 = { "SIAM J. Comput."                                 } {
1583   journal "SIAM Journal on Matrix Analysis and Applications"                                            = { "SIAM J. Matrix Anal. Appl."                      } {
1584   journal "{SIAM} Journal on Matrix Analysis and Applications"                                          = { "SIAM J. Matrix Anal. Appl."                      } {
1585   journal "SIAM Journal on Numerical Analysis"                                                          = { "SIAM J. Numer. Anal."                            } {
1586   journal "{SIAM} Journal on Numerical Analysis"                                                        = { "SIAM J. Numer. Anal."                            } {
1587   journal "SIAM Journal on Scientific and Statistical Computing"                                        = { "SIAM J. Sci. Statist. Comput."                   } {
1588   journal "{SIAM} Journal on Scientific and Statistical Computing"                                      = { "SIAM J. Sci. Statist. Comput."                   } {
1589   journal "SIAM Review"                                                                                 = { "SIAM Rev."                                       } {
1590   journal "{SIAM} Review"                                                                               = { "SIAM Rev."                                       } {
1591   journal "Software Practice and Experience"                                                            = { "Software Prac. Experience"                       } {
1592   journal "Statistical Science"                                                                         = { "Statist. Sci."                                   } {
1593   journal "The Computer Journal"                                                                        = { "Comput. J."                                      } {
1594   journal "Transactions of the American Mathematical Society"                                           = { "Trans. Amer. Math. Soc."                         } {
1595   journal "USSR Computational Mathematics and Mathematical Physics"                                     = { "U. S. S. R. Comput. Math. and Math. Phys."       } {
1596   journal "{USSR} Computational Mathematics and Mathematical Physics"                                   = { "U. S. S. R. Comput. Math. and Math. Phys."       } {
1597   journal "Zeitschrift fur Angewandte Mathematik und Mechanik"                                          = { "Z. Angew. Math. Mech."                           } {
1598   journal "Zeitschrift fur Angewandte Mathematik und Physik"                                            = { "Z. Angew. Math. Phys."                           } {
1599   journal
1600   } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$
1601   } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$
1602   } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$
1603   } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$
1604   } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$
1605   } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$
1606   } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$
1607   } if$ } if$ } if$ } if$ } if$ } if$ } if$ } if$
1608 }
1609
1610 FUNCTION { format.journal.volume.number.day.month.year }
1611 {
1612   % By Young (and Spencer)
1613   % GNP - fixed bugs with missing volume, number, and/or pages
1614   %
1615   % Format journal, volume, number, pages for article types.
1616   %
1617   journal empty.or.unknown
1618     { "no journal in " cite$ * warning$ "" }
1619     { "\bibinfo{journal}{"
1620       journal.canon.abbrev emphasize *
1621       "}" * }
1622   if$
1623
1624   number empty.or.unknown
1625     {
1626       volume empty.or.unknown
1627         { "no number and no volume in " cite$ * warning$ "" * }
1628         { " " * " \bibinfo{volume}{" * volume * "}" * }
1629       if$
1630     }
1631     {
1632       volume empty.or.unknown
1633         {
1634           "unusual to have number, but no volume, for " cite$ * warning$
1635           " \bibinfo{number}{" * number * "}" *
1636         }
1637         { " \bibinfo{volume}{" * volume  * "}, \bibinfo{number}{" *
1638           number * "}" *}
1639       if$
1640     }
1641   if$
1642   after.block 'output.state :=
1643
1644   % Sometimes proceedings are published in journals
1645   % In this case we do not want to put year, day and month here
1646
1647   type$ "inproceedings" =
1648     { }
1649     {format.day.month.year * }
1650   if$
1651 }
1652
1653 FUNCTION { format.chapter.pages }
1654 {
1655   chapter empty.or.unknown
1656     'format.pages
1657     { type empty.or.unknown
1658         { "Chapter" } % gnp - changed to mixed case
1659         { type "t" change.case$ }
1660       if$
1661       chapter tie.or.space.connect
1662       pages empty.or.unknown
1663         {"page numbers missing in " cite$ * warning$} % gnp - added check
1664         { ", " * format.pages * }
1665       if$
1666     }
1667   if$
1668 }
1669
1670 FUNCTION { format.in.emphasize.booktitle }
1671 { % jtb: format for collections or proceedings not appearing in a journal
1672   booktitle empty.or.unknown
1673   { "" }
1674   { "In " format.emphasize.booktitle * }
1675   if$
1676 }
1677
1678 FUNCTION { format.in.booktitle }
1679 { % jtb: format for proceedings appearing in a journal
1680   booktitle empty.or.unknown
1681   { "" }
1682   { "In \bibinfo{booktitle}{" booktitle * "}" * }
1683   if$
1684 }
1685
1686 FUNCTION { format.in.ed.booktitle }
1687 {
1688   booktitle empty.or.unknown
1689   { "" }
1690   { editor empty.or.unknown
1691     { "In " format.emphasize.booktitle * }
1692                 % jtb: swapped editor location
1693     { "In " format.emphasize.booktitle * ", " * format.editors.fml * }
1694     if$
1695   }
1696   if$
1697 }
1698
1699 FUNCTION { format.thesis.type }
1700 { % call with default type on stack top
1701   type empty.or.unknown
1702     'skip$    % use default type
1703     {
1704       pop$    % discard default type
1705       % NO: it is silly to have to brace protect every degree type!:  type "t" change.case$
1706       type
1707     }
1708   if$
1709 }
1710
1711 FUNCTION { format.tr.number }
1712 {
1713   "\bibinfo{type}{"
1714   type empty.or.unknown
1715     { "{T}echnical {R}eport" }
1716     'type
1717   if$
1718   "}" * *
1719   number empty.or.unknown
1720     { "t" change.case$ }
1721     %% LOOKS BAD: { "." * number tie.or.space.connect }
1722     %% Prefer "Research report RJ687." to "Research report. RJ687."
1723     { number tie.or.space.connect }
1724   if$
1725 }
1726
1727 FUNCTION { format.advisor }
1728 {
1729   advisor empty.or.unknown
1730     { "" }
1731     { "Advisor(s) " advisor * }
1732   if$
1733 }
1734
1735 FUNCTION { format.article.crossref }
1736 { "See"
1737   "\citeN{" * crossref * "}" *
1738 }
1739
1740 FUNCTION { format.crossref.editor }
1741 {
1742   editor #1 "{vv~}{ll}" format.name$
1743   editor num.names$ duplicate$
1744   #2 >
1745     { pop$ " et~al\mbox{.}" * }         % jrh: avoid spacing problems
1746     { #2 <
1747     'skip$
1748     { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
1749         { " et~al\mbox{.}" * }          % jrh: avoid spacing problems
1750         { " and " * editor #2 "{vv~}{ll}" format.name$ * }
1751       if$
1752     }
1753       if$
1754     }
1755   if$
1756 }
1757
1758 FUNCTION { format.book.crossref }
1759 {
1760   volume empty.or.unknown
1761     { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
1762       "In "
1763     }
1764     { "Volume" volume tie.or.space.connect % gnp - changed to mixed case
1765       " of " *
1766     }
1767   if$
1768   editor empty.or.unknown
1769   editor field.or.null author field.or.null =
1770   or
1771     { key empty.or.unknown
1772     { series empty.or.unknown
1773         { "need editor, key, or series for " cite$ * " to crossref " *
1774           crossref * warning$
1775           "" *
1776         }
1777         { series emphasize * }
1778       if$
1779     }
1780     { key * }
1781       if$
1782     }
1783     { format.crossref.editor * }
1784   if$
1785   " \citeN{" * crossref * "}" *
1786 }
1787
1788 FUNCTION { format.incoll.inproc.crossref }
1789 { "See"
1790   " \citeN{" * crossref * "}" *
1791 }
1792
1793 FUNCTION { format.lab.names }
1794 {
1795   % format.lab.names:
1796   %
1797   % determines "short" names for the abbreviated author information.
1798   % "Long" labels are created in calc.label, using the routine my.full.label
1799   % to format author and editor fields.
1800   %
1801   % There are 4 cases for labels.   (n=3 in the example)
1802   % a) one author             Foo
1803   % b) one to n               Foo, Bar and Baz
1804   % c) use of "and others"    Foo, Bar et al.
1805   % d) more than n            Foo et al.
1806
1807   's :=
1808   s num.names$ 'numnames :=
1809   numnames #2 >    % change number to number of others allowed before
1810                    % forcing "et al".
1811     { s #1 "{vv~}{ll}" format.name$ " et~al\mbox{.}" * } % jrh: \mbox{} added
1812     {
1813       numnames #1 - 'namesleft :=
1814       #2 'nameptr :=
1815       s #1 "{vv~}{ll}" format.name$
1816         { namesleft #0 > }
1817         { nameptr numnames =
1818             { s nameptr "{ff }{vv }{ll}{ jj}" format.name$ "others" =
1819                 { " et~al\mbox{.}" * }          % jrh: avoid spacing problems
1820                 { " and " * s nameptr "{vv~}{ll}" format.name$ * }
1821               if$
1822             }
1823             { ", " * s nameptr "{vv~}{ll}" format.name$ * }
1824           if$
1825           nameptr #1 + 'nameptr :=
1826           namesleft #1 - 'namesleft :=
1827         }
1828       while$
1829     }
1830   if$
1831 }
1832
1833 FUNCTION { author.key.label }
1834 {
1835   author empty.or.unknown
1836     { key empty.or.unknown
1837           { "no key, author in " cite$ * warning$
1838             cite$ #1 #3 substring$ }
1839          'key
1840       if$
1841     }
1842     { author format.lab.names }
1843   if$
1844 }
1845
1846 FUNCTION { editor.key.organization.label }
1847 { % added - gnp. Provide label formatting by organization if editor is null.
1848   editor empty.or.unknown
1849     { organization empty.or.unknown
1850         { key empty.or.unknown
1851             { "no key, editor or organization in " cite$ * warning$
1852               cite$ #1 #3 substring$ }
1853             'key
1854           if$
1855         }
1856         { organization }
1857       if$
1858     }
1859     { editor format.lab.names }
1860   if$
1861 }
1862
1863 FUNCTION { author.editor.key.label }
1864 {
1865   author empty.or.unknown
1866     { editor empty.or.unknown
1867           { key empty.or.unknown
1868                { "no key, author, or editor in " cite$ * warning$
1869                  cite$ #1 #3 substring$ }
1870              'key
1871            if$
1872          }
1873           { editor format.lab.names }
1874       if$
1875     }
1876     { author format.lab.names }
1877   if$
1878 }
1879
1880 FUNCTION { author.editor.key.organization.label }
1881 { % added - gnp. Provide label formatting by organization if author is null.
1882   author empty.or.unknown
1883     { editor empty.or.unknown
1884         { organization empty.or.unknown
1885             { key empty.or.unknown
1886                { "no key, author, editor or organization in " cite$ * warning$
1887                  cite$ #1 #3 substring$ }
1888                'key
1889               if$
1890             }
1891             { organization }
1892           if$
1893         }
1894         { editor format.lab.names }
1895       if$
1896     }
1897     { author format.lab.names }
1898   if$
1899 }
1900
1901 % Calculate label and leave it on stack
1902 FUNCTION { calc.basic.label }
1903 {
1904   type$ "book" =
1905   type$ "inbook" =
1906   or
1907   type$ "article" =
1908   or
1909     'author.editor.key.label
1910     { type$ "proceedings" =
1911       type$ "periodical" =
1912       or
1913         'editor.key.organization.label
1914         { type$ "manual" =
1915             'author.editor.key.organization.label
1916             'author.key.label
1917           if$
1918         }
1919       if$
1920     }
1921   if$
1922   duplicate$
1923   year empty.or.unknown
1924     { "[n. d.]" }
1925     { year field.or.null purify$ #-1 #4 substring$}
1926   if$
1927   *
1928   'basic.label.year :=
1929 }
1930
1931 FUNCTION { calc.label }
1932 {
1933   % Changed - GNP. See also author.editor.organization.sort, editor.organization.sort
1934   % Form label for BibTeX entry. The classification of which fields are used
1935   % for which type of entry (book, inbook, etc.) are taken from alpha.bst.
1936   % The change here from newapa is to also include organization as a
1937   % citation label if author or editor is missing.
1938
1939   calc.basic.label
1940
1941   author empty.or.unknown  % generate the full label citation information.
1942     {
1943       editor empty.or.unknown
1944         {
1945           organization empty.or.unknown
1946             {
1947               key empty.or.unknown
1948                 {
1949                   "no author, editor, organization, or key in " cite$ * warning$
1950                   "??"
1951                 }
1952                 { key }
1953               if$
1954             }
1955             { organization }
1956           if$
1957         }
1958         { editor my.full.label }
1959       if$
1960     }
1961     { author my.full.label }
1962   if$
1963
1964   % leave label on the stack, to be popped when required.
1965
1966   "}{" * swap$ * "}{" *
1967   %  year field.or.null purify$ #-1 #4 substring$ *
1968   %
1969   % save the year for sort processing afterwards (adding a, b, c, etc.)
1970   %
1971   year empty.or.unknown
1972     { "[n. d.]" }
1973     { year field.or.null purify$ #-1 #4 substring$}
1974   if$
1975   'label.year :=
1976 }
1977
1978
1979 FUNCTION { output.bibitem }
1980 {
1981   newline$
1982   "\bibitem[\protect\citeauthoryear{" write$
1983   calc.label write$
1984   sort.year write$
1985   "}]%" writeln
1986   "        {" write$
1987   cite$ write$
1988   "}" writeln
1989   ""
1990   before.all 'output.state :=
1991 }
1992
1993
1994 FUNCTION { output.issue.doi.coden.isxn.lccn.url.eprint }
1995 { % enter and return with stack empty
1996   %% We switch now from buffered output to output of complete lines, so
1997   %% that the Issue .. URL data have their own lines, and are less likely
1998   %% to be line-wrapped by BibTeX's short-sighted algorithm, which wraps
1999   %% lines longer than 79 characters, backtracking to what it thinks is
2000   %% a break point in the string.  Any such wrapping MUST be undone to
2001   %% prevent percent-newline from appearing in DOIs and URLs.  The
2002   %% output data are intentionally wrapped in \showxxx{} macros at
2003   %% beginning of line, and that supply their own punctuation (if they
2004   %% are not defined to suppress output entirely), to make it easier for
2005   %% other software to recover them from .bbl files.
2006   %%
2007   %% It also makes it possible to later change the macro definitions
2008   %% to suppress particular output values, or alter their appearance.
2009   %%
2010   %% Note that it is possible for theses, technical reports, and
2011   %% manuals to have ISBNs, and anything that has an ISBN may also
2012   %% have an ISSN.  When there are no values for these keys, there
2013   %% is no output generated for them here.
2014
2015   "\newblock" writeln
2016   after.block 'output.state :=
2017
2018   output.issue
2019   output.isbn
2020   output.coden  % CODEN is functionally like ISSN, so output them sequentially
2021   output.issn
2022   output.lccn
2023   output.doi    % DOI is ALWAYS last according to CrossRef DOI documentation
2024   output.eprint
2025   output.url    % but ACM wants URL last
2026 }
2027
2028 FUNCTION { output.issue.doi.coden.isxn.lccn.url.eprint.note }
2029 { % enter with stack empty, return with empty string on stack
2030   output.issue.doi.coden.isxn.lccn.url.eprint
2031   note empty.or.unknown
2032     { }
2033     {
2034       "\newblock" writeln
2035       output.note
2036     }
2037   if$
2038   ""
2039 }
2040
2041 FUNCTION { output.issue.doi.coden.isxn.lccn.url.eprint.note.check }
2042 { % enter with stack empty, return with empty string on stack
2043   output.issue.doi.coden.isxn.lccn.url.eprint
2044   note empty.or.unknown
2045     { }
2046     {
2047       "\newblock" writeln
2048       output.note.check
2049     }
2050   if$
2051   ""
2052 }
2053
2054 FUNCTION { article }
2055 {
2056   output.bibitem
2057
2058   author empty.or.unknown
2059     {
2060       editor empty.or.unknown
2061         { "neither author and editor supplied for " cite$ * warning$ }
2062         { format.editors "editor" output.check }
2063       if$
2064     }
2065     { format.authors "author" output.check }
2066   if$
2067
2068   author format.no.key output       % added
2069   output.year.check                 % added
2070   new.block
2071   format.articletitle "title" output.check
2072   new.block
2073   howpublished empty.or.unknown
2074     { }
2075     { "\bibinfo{howpublished}{" howpublished "}" * * output }
2076   if$
2077
2078   crossref missing$
2079     { format.journal.volume.number.day.month.year output}
2080     {
2081       "cross reference in @Article{...} is unusual" warning$
2082       format.article.crossref output.nonnull
2083     }
2084   if$
2085
2086   format.pages.check.without.articleno output
2087   format.articleno.numpages output
2088   fin.block
2089   output.issue.doi.coden.isxn.lccn.url.eprint.note
2090   fin.entry
2091 }
2092
2093 FUNCTION { book }
2094 {
2095   output.bibitem
2096   author empty.or.unknown
2097     { format.editors "author and editor" output.check }
2098     { format.authors output.nonnull
2099       crossref missing$
2100         { "author and editor" editor either.or.check }
2101         'skip$
2102       if$
2103     }
2104   if$
2105   output.year.check       % added
2106   new.block
2107   format.btitle "title" output.check
2108   crossref missing$
2109     { new.sentence              % jtb: start a new sentence for series/volume
2110       format.bvolume output
2111       new.block
2112       format.number.series output
2113       new.sentence
2114       publisher "publisher" bibinfo.output.check
2115       address "address" bibinfo.output.check    % jtb: require address
2116       fin.sentence
2117       pages empty.or.unknown
2118         { format.bookpages }    % use bookpages when pages empty
2119         { format.pages.check "pages" tie.or.space.connect }
2120       if$
2121       output
2122     }
2123     { new.block
2124       format.book.crossref output.nonnull
2125     }
2126   if$
2127   fin.block
2128   output.issue.doi.coden.isxn.lccn.url.eprint.note
2129   fin.entry
2130 }
2131
2132 FUNCTION { booklet }
2133 {
2134   output.bibitem
2135   format.authors output
2136   author format.key output          % added
2137   output.year.check                 % added
2138   new.block
2139   format.title "title" output.check
2140   new.block
2141     howpublished empty.or.unknown
2142     { }
2143     { "\bibinfo{howpublished}{" howpublished "}" * * output }
2144   if$
2145   address output
2146   fin.block
2147   output.issue.doi.coden.isxn.lccn.url.eprint.note
2148   fin.entry
2149 }
2150
2151 FUNCTION { inbook }
2152 {
2153   output.bibitem
2154   author empty.or.unknown
2155     { format.editors
2156       "author and editor" output.check
2157     }
2158     { format.authors output.nonnull
2159       crossref missing$
2160     { "author and editor" editor either.or.check }
2161     'skip$
2162       if$
2163     }
2164   if$
2165   output.year.check                 % added
2166   new.block
2167   format.btitle "title" output.check
2168   crossref missing$
2169     { new.sentence              % jtb: start a new sentence for series/volume
2170       format.bvolume output
2171       new.block
2172       format.number.series output
2173       new.sentence
2174       publisher "publisher" bibinfo.output.check
2175       address "address" bibinfo.output.check    % jtb: require address
2176       format.bookpages output
2177       format.chapter.pages
2178       "chapter and pages" output.check  % jtb: moved from before publisher
2179     }
2180     {
2181       format.bookpages output
2182       format.chapter.pages "chapter and pages" output.check
2183       new.block
2184       format.book.crossref output.nonnull
2185     }
2186   if$
2187   fin.block
2188   output.issue.doi.coden.isxn.lccn.url.eprint.note
2189   fin.entry
2190 }
2191
2192 FUNCTION { incollection }
2193 {
2194   output.bibitem
2195   format.authors "author" output.check
2196   author format.key output       % added
2197   output.year.check              % added
2198   new.block
2199   format.articletitle "title" output.check
2200   new.block
2201   crossref missing$
2202     { format.in.ed.booktitle "booktitle" output.check
2203       new.sentence                % jtb: start a new sentence for series/volume
2204       format.bvolume output
2205       format.number.series output
2206       new.sentence
2207       publisher "publisher" bibinfo.output.check
2208       address "address" bibinfo.output.check      % jtb: require address
2209       format.bookpages output
2210       format.chapter.pages output % gnp - was special.output.nonnull
2211                                   % left out comma before page numbers
2212                                   % jtb: moved from before publisher
2213     }
2214     {
2215       format.incoll.inproc.crossref output.nonnull
2216       format.chapter.pages output
2217     }
2218   if$
2219   fin.block
2220   output.issue.doi.coden.isxn.lccn.url.eprint.note
2221   fin.entry
2222 }
2223
2224 FUNCTION { inproceedings }
2225 {
2226   output.bibitem
2227   format.authors "author" output.check
2228   author format.key output            % added
2229   output.year.check                   % added
2230   new.block
2231   format.articletitle "title" output.check
2232   howpublished empty.or.unknown
2233     { }
2234     { "\bibinfo{howpublished}{" howpublished "}" * * output.dot.space }
2235   if$
2236   crossref missing$
2237     {
2238       journal missing$          % jtb: proceedings appearing in journals
2239         { format.in.emphasize.booktitle format.city "booktitle"  output.check.dot.space
2240           format.series output.removenospace
2241           format.editors.fml output % BV 2011/09/27 Moved dot to comma
2242           format.bvolume.noseries output
2243           new.sentence
2244           organization output
2245           publisher "publisher" bibinfo.output.check % jtb: require publisher (?)
2246           address "address" bibinfo.output.check  % jtb: require address
2247           format.bookpages output
2248         }
2249         {
2250            format.in.booktitle format.city "booktitle" output.check
2251            format.editors.fml output
2252            new.sentence
2253            format.journal.volume.number.day.month.year output
2254         }
2255       if$
2256       format.articleno output
2257       format.pages.check.without.articleno output
2258     }
2259     {
2260       format.incoll.inproc.crossref output.nonnull
2261       format.articleno output
2262       format.pages.check.without.articleno output
2263     }
2264   if$
2265   format.articleno.numpages output
2266   fin.block
2267   output.issue.doi.coden.isxn.lccn.url.eprint.note
2268   fin.entry
2269 }
2270
2271 FUNCTION { conference } { inproceedings }
2272
2273 FUNCTION { manual }
2274 {
2275   output.bibitem
2276   author empty.or.unknown
2277     { editor empty.or.unknown
2278       { organization "organization" output.check
2279         organization format.key output }  % if all else fails, use key
2280       { format.editors "author and editor" output.check }
2281       if$
2282     }
2283     { format.authors output.nonnull }
2284     if$
2285   output.year.check                 % added
2286   new.block
2287   format.btitle "title" output.check
2288   organization address new.block.checkb
2289   % jtb: back to normal style: organization, address
2290   organization "organization" output.check
2291   address output
2292   fin.block
2293   output.issue.doi.coden.isxn.lccn.url.eprint.note
2294   fin.entry
2295 }
2296
2297 FUNCTION { mastersthesis }
2298 {
2299   output.bibitem
2300   format.authors "author" output.check
2301   author format.key output          % added
2302   output.year.check                 % added
2303   new.block
2304   format.title emphasize "title" output.check  % NB: ACM style requires emphasized thesis title
2305   new.block
2306   "\bibinfo{thesistype}{Master's\ thesis}" format.thesis.type output
2307   new.sentence
2308   school "school" bibinfo.output.check
2309   address empty.or.unknown
2310      { }
2311      { "\bibinfo{address}{" address * "}" * output }
2312   if$
2313   new.block
2314   format.advisor output
2315   fin.block
2316   output.issue.doi.coden.isxn.lccn.url.eprint.note
2317   fin.entry
2318 }
2319
2320 FUNCTION { misc }
2321 {
2322   output.bibitem
2323   format.authors "author" output.check
2324   author format.key output            % added
2325   output.year.check                   % added
2326   title howpublished new.block.checkb
2327   format.title output
2328   new.block
2329   howpublished empty.or.unknown
2330     { }
2331     { "\bibinfo{howpublished}{" howpublished "}" * * output }
2332   if$
2333   "" output.nonnull.dot.space
2334   output.day.month.year
2335   calc.format.page.count output
2336   fin.block
2337   output.issue.doi.coden.isxn.lccn.url.eprint.note
2338   fin.entry
2339 }
2340
2341 FUNCTION { online } { misc }
2342
2343 FUNCTION { game } { misc }
2344
2345
2346 FUNCTION { phdthesis }
2347 {
2348   output.bibitem
2349   format.authors "author" output.check
2350   author format.key output          % added
2351   output.year.check                 % added
2352   new.block
2353   format.title emphasize "title" output.check  % NB: ACM style requires emphasized thesis title
2354   new.block
2355   "\bibinfo{thesistype}{Ph.D. Dissertation}" format.thesis.type output
2356   new.sentence
2357   school "school" bibinfo.output.check
2358   address empty.or.unknown
2359      { }
2360      { "\bibinfo{address}{" address * "}" * output }
2361   if$
2362   new.block
2363   format.advisor output
2364   fin.block
2365   output.issue.doi.coden.isxn.lccn.url.eprint.note
2366   fin.entry
2367 }
2368
2369 FUNCTION {format.date}
2370 { year empty.or.unknown
2371     { month empty.or.unknown
2372         {
2373           ""                    % output empty date if year/month both empty
2374           day empty.or.unknown
2375             {  }
2376             { "there's a day but no month or year in " cite$ * warning$ }
2377           if$
2378         }
2379         { "there's a month but no year in " cite$ * warning$
2380           month
2381           day empty.or.unknown
2382             { }
2383             { " " * day * }
2384           if$
2385         }
2386       if$
2387     }
2388     { month empty.or.unknown
2389         {
2390           year                  % output only year if month empty
2391           day empty.or.unknown
2392             {  }
2393             { "there's a day and year but no month in " cite$ * warning$ }
2394           if$
2395         }
2396         {
2397           month " " *
2398           day empty.or.unknown
2399             { }
2400             { day * ", " * }
2401           if$
2402           year *
2403         }
2404       if$
2405     }
2406   if$
2407 }
2408
2409 FUNCTION {new.block.checka}
2410 {
2411   empty.or.unknown
2412     'skip$
2413     'new.block
2414   if$
2415 }
2416
2417 FUNCTION { periodical }
2418 {
2419   output.bibitem
2420   editor empty.or.unknown
2421     { organization output }
2422     { format.editors output.nonnull }
2423   if$
2424   new.block
2425   output.year.check
2426   new.sentence
2427   format.articletitle "title" output.check
2428   format.journal.volume.number.day.month.year output
2429   calc.format.page.count output
2430   fin.entry
2431 }
2432
2433 FUNCTION { proceedings }
2434 {
2435   output.bibitem
2436   editor empty.or.unknown
2437     { organization output
2438       organization format.key output }  % gnp - changed from author format.key
2439     { format.editors output.nonnull }
2440   if$
2441   % author format.key output             % gnp - removed (should be either
2442   %                                        editor or organization
2443   output.year.check                    % added (newapa)
2444   new.block
2445   format.btitle format.city "title" output.check        % jtb: added city
2446   new.sentence
2447   format.bvolume output
2448   format.number.series output
2449   new.sentence
2450   organization output
2451   % jtb: normal order: publisher, address
2452   publisher empty.or.unknown
2453      { }
2454      { "\bibinfo{publisher}{" publisher * "}" * output }
2455   if$
2456   address empty.or.unknown
2457      { }
2458      { "\bibinfo{address}{" address * "}" * output }
2459   if$
2460   fin.block
2461   output.issue.doi.coden.isxn.lccn.url.eprint.note
2462   fin.entry
2463 }
2464
2465 FUNCTION { collection } { proceedings }
2466
2467 FUNCTION { techreport }
2468 {
2469   output.bibitem
2470   format.authors "author" output.check
2471   author format.key output             % added
2472   output.year.check                    % added
2473   new.block
2474   format.btitle "title" output.check
2475   new.block
2476 %   format.tr.number output               % jtb: moved month ...
2477   format.tr.number output new.sentence    % Gerry  - need dot 2011/09/28
2478   institution "institution" bibinfo.output.check
2479   address empty.or.unknown
2480     { }
2481     { "\bibinfo{address}{" address "}" * * output }
2482   if$
2483   new.sentence
2484   format.named.pages output
2485   % ACM omits year at end in transactions style
2486   % format.day.month.year output.nonnull.dot.space  % jtb: ... to here (no parens)
2487   fin.block
2488   output.issue.doi.coden.isxn.lccn.url.eprint.note
2489   fin.entry
2490 }
2491
2492 FUNCTION { unpublished }
2493 {
2494   output.bibitem
2495   format.authors
2496   "author" output.check
2497   author format.key output              % added
2498   output.year.check                     % added
2499   new.block
2500   format.title "title" output.check
2501   fin.sentence
2502   output.day.month.year                 % UTAH
2503   calc.format.page.count output
2504   fin.block
2505   output.issue.doi.coden.isxn.lccn.url.eprint.note.check
2506   fin.entry
2507 }
2508
2509 FUNCTION { default.type } { misc }
2510
2511 %%% ACM journal-style month definitions: full name if 1--5 letters, else
2512 %%% abbreviation of 3 or 4 characters and a dot
2513
2514 MACRO {jan}             {"Jan."}
2515
2516 MACRO {feb}             {"Feb."}
2517
2518 MACRO {mar}             {"March"}
2519
2520 MACRO {apr}             {"April"}
2521
2522 MACRO {may}             {"May"}
2523
2524 MACRO {jun}             {"June"}
2525
2526 MACRO {jul}             {"July"}
2527
2528 MACRO {aug}             {"Aug."}
2529
2530 MACRO {sep}             {"Sept."}
2531
2532 MACRO {oct}             {"Oct."}
2533
2534 MACRO {nov}             {"Nov."}
2535
2536 MACRO {dec}             {"Dec."}
2537
2538
2539
2540 READ
2541
2542 FUNCTION { sortify }
2543 {
2544   purify$
2545   "l" change.case$
2546 }
2547
2548 FUNCTION { chop.word }
2549 {
2550   's :=
2551   'len :=
2552   s #1 len substring$ =
2553     { s len #1 + global.max$ substring$ }
2554     's
2555   if$
2556 }
2557
2558 FUNCTION { sort.format.names }
2559 {
2560   's :=
2561   #1 'nameptr :=
2562   ""
2563   s num.names$ 'numnames :=
2564   numnames 'namesleft :=
2565     { namesleft #0 > }
2566     { nameptr #1 >
2567           { "   " * }
2568          'skip$
2569       if$
2570       s nameptr "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}" format.name$ 't :=
2571       nameptr numnames = t "others" = and
2572           { " et~al" * }
2573           { t sortify * }
2574       if$
2575       nameptr #1 + 'nameptr :=
2576       namesleft #1 - 'namesleft :=
2577     }
2578   while$
2579 }
2580
2581 FUNCTION { sort.format.title }
2582 {
2583   't :=
2584   "A " #2
2585     "An " #3
2586       "The " #4 t chop.word
2587     chop.word
2588   chop.word
2589   sortify
2590   #1 global.max$ substring$
2591 }
2592
2593 FUNCTION { author.sort }
2594 {
2595   author empty.or.unknown
2596     { key empty.or.unknown
2597          { "to sort, need author or key in " cite$ * warning$
2598            "" }
2599          { key sortify }
2600       if$
2601     }
2602     { author sort.format.names }
2603   if$
2604 }
2605
2606 FUNCTION { author.editor.sort }
2607 {
2608   author empty.or.unknown
2609     {
2610       editor empty.or.unknown
2611          {
2612            key empty.or.unknown
2613              { "to sort, need author, editor, or key in " cite$ * warning$
2614                ""
2615              }
2616              { key sortify }
2617            if$
2618          }
2619          { editor sort.format.names }
2620       if$
2621     }
2622     { author sort.format.names }
2623   if$
2624 }
2625
2626 FUNCTION { editor.organization.sort }
2627 {
2628   % added - GNP. Stack editor or organization for sorting (from alpha.bst).
2629   % Unlike alpha.bst, we need entire names, not abbreviations
2630
2631   editor empty.or.unknown
2632     { organization empty.or.unknown
2633         { key empty.or.unknown
2634             { "to sort, need editor, organization, or key in " cite$ * warning$
2635               ""
2636             }
2637             { key sortify }
2638           if$
2639         }
2640         { organization sortify }
2641       if$
2642     }
2643     { editor sort.format.names }
2644   if$
2645 }
2646
2647 FUNCTION { author.editor.organization.sort }
2648 {
2649   % added - GNP. Stack author or organization for sorting (from alpha.bst).
2650   % Unlike alpha.bst, we need entire names, not abbreviations
2651
2652   author empty.or.unknown
2653     {
2654       editor empty.or.unknown
2655         { organization empty.or.unknown
2656             { key empty.or.unknown
2657                 { "to sort, need author, editor, or key in " cite$ * warning$
2658                 ""
2659                 }
2660                 { key sortify }
2661               if$
2662             }
2663             { organization sortify }
2664           if$
2665         }
2666         { editor sort.format.names }
2667       if$
2668     }
2669     { author sort.format.names }
2670   if$
2671 }
2672
2673 FUNCTION { presort }
2674 {
2675   % Presort creates the bibentry's label via a call to calc.label, and then
2676   % sorts the entries based on entry type. Chicago.bst adds support for
2677   % including organizations as the sort key; the following is stolen from
2678   % alpha.bst.
2679
2680   calc.label
2681   basic.label.year
2682   swap$
2683   "    "
2684   swap$
2685   * *
2686   "    "
2687   *
2688   sortify
2689   year field.or.null purify$ #-1 #4 substring$ * % add year
2690   "    "
2691   *
2692   type$ "book" =
2693   type$ "inbook" =
2694   or
2695   type$ "article" =
2696   or
2697     'author.editor.sort
2698     { type$ "proceedings" =
2699       type$ "periodical" =
2700       or
2701         'editor.organization.sort
2702         { type$ "manual" =
2703             'author.editor.organization.sort
2704             'author.sort
2705           if$
2706         }
2707       if$
2708     }
2709   if$
2710   #1 entry.max$ substring$        % added for newapa
2711   'sort.label :=                  % added for newapa
2712   sort.label                      % added for newapa
2713   *
2714   "    "
2715   *
2716   title field.or.null
2717   sort.format.title
2718   *
2719   #1 entry.max$ substring$
2720   'sort.key$ :=
2721 }
2722
2723
2724
2725 ITERATE { presort }
2726
2727 SORT             % by label, year, author/editor, title
2728
2729 % From plainnat.bst
2730 STRINGS { longest.label }
2731
2732 INTEGERS { longest.label.width number.label }
2733
2734 FUNCTION {initialize.longest.label}
2735 { "" 'longest.label :=
2736   #0 int.to.chr$ 'last.label :=
2737   "" 'next.extra :=
2738   #0 'longest.label.width :=
2739   #0 'last.extra.num :=
2740   #0 'number.label :=
2741 }
2742
2743
2744
2745 FUNCTION { initialize.extra.label.stuff }
2746 { #0 int.to.chr$ 'last.label :=
2747   "" 'next.extra :=
2748   #0 'last.extra.num :=
2749 }
2750
2751 FUNCTION { forward.pass }
2752 {
2753   % Pass through all entries, comparing current entry to last one.
2754   % Need to concatenate year to the stack (done by calc.label) to determine
2755   % if two entries are the same (see presort)
2756
2757   last.label
2758   calc.basic.label year field.or.null purify$ #-1 #4 substring$ * % add year
2759   #1 entry.max$ substring$ =     % are they equal?
2760      { last.extra.num #1 + 'last.extra.num :=
2761        last.extra.num int.to.chr$ 'extra.label :=
2762      }
2763      { "a" chr.to.int$ 'last.extra.num :=
2764        "" 'extra.label :=
2765        calc.basic.label year field.or.null purify$ #-1 #4 substring$ * % add year
2766        #1 entry.max$ substring$ 'last.label := % assign to last.label
2767      }
2768   if$
2769   number.label #1 + 'number.label :=
2770 }
2771
2772 FUNCTION { reverse.pass }
2773 {
2774   next.extra "b" =
2775     { "a" 'extra.label := }
2776      'skip$
2777   if$
2778   label.year extra.label * 'sort.year :=
2779   extra.label 'next.extra :=
2780 }
2781
2782 EXECUTE {initialize.extra.label.stuff}
2783 EXECUTE {initialize.longest.label}
2784
2785
2786 ITERATE {forward.pass}
2787
2788 REVERSE {reverse.pass}
2789
2790 FUNCTION { bib.sort.order }
2791 {
2792   sort.label
2793   "    "
2794   *
2795   year field.or.null sortify
2796   *
2797   "    "
2798   *
2799   title field.or.null
2800   sort.format.title
2801   *
2802   #1 entry.max$ substring$
2803   'sort.key$ :=
2804 }
2805
2806 ITERATE { bib.sort.order }
2807
2808 SORT             % by sort.label, year, title --- giving final bib. order.
2809
2810 FUNCTION { begin.bib }
2811 {
2812   %% Set to #0 show 13-digit ISBN in preference to 10-digit ISBN.
2813   %% Set to #1 to show both 10-digit and 13-digit ISBNs.
2814   #1 'show-isbn-10-and-13 :=
2815
2816   "%%% -*-BibTeX-*-" writeln
2817   "%%% Do NOT edit. File created by BibTeX with style" writeln
2818   "%%% ACM-Reference-Format-Journals [18-Jan-2012]." writeln
2819   "" writeln
2820
2821   preamble$ empty.or.unknown
2822     'skip$
2823     { preamble$ writeln }
2824   if$
2825   "\begin{thebibliography}{" number.label int.to.str$ * "}" * writeln
2826   ""                                                                         writeln
2827   "%%% ====================================================================" writeln
2828   "%%% NOTE TO THE USER: you can override these defaults by providing"       writeln
2829   "%%% customized versions of any of these macros before the \bibliography"  writeln
2830   "%%% command.  Each of them MUST provide its own final punctuation,"       writeln
2831   "%%% except for \shownote{}, \showDOI{}, and \showURL{}.  The latter two"  writeln
2832   "%%% do not use final punctuation, in order to avoid confusing it with"    writeln
2833   "%%% the Web address."                                                     writeln
2834   "%%%"                                                                      writeln
2835   "%%% To suppress output of a particular field, define its macro to expand" writeln
2836   "%%% to an empty string, or better, \unskip, like this:"                   writeln
2837   "%%%"                                                                      writeln
2838   "%%% \newcommand{\showDOI}[1]{\unskip}   % LaTeX syntax"                   writeln
2839   "%%%"                                                                      writeln
2840   "%%% \def \showDOI #1{\unskip}           % plain TeX syntax"               writeln
2841   "%%%"                                                                      writeln
2842   "%%% ====================================================================" writeln
2843   ""                                                                         writeln
2844
2845   %% ACM publications do not use CODEN, ISSN, and LCCN data, so their default
2846   %% macro wrappers expand to \unskip, discarding their values and unwanted
2847   %% space.
2848   %%
2849   %% For other publications, prior definitions like these may be useful:
2850   %%
2851   %%     Plain TeX:
2852   %%         \def \showCODEN     #1{CODEN #1.}
2853   %%         \def \showISSN      #1{ISSN #1.}
2854   %%         \def \showLCCN      #1{LCCN #1.}
2855   %%
2856   %%     LaTeX:
2857   %%         \newcommand{\showCODEN}[1]{CODEN #1.}
2858   %%         \newcommand{\showISSN}[1]#1{ISSN #1.}
2859   %%         \newcommand{\showLCCN}[1]{LCCN #1.}
2860
2861   "\ifx \showCODEN    \undefined \def \showCODEN     #1{\unskip}     \fi" writeln
2862   "\ifx \showDOI      \undefined \def \showDOI       #1{#1}\fi" writeln
2863   % ACM styles omit ISBNs, but they can be included by suitable definitions of
2864   % \showISBNx and \showISBNxiii before the .bbl file is read
2865   "\ifx \showISBNx    \undefined \def \showISBNx     #1{\unskip}     \fi" writeln
2866   "\ifx \showISBNxiii \undefined \def \showISBNxiii  #1{\unskip}     \fi" writeln
2867   "\ifx \showISSN     \undefined \def \showISSN      #1{\unskip}     \fi" writeln
2868   "\ifx \showLCCN     \undefined \def \showLCCN      #1{\unskip}     \fi" writeln
2869   "\ifx \shownote     \undefined \def \shownote      #1{#1}          \fi" writeln % NB: final period supplied by add.period$ above
2870   "\ifx \showarticletitle \undefined \def \showarticletitle #1{#1}   \fi" writeln
2871   "\ifx \showURL      \undefined \def \showURL       {\relax}        \fi" writeln
2872   "% The following commands are used for tagged output and should be " writeln
2873   "% invisible to TeX" writeln
2874   "\providecommand\bibfield[2]{#2}" writeln
2875   "\providecommand\bibinfo[2]{#2}" writeln
2876   "\providecommand\natexlab[1]{#1}" writeln
2877   "\providecommand\showeprint[2][]{arXiv:#2}" writeln
2878 }
2879
2880 EXECUTE {begin.bib}
2881
2882 EXECUTE {init.state.consts}
2883
2884 ITERATE {call.type$}
2885
2886 FUNCTION { end.bib }
2887 {
2888   newline$
2889   "\end{thebibliography}"
2890   writeln
2891 }
2892
2893 EXECUTE {end.bib}