Man-page back end for Halibut. Also, a couple of additional markup
[sgt/halibut] / bk_text.c
index b682b42..989cdbf 100644 (file)
--- a/bk_text.c
+++ b/bk_text.c
@@ -96,7 +96,7 @@ static textconfig text_configure(paragraph *source) {
            } else if (!ustricmp(source->keyword, L"text-chapter-numeric")) {
                ret.achapter.just_numbers = utob(uadv(source->keyword));
            } else if (!ustricmp(source->keyword, L"text-chapter-suffix")) {
-               ret.achapter.number_suffix = uadv(source->keyword);
+               ret.achapter.number_suffix = ustrdup(uadv(source->keyword));
            } else if (!ustricmp(source->keyword, L"text-section-align")) {
                wchar_t *p = uadv(source->keyword);
                int n = 0;
@@ -156,7 +156,7 @@ static textconfig text_configure(paragraph *source) {
                        ret.asect[i] = ret.asect[ret.nasect-1];
                    ret.nasect = n+1;
                }
-               ret.asect[n].number_suffix = p;
+               ret.asect[n].number_suffix = ustrdup(p);
            } else if (!ustricmp(source->keyword, L"text-title-align")) {
                ret.atitle.align = utoalign(uadv(source->keyword));
            } else if (!ustricmp(source->keyword, L"text-title-underline")) {
@@ -182,6 +182,7 @@ void text_backend(paragraph *sourceform, keywordlist *keywords,
     word spaceword;
     FILE *fp;
     char *prefixextra;
+    int nesting, nestindent;
     int indentb, indenta;
 
     IGNORE(keywords);                 /* we don't happen to need this */
@@ -219,9 +220,20 @@ void text_backend(paragraph *sourceform, keywordlist *keywords,
                      conf.indent_preambles ? conf.indent : 0, 0,
                      conf.width + (conf.indent_preambles ? 0 : conf.indent));
 
+    nestindent = conf.listindentbefore + conf.listindentafter;
+    nesting = 0;
+
     /* Do the main document */
     for (p = sourceform; p; p = p->next) switch (p->type) {
 
+      case para_LcontPush:
+       nesting++;
+       break;
+      case para_LcontPop:
+       assert(nesting > 0);
+       nesting--;
+       break;
+
        /*
         * Things we ignore because we've already processed them or
         * aren't going to touch them in this pass.
@@ -254,10 +266,13 @@ void text_backend(paragraph *sourceform, keywordlist *keywords,
        break;
 
       case para_Rule:
-       text_rule(fp, conf.indent, conf.width);
+       text_rule(fp, conf.indent + nestindent*nesting,
+                 conf.width - nestindent*nesting);
        break;
 
       case para_Normal:
+      case para_DescribedThing:
+      case para_Description:
       case para_BiblioCited:
       case para_Bullet:
       case para_NumberedList:
@@ -271,6 +286,11 @@ void text_backend(paragraph *sourceform, keywordlist *keywords,
            prefixextra = ".";         /* FIXME: configurability */
            indentb = conf.listindentbefore;
            indenta = conf.listindentafter;
+       } else if (p->type == para_Description) {
+           prefix = NULL;
+           prefixextra = NULL;
+           indentb = conf.listindentbefore;
+           indenta = conf.listindentafter;
        } else {
            prefix = NULL;
            prefixextra = NULL;
@@ -289,8 +309,8 @@ void text_backend(paragraph *sourceform, keywordlist *keywords,
            body = p->words;
        }
        text_para(fp, prefix, prefixextra, body,
-                 conf.indent + indentb, indenta,
-                 conf.width - indentb - indenta);
+                 conf.indent + nestindent*nesting + indentb, indenta,
+                 conf.width - nestindent*nesting - indentb - indenta);
        if (wp) {
            wp->next = NULL;
            free_word_list(body);
@@ -298,7 +318,9 @@ void text_backend(paragraph *sourceform, keywordlist *keywords,
        break;
 
       case para_Code:
-       text_codepara(fp, p->words, conf.indent + conf.indent_code, conf.width - 2 * conf.indent_code);
+       text_codepara(fp, p->words,
+                     conf.indent + nestindent*nesting + conf.indent_code,
+                     conf.width - nestindent*nesting - 2 * conf.indent_code);
        break;
     }
 
@@ -313,7 +335,14 @@ void text_backend(paragraph *sourceform, keywordlist *keywords,
      * Tidy up
      */
     fclose(fp);
-    sfree(conf.bullet.text);
+    {
+       int i;
+       sfree(conf.achapter.number_suffix);
+       for (i = 0; i < conf.nasect; i++)
+           sfree(conf.asect[i].number_suffix);
+       sfree(conf.asect);
+       sfree(conf.bullet.text);
+    }
 }
 
 /*