- assert (0);
- }
-}
-
-/* Writes the headers. Some of them might be vertical; most are
- probably horizontal. */
-static void
-write_header (struct outp_driver *d)
-{
- struct list_ext *prc = d->prc;
-
- if (!prc->header_rows)
- return;
-
- if (n_lines_remaining (d) < prc->header_rows + 1)
- {
- outp_eject_page (d);
- assert (n_lines_remaining (d) >= prc->header_rows + 1);
- }
-
- /* Design the header. */
- if (!prc->header)
- {
- size_t i;
- size_t x;
-
- /* Allocate, initialize header. */
- prc->header = xnmalloc (prc->header_rows, sizeof *prc->header);
- {
- int w = n_chars_width (d);
- for (i = 0; i < prc->header_rows; i++)
- {
- prc->header[i] = xmalloc (w + 1);
- memset (prc->header[i], ' ', w);
- }
- }
-
- /* Put in vertical names. */
- for (i = x = 0; i < prc->n_vertical; i++)
- {
- struct variable *v = cmd.v_variables[i];
- size_t j;
-
- memset (&prc->header[prc->header_rows - 1][x], '-', v->print.w);
- x += v->print.w - 1;
- for (j = 0; j < strlen (v->name); j++)
- prc->header[strlen (v->name) - j - 1][x] = v->name[j];
- x += 2;
- }
-
- /* Put in horizontal names. */
- for (; i < cmd.n_variables; i++)
- {
- struct variable *v = cmd.v_variables[i];
-
- memset (&prc->header[prc->header_rows - 1][x], '-',
- max (v->print.w, (int) strlen (v->name)));
- if ((int) strlen (v->name) < v->print.w)
- x += v->print.w - strlen (v->name);
- memcpy (&prc->header[0][x], v->name, strlen (v->name));
- x += strlen (v->name) + 1;
- }
-
- /* Add null bytes. */
- for (i = 0; i < prc->header_rows; i++)
- {
- for (x = n_chars_width (d); x >= 1; x--)
- if (prc->header[i][x - 1] != ' ')
- {
- prc->header[i][x] = 0;
- break;
- }
- assert (x);
- }
- }
-
- /* Write out the header, in back-to-front order except for the last line. */
- if (prc->header_rows >= 2)
- {
- size_t i;
-
- for (i = prc->header_rows - 1; i-- != 0; )
- write_line (d, prc->header[i]);
- }
- write_line (d, prc->header[prc->header_rows - 1]);
-}
-
-
-/* Frees up all the memory we've allocated. */
-static void
-clean_up (void)
-{
- struct outp_driver *d;
-
- for (d = outp_drivers (NULL); d; d = outp_drivers (d))
- if (d->class->special == 0)
- {
- struct list_ext *prc = d->prc;
- size_t i;
-
- if (prc->header)
- {
- for (i = 0; i < prc->header_rows; i++)
- free (prc->header[i]);
- free (prc->header);
- }
- free (prc);
-
- d->class->text_set_font_by_name (d, "PROP");
- }
- else if (d->class == &html_class)
- {
- if (d->driver_open && d->page_open)
- {
- struct html_driver_ext *x = d->ext;
-
- fputs ("</TABLE>\n", x->file.file);
- }
- }
- else
- assert (0);
-
- free (cmd.v_variables);
-}
-
-/* Writes string STRING at the current position. If the text would
- fall off the side of the page, then advance to the next line,
- indenting by amount INDENT. */
-static void
-write_varname (struct outp_driver *d, char *string, int indent)
-{
- struct outp_text text;
-
- text.options = OUTP_T_JUST_LEFT;
- ls_init (&text.s, string, strlen (string));
- d->class->text_metrics (d, &text);
-
- if (d->cp_x + text.h > d->width)
- {
- d->cp_y += d->font_height;
- if (d->cp_y + d->font_height > d->length)
- outp_eject_page (d);
- d->cp_x = indent;
- }
-
- text.x = d->cp_x;
- text.y = d->cp_y;
- d->class->text_draw (d, &text);
- d->cp_x += text.h;
-}
-
-/* When we can't fit all the values across the page, we write out all
- the variable names just once. This is where we do it. */
-static void
-write_fallback_headers (struct outp_driver *d)
-{
- const int max_width = n_chars_width(d) - 10;
-
- int index = 0;
- int width = 0;
- int line_number = 0;