X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Ftable.c;h=9c931a5a3586fdfe3e267056f27e1b8a45e1e590;hb=d844266ecd4aebd32f55ab22d6ca4266d4a0c4e1;hp=480534e1de4c3de8dbd02a3bc282a96172219144;hpb=beced3ad774631c091241d5087761879c0aa88b1;p=pspp-builds.git diff --git a/src/output/table.c b/src/output/table.c index 480534e1..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 @@ -62,6 +61,7 @@ tab_create (int nc, int nr, int reallocable UNUSED) struct tab_table *t; t = pool_create_container (struct tab_table, container); + t->ref_cnt = 1; t->col_style = TAB_COL_NONE; t->col_group = 0; t->title = NULL; @@ -86,15 +86,28 @@ tab_create (int nc, int nr, int reallocable UNUSED) return t; } -/* Destroys table T. */ +/* Increases T's reference count and, if this causes T's + reference count to reach 0, destroys T. */ void tab_destroy (struct tab_table *t) { - assert (t != NULL); + assert (t->ref_cnt > 0); + if (--t->ref_cnt > 0) + return; + if (t->dim_free != NULL) + t->dim_free (t->dim_aux); free (t->title); pool_destroy (t->container); } +/* Increases T's reference count. */ +void +tab_ref (struct tab_table *t) +{ + assert (t->ref_cnt > 0); + t->ref_cnt++; +} + /* Sets the width and height of a table, in columns and rows, respectively. Use only to reduce the size of a table, since it does not change the amount of allocated memory. */ @@ -397,12 +410,22 @@ tab_title (struct tab_table *t, const char *title, ...) va_end (args); } -/* Set DIM_FUNC as the dimension function for table T. */ +/* Set DIM_FUNC, which will be passed auxiliary data AUX, as the + dimension function for table T. + + DIM_FUNC must not assume that it is called from the same + context as tab_dim; for example, table T might be kept in + memory and, thus, DIM_FUNC might be called after the currently + running command completes. If it is non-null, FREE_FUNC is + called when the table is destroyed, to allow any data + allocated for use by DIM_FUNC to be freed. */ void -tab_dim (struct tab_table *t, tab_dim_func *dim_func, void *aux) +tab_dim (struct tab_table *t, + tab_dim_func *dim_func, tab_dim_free_func *free_func, void *aux) { - assert (t != NULL && t->dim == NULL); + assert (t->dim == NULL); t->dim = dim_func; + t->dim_free = free_func; t->dim_aux = aux; } @@ -813,7 +836,7 @@ tab_output_text (int options, const char *buf, ...) tab_text (t, 0, 0, options & ~TAT_PRINTF, buf); tab_flags (t, SOMF_NO_TITLE | SOMF_NO_SPACING); - tab_dim (t, options & TAT_NOWRAP ? nowrap_dim : wrap_dim, NULL); + tab_dim (t, options & TAT_NOWRAP ? nowrap_dim : wrap_dim, NULL, NULL); tab_submit (t); free (tmp_buf); @@ -1005,10 +1028,12 @@ tabi_render_init (struct som_entity *t_, struct outp_driver *driver, for (i = 0; i < t->nr; i++) if (r->h[i] < 0) - error (0, 0, "height of table row %d not initialized", i); + error (0, 0, "height of table row %d is %d (not initialized?)", + i, r->h[i]); for (i = 0; i < t->nc; i++) if (r->w[i] < 0) - error (0, 0, "width of table column %d not initialized", i); + error (0, 0, "width of table column %d is %d (not initialized?)", + i, r->w[i]); /* Add up header sizes. */ for (i = 0, r->wl = r->wrv[0]; i < r->l; i++) @@ -1132,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) +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; @@ -1460,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; -}