From: Ben Pfaff Date: Tue, 11 Aug 2009 04:53:18 +0000 (-0700) Subject: Separate table functions that format their arguments from those that don't. X-Git-Tag: sid-i386-build98~8 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59981a5060a0e672b98655be240886d89a513d31;p=pspp-builds.git Separate table functions that format their arguments from those that don't. The tab_text, tab_joint_text, and tab_output_text functions, until now, had an option bit TAT_PRINTF that specified whether they passed their text argument through sprintf. This interface was bad because it made it impossible for GCC to tell whether it needed to verify a printf format string or not. This commit solves the problem by breaking each of these functions into one that does format its argument and one that doesn't. This is cross-ported from a similar commit on the master branch. --- diff --git a/src/language/data-io/data-parser.c b/src/language/data-io/data-parser.c index d348a4e2..b1592950 100644 --- a/src/language/data-io/data-parser.c +++ b/src/language/data-io/data-parser.c @@ -656,9 +656,9 @@ dump_fixed_table (const struct data_parser *parser, int row = i + 1; tab_text (t, 0, row, TAB_LEFT, f->name); - tab_text (t, 1, row, TAT_PRINTF, "%d", f->record); - tab_text (t, 2, row, TAT_PRINTF, "%3d-%3d", - f->first_column, f->first_column + f->format.w - 1); + tab_text_format (t, 1, row, 0, "%d", f->record); + tab_text_format (t, 2, row, 0, "%3d-%3d", + f->first_column, f->first_column + f->format.w - 1); tab_text (t, 3, row, TAB_LEFT | TAB_FIX, fmt_to_string (&f->format, fmt_string)); } diff --git a/src/language/data-io/print.c b/src/language/data-io/print.c index fa84f83a..f7a3d152 100644 --- a/src/language/data-io/print.c +++ b/src/language/data-io/print.c @@ -413,8 +413,9 @@ dump_table (struct print_trns *trns, const struct file_handle *fh) switch (spec->type) { case PRT_LITERAL: - tab_text (t, 0, row, TAB_LEFT | TAB_FIX | TAT_PRINTF, "\"%.*s\"", - (int) ds_length (&spec->string), ds_data (&spec->string)); + tab_text_format (t, 0, row, TAB_LEFT | TAB_FIX, "\"%.*s\"", + (int) ds_length (&spec->string), + ds_data (&spec->string)); width = ds_length (&spec->string); break; case PRT_VAR: @@ -426,9 +427,9 @@ dump_table (struct print_trns *trns, const struct file_handle *fh) default: NOT_REACHED (); } - tab_text (t, 1, row, TAT_PRINTF, "%d", spec->record); - tab_text (t, 2, row, TAT_PRINTF, "%3d-%3d", - spec->first_column, spec->first_column + width - 1); + tab_text_format (t, 1, row, 0, "%d", spec->record); + tab_text_format (t, 2, row, 0, "%3d-%3d", + spec->first_column, spec->first_column + width - 1); row++; } diff --git a/src/language/dictionary/split-file.c b/src/language/dictionary/split-file.c index 62b67762..c0349d02 100644 --- a/src/language/dictionary/split-file.c +++ b/src/language/dictionary/split-file.c @@ -92,12 +92,12 @@ output_split_file_values (const struct dataset *ds, const struct ccase *c) const char *val_lab; const struct fmt_spec *print = var_get_print_format (v); - tab_text (t, 0, i + 1, TAB_LEFT | TAT_PRINTF, "%s", var_get_name (v)); + tab_text_format (t, 0, i + 1, TAB_LEFT, "%s", var_get_name (v)); data_out (case_data (c, v), print, temp_buf); temp_buf[print->w] = 0; - tab_text (t, 1, i + 1, TAT_PRINTF, "%.*s", print->w, temp_buf); + tab_text_format (t, 1, i + 1, 0, "%.*s", print->w, temp_buf); val_lab = var_lookup_value_label (v, case_data (c, v)); if (val_lab) diff --git a/src/language/dictionary/sys-file-info.c b/src/language/dictionary/sys-file-info.c index fc22b9e9..0a7123e9 100644 --- a/src/language/dictionary/sys-file-info.c +++ b/src/language/dictionary/sys-file-info.c @@ -121,8 +121,8 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) tab_text (t, 1, 1, TAB_LEFT, label); } tab_text (t, 0, 2, TAB_LEFT, _("Created:")); - tab_text (t, 1, 2, TAB_LEFT | TAT_PRINTF, "%s %s by %s", - info.creation_date, info.creation_time, info.product); + tab_text_format (t, 1, 2, TAB_LEFT, "%s %s by %s", + info.creation_date, info.creation_time, info.product); tab_text (t, 0, 3, TAB_LEFT, _("Integer Format:")); tab_text (t, 1, 3, TAB_LEFT, info.integer_format == INTEGER_MSB_FIRST ? _("Big Endian.") @@ -137,11 +137,11 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) : info.float_format == FLOAT_Z_LONG ? _("IBM 390 Hex Long.") : _("Unknown.")); tab_text (t, 0, 5, TAB_LEFT, _("Variables:")); - tab_text (t, 1, 5, TAB_LEFT | TAT_PRINTF, "%zu", dict_get_var_cnt (d)); + tab_text_format (t, 1, 5, TAB_LEFT, "%zu", dict_get_var_cnt (d)); tab_text (t, 0, 6, TAB_LEFT, _("Cases:")); - tab_text (t, 1, 6, TAB_LEFT | TAT_PRINTF, - info.case_cnt == -1 ? _("Unknown") : "%ld", - (long int) info.case_cnt); + tab_text_format (t, 1, 6, TAB_LEFT, + info.case_cnt == -1 ? _("Unknown") : "%ld", + (long int) info.case_cnt); tab_text (t, 0, 7, TAB_LEFT, _("Type:")); tab_text (t, 1, 7, TAB_LEFT, _("System File.")); tab_text (t, 0, 8, TAB_LEFT, _("Weight:")); @@ -152,13 +152,13 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) ? var_get_name (weight_var) : _("Not weighted."))); } tab_text (t, 0, 9, TAB_LEFT, _("Mode:")); - tab_text (t, 1, 9, TAB_LEFT | TAT_PRINTF, - _("Compression %s."), info.compressed ? _("on") : _("off")); + tab_text_format (t, 1, 9, TAB_LEFT, + _("Compression %s."), info.compressed ? _("on") : _("off")); tab_text (t, 0, 10, TAB_LEFT, _("Charset:")); - tab_text (t, 1, 10, TAB_LEFT | TAT_PRINTF, - dict_get_encoding(d) ? dict_get_encoding(d) : _("Unknown")); + tab_text_format (t, 1, 10, TAB_LEFT, + dict_get_encoding(d) ? dict_get_encoding(d) : _("Unknown")); tab_dim (t, tab_natural_dimensions, NULL, NULL); @@ -464,8 +464,7 @@ display_attributes (struct tab_table *t, const struct attrset *set, int flags, for (i = 0; i < n_values; i++) { if (n_values > 1) - tab_text (t, c, r, TAB_LEFT | TAT_PRINTF, "%s[%d]", - name, i + 1); + tab_text_format (t, c, r, TAB_LEFT, "%s[%d]", name, i + 1); else tab_text (t, c, r, TAB_LEFT, name); tab_text (t, c + 1, r, TAB_LEFT, attribute_get_value (attr, i)); @@ -528,7 +527,7 @@ describe_variable (const struct variable *v, struct tab_table *t, int r, /* Put the name, var label, and position into the first row. */ tab_text (t, 0, r, TAB_LEFT, var_get_name (v)); if (flags & DF_DICT_INDEX) - tab_text (t, pc, r, TAT_PRINTF, "%zu", var_get_dict_index (v) + 1); + tab_text_format (t, pc, r, 0, "%zu", var_get_dict_index (v) + 1); if (flags & DF_VARIABLE_LABELS && var_has_label (v)) { @@ -545,18 +544,20 @@ describe_variable (const struct variable *v, struct tab_table *t, int r, if (fmt_equal (print, write)) { char str[FMT_STRING_LEN_MAX + 1]; - tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, - _("Format: %s"), fmt_to_string (print, str)); + tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT, + _("Format: %s"), fmt_to_string (print, str)); r++; } else { char str[FMT_STRING_LEN_MAX + 1]; - tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, - _("Print Format: %s"), fmt_to_string (print, str)); + tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT, + _("Print Format: %s"), + fmt_to_string (print, str)); r++; - tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, - _("Write Format: %s"), fmt_to_string (write, str)); + tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT, + _("Write Format: %s"), + fmt_to_string (write, str)); r++; } } @@ -567,20 +568,21 @@ describe_variable (const struct variable *v, struct tab_table *t, int r, enum measure m = var_get_measure (v); enum alignment a = var_get_alignment (v); - tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, - _("Measure: %s"), - m == MEASURE_NOMINAL ? _("Nominal") - : m == MEASURE_ORDINAL ? _("Ordinal") - : _("Scale")); + tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT, + _("Measure: %s"), + m == MEASURE_NOMINAL ? _("Nominal") + : m == MEASURE_ORDINAL ? _("Ordinal") + : _("Scale")); r++; - tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, - _("Display Alignment: %s"), - a == ALIGN_LEFT ? _("Left") - : a == ALIGN_CENTRE ? _("Center") - : _("Right")); + tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT, + _("Display Alignment: %s"), + a == ALIGN_LEFT ? _("Left") + : a == ALIGN_CENTRE ? _("Center") + : _("Right")); r++; - tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, - _("Display Width: %d"), var_get_display_width (v)); + tab_joint_text_format (t, 1, r, 2, r, TAB_LEFT, + _("Display Width: %d"), + var_get_display_width (v)); r++; } @@ -744,7 +746,7 @@ display_vectors (const struct dictionary *dict, int sorted) char fmt_string[FMT_STRING_LEN_MAX + 1]; fmt_to_string (var_get_print_format (var), fmt_string); - tab_text (t, 1, row, TAB_RIGHT | TAT_PRINTF, "%zu", j + 1); + tab_text_format (t, 1, row, TAB_RIGHT, "%zu", j + 1); tab_text (t, 2, row, TAB_LEFT, var_get_name (var)); tab_text (t, 3, row, TAB_LEFT, fmt_string); row++; diff --git a/src/language/stats/binomial.c b/src/language/stats/binomial.c index 67e378bb..68a747bb 100644 --- a/src/language/stats/binomial.c +++ b/src/language/stats/binomial.c @@ -261,9 +261,9 @@ binomial_execute (const struct dataset *ds, tab_text (table, 4, 0, TAB_CENTER, _("Observed Prop.")); tab_text (table, 5, 0, TAB_CENTER, _("Test Prop.")); - tab_text (table, 6, 0, TAB_CENTER | TAT_PRINTF, - _("Exact Sig. (%d-tailed)"), - bst->p == 0.5 ? 2: 1); + tab_text_format (table, 6, 0, TAB_CENTER, + _("Exact Sig. (%d-tailed)"), + bst->p == 0.5 ? 2 : 1); tab_vline (table, TAL_2, 2, 0, tab_nr (table) -1); tab_submit (table); diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index ff249136..2b45cf14 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -887,8 +887,8 @@ make_summary_table (struct crosstabs_proc *proc) { tab_double (summary, i * 2 + 1, 0, TAB_RIGHT, n[i], &proc->weight_format); - tab_text (summary, i * 2 + 2, 0, TAB_RIGHT | TAT_PRINTF, "%.1f%%", - n[i] / n[2] * 100.); + tab_text_format (summary, i * 2 + 2, 0, TAB_RIGHT, "%.1f%%", + n[i] / n[2] * 100.); } tab_next_row (summary); @@ -1282,8 +1282,8 @@ create_risk_table (struct pivot_table *pt) tab_title (risk, _("Risk estimate.")); tab_offset (risk, pt->n_vars - 2, 0); - tab_joint_text (risk, 2, 0, 3, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, - _("95%% Confidence Interval")); + tab_joint_text_format (risk, 2, 0, 3, 0, TAB_CENTER | TAT_TITLE, + _("95%% Confidence Interval")); tab_text (risk, 0, 1, TAB_LEFT | TAT_TITLE, _("Statistic")); tab_text (risk, 1, 1, TAB_RIGHT | TAT_TITLE, _("Value")); tab_text (risk, 2, 1, TAB_RIGHT | TAT_TITLE, _("Lower")); @@ -2080,8 +2080,8 @@ display_directional (struct crosstabs_proc *proc, struct pivot_table *pt, else string = var_get_name (pt->vars[1]); - tab_text (direct, j, 0, TAB_LEFT | TAT_PRINTF, - gettext (stats_names[j][k]), string); + tab_text_format (direct, j, 0, TAB_LEFT, + gettext (stats_names[j][k]), string); } } } diff --git a/src/language/stats/descriptives.c b/src/language/stats/descriptives.c index 7ecf7350..c5d46964 100644 --- a/src/language/stats/descriptives.c +++ b/src/language/stats/descriptives.c @@ -905,9 +905,9 @@ display (struct dsc_proc *dsc) nc = 0; tab_text (t, nc++, i + 1, TAB_LEFT, var_get_name (dv->v)); - tab_text (t, nc++, i + 1, TAT_PRINTF, "%g", dv->valid); + tab_text_format (t, nc++, i + 1, 0, "%g", dv->valid); if (dsc->format == DSC_SERIAL) - tab_text (t, nc++, i + 1, TAT_PRINTF, "%g", dv->missing); + tab_text_format (t, nc++, i + 1, 0, "%g", dv->missing); for (j = 0; j < DSC_N_STATS; j++) if (dsc->show_stats & (1ul << j)) diff --git a/src/language/stats/examine.q b/src/language/stats/examine.q index acbdf3e0..41a43abf 100644 --- a/src/language/stats/examine.q +++ b/src/language/stats/examine.q @@ -1294,10 +1294,10 @@ show_summary (const struct variable **dependent_var, int n_dep_var, TAB_LEFT, n, wfmt); - tab_text (tbl, heading_columns + 1, - heading_rows + j + v * ll_count (&fctr->result_list), - TAB_RIGHT | TAT_PRINTF, - "%g%%", n * 100.0 / result->metrics[v].n); + tab_text_format (tbl, heading_columns + 1, + heading_rows + j + v * ll_count (&fctr->result_list), + TAB_RIGHT, + "%g%%", n * 100.0 / result->metrics[v].n); /* Total Missing */ tab_double (tbl, heading_columns + 2, @@ -1306,12 +1306,12 @@ show_summary (const struct variable **dependent_var, int n_dep_var, result->metrics[v].n - n, wfmt); - tab_text (tbl, heading_columns + 3, - heading_rows + j + v * ll_count (&fctr->result_list), - TAB_RIGHT | TAT_PRINTF, - "%g%%", - (result->metrics[v].n - n) * 100.0 / result->metrics[v].n - ); + tab_text_format (tbl, heading_columns + 3, + heading_rows + j + v * ll_count (&fctr->result_list), + TAB_RIGHT, + "%g%%", + (result->metrics[v].n - n) * 100.0 / result->metrics[v].n + ); /* Total Valid + Missing */ tab_double (tbl, heading_columns + 4, @@ -1320,12 +1320,12 @@ show_summary (const struct variable **dependent_var, int n_dep_var, result->metrics[v].n, wfmt); - tab_text (tbl, heading_columns + 5, - heading_rows + j + v * ll_count (&fctr->result_list), - TAB_RIGHT | TAT_PRINTF, - "%g%%", - (result->metrics[v].n) * 100.0 / result->metrics[v].n - ); + tab_text_format (tbl, heading_columns + 5, + heading_rows + j + v * ll_count (&fctr->result_list), + TAB_RIGHT, + "%g%%", + ((result->metrics[v].n) * 100.0 + / result->metrics[v].n)); ++j; } @@ -1447,11 +1447,11 @@ show_descriptives (const struct variable **dependent_var, TAB_LEFT, _("Mean")); - tab_text (tbl, n_cols - 4, - heading_rows + row_var_start + 1 + i * DESCRIPTIVE_ROWS, - TAB_LEFT | TAT_PRINTF, - _("%g%% Confidence Interval for Mean"), - cmd.n_cinterval[0]); + tab_text_format (tbl, n_cols - 4, + heading_rows + row_var_start + 1 + i * DESCRIPTIVE_ROWS, + TAB_LEFT, + _("%g%% Confidence Interval for Mean"), + cmd.n_cinterval[0]); tab_text (tbl, n_cols - 3, heading_rows + row_var_start + 1 + i * DESCRIPTIVE_ROWS, @@ -1464,9 +1464,8 @@ show_descriptives (const struct variable **dependent_var, _("Upper Bound")); tab_text (tbl, n_cols - 4, - heading_rows + row_var_start + 3 + i * DESCRIPTIVE_ROWS, - TAB_LEFT | TAT_PRINTF, - _("5%% Trimmed Mean")); + heading_rows + row_var_start + 3 + i * DESCRIPTIVE_ROWS, + TAB_LEFT, _("5% Trimmed Mean")); tab_text (tbl, n_cols - 4, heading_rows + row_var_start + 4 + i * DESCRIPTIVE_ROWS, @@ -1737,15 +1736,15 @@ show_extremes (const struct variable **dependent_var, for ( e = 1; e <= cmd.st_n; ++e ) { - tab_text (tbl, n_cols - 3, - heading_rows + row_var_start + row_result_start + e - 1, - TAB_RIGHT | TAT_PRINTF, - _("%d"), e); - - tab_text (tbl, n_cols - 3, - heading_rows + row_var_start + row_result_start + cmd.st_n + e - 1, - TAB_RIGHT | TAT_PRINTF, - _("%d"), e); + tab_text_format (tbl, n_cols - 3, + heading_rows + row_var_start + row_result_start + e - 1, + TAB_RIGHT, + "%d", e); + + tab_text_format (tbl, n_cols - 3, + heading_rows + row_var_start + row_result_start + cmd.st_n + e - 1, + TAB_RIGHT, + "%d", e); } @@ -2008,11 +2007,10 @@ show_percentiles (const struct variable **dependent_var, for (i = 0 ; i < n_percentiles; ++i ) { - tab_text (tbl, n_cols - n_percentiles + i, 1, - TAB_CENTER | TAT_TITLE | TAT_PRINTF, - _("%g"), - subc_list_double_at (&percentile_list, i) - ); + tab_text_format (tbl, n_cols - n_percentiles + i, 1, + TAB_CENTER | TAT_TITLE, + _("%g"), + subc_list_double_at (&percentile_list, i)); } diff --git a/src/language/stats/oneway.q b/src/language/stats/oneway.q index e1d5b79f..de881734 100644 --- a/src/language/stats/oneway.q +++ b/src/language/stats/oneway.q @@ -394,8 +394,9 @@ show_descriptives (const struct dictionary *dict) tab_vline (t, TAL_0, 7, 0, 0); tab_hline (t, TAL_1, 6, 7, 1); - tab_joint_text (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, - _("%g%% Confidence Interval for Mean"), confidence*100.0); + tab_joint_text_format (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE, + _("%g%% Confidence Interval for Mean"), + confidence*100.0); tab_text (t, 6, 1, TAB_CENTER | TAT_TITLE, _("Lower Bound")); tab_text (t, 7, 1, TAB_CENTER | TAT_TITLE, _("Upper Bound")); @@ -636,14 +637,13 @@ show_contrast_coeffs (short *bad_contrast) for (i = 0; i < cmd.sbc_contrast; ++i ) { - tab_text (t, 1, i + 2, TAB_CENTER | TAT_PRINTF, "%d", i + 1); + tab_text_format (t, 1, i + 2, TAB_CENTER, "%d", i + 1); if ( bad_contrast[i] ) tab_text (t, count + 2, i + 2, TAB_RIGHT, "?" ); else - tab_text (t, count + 2, i + 2, TAB_RIGHT | TAT_PRINTF, "%g", - subc_list_double_at (&cmd.dl_contrast[i], count) - ); + tab_text_format (t, count + 2, i + 2, TAB_RIGHT, "%g", + subc_list_double_at (&cmd.dl_contrast[i], count)); } } @@ -740,12 +740,13 @@ show_contrast_tests (short *bad_contrast) _("Does not assume equal")); } - tab_text (t, 2, (v * lines_per_variable) + i + 1, - TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d", i + 1); + tab_text_format (t, 2, (v * lines_per_variable) + i + 1, + TAB_CENTER | TAT_TITLE, "%d", i + 1); - tab_text (t, 2, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast, - TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d", i + 1); + tab_text_format (t, 2, + (v * lines_per_variable) + i + 1 + cmd.sbc_contrast, + TAB_CENTER | TAT_TITLE, "%d", i + 1); if ( bad_contrast[i]) diff --git a/src/language/stats/rank.q b/src/language/stats/rank.q index 8ae4076d..c225370e 100644 --- a/src/language/stats/rank.q +++ b/src/language/stats/rank.q @@ -714,48 +714,44 @@ cmd_rank (struct lexer *lexer, struct dataset *ds) if ( rank_specs[i].rfunc == NORMAL || rank_specs[i].rfunc == PROPORTION ) - tab_output_text (TAT_PRINTF, - _("%s into %s(%s of %s using %s BY %s)"), - var_get_name (src_vars[v]), - var_get_name (rank_specs[i].destvars[v]), - function_name[rank_specs[i].rfunc], - var_get_name (src_vars[v]), - fraction_name(), - ds_cstr (&varlist) - ); + tab_output_text_format (0, + _("%s into %s(%s of %s using %s BY %s)"), + var_get_name (src_vars[v]), + var_get_name (rank_specs[i].destvars[v]), + function_name[rank_specs[i].rfunc], + var_get_name (src_vars[v]), + fraction_name(), + ds_cstr (&varlist)); else - tab_output_text (TAT_PRINTF, - _("%s into %s(%s of %s BY %s)"), - var_get_name (src_vars[v]), - var_get_name (rank_specs[i].destvars[v]), - function_name[rank_specs[i].rfunc], - var_get_name (src_vars[v]), - ds_cstr (&varlist) - ); + tab_output_text_format (0, + _("%s into %s(%s of %s BY %s)"), + var_get_name (src_vars[v]), + var_get_name (rank_specs[i].destvars[v]), + function_name[rank_specs[i].rfunc], + var_get_name (src_vars[v]), + ds_cstr (&varlist)); ds_destroy (&varlist); } else { if ( rank_specs[i].rfunc == NORMAL || rank_specs[i].rfunc == PROPORTION ) - tab_output_text (TAT_PRINTF, - _("%s into %s(%s of %s using %s)"), - var_get_name (src_vars[v]), - var_get_name (rank_specs[i].destvars[v]), - function_name[rank_specs[i].rfunc], - var_get_name (src_vars[v]), - fraction_name() - ); + tab_output_text_format (0, + _("%s into %s(%s of %s using %s)"), + var_get_name (src_vars[v]), + var_get_name (rank_specs[i].destvars[v]), + function_name[rank_specs[i].rfunc], + var_get_name (src_vars[v]), + fraction_name()); else - tab_output_text (TAT_PRINTF, - _("%s into %s(%s of %s)"), - var_get_name (src_vars[v]), - var_get_name (rank_specs[i].destvars[v]), - function_name[rank_specs[i].rfunc], - var_get_name (src_vars[v]) - ); + tab_output_text_format (0, + _("%s into %s(%s of %s)"), + var_get_name (src_vars[v]), + var_get_name (rank_specs[i].destvars[v]), + function_name[rank_specs[i].rfunc], + var_get_name (src_vars[v])); } } } diff --git a/src/language/stats/regression.q b/src/language/stats/regression.q index 155ac3fd..fc67845d 100644 --- a/src/language/stats/regression.q +++ b/src/language/stats/regression.q @@ -315,9 +315,9 @@ reg_stats_anova (pspp_linreg_cache * c) /* Degrees of freedom */ - tab_text (t, 3, 1, TAB_RIGHT | TAT_PRINTF, "%g", c->dfm); - tab_text (t, 3, 2, TAB_RIGHT | TAT_PRINTF, "%g", c->dfe); - tab_text (t, 3, 3, TAB_RIGHT | TAT_PRINTF, "%g", c->dft); + tab_text_format (t, 3, 1, TAB_RIGHT, "%g", c->dfm); + tab_text_format (t, 3, 2, TAB_RIGHT, "%g", c->dfe); + tab_text_format (t, 3, 3, TAB_RIGHT, "%g", c->dft); /* Mean Squares */ tab_double (t, 4, 1, TAB_RIGHT, msm, NULL); diff --git a/src/language/stats/reliability.q b/src/language/stats/reliability.q index 52d8e3cb..9d220b9d 100644 --- a/src/language/stats/reliability.q +++ b/src/language/stats/reliability.q @@ -386,7 +386,7 @@ run_reliability (struct casereader *input, struct dataset *ds, tab_dim (tab, tab_natural_dimensions, NULL, NULL); tab_flags (tab, SOMF_NO_TITLE ); - tab_text(tab, 0, 0, TAT_PRINTF, "Scale: %s", ds_cstr (&rel->scale_name)); + tab_text_format (tab, 0, 0, 0, "Scale: %s", ds_cstr (&rel->scale_name)); tab_submit(tab); } @@ -720,8 +720,7 @@ case_processing_summary (casenumber n_valid, casenumber n_missing, tab_text (tbl, heading_columns, 0, TAB_CENTER | TAT_TITLE, _("N")); - tab_text (tbl, heading_columns + 1, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, - _("%%")); + tab_text (tbl, heading_columns + 1, 0, TAB_CENTER | TAT_TITLE, _("%")); total = n_missing + n_valid; diff --git a/src/language/stats/t-test.q b/src/language/stats/t-test.q index fad93b4f..3b810f64 100644 --- a/src/language/stats/t-test.q +++ b/src/language/stats/t-test.q @@ -577,10 +577,10 @@ ssbox_independent_samples_populate (struct ssbox *ssb, tab_text (ssb->t, 0, i * 2 + 1, TAB_LEFT, var_get_name (proc->vars[i])); - tab_text (ssb->t, 1, i * 2 + 1, TAB_LEFT | TAT_PRINTF, - "%s%s", prefix[0], val_lab[0]); - tab_text (ssb->t, 1, i * 2 + 1+ 1, TAB_LEFT | TAT_PRINTF, - "%s%s", prefix[1], val_lab[1]); + tab_text_format (ssb->t, 1, i * 2 + 1, TAB_LEFT, + "%s%s", prefix[0], val_lab[0]); + tab_text_format (ssb->t, 1, i * 2 + 1+ 1, TAB_LEFT, + "%s%s", prefix[1], val_lab[1]); /* Fill in the group statistics */ for (count = 0; count < 2; count++) @@ -639,7 +639,7 @@ ssbox_paired_populate (struct ssbox *ssb, struct t_test_proc *proc) struct pair *p = &proc->pairs[i]; int j; - tab_text (ssb->t, 0, i * 2 + 1, TAB_LEFT | TAT_PRINTF, _("Pair %d"), i); + tab_text_format (ssb->t, 0, i * 2 + 1, TAB_LEFT, _("Pair %d"), i); for (j=0; j < 2; j++) { /* Titles */ @@ -757,9 +757,9 @@ trbox_independent_samples_init (struct trbox *self, tab_text (self->t, 9, 2, TAB_CENTER | TAT_TITLE, _("Lower")); tab_text (self->t, 10, 2, TAB_CENTER | TAT_TITLE, _("Upper")); - tab_joint_text (self->t, 9, 1, 10, 1, TAB_CENTER | TAT_PRINTF, - _("%g%% Confidence Interval of the Difference"), - proc->criteria * 100.0); + tab_joint_text_format (self->t, 9, 1, 10, 1, TAB_CENTER, + _("%g%% Confidence Interval of the Difference"), + proc->criteria * 100.0); } /* Populate the independent samples trbox */ @@ -911,9 +911,9 @@ trbox_paired_init (struct trbox *self, struct t_test_proc *proc) tab_hline (self->t, TAL_1, 5, 6, 2); tab_vline (self->t, TAL_GAP, 6, 0, 1); - tab_joint_text (self->t, 5, 1, 6, 1, TAB_CENTER | TAT_PRINTF, - _("%g%% Confidence Interval of the Difference"), - proc->criteria*100.0); + tab_joint_text_format (self->t, 5, 1, 6, 1, TAB_CENTER, + _("%g%% Confidence Interval of the Difference"), + proc->criteria*100.0); tab_text (self->t, 2, 2, TAB_CENTER | TAT_TITLE, _("Mean")); tab_text (self->t, 3, 2, TAB_CENTER | TAT_TITLE, _("Std. Deviation")); @@ -942,10 +942,10 @@ trbox_paired_populate (struct trbox *trb, double t; double df = n - 1; - tab_text (trb->t, 0, i + 3, TAB_LEFT | TAT_PRINTF, _("Pair %d"), i); - tab_text (trb->t, 1, i + 3, TAB_LEFT | TAT_PRINTF, "%s - %s", - var_get_name (pair->v[0]), - var_get_name (pair->v[1])); + tab_text_format (trb->t, 0, i + 3, TAB_LEFT, _("Pair %d"), i); + tab_text_format (trb->t, 1, i + 3, TAB_LEFT, "%s - %s", + var_get_name (pair->v[0]), + var_get_name (pair->v[1])); tab_double (trb->t, 2, i + 3, TAB_RIGHT, pair->mean_diff, NULL); tab_double (trb->t, 3, i + 3, TAB_RIGHT, pair->std_dev_diff, NULL); @@ -995,15 +995,15 @@ trbox_one_sample_init (struct trbox *self, struct t_test_proc *proc) tab_hline (self->t, TAL_1, 1, hsize - 1, 1); tab_vline (self->t, TAL_2, 1, 0, vsize - 1); - tab_joint_text (self->t, 1, 0, hsize - 1, 0, TAB_CENTER | TAT_PRINTF, - _("Test Value = %f"), proc->testval); + tab_joint_text_format (self->t, 1, 0, hsize - 1, 0, TAB_CENTER, + _("Test Value = %f"), proc->testval); tab_box (self->t, -1, -1, -1, TAL_1, 1, 1, hsize - 1, vsize - 1); - tab_joint_text (self->t, 5, 1, 6, 1, TAB_CENTER | TAT_PRINTF, - _("%g%% Confidence Interval of the Difference"), - proc->criteria * 100.0); + tab_joint_text_format (self->t, 5, 1, 6, 1, TAB_CENTER, + _("%g%% Confidence Interval of the Difference"), + proc->criteria * 100.0); tab_vline (self->t, TAL_GAP, 6, 1, 1); tab_hline (self->t, TAL_1, 5, 6, 2); @@ -1115,12 +1115,12 @@ pscbox (struct t_test_proc *proc) sqrt (1 - pow2 (pair->correlation))); /* row headings */ - tab_text (table, 0, i + 1, TAB_LEFT | TAT_TITLE | TAT_PRINTF, - _("Pair %d"), i); - tab_text (table, 1, i + 1, TAB_LEFT | TAT_TITLE | TAT_PRINTF, - _("%s & %s"), - var_get_name (pair->v[0]), - var_get_name (pair->v[1])); + tab_text_format (table, 0, i + 1, TAB_LEFT | TAT_TITLE, + _("Pair %d"), i); + tab_text_format (table, 1, i + 1, TAB_LEFT | TAT_TITLE, + _("%s & %s"), + var_get_name (pair->v[0]), + var_get_name (pair->v[1])); /* row data */ tab_double (table, 2, i + 1, TAB_RIGHT, pair->n, &proc->weight_format); diff --git a/src/output/table.c b/src/output/table.c index 7569c3e4..06cf47bb 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -382,18 +382,6 @@ tab_box (struct tab_table *t, int f_h, int f_v, int i_h, int i_v, } } -/* Formats text TEXT and arguments ARGS as indicated in OPT in - TABLE's pool and returns the resultant string. */ -static struct substring -text_format (struct tab_table *table, int opt, const char *text, va_list args) -{ - assert (table != NULL && text != NULL); - - return ss_cstr (opt & TAT_PRINTF - ? pool_vasprintf (table->container, text, args) - : pool_strdup (table->container, text)); -} - /* Set the title of table T to TITLE, which is formatted as if passed to printf(). */ void @@ -657,21 +645,14 @@ tab_double (struct tab_table *table, int c, int r, unsigned char opt, } -/* Sets cell (C,R) in TABLE, with options OPT, to have text value - TEXT. */ -void -tab_text (struct tab_table *table, int c, int r, unsigned opt, const char *text, ...) +static void +do_tab_text (struct tab_table *table, int c, int r, unsigned opt, char *text) { - va_list args; - - assert (table != NULL && text != NULL); - assert (c >= 0 ); assert (r >= 0 ); assert (c < tab_nc (table)); assert (r < tab_nr (table)); - #if DEBUGGING if (c + table->col_ofs < 0 || r + table->row_ofs < 0 || c + table->col_ofs >= tab_nc (table) @@ -686,21 +667,38 @@ tab_text (struct tab_table *table, int c, int r, unsigned opt, const char *text, } #endif - va_start (args, text); - table->cc[c + r * table->cf] = text_format (table, opt, text, args); + table->cc[c + r * table->cf] = ss_cstr (text); table->ct[c + r * table->cf] = opt; - va_end (args); } -/* Joins cells (X1,X2)-(Y1,Y2) inclusive in TABLE, and sets them with - options OPT to have text value TEXT. */ +/* Sets cell (C,R) in TABLE, with options OPT, to have text value + TEXT. */ void -tab_joint_text (struct tab_table *table, int x1, int y1, int x2, int y2, - unsigned opt, const char *text, ...) +tab_text (struct tab_table *table, int c, int r, unsigned opt, + const char *text) { - struct tab_joined_cell *j; + do_tab_text (table, c, r, opt, pool_strdup (table->container, text)); +} - assert (table != NULL && text != NULL); +/* Sets cell (C,R) in TABLE, with options OPT, to have text value + FORMAT, which is formatted as if passed to printf. */ +void +tab_text_format (struct tab_table *table, int c, int r, unsigned opt, + const char *format, ...) +{ + va_list args; + + va_start (args, format); + do_tab_text (table, c, r, opt, + pool_vasprintf (table->container, format, args)); + va_end (args); +} + +static void +do_tab_joint_text (struct tab_table *table, int x1, int y1, int x2, int y2, + unsigned opt, char *text) +{ + struct tab_joined_cell *j; assert (x1 + table->col_ofs >= 0); assert (y1 + table->row_ofs >= 0); @@ -733,14 +731,7 @@ tab_joint_text (struct tab_table *table, int x1, int y1, int x2, int y2, j->y1 = y1 + table->row_ofs; j->x2 = ++x2 + table->col_ofs; j->y2 = ++y2 + table->row_ofs; - - { - va_list args; - - va_start (args, text); - j->contents = text_format (table, opt, text, args); - va_end (args); - } + j->contents = ss_cstr (text); opt |= TAB_JOIN; @@ -767,6 +758,31 @@ tab_joint_text (struct tab_table *table, int x1, int y1, int x2, int y2, } } +/* Joins cells (X1,X2)-(Y1,Y2) inclusive in TABLE, and sets them with + options OPT to have text value TEXT. */ +void +tab_joint_text (struct tab_table *table, int x1, int y1, int x2, int y2, + unsigned opt, const char *text) +{ + do_tab_joint_text (table, x1, y1, x2, y2, opt, + pool_strdup (table->container, text)); +} + +/* Joins cells (X1,X2)-(Y1,Y2) inclusive in TABLE, and sets them + with options OPT to have text value FORMAT, which is formatted + as if passed to printf. */ +void +tab_joint_text_format (struct tab_table *table, int x1, int y1, int x2, int y2, + unsigned opt, const char *format, ...) +{ + va_list args; + + va_start (args, format); + do_tab_joint_text (table, x1, y1, x2, y2, opt, + 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, @@ -812,30 +828,41 @@ wrap_dim (struct tab_rendering *r, void *aux UNUSED) r->h[0] = tab_natural_height (r, 0); } -/* Outputs text BUF as a table with a single cell having cell options +static void +do_tab_output_text (struct tab_table *t, int options, char *text) +{ + do_tab_text (t, 0, 0, options, text); + tab_flags (t, SOMF_NO_TITLE | SOMF_NO_SPACING); + tab_dim (t, options & TAT_NOWRAP ? nowrap_dim : wrap_dim, NULL, NULL); + tab_submit (t); +} + +/* Outputs TEXT as a table with a single cell having cell options OPTIONS, which is a combination of the TAB_* and TAT_* - constants. */ + constants. */ void -tab_output_text (int options, const char *buf, ...) +tab_output_text (int options, const char *text) { - struct tab_table *t = tab_create (1, 1, 0); - char *tmp_buf = NULL; - - if (options & TAT_PRINTF) - { - va_list args; + struct tab_table *table = tab_create (1, 1, 0); + do_tab_output_text (table, options, pool_strdup (table->container, text)); +} - va_start (args, buf); - buf = tmp_buf = xvasprintf (buf, args); - va_end (args); - } +/* Outputs FORMAT as a table with a single cell having cell + options OPTIONS, which is a combination of the TAB_* and TAT_* + constants. FORMAT is formatted as if it was passed through + printf. */ +void +tab_output_text_format (int options, const char *format, ...) +{ + struct tab_table *table; + va_list args; - 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, NULL); - tab_submit (t); + table = tab_create (1, 1, 0); - free (tmp_buf); + va_start (args, format); + do_tab_output_text (table, options, + pool_vasprintf (table->container, format, args)); + va_end (args); } /* Set table flags to FLAGS. */ diff --git a/src/output/table.h b/src/output/table.h index 3cfac386..293c0c0d 100644 --- a/src/output/table.h +++ b/src/output/table.h @@ -155,7 +155,6 @@ void tab_box (struct tab_table *, int f_h, int f_v, int i_h, int i_v, enum { TAT_NONE = 0, /* No options. */ - TAT_PRINTF = 0x0100, /* Format the text string with sprintf. */ TAT_TITLE = 0x0200 | TAB_EMPH, /* Title attributes. */ TAT_NOWRAP = 0x0800 /* No text wrap (tab_output_text() only). */ }; @@ -172,11 +171,15 @@ void tab_fixed (struct tab_table *, int c, int r, unsigned char opt, void tab_double (struct tab_table *, int c, int r, unsigned char opt, double v, const struct fmt_spec *); -void tab_text (struct tab_table *, int c, int r, unsigned opt, - const char *, ...) +void tab_text (struct tab_table *, int c, int r, unsigned opt, const char *); +void tab_text_format (struct tab_table *, int c, int r, unsigned opt, + const char *, ...) PRINTF_FORMAT (5, 6); + void tab_joint_text (struct tab_table *, int x1, int y1, int x2, int y2, - unsigned opt, const char *, ...) + unsigned opt, const char *); +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. */ @@ -193,7 +196,8 @@ void tab_next_row (struct tab_table *); #define tab_col(TABLE) ((TABLE)->col_ofs) /* Simple output. */ -void tab_output_text (int options, const char *string, ...) +void tab_output_text (int options, const char *string); +void tab_output_text_format (int options, const char *, ...) PRINTF_FORMAT (2, 3); #endif /* tab_h */