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))
144 settings_set_cc ( cmd.s_cca, FMT_CCA);
146 settings_set_cc ( cmd.s_ccb, FMT_CCB);
148 settings_set_cc ( cmd.s_ccc, FMT_CCC);
150 settings_set_cc ( cmd.s_ccd, FMT_CCD);
152 settings_set_cc ( cmd.s_cce, FMT_CCE);
155 settings_set_decimal_char (cmd.dec == STC_DOT ? '.' : ',');
156 if (cmd.sbc_fuzzbits)
158 int fuzzbits = cmd.n_fuzzbits[0];
159 if (fuzzbits >= 0 && fuzzbits <= 20)
160 settings_set_fuzzbits (fuzzbits);
162 msg (SE, _("%s must be between 0 and 20."), "FUZZBITS");
166 settings_set_include (cmd.inc == STC_ON);
169 if (cmd.n_mxerrs[0] >= 1)
170 settings_set_max_messages (MSG_S_ERROR, cmd.n_mxerrs[0]);
172 msg (SE, _("%s must be at least 1."), "MXERRS");
176 if (cmd.n_mxloops[0] >= 1)
177 settings_set_mxloops (cmd.n_mxloops[0]);
179 msg (SE, _("%s must be at least 1."), "MXLOOPS");
183 if (cmd.n_mxwarns[0] >= 0)
184 settings_set_max_messages (MSG_S_WARNING, cmd.n_mxwarns[0]);
186 msg (SE, _("%s must not be negative."), "MXWARNS");
189 settings_set_input_integer_format (stc_to_integer_format (cmd.rib));
191 settings_set_input_float_format (stc_to_float_format (cmd.rrb));
193 settings_set_safer_mode ();
194 if (cmd.sbc_scompression)
195 settings_set_scompression (cmd.scompress == STC_ON);
196 if (cmd.sbc_undefined)
197 settings_set_undefined (cmd.undef == STC_WARN);
199 settings_set_output_integer_format (stc_to_integer_format (cmd.wib));
201 settings_set_output_float_format (stc_to_float_format (cmd.wrb));
202 if (cmd.sbc_workspace)
204 if ( cmd.n_workspace[0] < 1024 && ! settings_get_testing_mode ())
205 msg (SE, _("%s must be at least 1MB"), "WORKSPACE");
206 else if (cmd.n_workspace[0] <= 0)
207 msg (SE, _("%s must be positive"), "WORKSPACE");
209 settings_set_workspace (cmd.n_workspace[0] * 1024L);
213 msg (SW, _("%s is obsolete."), "BLOCK");
214 if (cmd.sbc_boxstring)
215 msg (SW, _("%s is obsolete."), "BOXSTRING");
217 msg (SW, _("%s is obsolete."), "CPI");
218 if (cmd.sbc_histogram)
219 msg (SW, _("%s is obsolete."), "HISTOGRAM");
221 msg (SW, _("%s is obsolete."), "LPI");
223 msg (SW, _("%s is obsolete."), "MENUS");
225 msg (SW, _("%s is obsolete."), "XSORT");
226 if (cmd.sbc_mxmemory)
227 msg (SE, _("%s is obsolete."), "MXMEMORY");
228 if (cmd.sbc_scripttab)
229 msg (SE, _("%s is obsolete."), "SCRIPTTAB");
231 msg (SW, _("%s is obsolete."), "TBFONTS");
232 if (cmd.sbc_tb1 && cmd.s_tb1)
233 msg (SW, _("%s is obsolete."), "TB1");
236 msg (SW, _("%s is not yet implemented."), "CASE");
238 if (cmd.sbc_compression)
239 msg (SW, _("Active file compression is not implemented."));
246 /* Returns the integer_format value corresponding to STC,
247 which should be the value of cmd.rib or cmd.wib. */
248 static enum integer_format
249 stc_to_integer_format (int stc)
251 return (stc == STC_MSBFIRST ? INTEGER_MSB_FIRST
252 : stc == STC_LSBFIRST ? INTEGER_LSB_FIRST
253 : stc == STC_VAX ? INTEGER_VAX
257 /* Returns the float_format value corresponding to STC,
258 which should be the value of cmd.rrb or cmd.wrb. */
259 static enum float_format
260 stc_to_float_format (int stc)
265 return FLOAT_NATIVE_DOUBLE;
268 return FLOAT_IEEE_SINGLE_LE;
270 return FLOAT_IEEE_SINGLE_BE;
272 return FLOAT_IEEE_DOUBLE_LE;
274 return FLOAT_IEEE_DOUBLE_BE;
284 return FLOAT_Z_SHORT;
293 set_output_routing (struct lexer *lexer, enum settings_output_type type)
295 enum settings_output_devices devices;
297 lex_match (lexer, T_EQUALS);
298 if (lex_match_id (lexer, "ON") || lex_match_id (lexer, "BOTH"))
299 devices = SETTINGS_DEVICE_LISTING | SETTINGS_DEVICE_TERMINAL;
300 else if (lex_match_id (lexer, "TERMINAL"))
301 devices = SETTINGS_DEVICE_TERMINAL;
302 else if (lex_match_id (lexer, "LISTING"))
303 devices = SETTINGS_DEVICE_LISTING;
304 else if (lex_match_id (lexer, "OFF") || lex_match_id (lexer, "NONE"))
308 lex_error (lexer, NULL);
312 settings_set_output_routing (type, devices);
317 /* Parses the BLANKS subcommand, which controls the value that
318 completely blank fields in numeric data imply. X, Wnd: Syntax is
319 SYSMIS or a numeric value. */
321 stc_custom_blanks (struct lexer *lexer,
322 struct dataset *ds UNUSED,
323 struct cmd_set *cmd UNUSED, void *aux UNUSED)
325 lex_match (lexer, T_EQUALS);
326 if (lex_match_id (lexer, "SYSMIS"))
329 settings_set_blanks (SYSMIS);
333 if (!lex_force_num (lexer))
335 settings_set_blanks (lex_number (lexer));
342 stc_custom_tnumbers (struct lexer *lexer,
343 struct dataset *ds UNUSED,
344 struct cmd_set *cmd UNUSED, void *aux UNUSED)
346 lex_match (lexer, T_EQUALS);
348 if (lex_match_id (lexer, "VALUES"))
350 settings_set_value_style (SETTINGS_VAL_STYLE_VALUES);
352 else if (lex_match_id (lexer, "LABELS"))
354 settings_set_value_style (SETTINGS_VAL_STYLE_LABELS);
356 else if (lex_match_id (lexer, "BOTH"))
358 settings_set_value_style (SETTINGS_VAL_STYLE_BOTH);
362 lex_error_expecting (lexer, "VALUES", "LABELS", "BOTH", NULL_SENTINEL);
371 stc_custom_tvars (struct lexer *lexer,
372 struct dataset *ds UNUSED,
373 struct cmd_set *cmd UNUSED, void *aux UNUSED)
375 lex_match (lexer, T_EQUALS);
377 if (lex_match_id (lexer, "NAMES"))
379 settings_set_var_style (SETTINGS_VAR_STYLE_NAMES);
381 else if (lex_match_id (lexer, "LABELS"))
383 settings_set_var_style (SETTINGS_VAR_STYLE_LABELS);
385 else if (lex_match_id (lexer, "BOTH"))
387 settings_set_var_style (SETTINGS_VAR_STYLE_BOTH);
391 lex_error_expecting (lexer, "NAMES", "LABELS", "BOTH", NULL_SENTINEL);
399 /* Parses the EPOCH subcommand, which controls the epoch used for
400 parsing 2-digit years. */
402 stc_custom_epoch (struct lexer *lexer,
403 struct dataset *ds UNUSED,
404 struct cmd_set *cmd UNUSED, void *aux UNUSED)
406 lex_match (lexer, T_EQUALS);
407 if (lex_match_id (lexer, "AUTOMATIC"))
408 settings_set_epoch (-1);
409 else if (lex_is_integer (lexer))
411 int new_epoch = lex_integer (lexer);
413 if (new_epoch < 1500)
415 msg (SE, _("%s must be 1500 or later."), "EPOCH");
418 settings_set_epoch (new_epoch);
422 lex_error (lexer, _("expecting %s or year"), "AUTOMATIC");
430 stc_custom_errors (struct lexer *lexer, struct dataset *ds UNUSED,
431 struct cmd_set *cmd UNUSED, void *aux UNUSED)
433 return set_output_routing (lexer, SETTINGS_OUTPUT_ERROR);
437 stc_custom_length (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
441 lex_match (lexer, T_EQUALS);
442 if (lex_match_id (lexer, "NONE"))
446 if (!lex_force_int (lexer))
448 if (lex_integer (lexer) < 1)
450 msg (SE, _("%s must be at least %d."), "LENGTH", 1);
453 page_length = lex_integer (lexer);
457 if (page_length != -1)
458 settings_set_viewlength (page_length);
464 stc_custom_locale (struct lexer *lexer, struct dataset *ds UNUSED,
465 struct cmd_set *cmd UNUSED, void *aux UNUSED)
469 lex_match (lexer, T_EQUALS);
471 if ( !lex_force_string (lexer))
474 s = lex_tokcstr (lexer);
476 /* First try this string as an encoding name */
477 if ( valid_encoding (s))
478 set_default_encoding (s);
480 /* Now try as a locale name (or alias) */
481 else if (set_encoding_from_locale (s))
486 msg (ME, _("%s is not a recognized encoding or locale name"), s);
496 stc_custom_messages (struct lexer *lexer, struct dataset *ds UNUSED,
497 struct cmd_set *cmd UNUSED, void *aux UNUSED)
499 return set_output_routing (lexer, SETTINGS_OUTPUT_NOTE);
503 stc_custom_printback (struct lexer *lexer, struct dataset *ds UNUSED,
504 struct cmd_set *cmd UNUSED, void *aux UNUSED)
506 return set_output_routing (lexer, SETTINGS_OUTPUT_SYNTAX);
510 stc_custom_results (struct lexer *lexer, struct dataset *ds UNUSED,
511 struct cmd_set *cmd UNUSED, void *aux UNUSED)
513 return set_output_routing (lexer, SETTINGS_OUTPUT_RESULT);
517 stc_custom_seed (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
519 lex_match (lexer, T_EQUALS);
520 if (lex_match_id (lexer, "RANDOM"))
524 if (!lex_force_num (lexer))
526 set_rng (lex_number (lexer));
534 stc_custom_width (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
536 lex_match (lexer, T_EQUALS);
537 if (lex_match_id (lexer, "NARROW"))
538 settings_set_viewwidth (79);
539 else if (lex_match_id (lexer, "WIDE"))
540 settings_set_viewwidth (131);
543 if (!lex_force_int (lexer))
545 if (lex_integer (lexer) < 40)
547 msg (SE, _("%s must be at least %d."), "WIDTH", 40);
550 settings_set_viewwidth (lex_integer (lexer));
557 /* Parses FORMAT subcommand, which consists of a numeric format
560 stc_custom_format (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
564 lex_match (lexer, T_EQUALS);
565 if (!parse_format_specifier (lexer, &fmt))
568 if (!fmt_check_output (&fmt))
571 if (fmt_is_string (fmt.type))
573 char str[FMT_STRING_LEN_MAX + 1];
574 msg (SE, _("%s requires numeric output format as an argument. "
575 "Specified format %s is of type string."),
577 fmt_to_string (&fmt, str));
581 settings_set_format (&fmt);
586 stc_custom_journal (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
588 lex_match (lexer, T_EQUALS);
589 if (lex_match_id (lexer, "ON") || lex_match_id (lexer, "YES"))
591 else if (lex_match_id (lexer, "OFF") || lex_match_id (lexer, "NO"))
593 else if (lex_is_string (lexer) || lex_token (lexer) == T_ID)
595 char *filename = utf8_to_filename (lex_tokcstr (lexer));
596 journal_set_file_name (filename);
603 lex_error (lexer, NULL);
610 stc_custom_log (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
612 return stc_custom_journal (lexer, ds, cmd, aux);
616 show_output_routing (enum settings_output_type type)
618 enum settings_output_devices devices;
621 devices = settings_get_output_routing (type);
622 if (devices & SETTINGS_DEVICE_LISTING)
623 s = devices & SETTINGS_DEVICE_TERMINAL ? "BOTH" : "LISTING";
624 else if (devices & SETTINGS_DEVICE_TERMINAL)
633 show_blanks (const struct dataset *ds UNUSED)
635 return (settings_get_blanks () == SYSMIS
637 : xasprintf ("%.*g", DBL_DIG + 1, settings_get_blanks ()));
641 format_cc (struct string *out, const char *in, char grouping)
646 if (c == grouping || c == '\'')
647 ds_put_byte (out, '\'');
649 ds_put_byte (out, '"');
650 ds_put_byte (out, c);
655 show_cc (enum fmt_type type)
657 const struct fmt_number_style *cc = settings_get_style (type);
660 ds_init_empty (&out);
661 format_cc (&out, cc->neg_prefix.s, cc->grouping);
662 ds_put_byte (&out, cc->grouping);
663 format_cc (&out, cc->prefix.s, cc->grouping);
664 ds_put_byte (&out, cc->grouping);
665 format_cc (&out, cc->suffix.s, cc->grouping);
666 ds_put_byte (&out, cc->grouping);
667 format_cc (&out, cc->neg_suffix.s, cc->grouping);
669 return ds_cstr (&out);
673 show_cca (const struct dataset *ds UNUSED)
675 return show_cc (FMT_CCA);
679 show_ccb (const struct dataset *ds UNUSED)
681 return show_cc (FMT_CCB);
685 show_ccc (const struct dataset *ds UNUSED)
687 return show_cc (FMT_CCC);
691 show_ccd (const struct dataset *ds UNUSED)
693 return show_cc (FMT_CCD);
697 show_cce (const struct dataset *ds UNUSED)
699 return show_cc (FMT_CCE);
703 show_decimals (const struct dataset *ds UNUSED)
705 return xasprintf ("`%c'", settings_get_decimal_char (FMT_F));
709 show_errors (const struct dataset *ds UNUSED)
711 return show_output_routing (SETTINGS_OUTPUT_ERROR);
715 show_format (const struct dataset *ds UNUSED)
717 char str[FMT_STRING_LEN_MAX + 1];
718 return xstrdup (fmt_to_string (settings_get_format (), str));
722 show_fuzzbits (const struct dataset *ds UNUSED)
724 return xasprintf ("%d", settings_get_fuzzbits ());
728 show_journal (const struct dataset *ds UNUSED)
730 return (journal_is_enabled ()
731 ? xasprintf ("\"%s\"", journal_get_file_name ())
732 : xstrdup ("disabled"));
736 show_length (const struct dataset *ds UNUSED)
738 return xasprintf ("%d", settings_get_viewlength ());
742 show_locale (const struct dataset *ds UNUSED)
744 return xstrdup (get_default_encoding ());
748 show_messages (const struct dataset *ds UNUSED)
750 return show_output_routing (SETTINGS_OUTPUT_NOTE);
754 show_printback (const struct dataset *ds UNUSED)
756 return show_output_routing (SETTINGS_OUTPUT_SYNTAX);
760 show_results (const struct dataset *ds UNUSED)
762 return show_output_routing (SETTINGS_OUTPUT_RESULT);
766 show_mxerrs (const struct dataset *ds UNUSED)
768 return xasprintf ("%d", settings_get_max_messages (MSG_S_ERROR));
772 show_mxloops (const struct dataset *ds UNUSED)
774 return xasprintf ("%d", settings_get_mxloops ());
778 show_mxwarns (const struct dataset *ds UNUSED)
780 return xasprintf ("%d", settings_get_max_messages (MSG_S_WARNING));
783 /* Returns a name for the given INTEGER_FORMAT value. */
785 show_integer_format (enum integer_format integer_format)
787 return xasprintf ("%s (%s)",
788 (integer_format == INTEGER_MSB_FIRST ? "MSBFIRST"
789 : integer_format == INTEGER_LSB_FIRST ? "LSBFIRST"
791 integer_format == INTEGER_NATIVE ? "NATIVE" : "nonnative");
794 /* Returns a name for the given FLOAT_FORMAT value. */
796 show_float_format (enum float_format float_format)
798 const char *format_name = "";
800 switch (float_format)
802 case FLOAT_IEEE_SINGLE_LE:
803 format_name = _("ISL (32-bit IEEE 754 single, little-endian)");
805 case FLOAT_IEEE_SINGLE_BE:
806 format_name = _("ISB (32-bit IEEE 754 single, big-endian)");
808 case FLOAT_IEEE_DOUBLE_LE:
809 format_name = _("IDL (64-bit IEEE 754 double, little-endian)");
811 case FLOAT_IEEE_DOUBLE_BE:
812 format_name = _("IDB (64-bit IEEE 754 double, big-endian)");
816 format_name = _("VF (32-bit VAX F, VAX-endian)");
819 format_name = _("VD (64-bit VAX D, VAX-endian)");
822 format_name = _("VG (64-bit VAX G, VAX-endian)");
826 format_name = _("ZS (32-bit IBM Z hexadecimal short, big-endian)");
829 format_name = _("ZL (64-bit IBM Z hexadecimal long, big-endian)");
837 return xasprintf ("%s (%s)", format_name,
838 (float_format == FLOAT_NATIVE_DOUBLE
839 ? "NATIVE" : "nonnative"));
843 show_rib (const struct dataset *ds UNUSED)
845 return show_integer_format (settings_get_input_integer_format ());
849 show_rrb (const struct dataset *ds UNUSED)
851 return show_float_format (settings_get_input_float_format ());
855 show_scompression (const struct dataset *ds UNUSED)
857 return xstrdup (settings_get_scompression () ? "ON" : "OFF");
861 show_undefined (const struct dataset *ds UNUSED)
863 return xstrdup (settings_get_undefined () ? "WARN" : "NOWARN");
867 show_weight (const struct dataset *ds)
869 const struct variable *var = dict_get_weight (dataset_dict (ds));
870 return xstrdup (var != NULL ? var_get_name (var) : "OFF");
874 show_wib (const struct dataset *ds UNUSED)
876 return show_integer_format (settings_get_output_integer_format ());
880 show_wrb (const struct dataset *ds UNUSED)
882 return show_float_format (settings_get_output_float_format ());
886 show_width (const struct dataset *ds UNUSED)
888 return xasprintf ("%d", settings_get_viewwidth ());
892 show_workspace (const struct dataset *ds UNUSED)
894 size_t ws = settings_get_workspace () / 1024L;
895 return xasprintf ("%zu", ws);
899 show_current_directory (const struct dataset *ds UNUSED)
908 buf = xrealloc (buf, len);
910 while (NULL == (wd = getcwd (buf, len)));
916 show_tempdir (const struct dataset *ds UNUSED)
918 return strdup (temp_dir_name ());
922 show_version (const struct dataset *ds UNUSED)
924 return strdup (announced_version);
928 show_system (const struct dataset *ds UNUSED)
930 return strdup (host_system);
934 show_n (const struct dataset *ds)
939 const struct casereader *reader = dataset_source (ds);
942 return strdup (_("Unknown"));
944 n = casereader_count_cases (reader);
946 return asnprintf (NULL, &l, "%ld", n);
953 char *(*function) (const struct dataset *);
956 const struct show_sbc show_table[] =
958 {"BLANKS", show_blanks},
964 {"DECIMALS", show_decimals},
965 {"DIRECTORY", show_current_directory},
966 {"ENVIRONMENT", show_system},
967 {"ERRORS", show_errors},
968 {"FORMAT", show_format},
969 {"FUZZBITS", show_fuzzbits},
970 {"JOURNAL", show_journal},
971 {"LENGTH", show_length},
972 {"LOCALE", show_locale},
973 {"MESSAGES", show_messages},
974 {"MXERRS", show_mxerrs},
975 {"MXLOOPS", show_mxloops},
976 {"MXWARNS", show_mxwarns},
978 {"PRINTBACk", show_printback},
979 {"RESULTS", show_results},
982 {"SCOMPRESSION", show_scompression},
983 {"TEMPDIR", show_tempdir},
984 {"UNDEFINED", show_undefined},
985 {"VERSION", show_version},
986 {"WEIGHT", show_weight},
989 {"WIDTH", show_width},
990 {"WORKSPACE", show_workspace},
994 do_show (const struct dataset *ds, const struct show_sbc *sbc)
996 char *value = sbc->function (ds);
997 msg (SN, _("%s is %s."), sbc->name, value);
1002 show_all (const struct dataset *ds)
1006 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1007 do_show (ds, &show_table[i]);
1011 show_all_cc (const struct dataset *ds)
1015 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1017 const struct show_sbc *sbc = &show_table[i];
1018 if (!strncmp (sbc->name, "CC", 2))
1024 show_warranty (const struct dataset *ds UNUSED)
1026 fputs (lack_of_warranty, stdout);
1030 show_copying (const struct dataset *ds UNUSED)
1032 fputs (copyleft, stdout);
1037 cmd_show (struct lexer *lexer, struct dataset *ds)
1039 if (lex_token (lexer) == T_ENDCMD)
1047 if (lex_match (lexer, T_ALL))
1049 else if (lex_match_id (lexer, "CC"))
1051 else if (lex_match_id (lexer, "WARRANTY"))
1053 else if (lex_match_id (lexer, "COPYING") || lex_match_id (lexer, "LICENSE"))
1055 else if (lex_token (lexer) == T_ID)
1059 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1061 const struct show_sbc *sbc = &show_table[i];
1062 if (lex_match_id (lexer, sbc->name))
1068 lex_error (lexer, NULL);
1075 lex_error (lexer, NULL);
1079 lex_match (lexer, T_SLASH);
1081 while (lex_token (lexer) != T_ENDCMD);
1086 #define MAX_SAVED_SETTINGS 5
1088 static struct settings *saved_settings[MAX_SAVED_SETTINGS];
1089 static int n_saved_settings;
1092 cmd_preserve (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
1094 if (n_saved_settings < MAX_SAVED_SETTINGS)
1096 saved_settings[n_saved_settings++] = settings_get ();
1101 msg (SE, _("Too many %s commands without a %s: at most "
1102 "%d levels of saved settings are allowed."),
1103 "PRESERVE", "RESTORE",
1104 MAX_SAVED_SETTINGS);
1105 return CMD_CASCADING_FAILURE;
1110 cmd_restore (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
1112 if (n_saved_settings > 0)
1114 struct settings *s = saved_settings[--n_saved_settings];
1116 settings_destroy (s);
1121 msg (SE, _("%s without matching %s."), "RESTORE", "PRESERVE");