1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "gl/vasnprintf.h"
28 #include "data/casereader.h"
29 #include "data/data-in.h"
30 #include "data/data-out.h"
31 #include "data/dataset.h"
32 #include "data/dictionary.h"
33 #include "data/format.h"
34 #include "data/settings.h"
35 #include "data/value.h"
36 #include "data/variable.h"
37 #include "language/command.h"
38 #include "language/lexer/format-parser.h"
39 #include "language/lexer/lexer.h"
40 #include "libpspp/assertion.h"
41 #include "libpspp/compiler.h"
42 #include "libpspp/copyleft.h"
43 #include "libpspp/temp-file.h"
44 #include "libpspp/version.h"
45 #include "libpspp/float-format.h"
46 #include "libpspp/i18n.h"
47 #include "libpspp/integer-format.h"
48 #include "libpspp/message.h"
49 #include "math/random.h"
50 #include "output/driver.h"
51 #include "output/journal.h"
52 #include "output/pivot-table.h"
54 #include "gl/xalloc.h"
57 #define _(msgid) gettext (msgid)
60 match_subcommand (struct lexer *lexer, const char *name)
62 if (lex_match_id (lexer, name))
64 lex_match (lexer, T_EQUALS);
72 parse_enum_valist (struct lexer *lexer, va_list args)
76 const char *name = va_arg (args, char *);
79 int value = va_arg (args, int);
81 if (lex_match_id (lexer, name))
86 #define parse_enum(...) parse_enum (__VA_ARGS__, NULL_SENTINEL)
87 static int SENTINEL(0)
88 (parse_enum) (struct lexer *lexer, ...)
92 va_start (args, lexer);
93 int retval = parse_enum_valist (lexer, args);
99 #define force_parse_enum(...) force_parse_enum (__VA_ARGS__, NULL_SENTINEL)
100 static int SENTINEL(0)
101 (force_parse_enum) (struct lexer *lexer, ...)
105 va_start (args, lexer);
106 int retval = parse_enum_valist (lexer, args);
111 enum { MAX_OPTIONS = 9 };
112 const char *options[MAX_OPTIONS];
115 va_start (args, lexer);
116 while (n < MAX_OPTIONS)
118 const char *name = va_arg (args, char *);
127 lex_error_expecting_array (lexer, options, n);
134 parse_bool (struct lexer *lexer)
136 return parse_enum (lexer,
137 "ON", true, "YES", true,
138 "OFF", false, "NO", false);
142 force_parse_bool (struct lexer *lexer)
144 return force_parse_enum (lexer,
145 "ON", true, "YES", true,
146 "OFF", false, "NO", false);
150 force_parse_int (struct lexer *lexer, int *integerp)
152 if (!lex_force_int (lexer))
154 *integerp = lex_integer (lexer);
160 parse_output_routing (struct lexer *lexer, enum settings_output_type type)
162 enum settings_output_devices devices;
163 if (lex_match_id (lexer, "ON") || lex_match_id (lexer, "BOTH"))
164 devices = SETTINGS_DEVICE_LISTING | SETTINGS_DEVICE_TERMINAL;
165 else if (lex_match_id (lexer, "TERMINAL"))
166 devices = SETTINGS_DEVICE_TERMINAL;
167 else if (lex_match_id (lexer, "LISTING"))
168 devices = SETTINGS_DEVICE_LISTING;
169 else if (lex_match_id (lexer, "OFF") || lex_match_id (lexer, "NONE"))
173 lex_error (lexer, NULL);
177 settings_set_output_routing (type, devices);
183 parse_integer_format (struct lexer *lexer,
184 void (*set_format) (enum integer_format))
186 int value = force_parse_enum (lexer,
187 "MSBFIRST", INTEGER_MSB_FIRST,
188 "LSBFIRST", INTEGER_LSB_FIRST,
190 "NATIVE", INTEGER_NATIVE);
197 parse_real_format (struct lexer *lexer,
198 void (*set_format) (enum float_format))
200 int value = force_parse_enum (lexer,
201 "NATIVE", FLOAT_NATIVE_DOUBLE,
202 "ISL", FLOAT_IEEE_SINGLE_LE,
203 "ISB", FLOAT_IEEE_SINGLE_BE,
204 "IDL", FLOAT_IEEE_DOUBLE_LE,
205 "IDB", FLOAT_IEEE_DOUBLE_BE,
217 parse_unimplemented (struct lexer *lexer, const char *name)
219 msg (SW, _("%s is not yet implemented."), name);
220 if (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD)
226 parse_ccx (struct lexer *lexer, enum fmt_type ccx)
228 if (!lex_force_string (lexer))
231 settings_set_cc (lex_tokcstr (lexer), ccx);
237 parse_BASETEXTDIRECTION (struct lexer *lexer)
239 return parse_unimplemented (lexer, "BASETEXTDIRECTION");
243 parse_BLANKS (struct lexer *lexer)
245 if (lex_match_id (lexer, "SYSMIS"))
246 settings_set_blanks (SYSMIS);
249 if (!lex_force_num (lexer))
251 settings_set_blanks (lex_number (lexer));
258 parse_BLOCK (struct lexer *lexer)
260 return parse_unimplemented (lexer, "BLOCK");
264 parse_BOX (struct lexer *lexer)
266 return parse_unimplemented (lexer, "BOX");
270 parse_CACHE (struct lexer *lexer)
272 return parse_unimplemented (lexer, "CACHE");
276 parse_CCA (struct lexer *lexer)
278 return parse_ccx (lexer, FMT_CCA);
282 parse_CCB (struct lexer *lexer)
284 return parse_ccx (lexer, FMT_CCB);
288 parse_CCC (struct lexer *lexer)
290 return parse_ccx (lexer, FMT_CCC);
294 parse_CCD (struct lexer *lexer)
296 return parse_ccx (lexer, FMT_CCD);
300 parse_CCE (struct lexer *lexer)
302 return parse_ccx (lexer, FMT_CCE);
306 parse_CELLSBREAK (struct lexer *lexer)
308 return parse_unimplemented (lexer, "CELLSBREAK");
312 parse_CMPTRANS (struct lexer *lexer)
314 return parse_unimplemented (lexer, "CMPTRANS");
318 parse_COMPRESSION (struct lexer *lexer)
320 return parse_unimplemented (lexer, "COMPRESSION");
324 parse_CTEMPLATE (struct lexer *lexer)
326 return parse_unimplemented (lexer, "CTEMPLATE");
330 parse_DECIMAL (struct lexer *lexer)
332 int decimal_char = force_parse_enum (lexer,
335 if (decimal_char != -1)
336 settings_set_decimal_char (decimal_char);
337 return decimal_char != -1;
341 parse_EPOCH (struct lexer *lexer)
343 if (lex_match_id (lexer, "AUTOMATIC"))
344 settings_set_epoch (-1);
345 else if (lex_is_integer (lexer))
347 int new_epoch = lex_integer (lexer);
349 if (new_epoch < 1500)
351 msg (SE, _("%s must be 1500 or later."), "EPOCH");
354 settings_set_epoch (new_epoch);
358 lex_error (lexer, _("expecting %s or year"), "AUTOMATIC");
366 parse_ERRORS (struct lexer *lexer)
368 return parse_output_routing (lexer, SETTINGS_OUTPUT_ERROR);
372 parse_FORMAT (struct lexer *lexer)
376 lex_match (lexer, T_EQUALS);
377 if (!parse_format_specifier (lexer, &fmt))
380 if (!fmt_check_output (&fmt))
383 if (fmt_is_string (fmt.type))
385 char str[FMT_STRING_LEN_MAX + 1];
386 msg (SE, _("%s requires numeric output format as an argument. "
387 "Specified format %s is of type string."),
389 fmt_to_string (&fmt, str));
393 settings_set_format (&fmt);
398 parse_FUZZBITS (struct lexer *lexer)
400 if (!lex_force_int (lexer))
402 int fuzzbits = lex_integer (lexer);
405 if (fuzzbits >= 0 && fuzzbits <= 20)
406 settings_set_fuzzbits (fuzzbits);
408 msg (SE, _("%s must be between 0 and 20."), "FUZZBITS");
413 parse_HEADER (struct lexer *lexer)
415 return parse_unimplemented (lexer, "HEADER");
419 parse_INCLUDE (struct lexer *lexer)
421 int include = force_parse_bool (lexer);
423 settings_set_include (include);
424 return include != -1;
428 parse_JOURNAL (struct lexer *lexer)
430 int b = parse_bool (lexer);
435 else if (lex_is_string (lexer) || lex_token (lexer) == T_ID)
437 char *filename = utf8_to_filename (lex_tokcstr (lexer));
438 journal_set_file_name (filename);
445 lex_error (lexer, NULL);
452 parse_LENGTH (struct lexer *lexer)
456 if (lex_match_id (lexer, "NONE"))
460 if (!lex_force_int (lexer))
462 if (lex_integer (lexer) < 1)
464 msg (SE, _("%s must be at least %d."), "LENGTH", 1);
467 page_length = lex_integer (lexer);
471 if (page_length != -1)
472 settings_set_viewlength (page_length);
478 parse_LOCALE (struct lexer *lexer)
480 if (!lex_force_string (lexer))
483 /* Try the argument as an encoding name, then as a locale name or alias. */
484 const char *s = lex_tokcstr (lexer);
485 if (valid_encoding (s))
486 set_default_encoding (s);
487 else if (!set_encoding_from_locale (s))
489 msg (ME, _("%s is not a recognized encoding or locale name"), s);
498 parse_MESSAGES (struct lexer *lexer)
500 return parse_output_routing (lexer, SETTINGS_OUTPUT_NOTE);
504 parse_MEXPAND (struct lexer *lexer)
506 return parse_unimplemented (lexer, "MEXPAND");
510 parse_MITERATE (struct lexer *lexer)
512 return parse_unimplemented (lexer, "MITERATE");
516 parse_MNEST (struct lexer *lexer)
518 return parse_unimplemented (lexer, "MNEST");
522 parse_MPRINT (struct lexer *lexer)
524 return parse_unimplemented (lexer, "MPRINT");
528 parse_MXERRS (struct lexer *lexer)
531 if (!force_parse_int (lexer, &n))
535 settings_set_max_messages (MSG_S_ERROR, n);
537 msg (SE, _("%s must be at least 1."), "MXERRS");
542 parse_MXLOOPS (struct lexer *lexer)
545 if (!force_parse_int (lexer, &n))
549 settings_set_mxloops (n);
551 msg (SE, _("%s must be at least 1."), "MXLOOPS");
556 parse_MXWARNS (struct lexer *lexer)
559 if (!force_parse_int (lexer, &n))
563 settings_set_max_messages (MSG_S_WARNING, n);
565 msg (SE, _("%s must not be negative."), "MXWARNS");
570 parse_PRINTBACK (struct lexer *lexer)
572 return parse_output_routing (lexer, SETTINGS_OUTPUT_SYNTAX);
576 parse_RESULTS (struct lexer *lexer)
578 return parse_output_routing (lexer, SETTINGS_OUTPUT_RESULT);
582 parse_RIB (struct lexer *lexer)
584 return parse_integer_format (lexer, settings_set_input_integer_format);
588 parse_RRB (struct lexer *lexer)
590 return parse_real_format (lexer, settings_set_input_float_format);
594 parse_SAFER (struct lexer *lexer)
596 bool ok = force_parse_enum (lexer, "ON", true, "YES", true) != -1;
598 settings_set_safer_mode ();
603 parse_SCOMPRESSION (struct lexer *lexer)
605 int value = force_parse_bool (lexer);
607 settings_set_scompression (value);
612 parse_SEED (struct lexer *lexer)
614 if (lex_match_id (lexer, "RANDOM"))
618 if (!lex_force_num (lexer))
620 set_rng (lex_number (lexer));
628 parse_SMALL (struct lexer *lexer)
630 if (!lex_force_num (lexer))
632 settings_set_small (lex_number (lexer));
638 parse_TNUMBERS (struct lexer *lexer)
640 int value = force_parse_enum (lexer,
641 "LABELS", SETTINGS_VALUE_SHOW_LABEL,
642 "VALUES", SETTINGS_VALUE_SHOW_VALUE,
643 "BOTH", SETTINGS_VALUE_SHOW_BOTH);
645 settings_set_show_values (value);
650 parse_TVARS (struct lexer *lexer)
652 int value = force_parse_enum (lexer,
653 "LABELS", SETTINGS_VALUE_SHOW_LABEL,
654 "NAMES", SETTINGS_VALUE_SHOW_VALUE,
655 "BOTH", SETTINGS_VALUE_SHOW_BOTH);
657 settings_set_show_variables (value);
662 parse_TLOOK (struct lexer *lexer)
664 if (lex_match_id (lexer, "NONE"))
665 pivot_table_look_set_default (pivot_table_look_builtin_default ());
666 else if (lex_is_string (lexer))
668 struct pivot_table_look *look;
669 char *error = pivot_table_look_read (lex_tokcstr (lexer), &look);
674 msg (SE, "%s", error);
679 pivot_table_look_set_default (look);
680 pivot_table_look_unref (look);
687 parse_UNDEFINED (struct lexer *lexer)
689 int value = force_parse_enum (lexer,
693 settings_set_undefined (value);
698 parse_WIB (struct lexer *lexer)
700 return parse_integer_format (lexer, settings_set_output_integer_format);
704 parse_WRB (struct lexer *lexer)
706 return parse_real_format (lexer, settings_set_output_float_format);
710 parse_WIDTH (struct lexer *lexer)
712 if (lex_match_id (lexer, "NARROW"))
713 settings_set_viewwidth (79);
714 else if (lex_match_id (lexer, "WIDE"))
715 settings_set_viewwidth (131);
718 if (!lex_force_int (lexer))
720 if (lex_integer (lexer) < 40)
722 msg (SE, _("%s must be at least %d."), "WIDTH", 40);
725 settings_set_viewwidth (lex_integer (lexer));
733 parse_WORKSPACE (struct lexer *lexer)
735 if (!lex_force_int (lexer))
737 int workspace = lex_integer (lexer);
740 if (workspace < 1024 && !settings_get_testing_mode ())
741 msg (SE, _("%s must be at least 1MB"), "WORKSPACE");
742 else if (workspace <= 0)
743 msg (SE, _("%s must be positive"), "WORKSPACE");
745 settings_set_workspace (workspace * 1024L);
750 parse_setting (struct lexer *lexer)
755 bool (*function) (struct lexer *);
757 const struct setting settings[] = {
758 { "BASETEXTDIRECTION", parse_BASETEXTDIRECTION },
759 { "BLANKS", parse_BLANKS },
760 { "BLOCK", parse_BLOCK },
761 { "BOX", parse_BOX },
762 { "CACHE", parse_CACHE },
763 { "CCA", parse_CCA },
764 { "CCB", parse_CCB },
765 { "CCC", parse_CCC },
766 { "CCD", parse_CCD },
767 { "CCE", parse_CCE },
768 { "CELLSBREAK", parse_CELLSBREAK },
769 { "CMPTRANS", parse_CMPTRANS },
770 { "COMPRESSION", parse_COMPRESSION },
771 { "CTEMPLATE", parse_CTEMPLATE },
772 { "DECIMAL", parse_DECIMAL },
773 { "EPOCH", parse_EPOCH },
774 { "ERRORS", parse_ERRORS },
775 { "FORMAT", parse_FORMAT },
776 { "FUZZBITS", parse_FUZZBITS },
777 { "HEADER", parse_HEADER },
778 { "INCLUDE", parse_INCLUDE },
779 { "JOURNAL", parse_JOURNAL },
780 { "LENGTH", parse_LENGTH },
781 { "LOCALE", parse_LOCALE },
782 { "MESSAGES", parse_MESSAGES },
783 { "MEXPAND", parse_MEXPAND },
784 { "MITERATE", parse_MITERATE },
785 { "MNEST", parse_MNEST },
786 { "MPRINT", parse_MPRINT },
787 { "MXERRS", parse_MXERRS },
788 { "MXLOOPS", parse_MXLOOPS },
789 { "MXWARNS", parse_MXWARNS },
790 { "PRINTBACK", parse_PRINTBACK },
791 { "RESULTS", parse_RESULTS },
792 { "RIB", parse_RIB },
793 { "RRB", parse_RRB },
794 { "SAFER", parse_SAFER },
795 { "SCOMPRESSION", parse_SCOMPRESSION },
796 { "SEED", parse_SEED },
797 { "SMALL", parse_SMALL },
798 { "TNUMBERS", parse_TNUMBERS },
799 { "TVARS", parse_TVARS },
800 { "TLOOK", parse_TLOOK },
801 { "UNDEFINED", parse_UNDEFINED },
802 { "WIB", parse_WIB },
803 { "WRB", parse_WRB },
804 { "WIDTH", parse_WIDTH },
805 { "WORKSPACE", parse_WORKSPACE },
807 enum { N_SETTINGS = sizeof settings / sizeof *settings };
809 for (size_t i = 0; i < N_SETTINGS; i++)
810 if (match_subcommand (lexer, settings[i].name))
811 return settings[i].function (lexer);
813 lex_error (lexer, NULL);
818 cmd_set (struct lexer *lexer, struct dataset *ds UNUSED)
822 lex_match (lexer, T_SLASH);
823 if (lex_token (lexer) == T_ENDCMD)
826 if (!parse_setting (lexer))
834 show_output_routing (enum settings_output_type type)
836 enum settings_output_devices devices;
839 devices = settings_get_output_routing (type);
840 if (devices & SETTINGS_DEVICE_LISTING)
841 s = devices & SETTINGS_DEVICE_TERMINAL ? "BOTH" : "LISTING";
842 else if (devices & SETTINGS_DEVICE_TERMINAL)
851 show_blanks (const struct dataset *ds UNUSED)
853 return (settings_get_blanks () == SYSMIS
855 : xasprintf ("%.*g", DBL_DIG + 1, settings_get_blanks ()));
859 show_cc (enum fmt_type type)
861 return fmt_number_style_to_string (fmt_settings_get_style (
862 settings_get_fmt_settings (), type));
866 show_cca (const struct dataset *ds UNUSED)
868 return show_cc (FMT_CCA);
872 show_ccb (const struct dataset *ds UNUSED)
874 return show_cc (FMT_CCB);
878 show_ccc (const struct dataset *ds UNUSED)
880 return show_cc (FMT_CCC);
884 show_ccd (const struct dataset *ds UNUSED)
886 return show_cc (FMT_CCD);
890 show_cce (const struct dataset *ds UNUSED)
892 return show_cc (FMT_CCE);
896 show_decimals (const struct dataset *ds UNUSED)
898 return xasprintf ("`%c'", settings_get_fmt_settings ()->decimal);
902 show_errors (const struct dataset *ds UNUSED)
904 return show_output_routing (SETTINGS_OUTPUT_ERROR);
908 show_format (const struct dataset *ds UNUSED)
910 char str[FMT_STRING_LEN_MAX + 1];
911 return xstrdup (fmt_to_string (settings_get_format (), str));
915 show_fuzzbits (const struct dataset *ds UNUSED)
917 return xasprintf ("%d", settings_get_fuzzbits ());
921 show_journal (const struct dataset *ds UNUSED)
923 return (journal_is_enabled ()
924 ? xasprintf ("\"%s\"", journal_get_file_name ())
925 : xstrdup ("disabled"));
929 show_length (const struct dataset *ds UNUSED)
931 return xasprintf ("%d", settings_get_viewlength ());
935 show_locale (const struct dataset *ds UNUSED)
937 return xstrdup (get_default_encoding ());
941 show_messages (const struct dataset *ds UNUSED)
943 return show_output_routing (SETTINGS_OUTPUT_NOTE);
947 show_printback (const struct dataset *ds UNUSED)
949 return show_output_routing (SETTINGS_OUTPUT_SYNTAX);
953 show_results (const struct dataset *ds UNUSED)
955 return show_output_routing (SETTINGS_OUTPUT_RESULT);
959 show_mxerrs (const struct dataset *ds UNUSED)
961 return xasprintf ("%d", settings_get_max_messages (MSG_S_ERROR));
965 show_mxloops (const struct dataset *ds UNUSED)
967 return xasprintf ("%d", settings_get_mxloops ());
971 show_mxwarns (const struct dataset *ds UNUSED)
973 return xasprintf ("%d", settings_get_max_messages (MSG_S_WARNING));
976 /* Returns a name for the given INTEGER_FORMAT value. */
978 show_integer_format (enum integer_format integer_format)
980 return xasprintf ("%s (%s)",
981 (integer_format == INTEGER_MSB_FIRST ? "MSBFIRST"
982 : integer_format == INTEGER_LSB_FIRST ? "LSBFIRST"
984 integer_format == INTEGER_NATIVE ? "NATIVE" : "nonnative");
987 /* Returns a name for the given FLOAT_FORMAT value. */
989 show_float_format (enum float_format float_format)
991 const char *format_name = "";
993 switch (float_format)
995 case FLOAT_IEEE_SINGLE_LE:
996 format_name = _("ISL (32-bit IEEE 754 single, little-endian)");
998 case FLOAT_IEEE_SINGLE_BE:
999 format_name = _("ISB (32-bit IEEE 754 single, big-endian)");
1001 case FLOAT_IEEE_DOUBLE_LE:
1002 format_name = _("IDL (64-bit IEEE 754 double, little-endian)");
1004 case FLOAT_IEEE_DOUBLE_BE:
1005 format_name = _("IDB (64-bit IEEE 754 double, big-endian)");
1009 format_name = _("VF (32-bit VAX F, VAX-endian)");
1012 format_name = _("VD (64-bit VAX D, VAX-endian)");
1015 format_name = _("VG (64-bit VAX G, VAX-endian)");
1019 format_name = _("ZS (32-bit IBM Z hexadecimal short, big-endian)");
1022 format_name = _("ZL (64-bit IBM Z hexadecimal long, big-endian)");
1030 return xasprintf ("%s (%s)", format_name,
1031 (float_format == FLOAT_NATIVE_DOUBLE
1032 ? "NATIVE" : "nonnative"));
1036 show_rib (const struct dataset *ds UNUSED)
1038 return show_integer_format (settings_get_input_integer_format ());
1042 show_rrb (const struct dataset *ds UNUSED)
1044 return show_float_format (settings_get_input_float_format ());
1048 show_scompression (const struct dataset *ds UNUSED)
1050 return xstrdup (settings_get_scompression () ? "ON" : "OFF");
1054 show_undefined (const struct dataset *ds UNUSED)
1056 return xstrdup (settings_get_undefined () ? "WARN" : "NOWARN");
1060 show_weight (const struct dataset *ds)
1062 const struct variable *var = dict_get_weight (dataset_dict (ds));
1063 return xstrdup (var != NULL ? var_get_name (var) : "OFF");
1067 show_wib (const struct dataset *ds UNUSED)
1069 return show_integer_format (settings_get_output_integer_format ());
1073 show_wrb (const struct dataset *ds UNUSED)
1075 return show_float_format (settings_get_output_float_format ());
1079 show_width (const struct dataset *ds UNUSED)
1081 return xasprintf ("%d", settings_get_viewwidth ());
1085 show_workspace (const struct dataset *ds UNUSED)
1087 size_t ws = settings_get_workspace () / 1024L;
1088 return xasprintf ("%zu", ws);
1092 show_current_directory (const struct dataset *ds UNUSED)
1101 buf = xrealloc (buf, len);
1103 while (NULL == (wd = getcwd (buf, len)));
1109 show_tempdir (const struct dataset *ds UNUSED)
1111 return strdup (temp_dir_name ());
1115 show_version (const struct dataset *ds UNUSED)
1117 return strdup (announced_version);
1121 show_system (const struct dataset *ds UNUSED)
1123 return strdup (host_system);
1127 show_n (const struct dataset *ds)
1132 const struct casereader *reader = dataset_source (ds);
1135 return strdup (_("Unknown"));
1137 n = casereader_count_cases (reader);
1139 return asnprintf (NULL, &l, "%ld", n);
1146 char *(*function) (const struct dataset *);
1149 const struct show_sbc show_table[] =
1151 {"BLANKS", show_blanks},
1157 {"DECIMALS", show_decimals},
1158 {"DIRECTORY", show_current_directory},
1159 {"ENVIRONMENT", show_system},
1160 {"ERRORS", show_errors},
1161 {"FORMAT", show_format},
1162 {"FUZZBITS", show_fuzzbits},
1163 {"JOURNAL", show_journal},
1164 {"LENGTH", show_length},
1165 {"LOCALE", show_locale},
1166 {"MESSAGES", show_messages},
1167 {"MXERRS", show_mxerrs},
1168 {"MXLOOPS", show_mxloops},
1169 {"MXWARNS", show_mxwarns},
1171 {"PRINTBACk", show_printback},
1172 {"RESULTS", show_results},
1175 {"SCOMPRESSION", show_scompression},
1176 {"TEMPDIR", show_tempdir},
1177 {"UNDEFINED", show_undefined},
1178 {"VERSION", show_version},
1179 {"WEIGHT", show_weight},
1182 {"WIDTH", show_width},
1183 {"WORKSPACE", show_workspace},
1187 do_show (const struct dataset *ds, const struct show_sbc *sbc)
1189 char *value = sbc->function (ds);
1190 msg (SN, _("%s is %s."), sbc->name, value);
1195 show_all (const struct dataset *ds)
1199 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1200 do_show (ds, &show_table[i]);
1204 show_all_cc (const struct dataset *ds)
1208 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1210 const struct show_sbc *sbc = &show_table[i];
1211 if (!strncmp (sbc->name, "CC", 2))
1217 show_warranty (const struct dataset *ds UNUSED)
1219 fputs (lack_of_warranty, stdout);
1223 show_copying (const struct dataset *ds UNUSED)
1225 fputs (copyleft, stdout);
1230 cmd_show (struct lexer *lexer, struct dataset *ds)
1232 if (lex_token (lexer) == T_ENDCMD)
1240 if (lex_match (lexer, T_ALL))
1242 else if (lex_match_id (lexer, "CC"))
1244 else if (lex_match_id (lexer, "WARRANTY"))
1246 else if (lex_match_id (lexer, "COPYING") || lex_match_id (lexer, "LICENSE"))
1248 else if (lex_token (lexer) == T_ID)
1252 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1254 const struct show_sbc *sbc = &show_table[i];
1255 if (lex_match_id (lexer, sbc->name))
1261 lex_error (lexer, NULL);
1268 lex_error (lexer, NULL);
1272 lex_match (lexer, T_SLASH);
1274 while (lex_token (lexer) != T_ENDCMD);
1279 #define MAX_SAVED_SETTINGS 5
1281 static struct settings *saved_settings[MAX_SAVED_SETTINGS];
1282 static int n_saved_settings;
1285 cmd_preserve (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
1287 if (n_saved_settings < MAX_SAVED_SETTINGS)
1289 saved_settings[n_saved_settings++] = settings_get ();
1294 msg (SE, _("Too many %s commands without a %s: at most "
1295 "%d levels of saved settings are allowed."),
1296 "PRESERVE", "RESTORE",
1297 MAX_SAVED_SETTINGS);
1298 return CMD_CASCADING_FAILURE;
1303 cmd_restore (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
1305 if (n_saved_settings > 0)
1307 struct settings *s = saved_settings[--n_saved_settings];
1309 settings_destroy (s);
1314 msg (SE, _("%s without matching %s."), "RESTORE", "PRESERVE");