Adopt use of gnulib for portability.
[pspp-builds.git] / src / list.q
index c875e6f53a17d81136879c37db39a109db956974..1876f69f4ffbbd0feb35d4827c12c2412b6f4d33 100644 (file)
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA. */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA. */
 
 #include <config.h>
-#include <assert.h>
+#include "error.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include "alloc.h"
+#include "case.h"
 #include "command.h"
 #include "devind.h"
+#include "dictionary.h"
 #include "lexer.h"
 #include "error.h"
 #include "magic.h"
 #include "vfm.h"
 #include "format.h"
 
-#include "debug-print.h"
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
 
-#if DEBUGGING
-static void debug_print (void);
-#endif
+/* (headers) */
+
+#include "debug-print.h"
 
 /* (specification)
    list (lst_):
@@ -66,7 +69,7 @@ struct list_ext
 static struct cmd_list cmd;
 
 /* Current case number. */
-static int case_num;
+static int case_idx;
 
 /* Line buffer. */
 static char *line_buf;
@@ -125,7 +128,6 @@ cmd_list (void)
 {
   struct variable casenum_var;
 
-  lex_match_id ("LIST");
   if (!parse_list (&cmd))
     return CMD_FAILURE;
   
@@ -206,9 +208,9 @@ cmd_list (void)
       strcpy (casenum_var.name, "Case#");
       casenum_var.type = NUMERIC;
       casenum_var.fv = -1;
-      casenum_var.print.type = FMT_F;
-      casenum_var.print.w = (cmd.last == LONG_MAX ? 5 : intlog10 (cmd.last));
-      casenum_var.print.d = 0;
+      casenum_var.print = make_output_format (FMT_F,
+                                              (cmd.last == LONG_MAX
+                                               ? 5 : intlog10 (cmd.last)), 0);
 
       /* Add the weight variable at the beginning of the variable list. */
       cmd.n_variables++;
@@ -219,14 +221,9 @@ cmd_list (void)
       cmd.v_variables[0] = &casenum_var;
     }
 
-#if DEBUGGING
-  /* Print out command. */
-  debug_print ();
-#endif
-
   determine_layout ();
 
-  case_num = 0;
+  case_idx = 0;
   procedure_with_splits (write_all_headers, list_cases, NULL, NULL);
   free (line_buf);
 
@@ -524,8 +521,9 @@ determine_layout (void)
     {
       int column;      /* Current column. */
       int width;       /* Accumulated width. */
+      int height;       /* Height of vertical names. */
       int max_width;   /* Page width. */
-      
+
       struct list_ext *prc;
 
       if (d->class == &html_class)
@@ -564,14 +562,19 @@ determine_layout (void)
        }
 
       /* Try layout #2. */
-      for (width = cmd.n_variables - 1, column = 0;
+      for (width = cmd.n_variables - 1, height = 0, column = 0;
           column < cmd.n_variables && width <= max_width;
-          column++)
-         width += cmd.v_variables[column]->print.w;
+          column++) 
+        {
+          struct variable *v = cmd.v_variables[column];
+          width += v->print.w;
+          if (strlen (v->name) > height)
+            height = strlen (v->name);
+        }
       
       /* If it fit then we need to determine how many labels can be
          written horizontally. */
-      if (width <= max_width)
+      if (width <= max_width && height <= SHORT_NAME_LEN)
        {
 #ifndef NDEBUG
          prc->n_vertical = -1;
@@ -622,9 +625,9 @@ list_cases (struct ccase *c, void *aux UNUSED)
 {
   struct outp_driver *d;
   
-  case_num++;
-  if (case_num < cmd.first || case_num > cmd.last
-      || (cmd.step != 1 && (case_num - cmd.first) % cmd.step))
+  case_idx++;
+  if (case_idx < cmd.first || case_idx > cmd.last
+      || (cmd.step != 1 && (case_idx - cmd.first) % cmd.step))
     return 1;
 
   for (d = outp_drivers (NULL); d; d = outp_drivers (d))
@@ -671,12 +674,12 @@ list_cases (struct ccase *c, void *aux UNUSED)
              }
 
             if ((formats[v->print.type].cat & FCAT_STRING) || v->fv != -1)
-             data_out (&line_buf[x], &v->print, &c->data[v->fv]);
+             data_out (&line_buf[x], &v->print, case_data (c, v->fv));
             else 
               {
-                union value case_num_value;
-                case_num_value.f = case_num;
-                data_out (&line_buf[x], &v->print, &case_num_value); 
+                union value case_idx_value;
+                case_idx_value.f = case_idx;
+                data_out (&line_buf[x], &v->print, &case_idx_value); 
               }
            x += v->print.w;
          
@@ -705,12 +708,12 @@ list_cases (struct ccase *c, void *aux UNUSED)
            char buf[41];
            
             if ((formats[v->print.type].cat & FCAT_STRING) || v->fv != -1)
-             data_out (buf, &v->print, &c->data[v->fv]);
+             data_out (buf, &v->print, case_data (c, v->fv));
             else 
               {
-                union value case_num_value;
-                case_num_value.f = case_num;
-                data_out (buf, &v->print, &case_num_value); 
+                union value case_idx_value;
+                case_idx_value.f = case_idx;
+                data_out (buf, &v->print, &case_idx_value); 
               }
            buf[v->print.w] = 0;
 
@@ -729,45 +732,6 @@ list_cases (struct ccase *c, void *aux UNUSED)
 
   return 1;
 }
-\f
-/* Debugging output. */
-
-#if DEBUGGING
-/* Prints out the command as parsed by cmd_list(). */
-static void
-debug_print (void)
-{
-  int i;
-
-  puts ("LIST");
-  printf ("  VARIABLES=");
-  for (i = 0; i < cmd.n_variables; i++)
-    {
-      if (i)
-       putc (' ', stdout);
-      fputs (cmd.v_variables[i]->name, stdout);
-    }
-
-  printf ("\n  /CASES=FROM %ld TO %ld BY %ld\n", cmd.first, cmd.last, cmd.step);
-
-  fputs ("  /FORMAT=", stdout);
-  if (cmd.numbering == LST_NUMBERED)
-    fputs ("NUMBERED", stdout);
-  else
-    fputs ("UNNUMBERED", stdout);
-  putc (' ', stdout);
-  if (cmd.wrap == LST_WRAP)
-    fputs ("WRAP", stdout);
-  else
-    fputs ("SINGLE", stdout);
-  putc (' ', stdout);
-  if (cmd.weight == LST_WEIGHT)
-    fputs ("WEIGHT", stdout);
-  else
-    fputs ("NOWEIGHT", stdout);
-  puts (".");
-}
-#endif /* DEBUGGING */
 
 /* 
    Local Variables: