X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Ftex.c;h=8a88452ec8a22760c146edd8f4c27e800d54a85b;hb=95cde62bdf5210c1c60dad5598a888b864f93161;hp=254d6a686183e64b9ebc60b76e301eb1995bc371;hpb=507ebaea36737618ef8265a60cd3e9005d9f3457;p=pspp diff --git a/src/output/tex.c b/src/output/tex.c index 254d6a6861..8a88452ec8 100644 --- a/src/output/tex.c +++ b/src/output/tex.c @@ -75,7 +75,7 @@ struct tex_driver char *chart_file_name; FILE *file; - size_t chart_cnt; + size_t n_charts; struct ll_list preamble_list; struct ll_list token_list; @@ -108,46 +108,43 @@ tex_driver_cast (struct output_driver *driver) return UP_CAST (driver, struct tex_driver, driver); } -static struct driver_option * -opt (struct output_driver *d, struct string_map *options, const char *key, - const char *default_value) +static struct driver_option +opt (struct driver_options *options, const char *key, const char *default_value) { - return driver_option_get (d, options, key, default_value); + return driver_option_get (options, key, default_value); } static struct output_driver * tex_create (struct file_handle *fh, enum settings_output_devices device_type, - struct string_map *o) + struct driver_options *o) { - struct output_driver *d; - struct tex_driver *tex = XZALLOC (struct tex_driver); - hmap_init (&tex->macros); - ll_init (&tex->preamble_list); - ll_init (&tex->token_list); - - d = &tex->driver; - output_driver_init (&tex->driver, &tex_driver_class, fh_get_file_name (fh), - device_type); - tex->handle = fh; - tex->chart_file_name = parse_chart_file_name (opt (d, o, "charts", - fh_get_file_name (fh))); - tex->chart_cnt = 1; - tex->bg = parse_color (opt (d, o, "background-color", "#FFFFFFFFFFFF")); - tex->fg = parse_color (opt (d, o, "foreground-color", "#000000000000")); - - tex->file = fn_open (tex->handle, "w"); - if (tex->file == NULL) + FILE *file = fn_open (fh, "w"); + if (!file) { msg_error (errno, _("error opening output file `%s'"), - fh_get_file_name (tex->handle)); - goto error; + fh_get_file_name (fh)); + return NULL; } - return d; - - error: - output_driver_destroy (d); - return NULL; + struct tex_driver *tex = xmalloc (sizeof *tex); + *tex = (struct tex_driver) { + .driver = { + .class = &tex_driver_class, + .name = xstrdup (fh_get_file_name (fh)), + .device_type = device_type, + }, + .macros = HMAP_INITIALIZER (tex->macros), + .bg = parse_color (opt (o, "background-color", "#FFFFFFFFFFFF")), + .fg = parse_color (opt (o, "foreground-color", "#000000000000")), + .handle = fh, + .chart_file_name = parse_chart_file_name (opt (o, "charts", + fh_get_file_name (fh))), + .file = file, + .n_charts = 1, + .preamble_list = LL_INITIALIZER (tex->preamble_list), + .token_list = LL_INITIALIZER (tex->token_list), + }; + return &tex->driver; } @@ -175,7 +172,11 @@ post_process_tokens (FILE *file, struct ll_list *list) if (nt->cat == CAT_SPACE || nt->cat == CAT_EOL) break; if (prev_x && (prev_x->cat == CAT_COMMENT) && (nt->cat != CAT_COMMENT)) - break; + { + ds_destroy (&prev_x->str); + free (prev_x); + break; + } word_len += ds_length (&nt->str); prev_x = nt; } @@ -184,6 +185,11 @@ post_process_tokens (FILE *file, struct ll_list *list) { fputs ("\n", file); line_len = 0; + if (tt) + { + ds_destroy (&tt->str); + free (tt); + } continue; } } @@ -314,7 +320,7 @@ tex_submit (struct output_driver *driver, const struct output_item *item) { char *file_name = xr_draw_png_chart (item->chart, tex->chart_file_name, - tex->chart_cnt++, + tex->n_charts++, &tex->fg, &tex->bg); if (file_name != NULL) { @@ -329,12 +335,12 @@ tex_submit (struct output_driver *driver, const struct output_item *item) break; case OUTPUT_ITEM_GROUP: - NOT_REACHED (); + break; case OUTPUT_ITEM_IMAGE: { char *file_name = xr_write_png_image ( - item->image, tex->chart_file_name, tex->chart_cnt++); + item->image, tex->chart_file_name, tex->n_charts++); if (file_name != NULL) { shipout (&tex->token_list, "\\includegraphics{%s}\n", file_name); @@ -356,9 +362,6 @@ tex_submit (struct output_driver *driver, const struct output_item *item) case OUTPUT_ITEM_PAGE_BREAK: break; - case OUTPUT_ITEM_PAGE_SETUP: - break; - case OUTPUT_ITEM_TABLE: tex_output_table (tex, item->table); break; @@ -396,13 +399,12 @@ tex_submit (struct output_driver *driver, const struct output_item *item) static void tex_put_footnote_markers (struct tex_driver *tex, const struct pivot_table *pt, - const size_t *footnote_indexes, - size_t n_footnotes) + const struct pivot_value_ex *ex) { size_t n_visible = 0; - for (size_t i = 0; i < n_footnotes; i++) + for (size_t i = 0; i < ex->n_footnotes; i++) { - const struct pivot_footnote *f = pt->footnotes[footnote_indexes[i]]; + const struct pivot_footnote *f = pt->footnotes[ex->footnote_indexes[i]]; if (f->show) { if (!n_visible++) @@ -426,9 +428,7 @@ tex_put_table_cell (struct tex_driver *tex, const struct pivot_table *pt, tex_escape_string (tex, ds_cstr (&s), false); ds_destroy (&s); - tex_put_footnote_markers (tex, pt, - cell->value->footnote_indexes, - cell->value->n_footnotes); + tex_put_footnote_markers (tex, pt, pivot_value_ex (cell->value)); } static void @@ -552,8 +552,7 @@ tex_output_table_layer (struct tex_driver *tex, const struct pivot_table *pt, tex_escape_string (tex, ds_cstr (&s), true); ds_destroy (&s); - tex_put_footnote_markers (tex, pt, cell.value->footnote_indexes, - cell.value->n_footnotes); + tex_put_footnote_markers (tex, pt, pivot_value_ex (cell.value)); if (halign == TABLE_HALIGN_CENTER || halign == TABLE_HALIGN_RIGHT) { shipout (&tex->token_list, "}");