From: Ben Pfaff Date: Sun, 24 Apr 2011 04:45:19 +0000 (-0700) Subject: variable: Make var_set_label() use the variable's own encoding. X-Git-Tag: v0.7.8~39 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd2104e10011b87d6558e8623d629da4cee82b25;p=pspp-builds.git variable: Make var_set_label() use the variable's own encoding. I don't see any reason to make the caller supply this. It just makes code harder to read and write. --- diff --git a/perl-module/PSPP.xs b/perl-module/PSPP.xs index 896d7d88..143eb549 100644 --- a/perl-module/PSPP.xs +++ b/perl-module/PSPP.xs @@ -376,7 +376,7 @@ set_label (var, label) struct variable *var; char *label CODE: - var_set_label (var, label, NULL, false); + var_set_label (var, label, false); void diff --git a/src/data/por-file-reader.c b/src/data/por-file-reader.c index a05f6b3d..58d4d039 100644 --- a/src/data/por-file-reader.c +++ b/src/data/por-file-reader.c @@ -746,7 +746,7 @@ read_variables (struct pfm_reader *r, struct dictionary *dict) { char label[256]; read_string (r, label); - var_set_label (v, label, NULL, false); /* XXX */ + var_set_label (v, label, false); /* XXX */ } } diff --git a/src/data/sys-file-reader.c b/src/data/sys-file-reader.c index 7e5a9e0f..6a5afff2 100644 --- a/src/data/sys-file-reader.c +++ b/src/data/sys-file-reader.c @@ -974,7 +974,7 @@ parse_variable_records (struct sfm_reader *r, struct dictionary *dict, utf8_label = recode_string_pool ("UTF-8", dict_encoding, rec->label, -1, r->pool); - var_set_label (var, utf8_label, NULL, false); + var_set_label (var, utf8_label, false); } /* Set missing values. */ diff --git a/src/data/variable.c b/src/data/variable.c index 17a1542c..121a5751 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -133,7 +133,7 @@ var_clone (const struct variable *old_var) var_set_print_format (new_var, var_get_print_format (old_var)); var_set_write_format (new_var, var_get_write_format (old_var)); var_set_value_labels (new_var, var_get_value_labels (old_var)); - var_set_label (new_var, var_get_label (old_var), NULL, false); + var_set_label (new_var, var_get_label (old_var), false); var_set_measure (new_var, var_get_measure (old_var)); var_set_display_width (new_var, var_get_display_width (old_var)); var_set_alignment (new_var, var_get_alignment (old_var)); @@ -571,14 +571,12 @@ var_get_label (const struct variable *v) empty string (after stripping white space), then V's variable label (if any) is removed. - Variable labels are limited to 255 bytes in the dictionary encoding, which - should be specified as DICT_ENCODING. If LABEL fits within this limit, this - function returns true. Otherwise, the variable label is set to a truncated - value, this function returns false and, if ISSUE_WARNING is true, issues a - warning. */ + Variable labels are limited to 255 bytes in V's encoding (as returned by + var_get_encoding()). If LABEL fits within this limit, this function returns + true. Otherwise, the variable label is set to a truncated value, this + function returns false and, if ISSUE_WARNING is true, issues a warning. */ bool -var_set_label (struct variable *v, const char *label, - const char *dict_encoding, bool issue_warning) +var_set_label (struct variable *v, const char *label, bool issue_warning) { bool truncated = false; @@ -587,6 +585,7 @@ var_set_label (struct variable *v, const char *label, if (label != NULL) { + const char *dict_encoding = var_get_encoding (v); struct substring s = ss_cstr (label); size_t trunc_len; @@ -620,7 +619,7 @@ var_set_label (struct variable *v, const char *label, void var_clear_label (struct variable *v) { - var_set_label (v, NULL, NULL, false); + var_set_label (v, NULL, false); } /* Returns true if V has a variable V, diff --git a/src/data/variable.h b/src/data/variable.h index 9cffafc9..456d2aca 100644 --- a/src/data/variable.h +++ b/src/data/variable.h @@ -98,8 +98,7 @@ struct fmt_spec var_default_formats (int width); /* Variable labels. */ const char *var_to_string (const struct variable *); const char *var_get_label (const struct variable *); -bool var_set_label (struct variable *, const char *label, - const char *dict_encoding, bool issue_warning); +bool var_set_label (struct variable *, const char *label, bool issue_warning); void var_clear_label (struct variable *); bool var_has_label (const struct variable *); diff --git a/src/language/data-io/combine-files.c b/src/language/data-io/combine-files.c index b4f06655..5f82d151 100644 --- a/src/language/data-io/combine-files.c +++ b/src/language/data-io/combine-files.c @@ -582,7 +582,7 @@ merge_dictionary (struct dictionary *const m, struct comb_file *f) if (var_has_missing_values (dv) && !var_has_missing_values (mv)) var_set_missing_values (mv, var_get_missing_values (dv)); if (var_get_label (dv) && !var_get_label (mv)) - var_set_label (mv, var_get_label (dv), file_encoding, false); + var_set_label (mv, var_get_label (dv), false); } else mv = dict_clone_var_assert (m, dv); diff --git a/src/language/dictionary/apply-dictionary.c b/src/language/dictionary/apply-dictionary.c index 96b77dc0..78824cf8 100644 --- a/src/language/dictionary/apply-dictionary.c +++ b/src/language/dictionary/apply-dictionary.c @@ -80,8 +80,7 @@ cmd_apply_dictionary (struct lexer *lexer, struct dataset *ds) } if (var_has_label (s)) - var_set_label (t, var_get_label (s), - dict_get_encoding (dataset_dict (ds)), false); + var_set_label (t, var_get_label (s), false); if (var_has_value_labels (s)) { diff --git a/src/language/dictionary/variable-label.c b/src/language/dictionary/variable-label.c index 41fae5ed..bceb8499 100644 --- a/src/language/dictionary/variable-label.c +++ b/src/language/dictionary/variable-label.c @@ -36,7 +36,6 @@ int cmd_variable_labels (struct lexer *lexer, struct dataset *ds) { struct dictionary *dict = dataset_dict (ds); - const char *dict_encoding = dict_get_encoding (dict); do { @@ -55,7 +54,7 @@ cmd_variable_labels (struct lexer *lexer, struct dataset *ds) } for (i = 0; i < nv; i++) - var_set_label (v[i], lex_tokcstr (lexer), dict_encoding, i == 0); + var_set_label (v[i], lex_tokcstr (lexer), i == 0); lex_get (lexer); while (lex_token (lexer) == T_SLASH) diff --git a/src/language/stats/aggregate.c b/src/language/stats/aggregate.c index fe6f5eed..0dee9b44 100644 --- a/src/language/stats/aggregate.c +++ b/src/language/stats/aggregate.c @@ -638,8 +638,7 @@ parse_aggregate_functions (struct lexer *lexer, const struct dictionary *dict, free (dest[i]); if (dest_label[i]) - var_set_label (destvar, dest_label[i], - dict_get_encoding (agr->dict), true); + var_set_label (destvar, dest_label[i], true); v->dest = destvar; } diff --git a/src/language/stats/descriptives.c b/src/language/stats/descriptives.c index 935ca9b3..017b78c2 100644 --- a/src/language/stats/descriptives.c +++ b/src/language/stats/descriptives.c @@ -680,9 +680,9 @@ setup_z_trns (struct dsc_proc *dsc, struct dataset *ds) struct variable *dst_var; dst_var = dict_create_var_assert (dataset_dict (ds), dv->z_name, 0); - var_set_label (dst_var, xasprintf (_("Z-score of %s"), - var_to_string (dv->v)), - dict_get_encoding (dataset_dict (ds)), false); + var_set_label (dst_var, + xasprintf (_("Z-score of %s"),var_to_string (dv->v)), + false); z = &t->z_scores[cnt++]; z->src_var = dv->v; diff --git a/src/language/stats/rank.q b/src/language/stats/rank.q index 91ef1861..2247354d 100644 --- a/src/language/stats/rank.q +++ b/src/language/stats/rank.q @@ -198,8 +198,7 @@ fraction_name(void) /* Create a label on DEST_VAR, describing its derivation from SRC_VAR and F */ static void create_var_label (struct variable *dest_var, - const struct variable *src_var, enum RANK_FUNC f, - const char *dict_encoding) + const struct variable *src_var, enum RANK_FUNC f) { struct string label; ds_init_empty (&label); @@ -225,7 +224,7 @@ create_var_label (struct variable *dest_var, ds_put_format (&label, _("%s of %s"), function_name[f], var_get_name (src_var)); - var_set_label (dest_var, ds_cstr (&label), dict_encoding, false); + var_set_label (dest_var, ds_cstr (&label), false); ds_destroy (&label); } @@ -684,8 +683,7 @@ cmd_rank (struct lexer *lexer, struct dataset *ds) create_var_label ( rank_specs[i].destvars[v], src_vars[v], - rank_specs[i].rfunc, - dict_get_encoding (dict)); + rank_specs[i].rfunc); } } diff --git a/src/ui/gui/psppire-var-store.c b/src/ui/gui/psppire-var-store.c index d495bd98..e41b4922 100644 --- a/src/ui/gui/psppire-var-store.c +++ b/src/ui/gui/psppire-var-store.c @@ -588,8 +588,7 @@ psppire_var_store_set_string (PsppireSheetModel *model, break; case PSPPIRE_VAR_STORE_COL_LABEL: { - var_set_label (pv, text, - psppire_dict_encoding (var_store->dictionary), true); + var_set_label (pv, text, true); return TRUE; } break;