From: John Darrington Date: Thu, 19 Apr 2012 19:11:36 +0000 (+0200) Subject: SHOW: New subcommand N X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=58fe146604dfb8522c251aefbd9616779ae6cb46 SHOW: New subcommand N This subcommand reports the number of cases in the active dataset. --- diff --git a/doc/utilities.texi b/doc/utilities.texi index d370d80844..c568acec6c 100644 --- a/doc/utilities.texi +++ b/doc/utilities.texi @@ -835,6 +835,7 @@ SHOW [MXERRS] [MXLOOPS] [MXWARNS] + [N] [SCOMPRESSION] [TEMPDIR] [UNDEFINED] @@ -859,6 +860,9 @@ Show all custom currency settings (@subcmd{CCA} through @subcmd{CCE}). Shows the current working directory. @item @subcmd{ENVIRONMENT} Shows the operating system details. +@item @subcmd{N} +Reports the number of cases in the active dataset. The reported number is not +weighted. If no dataset is defined, then @samp{Unknown} will be reported. @item @subcmd{TEMPDIR} Shows the path of the directory where temporary files will be stored. @item @subcmd{VERSION} diff --git a/src/language/utilities/set.q b/src/language/utilities/set.q index 38a6589b8e..dcf7a327be 100644 --- a/src/language/utilities/set.q +++ b/src/language/utilities/set.q @@ -22,6 +22,9 @@ #include #include +#include "gl/vasnprintf.h" + +#include "data/casereader.h" #include "data/data-in.h" #include "data/data-out.h" #include "data/dataset.h" @@ -866,6 +869,23 @@ show_system (const struct dataset *ds UNUSED) return strdup (host_system); } +static char * +show_n (const struct dataset *ds) +{ + casenumber n; + size_t l; + + const struct casereader *reader = dataset_source (ds); + + if (reader == NULL) + return strdup (_("Unknown")); + + n = casereader_count_cases (reader); + + return asnprintf (NULL, &l, "%ld", n); +} + + struct show_sbc { const char *name; @@ -891,6 +911,7 @@ const struct show_sbc show_table[] = {"MXERRS", show_mxerrs}, {"MXLOOPS", show_mxloops}, {"MXWARNS", show_mxwarns}, + {"N", show_n}, {"PRINTBACk", show_printback}, {"RESULTS", show_results}, {"RIB", show_rib}, diff --git a/tests/automake.mk b/tests/automake.mk index cb8da0f51c..59d1977b95 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -299,6 +299,7 @@ TESTSUITE_AT = \ tests/language/utilities/insert.at \ tests/language/utilities/permissions.at \ tests/language/utilities/set.at \ + tests/language/utilities/show.at \ tests/language/utilities/title.at \ tests/language/xforms/compute.at \ tests/language/xforms/count.at \ diff --git a/tests/language/utilities/show.at b/tests/language/utilities/show.at new file mode 100644 index 0000000000..ad3ebc0c74 --- /dev/null +++ b/tests/language/utilities/show.at @@ -0,0 +1,34 @@ +AT_BANNER([SHOW]) + +AT_SETUP([SHOW N]) + +AT_DATA([show.sps], [dnl +DATA LIST LIST NOTABLE /x. +BEGIN DATA. +1 +2 +3 +END DATA. + +SHOW N. +]) + +AT_CHECK([pspp -O format=csv show.sps], [0], [dnl +show.sps:8: note: SHOW: N is 3. +]) + +AT_CLEANUP + + +AT_SETUP([SHOW N empty]) + +AT_DATA([shown-empty.sps], [dnl +SHOW N. +]) + +AT_CHECK([pspp -O format=csv shown-empty.sps], [0], [dnl +shown-empty.sps:1: note: SHOW: N is Unknown. +]) + +AT_CLEANUP +