-
-static void
-output_title_line (FILE *out, int width, const char *left, const char *right)
-{
- struct string s = DS_EMPTY_INITIALIZER;
- ds_put_byte_multiple (&s, ' ', width);
- if (left != NULL)
- {
- size_t length = MIN (strlen (left), width);
- memcpy (ds_end (&s) - width, left, length);
- }
- if (right != NULL)
- {
- size_t length = MIN (strlen (right), width);
- memcpy (ds_end (&s) - length, right, length);
- }
- ds_put_byte (&s, '\n');
- fputs (ds_cstr (&s), out);
- ds_destroy (&s);
-}
-
-static void
-ascii_close_page (struct ascii_driver *a)
-{
- bool any_blank;
- int i, y;
-
- a->y = 0;
- if (a->file == NULL)
- return;
-
- if (!a->top_margin && !a->bottom_margin && a->squeeze_blank_lines
- && !a->paginate && a->page_number > 1)
- putc ('\n', a->file);
-
- for (i = 0; i < a->top_margin; i++)
- putc ('\n', a->file);
- if (a->headers)
- {
- char *r1, *r2;
-
- r1 = xasprintf (_("%s - Page %d"), get_start_date (), a->page_number);
- r2 = xasprintf ("%s - %s" , version, host_system);
-
- output_title_line (a->file, a->width, a->title, r1);
- output_title_line (a->file, a->width, a->subtitle, r2);
- putc ('\n', a->file);
-
- free (r1);
- free (r2);
- }
-
- any_blank = false;
- for (y = 0; y < a->allocated_lines; y++)
- {
- struct ascii_line *line = &a->lines[y];
-
- if (a->squeeze_blank_lines && y > 0 && line->width == 0)
- any_blank = true;
- else
- {
- if (any_blank)
- {
- putc ('\n', a->file);
- any_blank = false;
- }
-
- while (ds_chomp_byte (&line->s, ' '))
- continue;
- fwrite (ds_data (&line->s), 1, ds_length (&line->s), a->file);
- putc ('\n', a->file);
- }
- }
- if (!a->squeeze_blank_lines)
- for (y = a->allocated_lines; y < a->length; y++)
- putc ('\n', a->file);
-
- for (i = 0; i < a->bottom_margin; i++)
- putc ('\n', a->file);
- if (a->paginate)
- putc ('\f', a->file);
-}