Get rid of capacity argument to ds_init() and update all callers.
[pspp-builds.git] / src / language / data-io / list.q
index dd9a8ae1cf329b089d40c8a0994753b4cb3da7fb..84b1ac81baa8b2fb9bf9e5f9e4f5957b585c531d 100644 (file)
@@ -30,6 +30,7 @@
 #include <data/procedure.h>
 #include <data/variable.h>
 #include <language/command.h>
+#include <language/dictionary/split-file.h>
 #include <language/lexer/lexer.h>
 #include <libpspp/alloc.h>
 #include <libpspp/compiler.h>
@@ -82,11 +83,11 @@ static unsigned n_chars_width (struct outp_driver *d);
 static void write_line (struct outp_driver *d, const char *s);
 
 /* Other functions. */
-static bool list_cases (struct ccase *, void *);
+static bool list_cases (const struct ccase *, void *);
 static void determine_layout (void);
 static void clean_up (void);
 static void write_header (struct outp_driver *);
-static void write_all_headers (void *);
+static void write_all_headers (const struct ccase *, void *);
 
 /* Returns the number of text lines that can fit on the remainder of
    the page. */
@@ -239,10 +240,11 @@ cmd_list (void)
 /* Writes headers to all devices.  This is done at the beginning of
    each SPLIT FILE group. */
 static void
-write_all_headers (void *aux UNUSED)
+write_all_headers (const struct ccase *c, void *aux UNUSED)
 {
   struct outp_driver *d;
 
+  output_split_file_values (c);
   for (d = outp_drivers (NULL); d; d = outp_drivers (d))
     {
       if (!d->class->special)
@@ -436,6 +438,7 @@ write_fallback_headers (struct outp_driver *d)
   while (index < cmd.n_variables)
     {
       struct outp_text text;
+      int leader_width;
 
       /* Ensure that there is enough room for a line of text. */
       if (d->cp_y + d->font_height > d->length)
@@ -450,7 +453,8 @@ write_fallback_headers (struct outp_driver *d)
       text.y = d->cp_y;
       text.h = text.v = INT_MAX;
       d->class->text_draw (d, &text);
-      d->class->text_metrics (d, &text, &d->cp_x, NULL);
+      d->class->text_metrics (d, &text, &leader_width, NULL);
+      d->cp_x = leader_width;
 
       goto entry;
       do
@@ -471,9 +475,10 @@ write_fallback_headers (struct outp_driver *d)
          }
          
          {
-           char varname[10];
-           sprintf (varname, " %s", cmd.v_variables[index]->name);
-           write_varname (d, varname, text.h);
+           char varname[LONG_NAME_LEN + 2];
+           snprintf (varname, sizeof varname,
+                      " %s", cmd.v_variables[index]->name);
+           write_varname (d, varname, leader_width);
          }
        }
       while (++index < cmd.n_variables);
@@ -599,12 +604,12 @@ determine_layout (void)
       d->cp_y += d->font_height;
     }
 
-  ds_init(&line_buffer, largest_page_width + 2);
+  ds_init (&line_buffer);
 }
 
 /* Writes case C to output. */
 static bool
-list_cases (struct ccase *c, void *aux UNUSED)
+list_cases (const struct ccase *c, void *aux UNUSED)
 {
   struct outp_driver *d;