Man-page back end for Halibut. Also, a couple of additional markup
[sgt/halibut] / bk_whlp.c
index a8cb99e..a21ac04 100644 (file)
--- a/bk_whlp.c
+++ b/bk_whlp.c
@@ -50,6 +50,7 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
     struct bk_whlp_state state;
     WHLP_TOPIC contents_topic;
     int i;
+    int nesting;
     indexentry *ie;
 
     filename = "output.hlp";          /* FIXME: configurability */
@@ -216,6 +217,7 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
      * Now we've done the contents page, we're ready to go through
      * and do the main manual text. Ooh.
      */
+    nesting = 0;
     for (p = sourceform; p; p = p->next) switch (p->type) {
        /*
         * Things we ignore because we've already processed them or
@@ -231,6 +233,14 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
       case para_Title:
        break;
 
+      case para_LcontPush:
+       nesting++;
+       break;
+      case para_LcontPop:
+       assert(nesting > 0);
+       nesting--;
+       break;
+
        /*
         * Chapter and section titles: start a new Help topic.
         */
@@ -343,12 +353,14 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
        break;
 
       case para_Normal:
+      case para_DescribedThing:
+      case para_Description:
       case para_BiblioCited:
       case para_Bullet:
       case para_NumberedList:
        whlp_para_attr(h, WHLP_PARA_SPACEBELOW, 12);
        if (p->type == para_Bullet || p->type == para_NumberedList) {
-           whlp_para_attr(h, WHLP_PARA_LEFTINDENT, 72);
+           whlp_para_attr(h, WHLP_PARA_LEFTINDENT, 72*nesting + 72);
            whlp_para_attr(h, WHLP_PARA_FIRSTLINEINDENT, -36);
            whlp_set_tabstop(h, 72, WHLP_ALIGN_LEFT);
            whlp_begin_para(h, WHLP_PARA_SCROLL);
@@ -361,6 +373,8 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
            }
            whlp_tab(h);
        } else {
+           whlp_para_attr(h, WHLP_PARA_LEFTINDENT,
+                          72*nesting + (p->type==para_Description ? 72 : 0));
            whlp_begin_para(h, WHLP_PARA_SCROLL);
        }
 
@@ -386,6 +400,7 @@ void whlp_backend(paragraph *sourceform, keywordlist *keywords,
            for (w = p->words; w; w = w->next) {
                if (!w->next)
                    whlp_para_attr(h, WHLP_PARA_SPACEBELOW, 12);
+               whlp_para_attr(h, WHLP_PARA_LEFTINDENT, 72*nesting);
                whlp_begin_para(h, WHLP_PARA_SCROLL);
                whlp_set_font(h, FONT_CODE);
                whlp_convert(w->text, &c, FALSE);
@@ -479,22 +494,25 @@ static void whlp_mkparagraph(struct bk_whlp_state *state,
       case word_LowerXref:
        if (subsidiary) break;         /* disabled in subsidiary bits */
         kwl = kw_lookup(state->keywords, text->text);
-       assert(xref_target == NULL);
-       if (kwl->para->type == para_NumberedList) {
-           break;                     /* don't xref to numbered list items */
-       } else if (kwl->para->type == para_BiblioCited) {
-           /*
-            * An xref to a bibliography item jumps to the section
-            * containing it.
-            */
-           if (kwl->para->parent)
-               xref_target = kwl->para->parent;
-           else
-               break;
-       } else {
-           xref_target = kwl->para;
-       }
-       whlp_start_hyperlink(state->h, (WHLP_TOPIC)xref_target->private_data);
+        assert(xref_target == NULL);
+        if (kwl) {
+            if (kwl->para->type == para_NumberedList) {
+                break;                /* don't xref to numbered list items */
+            } else if (kwl->para->type == para_BiblioCited) {
+                /*
+                 * An xref to a bibliography item jumps to the section
+                 * containing it.
+                 */
+                if (kwl->para->parent)
+                    xref_target = kwl->para->parent;
+                else
+                    break;
+            } else {
+                xref_target = kwl->para;
+            }
+            whlp_start_hyperlink(state->h,
+                                 (WHLP_TOPIC)xref_target->private_data);
+        }
        break;
 
       case word_XrefEnd: