From: Ben Pfaff Date: Tue, 7 Mar 2023 05:16:37 +0000 (-0800) Subject: SHOW: Implement SHOW ENVIRONMENT. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44865eced89408cf217088517ee407c0ddd7d517;p=pspp SHOW: Implement SHOW ENVIRONMENT. Requested by knassen@chartermi.net. --- diff --git a/NEWS b/NEWS index 79c0f000bf..9abe5bc18b 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,8 @@ Changes after 1.6.2: * DISPLAY MACROS is now implemented. + * SHOW ENVIRONMENT is now implemented. + * Removed the MODIFY VARS command, which is not in SPSS. * Building from a Git repository, which previously required GIMP, now diff --git a/src/language/commands/set.c b/src/language/commands/set.c index 905b489f79..7998850127 100644 --- a/src/language/commands/set.c +++ b/src/language/commands/set.c @@ -45,6 +45,7 @@ #include "libpspp/i18n.h" #include "libpspp/integer-format.h" #include "libpspp/message.h" +#include "libpspp/string-array.h" #include "math/random.h" #include "output/driver.h" #include "output/journal.h" @@ -1369,6 +1370,33 @@ show_all_cc (const struct dataset *ds, struct pivot_table **ptp) } } +static void +show_environment (void) +{ + struct pivot_table *pt = pivot_table_create (N_("Environment Variables")); + pivot_dimension_create (pt, PIVOT_AXIS_ROW, N_("Variable")); + + struct string_array sa = STRING_ARRAY_INITIALIZER; + for (char **env = environ; *env; env++) + string_array_append (&sa, *env); + string_array_sort (&sa); + + for (size_t i = 0; i < sa.n; i++) + { + struct substring value = ss_cstr (sa.strings[i]); + struct substring variable; + ss_get_until (&value, '=', &variable); + + char *variable_s = ss_xstrdup (variable); + char *value_s = ss_xstrdup (value); + add_row (pt, variable_s, value_s); + free (variable_s); + free (value_s); + } + string_array_destroy (&sa); + pivot_table_submit (pt); +} + int cmd_show (struct lexer *lexer, struct dataset *ds) { @@ -1392,6 +1420,8 @@ cmd_show (struct lexer *lexer, struct dataset *ds) show_copying (ds); else if (lex_match_id (lexer, "SYSTEM")) show_system (ds); + else if (lex_match_id (lexer, "ENVIRONMENT")) + show_environment (); else if (lex_match_id (lexer, "TITLE")) { struct setting s = { .name = "TITLE", .show = show_TITLE }; diff --git a/tests/language/commands/show.at b/tests/language/commands/show.at index 02c8ee1f94..afaf86174f 100644 --- a/tests/language/commands/show.at +++ b/tests/language/commands/show.at @@ -17,7 +17,6 @@ dnl AT_BANNER([SHOW]) AT_SETUP([SHOW N]) - AT_DATA([show.sps], [dnl DATA LIST LIST NOTABLE /x. BEGIN DATA. @@ -28,25 +27,26 @@ END DATA. SHOW N. ]) - AT_CHECK([pspp -O format=csv show.sps], [0], [dnl Table: Settings N,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 Table: Settings N,Unknown ]) - AT_CLEANUP +AT_SETUP([SHOW ENVIRONMENT]) +AT_DATA([show.sps], [dnl +SHOW ENVIRONMENT. +]) +AT_CHECK([pspp -O format=csv show.sps], [0], [ignore]) +AT_CLEANUP \ No newline at end of file