Added SHOW options DIRECTORY, ENVIRONMENT, TEMPDIR and VERSION 20120225030502/pspp 20120226030503/pspp
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 25 Feb 2012 10:57:06 +0000 (11:57 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 25 Feb 2012 10:57:06 +0000 (11:57 +0100)
doc/utilities.texi
src/language/utilities/set.q
src/libpspp/temp-file.c
src/libpspp/temp-file.h

index 3779615a6739ebf67e803fdde1bb672f7e88421b..40648d430c28ee014f9c201983e0fc1d96d617c0 100644 (file)
@@ -824,13 +824,17 @@ SHOW
         [CCE]
         [COPYING]
         [DECIMALS]
+        [DIRECTORY]
+        [ENVIRONMENT]
         [FORMAT]
         [LENGTH]
         [MXERRS]
         [MXLOOPS]
         [MXWARNS]
         [SCOMPRESSION]
+        [TEMPDIR]
         [UNDEFINED]
+        [VERSION]
         [WARRANTY]
         [WEIGHT]
         [WIDTH]
@@ -847,9 +851,17 @@ subcommands:
 Show all settings.
 @item CC
 Show all custom currency settings (CCA through CCE).
+@item DIRECTORY
+Shows the current working directory.
+@item ENVIRONMENT
+Shows the operating system details.
+@item TEMPDIR
+Shows the path of the directory where temporary files will be stored.
+@item VERSION
+Shows the version of this installation of PSPP.
 @item WARRANTY
 Show details of the lack of warranty for PSPP.
-@item COPYING
+@item COPYING / LICENSE
 Display the terms of PSPP's copyright licence (@pxref{License}).
 @end table
 
index ed6a08519ed7418e33ac6af1cb267f3bc5db94e6..38a6589b8e4c10aa23d4ccd6825c914b9f58097b 100644 (file)
@@ -20,6 +20,7 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <time.h>
+#include <unistd.h>
 
 #include "data/data-in.h"
 #include "data/data-out.h"
@@ -34,6 +35,8 @@
 #include "language/lexer/lexer.h"
 #include "libpspp/compiler.h"
 #include "libpspp/copyleft.h"
+#include "libpspp/temp-file.h"
+#include "libpspp/version.h"
 #include "libpspp/float-format.h"
 #include "libpspp/i18n.h"
 #include "libpspp/integer-format.h"
@@ -828,6 +831,41 @@ show_width (const struct dataset *ds UNUSED)
   return xasprintf ("%d", settings_get_viewwidth ());
 }
 
+static char *
+show_current_directory (const struct dataset *ds UNUSED)
+{
+  char *buf = NULL;
+  char *wd = NULL;
+  size_t len = 256;
+
+  do
+    {
+      len <<= 1;
+      buf = xrealloc (buf, len);
+    } 
+  while (NULL == (wd = getcwd (buf, len)));
+
+  return wd;
+}
+
+static char *
+show_tempdir (const struct dataset *ds UNUSED)
+{
+  return strdup (temp_dir_name ());
+}
+
+static char *
+show_version (const struct dataset *ds UNUSED)
+{
+  return strdup (version);
+}
+
+static char *
+show_system (const struct dataset *ds UNUSED)
+{
+  return strdup (host_system);
+}
+
 struct show_sbc
   {
     const char *name;
@@ -843,6 +881,8 @@ const struct show_sbc show_table[] =
     {"CCD", show_ccd},
     {"CCE", show_cce},
     {"DECIMALS", show_decimals},
+    {"DIRECTORY", show_current_directory},
+    {"ENVIRONMENT", show_system},
     {"ERRORS", show_errors},
     {"FORMAT", show_format},
     {"LENGTH", show_length},
@@ -856,7 +896,9 @@ const struct show_sbc show_table[] =
     {"RIB", show_rib},
     {"RRB", show_rrb},
     {"SCOMPRESSION", show_scompression},
+    {"TEMPDIR", show_tempdir},
     {"UNDEFINED", show_undefined},
+    {"VERSION", show_version},
     {"WEIGHT", show_weight},
     {"WIB", show_wib},
     {"WRB", show_wrb},
@@ -905,6 +947,7 @@ show_copying (const struct dataset *ds UNUSED)
   fputs (copyleft, stdout);
 }
 
+
 int
 cmd_show (struct lexer *lexer, struct dataset *ds)
 {
@@ -922,7 +965,7 @@ cmd_show (struct lexer *lexer, struct dataset *ds)
         show_all_cc (ds);
       else if (lex_match_id (lexer, "WARRANTY"))
         show_warranty (ds);
-      else if (lex_match_id (lexer, "COPYING"))
+      else if (lex_match_id (lexer, "COPYING") || lex_match_id (lexer, "LICENSE"))
         show_copying (ds);
       else if (lex_token (lexer) == T_ID)
         {
index 9d3c392659753043667af822b9bbfe7bd3e1b0f0..d121cb9e2e5fc42466aeb0f68fd42bdb5f9daf61 100644 (file)
@@ -40,6 +40,7 @@
 
 */
 
+static void cleanup (void);
 
 static struct temp_dir *temp_dir;
 struct hmapx map;
@@ -51,6 +52,30 @@ setup (void)
   temp_dir = create_temp_dir ("pspp", NULL, true);
 }
 
+static void
+initialise (void)
+{
+  if (temp_dir == NULL)
+    {
+      setup ();
+      if (temp_dir == NULL)
+        return ;
+      atexit (cleanup);
+    }
+}
+
+
+const char *
+temp_dir_name (void)
+{
+  initialise ();
+
+  if (temp_dir)
+    return temp_dir->dir_name;
+
+  return NULL;
+}
+
 static void
 cleanup (void)
 {
@@ -74,13 +99,9 @@ create_temp_file (void)
   char *file_name;
   FILE *stream;
 
+  initialise ();
   if (temp_dir == NULL)
-    {
-      setup ();
-      if (temp_dir == NULL)
-        return NULL;
-      atexit (cleanup);
-    }
+    return NULL;
 
   file_name = xasprintf ("%s/%d", temp_dir->dir_name, idx++);
   register_temp_file (temp_dir, file_name);
index 499c1e34884df8aa4d6427b142366e800644bad1..186266574ec33966153eef15cac74976ac16363f 100644 (file)
@@ -23,5 +23,7 @@
 
 FILE *create_temp_file (void);
 void close_temp_file (FILE *);
+const char *temp_dir_name (void);
+
 
 #endif /* libpspp/ext-array.h */