2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley software License Agreement
12 * specifies the terms and conditions for redistribution.
15 #pragma ident "%Z%%M% %I% %E% SMI"
18 #define dsde (macro? "de" : "ds")
19 #define ifnl (macro? sep : ' ')
22 extern char *mindex();
24 int hastype(int, char *[], char);
25 static char last(char *);
26 char *class(int, char *[]);
27 char *caps(char *, char *);
28 char *revauth(char *, char *);
31 putref(int n
, char *tvec
[])
34 char buf1
[BUFSIZ
], buf2
[50];
35 int nauth
= 0, i
, lastype
= 0, cch
, macro
= 0, la
;
36 int lauth
= 0, ltitle
= 0, lother
= 0;
38 fprintf(fo
, ".]-%c", sep
);
39 for (i
= 0; i
< n
; i
++) {
45 fprintf(fo
, "..%c", sep
);
60 fprintf(stderr
, "smallcaps %s cch %c\n", smallcaps
, cch
);
62 if (mindex(smallcaps
, cch
))
65 fprintf(stderr
, " s %o tx %o %s\n", s
, tx
, tx
);
67 if (!control(s
[0])) { /* append to previous item */
70 fprintf(fo
, "%s%c", tx
, sep
);
72 fprintf(fo
, ".as [%c \" %s%c",
75 ltitle
= (mindex(".;,?",
78 lauth
= last(tx
) == '.';
82 if (mindex("XYZ[]", cch
)) { /* skip these */
88 tx
= revauth(tx
, buf2
);
91 fprintf(fo
, ".de [%c%c%s%c",
94 fprintf(fo
, ".ds [%c%s%c",
97 la
= (tvec
[i
+1][1] != 'A');
98 fprintf(fo
, ".as [A \"");
99 if (la
== 0 || nauth
!= 2)
103 mindex(smallcaps
, 'A') ?
104 " \\s-2AND\\s+2" : " and");
105 fprintf(fo
, "%s%c", tx
, sep
);
107 lauth
= last(tx
) == '.';
110 fprintf(fo
, ".de [%c%c%s%c",
113 fprintf(fo
, ".ds [%c%s%c",
118 fprintf(fo
, ".nr [P %d%c", mindex(s
, '-') != 0, sep
);
121 ltitle
= (mindex(".;,?", last(tx
)) != 0);
123 lother
= (mindex(".;,?", last(tx
)) != 0);
125 if (lastype
&& macro
)
126 fprintf(fo
, "..%c", sep
);
127 fprintf(fo
, ".nr [T %d%c", ltitle
, sep
);
128 fprintf(fo
, ".nr [A %d%c", lauth
, sep
);
129 fprintf(fo
, ".nr [O %d%c", lother
, sep
);
130 fprintf(fo
, ".][ %s%c", class(n
, tvec
), '\n');
134 tabs(char *sv
[], char *line
)
140 for (p
= line
; *p
; p
++) {
150 class(int nt
, char *tv
[])
152 if (hastype(nt
, tv
, 'J'))
153 return ("1 journal-article");
154 if (hastype(nt
, tv
, 'B'))
155 return ("3 article-in-book");
156 if (hastype(nt
, tv
, 'R'))
157 return ("4 tech-report");
158 if (hastype(nt
, tv
, 'G'))
159 return ("4 tech-report");
160 if (hastype(nt
, tv
, 'I'))
162 if (hastype(nt
, tv
, 'M'))
163 return ("5 bell-tm");
168 hastype(int nt
, char *tv
[], char c
)
171 for (i
= 0; i
< nt
; i
++)
172 if (control(tv
[i
][0]) && tv
[i
][1] == c
)
178 caps(char *a
, char *b
)
187 if (this && alph
== 1) {
193 if (!this && alph
> 1) {
202 alph
= this ? alph
+1 : 0;
215 revauth(char *s
, char *b
)
217 char *init
, *name
, *jr
, *p
, *bcop
;
224 while (name
> init
&& *name
!= ' ')
226 if (name
[-1] == ',' || name
[-1] == '(') {
228 while (name
> init
&& *name
!= ' ')