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. */
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. */
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]);
"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,
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;
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);
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 (¶ms, table_item_get_table (table_item));
for (render_break_init (&x_break, page, H);
{
assert (a->y > 0);
ascii_close_page (a);
- ascii_open_page (a);
+ if (!ascii_open_page (a))
+ return;
continue;
}
{
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);
}
\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");
}
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;
}
}
for (i = 0; i < a->length; i++)
a->lines[i].n_chars = 0;
+
+ return true;
}
/* Writes LINE to A's output file. */
bool any_blank;
int i, y;
+ a->y = 0;
if (a->file == NULL)
return;
putc ('\n', a->file);
if (a->paginate)
putc ('\f', a->file);
-
- a->y = 0;
}