From 6ee30c166727634ef579354e29eff96f70675418 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 6 Jul 2018 12:19:45 +0200 Subject: [PATCH] ODS reader: Deal with case where /READNAMES vs. non-unity column spans. * src/data/ods-reader.c (ods_make_reader): Populate var_specs for the entire column span. * tests/language/data-io/readnames.ods: New file * tests/automake.mk: Add it. * tests/language/data-io/get-data-spreadsheet.at: New test. --- src/data/ods-reader.c | 24 ++++++------- tests/automake.mk | 1 + .../language/data-io/get-data-spreadsheet.at | 32 ++++++++++++++++++ tests/language/data-io/readnames.ods | Bin 0 -> 7957 bytes 4 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 tests/language/data-io/readnames.ods diff --git a/src/data/ods-reader.c b/src/data/ods-reader.c index 387bea00ac..ce9310a230 100644 --- a/src/data/ods-reader.c +++ b/src/data/ods-reader.c @@ -401,7 +401,7 @@ process_node (struct ods_reader *or, struct state_data *r) or->sheets[r->current_sheet].stop_row = r->row - 1; - if ( or->sheets[r->current_sheet].stop_col < r->col - 1) + if ( or->sheets[r->current_sheet].stop_col < r->col - 1) or->sheets[r->current_sheet].stop_col = r->col - 1; if (XML_READER_TYPE_END_ELEMENT == r->node_type) @@ -721,17 +721,15 @@ ods_make_reader (struct spreadsheet *spreadsheet, { while (1 == xmlTextReaderRead (r->rsd.xtr)) { - int idx; - process_node (r, &r->rsd); /* If the row is finished then stop for now */ if (r->rsd.state == STATE_TABLE && r->rsd.row > r->start_row) break; - idx = r->rsd.col - r->start_col -1 ; + int idx = r->rsd.col - r->start_col - 1; - if ( idx < 0) + if (idx < 0) continue; if (r->stop_col != -1 && idx > r->stop_col - r->start_col) @@ -742,8 +740,7 @@ ods_make_reader (struct spreadsheet *spreadsheet, XML_READER_TYPE_TEXT == r->rsd.node_type) { xmlChar *value = xmlTextReaderValue (r->rsd.xtr); - - if ( idx >= n_var_specs) + if (idx >= n_var_specs) { var_spec = xrealloc (var_spec, sizeof (*var_spec) * (idx + 1)); @@ -753,11 +750,14 @@ ods_make_reader (struct spreadsheet *spreadsheet, (idx - n_var_specs + 1) * sizeof (*var_spec)); n_var_specs = idx + 1; } - var_spec[idx].firstval.text = 0; - var_spec[idx].firstval.value = 0; - var_spec[idx].firstval.type = 0; - - var_spec [idx].name = strdup (CHAR_CAST (const char *, value)); + for (int i = 0; i < r->rsd.col_span; ++i) + { + var_spec[idx - i].firstval.text = 0; + var_spec[idx - i].firstval.value = 0; + var_spec[idx - i].firstval.type = 0; + var_spec[idx - i].name = + strdup (CHAR_CAST (const char *, value)); + } xmlFree (value); } diff --git a/tests/automake.mk b/tests/automake.mk index 4a05bea980..7c7bdc7496 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -278,6 +278,7 @@ EXTRA_DIST += \ tests/language/data-io/Book1.gnm.unzipped \ tests/language/data-io/test.ods \ tests/language/data-io/newone.ods \ + tests/language/data-io/readnames.ods \ tests/language/stats/llz.zsav CLEANFILES += *.save pspp.* foo* diff --git a/tests/language/data-io/get-data-spreadsheet.at b/tests/language/data-io/get-data-spreadsheet.at index 6c838d99bd..eca194a02d 100644 --- a/tests/language/data-io/get-data-spreadsheet.at +++ b/tests/language/data-io/get-data-spreadsheet.at @@ -385,3 +385,35 @@ AT_CHECK([pspp -O format=csv crash.sps], [0], [ignore]) AT_CLEANUP + +AT_SETUP([GET DATA /TYPE=ODS readnames]) + +dnl Check for a bug where in the ODS reader /READNAMES incorrectly +dnl dealt with repeated names. +AT_CHECK([cp $top_srcdir/tests/language/data-io/readnames.ods this.ods])dnl + +AT_DATA([readnames.sps],[dnl +GET DATA /TYPE=ODS /FILE='this.ods' /CELLRANGE=RANGE 'A1:H8' /READNAMES=ON +DISPLAY DICTIONARY. +LIST. +]) + + +AT_CHECK([pspp -O format=csv readnames.sps], [0], +[Variable,Description,Position +freda,Format: F8.2,1 +fred,Format: F8.2,2 +fred_A,Format: F8.2,3 +fred_B,Format: F8.2,4 +fred_C,Format: F8.2,5 +fred_D,Format: F8.2,6 +fred_E,Format: F8.2,7 + +Table: Data List +freda,fred,fred_A,fred_B,fred_C,fred_D,fred_E +1.00,2.00,3.00,4.00,5.00,6.00,7.00 +8.00,9.00,10.00,11.00,12.00,13.00,14.00 +]) + +AT_CLEANUP + diff --git a/tests/language/data-io/readnames.ods b/tests/language/data-io/readnames.ods new file mode 100644 index 0000000000000000000000000000000000000000..3cccb2da06bb4b055380bd92721e666421c0aace GIT binary patch literal 7957 zcmdT}XIN9)whahKXwrLCkfIPpiuB%llcEA4gqjc_p%J?H9q_x*e`-}?5-PR7XIGkc9$mcG^*0$Koo7yzJjTGS4MNkj?( z0D#kRatZ)JA0l zA|0Sml>T2h+aR9X(q{mG)4_PcY3$$uw{ZbG!jK@;_omQkT zc!_IQn8=gWt=@hfk#Zi86$!8SqT|1}T<(Laf8_3%hu2#h=&!{(VgWfkl-SMv+zP_!m~c{a0I zb*G@&Hb-_gD$C~3)uT*g5JU5ErYncY-ZEtK3)gm6Ixrw&e0g1LPa!v}v+?a!A1NP$ z>Gah*78W^2$Ff(4@{U~&B^_>LPNVqSGO7gXG$aobEfSjtN~9$b9?~MI>v=Wqk|v&! zJ!!7ak>}$F?v%-vxSMN{r`wc(T{Qz-M0;2*%^&r>%knf0&GIyOb69!VU9UdRDzcy5 z*>G&}k;LZEF)#pVY1G}*KU}upt`?*Fj%@%vx}3Nt7$L+xXt}@NK-Vc`)Oc^UG;DLv z+H?S8w5s=^NqTR_k-4B%c4mAAPS4RfZn|l(ytFuau-y0NP|KG^>&dbl@^izjI}B+7 z0Z)!dEJyS`LD+*55B{F7%ve`@%pH=)UzdmS)MD9Xe7FDqP4-@VJpiyfcFC|M**cy) zvH%SgUFA|m>)=0E95FHRAFKHElkY}$GC@L7C`T82q>wipwqZWyK7XAuV74s#;CZ68 zdN+k}TY_616dx#-5-L7PZ+8E3JvWn5b0CzgDzuda|BG>rlh1n_jVDtZc_Y*Fd;4u& zVG_2i2JU$Y111H4`%1T!?ZkT>CM5R@{mYKsbe?8X=RxQ*0ZVh&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