X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdata-io%2Fdata-list.c;h=cf8cd6bd47cbda580441fad7fcdce08d5b9cf1ec;hb=b2859987e3e1c67ffd240945f4590bb23d31bdb8;hp=59830347009e5005ffd5264f274b18d69a873f67;hpb=dcf9b154cbcaa35c3d8459a201b77eec8bcb30bd;p=pspp diff --git a/src/language/data-io/data-list.c b/src/language/data-io/data-list.c index 5983034700..cf8cd6bd47 100644 --- a/src/language/data-io/data-list.c +++ b/src/language/data-io/data-list.c @@ -18,29 +18,35 @@ 02110-1301, USA. */ #include + #include "data-list.h" -#include "message.h" + #include #include #include #include -#include "alloc.h" -#include "case.h" -#include "command.h" -#include "data-in.h" -#include "debug-print.h" -#include "data-reader.h" -#include "dictionary.h" -#include "message.h" -#include "file-handle.h" -#include "format.h" -#include "lexer.h" -#include "misc.h" -#include "settings.h" -#include "str.h" -#include "table.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 #include "gettext.h" #define _(msgid) gettext (msgid) @@ -96,6 +102,7 @@ struct data_list_pgm static const struct case_source_class data_list_source_class; +static void rpd_msg (enum msg_class, const char *format, ...); static int parse_fixed (struct data_list_pgm *); static int parse_free (struct dls_var_spec **, struct dls_var_spec **); static void dump_fixed_table (const struct dls_var_spec *, @@ -106,9 +113,6 @@ static void destroy_dls_var_spec (struct dls_var_spec *); static trns_free_func data_list_trns_free; static trns_proc_func data_list_trns_proc; -/* Message title for REPEATING DATA. */ -#define RPD_ERR "REPEATING DATA: " - int cmd_data_list (void) { @@ -116,7 +120,7 @@ cmd_data_list (void) int table = -1; /* Print table if nonzero, -1=undecided. */ struct file_handle *fh = fh_inline_file (); - if (!case_source_is_complex (vfm_source)) + if (!in_input_program () && !in_file_type ()) discard_variables (); dls = xmalloc (sizeof *dls); @@ -136,8 +140,7 @@ cmd_data_list (void) fh = fh_parse (FH_REF_FILE | FH_REF_INLINE); if (fh == NULL) goto error; - if (case_source_is_class (vfm_source, &file_type_source_class) - && fh != fh_get_default_handle ()) + if (in_file_type () && fh != fh_get_default_handle ()) { msg (SE, _("DATA LIST must use the same file " "as the enclosing FILE TYPE.")); @@ -542,8 +545,6 @@ fixed_parse_compatible (struct fixed_parsing_state *fx, { convert_fmt_ItoO (&input, &v->print); v->write = v->print; - if (!case_source_is_complex (vfm_source)) - v->init = 0; } else { @@ -650,9 +651,6 @@ dump_fmt_list (struct fixed_parsing_state *fx, struct fmt_list *f, return 0; } - if (!case_source_is_complex (vfm_source)) - v->init = 0; - spec = xmalloc (sizeof *spec); spec->v = v; spec->input = f->f; @@ -791,12 +789,12 @@ dump_fixed_table (const struct dls_var_spec *specs, tab_text (t, 1, i, TAT_PRINTF, "%d", spec->rec); tab_text (t, 2, i, TAT_PRINTF, "%3d-%3d", spec->fc, spec->lc); - tab_text (t, 3, i, TAB_LEFT | TAT_FIX, + tab_text (t, 3, i, TAB_LEFT | TAB_FIX, fmt_to_string (&spec->input)); } - tab_title (t, 1, ngettext ("Reading %d record from %s.", - "Reading %d records from %s.", rec_cnt), + tab_title (t, ngettext ("Reading %d record from %s.", + "Reading %d records from %s.", rec_cnt), rec_cnt, fh_get_name (fh)); tab_submit (t); } @@ -859,9 +857,6 @@ parse_free (struct dls_var_spec **first, struct dls_var_spec **last) } v->print = v->write = output; - if (!case_source_is_complex (vfm_source)) - v->init = 0; - spec = xmalloc (sizeof *spec); spec->input = input; spec->v = v; @@ -907,11 +902,11 @@ dump_free_table (const struct data_list_pgm *dls, for (i = 1, spec = dls->first; spec; spec = spec->next, i++) { tab_text (t, 0, i, TAB_LEFT, spec->v->name); - tab_text (t, 1, i, TAB_LEFT | TAT_FIX, fmt_to_string (&spec->input)); + tab_text (t, 1, i, TAB_LEFT | TAB_FIX, fmt_to_string (&spec->input)); } } - tab_title (t, 1, _("Reading free-form data from %s."), fh_get_name (fh)); + tab_title (t, _("Reading free-form data from %s."), fh_get_name (fh)); tab_submit (t); } @@ -1345,6 +1340,8 @@ static int parse_repeating_data (struct dls_var_spec **, static void find_variable_input_spec (struct variable *v, struct fmt_spec *spec); +int cmd_repeating_data (void); + /* Parses the REPEATING DATA command. */ int cmd_repeating_data (void) @@ -1358,7 +1355,7 @@ cmd_repeating_data (void) bool saw_id = false; /* Saw ID subcommand? */ struct file_handle *const fh = fh_get_default_handle (); - assert (case_source_is_complex (vfm_source)); + assert (in_input_program () || in_file_type ()); rpd = xmalloc (sizeof *rpd); rpd->reader = dfm_open_reader (fh); @@ -1810,9 +1807,10 @@ rpd_parse_record (const struct rpd_parse_info *info) data_out (actual_str, &t->id_var->print, id_temp); actual_str[t->id_var->print.w] = '\0'; - tmsg (SE, RPD_ERR, - _("Encountered mismatched record ID \"%s\" expecting \"%s\"."), - actual_str, expected_str); + rpd_msg (SE, + _("Encountered mismatched record ID \"%s\" " + "expecting \"%s\"."), + actual_str, expected_str); return 0; } @@ -1842,10 +1840,10 @@ rpd_parse_record (const struct rpd_parse_info *info) { warned = 1; - tmsg (SW, RPD_ERR, - _("Variable %s starting in column %d extends " - "beyond physical record length of %d."), - var_spec->v->name, fc, info->len); + rpd_msg (SW, + _("Variable %s starting in column %d extends " + "beyond physical record length of %d."), + var_spec->v->name, fc, info->len); } { @@ -1910,46 +1908,45 @@ repeating_data_trns_proc (void *trns_, struct ccase *c, int case_num UNUSED) occurs_left = occurs = realize_value (&t->occurs, c); if (occurs <= 0) { - tmsg (SE, RPD_ERR, _("Invalid value %d for OCCURS."), occurs); + rpd_msg (SE, _("Invalid value %d for OCCURS."), occurs); return TRNS_NEXT_CASE; } starts_beg = realize_value (&t->starts_beg, c); if (starts_beg <= 0) { - tmsg (SE, RPD_ERR, _("Beginning column for STARTS (%d) must be " - "at least 1."), - starts_beg); + rpd_msg (SE, _("Beginning column for STARTS (%d) must be at least 1."), + starts_beg); return TRNS_NEXT_CASE; } starts_end = realize_value (&t->starts_end, c); if (starts_end < starts_beg) { - tmsg (SE, RPD_ERR, _("Ending column for STARTS (%d) is less than " - "beginning column (%d)."), - starts_end, starts_beg); + rpd_msg (SE, _("Ending column for STARTS (%d) is less than " + "beginning column (%d)."), + starts_end, starts_beg); skip_first_record = 1; } length = realize_value (&t->length, c); if (length < 0) { - tmsg (SE, RPD_ERR, _("Invalid value %d for LENGTH."), length); + rpd_msg (SE, _("Invalid value %d for LENGTH."), length); length = 1; occurs = occurs_left = 1; } cont_beg = realize_value (&t->cont_beg, c); if (cont_beg < 0) { - tmsg (SE, RPD_ERR, _("Beginning column for CONTINUED (%d) must be " - "at least 1."), - cont_beg); + rpd_msg (SE, _("Beginning column for CONTINUED (%d) must be " + "at least 1."), + cont_beg); return TRNS_DROP_CASE; } cont_end = realize_value (&t->cont_end, c); if (cont_end < cont_beg) { - tmsg (SE, RPD_ERR, _("Ending column for CONTINUED (%d) is less than " - "beginning column (%d)."), - cont_end, cont_beg); + rpd_msg (SE, _("Ending column for CONTINUED (%d) is less than " + "beginning column (%d)."), + cont_end, cont_beg); return TRNS_DROP_CASE; } @@ -1978,11 +1975,11 @@ repeating_data_trns_proc (void *trns_, struct ccase *c, int case_num UNUSED) continuation records. */ if (occurs_left > 0 && cont_beg == 0) { - tmsg (SE, RPD_ERR, - _("Number of repetitions specified on OCCURS (%d) " - "exceed number of repetitions available in " - "space on STARTS (%d), and CONTINUED not specified."), - occurs, (starts_end - starts_beg + 1) / length); + rpd_msg (SE, + _("Number of repetitions specified on OCCURS (%d) " + "exceed number of repetitions available in " + "space on STARTS (%d), and CONTINUED not specified."), + occurs, (starts_end - starts_beg + 1) / length); return TRNS_DROP_CASE; } @@ -1996,10 +1993,10 @@ repeating_data_trns_proc (void *trns_, struct ccase *c, int case_num UNUSED) /* Read in another record. */ if (dfm_eof (t->reader)) { - tmsg (SE, RPD_ERR, - _("Unexpected end of file with %d repetitions " - "remaining out of %d."), - occurs_left, occurs); + rpd_msg (SE, + _("Unexpected end of file with %d repetitions " + "remaining out of %d."), + occurs_left, occurs); return TRNS_DROP_CASE; } dfm_expand_tabs (t->reader); @@ -2056,3 +2053,27 @@ repeating_data_set_write_case (struct transformation *trns_, t->write_case = write_case; t->wc_data = wc_data; } + +/* Reports a message in CLASS with the given FORMAT as text, + prefixing the message with "REPEATING DATA: " to make the + cause clear. */ +static void +rpd_msg (enum msg_class class, const char *format, ...) +{ + struct msg m; + va_list args; + struct string text; + + ds_create (&text, "REPEATING DATA: "); + va_start (args, format); + ds_vprintf (&text, format, args); + va_end (args); + + m.category = msg_class_to_category (class); + m.severity = msg_class_to_severity (class); + m.where.file_name = NULL; + m.where.line_number = 0; + m.text = ds_c_str (&text); + + msg_emit (&m); +}