Remove the svn:externals property that pulls a copy of libcharset
[sgt/halibut] / bk_man.c
index 7271428..21e33f3 100644 (file)
--- a/bk_man.c
+++ b/bk_man.c
@@ -69,9 +69,7 @@ static manconfig man_configure(paragraph *source) {
                ret.th = snewn(ep - wp + 1, wchar_t);
                memcpy(ret.th, wp, (ep - wp + 1) * sizeof(wchar_t));
            } else if (!ustricmp(p->keyword, L"man-charset")) {
-               char *csname = utoa_dup(uadv(p->keyword), CS_ASCII);
-               ret.charset = charset_from_localenc(csname);
-               sfree(csname);
+               ret.charset = charset_from_ustr(&p->fpos, uadv(p->keyword));
            } else if (!ustricmp(p->keyword, L"man-headnumbers")) {
                ret.headnumbers = utob(uadv(p->keyword));
            } else if (!ustricmp(p->keyword, L"man-mindepth")) {
@@ -126,6 +124,7 @@ void man_backend(paragraph *sourceform, keywordlist *keywords,
     paragraph *p;
     FILE *fp;
     manconfig conf;
+    int had_described_thing;
 
     IGNORE(unused);
     IGNORE(keywords);
@@ -167,6 +166,13 @@ void man_backend(paragraph *sourceform, keywordlist *keywords,
 
     fprintf(fp, ".UC\n");
 
+    had_described_thing = FALSE;
+#define cleanup_described_thing do { \
+    if (had_described_thing) \
+       fprintf(fp, "\n"); \
+    had_described_thing = FALSE; \
+} while (0)
+
     for (p = sourceform; p; p = p->next) switch (p->type) {
        /*
         * Things we ignore because we've already processed them or
@@ -189,6 +195,7 @@ void man_backend(paragraph *sourceform, keywordlist *keywords,
       case para_Heading:
       case para_Subsect:
 
+       cleanup_described_thing;
        {
            int depth;
            if (p->type == para_Subsect)
@@ -198,7 +205,10 @@ void man_backend(paragraph *sourceform, keywordlist *keywords,
            else
                depth = 0;
            if (depth >= conf.mindepth) {
-               fprintf(fp, ".SH \"");
+               if (depth > conf.mindepth)
+                   fprintf(fp, ".SS \"");
+               else
+                   fprintf(fp, ".SH \"");
                if (conf.headnumbers && p->kwtext) {
                    man_text(fp, p->kwtext, FALSE, QUOTE_QUOTES, &conf);
                    fprintf(fp, " ");
@@ -213,6 +223,7 @@ void man_backend(paragraph *sourceform, keywordlist *keywords,
         * Code paragraphs.
         */
       case para_Code:
+       cleanup_described_thing;
        fprintf(fp, ".PP\n");
        man_codepara(fp, p->words, conf.charset);
        break;
@@ -222,6 +233,7 @@ void man_backend(paragraph *sourceform, keywordlist *keywords,
         */
       case para_Normal:
       case para_Copyright:
+       cleanup_described_thing;
        fprintf(fp, ".PP\n");
        man_text(fp, p->words, TRUE, 0, &conf);
        break;
@@ -233,6 +245,9 @@ void man_backend(paragraph *sourceform, keywordlist *keywords,
       case para_BiblioCited:
       case para_Bullet:
       case para_NumberedList:
+       if (p->type != para_Description)
+           cleanup_described_thing;
+
        if (p->type == para_Bullet) {
            char *bullettext;
            man_convert(conf.bullet, -1, &bullettext, QUOTE_QUOTES,
@@ -244,22 +259,34 @@ void man_backend(paragraph *sourceform, keywordlist *keywords,
            man_text(fp, p->kwtext, FALSE, QUOTE_QUOTES, &conf);
            fprintf(fp, "\"\n");
        } else if (p->type == para_Description) {
-           /*
-            * Do nothing; the .xP for this paragraph is the .IP
-            * which has come before it in the DescribedThing.
-            */
+           if (had_described_thing) {
+               /*
+                * Do nothing; the .xP for this paragraph is the
+                * .IP which has come before it in the
+                * DescribedThing.
+                */
+           } else {
+               /*
+                * A \dd without a preceding \dt is given a blank
+                * one.
+                */
+               fprintf(fp, ".IP \"\"\n");
+           }
        } else if (p->type == para_BiblioCited) {
            fprintf(fp, ".IP \"");
            man_text(fp, p->kwtext, FALSE, QUOTE_QUOTES, &conf);
            fprintf(fp, "\"\n");
        }
        man_text(fp, p->words, TRUE, 0, &conf);
+       had_described_thing = FALSE;
        break;
 
       case para_DescribedThing:
+       cleanup_described_thing;
        fprintf(fp, ".IP \"");
        man_text(fp, p->words, FALSE, QUOTE_QUOTES, &conf);
        fprintf(fp, "\"\n");
+       had_described_thing = TRUE;
        break;
 
       case para_Rule:
@@ -267,18 +294,22 @@ void man_backend(paragraph *sourceform, keywordlist *keywords,
         * This isn't terribly good. Anyone who wants to do better
         * should feel free!
         */
+       cleanup_described_thing;
        fprintf(fp, ".PP\n----------------------------------------\n");
        break;
 
       case para_LcontPush:
       case para_QuotePush:
+       cleanup_described_thing;
        fprintf(fp, ".RS\n");
        break;
       case para_LcontPop:
       case para_QuotePop:
+       cleanup_described_thing;
        fprintf(fp, ".RE\n");
        break;
     }
+    cleanup_described_thing;
 
     /*
      * Tidy up.