X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fmrset.c;h=38b0ab2d5266e88192342166df828cd7a98e2bd9;hb=9ade26c8349;hp=d1807b96f301000f807ccc87fb696d735562530e;hpb=afdf3096926b561f4e6511c10fcf73fc6796b9d2;p=pspp-builds.git diff --git a/src/data/mrset.c b/src/data/mrset.c index d1807b96..38b0ab2d 100644 --- a/src/data/mrset.c +++ b/src/data/mrset.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010, 2011 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 @@ -21,11 +21,16 @@ #include #include "data/dictionary.h" +#include "data/identifier.h" #include "data/val-type.h" #include "data/variable.h" +#include "libpspp/message.h" #include "gl/xalloc.h" +#include "gettext.h" +#define _(msgid) gettext (msgid) + /* Creates and returns a clone of OLD. The caller is responsible for freeing the new multiple response set (using mrset_destroy()). */ struct mrset * @@ -62,9 +67,31 @@ mrset_destroy (struct mrset *mrset) } } +/* Returns true if the UTF-8 encoded NAME is a valid name for a multiple + response set in a dictionary encoded in DICT_ENCODING, false otherwise. If + ISSUE_ERROR is true, issues an explanatory error message on failure. */ +bool +mrset_is_valid_name (const char *name, const char *dict_encoding, + bool issue_error) +{ + if (!id_is_valid (name, dict_encoding, issue_error)) + return false; + + if (name[0] != '$') + { + if (issue_error) + msg (SE, _("%s is not a valid name for a multiple response " + "set. Multiple response set names must begin with " + "`$'."), name); + return false; + } + + return true; +} + /* Checks various constraints on MRSET: - - MRSET has a valid name for a multiple response set (beginning with '$'). + - MRSET's name begins with '$' and is valid as an identifier in DICT. - MRSET has a valid type. @@ -85,7 +112,7 @@ mrset_ok (const struct mrset *mrset, const struct dictionary *dict) size_t i; if (mrset->name == NULL - || mrset->name[0] != '$' + || !mrset_is_valid_name (mrset->name, dict_get_encoding (dict), false) || (mrset->type != MRSET_MD && mrset->type != MRSET_MC) || mrset->vars == NULL || mrset->n_vars < 2)