Fully implement arbitrary delimiters on DATA LIST, extending the half
[pspp-builds.git] / src / html.c
index 3f7416290b070d92c94db48c8f8dbf7688fa03b8..ea11459d132d642449c348227a9d623a65829760 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <config.h>
 #include "htmlP.h"
-#include <assert.h>
+#include "error.h"
 #include <errno.h>
 #include <stdlib.h>
 #include <ctype.h>
@@ -46,13 +46,13 @@ static int postopen (struct file_ext *);
 static int preclose (struct file_ext *);
 
 static int
-html_open_global (struct outp_class *this unused)
+html_open_global (struct outp_class *this UNUSED)
 {
   return 1;
 }
 
 static int
-html_close_global (struct outp_class *this unused)
+html_close_global (struct outp_class *this UNUSED)
 {
   return 1;
 }
@@ -156,7 +156,7 @@ html_option (struct outp_driver *this, const char *key, const struct string *val
       break;
     case 1:
       free (x->file.filename);
-      x->file.filename = xstrdup (ds_value (val));
+      x->file.filename = xstrdup (ds_c_str (val));
       break;
     case string_arg:
       {
@@ -168,10 +168,11 @@ html_option (struct outp_driver *this, const char *key, const struct string *val
            break;
          default:
            assert (0);
+            abort ();
          }
        if (*dest)
          free (*dest);
-       *dest = xstrdup (ds_value (val));
+       *dest = xstrdup (ds_c_str (val));
       }
       break;
     default:
@@ -409,26 +410,6 @@ html_submit (struct outp_driver *this, struct som_table *s)
     assert (0);
 }
 
-/* Emit HTML to FILE to change from *OLD_ATTR attributes to NEW_ATTR.
-   Sets *OLD_ATTR to NEW_ATTR when done. */
-static void
-change_attributes (FILE *f, int *old_attr, int new_attr)
-{
-  if (*old_attr == new_attr)
-    return;
-
-  if (*old_attr & OUTP_F_B)
-    fputs ("</B>", f);
-  if (*old_attr & OUTP_F_I)
-    fputs ("</I>", f);
-  if (new_attr & OUTP_F_I)
-    fputs ("<I>", f);
-  if (new_attr & OUTP_F_B)
-    fputs ("<B>", f);
-
-  *old_attr = new_attr;
-}
-
 /* Write string S of length LEN to file F, escaping characters as
    necessary for HTML. */
 static void
@@ -436,7 +417,6 @@ escape_string (FILE *f, char *s, int len)
 {
   char *ep = &s[len];
   char *bp, *cp;
-  int attr = 0;
 
   for (bp = cp = s; bp < ep; bp = cp)
     {
@@ -462,9 +442,6 @@ escape_string (FILE *f, char *s, int len)
            assert (0);
          }
     }
-
-  if (attr)
-    change_attributes (f, &attr, 0);
 }
   
 /* Write table T to THIS output driver. */
@@ -473,13 +450,11 @@ output_tab_table (struct outp_driver *this, struct tab_table *t)
 {
   struct html_driver_ext *x = this->ext;
   
-  tab_hit++;
-
   if (t->nr == 1 && t->nc == 1)
     {
       fputs ("<P>", x->file.file);
       if (!ls_empty_p (t->cc))
-       escape_string (x->file.file, ls_value (t->cc), ls_length (t->cc));
+       escape_string (x->file.file, ls_c_str (t->cc), ls_length (t->cc));
       fputs ("</P>\n", x->file.file);
       
       return;
@@ -490,14 +465,13 @@ output_tab_table (struct outp_driver *this, struct tab_table *t)
   if (!ls_empty_p (&t->title))
     {
       fprintf (x->file.file, "  <TR>\n    <TH COLSPAN=%d>", t->nc);
-      escape_string (x->file.file, ls_value (&t->title),
+      escape_string (x->file.file, ls_c_str (&t->title),
                     ls_length (&t->title));
       fputs ("</TH>\n  </TR>\n", x->file.file);
     }
   
   {
     int r;
-    struct len_string *cc = t->cc;
     unsigned char *ct = t->ct;
 
     for (r = 0; r < t->nr; r++)
@@ -505,15 +479,22 @@ output_tab_table (struct outp_driver *this, struct tab_table *t)
        int c;
        
        fputs ("  <TR>\n", x->file.file);
-       for (c = 0; c < t->nc; c++, cc++, ct++)
+       for (c = 0; c < t->nc; c++, ct++)
          {
+            struct len_string *cc;
            int tag;
            char header[128];
            char *cp;
+            struct tab_joined_cell *j = NULL;
 
-           if ((*ct & TAB_JOIN)
-               && ((struct tab_joined_cell *) ls_value (cc))->hit == tab_hit)
-             continue;
+            cc = t->cc + c + r * t->nc;
+           if (*ct & TAB_JOIN) 
+              {
+                j = (struct tab_joined_cell *) ls_c_str (cc);
+                cc = &j->contents;
+                if (j->x1 != c || j->y1 != r)
+                  continue; 
+              }
 
            if (r < t->t || r >= t->nr - t->b
                || c < t->l || c >= t->nc - t->r)
@@ -539,14 +520,12 @@ output_tab_table (struct outp_driver *this, struct tab_table *t)
 
            if (*ct & TAB_JOIN)
              {
-               struct tab_joined_cell *j =
-                 (struct tab_joined_cell *) ls_value (cc);
-               j->hit = tab_hit;
-               
                if (j->x2 - j->x1 > 1)
                  cp = spprintf (cp, " COLSPAN=%d", j->x2 - j->x1);
                if (j->y2 - j->y1 > 1)
                  cp = spprintf (cp, " ROWSPAN=%d", j->y2 - j->y1);
+
+                cc = &j->contents;
              }
            
            strcpy (cp, ">");
@@ -554,7 +533,7 @@ output_tab_table (struct outp_driver *this, struct tab_table *t)
            
            if ( ! (*ct & TAB_EMPTY)  ) 
              {
-               char *s = ls_value (cc);
+               char *s = ls_c_str (cc);
                size_t l = ls_length (cc);
 
                while (l && isspace ((unsigned char) *s))