/* PSPP - computes sample statistics.
Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
- Written by Ben Pfaff <blp@gnu.org>.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
#include <data/file-name.h>
#include <libpspp/alloc.h>
+#include <libpspp/assertion.h>
#include <libpspp/compiler.h>
#include <libpspp/pool.h>
#include <libpspp/start-date.h>
output-file="pspp.list"
paginate=on|off Formfeeds are desired?
tab-width=8 Width of a tab; 0 to not use tabs.
-
+
headers=on|off Put headers at top of page?
emphasis=bold|underline|none Style to use for emphasis.
length=66
#define ATTR_BOX 0x200 /* Line drawing character. */
/* A line of text. */
-struct line
+struct line
{
unsigned short *chars; /* Characters and attributes. */
int char_cnt; /* Length. */
};
/* How to emphasize text. */
-enum emphasis_style
+enum emphasis_style
{
EMPH_BOLD, /* Overstrike for bold. */
EMPH_UNDERLINE, /* Overstrike for underlining. */
const struct string *val);
static bool
-ascii_open_driver (struct outp_driver *this, const struct string *options)
+ascii_open_driver (struct outp_driver *this, struct substring options)
{
struct ascii_driver_ext *x;
int i;
this->length = x->page_length - x->top_margin - x->bottom_margin - 1;
if (x->headers)
this->length -= 3;
-
+
if (this->width < 59 || this->length < 15)
{
error (0, 0,
}
for (i = 0; i < LNS_COUNT; i++)
- if (x->box[i] == NULL)
+ if (x->box[i] == NULL)
{
char s[2];
s[0] = get_default_box_char (i);
s[1] = '\0';
x->box[i] = pool_strdup (x->pool, s);
}
-
+
return true;
error:
ascii_close_driver (struct outp_driver *this)
{
struct ascii_driver_ext *x = this->ext;
-
+
if (fn_close (x->file_name, x->file) != 0)
error (0, errno, _("ascii: closing output file \"%s\""), x->file_name);
pool_detach_file (x->pool, x->file);
pool_destroy (x->pool);
-
+
return true;
}
output_file_arg
};
-static struct outp_option option_tab[] =
+static const struct outp_option option_tab[] =
{
{"headers", boolean_arg, 0},
{"paginate", boolean_arg, 1},
int subcat;
const char *value;
- value = ds_c_str (val);
+ value = ds_cstr (val);
if (!strncmp (key, "box[", 4))
{
char *tail;
this->width = arg;
break;
default:
- abort ();
+ NOT_REACHED ();
}
}
break;
x->emphasis = EMPH_UNDERLINE;
else if (!strcmp (value, "none"))
x->emphasis = EMPH_NONE;
- else
+ else
error (0, 0,
_("ascii: `emphasis' value must be `bold', "
"`underline', or `none'"));
x->tab_width = arg;
break;
default:
- abort ();
+ NOT_REACHED ();
}
}
break;
x->squeeze_blank_lines = setting;
break;
default:
- abort ();
+ NOT_REACHED ();
}
}
break;
default:
- abort ();
+ NOT_REACHED ();
}
return true;
{
x->lines = pool_nrealloc (x->pool,
x->lines, this->length, sizeof *x->lines);
- for (i = x->line_cap; i < this->length; i++)
+ for (i = x->line_cap; i < this->length; i++)
{
struct line *line = &x->lines[i];
line->chars = NULL;
{
struct ascii_driver_ext *ext = this->ext;
struct line *line = &ext->lines[y];
- if (line->char_cnt < length)
+ if (line->char_cnt < length)
{
int x;
- if (line->char_cap < length)
+ if (line->char_cap < length)
{
line->char_cap = MIN (length * 2, this->width);
line->chars = pool_nrealloc (ext->pool,
line->chars,
- line->char_cap, sizeof *line->chars);
+ line->char_cap, sizeof *line->chars);
}
for (x = line->char_cnt; x < length; x++)
line->chars[x] = ' ';
- line->char_cnt = length;
+ line->char_cnt = length;
}
}
static void
-ascii_line (struct outp_driver *this,
+ascii_line (struct outp_driver *this,
int x0, int y0, int x1, int y1,
enum outp_line_style top, enum outp_line_style left,
enum outp_line_style bottom, enum outp_line_style right)
value = ((left << LNS_LEFT) | (right << LNS_RIGHT)
| (top << LNS_TOP) | (bottom << LNS_BOTTOM) | ATTR_BOX);
- for (y = y0; y < y1; y++)
+ for (y = y0; y < y1; y++)
{
int x;
expand_line (this, y, x1);
for (x = x0; x < x1; x++)
- ext->lines[y].chars[x] = value;
+ ext->lines[y].chars[x] = value;
}
}
x += width - length;
break;
default:
- abort ();
+ NOT_REACHED ();
}
if (y >= this->length || x >= this->width)
int max_width;
int height_left;
- const char *cp = ls_c_str (&text->string);
+ const char *cp = ss_data (text->string);
max_width = 0;
height_left = text->v;
const char *end;
/* Initially the line is up to text->h characters long. */
- chars_left = ls_end (&text->string) - cp;
+ chars_left = ss_end (text->string) - cp;
if (chars_left == 0)
break;
line_len = MIN (chars_left, text->h);
line_len = end - cp;
/* Don't cut off words if it can be avoided. */
- if (cp + line_len < ls_end (&text->string))
+ if (cp + line_len < ss_end (text->string))
{
size_t space_len = line_len;
while (space_len > 0 && !isspace ((unsigned char) cp[space_len]))
if (space_len > 0)
line_len = space_len;
}
-
+
/* Draw text. */
if (draw)
text_draw (this,
/* Next line. */
cp += line_len;
- if (cp < ls_end (&text->string) && isspace ((unsigned char) *cp))
+ if (cp < ss_end (text->string) && isspace ((unsigned char) *cp))
cp++;
}
for (length = line->char_cnt; length-- > 0; s++)
if (*s & ATTR_BOX)
- ds_puts (out, ext->box[*s & 0xff]);
+ ds_put_cstr (out, ext->box[*s & 0xff]);
else
{
- if (*s & ATTR_EMPHASIS)
+ if (*s & ATTR_EMPHASIS)
{
if (ext->emphasis == EMPH_BOLD)
{
- ds_putc (out, *s);
- ds_putc (out, '\b');
+ ds_put_char (out, *s);
+ ds_put_char (out, '\b');
}
else if (ext->emphasis == EMPH_UNDERLINE)
- ds_puts (out, "_\b");
+ ds_put_cstr (out, "_\b");
}
- ds_putc (out, *s);
+ ds_put_char (out, *s);
}
}
append_lr_justified (struct string *out, int width,
const char *left, const char *right)
{
- ds_putc_multiple (out, ' ', width);
- if (left != NULL)
+ ds_put_char_multiple (out, ' ', width);
+ if (left != NULL)
{
size_t length = MIN (strlen (left), width);
- memcpy (ds_end (out) - width, left, length);
+ memcpy (ds_end (out) - width, left, length);
}
if (right != NULL)
{
size_t length = MIN (strlen (right), width);
memcpy (ds_end (out) - length, right, length);
}
- ds_putc (out, '\n');
+ ds_put_char (out, '\n');
}
static void
-dump_output (struct outp_driver *this, struct string *out)
+dump_output (struct outp_driver *this, struct string *out)
{
struct ascii_driver_ext *x = this->ext;
fwrite (ds_data (out), ds_length (out), 1, x->file);
struct ascii_driver_ext *x = this->ext;
struct string out;
int line_num;
-
- ds_init (&out);
-
- ds_putc_multiple (&out, '\n', x->top_margin);
+
+ ds_init_empty (&out);
+
+ ds_put_char_multiple (&out, '\n', x->top_margin);
if (x->headers)
{
char *r1, *r2;
-
+
r1 = xasprintf (_("%s - Page %d"), get_start_date (), x->page_number);
r2 = xasprintf ("%s - %s" , version, host_system);
-
+
append_lr_justified (&out, this->width, outp_title, r1);
append_lr_justified (&out, this->width, outp_subtitle, r2);
- ds_putc (&out, '\n');
-
+ ds_put_char (&out, '\n');
+
free (r1);
free (r2);
}
dump_output (this, &out);
-
+
for (line_num = 0; line_num < this->length; line_num++)
{
-
+
/* Squeeze multiple blank lines into a single blank line if
requested. */
- if (x->squeeze_blank_lines)
+ if (x->squeeze_blank_lines)
{
if (line_num >= x->line_cap)
break;
if (line_num > 0
&& x->lines[line_num].char_cnt == 0
&& x->lines[line_num - 1].char_cnt == 0)
- continue;
+ continue;
}
-
- if (line_num < x->line_cap)
- output_line (this, &x->lines[line_num], &out);
- ds_putc (&out, '\n');
+
+ if (line_num < x->line_cap)
+ output_line (this, &x->lines[line_num], &out);
+ ds_put_char (&out, '\n');
dump_output (this, &out);
}
-
- ds_putc_multiple (&out, '\n', x->bottom_margin);
- if (x->paginate)
- ds_putc (&out, '\f');
+
+ ds_put_char_multiple (&out, '\n', x->bottom_margin);
+ if (x->paginate)
+ ds_put_char (&out, '\f');
dump_output (this, &out);
ds_destroy (&out);
ch->lp = 0;
}
-static void
+static void
ascii_chart_finalise (struct outp_driver *d UNUSED, struct chart *ch UNUSED)
{
-
+
}
-struct outp_class ascii_class =
+const struct outp_class ascii_class =
{
"ascii",
0,