From: John Darrington Date: Sat, 25 Feb 2012 10:57:06 +0000 (+0100) Subject: Added SHOW options DIRECTORY, ENVIRONMENT, TEMPDIR and VERSION X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=14decddbe997e8059910e02d28c5cccd747240fc Added SHOW options DIRECTORY, ENVIRONMENT, TEMPDIR and VERSION --- diff --git a/doc/utilities.texi b/doc/utilities.texi index 3779615a67..40648d430c 100644 --- a/doc/utilities.texi +++ b/doc/utilities.texi @@ -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 diff --git a/src/language/utilities/set.q b/src/language/utilities/set.q index ed6a08519e..38a6589b8e 100644 --- a/src/language/utilities/set.q +++ b/src/language/utilities/set.q @@ -20,6 +20,7 @@ #include #include #include +#include #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) { diff --git a/src/libpspp/temp-file.c b/src/libpspp/temp-file.c index 9d3c392659..d121cb9e2e 100644 --- a/src/libpspp/temp-file.c +++ b/src/libpspp/temp-file.c @@ -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); diff --git a/src/libpspp/temp-file.h b/src/libpspp/temp-file.h index 499c1e3488..186266574e 100644 --- a/src/libpspp/temp-file.h +++ b/src/libpspp/temp-file.h @@ -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 */