DO REPEAT: Order PRINT output correctly.
[pspp] / src / output / spv / spv-writer.c
index f1f9b969563f7fab49cf785ae01b19b621212035..182cc5e5471b1b0a81003fb057957c43b8019588 100644 (file)
@@ -144,10 +144,10 @@ write_page_heading (struct spv_writer *w, const struct page_heading *h,
   start_elem (w, name);
   if (h->n)
     {
-      start_elem (w, "pageParagraph");
+      start_elem (w, "vps:pageParagraph");
       for (size_t i = 0; i < h->n; i++)
         {
-          start_elem (w, "text");
+          start_elem (w, "vtx:text");
           write_attr (w, "type", "title");
           write_text (w, h->paragraphs[i].markup); /* XXX */
           end_elem (w);
@@ -160,7 +160,7 @@ write_page_heading (struct spv_writer *w, const struct page_heading *h,
 static void
 write_page_setup (struct spv_writer *w, const struct page_setup *ps)
 {
-  start_elem (w, "pageSetup");
+  start_elem (w, "vps:pageSetup");
   write_attr_format (w, "initial-page-number", "%d", ps->initial_page_number);
   write_attr (w, "chart-size",
               (ps->chart_size == PAGE_CHART_AS_IS ? "as-is"
@@ -176,8 +176,8 @@ write_page_setup (struct spv_writer *w, const struct page_setup *ps)
   write_attr (w, "reference-orientation",
               ps->orientation == PAGE_PORTRAIT ? "portrait" : "landscape");
   write_attr_format (w, "space-after", "%.1fpt", ps->object_spacing * 72.0);
-  write_page_heading (w, &ps->headings[0], "pageHeader");
-  write_page_heading (w, &ps->headings[1], "pageFooter");
+  write_page_heading (w, &ps->headings[0], "vps:pageHeader");
+  write_page_heading (w, &ps->headings[1], "vps:pageFooter");
   end_elem (w);
 }
 
@@ -194,8 +194,9 @@ spv_writer_open_file (struct spv_writer *w)
 
   time_t t = time (NULL);
   struct tm *tm = gmtime (&t);
-  char *tm_s = asctime (tm);
-  write_attr (w, "creation-date-time", tm_s);
+  char tm_s[128];
+  if (strftime (tm_s, sizeof tm_s, "%x %X", tm))
+    write_attr (w, "creation-date-time", tm_s);
 
   write_attr (w, "creator", version);
 
@@ -557,20 +558,25 @@ static void
 put_value_mod (struct buf *buf, const struct pivot_value *value,
                const char *template)
 {
-  if (value->n_footnotes || value->n_subscripts
-      || template || value->font_style || value->cell_style)
+  if ((value->ex
+       && (value->ex->n_footnotes
+           || value->ex->n_subscripts
+           || value->ex->font_style
+           || value->ex->cell_style))
+      || template)
     {
+      const struct pivot_value_ex *ex = pivot_value_ex (value);
       put_byte (buf, 0x31);
 
       /* Footnotes. */
-      put_u32 (buf, value->n_footnotes);
-      for (size_t i = 0; i < value->n_footnotes; i++)
-        put_u16 (buf, value->footnote_indexes[i]);
+      put_u32 (buf, ex->n_footnotes);
+      for (size_t i = 0; i < ex->n_footnotes; i++)
+        put_u16 (buf, ex->footnote_indexes[i]);
 
       /* Subscripts. */
-      put_u32 (buf, value->n_subscripts);
-      for (size_t i = 0; i < value->n_subscripts; i++)
-        put_string (buf, value->subscripts[i]);
+      put_u32 (buf, ex->n_subscripts);
+      for (size_t i = 0; i < ex->n_subscripts; i++)
+        put_string (buf, ex->subscripts[i]);
 
       /* Template and style. */
       uint32_t v3_start = start_count (buf);
@@ -584,7 +590,7 @@ put_value_mod (struct buf *buf, const struct pivot_value *value,
           put_string (buf, template);
         }
       end_count_u32 (buf, template_string_start);
-      put_style_pair (buf, value->font_style, value->cell_style);
+      put_style_pair (buf, ex->font_style, ex->cell_style);
       end_count_u32 (buf, v3_start);
     }
   else
@@ -592,10 +598,10 @@ put_value_mod (struct buf *buf, const struct pivot_value *value,
 }
 
 static void
-put_format (struct buf *buf, const struct fmt_spec *f, bool honor_small)
+put_format (struct buf *buf, struct fmt_spec f, bool honor_small)
 {
-  int type = f->type == FMT_F && honor_small ? 40 : fmt_to_io (f->type);
-  put_u32 (buf, (type << 16) | (f->w << 8) | f->d);
+  int type = f.type == FMT_F && honor_small ? 40 : fmt_to_io (f.type);
+  put_u32 (buf, (type << 16) | (f.w << 8) | f.d);
 }
 
 static int
@@ -623,7 +629,7 @@ put_value (struct buf *buf, const struct pivot_value *value)
         {
           put_byte (buf, 2);
           put_value_mod (buf, value, NULL);
-          put_format (buf, &value->numeric.format, value->numeric.honor_small);
+          put_format (buf, value->numeric.format, value->numeric.honor_small);
           put_double (buf, value->numeric.x);
           put_string (buf, value->numeric.var_name);
           put_string (buf, value->numeric.value_label);
@@ -633,7 +639,7 @@ put_value (struct buf *buf, const struct pivot_value *value)
         {
           put_byte (buf, 1);
           put_value_mod (buf, value, NULL);
-          put_format (buf, &value->numeric.format, value->numeric.honor_small);
+          put_format (buf, value->numeric.format, value->numeric.honor_small);
           put_double (buf, value->numeric.x);
         }
       break;
@@ -643,9 +649,10 @@ put_value (struct buf *buf, const struct pivot_value *value)
       put_value_mod (buf, value, NULL);
       size_t len = strlen (value->string.s);
       if (value->string.hex)
-        put_format (buf, &(struct fmt_spec) { FMT_AHEX, len * 2, 0 }, false);
+        put_format (buf, (struct fmt_spec) { .type = FMT_AHEX, .w = len * 2 },
+                    false);
       else
-        put_format (buf, &(struct fmt_spec) { FMT_A, len, 0 }, false);
+        put_format (buf, (struct fmt_spec) { .type = FMT_A, .w = len }, false);
       put_string (buf, value->string.value_label);
       put_string (buf, value->string.var_name);
       put_show_values (buf, value->string.show);
@@ -792,7 +799,10 @@ put_y1 (struct buf *buf, const struct pivot_table *table)
   put_string (buf, table->language);
   put_string (buf, "UTF-8");    /* XXX */
   put_string (buf, table->locale);
-  put_bytes (buf, "\0\0\1\1", 4);
+  put_bool (buf, false);        /* x10 */
+  put_bool (buf, table->settings.include_leading_zero);
+  put_bool (buf, true);         /* x12 */
+  put_bool (buf, true);         /* x13 */
   put_y0 (buf, table);
 }
 
@@ -852,10 +862,10 @@ put_light_table (struct buf *buf, uint64_t table_id,
   put_bool (buf, table->rotate_outer_row_labels);
   put_bool (buf, true);
   put_u32 (buf, 0x15);
-  put_u32 (buf, table->look->width_ranges[H][0]);
-  put_u32 (buf, table->look->width_ranges[H][1]);
-  put_u32 (buf, table->look->width_ranges[V][0]);
-  put_u32 (buf, table->look->width_ranges[V][1]);
+  put_u32 (buf, table->look->col_heading_width_range[0]);
+  put_u32 (buf, table->look->col_heading_width_range[1]);
+  put_u32 (buf, table->look->row_heading_width_range[0]);
+  put_u32 (buf, table->look->row_heading_width_range[1]);
   put_u64 (buf, table_id);
 
   /* Titles. */
@@ -895,8 +905,8 @@ put_light_table (struct buf *buf, uint64_t table_id,
       put_color (buf, &a->font_style.bg[0]);
 
       bool alt
-        = (!cell_color_equal (&a->font_style.fg[0], &a->font_style.fg[1])
-           || !cell_color_equal (&a->font_style.bg[0], &a->font_style.bg[1]));
+        = (!cell_color_equal (a->font_style.fg[0], a->font_style.fg[1])
+           || !cell_color_equal (a->font_style.bg[0], a->font_style.bg[1]));
       put_bool (buf, alt);
       if (alt)
         {