+ * Format the contents entry for each heading.
+ */
+ {
+ word *contents_title;
+ contents_title = fake_word(L"Contents");
+
+ firstcont = make_para_data(para_UnnumberedChapter, 0, 0, 0,
+ NULL, NULL, contents_title, conf);
+ lastcont = firstcont;
+ lastcont->next = NULL;
+ firstcontline = firstcont->first;
+ lastcontline = lastcont->last;
+ for (p = sourceform; p; p = p->next) {
+ word *words;
+ int indent;
+
+ switch (p->type) {
+ case para_Chapter:
+ case para_Appendix:
+ case para_UnnumberedChapter:
+ case para_Heading:
+ case para_Subsect:
+ switch (p->type) {
+ case para_Chapter:
+ case para_Appendix:
+ words = prepare_contents_title(p->kwtext, L": ", p->words);
+ indent = 0;
+ break;
+ case para_UnnumberedChapter:
+ words = prepare_contents_title(NULL, NULL, p->words);
+ indent = 0;
+ break;
+ case para_Heading:
+ case para_Subsect:
+ words = prepare_contents_title(p->kwtext2, L" ", p->words);
+ indent = (p->aux + 1) * conf->contents_indent_step;
+ break;
+ }
+ pdata = make_para_data(para_Normal, p->aux, indent,
+ conf->contents_margin,
+ NULL, NULL, words, conf);
+ pdata->next = NULL;
+ pdata->contents_entry = p;
+ lastcont->next = pdata;
+ lastcont = pdata;
+
+ /*
+ * Link all contents line structures together into
+ * a big list.
+ */
+ if (pdata->first) {
+ if (lastcontline) {
+ lastcontline->next = pdata->first;
+ pdata->first->prev = lastcontline;
+ } else {
+ firstcontline = pdata->first;
+ pdata->first->prev = NULL;
+ }
+ lastcontline = pdata->last;
+ lastcontline->next = NULL;
+ }
+
+ break;
+ }
+ }
+ }
+
+ /*
+ * Do the main paragraph formatting.