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"
19 #define NFLAB 3000 /* number of bytes to record all labels */
20 #define NLABC 1000 /* max number of labels */
22 static char sig
[MXSIG
];
23 static char bflab
[NFLAB
];
24 static char *labtab
[NLABC
];
25 static char *lbp
= bflab
;
26 static char labc
[NLABC
];
27 static char stbuff
[50];
36 char keylet(char *, int);
37 static void initadd(char *, char *, char *);
38 static void mycpy(char *, char *);
39 static void mycpy2(char *, char *, int);
40 void tokeytab(char *, int);
42 /* choose signal style */
44 putsig(int nf
, char *flds
[], int nref
, char *nstline
,
45 char *endline
, int toindex
)
47 char t
[100], t1
[MXSIG
], t2
[100], format
[10], *sd
, *stline
;
48 int addon
, another
= 0;
49 static FILE *fhide
= 0;
54 if (nf
== 0) /* old */
55 sprintf(t
, "%s%c", labtab
[nref
], labc
[nref
]);
59 fpar(nf
, flds
, t
, keywant
, 1, 0);
60 if (science
&& t
[0] == 0) {
61 if (fpar(nf
, flds
, t
, 'A', 1, 0) != 0) {
62 if (fpar(nf
, flds
, t2
, 'D',
68 } else if (t
[0] == 0) {
70 nmlen
> 0 ? "%%.%ds%%s" : "%%s%%s",
72 /* format is %s%s for default labels */
73 /* or %.3s%s eg if wanted */
74 if (fpar(nf
, flds
, t2
, 'D', 1, 0)) {
77 int n
= strlen(sd
) - dtlen
;
85 fpar(nf
, flds
, t1
, 'A', 1, 0);
86 sprintf(t
, format
, t1
, sd
);
90 for (sd
= t
; *sd
; sd
++)
97 if ((!keywant
|| addon
) && !science
) {
98 addch(t
, keylet(t
, nref
));
105 sprintf(t
, "%c%d%c", FLAG
, nref
, FLAG
);
107 sprintf(t
, "%d", nref
);
109 another
= (sd
= lookat()) ? prefix(".[", sd
) : 0;
110 if (another
&& (strcmp(".[\n", sd
) != SAME
))
111 fprintf(stderr
, (char *)gettext(
112 "File %s line %d: punctuation ignored from: %s"),
114 if ((strlen(sig
) + strlen(t
)) > MXSIG
)
115 err(gettext("sig overflow (%d)"), MXSIG
);
118 fprintf(stderr
, "sig is now %s leng %d\n", sig
, strlen(sig
));
124 strcpy(stline
, nstline
);
127 if (stline
[2] || endline
[2]) {
140 sprintf(t1
, "%s%s%s\n", stline
, sig
, endline
);
141 if (strlen(t1
) > MXSIG
)
142 err(gettext("t1 overflow (%d)"), MXSIG
);
150 fhide
= fopen(hidenam
, "r");
152 while ((ch
= getc(fhide
)) != EOF
)
162 * Seperate reference numbers with AFLAG
163 * for later sorting and condensing.
169 if (fo
== ftemp
) { /* hide if need be */
170 sprintf(hidenam
, "/tmp/rj%dc", getpid());
172 fprintf(stderr
, "hiding in %s\n", hidenam
);
174 fhide
= fopen(hidenam
, "w");
177 "Can't get scratch file %s"),
184 if (nf
> 0 && toindex
)
185 fprintf(fo
, ".ds [F %s%c", t
, sep
);
189 fprintf(stderr
, "sig is now %s\n", sig
);
194 fpar(int nf
, char *flds
[], char *out
, int c
, int seq
, int prepend
)
199 for (i
= 0; i
< nf
; i
++)
200 if (flds
[i
][1] == c
&& ++fnd
>= seq
) {
201 /* for titles use first word otherwise last */
202 if (c
== 'T' || c
== 'J') {
206 if (prefix("An ", p
))
208 if (prefix("The ", p
))
213 /* if its not 'L' then use just the last word */
218 while (p
> s
&& *p
!= ' ')
221 /* special wart for authors */
222 if (c
== 'A' && (p
[-1] == ',' || p
[1] == '(')) {
224 while (p
> s
&& *p
!= ' ')
229 if (c
== 'A' && prepend
)
230 initadd(out
, flds
[i
]+2, p
);
237 putkey(int nf
, char *flds
[], int nref
, char *keystr
)
242 fprintf(fo
, ".\\\"");
244 fprintf(fo
, "%s%c%c", labtab
[nref
], labc
[nref
], sep
);
246 while (ctype
= *keystr
++) {
247 count
= atoi(keystr
);
252 for (i
= 1; i
<= count
; i
++) {
253 sf
= fpar(nf
, flds
, t1
, ctype
, i
, 1);
257 fprintf(fo
, "%s%c", sf
, '-');
260 fprintf(fo
, "%c%d%c%c", FLAG
, nref
, FLAG
, sep
);
266 tokeytab(char *t
, int nref
)
268 strcpy(labtab
[nref
] = lbp
, t
);
274 keylet(char *t
, int nref
)
279 for (i
= 1; i
< nref
; i
++) {
280 if (strcmp(labtab
[i
], t
) == 0)
284 if (lbp
-bflab
> NFLAB
)
285 err(gettext("bflab overflow (%d)"), NFLAB
);
287 err(gettext("nref in labc overflow (%d)"), NLABC
);
289 fprintf(stderr
, "lbp up to %d of %d\n", lbp
-bflab
, NFLAB
);
291 return (labc
[nref
] = x
+1);
295 mycpy(char *s
, char *t
)
297 while (*t
&& *t
!= ',' && *t
!= ' ')
303 mycpy2(char *s
, char *t
, int n
)
307 while (n
-- && (c
= *t
++) > 0) {
316 initadd(char *to
, char *from
, char *stop
)
322 while (from
< stop
) {
336 static char *articles
[] = {
337 "the ", "an ", "a ", 0
341 artskp(s
) /* skips over initial "a ", "an ", "the " in s */
347 for (p
= articles
; *p
; p
++) {
349 for (r1
= *p
; ((*r1
^ *r2
) & ~040) == 0; r1
++)
351 if (*r1
== 0 && *r2
!= 0)