SHOW: New subcommand N
authorJohn Darrington <john@darrington.wattle.id.au>
Thu, 19 Apr 2012 19:11:36 +0000 (21:11 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Thu, 19 Apr 2012 19:11:36 +0000 (21:11 +0200)
This subcommand reports the number of cases in the active dataset.

doc/utilities.texi
src/language/utilities/set.q
tests/automake.mk
tests/language/utilities/show.at [new file with mode: 0644]

index d370d808443cdcaef8a28a2a6c1fc75feecbc487..c568acec6c1967f61918cb1a64e30e65855f4069 100644 (file)
@@ -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}
index 38a6589b8e4c10aa23d4ccd6825c914b9f58097b..dcf7a327be79e2681bbfbe841affb0a02b370592 100644 (file)
@@ -22,6 +22,9 @@
 #include <time.h>
 #include <unistd.h>
 
+#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},
index cb8da0f51cb186c3a5e817a4c3f4a7696621509a..59d1977b95e2d4aa52be9518a60e61b81b5fb99b 100644 (file)
@@ -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 (file)
index 0000000..ad3ebc0
--- /dev/null
@@ -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
+