ascii: Remove unimplemented "tab-width" setting.
[pspp-builds.git] / src / output / ascii.c
index d821993e3bc8bd283b771e5a95cb7fc245195d17..ffe8515f8b51a7bc3147431e9b68ad30b44aa8b8 100644 (file)
@@ -98,7 +98,6 @@ struct ascii_driver
     bool paginate;             /* Insert formfeeds? */
     bool squeeze_blank_lines;   /* Squeeze multiple blank lines into one? */
     enum emphasis_style emphasis; /* How to emphasize text. */
-    int tab_width;             /* Width of a tab; 0 not to use tabs. */
     char *chart_file_name;      /* Name of files used for charts. */
 
     int width;                  /* Page width. */
@@ -117,7 +116,7 @@ struct ascii_driver
     char *subtitle;
     char *file_name;            /* Output file name. */
     FILE *file;                 /* Output file. */
-    bool reported_error;        /* Reported file open error? */
+    bool error;                 /* Output error? */
     int page_number;           /* Current page number. */
     struct ascii_line *lines;   /* Page content. */
     int allocated_lines;        /* Number of lines allocated. */
@@ -132,7 +131,7 @@ static bool update_page_size (struct ascii_driver *, bool issue_error);
 static int parse_page_size (struct driver_option *);
 
 static void ascii_close_page (struct ascii_driver *);
-static void ascii_open_page (struct ascii_driver *);
+static bool ascii_open_page (struct ascii_driver *);
 
 static void ascii_draw_line (void *, int bb[TABLE_N_AXES][2],
                              enum render_line_style styles[TABLE_N_AXES][2]);
@@ -179,7 +178,6 @@ ascii_create (const char *name, enum output_device_type device_type,
                             "underline", EMPH_UNDERLINE,
                             "none", EMPH_NONE,
                             (char *) NULL);
-  a->tab_width = parse_int (opt (d, o, "tab-width", "0"), 8, INT_MAX);
 
   if (parse_enum (opt (d, o, "chart-type", "png"),
                   "png", true,
@@ -218,7 +216,7 @@ ascii_create (const char *name, enum output_device_type device_type,
   a->subtitle = xstrdup ("");
   a->file_name = parse_string (opt (d, o, "output-file", "pspp.list"));
   a->file = NULL;
-  a->reported_error = false;
+  a->error = false;
   a->page_number = 0;
   a->lines = NULL;
   a->allocated_lines = 0;
@@ -376,6 +374,8 @@ ascii_submit (struct output_driver *driver,
               const struct output_item *output_item)
 {
   struct ascii_driver *a = ascii_driver_cast (driver);
+  if (a->error)
+    return;
   if (is_table_item (output_item))
     {
       struct table_item *table_item = to_table_item (output_item);
@@ -414,8 +414,8 @@ ascii_submit (struct output_driver *driver,
           params.line_widths[V][i] = width;
         }
 
-      if (a->file == NULL)
-        ascii_open_page (a);
+      if (a->file == NULL && !ascii_open_page (a))
+        return;
 
       page = render_page_create (&params, table_item_get_table (table_item));
       for (render_break_init (&x_break, page, H);
@@ -439,7 +439,8 @@ ascii_submit (struct output_driver *driver,
                 {
                   assert (a->y > 0);
                   ascii_close_page (a);
-                  ascii_open_page (a);
+                  if (!ascii_open_page (a))
+                    return;
                   continue;
                 }
 
@@ -520,7 +521,8 @@ ascii_submit (struct output_driver *driver,
           {
             struct table_item *item;
 
-            item = table_item_create (table_from_string (0, text), NULL);
+            item = table_item_create (table_from_string (TAB_LEFT, text),
+                                      NULL);
             ascii_submit (&a->driver, &item->output_item);
             table_item_unref (item);
           }
@@ -756,11 +758,14 @@ ascii_layout_cell (struct ascii_driver *a, const struct table_cell *cell,
 \f
 /* ascii_close_page () and support routines. */
 
-static void
+static bool
 ascii_open_page (struct ascii_driver *a)
 {
   int i;
 
+  if (a->error)
+    return false;
+
   if (a->file == NULL)
     {
       a->file = fn_open (a->file_name, a->append ? "a" : "w");
@@ -771,16 +776,10 @@ ascii_open_page (struct ascii_driver *a)
         }
       else
         {
-          /* Report the error to the user and complete
-             initialization.  If we do not finish initialization,
-             then calls to other driver functions will segfault
-             later.  It would be better to simply drop the driver
-             entirely, but we do not have a convenient mechanism
-             for this (yet). */
-          if (!a->reported_error)
-            error (0, errno, _("ascii: opening output file \"%s\""),
-                   a->file_name);
-          a->reported_error = true;
+          error (0, errno, _("ascii: opening output file \"%s\""),
+                 a->file_name);
+          a->error = true;
+          return false;
         }
     }
 
@@ -800,6 +799,8 @@ ascii_open_page (struct ascii_driver *a)
 
   for (i = 0; i < a->length; i++)
     a->lines[i].n_chars = 0;
+
+  return true;
 }
 
 /* Writes LINE to A's output file.  */
@@ -868,6 +869,7 @@ ascii_close_page (struct ascii_driver *a)
   bool any_blank;
   int i, y;
 
+  a->y = 0;
   if (a->file == NULL)
     return;
 
@@ -918,6 +920,4 @@ ascii_close_page (struct ascii_driver *a)
     putc ('\n', a->file);
   if (a->paginate)
     putc ('\f', a->file);
-
-  a->y = 0;
 }