X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fformats.c;h=32d638ae4a44f3fd0bed1ad7dd6484c77a4c52ea;hb=92fb12eb06716d14c05b781f5d9dcde956d77c30;hp=9198b0ad35ce7dbdb0843d364361098cae921f64;hpb=3a7fba81ceae5b049d0f7d671e9e3c3c43bbf703;p=pspp diff --git a/src/formats.c b/src/formats.c index 9198b0ad35..32d638ae4a 100644 --- a/src/formats.c +++ b/src/formats.c @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ #include #include @@ -28,11 +28,10 @@ #include "str.h" #include "var.h" -#include "debug-print.h" +#include "gettext.h" +#define _(msgid) gettext (msgid) -#if DEBUGGING -static void debug_print (void); -#endif +#include "debug-print.h" enum { @@ -45,21 +44,18 @@ static int internal_cmd_formats (int); int cmd_print_formats (void) { - lex_match_id ("FORMATS"); return internal_cmd_formats (FORMATS_PRINT); } int cmd_write_formats (void) { - lex_match_id ("FORMATS"); return internal_cmd_formats (FORMATS_WRITE); } int cmd_formats (void) { - lex_match_id ("FORMATS"); return internal_cmd_formats (FORMATS_PRINT | FORMATS_WRITE); } @@ -68,7 +64,7 @@ internal_cmd_formats (int which) { /* Variables. */ struct variable **v; - int cv; + size_t cv; /* Format to set the variables to. */ struct fmt_spec f; @@ -77,14 +73,14 @@ internal_cmd_formats (int which) int type; /* Counter. */ - int i; + size_t i; for (;;) { if (token == '.') break; - if (!parse_variables (default_dict, &v, &cv, PV_SAME_TYPE)) + if (!parse_variables (default_dict, &v, &cv, PV_NUMERIC)) return CMD_PART_SUCCESS_MAYBE; type = v[0]->type; @@ -93,31 +89,11 @@ internal_cmd_formats (int which) msg (SE, _("`(' expected after variable list")); goto fail; } - if (!parse_format_specifier (&f, 0) || !check_output_specifier (&f)) + if (!parse_format_specifier (&f, 0) + || !check_output_specifier (&f, true) + || !check_specifier_type (&f, NUMERIC, true)) goto fail; - /* Catch type mismatch errors. */ - if ((type == ALPHA) ^ (0 != (formats[f.type].cat & FCAT_STRING))) - { - msg (SE, _("Format %s may not be assigned to a %s variable."), - fmt_to_string (&f), type == NUMERIC ? _("numeric") : _("string")); - goto fail; - } - - /* This is an additional check for string variables. We can't - let the user specify an A8 format for a string variable with - width 4. */ - if (type == ALPHA) - { - /* Shortest string so far. */ - int min_len = INT_MAX; - - for (i = 0; i < cv; i++) - min_len = min (min_len, v[i]->width); - if (!check_string_specifier (&f, min_len)) - goto fail; - } - if (!lex_match (')')) { msg (SE, _("`)' expected after output format.")); @@ -134,30 +110,9 @@ internal_cmd_formats (int which) free (v); v = NULL; } -#if DEBUGGING - debug_print (); -#endif return CMD_SUCCESS; fail: free (v); return CMD_PART_SUCCESS_MAYBE; } - -#if DEBUGGING -static void -debug_print (void) -{ - int i; - - printf (_("Formats:\n")); - printf (_(" Name Print Write\n")); - printf (" -------- ------------ ------------\n"); - for (i = 0; i < default_dict.nvar; i++) - { - struct variable *v = default_dict.var[i]; - printf (" %-8s %-12s", v->name, fmt_to_string (&v->print)); - printf (" %-12s\n", fmt_to_string (&v->write)); - } -} -#endif /* DEBUGGING */