2 * biblio.c: process the bibliography
8 static wchar_t *gentext(int num
) {
10 wchar_t *p
= text
+ lenof(text
);
15 *--p
= L
"0123456789"[num
% 10];
23 static void cite_biblio(keywordlist
*kl
, wchar_t *key
, filepos fpos
) {
24 keyword
*kw
= kw_lookup(kl
, key
);
26 err_nosuchkw(&fpos
, key
);
29 * We've found a \k reference. If it's a
30 * bibliography entry ...
32 if (kw
->para
->type
== para_Biblio
) {
34 * ... then mark the paragraph as cited.
36 kw
->para
->type
= para_BiblioCited
;
42 * Make a pass through the source form, generating citation formats
43 * for bibliography entries and also marking which bibliography
44 * entries are actually cited (or \nocite-ed).
47 void gen_citations(paragraph
*source
, keywordlist
*kl
) {
51 for (para
= source
; para
; para
= para
->next
) {
55 * \BR and \nocite paragraphs get special processing here.
57 if (para
->type
== para_BR
) {
58 keyword
*kw
= kw_lookup(kl
, para
->keyword
);
60 err_nosuchkw(¶
->fpos
, para
->keyword
);
61 } else if (kw
->text
) {
62 err_multiBR(¶
->fpos
, para
->keyword
);
64 kw
->text
= dup_word_list(para
->words
);
66 } else if (para
->type
== para_NoCite
) {
67 wchar_t *wp
= para
->keyword
;
69 cite_biblio(kl
, wp
, para
->fpos
);
75 * Scan for keyword references.
77 for (ptr
= para
->words
; ptr
; ptr
= ptr
->next
) {
78 if (ptr
->type
== word_UpperXref
||
79 ptr
->type
== word_LowerXref
)
80 cite_biblio(kl
, ptr
->text
, ptr
->fpos
);
85 * We're now almost done; all that remains is to scan through
86 * the cited bibliography entries and invent default citation
87 * texts for the ones that don't already have explicitly
90 for (para
= source
; para
; para
= para
->next
) {
91 if (para
->type
== para_BiblioCited
) {
92 keyword
*kw
= kw_lookup(kl
, para
->keyword
);
95 word
*wd
= smalloc(sizeof(word
));
96 wd
->text
= gentext(++bibnum
);
97 wd
->type
= word_Normal
;
102 para
->kwtext
= kw
->text
;