X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdata-io%2Fmatrix-data.c;h=5526db91cf01e71a58b1cfec35bdd8ca52bfbe32;hb=755ecfd2e8d86bc134fe7202c46fee354ec166d0;hp=343e96dc2231fe048412750669d9253e562b5427;hpb=dcf9b154cbcaa35c3d8459a201b77eec8bcb30bd;p=pspp-builds.git diff --git a/src/language/data-io/matrix-data.c b/src/language/data-io/matrix-data.c index 343e96dc..5526db91 100644 --- a/src/language/data-io/matrix-data.c +++ b/src/language/data-io/matrix-data.c @@ -18,31 +18,37 @@ 02110-1301, USA. */ #include -#include "message.h" + #include #include #include -#include "array.h" -#include "alloc.h" -#include "case.h" -#include "command.h" -#include "data-in.h" -#include "data-reader.h" -#include "dictionary.h" -#include "message.h" -#include "file-handle.h" -#include "lexer.h" -#include "misc.h" -#include "pool.h" -#include "str.h" -#include "variable.h" -#include "procedure.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "size_max.h" #include "gettext.h" #define _(msgid) gettext (msgid) -#include "debug-print.h" - /* FIXME: /N subcommand not implemented. It should be pretty simple, too. */ @@ -749,7 +755,7 @@ mdump_token (const struct matrix_token *token) printf (" '%.*s'", token->length, token->string); break; default: - assert (0); + NOT_REACHED (); } fflush (stdout); } @@ -767,38 +773,25 @@ mget_token_dump (struct matrix_token *token, struct dfm_reader *reader) static const char * context (struct dfm_reader *reader) { - static char buf[32]; + static struct string buf = DS_EMPTY_INITIALIZER; + ds_clear (&buf); if (dfm_eof (reader)) - strcpy (buf, "at end of file"); + ds_assign_cstr (&buf, "at end of file"); else { - struct fixed_string line; - const char *sp; + struct substring p; - dfm_get_record (reader, &line); - sp = ls_c_str (&line); - while (sp < ls_end (&line) && isspace ((unsigned char) *sp)) - sp++; - if (sp >= ls_end (&line)) - strcpy (buf, "at end of line"); + p = dfm_get_record (reader); + ss_ltrim (&p, ss_cstr (CC_SPACES)); + if (ss_is_empty (p)) + ds_assign_cstr (&buf, "at end of line"); else - { - char *dp; - size_t copy_cnt = 0; - - dp = stpcpy (buf, "before `"); - while (sp < ls_end (&line) && !isspace ((unsigned char) *sp) - && copy_cnt < 10) - { - *dp++ = *sp++; - copy_cnt++; - } - strcpy (dp, "'"); - } + ds_put_format (&buf, "before `%.*s'", + (int) ss_cspan (p, ss_cstr (CC_SPACES)), ss_data (p)); } - return buf; + return ds_cstr (&buf); } /* Is there at least one token left in the data file? */ @@ -807,20 +800,17 @@ another_token (struct dfm_reader *reader) { for (;;) { - struct fixed_string line; - const char *cp; + struct substring p; + size_t space_cnt; if (dfm_eof (reader)) return 0; - dfm_get_record (reader, &line); - - cp = ls_c_str (&line); - while (isspace ((unsigned char) *cp) && cp < ls_end (&line)) - cp++; - if (cp < ls_end (&line)) + p = dfm_get_record (reader); + space_cnt = ss_span (p, ss_cstr (CC_SPACES)); + if (space_cnt < ss_length (p)) { - dfm_forward_columns (reader, cp - ls_c_str (&line)); + dfm_forward_columns (reader, space_cnt); return 1; } @@ -832,73 +822,65 @@ another_token (struct dfm_reader *reader) static int (mget_token) (struct matrix_token *token, struct dfm_reader *reader) { - struct fixed_string line; - int first_column; - char *cp; + struct substring line, p; + struct substring s; + int c; if (!another_token (reader)) return 0; - dfm_get_record (reader, &line); - first_column = dfm_column_start (reader); + line = p = dfm_get_record (reader); /* Three types of fields: quoted with ', quoted with ", unquoted. */ - cp = ls_c_str (&line); - if (*cp == '\'' || *cp == '"') + c = ss_first (p); + if (c == '\'' || c == '"') { - int quote = *cp; - - token->type = MSTR; - token->string = ++cp; - while (cp < ls_end (&line) && *cp != quote) - cp++; - token->length = cp - token->string; - if (cp < ls_end (&line)) - cp++; - else - msg (SW, _("Scope of string exceeds line.")); + ss_get_char (&p); + if (!ss_get_until (&p, c, &s)) + msg (SW, _("Scope of string exceeds line.")); } else { - int is_num = isdigit ((unsigned char) *cp) || *cp == '.'; - - token->string = cp++; - while (cp < ls_end (&line) - && !isspace ((unsigned char) *cp) && *cp != ',' - && *cp != '-' && *cp != '+') - { - if (isdigit ((unsigned char) *cp)) - is_num = 1; - - if ((tolower ((unsigned char) *cp) == 'd' - || tolower ((unsigned char) *cp) == 'e') - && (cp[1] == '+' || cp[1] == '-')) - cp += 2; - else - cp++; - } + bool is_num = isdigit (c) || c == '.'; + const char *start = ss_data (p); - token->length = cp - token->string; - assert (token->length); + for (;;) + { + c = ss_first (p); + if (strchr (CC_SPACES ",-+", c) != NULL) + break; + + if (isdigit (c)) + is_num = true; + if (strchr ("deDE", c) && strchr ("+-", ss_at (p, 1))) + { + is_num = true; + ss_advance (&p, 2); + } + else + ss_advance (&p, 1); + } + s = ss_buffer (start, ss_data (p) - start); if (is_num) { struct data_in di; - di.s = token->string; - di.e = token->string + token->length; + di.s = ss_data (s); + di.e = ss_end (s); di.v = (union value *) &token->number; - di.f1 = first_column; + di.f1 = dfm_get_column (reader, di.s); di.format = make_output_format (FMT_F, token->length, 0); - if (!data_in (&di)) - return 0; + data_in (&di); } else token->type = MSTR; } - - dfm_forward_columns (reader, cp - ls_c_str (&line)); + token->string = ss_data (s); + token->length = ss_length (s); + + dfm_reread_record (reader, dfm_get_column (reader, ss_end (s))); return 1; } @@ -908,18 +890,13 @@ static int static int force_eol (struct dfm_reader *reader, const char *content) { - struct fixed_string line; - const char *cp; + struct substring p; if (dfm_eof (reader)) return 0; - dfm_get_record (reader, &line); - cp = ls_c_str (&line); - while (isspace ((unsigned char) *cp) && cp < ls_end (&line)) - cp++; - - if (cp < ls_end (&line)) + p = dfm_get_record (reader); + if (ss_span (p, ss_cstr (CC_SPACES)) != ss_length (p)) { msg (SE, _("End of line expected %s while reading %s."), context (reader), content); @@ -970,7 +947,8 @@ read_matrices_without_rowtype (struct matrix_data_pgm *mx) nr.split_values = xnmalloc (dict_get_split_cnt (default_dict), sizeof *nr.split_values); - vfm_source = create_case_source (&matrix_data_without_rowtype_source_class, &nr); + proc_set_source (create_case_source ( + &matrix_data_without_rowtype_source_class, &nr)); ok = procedure (NULL, NULL); @@ -1089,16 +1067,14 @@ nr_read_data_lines (struct nr_aux_data *nr, n_cols = mx->n_continuous; break; default: - assert (0); - abort (); + NOT_REACHED (); } break; case 2: n_cols = 1; break; default: - assert (0); - abort (); + NOT_REACHED (); } { @@ -1122,7 +1098,6 @@ nr_read_data_lines (struct nr_aux_data *nr, if (mx->fmt != FREE && !force_eol (mx->reader, content_names[content])) return 0; - debug_printf (("\n")); } if (mx->section == LOWER) @@ -1418,11 +1393,8 @@ nr_output_data (struct nr_aux_data *nr, struct ccase *c, size_t factor; for (factor = 0; factor < mx->n_factors; factor++) - { - case_data_rw (c, mx->factors[factor]->fv)->f - = nr->factor_values[factor + cell * mx->n_factors]; - debug_printf (("f:%s ", mx->factors[factor]->name)); - } + case_data_rw (c, mx->factors[factor]->fv)->f + = nr->factor_values[factor + cell * mx->n_factors]; } { @@ -1514,8 +1486,8 @@ read_matrices_with_rowtype (struct matrix_data_pgm *mx) wr.current = NULL; mx->cells = 0; - vfm_source = create_case_source (&matrix_data_with_rowtype_source_class, - &wr); + proc_set_source (create_case_source (&matrix_data_with_rowtype_source_class, + &wr)); ok = procedure (NULL, NULL); free (wr.split_values); @@ -1962,18 +1934,14 @@ wr_read_indeps (struct wr_aux_data *wr) n_cols = mx->n_continuous; break; default: - assert (0); - abort (); + NOT_REACHED (); } break; default: - assert (0); - abort (); + NOT_REACHED (); } c->n_rows[wr->content]++; - debug_printf ((" (c=%p,r=%d,n=%d)", c, n_rows + 1, n_cols)); - /* Read N_COLS items at CP. */ { int j; @@ -1996,7 +1964,6 @@ wr_read_indeps (struct wr_aux_data *wr) if (mx->fmt != FREE && !force_eol (mx->reader, content_names[wr->content])) return 0; - debug_printf (("\n")); } return 1;