-
Notifications
You must be signed in to change notification settings - Fork 0
/
ACM-Reference-Format.bst
2970 lines (2692 loc) · 83.3 KB
/
ACM-Reference-Format.bst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%%% -*-BibTeX-*-
%%% ====================================================================
%%% @BibTeX-style-file{
%%% author = "Nelson H. F. Beebe, Boris Veytsman and Gerald Murray",
%%% version = "2.1",
%%% date = "14 June 2017",
%%% filename = "ACM-Reference-Format.bst",
%%% email = "borisv@lk.net, boris@varphi.com",
%%% codetable = "ISO/ASCII",
%%% keywords = "ACM Transactions bibliography style; BibTeX",
%%% license = "public domain",
%%% supported = "yes",
%%% abstract = "",
%%% }
%%% ====================================================================
%%% Revision history: see source in git
ENTRY
{ address
advisor
archiveprefix
author
booktitle
chapter
city
date
edition
editor
eprint
eprinttype
eprintclass
howpublished
institution
journal
key
location
month
note
number
organization
pages
primaryclass
publisher
school
series
title
type
volume
year
% New keys recognized
issue % UTAH: used in, e.g., ACM SIGSAM Bulletin and ACM Communications in Computer Algebra
articleno
eid
day % UTAH: needed for newspapers, weeklies, bi-weeklies
doi % UTAH
url % UTAH
bookpages % UTAH
numpages
lastaccessed % UTAH: used only for @Misc{...}
coden % UTAH
isbn % UTAH
isbn-13 % UTAH
issn % UTAH
lccn % UTAH
}
{}
{ label.year extra.label sort.year sort.label basic.label.year}
INTEGERS { output.state before.all mid.sentence after.sentence after.block }
INTEGERS { show-isbn-10-and-13 } % initialized below in begin.bib
INTEGERS { nameptr namesleft numnames }
INTEGERS { multiresult }
INTEGERS { len }
INTEGERS { last.extra.num }
STRINGS { s t t.org u }
STRINGS { last.label next.extra }
STRINGS { p1 p2 p3 page.count }
FUNCTION { not }
{
{ #0 }
{ #1 }
if$
}
FUNCTION { and }
{
'skip$
{ pop$ #0 }
if$
}
FUNCTION { or }
{
{ pop$ #1 }
'skip$
if$
}
FUNCTION { dump.stack.1 }
{
duplicate$ "STACK[top] = [" swap$ * "]" * warning$
}
FUNCTION { dump.stack.2 }
{
duplicate$ "STACK[top ] = [" swap$ * "]" * warning$
swap$
duplicate$ "STACK[top-1] = [" swap$ * "]" * warning$
swap$
}
FUNCTION { empty.or.unknown }
{
%% Examine the top stack entry, and push 1 if it is empty, or
%% consists only of whitespace, or is a string beginning with two
%% queries (??), and otherwise, push 0.
%%
%% This function provides a replacement for empty$, with the
%% convenient feature that unknown values marked by two leading
%% queries are treated the same as missing values, and thus, do not
%% appear in the output .bbl file, and yet, their presence in .bib
%% file(s) serves to mark values which are temporarily missing, but
%% are expected to be filled in eventually once more data is
%% obtained. The TeX User Group and BibNet bibliography archives
%% make extensive use of this practice.
%%
%% An empty string cannot serve the same purpose, because just as in
%% statistics data processing, an unknown value is not the same as an
%% empty value.
%%
%% At entry: stack = ... top:[string]
%% At exit: stack = ... top:[0 or 1]
duplicate$ empty$
{ pop$ #1 }
{ #1 #2 substring$ "??" = }
if$
}
FUNCTION { writeln }
{
%% In BibTeX style files, the sequences
%%
%% ... "one" "two" output
%% ... "one" "two" output.xxx
%%
%% ship "one" to the output file, possibly following by punctuation,
%% leaving the stack with
%%
%% ... "two"
%%
%% There is thus a one-string lag in output processing that must be
%% carefully handled to avoid duplicating a string in the output
%% file. Unless otherwise noted, all output.xxx functions leave
%% just one new string on the stack, and that model should be born
%% in mind when reading or writing function code.
%%
%% BibTeX's asynchronous buffering of output from strings from the
%% stack is confusing because newline$ bypasses the buffer. It
%% would have been so much easier for newline to be a character
%% rather than a state of the output-in-progress.
%%
%% The documentation in btxhak.dvi is WRONG: it says
%%
%% newline$ Writes onto the bbl file what's accumulated in the
%% output buffer. It writes a blank line if and only
%% if the output buffer is empty. Since write$ does
%% reasonable line breaking, you should use this
%% function only when you want a blank line or an
%% explicit line break.
%%
%% write$ Pops the top (string) literal and writes it on the
%% output buffer (which will result in stuff being
%% written onto the bbl file when the buffer fills
%% up).
%%
%% Examination of the BibTeX source code shows that write$ does
%% indeed behave as claimed, but newline$ sends a newline character
%% directly to the output file, leaving the stack unchanged. The
%% first line "Writes onto ... buffer." is therefore wrong.
%%
%% The original BibTeX style files almost always use "write$ newline$"
%% in that order, so it makes sense to hide that pair in a private
%% function like this one, named after a statement in Pascal,
%% the programming language embedded in the BibTeX Web program.
write$ % output top-of-stack string
newline$ % immediate write of newline (not via stack)
}
FUNCTION { init.state.consts }
{
#0 'before.all :=
#1 'mid.sentence :=
#2 'after.sentence :=
#3 'after.block :=
}
FUNCTION { output.nonnull }
{ % Stack in: ... R S T Stack out: ... R T File out: S<comma><space>
's :=
output.state mid.sentence =
{
", " * write$
}
{
output.state after.block =
{
add.period$ writeln
"\newblock " write$
}
{
output.state before.all =
{
write$
}
{
add.period$ " " * write$
}
if$
}
if$
mid.sentence 'output.state :=
}
if$
s
}
FUNCTION { output.nonnull.dot.space }
{ % Stack in: ... R S T Stack out: ... R T File out: S<dot><space>
's :=
output.state mid.sentence = % { "<DEBUG output.nonnull.dot.space>. " * write$ }
{
". " * write$
}
{
output.state after.block =
{
add.period$ writeln "\newblock " write$
}
{
output.state before.all =
{
write$
}
{
add.period$ " " * write$
}
if$
}
if$
mid.sentence 'output.state :=
}
if$
s
}
FUNCTION { output.nonnull.remove }
{ % Stack in: ... R S T Stack out: ... R T File out: S<space>
's :=
output.state mid.sentence =
{
" " * write$
}
{
output.state after.block =
{
add.period$ writeln "\newblock " write$
}
{
output.state before.all =
{
write$
}
{
add.period$ " " * write$
}
if$
}
if$
mid.sentence 'output.state :=
}
if$
s
}
FUNCTION { output.nonnull.removenospace }
{ % Stack in: ... R S T Stack out: ... R T File out: S
's :=
output.state mid.sentence =
{
"" * write$
}
{
output.state after.block =
{
add.period$ writeln "\newblock " write$
}
{
output.state before.all =
{
write$
}
{
add.period$ " " * write$
}
if$
}
if$
mid.sentence 'output.state :=
}
if$
s
}
FUNCTION { output }
{ % discard top token if empty, else like output.nonnull
duplicate$ empty.or.unknown
'pop$
'output.nonnull
if$
}
FUNCTION { output.dot.space }
{ % discard top token if empty, else like output.nonnull.dot.space
duplicate$ empty.or.unknown
'pop$
'output.nonnull.dot.space
if$
}
FUNCTION { output.removenospace }
{ % discard top token if empty, else like output.nonnull.removenospace
duplicate$ empty.or.unknown
'pop$
'output.nonnull.removenospace
if$
}
FUNCTION { output.check }
{ % like output, but warn if key name on top-of-stack is not set
't :=
duplicate$ empty.or.unknown
{ pop$ "empty " t * " in " * cite$ * warning$ }
'output.nonnull
if$
}
FUNCTION { bibinfo.output.check }
{ % like output.check, adding bibinfo field
't :=
duplicate$ empty.or.unknown
{ pop$ "empty " t * " in " * cite$ * warning$ }
{ "\bibinfo{" t "}{" * * swap$ * "}" *
output.nonnull }
if$
}
FUNCTION { output.check.dot.space }
{ % like output.dot.space, but warn if key name on top-of-stack is not set
't :=
duplicate$ empty.or.unknown
{ pop$ "empty " t * " in " * cite$ * warning$ }
'output.nonnull.dot.space
if$
}
FUNCTION { fin.block }
{ % functionally, but not logically, identical to fin.entry
add.period$
writeln
}
FUNCTION { fin.entry }
{
add.period$
writeln
}
FUNCTION { new.sentence }
{ % update sentence state, with neither output nor stack change
output.state after.block =
'skip$
{
output.state before.all =
'skip$
{ after.sentence 'output.state := }
if$
}
if$
}
FUNCTION { fin.sentence }
{
add.period$
write$
new.sentence
""
}
FUNCTION { new.block }
{
output.state before.all =
'skip$
{ after.block 'output.state := }
if$
}
FUNCTION { output.coden } % UTAH
{ % output non-empty CODEN as one-line sentence (stack untouched)
coden empty.or.unknown
{ }
{ "\showCODEN{" coden * "}" * writeln }
if$
}
%
% Sometimes articleno starts with the word 'Article' or 'Paper.
% (this is a bug of acmdl, sigh)
% We strip them. We assume eid or articleno is already on stack
%
FUNCTION { strip.articleno.or.eid }
{
't :=
t #1 #7 substring$ "Article" =
{t #8 t text.length$ substring$ 't :=}
{ }
if$
t #1 #7 substring$ "article" =
{t #8 t text.length$ substring$ 't :=}
{ }
if$
t #1 #5 substring$ "Paper" =
{t #6 t text.length$ substring$ 't :=}
{ }
if$
t #1 #5 substring$ "paper" =
{t #6 t text.length$ substring$ 't :=}
{ }
if$
% Strip any left trailing space or ~
t #1 #1 substring$ " " =
{t #2 t text.length$ substring$ 't :=}
{ }
if$
t #1 #1 substring$ "~" =
{t #2 t text.length$ substring$ 't :=}
{ }
if$
t
}
FUNCTION { format.articleno }
{
articleno empty.or.unknown not eid empty.or.unknown not and
{ "Both articleno and eid are defined for " cite$ * warning$ }
'skip$
if$
articleno empty.or.unknown eid empty.or.unknown and
{ "" }
{
numpages empty.or.unknown
{ "articleno or eid field, but no numpages field, in "
cite$ * warning$ }
{ }
if$
eid empty.or.unknown
{ "Article \bibinfo{articleno}{" articleno strip.articleno.or.eid * "}" * }
{ "Article \bibinfo{articleno}{" eid strip.articleno.or.eid * "}" * }
if$
}
if$
}
FUNCTION { format.year }
{ % push year string or "[n.\,d.]" onto output stack
%% Because year is a mandatory field, we always force SOMETHING
%% to be output
"\bibinfo{year}{"
year empty.or.unknown
{ "[n.\,d.]" }
{ year }
if$
* "}" *
}
FUNCTION { format.day.month }
{ % push "day month " or "month " or "" onto output stack
day empty.or.unknown
{
month empty.or.unknown
{ "" }
{ "\bibinfo{date}{" month * "} " *}
if$
}
{
month empty.or.unknown
{ "" }
{ "\bibinfo{date}{" day * " " * month * "} " *}
if$
}
if$
}
FUNCTION { format.day.month.year } % UTAH
{ % if month is empty, push "" else push "(MON.)" or "(DD MON.)"
% Needed for frequent periodicals: 2008. ... New York Times C-1, C-2, C-17 (23 Oct.)
% acm-*.bst addition: prefix parenthesized date string with
% ", Article nnn "
articleno empty.or.unknown eid empty.or.unknown and
{ "" }
{ output.state after.block =
{", " format.articleno * }
{ format.articleno }
if$
}
if$
" (" * format.day.month * format.year * ")" *
}
FUNCTION { output.day.month.year } % UTAH
{ % if month is empty value, do nothing; else output stack top and
% leave with new top string "(MON.)" or "(DD MON.)"
% Needed for frequent periodicals: 2008. ... New York Times C-1, C-2, C-17 (23 Oct.)
format.day.month.year
output.nonnull.remove
}
FUNCTION { strip.doi } % UTAH
{ % Strip any Web address prefix to recover the bare DOI, leaving the
% result on the output stack, as recommended by CrossRef DOI
% documentation.
% For example, reduce "http://doi.acm.org/10.1145/1534530.1534545" to
% "10.1145/1534530.1534545". A suitable URL is later typeset and
% displayed as the LAST item in the reference list entry. Publisher Web
% sites wrap this with a suitable link to a real URL to resolve the DOI,
% and the master https://doi.org/ address is preferred, since publisher-
% specific URLs can disappear in response to economic events. All
% journals are encouraged by the DOI authorities to use that typeset
% format and link procedures for uniformity across all publications that
% include DOIs in reference lists.
% The numeric prefix is guaranteed to start with "10.", so we use
% that as a test.
% 2017-02-04 Added stripping of https:// (Boris)
doi #1 #3 substring$ "10." =
{ doi }
{
doi 't := % get modifiable copy of DOI
% Change https:// to http:// to strip both prefixes (BV)
t #1 #8 substring$ "https://" =
{ "http://" t #9 t text.length$ #8 - substring$ * 't := }
{ }
if$
t #1 #7 substring$ "http://" =
{
t #8 t text.length$ #7 - substring$ 't :=
"INTERNAL STYLE-FILE ERROR" 's :=
% search for next "/" and assign its suffix to s
{ t text.length$ }
{
t #1 #1 substring$ "/" =
{
% save rest of string as true DOI (should be 10.xxxx/yyyy)
t #2 t text.length$ #1 - substring$ 's :=
"" 't := % empty string t terminates the loop
}
{
% discard first character and continue loop: t <= substring(t,2,last)
t #2 t text.length$ #1 - substring$ 't :=
}
if$
}
while$
% check for valid DOI (should be 10.xxxx/yyyy)
s #1 #3 substring$ "10." =
{ }
{ "unrecognized DOI substring " s * " in DOI value [" * doi * "]" * warning$ }
if$
s % push the stripped DOI on the output stack
}
{
"unrecognized DOI value [" doi * "]" * warning$
doi % push the unrecognized original DOI on the output stack
}
if$
}
if$
}
%
% Change by BV: added standard prefix to URL
%
FUNCTION { output.doi } % UTAH
{ % output non-empty DOI as one-line sentence (stack untouched)
doi empty.or.unknown
{ }
{
%% Use \urldef here for the same reason it is used in output.url,
%% see output.url for further discussion.
"\urldef\tempurl%" writeln
"\url{https://doi.org/" strip.doi * "}" * writeln
"\showDOI{\tempurl}" writeln
}
if$
}
FUNCTION { output.isbn } % UTAH
{ % output non-empty ISBN-10 and/or ISBN-13 as one-line sentences (stack untouched)
show-isbn-10-and-13
{
%% show both 10- and 13-digit ISBNs
isbn empty.or.unknown
{ }
{
"\showISBNx{" isbn * "}" * writeln
}
if$
isbn-13 empty.or.unknown
{ }
{
"\showISBNxiii{" isbn-13 * "}" * writeln
}
if$
}
{
%% show 10-digit ISBNs only if 13-digit ISBNs not available
isbn-13 empty.or.unknown
{
isbn empty.or.unknown
{ }
{
"\showISBNx{" isbn * "}" * writeln
}
if$
}
{
"\showISBNxiii{" isbn-13 * "}" * writeln
}
if$
}
if$
}
FUNCTION { output.issn } % UTAH
{ % output non-empty ISSN as one-line sentence (stack untouched)
issn empty.or.unknown
{ }
{ "\showISSN{" issn * "}" * writeln }
if$
}
FUNCTION { output.issue }
{ % output non-empty issue number as a one-line sentence (stack untouched)
issue empty.or.unknown
{ }
{ "Issue " issue * "." * writeln }
if$
}
FUNCTION { output.lccn } % UTAH
{ % return with stack untouched
lccn empty.or.unknown
{ }
{ "\showLCCN{" lccn * "}" * writeln }
if$
}
FUNCTION { output.note } % UTAH
{ % return with stack empty
note empty.or.unknown
{ }
{ "\shownote{" note add.period$ * "}" * writeln }
if$
}
FUNCTION { output.note.check } % UTAH
{ % return with stack empty
note empty.or.unknown
{ "empty note in " cite$ * warning$ }
{ "\shownote{" note add.period$ * "}" * writeln }
if$
}
FUNCTION { output.eprint } %
{ % return with stack empty
eprint empty.or.unknown
{ }
{ "\showeprint"
archiveprefix empty.or.unknown
{ eprinttype empty.or.unknown
{ }
{ "[" eprinttype "]" * * * }
if$
}
{ "[" archiveprefix "l" change.case$ "]" * * * }
if$
"{" eprint "}" * * *
primaryclass empty.or.unknown
{ eprintclass empty.or.unknown
{ }
{ "~[" eprintclass "]" * * * }
if$
}
{ "~[" primaryclass "]" * * * }
if$
writeln
}
if$
}
%
% Changes by BV 2011/04/15. Do not output
% url if doi is defined
%
FUNCTION { output.url } % UTAH
{ % return with stack untouched
% output URL and associated lastaccessed fields
doi empty.or.unknown
{
url empty.or.unknown
{ }
{
%% Use \urldef, outside \showURL, so that %nn, #, etc in URLs work
%% correctly. Put the actual URL on its own line to reduce the
%% likelihood of BibTeX's nasty line wrapping after column 79.
%% \url{} can undo this, but if that doesn't work for some reason
%% the .bbl file would have to be repaired manually.
"\urldef\tempurl%" writeln
"\url{" url * "}" * writeln
"\showURL{%" writeln
lastaccessed empty.or.unknown
{ "" }
{ "Retrieved " lastaccessed * " from " * }
if$
"\tempurl}" * writeln
}
if$
}
{ }
if$
}
FUNCTION { output.year.check }
{ % warn if year empty, output top string and leave " YEAR<label>" on stack in mid-sentence
year empty.or.unknown
{ "empty year in " cite$ * warning$
write$
" \bibinfo{year}{[n.d.]}"
"\natexlab{" extra.label * "}" * *
mid.sentence 'output.state :=
}
{ write$
" \bibinfo{year}{" year * "}" *
"\natexlab{" extra.label * "}" * *
mid.sentence 'output.state :=
}
if$
}
FUNCTION { le }
{
%% test whether first number is less than or equal to second number
%% stack in: n1 n2
%% stack out: if n1 <= n2 then 1 else 0
%% "DEBUG: le " cite$ * warning$
> { #0 } { #1 } if$
}
FUNCTION { ge }
{
%% test whether first number is greater than or equal to second number
%% stack in: n1 n2
%% stack out: if n1 >= n2 then 1 else 0
%% "DEBUG: ge " cite$ * warning$
< { #0 } { #1 } if$
}
FUNCTION { is.leading.digit }
{
%% test whether first character of string is a digit
%% stack in: string
%% stack out: if first-char-is-digit then 1 else 0
#1 #1 substring$ % replace string by string[1:1]
duplicate$ % string[1:1] string[1:1]
chr.to.int$
"0" chr.to.int$ swap$ le % "0" <= string[1:1] --> 0-or-1
swap$ % 0-or-1 string[1:1]
chr.to.int$
"9" chr.to.int$ le % string[1:1} <= "9" --> 0-or-1
and
}
FUNCTION { skip.digits }
{
%% skip over leading digits in string
%% stack in: string
%% stack out: rest-of-string leading-digits
%% "DEBUG: enter skip.digits " cite$ * warning$
%% dump.stack.1
duplicate$
't :=
't.org :=
"" 'u :=
{ t text.length$ }
{
%% "=================DEBUG: skip.digits t = [" t * "]" * warning$
t is.leading.digit
{ t #2 t text.length$ #1 - substring$ }
{
t 'u :=
""
}
if$
't :=
}
while$
u % rest of string
t.org #1 t.org text.length$ u text.length$ - substring$ % leading digits
%% "DEBUG: t.org = [" t.org * "]" * warning$
%% "DEBUG: u = [" u * "]" * warning$
%% dump.stack.2
%% "DEBUG: leave skip.digits " cite$ * warning$
}
FUNCTION { skip.nondigits }
{
%% skip over leading nondigits in string
%% stack in: string
%% stack out: rest-of-string
%% "DEBUG: enter skip.nondigits " cite$ * warning$
't :=
"" 'u :=
{ t text.length$ }
{
%% "=================DEBUG: skip.nondigits t = [" t * "]" * warning$
t is.leading.digit
{
t 'u :=
""
}
{ t #2 t text.length$ #1 - substring$ }
if$
't :=
}
while$
u % rest of string
%% dump.stack.1
%% "DEBUG: leave skip.nondigits " cite$ * warning$
}
FUNCTION { parse.next.number }
{
%% stack in: string
%% stack out: rest-of-string next-numeric-part-of-string
%% Example:
%% stack in: "123:1--123:59"
%% stack out: ":1--123:59" "123"
's :=
s skip.nondigits 's :=
s skip.digits
}
FUNCTION { reduce.pages.to.page.count }
{
%% Stack in: arbitrary-and-unused
%% Stack out: unchanged
%%
%% For the new-style pagination with article number and numpages or
%% pages, we expect to have BibTeX entries containing something like
%% articleno = "17",
%% pages = "1--23",
%% with output "Article 17, 23 pages",
%% or
%% articleno = "17",
%% numpages = "23",
%% with output "Article 17, 23 pages",
%% or
%% articleno = "17",
%% pages = "17:1--17:23",
%% with output "Article 17, 23 pages",
%%
%% If articleno is missing or empty, then we should output "1--23",
%% "23" (with a warning of a missing articleno), or "17:1--17:23",
%% respectively.
%% "DEBUG: enter reduce.pages.to.page.count " cite$ * warning$
%% "DEBUG: pages = [" pages * "]" * warning$
pages
parse.next.number 'p1 :=
parse.next.number 'p2 :=
parse.next.number 'p3 :=
parse.next.number 'page.count :=
duplicate$
empty.or.unknown
{ }
{
duplicate$ "unexpected trailing garbage [" swap$ *
"] after n:p1--n:p2 in pages = [" *
pages *
"] in " *
cite$ *
warning$
}
if$
pop$
%% "DEBUG: reduce.pages.to.page.count: "
%% " p1 = " p1 * *
%% " p2 = " p2 * *
%% " p3 = " p3 * *
%% " p4 = " page.count * *
%% " in " cite$ * * warning$
p1 p3 = p2 "1" = and numpages empty.or.unknown and
{ "INFO: reduced pages = [" pages * "] to numpages = [" * page.count * "]" * warning$ }
{
numpages empty.or.unknown
{ pages }
{ numpages }
if$
'page.count :=
}
if$
p1 "1" = p3 empty.or.unknown and numpages empty.or.unknown and
{
p2 'page.count :=
"INFO: reduced pages = [" pages * "] to numpages = [" * page.count * "]" * warning$
}
{
numpages empty.or.unknown
{ pages }
{ numpages }
if$
'page.count :=
}
if$
%% "DEBUG: leave reduce.pages.to.page.count " cite$ * warning$
}
FUNCTION { new.block.checkb }
{ % issue a new.block only if at least one of top two stack strings is not empty
empty.or.unknown
swap$ empty.or.unknown
and
'skip$
'new.block
if$
}
FUNCTION { field.or.null }
{ % convert empty value to null string, else return value