Ahem; that only didn't cause a segfault by sheer luck.
[sgt/halibut] / bk_xhtml.c
index 439f9f9..4d5069a 100644 (file)
@@ -192,19 +192,19 @@ static xhtmlconfig xhtml_configure(paragraph *source)
     {
       if (!ustricmp(source->keyword, L"xhtml-contents-filename")) {
        sfree(ret.contents_filename);
-       ret.contents_filename = utoa_dup(uadv(source->keyword));
+       ret.contents_filename = dupstr(adv(source->origkeyword));
       } else if (!ustricmp(source->keyword, L"xhtml-single-filename")) {
        sfree(ret.single_filename);
-       ret.single_filename = utoa_dup(uadv(source->keyword));
+       ret.single_filename = dupstr(adv(source->origkeyword));
       } else if (!ustricmp(source->keyword, L"xhtml-index-filename")) {
        sfree(ret.index_filename);
-       ret.index_filename = utoa_dup(uadv(source->keyword));
+       ret.index_filename = dupstr(adv(source->origkeyword));
       } else if (!ustricmp(source->keyword, L"xhtml-template-filename")) {
        sfree(ret.template_filename);
-       ret.template_filename = utoa_dup(uadv(source->keyword));
+       ret.template_filename = dupstr(adv(source->origkeyword));
       } else if (!ustricmp(source->keyword, L"xhtml-template-fragment")) {
        sfree(ret.template_fragment);
-       ret.template_fragment = utoa_dup(uadv(source->keyword));
+       ret.template_fragment = utoa_dup(uadv(source->keyword), CS_ASCII);
       } else if (!ustricmp(source->keyword, L"xhtml-contents-depth-0")) {
         ret.contents_depth[0] = utoi(uadv(source->keyword));
       } else if (!ustricmp(source->keyword, L"xhtml-contents-depth-1")) {
@@ -304,45 +304,12 @@ paragraph *xhtml_config_filename(char *filename)
      * \cfg{xhtml-leaf-level}{0}; the rationale being that the user
      * wants their output _in that file_.
      */
+    paragraph *p, *q;
 
-    paragraph *p[2];
-    int i, len;
-    wchar_t *ufilename, *up;
-
-    for (i = 0; i < 2; i++) {
-       p[i] = mknew(paragraph);
-       memset(p[i], 0, sizeof(*p[i]));
-       p[i]->type = para_Config;
-       p[i]->next = NULL;
-       p[i]->fpos.filename = "<command line>";
-       p[i]->fpos.line = p[i]->fpos.col = -1;
-    }
-
-    ufilename = ufroma_dup(filename);
-    len = ustrlen(ufilename) + 2 + lenof(L"xhtml-single-filename");
-    p[0]->keyword = mknewa(wchar_t, len);
-    up = p[0]->keyword;
-    ustrcpy(up, L"xhtml-single-filename");
-    up = uadv(up);
-    ustrcpy(up, ufilename);
-    up = uadv(up);
-    *up = L'\0';
-    assert(up - p[0]->keyword < len);
-    sfree(ufilename);
-
-    len = lenof(L"xhtml-leaf-level") + lenof(L"0") + 1;
-    p[1]->keyword = mknewa(wchar_t, len);
-    up = p[1]->keyword;
-    ustrcpy(up, L"xhtml-leaf-level");
-    up = uadv(up);
-    ustrcpy(up, L"0");
-    up = uadv(up);
-    *up = L'\0';
-    assert(up - p[1]->keyword < len);
-
-    p[0]->next = p[1];
-
-    return p[0];
+    p = cmdline_cfg_simple("xhtml-single-filename", filename, NULL);
+    q = cmdline_cfg_simple("xhtml-leaf-level", "0", NULL);
+    p->next = q;
+    return p;
 }
 
 static xhtmlsection *xhtml_new_section(xhtmlsection *last)
@@ -844,13 +811,13 @@ static void xhtml_donavlinks(FILE *fp, xhtmlfile *file)
   if (xhtml_last_file==NULL) {
     fprintf(fp, "Previous | ");
   } else {
-    fprintf(fp, "<a href='%s'>Previous</a> | ", xhtml_last_file->filename);
+    fprintf(fp, "<a href=\"%s\">Previous</a> | ", xhtml_last_file->filename);
   }
-  fprintf(fp, "<a href='%s'>Contents</a> | ", conf.contents_filename);
+  fprintf(fp, "<a href=\"%s\">Contents</a> | ", conf.contents_filename);
   if (file == NULL) {
     fprintf(fp, "Index | ");
   } else {
-    fprintf(fp, "<a href='%s'>Index</a> | ", conf.index_filename);
+    fprintf(fp, "<a href=\"%s\">Index</a> | ", conf.index_filename);
   }
   if (file != NULL) { /* otherwise we're doing nav links for the index */
     if (xhtml_next_file==NULL)
@@ -864,10 +831,10 @@ static void xhtml_donavlinks(FILE *fp, xhtmlfile *file)
     if (file==NULL) { /* index, so no next file */
       fprintf(fp, "Next        ");
     } else {
-      fprintf(fp, "<a href='%s'>Next</a>", conf.index_filename);
+      fprintf(fp, "<a href=\"%s\">Next</a>", conf.index_filename);
     }
   } else {
-    fprintf(fp, "<a href='%s'>Next</a>", xhtml_next_file->filename);
+    fprintf(fp, "<a href=\"%s\">Next</a>", xhtml_next_file->filename);
   }
   fprintf(fp, "</p>\n");
 }
@@ -896,7 +863,7 @@ static void xhtml_do_index_body(FILE *fp)
       for (i=0; i<xi->nsection; i++) {
        xhtmlsection *sect = xi->sections[i];
        if (sect) {
-         fprintf(fp, "<a href='%s#%s'>", sect->file->filename, sect->fragment);
+         fprintf(fp, "<a href=\"%s#%s\">", sect->file->filename, sect->fragment);
          if (sect->para->kwtext) {
            xhtml_para(fp, sect->para->kwtext, FALSE);
          } else if (sect->para->words) {
@@ -1367,7 +1334,7 @@ static void xhtml_doheader(FILE *fp, word *title)
 {
   fprintf(fp, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n");
   fprintf(fp, "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n");
-  fprintf(fp, "<html xmlns='http://www.w3.org/1999/xhtml'>\n\n<head>\n<title>");
+  fprintf(fp, "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n\n<head>\n<title>");
   if (title==NULL)
     fprintf(fp, "The thing with no name!");
   else
@@ -1651,7 +1618,8 @@ static void xhtml_rdaddwc(rdstringc *rs, word *text, word *end, int indexable) {
            rdaddsc(rs, "<code>");
 
        if (removeattr(text->type) == word_Normal) {
-         if (xhtml_convert(text->text, 0, &c, TRUE)) /* spaces in the word are hard */
+         if (xhtml_convert(text->text, 0, &c, TRUE) || !text->alt)
+               /* spaces in the word are hard */
            rdaddsc(rs, c);
          else
            xhtml_rdaddwc(rs, text->alt, NULL, indexable);