Completely rewrite src/data/format.[ch], to achieve better
[pspp-builds.git] / src / output / table.c
index 430742d743f3c045c3f6c3c8f7f397db816826c5..029fd5d07ddc57db49395c02717e45664d93ab57 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - computes sample statistics.
-   Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
    Written by Ben Pfaff <blp@gnu.org>.
 
    This program is free software; you can redistribute it and/or
    02110-1301, USA. */
 
 #include <config.h>
+
 #include "table.h"
+
 #include <ctype.h>
 #include <stdarg.h>
 #include <limits.h>
 #include <stdlib.h>
+
+#include "output.h"
+#include "manager.h"
+
+#include <data/format.h>
+#include <data/variable.h>
 #include <libpspp/alloc.h>
 #include <libpspp/assertion.h>
 #include <libpspp/compiler.h>
-#include <data/format.h>
 #include <libpspp/magic.h>
 #include <libpspp/misc.h>
-#include "minmax.h"
-#include "output.h"
 #include <libpspp/pool.h>
-#include "manager.h"
-#include <data/variable.h>
+
+#include "minmax.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 \f
-struct som_table_class tab_table_class;
+const struct som_table_class tab_table_class;
 static char *command_name;
 
 /* Returns the font to use for a cell with the given OPTIONS. */
@@ -87,6 +92,7 @@ void
 tab_destroy (struct tab_table *t)
 {
   assert (t != NULL);
+  free (t->title);
   pool_destroy (t->container);
 }
 
@@ -435,10 +441,10 @@ tab_natural_width (struct tab_table *t, struct outp_driver *d, int c)
 
   if (width == 0)
     {
-      width = d->prop_em_width * 8;
-#if DEBUGGING
-      printf ("warning: table column %d contains no data.\n", c);
-#endif
+      /* FIXME: This is an ugly kluge to compensate for the fact
+         that we don't let joined cells contribute to column
+         widths. */
+      width = d->prop_em_width * 8; 
     }
   
   {
@@ -557,7 +563,7 @@ tab_float (struct tab_table *table, int c, int r, unsigned char opt,
   assert (r >= 0);
   assert (r < table->nr);
 
-  f = make_output_format (FMT_F, w, d);
+  f = fmt_for_output (FMT_F, w, d);
   
 #if DEBUGGING
   if (c + table->col_ofs < 0 || r + table->row_ofs < 0
@@ -802,12 +808,12 @@ tab_offset (struct tab_table *t, int col, int row)
 
   assert (t != NULL);
 #if DEBUGGING
-  if (row < -1 || row >= t->nr)
+  if (row < -1 || row > t->nr)
     {
       printf ("tab_offset(): row=%d in %d-row table\n", row, t->nr);
       NOT_REACHED ();
     }
-  if (col < -1 || col >= t->nc)
+  if (col < -1 || col > t->nc)
     {
       printf ("tab_offset(): col=%d in %d-column table\n", col, t->nc);
       NOT_REACHED ();
@@ -837,7 +843,7 @@ tab_next_row (struct tab_table *t)
 \f
 static struct tab_table *t;
 static struct outp_driver *d;
-int tab_hit;
+static int tab_hit;
 
 /* Set the current table to TABLE. */
 static void
@@ -1219,7 +1225,7 @@ tabi_render (int c0, int r0, int c1, int r1)
   y = render_rows (y, c0, c1, (t->nr - t->b) * 2, t->nr * 2 + 1);
 }
 
-struct som_table_class tab_table_class =
+const struct som_table_class tab_table_class =
   {
     tabi_table,
     tabi_driver,