- fputs ("</TABLE>\n", x->file);
- }
- }
- else
- NOT_REACHED ();
-
- 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;
- int width;
-
- if (d->cp_x + outp_string_width (d, string, OUTP_FIXED) > 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.font = OUTP_FIXED;
- text.justification = OUTP_LEFT;
- text.string = ss_cstr (string);
- text.x = d->cp_x;
- text.y = d->cp_y;
- text.h = text.v = INT_MAX;
- d->class->text_draw (d, &text);
- d->class->text_metrics (d, &text, &width, NULL);
- d->cp_x += width;
-}
-
-/* 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;
-
- const char *Line = _("Line");
- char *leader = xmalloca (strlen (Line)
- + INT_STRLEN_BOUND (line_number) + 1 + 1);
-
- while (index < cmd.n_variables)
- {
- struct outp_text text;
- int leader_width;
-
- /* Ensure that there is enough room for a line of text. */
- if (d->cp_y + d->font_height > d->length)
- outp_eject_page (d);
-
- /* The leader is a string like `Line 1: '. Write the leader. */
- sprintf (leader, "%s %d:", Line, ++line_number);
- text.font = OUTP_FIXED;
- text.justification = OUTP_LEFT;
- text.string = ss_cstr (leader);
- text.x = 0;
- text.y = d->cp_y;
- text.h = text.v = INT_MAX;
- d->class->text_draw (d, &text);
- d->class->text_metrics (d, &text, &leader_width, NULL);
- d->cp_x = leader_width;
-
- goto entry;
- do
- {
- width++;
-
- entry:
- {
- int var_width = var_get_print_format (cmd.v_variables[index])->w;
- if (width + var_width > max_width && width != 0)
- {
- width = 0;
- d->cp_x = 0;
- d->cp_y += d->font_height;
- break;
- }
- width += var_width;
- }
-
- {
- char varname[VAR_NAME_LEN + 2];
- snprintf (varname, sizeof varname,
- " %s", var_get_name (cmd.v_variables[index]));
- write_varname (d, varname, leader_width);
- }
- }
- while (++index < cmd.n_variables);
-
- }
- d->cp_x = 0;
- d->cp_y += d->font_height;
-
- freea (leader);
-}
-
-/* There are three possible layouts for the LIST procedure:
-
- 1. If the values and their variables' name fit across the page,
- then they are listed across the page in that way.
-
- 2. If the values can fit across the page, but not the variable
- names, then as many variable names as necessary are printed
- vertically to compensate.
-
- 3. If not even the values can fit across the page, the variable
- names are listed just once, at the beginning, in a compact format,
- and the values are listed with a variable name label at the
- beginning of each line for easier reference.
-
- This is complicated by the fact that we have to do all this for
- every output driver, not just once. */
-static void
-determine_layout (void)
-{
- struct outp_driver *d;
-
- /* This is the largest page width of any driver, so we can tell what
- size buffer to allocate. */
- int largest_page_width = 0;
-
- for (d = outp_drivers (NULL); d; d = outp_drivers (d))
- {
- size_t 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)
- continue;
-
- assert (d->class->special == 0);
-
- outp_open_page (d);
-
- max_width = n_chars_width (d);
- largest_page_width = MAX (largest_page_width, max_width);
-
- prc = d->prc = xmalloc (sizeof *prc);
- prc->type = 0;
- prc->n_vertical = 0;
- prc->header = NULL;
-
- /* Try layout #1. */
- for (width = cmd.n_variables - 1, column = 0; column < cmd.n_variables; column++)
- {
- const struct variable *v = cmd.v_variables[column];
- int fmt_width = var_get_print_format (v)->w;
- int name_len = strlen (var_get_name (v));
- width += MAX (fmt_width, name_len);
- }
- if (width <= max_width)
- {
- prc->header_rows = 2;
- continue;
- }
-
- /* Try layout #2. */
- for (width = cmd.n_variables - 1, height = 0, column = 0;
- column < cmd.n_variables && width <= max_width;
- column++)