From: Ben Pfaff Date: Tue, 23 Jun 2009 06:01:03 +0000 (-0700) Subject: output: Include command names in titles in GUI output. X-Git-Tag: v0.7.3~26 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20f2c8b593eba29c2cca67569a5ef5bb68189c54;p=pspp-builds.git output: Include command names in titles in GUI output. The command name displayed by the output engine was the current command name. The GUI output was never displayed during the actual execution of a command, so GUI titles never included a command name. This commit puts the command name into the struct passed into the output engine, so that it gets saved and displayed. --- diff --git a/src/language/command.c b/src/language/command.c index 5dd2a308..548d671e 100644 --- a/src/language/command.c +++ b/src/language/command.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -37,7 +37,6 @@ #include #include #include -#include #include #if HAVE_SYS_WAIT_H @@ -231,9 +230,9 @@ do_parse_command (struct lexer *lexer, /* Execute command. */ msg_set_command_name (command->name); - tab_set_command_name (command->name); + som_set_command_name (command->name); result = command->function (lexer, ds); - tab_set_command_name (NULL); + som_set_command_name (NULL); msg_set_command_name (NULL); assert (cmd_result_is_valid (result)); diff --git a/src/output/manager.c b/src/output/manager.c index 4699da03..505362d3 100644 --- a/src/output/manager.c +++ b/src/output/manager.c @@ -15,16 +15,42 @@ along with this program. If not, see . */ #include -#include "manager.h" + +#include + #include #include + #include -#include "output.h" +#include + +#include "gl/xalloc.h" /* Table. */ static int table_num = 1; static int subtable_num; + +/* Name of PSPP's current command, or NULL if outside a command. */ +static char *command_name; +struct som_entity * +som_entity_clone (struct som_entity *entity) +{ + struct som_entity *copy = xmemdup (entity, sizeof *entity); + copy->command_name = xstrdup (entity->command_name); + return copy; +} + +void +som_entity_destroy (struct som_entity *entity) +{ + if (entity != NULL) + { + free (entity->command_name); + free (entity); + } +} + /* Increments table_num so different procedures' output can be distinguished. */ void @@ -37,6 +63,15 @@ som_new_series (void) } } +/* Sets COMMAND_NAME as the name of the current command, + for embedding in output. */ +void +som_set_command_name (const char *command_name_) +{ + free (command_name); + command_name = command_name_ ? xstrdup (command_name_) : NULL; +} + /* Ejects the paper for all active devices. */ void som_eject_page (void) @@ -86,6 +121,7 @@ void som_submit (struct som_entity *t) { struct outp_driver *d; + unsigned int flags; #if DEBUGGING static int entry; @@ -93,18 +129,18 @@ som_submit (struct som_entity *t) assert (entry++ == 0); #endif + t->class->flags (t, &flags); + if (!(flags & SOMF_NO_TITLE)) + subtable_num++; + t->table_num = table_num; + t->subtable_num = subtable_num; + t->command_name = xstrdup (command_name); + if (t->type == SOM_TABLE) { - unsigned int flags; int hl, hr, ht, hb; int nc, nr; - t->class->flags (t, &flags); - if (!(flags & SOMF_NO_TITLE)) - subtable_num++; - t->table_num = table_num; - t->subtable_num = subtable_num; - t->class->count (t, &nc, &nr); t->class->headers (t, &hl, &hr, &ht, &hb); if (hl + hr > nc || ht + hb > nr) @@ -260,7 +296,8 @@ render_columns (void *r, struct outp_driver *d, struct som_entity *t, if (len > max_len) max_len = len; - t->class->title (r, index++, 0, t->table_num, t->subtable_num); + t->class->title (r, index++, 0, t->table_num, t->subtable_num, + t->command_name); t->class->render (r, 0, y0, nc, y1); d->cp_x += tw + 2 * d->prop_em_width; @@ -293,7 +330,7 @@ render_simple (void *r, struct outp_driver *d, struct som_entity *t, assert (d->cp_x == 0); assert (tw < d->width && th + d->cp_y < d->length); - t->class->title (r, 0, 0, t->table_num, t->subtable_num); + t->class->title (r, 0, 0, t->table_num, t->subtable_num, t->command_name); t->class->render (r, hl, ht, nc - hr, nr - hb); d->cp_y += th; } @@ -343,7 +380,7 @@ render_segments (void *r, struct outp_driver *d, struct som_entity *t, { t->class->title (r, x_index ? x_index : y_index, x_index ? y_index : 0, - t->table_num, t->subtable_num); + t->table_num, t->subtable_num, t->command_name); t->class->render (r, x0, y0, x1, y1); d->cp_y += len; diff --git a/src/output/manager.h b/src/output/manager.h index 1aa2c36a..8ed104ba 100644 --- a/src/output/manager.h +++ b/src/output/manager.h @@ -49,8 +49,12 @@ struct som_entity void *ext; /* Owned by table or chart class. */ int table_num; /* Table number. */ int subtable_num; /* Sub-table number. */ + char *command_name; /* Command that yielded this output. */ }; +struct som_entity *som_entity_clone (struct som_entity *); +void som_entity_destroy (struct som_entity *); + /* Group styles. */ enum { @@ -92,12 +96,14 @@ struct som_table_class void (*area) (void *, int *horiz, int *vert); void (*cumulate) (void *, int cumtype, int start, int *end, int max, int *actual); - void (*title) (void *, int x, int y, int table_num, int subtable_num); + void (*title) (void *, int x, int y, int table_num, int subtable_num, + const char *command_name); void (*render) (void *, int x1, int y1, int x2, int y2); }; /* Submission. */ void som_new_series (void); +void som_set_command_name (const char *); void som_submit (struct som_entity *t); /* Miscellaneous. */ diff --git a/src/output/table.c b/src/output/table.c index 1b052888..9c931a5a 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -44,7 +44,6 @@ #define _(msgid) gettext (msgid) const struct som_table_class tab_table_class; -static char *command_name; /* Returns the font to use for a cell with the given OPTIONS. */ static enum outp_font @@ -1158,7 +1157,8 @@ tabi_cumulate (void *r_, int cumtype, int start, int *end, Y. Y may be zero, or X and Y may be zero, but X should be nonzero if Y is nonzero. */ static void -tabi_title (void *r_, int x, int y, int table_num, int subtable_num) +tabi_title (void *r_, int x, int y, int table_num, int subtable_num, + const char *command_name) { const struct tab_rendering *r = r_; const struct tab_table *t = r->table; @@ -1486,12 +1486,3 @@ render_strip (const struct tab_rendering *r, return x; } - -/* Sets COMMAND_NAME as the name of the current command, - for embedding in output. */ -void -tab_set_command_name (const char *command_name_) -{ - free (command_name); - command_name = command_name_ ? xstrdup (command_name_) : NULL; -} diff --git a/src/output/table.h b/src/output/table.h index 03c981a3..7f128814 100644 --- a/src/output/table.h +++ b/src/output/table.h @@ -198,8 +198,5 @@ void tab_next_row (struct tab_table *); void tab_output_text (int options, const char *string, ...) PRINTF_FORMAT (2, 3); -/* Embedding the command name in the output. */ -void tab_set_command_name (const char *); - #endif /* tab_h */ diff --git a/src/ui/gui/psppire-output-window.c b/src/ui/gui/psppire-output-window.c index 06692c2a..542e7b30 100644 --- a/src/ui/gui/psppire-output-window.c +++ b/src/ui/gui/psppire-output-window.c @@ -129,7 +129,8 @@ expose_event_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data) tab_r (t), tab_t (t), tab_b (t)); entity->class->title (rendering, 0, 0, - entity->table_num, entity->subtable_num); + entity->table_num, entity->subtable_num, + entity->command_name); entity->class->render (rendering, tab_l (t), tab_t (t), tab_nc (t) - tab_r (t), tab_nr (t) - tab_b (t)); @@ -168,7 +169,7 @@ psppire_output_submit (struct outp_driver *this, struct som_entity *entity) gtk_widget_modify_bg (GTK_WIDGET (drawing_area), GTK_STATE_NORMAL, >k_widget_get_style (drawing_area)->base[GTK_STATE_NORMAL]); g_object_set_data (G_OBJECT (drawing_area), - "entity", xmemdup (entity, sizeof *entity)); + "entity", som_entity_clone (entity)); gtk_widget_set_size_request (drawing_area, tw / 1024, th / 1024); gtk_layout_put (the_output_viewer->output, drawing_area, 0, the_output_viewer->y);