From: Ben Pfaff Date: Sat, 11 Nov 2006 19:30:59 +0000 (+0000) Subject: Implement SKIP keyword on DATA LIST. Fixes bug #17099. X-Git-Tag: v0.6.0~699 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cdecc06d6e3298bc8284753cd74ff22ded1f06c5;p=pspp-builds.git Implement SKIP keyword on DATA LIST. Fixes bug #17099. --- diff --git a/doc/data-io.texi b/doc/data-io.texi index efff25ea..b5e6ca22 100644 --- a/doc/data-io.texi +++ b/doc/data-io.texi @@ -138,9 +138,10 @@ Each form of @cmd{DATA LIST} is described in detail below. @display DATA LIST [FIXED] @{TABLE,NOTABLE@} - FILE='file-name' - RECORDS=record_count - END=end_var + [FILE='file-name'] + [RECORDS=record_count] + [END=end_var] + [SKIP=record_count] /[line_no] var_spec@dots{} where each var_spec takes one of the forms @@ -166,6 +167,10 @@ the list of variable specifications later in @cmd{DATA LIST}. The END subcommand is only useful in conjunction with @cmd{INPUT PROGRAM}. @xref{INPUT PROGRAM}, for details. +The optional SKIP subcommand specifies a number of records to skip at +the beginning of an input file. It can be used to skip over a row +that contains variable names, for example. + @cmd{DATA LIST} can optionally output a table describing how the data file will be read. The TABLE subcommand enables this output, and NOTABLE disables it. The default is to output the table. @@ -346,8 +351,9 @@ This example shows keywords abbreviated to their first 3 letters. DATA LIST FREE [(@{TAB,'c'@}, @dots{})] [@{NOTABLE,TABLE@}] - FILE='file-name' - END=end_var + [FILE='file-name'] + [END=end_var] + [SKIP=record_cnt] /var_spec@dots{} where each var_spec takes one of the forms @@ -376,7 +382,7 @@ of quoting is allowed. The NOTABLE and TABLE subcommands are as in @cmd{DATA LIST FIXED} above. NOTABLE is the default. -The FILE and END subcommands are as in @cmd{DATA LIST FIXED} above. +The FILE, END, and SKIP subcommands are as in @cmd{DATA LIST FIXED} above. The variables to be parsed are given as a single list of variable names. This list must be introduced by a single slash (@samp{/}). The set of @@ -398,8 +404,9 @@ on field width apply, but they are honored on output. DATA LIST LIST [(@{TAB,'c'@}, @dots{})] [@{NOTABLE,TABLE@}] - FILE='file-name' - END=end_var + [FILE='file-name'] + [END=end_var] + [SKIP=record_count] /var_spec@dots{} where each var_spec takes one of the forms diff --git a/src/language/data-io/ChangeLog b/src/language/data-io/ChangeLog index 2fb050dc..099c4c5e 100644 --- a/src/language/data-io/ChangeLog +++ b/src/language/data-io/ChangeLog @@ -1,3 +1,11 @@ +Thu Nov 2 20:56:03 2006 Ben Pfaff + + Implement SKIP keyword on DATA LIST. Fixes bug #17099. + + * data-list.c: (struct data_list_pgm) Add `skip_records' members. + (cmd_data_list) Set skip_records based on user input. + (data_list_source_read) Skip records requested by user. + Tue Oct 31 20:04:06 2006 Ben Pfaff * placement-parser.c: (PRS_TYPE_T) Now that struct fmt_spec uses @@ -12,7 +20,6 @@ Tue Oct 31 20:04:06 2006 Ben Pfaff (fixed_parse_columns) Ditto. (fixed_parse_fortran) Ditto. - Tue Oct 31 18:21:48 2006 Ben Pfaff * print-space.c (print_space_trns_proc): Let dfm_put_record add diff --git a/src/language/data-io/data-list.c b/src/language/data-io/data-list.c index a1faffe4..136c8e44 100644 --- a/src/language/data-io/data-list.c +++ b/src/language/data-io/data-list.c @@ -99,6 +99,7 @@ struct data_list_pgm struct variable *end; /* Variable specified on END subcommand. */ int record_cnt; /* Number of records. */ struct string delims; /* Field delimiters. */ + int skip_records; /* Records to skip before first case. */ }; static const struct case_source_class data_list_source_class; @@ -134,6 +135,7 @@ cmd_data_list (struct dataset *ds) dls->type = -1; dls->end = NULL; dls->record_cnt = 0; + dls->skip_records = 0; ds_init_empty (&dls->delims); ds_register_pool (&dls->delims, dls->pool); @@ -158,6 +160,14 @@ cmd_data_list (struct dataset *ds) lex_get (); lex_match (')'); } + else if (lex_match_id ("SKIP")) + { + lex_match ('='); + if (!lex_force_int ()) + goto error; + dls->skip_records = lex_integer (); + lex_get (); + } else if (lex_match_id ("END")) { if (dls->end) @@ -819,6 +829,16 @@ data_list_source_read (struct case_source *source, { struct data_list_pgm *dls = source->aux; + /* Skip the requested number of records before reading the + first case. */ + while (dls->skip_records > 0) + { + if (dfm_eof (dls->reader)) + return false; + dfm_forward_record (dls->reader); + dls->skip_records--; + } + for (;;) { bool ok; diff --git a/tests/ChangeLog b/tests/ChangeLog index 790a3316..071cd012 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,8 @@ +Thu Nov 2 20:58:12 2006 Ben Pfaff + + * command/data-list.sh: Test newly implement SKIP keyword on DATA + LIST. + Sat Nov 4 16:08:58 2006 Ben Pfaff * automake.mk: Add binhex-out.sh, date-out.sh, month-out.sh, diff --git a/tests/command/data-list.sh b/tests/command/data-list.sh index fc42b94c..d16521a1 100755 --- a/tests/command/data-list.sh +++ b/tests/command/data-list.sh @@ -64,8 +64,9 @@ end data. list. -data list free/A B C D. +data list free skip=1/A B C D. begin data. +# This record is ignored. ,1,2,3 ,4,,5 6 @@ -81,8 +82,10 @@ begin data. end data. list. -data list free (tab)/A B C D. +data list free (tab) skip=2/A B C D. begin data. +# These records +# are skipped. 1 2 3 4 1 2 3 1 2 4