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/compiler.h"
41 #include "libpspp/copyleft.h"
42 #include "libpspp/temp-file.h"
43 #include "libpspp/version.h"
44 #include "libpspp/float-format.h"
45 #include "libpspp/i18n.h"
46 #include "libpspp/integer-format.h"
47 #include "libpspp/message.h"
48 #include "math/random.h"
49 #include "output/driver.h"
50 #include "output/journal.h"
55 #else /* !HAVE_TERMCAP_H */
56 int tgetent (char *, const char *);
57 int tgetnum (const char *);
58 #endif /* !HAVE_TERMCAP_H */
59 #endif /* !HAVE_LIBTERMCAP */
64 #define _(msgid) gettext (msgid)
71 case=size:upper/uplow;
77 compression=compress:on/off;
79 decimal=dec:dot/comma;
84 headers=headers:no/yes/blank;
92 lowres=lores:auto/on/off;
94 menus=menus:standard/extended;
106 rib=rib:msbfirst/lsbfirst/vax/native;
107 rrb=rrb:native/isl/isb/idl/idb/vf/vd/vg/zs/zl;
109 scompression=scompress:on/off;
116 undefined=undef:warn/nowarn;
117 wib=wib:msbfirst/lsbfirst/vax/native;
118 wrb=wrb:native/isl/isb/idl/idb/vf/vd/vg/zs/zl;
130 static enum integer_format stc_to_integer_format (int stc);
131 static enum float_format stc_to_float_format (int stc);
134 cmd_set (struct lexer *lexer, struct dataset *ds)
138 if (!parse_set (lexer, ds, &cmd, NULL))
145 settings_set_cc ( cmd.s_cca, FMT_CCA);
147 settings_set_cc ( cmd.s_ccb, FMT_CCB);
149 settings_set_cc ( cmd.s_ccc, FMT_CCC);
151 settings_set_cc ( cmd.s_ccd, FMT_CCD);
153 settings_set_cc ( cmd.s_cce, FMT_CCE);
156 settings_set_decimal_char (cmd.dec == STC_DOT ? '.' : ',');
157 if (cmd.sbc_fuzzbits)
159 int fuzzbits = cmd.n_fuzzbits[0];
160 if (fuzzbits >= 0 && fuzzbits <= 20)
161 settings_set_fuzzbits (fuzzbits);
163 msg (SE, _("%s must be between 0 and 20."), "FUZZBITS");
167 settings_set_include (cmd.inc == STC_ON);
170 if (cmd.n_mxerrs[0] >= 1)
171 settings_set_max_messages (MSG_S_ERROR, cmd.n_mxerrs[0]);
173 msg (SE, _("%s must be at least 1."), "MXERRS");
177 if (cmd.n_mxloops[0] >= 1)
178 settings_set_mxloops (cmd.n_mxloops[0]);
180 msg (SE, _("%s must be at least 1."), "MXLOOPS");
184 if (cmd.n_mxwarns[0] >= 0)
185 settings_set_max_messages (MSG_S_WARNING, cmd.n_mxwarns[0]);
187 msg (SE, _("%s must not be negative."), "MXWARNS");
190 settings_set_input_integer_format (stc_to_integer_format (cmd.rib));
192 settings_set_input_float_format (stc_to_float_format (cmd.rrb));
194 settings_set_safer_mode ();
195 if (cmd.sbc_scompression)
196 settings_set_scompression (cmd.scompress == STC_ON);
197 if (cmd.sbc_undefined)
198 settings_set_undefined (cmd.undef == STC_WARN);
200 settings_set_output_integer_format (stc_to_integer_format (cmd.wib));
202 settings_set_output_float_format (stc_to_float_format (cmd.wrb));
203 if (cmd.sbc_workspace)
205 if ( cmd.n_workspace[0] < 1024 && ! settings_get_testing_mode ())
206 msg (SE, _("%s must be at least 1MB"), "WORKSPACE");
207 else if (cmd.n_workspace[0] <= 0)
208 msg (SE, _("%s must be positive"), "WORKSPACE");
210 settings_set_workspace (cmd.n_workspace[0] * 1024L);
214 msg (SW, _("%s is obsolete."), "BLOCK");
215 if (cmd.sbc_boxstring)
216 msg (SW, _("%s is obsolete."), "BOXSTRING");
218 msg (SW, _("%s is obsolete."), "CPI");
219 if (cmd.sbc_histogram)
220 msg (SW, _("%s is obsolete."), "HISTOGRAM");
222 msg (SW, _("%s is obsolete."), "LPI");
224 msg (SW, _("%s is obsolete."), "MENUS");
226 msg (SW, _("%s is obsolete."), "XSORT");
227 if (cmd.sbc_mxmemory)
228 msg (SE, _("%s is obsolete."), "MXMEMORY");
229 if (cmd.sbc_scripttab)
230 msg (SE, _("%s is obsolete."), "SCRIPTTAB");
232 msg (SW, _("%s is obsolete."), "TBFONTS");
233 if (cmd.sbc_tb1 && cmd.s_tb1)
234 msg (SW, _("%s is obsolete."), "TB1");
237 msg (SW, _("%s is not yet implemented."), "CASE");
239 if (cmd.sbc_compression)
240 msg (SW, _("Active file compression is not implemented."));
247 /* Returns the integer_format value corresponding to STC,
248 which should be the value of cmd.rib or cmd.wib. */
249 static enum integer_format
250 stc_to_integer_format (int stc)
252 return (stc == STC_MSBFIRST ? INTEGER_MSB_FIRST
253 : stc == STC_LSBFIRST ? INTEGER_LSB_FIRST
254 : stc == STC_VAX ? INTEGER_VAX
258 /* Returns the float_format value corresponding to STC,
259 which should be the value of cmd.rrb or cmd.wrb. */
260 static enum float_format
261 stc_to_float_format (int stc)
266 return FLOAT_NATIVE_DOUBLE;
269 return FLOAT_IEEE_SINGLE_LE;
271 return FLOAT_IEEE_SINGLE_BE;
273 return FLOAT_IEEE_DOUBLE_LE;
275 return FLOAT_IEEE_DOUBLE_BE;
285 return FLOAT_Z_SHORT;
294 set_output_routing (struct lexer *lexer, enum settings_output_type type)
296 enum settings_output_devices devices;
298 lex_match (lexer, T_EQUALS);
299 if (lex_match_id (lexer, "ON") || lex_match_id (lexer, "BOTH"))
300 devices = SETTINGS_DEVICE_LISTING | SETTINGS_DEVICE_TERMINAL;
301 else if (lex_match_id (lexer, "TERMINAL"))
302 devices = SETTINGS_DEVICE_TERMINAL;
303 else if (lex_match_id (lexer, "LISTING"))
304 devices = SETTINGS_DEVICE_LISTING;
305 else if (lex_match_id (lexer, "OFF") || lex_match_id (lexer, "NONE"))
309 lex_error (lexer, NULL);
313 settings_set_output_routing (type, devices);
318 /* Parses the BLANKS subcommand, which controls the value that
319 completely blank fields in numeric data imply. X, Wnd: Syntax is
320 SYSMIS or a numeric value. */
322 stc_custom_blanks (struct lexer *lexer,
323 struct dataset *ds UNUSED,
324 struct cmd_set *cmd UNUSED, void *aux UNUSED)
326 lex_match (lexer, T_EQUALS);
327 if (lex_match_id (lexer, "SYSMIS"))
330 settings_set_blanks (SYSMIS);
334 if (!lex_force_num (lexer))
336 settings_set_blanks (lex_number (lexer));
343 stc_custom_tnumbers (struct lexer *lexer,
344 struct dataset *ds UNUSED,
345 struct cmd_set *cmd UNUSED, void *aux UNUSED)
347 lex_match (lexer, T_EQUALS);
349 if (lex_match_id (lexer, "VALUES"))
351 settings_set_value_style (SETTINGS_VAL_STYLE_VALUES);
353 else if (lex_match_id (lexer, "LABELS"))
355 settings_set_value_style (SETTINGS_VAL_STYLE_LABELS);
357 else if (lex_match_id (lexer, "BOTH"))
359 settings_set_value_style (SETTINGS_VAL_STYLE_BOTH);
363 lex_error_expecting (lexer, "VALUES", "LABELS", "BOTH", NULL_SENTINEL);
372 stc_custom_tvars (struct lexer *lexer,
373 struct dataset *ds UNUSED,
374 struct cmd_set *cmd UNUSED, void *aux UNUSED)
376 lex_match (lexer, T_EQUALS);
378 if (lex_match_id (lexer, "NAMES"))
380 settings_set_var_style (SETTINGS_VAR_STYLE_NAMES);
382 else if (lex_match_id (lexer, "LABELS"))
384 settings_set_var_style (SETTINGS_VAR_STYLE_LABELS);
386 else if (lex_match_id (lexer, "BOTH"))
388 settings_set_var_style (SETTINGS_VAR_STYLE_BOTH);
392 lex_error_expecting (lexer, "NAMES", "LABELS", "BOTH", NULL_SENTINEL);
400 /* Parses the EPOCH subcommand, which controls the epoch used for
401 parsing 2-digit years. */
403 stc_custom_epoch (struct lexer *lexer,
404 struct dataset *ds UNUSED,
405 struct cmd_set *cmd UNUSED, void *aux UNUSED)
407 lex_match (lexer, T_EQUALS);
408 if (lex_match_id (lexer, "AUTOMATIC"))
409 settings_set_epoch (-1);
410 else if (lex_is_integer (lexer))
412 int new_epoch = lex_integer (lexer);
414 if (new_epoch < 1500)
416 msg (SE, _("%s must be 1500 or later."), "EPOCH");
419 settings_set_epoch (new_epoch);
423 lex_error (lexer, _("expecting %s or year"), "AUTOMATIC");
431 stc_custom_errors (struct lexer *lexer, struct dataset *ds UNUSED,
432 struct cmd_set *cmd UNUSED, void *aux UNUSED)
434 return set_output_routing (lexer, SETTINGS_OUTPUT_ERROR);
438 stc_custom_length (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
442 lex_match (lexer, T_EQUALS);
443 if (lex_match_id (lexer, "NONE"))
447 if (!lex_force_int (lexer))
449 if (lex_integer (lexer) < 1)
451 msg (SE, _("%s must be at least %d."), "LENGTH", 1);
454 page_length = lex_integer (lexer);
458 if (page_length != -1)
459 settings_set_viewlength (page_length);
465 stc_custom_locale (struct lexer *lexer, struct dataset *ds UNUSED,
466 struct cmd_set *cmd UNUSED, void *aux UNUSED)
470 lex_match (lexer, T_EQUALS);
472 if ( !lex_force_string (lexer))
475 s = lex_tokcstr (lexer);
477 /* First try this string as an encoding name */
478 if ( valid_encoding (s))
479 set_default_encoding (s);
481 /* Now try as a locale name (or alias) */
482 else if (set_encoding_from_locale (s))
487 msg (ME, _("%s is not a recognized encoding or locale name"), s);
497 stc_custom_messages (struct lexer *lexer, struct dataset *ds UNUSED,
498 struct cmd_set *cmd UNUSED, void *aux UNUSED)
500 return set_output_routing (lexer, SETTINGS_OUTPUT_NOTE);
504 stc_custom_printback (struct lexer *lexer, struct dataset *ds UNUSED,
505 struct cmd_set *cmd UNUSED, void *aux UNUSED)
507 return set_output_routing (lexer, SETTINGS_OUTPUT_SYNTAX);
511 stc_custom_results (struct lexer *lexer, struct dataset *ds UNUSED,
512 struct cmd_set *cmd UNUSED, void *aux UNUSED)
514 return set_output_routing (lexer, SETTINGS_OUTPUT_RESULT);
518 stc_custom_seed (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
520 lex_match (lexer, T_EQUALS);
521 if (lex_match_id (lexer, "RANDOM"))
525 if (!lex_force_num (lexer))
527 set_rng (lex_number (lexer));
535 stc_custom_width (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
537 lex_match (lexer, T_EQUALS);
538 if (lex_match_id (lexer, "NARROW"))
539 settings_set_viewwidth (79);
540 else if (lex_match_id (lexer, "WIDE"))
541 settings_set_viewwidth (131);
544 if (!lex_force_int (lexer))
546 if (lex_integer (lexer) < 40)
548 msg (SE, _("%s must be at least %d."), "WIDTH", 40);
551 settings_set_viewwidth (lex_integer (lexer));
558 /* Parses FORMAT subcommand, which consists of a numeric format
561 stc_custom_format (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
565 lex_match (lexer, T_EQUALS);
566 if (!parse_format_specifier (lexer, &fmt))
569 if (!fmt_check_output (&fmt))
572 if (fmt_is_string (fmt.type))
574 char str[FMT_STRING_LEN_MAX + 1];
575 msg (SE, _("%s requires numeric output format as an argument. "
576 "Specified format %s is of type string."),
578 fmt_to_string (&fmt, str));
582 settings_set_format (&fmt);
587 stc_custom_journal (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
589 lex_match (lexer, T_EQUALS);
590 if (lex_match_id (lexer, "ON") || lex_match_id (lexer, "YES"))
592 else if (lex_match_id (lexer, "OFF") || lex_match_id (lexer, "NO"))
594 else if (lex_is_string (lexer) || lex_token (lexer) == T_ID)
596 char *filename = utf8_to_filename (lex_tokcstr (lexer));
597 journal_set_file_name (filename);
604 lex_error (lexer, NULL);
611 stc_custom_log (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
613 return stc_custom_journal (lexer, ds, cmd, aux);
617 show_output_routing (enum settings_output_type type)
619 enum settings_output_devices devices;
622 devices = settings_get_output_routing (type);
623 if (devices & SETTINGS_DEVICE_LISTING)
624 s = devices & SETTINGS_DEVICE_TERMINAL ? "BOTH" : "LISTING";
625 else if (devices & SETTINGS_DEVICE_TERMINAL)
634 show_blanks (const struct dataset *ds UNUSED)
636 return (settings_get_blanks () == SYSMIS
638 : xasprintf ("%.*g", DBL_DIG + 1, settings_get_blanks ()));
642 format_cc (struct string *out, const char *in, char grouping)
647 if (c == grouping || c == '\'')
648 ds_put_byte (out, '\'');
650 ds_put_byte (out, '"');
651 ds_put_byte (out, c);
656 show_cc (enum fmt_type type)
658 const struct fmt_number_style *cc = settings_get_style (type);
661 ds_init_empty (&out);
662 format_cc (&out, cc->neg_prefix.s, cc->grouping);
663 ds_put_byte (&out, cc->grouping);
664 format_cc (&out, cc->prefix.s, cc->grouping);
665 ds_put_byte (&out, cc->grouping);
666 format_cc (&out, cc->suffix.s, cc->grouping);
667 ds_put_byte (&out, cc->grouping);
668 format_cc (&out, cc->neg_suffix.s, cc->grouping);
670 return ds_cstr (&out);
674 show_cca (const struct dataset *ds UNUSED)
676 return show_cc (FMT_CCA);
680 show_ccb (const struct dataset *ds UNUSED)
682 return show_cc (FMT_CCB);
686 show_ccc (const struct dataset *ds UNUSED)
688 return show_cc (FMT_CCC);
692 show_ccd (const struct dataset *ds UNUSED)
694 return show_cc (FMT_CCD);
698 show_cce (const struct dataset *ds UNUSED)
700 return show_cc (FMT_CCE);
704 show_decimals (const struct dataset *ds UNUSED)
706 return xasprintf ("`%c'", settings_get_decimal_char (FMT_F));
710 show_errors (const struct dataset *ds UNUSED)
712 return show_output_routing (SETTINGS_OUTPUT_ERROR);
716 show_format (const struct dataset *ds UNUSED)
718 char str[FMT_STRING_LEN_MAX + 1];
719 return xstrdup (fmt_to_string (settings_get_format (), str));
723 show_fuzzbits (const struct dataset *ds UNUSED)
725 return xasprintf ("%d", settings_get_fuzzbits ());
729 show_journal (const struct dataset *ds UNUSED)
731 return (journal_is_enabled ()
732 ? xasprintf ("\"%s\"", journal_get_file_name ())
733 : xstrdup ("disabled"));
737 show_length (const struct dataset *ds UNUSED)
739 return xasprintf ("%d", settings_get_viewlength ());
743 show_locale (const struct dataset *ds UNUSED)
745 return xstrdup (get_default_encoding ());
749 show_messages (const struct dataset *ds UNUSED)
751 return show_output_routing (SETTINGS_OUTPUT_NOTE);
755 show_printback (const struct dataset *ds UNUSED)
757 return show_output_routing (SETTINGS_OUTPUT_SYNTAX);
761 show_results (const struct dataset *ds UNUSED)
763 return show_output_routing (SETTINGS_OUTPUT_RESULT);
767 show_mxerrs (const struct dataset *ds UNUSED)
769 return xasprintf ("%d", settings_get_max_messages (MSG_S_ERROR));
773 show_mxloops (const struct dataset *ds UNUSED)
775 return xasprintf ("%d", settings_get_mxloops ());
779 show_mxwarns (const struct dataset *ds UNUSED)
781 return xasprintf ("%d", settings_get_max_messages (MSG_S_WARNING));
784 /* Returns a name for the given INTEGER_FORMAT value. */
786 show_integer_format (enum integer_format integer_format)
788 return xasprintf ("%s (%s)",
789 (integer_format == INTEGER_MSB_FIRST ? "MSBFIRST"
790 : integer_format == INTEGER_LSB_FIRST ? "LSBFIRST"
792 integer_format == INTEGER_NATIVE ? "NATIVE" : "nonnative");
795 /* Returns a name for the given FLOAT_FORMAT value. */
797 show_float_format (enum float_format float_format)
799 const char *format_name = "";
801 switch (float_format)
803 case FLOAT_IEEE_SINGLE_LE:
804 format_name = _("ISL (32-bit IEEE 754 single, little-endian)");
806 case FLOAT_IEEE_SINGLE_BE:
807 format_name = _("ISB (32-bit IEEE 754 single, big-endian)");
809 case FLOAT_IEEE_DOUBLE_LE:
810 format_name = _("IDL (64-bit IEEE 754 double, little-endian)");
812 case FLOAT_IEEE_DOUBLE_BE:
813 format_name = _("IDB (64-bit IEEE 754 double, big-endian)");
817 format_name = _("VF (32-bit VAX F, VAX-endian)");
820 format_name = _("VD (64-bit VAX D, VAX-endian)");
823 format_name = _("VG (64-bit VAX G, VAX-endian)");
827 format_name = _("ZS (32-bit IBM Z hexadecimal short, big-endian)");
830 format_name = _("ZL (64-bit IBM Z hexadecimal long, big-endian)");
838 return xasprintf ("%s (%s)", format_name,
839 (float_format == FLOAT_NATIVE_DOUBLE
840 ? "NATIVE" : "nonnative"));
844 show_rib (const struct dataset *ds UNUSED)
846 return show_integer_format (settings_get_input_integer_format ());
850 show_rrb (const struct dataset *ds UNUSED)
852 return show_float_format (settings_get_input_float_format ());
856 show_scompression (const struct dataset *ds UNUSED)
858 return xstrdup (settings_get_scompression () ? "ON" : "OFF");
862 show_undefined (const struct dataset *ds UNUSED)
864 return xstrdup (settings_get_undefined () ? "WARN" : "NOWARN");
868 show_weight (const struct dataset *ds)
870 const struct variable *var = dict_get_weight (dataset_dict (ds));
871 return xstrdup (var != NULL ? var_get_name (var) : "OFF");
875 show_wib (const struct dataset *ds UNUSED)
877 return show_integer_format (settings_get_output_integer_format ());
881 show_wrb (const struct dataset *ds UNUSED)
883 return show_float_format (settings_get_output_float_format ());
887 show_width (const struct dataset *ds UNUSED)
889 return xasprintf ("%d", settings_get_viewwidth ());
893 show_workspace (const struct dataset *ds UNUSED)
895 size_t ws = settings_get_workspace () / 1024L;
896 return xasprintf ("%zu", ws);
900 show_current_directory (const struct dataset *ds UNUSED)
909 buf = xrealloc (buf, len);
911 while (NULL == (wd = getcwd (buf, len)));
917 show_tempdir (const struct dataset *ds UNUSED)
919 return strdup (temp_dir_name ());
923 show_version (const struct dataset *ds UNUSED)
925 return strdup (version);
929 show_system (const struct dataset *ds UNUSED)
931 return strdup (host_system);
935 show_n (const struct dataset *ds)
940 const struct casereader *reader = dataset_source (ds);
943 return strdup (_("Unknown"));
945 n = casereader_count_cases (reader);
947 return asnprintf (NULL, &l, "%ld", n);
954 char *(*function) (const struct dataset *);
957 const struct show_sbc show_table[] =
959 {"BLANKS", show_blanks},
965 {"DECIMALS", show_decimals},
966 {"DIRECTORY", show_current_directory},
967 {"ENVIRONMENT", show_system},
968 {"ERRORS", show_errors},
969 {"FORMAT", show_format},
970 {"FUZZBITS", show_fuzzbits},
971 {"JOURNAL", show_journal},
972 {"LENGTH", show_length},
973 {"LOCALE", show_locale},
974 {"MESSAGES", show_messages},
975 {"MXERRS", show_mxerrs},
976 {"MXLOOPS", show_mxloops},
977 {"MXWARNS", show_mxwarns},
979 {"PRINTBACk", show_printback},
980 {"RESULTS", show_results},
983 {"SCOMPRESSION", show_scompression},
984 {"TEMPDIR", show_tempdir},
985 {"UNDEFINED", show_undefined},
986 {"VERSION", show_version},
987 {"WEIGHT", show_weight},
990 {"WIDTH", show_width},
991 {"WORKSPACE", show_workspace},
995 do_show (const struct dataset *ds, const struct show_sbc *sbc)
997 char *value = sbc->function (ds);
998 msg (SN, _("%s is %s."), sbc->name, value);
1003 show_all (const struct dataset *ds)
1007 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1008 do_show (ds, &show_table[i]);
1012 show_all_cc (const struct dataset *ds)
1016 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1018 const struct show_sbc *sbc = &show_table[i];
1019 if (!strncmp (sbc->name, "CC", 2))
1025 show_warranty (const struct dataset *ds UNUSED)
1027 fputs (lack_of_warranty, stdout);
1031 show_copying (const struct dataset *ds UNUSED)
1033 fputs (copyleft, stdout);
1038 cmd_show (struct lexer *lexer, struct dataset *ds)
1040 if (lex_token (lexer) == T_ENDCMD)
1048 if (lex_match (lexer, T_ALL))
1050 else if (lex_match_id (lexer, "CC"))
1052 else if (lex_match_id (lexer, "WARRANTY"))
1054 else if (lex_match_id (lexer, "COPYING") || lex_match_id (lexer, "LICENSE"))
1056 else if (lex_token (lexer) == T_ID)
1060 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1062 const struct show_sbc *sbc = &show_table[i];
1063 if (lex_match_id (lexer, sbc->name))
1069 lex_error (lexer, NULL);
1076 lex_error (lexer, NULL);
1080 lex_match (lexer, T_SLASH);
1082 while (lex_token (lexer) != T_ENDCMD);
1087 #define MAX_SAVED_SETTINGS 5
1089 static struct settings *saved_settings[MAX_SAVED_SETTINGS];
1090 static int n_saved_settings;
1093 cmd_preserve (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
1095 if (n_saved_settings < MAX_SAVED_SETTINGS)
1097 saved_settings[n_saved_settings++] = settings_get ();
1102 msg (SE, _("Too many %s commands without a %s: at most "
1103 "%d levels of saved settings are allowed."),
1104 "PRESERVE", "RESTORE",
1105 MAX_SAVED_SETTINGS);
1106 return CMD_CASCADING_FAILURE;
1111 cmd_restore (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
1113 if (n_saved_settings > 0)
1115 struct settings *s = saved_settings[--n_saved_settings];
1117 settings_destroy (s);
1122 msg (SE, _("%s without matching %s."), "RESTORE", "PRESERVE");