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"
51 #include "output/pivot-table.h"
56 #else /* !HAVE_TERMCAP_H */
57 int tgetent (char *, const char *);
58 int tgetnum (const char *);
59 #endif /* !HAVE_TERMCAP_H */
60 #endif /* !HAVE_LIBTERMCAP */
65 #define _(msgid) gettext (msgid)
72 case=size:upper/uplow;
78 compression=compress:on/off;
80 decimal=dec:dot/comma;
85 headers=headers:no/yes/blank;
93 lowres=lores:auto/on/off;
95 menus=menus:standard/extended;
100 mprint=mprint:on/off;
107 rib=rib:msbfirst/lsbfirst/vax/native;
108 rrb=rrb:native/isl/isb/idl/idb/vf/vd/vg/zs/zl;
110 scompression=scompress:on/off;
118 undefined=undef:warn/nowarn;
119 wib=wib:msbfirst/lsbfirst/vax/native;
120 wrb=wrb:native/isl/isb/idl/idb/vf/vd/vg/zs/zl;
132 static enum integer_format stc_to_integer_format (int stc);
133 static enum float_format stc_to_float_format (int stc);
136 cmd_set (struct lexer *lexer, struct dataset *ds)
140 if (!parse_set (lexer, ds, &cmd, NULL))
146 settings_set_cc ( cmd.s_cca, FMT_CCA);
148 settings_set_cc ( cmd.s_ccb, FMT_CCB);
150 settings_set_cc ( cmd.s_ccc, FMT_CCC);
152 settings_set_cc ( cmd.s_ccd, FMT_CCD);
154 settings_set_cc ( cmd.s_cce, FMT_CCE);
157 settings_set_decimal_char (cmd.dec == STC_DOT ? '.' : ',');
158 if (cmd.sbc_fuzzbits)
160 int fuzzbits = cmd.n_fuzzbits[0];
161 if (fuzzbits >= 0 && fuzzbits <= 20)
162 settings_set_fuzzbits (fuzzbits);
164 msg (SE, _("%s must be between 0 and 20."), "FUZZBITS");
168 settings_set_include (cmd.inc == STC_ON);
171 if (cmd.n_mxerrs[0] >= 1)
172 settings_set_max_messages (MSG_S_ERROR, cmd.n_mxerrs[0]);
174 msg (SE, _("%s must be at least 1."), "MXERRS");
178 if (cmd.n_mxloops[0] >= 1)
179 settings_set_mxloops (cmd.n_mxloops[0]);
181 msg (SE, _("%s must be at least 1."), "MXLOOPS");
185 if (cmd.n_mxwarns[0] >= 0)
186 settings_set_max_messages (MSG_S_WARNING, cmd.n_mxwarns[0]);
188 msg (SE, _("%s must not be negative."), "MXWARNS");
191 settings_set_input_integer_format (stc_to_integer_format (cmd.rib));
193 settings_set_input_float_format (stc_to_float_format (cmd.rrb));
195 settings_set_safer_mode ();
196 if (cmd.sbc_scompression)
197 settings_set_scompression (cmd.scompress == STC_ON);
198 if (cmd.sbc_undefined)
199 settings_set_undefined (cmd.undef == STC_WARN);
201 settings_set_output_integer_format (stc_to_integer_format (cmd.wib));
203 settings_set_output_float_format (stc_to_float_format (cmd.wrb));
204 if (cmd.sbc_workspace)
206 if ( cmd.n_workspace[0] < 1024 && ! settings_get_testing_mode ())
207 msg (SE, _("%s must be at least 1MB"), "WORKSPACE");
208 else if (cmd.n_workspace[0] <= 0)
209 msg (SE, _("%s must be positive"), "WORKSPACE");
211 settings_set_workspace (cmd.n_workspace[0] * 1024L);
215 msg (SW, _("%s is obsolete."), "BLOCK");
216 if (cmd.sbc_boxstring)
217 msg (SW, _("%s is obsolete."), "BOXSTRING");
219 msg (SW, _("%s is obsolete."), "CPI");
220 if (cmd.sbc_histogram)
221 msg (SW, _("%s is obsolete."), "HISTOGRAM");
223 msg (SW, _("%s is obsolete."), "LPI");
225 msg (SW, _("%s is obsolete."), "MENUS");
227 msg (SW, _("%s is obsolete."), "XSORT");
228 if (cmd.sbc_mxmemory)
229 msg (SE, _("%s is obsolete."), "MXMEMORY");
230 if (cmd.sbc_scripttab)
231 msg (SE, _("%s is obsolete."), "SCRIPTTAB");
233 msg (SW, _("%s is obsolete."), "TBFONTS");
234 if (cmd.sbc_tb1 && cmd.s_tb1)
235 msg (SW, _("%s is obsolete."), "TB1");
238 msg (SW, _("%s is not yet implemented."), "CASE");
240 if (cmd.sbc_compression)
241 msg (SW, _("Active file compression is not implemented."));
248 /* Returns the integer_format value corresponding to STC,
249 which should be the value of cmd.rib or cmd.wib. */
250 static enum integer_format
251 stc_to_integer_format (int stc)
253 return (stc == STC_MSBFIRST ? INTEGER_MSB_FIRST
254 : stc == STC_LSBFIRST ? INTEGER_LSB_FIRST
255 : stc == STC_VAX ? INTEGER_VAX
259 /* Returns the float_format value corresponding to STC,
260 which should be the value of cmd.rrb or cmd.wrb. */
261 static enum float_format
262 stc_to_float_format (int stc)
267 return FLOAT_NATIVE_DOUBLE;
270 return FLOAT_IEEE_SINGLE_LE;
272 return FLOAT_IEEE_SINGLE_BE;
274 return FLOAT_IEEE_DOUBLE_LE;
276 return FLOAT_IEEE_DOUBLE_BE;
286 return FLOAT_Z_SHORT;
295 set_output_routing (struct lexer *lexer, enum settings_output_type type)
297 enum settings_output_devices devices;
299 lex_match (lexer, T_EQUALS);
300 if (lex_match_id (lexer, "ON") || lex_match_id (lexer, "BOTH"))
301 devices = SETTINGS_DEVICE_LISTING | SETTINGS_DEVICE_TERMINAL;
302 else if (lex_match_id (lexer, "TERMINAL"))
303 devices = SETTINGS_DEVICE_TERMINAL;
304 else if (lex_match_id (lexer, "LISTING"))
305 devices = SETTINGS_DEVICE_LISTING;
306 else if (lex_match_id (lexer, "OFF") || lex_match_id (lexer, "NONE"))
310 lex_error (lexer, NULL);
314 settings_set_output_routing (type, devices);
319 /* Parses the BLANKS subcommand, which controls the value that
320 completely blank fields in numeric data imply. X, Wnd: Syntax is
321 SYSMIS or a numeric value. */
323 stc_custom_blanks (struct lexer *lexer,
324 struct dataset *ds UNUSED,
325 struct cmd_set *cmd UNUSED, void *aux UNUSED)
327 lex_match (lexer, T_EQUALS);
328 if (lex_match_id (lexer, "SYSMIS"))
331 settings_set_blanks (SYSMIS);
335 if (!lex_force_num (lexer))
337 settings_set_blanks (lex_number (lexer));
344 stc_custom_tnumbers (struct lexer *lexer,
345 struct dataset *ds UNUSED,
346 struct cmd_set *cmd UNUSED, void *aux UNUSED)
348 lex_match (lexer, T_EQUALS);
350 if (lex_match_id (lexer, "VALUES"))
351 settings_set_show_values (SETTINGS_VALUE_SHOW_VALUE);
352 else if (lex_match_id (lexer, "LABELS"))
353 settings_set_show_values (SETTINGS_VALUE_SHOW_LABEL);
354 else if (lex_match_id (lexer, "BOTH"))
355 settings_set_show_values (SETTINGS_VALUE_SHOW_BOTH);
358 lex_error_expecting (lexer, "VALUES", "LABELS", "BOTH");
367 stc_custom_tvars (struct lexer *lexer,
368 struct dataset *ds UNUSED,
369 struct cmd_set *cmd UNUSED, void *aux UNUSED)
371 lex_match (lexer, T_EQUALS);
373 if (lex_match_id (lexer, "NAMES"))
374 settings_set_show_variables (SETTINGS_VALUE_SHOW_VALUE);
375 else if (lex_match_id (lexer, "LABELS"))
376 settings_set_show_variables (SETTINGS_VALUE_SHOW_LABEL);
377 else if (lex_match_id (lexer, "BOTH"))
378 settings_set_show_variables (SETTINGS_VALUE_SHOW_BOTH);
381 lex_error_expecting (lexer, "NAMES", "LABELS", "BOTH");
389 stc_custom_tlook (struct lexer *lexer,
390 struct dataset *ds UNUSED,
391 struct cmd_set *cmd UNUSED, void *aux UNUSED)
393 lex_match (lexer, T_EQUALS);
395 if (lex_match_id (lexer, "NONE"))
396 pivot_table_look_set_default (pivot_table_look_builtin_default ());
397 else if (lex_is_string (lexer))
399 struct pivot_table_look *look;
400 char *error = pivot_table_look_read (lex_tokcstr (lexer), &look);
405 msg (SE, "%s", error);
410 pivot_table_look_set_default (look);
411 pivot_table_look_unref (look);
417 /* Parses the EPOCH subcommand, which controls the epoch used for
418 parsing 2-digit years. */
420 stc_custom_epoch (struct lexer *lexer,
421 struct dataset *ds UNUSED,
422 struct cmd_set *cmd UNUSED, void *aux UNUSED)
424 lex_match (lexer, T_EQUALS);
425 if (lex_match_id (lexer, "AUTOMATIC"))
426 settings_set_epoch (-1);
427 else if (lex_is_integer (lexer))
429 int new_epoch = lex_integer (lexer);
431 if (new_epoch < 1500)
433 msg (SE, _("%s must be 1500 or later."), "EPOCH");
436 settings_set_epoch (new_epoch);
440 lex_error (lexer, _("expecting %s or year"), "AUTOMATIC");
448 stc_custom_errors (struct lexer *lexer, struct dataset *ds UNUSED,
449 struct cmd_set *cmd UNUSED, void *aux UNUSED)
451 return set_output_routing (lexer, SETTINGS_OUTPUT_ERROR);
455 stc_custom_length (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
459 lex_match (lexer, T_EQUALS);
460 if (lex_match_id (lexer, "NONE"))
464 if (!lex_force_int (lexer))
466 if (lex_integer (lexer) < 1)
468 msg (SE, _("%s must be at least %d."), "LENGTH", 1);
471 page_length = lex_integer (lexer);
475 if (page_length != -1)
476 settings_set_viewlength (page_length);
482 stc_custom_locale (struct lexer *lexer, struct dataset *ds UNUSED,
483 struct cmd_set *cmd UNUSED, void *aux UNUSED)
487 lex_match (lexer, T_EQUALS);
489 if ( !lex_force_string (lexer))
492 s = lex_tokcstr (lexer);
494 /* First try this string as an encoding name */
495 if ( valid_encoding (s))
496 set_default_encoding (s);
498 /* Now try as a locale name (or alias) */
499 else if (set_encoding_from_locale (s))
504 msg (ME, _("%s is not a recognized encoding or locale name"), s);
514 stc_custom_messages (struct lexer *lexer, struct dataset *ds UNUSED,
515 struct cmd_set *cmd UNUSED, void *aux UNUSED)
517 return set_output_routing (lexer, SETTINGS_OUTPUT_NOTE);
521 stc_custom_printback (struct lexer *lexer, struct dataset *ds UNUSED,
522 struct cmd_set *cmd UNUSED, void *aux UNUSED)
524 return set_output_routing (lexer, SETTINGS_OUTPUT_SYNTAX);
528 stc_custom_results (struct lexer *lexer, struct dataset *ds UNUSED,
529 struct cmd_set *cmd UNUSED, void *aux UNUSED)
531 return set_output_routing (lexer, SETTINGS_OUTPUT_RESULT);
535 stc_custom_seed (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, "RANDOM"))
542 if (!lex_force_num (lexer))
544 set_rng (lex_number (lexer));
552 stc_custom_width (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
554 lex_match (lexer, T_EQUALS);
555 if (lex_match_id (lexer, "NARROW"))
556 settings_set_viewwidth (79);
557 else if (lex_match_id (lexer, "WIDE"))
558 settings_set_viewwidth (131);
561 if (!lex_force_int (lexer))
563 if (lex_integer (lexer) < 40)
565 msg (SE, _("%s must be at least %d."), "WIDTH", 40);
568 settings_set_viewwidth (lex_integer (lexer));
575 /* Parses FORMAT subcommand, which consists of a numeric format
578 stc_custom_format (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
582 lex_match (lexer, T_EQUALS);
583 if (!parse_format_specifier (lexer, &fmt))
586 if (!fmt_check_output (&fmt))
589 if (fmt_is_string (fmt.type))
591 char str[FMT_STRING_LEN_MAX + 1];
592 msg (SE, _("%s requires numeric output format as an argument. "
593 "Specified format %s is of type string."),
595 fmt_to_string (&fmt, str));
599 settings_set_format (&fmt);
604 stc_custom_journal (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
606 lex_match (lexer, T_EQUALS);
607 if (lex_match_id (lexer, "ON") || lex_match_id (lexer, "YES"))
609 else if (lex_match_id (lexer, "OFF") || lex_match_id (lexer, "NO"))
611 else if (lex_is_string (lexer) || lex_token (lexer) == T_ID)
613 char *filename = utf8_to_filename (lex_tokcstr (lexer));
614 journal_set_file_name (filename);
621 lex_error (lexer, NULL);
628 stc_custom_log (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
630 return stc_custom_journal (lexer, ds, cmd, aux);
634 show_output_routing (enum settings_output_type type)
636 enum settings_output_devices devices;
639 devices = settings_get_output_routing (type);
640 if (devices & SETTINGS_DEVICE_LISTING)
641 s = devices & SETTINGS_DEVICE_TERMINAL ? "BOTH" : "LISTING";
642 else if (devices & SETTINGS_DEVICE_TERMINAL)
651 show_blanks (const struct dataset *ds UNUSED)
653 return (settings_get_blanks () == SYSMIS
655 : xasprintf ("%.*g", DBL_DIG + 1, settings_get_blanks ()));
659 show_cc (enum fmt_type type)
661 return fmt_number_style_to_string (fmt_settings_get_style (
662 settings_get_fmt_settings (), type));
666 show_cca (const struct dataset *ds UNUSED)
668 return show_cc (FMT_CCA);
672 show_ccb (const struct dataset *ds UNUSED)
674 return show_cc (FMT_CCB);
678 show_ccc (const struct dataset *ds UNUSED)
680 return show_cc (FMT_CCC);
684 show_ccd (const struct dataset *ds UNUSED)
686 return show_cc (FMT_CCD);
690 show_cce (const struct dataset *ds UNUSED)
692 return show_cc (FMT_CCE);
696 show_decimals (const struct dataset *ds UNUSED)
698 return xasprintf ("`%c'", settings_get_fmt_settings ()->decimal);
702 show_errors (const struct dataset *ds UNUSED)
704 return show_output_routing (SETTINGS_OUTPUT_ERROR);
708 show_format (const struct dataset *ds UNUSED)
710 char str[FMT_STRING_LEN_MAX + 1];
711 return xstrdup (fmt_to_string (settings_get_format (), str));
715 show_fuzzbits (const struct dataset *ds UNUSED)
717 return xasprintf ("%d", settings_get_fuzzbits ());
721 show_journal (const struct dataset *ds UNUSED)
723 return (journal_is_enabled ()
724 ? xasprintf ("\"%s\"", journal_get_file_name ())
725 : xstrdup ("disabled"));
729 show_length (const struct dataset *ds UNUSED)
731 return xasprintf ("%d", settings_get_viewlength ());
735 show_locale (const struct dataset *ds UNUSED)
737 return xstrdup (get_default_encoding ());
741 show_messages (const struct dataset *ds UNUSED)
743 return show_output_routing (SETTINGS_OUTPUT_NOTE);
747 show_printback (const struct dataset *ds UNUSED)
749 return show_output_routing (SETTINGS_OUTPUT_SYNTAX);
753 show_results (const struct dataset *ds UNUSED)
755 return show_output_routing (SETTINGS_OUTPUT_RESULT);
759 show_mxerrs (const struct dataset *ds UNUSED)
761 return xasprintf ("%d", settings_get_max_messages (MSG_S_ERROR));
765 show_mxloops (const struct dataset *ds UNUSED)
767 return xasprintf ("%d", settings_get_mxloops ());
771 show_mxwarns (const struct dataset *ds UNUSED)
773 return xasprintf ("%d", settings_get_max_messages (MSG_S_WARNING));
776 /* Returns a name for the given INTEGER_FORMAT value. */
778 show_integer_format (enum integer_format integer_format)
780 return xasprintf ("%s (%s)",
781 (integer_format == INTEGER_MSB_FIRST ? "MSBFIRST"
782 : integer_format == INTEGER_LSB_FIRST ? "LSBFIRST"
784 integer_format == INTEGER_NATIVE ? "NATIVE" : "nonnative");
787 /* Returns a name for the given FLOAT_FORMAT value. */
789 show_float_format (enum float_format float_format)
791 const char *format_name = "";
793 switch (float_format)
795 case FLOAT_IEEE_SINGLE_LE:
796 format_name = _("ISL (32-bit IEEE 754 single, little-endian)");
798 case FLOAT_IEEE_SINGLE_BE:
799 format_name = _("ISB (32-bit IEEE 754 single, big-endian)");
801 case FLOAT_IEEE_DOUBLE_LE:
802 format_name = _("IDL (64-bit IEEE 754 double, little-endian)");
804 case FLOAT_IEEE_DOUBLE_BE:
805 format_name = _("IDB (64-bit IEEE 754 double, big-endian)");
809 format_name = _("VF (32-bit VAX F, VAX-endian)");
812 format_name = _("VD (64-bit VAX D, VAX-endian)");
815 format_name = _("VG (64-bit VAX G, VAX-endian)");
819 format_name = _("ZS (32-bit IBM Z hexadecimal short, big-endian)");
822 format_name = _("ZL (64-bit IBM Z hexadecimal long, big-endian)");
830 return xasprintf ("%s (%s)", format_name,
831 (float_format == FLOAT_NATIVE_DOUBLE
832 ? "NATIVE" : "nonnative"));
836 show_rib (const struct dataset *ds UNUSED)
838 return show_integer_format (settings_get_input_integer_format ());
842 show_rrb (const struct dataset *ds UNUSED)
844 return show_float_format (settings_get_input_float_format ());
848 show_scompression (const struct dataset *ds UNUSED)
850 return xstrdup (settings_get_scompression () ? "ON" : "OFF");
854 show_undefined (const struct dataset *ds UNUSED)
856 return xstrdup (settings_get_undefined () ? "WARN" : "NOWARN");
860 show_weight (const struct dataset *ds)
862 const struct variable *var = dict_get_weight (dataset_dict (ds));
863 return xstrdup (var != NULL ? var_get_name (var) : "OFF");
867 show_wib (const struct dataset *ds UNUSED)
869 return show_integer_format (settings_get_output_integer_format ());
873 show_wrb (const struct dataset *ds UNUSED)
875 return show_float_format (settings_get_output_float_format ());
879 show_width (const struct dataset *ds UNUSED)
881 return xasprintf ("%d", settings_get_viewwidth ());
885 show_workspace (const struct dataset *ds UNUSED)
887 size_t ws = settings_get_workspace () / 1024L;
888 return xasprintf ("%zu", ws);
892 show_current_directory (const struct dataset *ds UNUSED)
901 buf = xrealloc (buf, len);
903 while (NULL == (wd = getcwd (buf, len)));
909 show_tempdir (const struct dataset *ds UNUSED)
911 return strdup (temp_dir_name ());
915 show_version (const struct dataset *ds UNUSED)
917 return strdup (announced_version);
921 show_system (const struct dataset *ds UNUSED)
923 return strdup (host_system);
927 show_n (const struct dataset *ds)
932 const struct casereader *reader = dataset_source (ds);
935 return strdup (_("Unknown"));
937 n = casereader_count_cases (reader);
939 return asnprintf (NULL, &l, "%ld", n);
946 char *(*function) (const struct dataset *);
949 const struct show_sbc show_table[] =
951 {"BLANKS", show_blanks},
957 {"DECIMALS", show_decimals},
958 {"DIRECTORY", show_current_directory},
959 {"ENVIRONMENT", show_system},
960 {"ERRORS", show_errors},
961 {"FORMAT", show_format},
962 {"FUZZBITS", show_fuzzbits},
963 {"JOURNAL", show_journal},
964 {"LENGTH", show_length},
965 {"LOCALE", show_locale},
966 {"MESSAGES", show_messages},
967 {"MXERRS", show_mxerrs},
968 {"MXLOOPS", show_mxloops},
969 {"MXWARNS", show_mxwarns},
971 {"PRINTBACk", show_printback},
972 {"RESULTS", show_results},
975 {"SCOMPRESSION", show_scompression},
976 {"TEMPDIR", show_tempdir},
977 {"UNDEFINED", show_undefined},
978 {"VERSION", show_version},
979 {"WEIGHT", show_weight},
982 {"WIDTH", show_width},
983 {"WORKSPACE", show_workspace},
987 do_show (const struct dataset *ds, const struct show_sbc *sbc)
989 char *value = sbc->function (ds);
990 msg (SN, _("%s is %s."), sbc->name, value);
995 show_all (const struct dataset *ds)
999 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1000 do_show (ds, &show_table[i]);
1004 show_all_cc (const struct dataset *ds)
1008 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1010 const struct show_sbc *sbc = &show_table[i];
1011 if (!strncmp (sbc->name, "CC", 2))
1017 show_warranty (const struct dataset *ds UNUSED)
1019 fputs (lack_of_warranty, stdout);
1023 show_copying (const struct dataset *ds UNUSED)
1025 fputs (copyleft, stdout);
1030 cmd_show (struct lexer *lexer, struct dataset *ds)
1032 if (lex_token (lexer) == T_ENDCMD)
1040 if (lex_match (lexer, T_ALL))
1042 else if (lex_match_id (lexer, "CC"))
1044 else if (lex_match_id (lexer, "WARRANTY"))
1046 else if (lex_match_id (lexer, "COPYING") || lex_match_id (lexer, "LICENSE"))
1048 else if (lex_token (lexer) == T_ID)
1052 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1054 const struct show_sbc *sbc = &show_table[i];
1055 if (lex_match_id (lexer, sbc->name))
1061 lex_error (lexer, NULL);
1068 lex_error (lexer, NULL);
1072 lex_match (lexer, T_SLASH);
1074 while (lex_token (lexer) != T_ENDCMD);
1079 #define MAX_SAVED_SETTINGS 5
1081 static struct settings *saved_settings[MAX_SAVED_SETTINGS];
1082 static int n_saved_settings;
1085 cmd_preserve (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
1087 if (n_saved_settings < MAX_SAVED_SETTINGS)
1089 saved_settings[n_saved_settings++] = settings_get ();
1094 msg (SE, _("Too many %s commands without a %s: at most "
1095 "%d levels of saved settings are allowed."),
1096 "PRESERVE", "RESTORE",
1097 MAX_SAVED_SETTINGS);
1098 return CMD_CASCADING_FAILURE;
1103 cmd_restore (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
1105 if (n_saved_settings > 0)
1107 struct settings *s = saved_settings[--n_saved_settings];
1109 settings_destroy (s);
1114 msg (SE, _("%s without matching %s."), "RESTORE", "PRESERVE");