X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdata-io%2Fplacement-parser.c;h=81e3fee8661a9c2f7b2dc69934e7a325c15177ef;hb=84d8b182e81aea6cd7422611888192bcc1ac6980;hp=b0c329367403da025ef14cbe82c82f7c2f232020;hpb=8e018d25310cb53e5339b46e95f0abe02db83782;p=pspp-builds.git diff --git a/src/language/data-io/placement-parser.c b/src/language/data-io/placement-parser.c index b0c32936..81e3fee8 100644 --- a/src/language/data-io/placement-parser.c +++ b/src/language/data-io/placement-parser.c @@ -1,6 +1,5 @@ /* PSPP - computes sample statistics. Copyright (C) 2006 Free Software Foundation, Inc. - Written by Ben Pfaff . This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -39,14 +38,14 @@ placement. */ enum { - PRS_TYPE_T = -1, /* Tab to absolute column. */ - PRS_TYPE_X = -2, /* Skip columns. */ - PRS_TYPE_NEW_REC = -3 /* Next record. */ + PRS_TYPE_T = SCHAR_MAX - 3, /* Tab to absolute column. */ + PRS_TYPE_X, /* Skip columns. */ + PRS_TYPE_NEW_REC /* Next record. */ }; -static bool fixed_parse_columns (struct pool *, size_t var_cnt, +static bool fixed_parse_columns (struct lexer *, struct pool *, size_t var_cnt, bool for_input, struct fmt_spec **, size_t *); -static bool fixed_parse_fortran (struct pool *, +static bool fixed_parse_fortran (struct lexer *l, struct pool *, bool for_input, struct fmt_spec **, size_t *); /* Parses Fortran-like or column-based specifications for placing @@ -65,23 +64,23 @@ static bool fixed_parse_fortran (struct pool *, Uses POOL for allocation. When the caller is finished interpreting *FORMATS, POOL may be destroyed. */ bool -parse_var_placements (struct pool *pool, size_t var_cnt, +parse_var_placements (struct lexer *lexer, struct pool *pool, size_t var_cnt, bool for_input, struct fmt_spec **formats, size_t *format_cnt) { assert (var_cnt > 0); - if (lex_is_number ()) - return fixed_parse_columns (pool, var_cnt, formats, format_cnt); - else if (lex_match ('(')) + if (lex_is_number (lexer)) + return fixed_parse_columns (lexer, pool, var_cnt, for_input, formats, format_cnt); + else if (lex_match (lexer, '(')) { size_t assignment_cnt; size_t i; - if (!fixed_parse_fortran (pool, formats, format_cnt)) + if (!fixed_parse_fortran (lexer, pool, for_input, formats, format_cnt)) return false; assignment_cnt = 0; for (i = 0; i < *format_cnt; i++) - assignment_cnt += (*formats)[i].type >= 0; + assignment_cnt += (*formats)[i].type < FMT_NUMBER_OF_FORMATS; if (assignment_cnt != var_cnt) { @@ -103,14 +102,14 @@ parse_var_placements (struct pool *pool, size_t var_cnt, /* Implements parse_var_placements for column-based formats. */ static bool -fixed_parse_columns (struct pool *pool, size_t var_cnt, +fixed_parse_columns (struct lexer *lexer, struct pool *pool, size_t var_cnt, bool for_input, struct fmt_spec **formats, size_t *format_cnt) { struct fmt_spec format; int fc, lc; size_t i; - if (!parse_column_range (&fc, &lc, NULL)) + if ( !parse_column_range (lexer, &fc, &lc, NULL) ) return false; /* Divide columns evenly. */ @@ -118,34 +117,34 @@ fixed_parse_columns (struct pool *pool, size_t var_cnt, if ((lc - fc + 1) % var_cnt) { msg (SE, _("The %d columns %d-%d " - "can't be evenly divided into %d fields."), - lc - fc + 1, fc, lc, var_cnt); + "can't be evenly divided into %u fields."), + lc - fc + 1, fc, lc, (unsigned int) var_cnt); return false; } /* Format specifier. */ - if (lex_match ('(')) + if (lex_match (lexer, '(')) { /* Get format type. */ - if (token == T_ID) + if (lex_token (lexer) == T_ID) { - if (!parse_format_specifier_name (&format.type)) + if (!parse_format_specifier_name (lexer, &format.type)) return false; - lex_match (','); + lex_match (lexer, ','); } else format.type = FMT_F; /* Get decimal places. */ - if (lex_is_integer ()) + if (lex_is_integer (lexer)) { - format.d = lex_integer (); - lex_get (); + format.d = lex_integer (lexer); + lex_get (lexer); } else format.d = 0; - if (!lex_force_match (')')) + if (!lex_force_match (lexer, ')')) return false; } else @@ -153,7 +152,7 @@ fixed_parse_columns (struct pool *pool, size_t var_cnt, format.type = FMT_F; format.d = 0; } - if (!check_input_specifier (&format, 1)) + if (!fmt_check (&format, for_input)) return false; *formats = pool_nalloc (pool, var_cnt + 1, sizeof **formats); @@ -167,14 +166,14 @@ fixed_parse_columns (struct pool *pool, size_t var_cnt, /* Implements parse_var_placements for Fortran-like formats. */ static bool -fixed_parse_fortran (struct pool *pool, +fixed_parse_fortran (struct lexer *lexer, struct pool *pool, bool for_input, struct fmt_spec **formats, size_t *format_cnt) { size_t formats_allocated = 0; size_t formats_used = 0; *formats = NULL; - while (!lex_match (')')) + while (!lex_match (lexer, ')')) { struct fmt_spec f; struct fmt_spec *new_formats; @@ -183,32 +182,33 @@ fixed_parse_fortran (struct pool *pool, size_t formats_needed; /* Parse count. */ - if (lex_is_integer ()) + if (lex_is_integer (lexer)) { - count = lex_integer (); - lex_get (); + count = lex_integer (lexer); + lex_get (lexer); } else count = 1; /* Parse format specifier. */ - if (lex_match ('(')) + if (lex_match (lexer, '(')) { /* Call ourselves recursively to handle parentheses. */ - if (!fixed_parse_fortran (pool, &new_formats, &new_format_cnt)) + if (!fixed_parse_fortran (lexer, pool, for_input, + &new_formats, &new_format_cnt)) return false; } else { new_formats = &f; new_format_cnt = 1; - if (lex_match ('/')) + if (lex_match (lexer, '/')) f.type = PRS_TYPE_NEW_REC; else { char type[FMT_TYPE_LEN_MAX + 1]; - if (!parse_abstract_format_specifier (type, &f.w, &f.d)) + if (!parse_abstract_format_specifier (lexer, type, &f.w, &f.d)) return false; if (!strcasecmp (type, "T")) @@ -221,12 +221,12 @@ fixed_parse_fortran (struct pool *pool, } else { - if (!fmt_type_from_string (type, &f.type)) + if (!fmt_from_name (type, &f.type)) { msg (SE, _("Unknown format type \"%s\"."), type); return false; } - if (!check_input_specifier (&f, 1)) + if (!fmt_check (&f, for_input)) return false; } } @@ -253,7 +253,7 @@ fixed_parse_fortran (struct pool *pool, formats_used += new_format_cnt; } - lex_match (','); + lex_match (lexer, ','); } *format_cnt = formats_used; @@ -284,7 +284,7 @@ execute_placement_format (const struct fmt_spec *format, return true; default: - assert (format->type >= 0 && format->type < FMT_NUMBER_OF_FORMATS); + assert (format->type < FMT_NUMBER_OF_FORMATS); return false; } } @@ -298,27 +298,27 @@ execute_placement_format (const struct fmt_spec *format, successful, false if the syntax was invalid or the values specified did not make sense. */ bool -parse_column_range (int *first_column, int *last_column, +parse_column_range (struct lexer *lexer, int *first_column, int *last_column, bool *range_specified) { /* First column. */ - if (!lex_force_int ()) + if (!lex_force_int (lexer)) return false; - *first_column = lex_integer (); + *first_column = lex_integer (lexer); if (*first_column < 1) { msg (SE, _("Column positions for fields must be positive.")); return false; } - lex_get (); + lex_get (lexer); /* Last column. */ - lex_negative_to_dash (); - if (lex_match ('-')) + lex_negative_to_dash (lexer); + if (lex_match (lexer, '-')) { - if (!lex_force_int ()) + if (!lex_force_int (lexer)) return false; - *last_column = lex_integer (); + *last_column = lex_integer (lexer); if (*last_column < 1) { msg (SE, _("Column positions for fields must be positive.")); @@ -333,7 +333,7 @@ parse_column_range (int *first_column, int *last_column, if (range_specified) *range_specified = true; - lex_get (); + lex_get (lexer); } else { @@ -353,23 +353,23 @@ parse_column_range (int *first_column, int *last_column, Returns true if successful, false on syntax error. */ bool -parse_record_placement (int *record, int *column) +parse_record_placement (struct lexer *lexer, int *record, int *column) { - while (lex_match ('/')) + while (lex_match (lexer, '/')) { - if (lex_is_integer ()) + if (lex_is_integer (lexer)) { - if (lex_integer () <= *record) + if (lex_integer (lexer) <= *record) { msg (SE, _("The record number specified, %ld, is at or " "before the previous record, %d. Data " "fields must be listed in order of " "increasing record number."), - lex_integer (), *record); + lex_integer (lexer), *record); return false; } - *record = lex_integer (); - lex_get (); + *record = lex_integer (lexer); + lex_get (lexer); } else (*record)++;