From 32b22a683b99b2675a208b43937fed8463583c1a Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 10 Aug 2009 22:38:21 -0700 Subject: [PATCH] Delete tab_raw function and tab_alloc macro. This function and macro were only used within crosstabs.q. They violate encapsulation (though not too badly) and since it is not difficult to remove them, this commit does so. --- src/language/stats/crosstabs.q | 50 ++++++++++++++-------------------- src/output/table.c | 25 ----------------- src/output/table.h | 5 ---- 3 files changed, 20 insertions(+), 60 deletions(-) diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index ad278eeb..7db55a2c 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -1526,27 +1526,22 @@ table_value_missing (struct crosstabs_proc *proc, struct tab_table *table, int c, int r, unsigned char opt, const union value *v, const struct variable *var) { - struct substring s; - const struct fmt_spec *print = var_get_print_format (var); - const char *label = var_lookup_value_label (var, v); - if (label) - { - tab_text (table, c, r, TAB_LEFT, label); - return; - } - - s.string = tab_alloc (table, print->w); - data_out (v, print, s.string); - s.length = print->w; - if (proc->exclude == MV_NEVER && var_is_num_missing (var, v->f, MV_USER)) - s.string[s.length++] = 'M'; - while (s.length && *s.string == ' ') + if (label != NULL) + tab_text (table, c, r, TAB_LEFT, label); + else { - s.length--; - s.string++; + const struct fmt_spec *print = var_get_print_format (var); + if (proc->exclude == MV_NEVER && var_is_value_missing (var, v, MV_USER)) + { + char *s = xmalloc (print->w + 2); + strcpy (&s[print->w], "M"); + tab_text (table, c, r, opt, s + strspn (s, " ")); + free (s); + } + else + tab_value (table, c, r, opt, v, print); } - tab_raw (table, c, r, opt, &s); } /* Draws a line across TABLE at the current row to indicate the most @@ -1575,23 +1570,18 @@ format_cell_entry (struct tab_table *table, int c, int r, double value, { const struct fmt_spec f = {FMT_F, 10, 1}; union value v; - struct substring s; + int len = 10; + char s[16]; - s.length = 10; - s.string = tab_alloc (table, 16); v.f = value; - data_out (&v, &f, s.string); - while (*s.string == ' ') - { - s.length--; - s.string++; - } + data_out (&v, &f, s); if (suffix != 0) - s.string[s.length++] = suffix; + s[len++] = suffix; if (mark_missing) - s.string[s.length++] = 'M'; + s[len++] = 'M'; + s[len] = '\0'; - tab_raw (table, c, r, TAB_RIGHT, &s); + tab_text (table, c, r, TAB_RIGHT, s + strspn (s, " ")); } /* Displays the crosstabulation table. */ diff --git a/src/output/table.c b/src/output/table.c index b3e0de7a..c94532e8 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -782,31 +782,6 @@ tab_joint_text_format (struct tab_table *table, int x1, int y1, int x2, int y2, pool_vasprintf (table->container, format, args)); va_end (args); } - -/* Sets cell (C,R) in TABLE, with options OPT, to contents STRING. */ -void -tab_raw (struct tab_table *table, int c, int r, unsigned opt, - struct substring *string) -{ - assert (table != NULL && string != NULL); - -#if DEBUGGING - if (c + table->col_ofs < 0 || r + table->row_ofs < 0 - || c + table->col_ofs >= tab_nc (table) - || r + table->row_ofs >= tab_nr (table)) - { - printf ("tab_raw(): bad cell (%d+%d=%d,%d+%d=%d) in table size " - "(%d,%d)\n", - c, table->col_ofs, c + table->col_ofs, - r, table->row_ofs, r + table->row_ofs, - tab_nc (table), tab_nr (table)); - return; - } -#endif - - table->cc[c + r * table->cf] = *string; - table->ct[c + r * table->cf] = opt; -} /* Miscellaneous. */ diff --git a/src/output/table.h b/src/output/table.h index e04da584..84c70964 100644 --- a/src/output/table.h +++ b/src/output/table.h @@ -182,11 +182,6 @@ void tab_joint_text_format (struct tab_table *, int x1, int y1, int x2, int y2, unsigned opt, const char *, ...) PRINTF_FORMAT (7, 8); -/* Cell low-level access. */ -#define tab_alloc(TABLE, AMT) pool_alloc ((TABLE)->container, (AMT)) -void tab_raw (struct tab_table *, int c, int r, unsigned opt, - struct substring *); - /* Editing. */ void tab_offset (struct tab_table *, int col, int row); void tab_next_row (struct tab_table *); -- 2.30.2