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"))
349 settings_set_show_values (SETTINGS_VALUE_SHOW_VALUE);
350 else if (lex_match_id (lexer, "LABELS"))
351 settings_set_show_values (SETTINGS_VALUE_SHOW_LABEL);
352 else if (lex_match_id (lexer, "BOTH"))
353 settings_set_show_values (SETTINGS_VALUE_SHOW_BOTH);
356 lex_error_expecting (lexer, "VALUES", "LABELS", "BOTH");
365 stc_custom_tvars (struct lexer *lexer,
366 struct dataset *ds UNUSED,
367 struct cmd_set *cmd UNUSED, void *aux UNUSED)
369 lex_match (lexer, T_EQUALS);
371 if (lex_match_id (lexer, "NAMES"))
372 settings_set_show_variables (SETTINGS_VALUE_SHOW_VALUE);
373 else if (lex_match_id (lexer, "LABELS"))
374 settings_set_show_variables (SETTINGS_VALUE_SHOW_LABEL);
375 else if (lex_match_id (lexer, "BOTH"))
376 settings_set_show_variables (SETTINGS_VALUE_SHOW_BOTH);
379 lex_error_expecting (lexer, "NAMES", "LABELS", "BOTH");
387 /* Parses the EPOCH subcommand, which controls the epoch used for
388 parsing 2-digit years. */
390 stc_custom_epoch (struct lexer *lexer,
391 struct dataset *ds UNUSED,
392 struct cmd_set *cmd UNUSED, void *aux UNUSED)
394 lex_match (lexer, T_EQUALS);
395 if (lex_match_id (lexer, "AUTOMATIC"))
396 settings_set_epoch (-1);
397 else if (lex_is_integer (lexer))
399 int new_epoch = lex_integer (lexer);
401 if (new_epoch < 1500)
403 msg (SE, _("%s must be 1500 or later."), "EPOCH");
406 settings_set_epoch (new_epoch);
410 lex_error (lexer, _("expecting %s or year"), "AUTOMATIC");
418 stc_custom_errors (struct lexer *lexer, struct dataset *ds UNUSED,
419 struct cmd_set *cmd UNUSED, void *aux UNUSED)
421 return set_output_routing (lexer, SETTINGS_OUTPUT_ERROR);
425 stc_custom_length (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
429 lex_match (lexer, T_EQUALS);
430 if (lex_match_id (lexer, "NONE"))
434 if (!lex_force_int (lexer))
436 if (lex_integer (lexer) < 1)
438 msg (SE, _("%s must be at least %d."), "LENGTH", 1);
441 page_length = lex_integer (lexer);
445 if (page_length != -1)
446 settings_set_viewlength (page_length);
452 stc_custom_locale (struct lexer *lexer, struct dataset *ds UNUSED,
453 struct cmd_set *cmd UNUSED, void *aux UNUSED)
457 lex_match (lexer, T_EQUALS);
459 if ( !lex_force_string (lexer))
462 s = lex_tokcstr (lexer);
464 /* First try this string as an encoding name */
465 if ( valid_encoding (s))
466 set_default_encoding (s);
468 /* Now try as a locale name (or alias) */
469 else if (set_encoding_from_locale (s))
474 msg (ME, _("%s is not a recognized encoding or locale name"), s);
484 stc_custom_messages (struct lexer *lexer, struct dataset *ds UNUSED,
485 struct cmd_set *cmd UNUSED, void *aux UNUSED)
487 return set_output_routing (lexer, SETTINGS_OUTPUT_NOTE);
491 stc_custom_printback (struct lexer *lexer, struct dataset *ds UNUSED,
492 struct cmd_set *cmd UNUSED, void *aux UNUSED)
494 return set_output_routing (lexer, SETTINGS_OUTPUT_SYNTAX);
498 stc_custom_results (struct lexer *lexer, struct dataset *ds UNUSED,
499 struct cmd_set *cmd UNUSED, void *aux UNUSED)
501 return set_output_routing (lexer, SETTINGS_OUTPUT_RESULT);
505 stc_custom_seed (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
507 lex_match (lexer, T_EQUALS);
508 if (lex_match_id (lexer, "RANDOM"))
512 if (!lex_force_num (lexer))
514 set_rng (lex_number (lexer));
522 stc_custom_width (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
524 lex_match (lexer, T_EQUALS);
525 if (lex_match_id (lexer, "NARROW"))
526 settings_set_viewwidth (79);
527 else if (lex_match_id (lexer, "WIDE"))
528 settings_set_viewwidth (131);
531 if (!lex_force_int (lexer))
533 if (lex_integer (lexer) < 40)
535 msg (SE, _("%s must be at least %d."), "WIDTH", 40);
538 settings_set_viewwidth (lex_integer (lexer));
545 /* Parses FORMAT subcommand, which consists of a numeric format
548 stc_custom_format (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
552 lex_match (lexer, T_EQUALS);
553 if (!parse_format_specifier (lexer, &fmt))
556 if (!fmt_check_output (&fmt))
559 if (fmt_is_string (fmt.type))
561 char str[FMT_STRING_LEN_MAX + 1];
562 msg (SE, _("%s requires numeric output format as an argument. "
563 "Specified format %s is of type string."),
565 fmt_to_string (&fmt, str));
569 settings_set_format (&fmt);
574 stc_custom_journal (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
576 lex_match (lexer, T_EQUALS);
577 if (lex_match_id (lexer, "ON") || lex_match_id (lexer, "YES"))
579 else if (lex_match_id (lexer, "OFF") || lex_match_id (lexer, "NO"))
581 else if (lex_is_string (lexer) || lex_token (lexer) == T_ID)
583 char *filename = utf8_to_filename (lex_tokcstr (lexer));
584 journal_set_file_name (filename);
591 lex_error (lexer, NULL);
598 stc_custom_log (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
600 return stc_custom_journal (lexer, ds, cmd, aux);
604 show_output_routing (enum settings_output_type type)
606 enum settings_output_devices devices;
609 devices = settings_get_output_routing (type);
610 if (devices & SETTINGS_DEVICE_LISTING)
611 s = devices & SETTINGS_DEVICE_TERMINAL ? "BOTH" : "LISTING";
612 else if (devices & SETTINGS_DEVICE_TERMINAL)
621 show_blanks (const struct dataset *ds UNUSED)
623 return (settings_get_blanks () == SYSMIS
625 : xasprintf ("%.*g", DBL_DIG + 1, settings_get_blanks ()));
629 format_cc (struct string *out, const char *in, char grouping)
634 if (c == grouping || c == '\'')
635 ds_put_byte (out, '\'');
637 ds_put_byte (out, '"');
638 ds_put_byte (out, c);
643 show_cc (enum fmt_type type)
645 const struct fmt_number_style *cc = settings_get_style (type);
648 ds_init_empty (&out);
649 format_cc (&out, cc->neg_prefix.s, cc->grouping);
650 ds_put_byte (&out, cc->grouping);
651 format_cc (&out, cc->prefix.s, cc->grouping);
652 ds_put_byte (&out, cc->grouping);
653 format_cc (&out, cc->suffix.s, cc->grouping);
654 ds_put_byte (&out, cc->grouping);
655 format_cc (&out, cc->neg_suffix.s, cc->grouping);
657 return ds_cstr (&out);
661 show_cca (const struct dataset *ds UNUSED)
663 return show_cc (FMT_CCA);
667 show_ccb (const struct dataset *ds UNUSED)
669 return show_cc (FMT_CCB);
673 show_ccc (const struct dataset *ds UNUSED)
675 return show_cc (FMT_CCC);
679 show_ccd (const struct dataset *ds UNUSED)
681 return show_cc (FMT_CCD);
685 show_cce (const struct dataset *ds UNUSED)
687 return show_cc (FMT_CCE);
691 show_decimals (const struct dataset *ds UNUSED)
693 return xasprintf ("`%c'", settings_get_decimal_char (FMT_F));
697 show_errors (const struct dataset *ds UNUSED)
699 return show_output_routing (SETTINGS_OUTPUT_ERROR);
703 show_format (const struct dataset *ds UNUSED)
705 char str[FMT_STRING_LEN_MAX + 1];
706 return xstrdup (fmt_to_string (settings_get_format (), str));
710 show_fuzzbits (const struct dataset *ds UNUSED)
712 return xasprintf ("%d", settings_get_fuzzbits ());
716 show_journal (const struct dataset *ds UNUSED)
718 return (journal_is_enabled ()
719 ? xasprintf ("\"%s\"", journal_get_file_name ())
720 : xstrdup ("disabled"));
724 show_length (const struct dataset *ds UNUSED)
726 return xasprintf ("%d", settings_get_viewlength ());
730 show_locale (const struct dataset *ds UNUSED)
732 return xstrdup (get_default_encoding ());
736 show_messages (const struct dataset *ds UNUSED)
738 return show_output_routing (SETTINGS_OUTPUT_NOTE);
742 show_printback (const struct dataset *ds UNUSED)
744 return show_output_routing (SETTINGS_OUTPUT_SYNTAX);
748 show_results (const struct dataset *ds UNUSED)
750 return show_output_routing (SETTINGS_OUTPUT_RESULT);
754 show_mxerrs (const struct dataset *ds UNUSED)
756 return xasprintf ("%d", settings_get_max_messages (MSG_S_ERROR));
760 show_mxloops (const struct dataset *ds UNUSED)
762 return xasprintf ("%d", settings_get_mxloops ());
766 show_mxwarns (const struct dataset *ds UNUSED)
768 return xasprintf ("%d", settings_get_max_messages (MSG_S_WARNING));
771 /* Returns a name for the given INTEGER_FORMAT value. */
773 show_integer_format (enum integer_format integer_format)
775 return xasprintf ("%s (%s)",
776 (integer_format == INTEGER_MSB_FIRST ? "MSBFIRST"
777 : integer_format == INTEGER_LSB_FIRST ? "LSBFIRST"
779 integer_format == INTEGER_NATIVE ? "NATIVE" : "nonnative");
782 /* Returns a name for the given FLOAT_FORMAT value. */
784 show_float_format (enum float_format float_format)
786 const char *format_name = "";
788 switch (float_format)
790 case FLOAT_IEEE_SINGLE_LE:
791 format_name = _("ISL (32-bit IEEE 754 single, little-endian)");
793 case FLOAT_IEEE_SINGLE_BE:
794 format_name = _("ISB (32-bit IEEE 754 single, big-endian)");
796 case FLOAT_IEEE_DOUBLE_LE:
797 format_name = _("IDL (64-bit IEEE 754 double, little-endian)");
799 case FLOAT_IEEE_DOUBLE_BE:
800 format_name = _("IDB (64-bit IEEE 754 double, big-endian)");
804 format_name = _("VF (32-bit VAX F, VAX-endian)");
807 format_name = _("VD (64-bit VAX D, VAX-endian)");
810 format_name = _("VG (64-bit VAX G, VAX-endian)");
814 format_name = _("ZS (32-bit IBM Z hexadecimal short, big-endian)");
817 format_name = _("ZL (64-bit IBM Z hexadecimal long, big-endian)");
825 return xasprintf ("%s (%s)", format_name,
826 (float_format == FLOAT_NATIVE_DOUBLE
827 ? "NATIVE" : "nonnative"));
831 show_rib (const struct dataset *ds UNUSED)
833 return show_integer_format (settings_get_input_integer_format ());
837 show_rrb (const struct dataset *ds UNUSED)
839 return show_float_format (settings_get_input_float_format ());
843 show_scompression (const struct dataset *ds UNUSED)
845 return xstrdup (settings_get_scompression () ? "ON" : "OFF");
849 show_undefined (const struct dataset *ds UNUSED)
851 return xstrdup (settings_get_undefined () ? "WARN" : "NOWARN");
855 show_weight (const struct dataset *ds)
857 const struct variable *var = dict_get_weight (dataset_dict (ds));
858 return xstrdup (var != NULL ? var_get_name (var) : "OFF");
862 show_wib (const struct dataset *ds UNUSED)
864 return show_integer_format (settings_get_output_integer_format ());
868 show_wrb (const struct dataset *ds UNUSED)
870 return show_float_format (settings_get_output_float_format ());
874 show_width (const struct dataset *ds UNUSED)
876 return xasprintf ("%d", settings_get_viewwidth ());
880 show_workspace (const struct dataset *ds UNUSED)
882 size_t ws = settings_get_workspace () / 1024L;
883 return xasprintf ("%zu", ws);
887 show_current_directory (const struct dataset *ds UNUSED)
896 buf = xrealloc (buf, len);
898 while (NULL == (wd = getcwd (buf, len)));
904 show_tempdir (const struct dataset *ds UNUSED)
906 return strdup (temp_dir_name ());
910 show_version (const struct dataset *ds UNUSED)
912 return strdup (announced_version);
916 show_system (const struct dataset *ds UNUSED)
918 return strdup (host_system);
922 show_n (const struct dataset *ds)
927 const struct casereader *reader = dataset_source (ds);
930 return strdup (_("Unknown"));
932 n = casereader_count_cases (reader);
934 return asnprintf (NULL, &l, "%ld", n);
941 char *(*function) (const struct dataset *);
944 const struct show_sbc show_table[] =
946 {"BLANKS", show_blanks},
952 {"DECIMALS", show_decimals},
953 {"DIRECTORY", show_current_directory},
954 {"ENVIRONMENT", show_system},
955 {"ERRORS", show_errors},
956 {"FORMAT", show_format},
957 {"FUZZBITS", show_fuzzbits},
958 {"JOURNAL", show_journal},
959 {"LENGTH", show_length},
960 {"LOCALE", show_locale},
961 {"MESSAGES", show_messages},
962 {"MXERRS", show_mxerrs},
963 {"MXLOOPS", show_mxloops},
964 {"MXWARNS", show_mxwarns},
966 {"PRINTBACk", show_printback},
967 {"RESULTS", show_results},
970 {"SCOMPRESSION", show_scompression},
971 {"TEMPDIR", show_tempdir},
972 {"UNDEFINED", show_undefined},
973 {"VERSION", show_version},
974 {"WEIGHT", show_weight},
977 {"WIDTH", show_width},
978 {"WORKSPACE", show_workspace},
982 do_show (const struct dataset *ds, const struct show_sbc *sbc)
984 char *value = sbc->function (ds);
985 msg (SN, _("%s is %s."), sbc->name, value);
990 show_all (const struct dataset *ds)
994 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
995 do_show (ds, &show_table[i]);
999 show_all_cc (const struct dataset *ds)
1003 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1005 const struct show_sbc *sbc = &show_table[i];
1006 if (!strncmp (sbc->name, "CC", 2))
1012 show_warranty (const struct dataset *ds UNUSED)
1014 fputs (lack_of_warranty, stdout);
1018 show_copying (const struct dataset *ds UNUSED)
1020 fputs (copyleft, stdout);
1025 cmd_show (struct lexer *lexer, struct dataset *ds)
1027 if (lex_token (lexer) == T_ENDCMD)
1035 if (lex_match (lexer, T_ALL))
1037 else if (lex_match_id (lexer, "CC"))
1039 else if (lex_match_id (lexer, "WARRANTY"))
1041 else if (lex_match_id (lexer, "COPYING") || lex_match_id (lexer, "LICENSE"))
1043 else if (lex_token (lexer) == T_ID)
1047 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1049 const struct show_sbc *sbc = &show_table[i];
1050 if (lex_match_id (lexer, sbc->name))
1056 lex_error (lexer, NULL);
1063 lex_error (lexer, NULL);
1067 lex_match (lexer, T_SLASH);
1069 while (lex_token (lexer) != T_ENDCMD);
1074 #define MAX_SAVED_SETTINGS 5
1076 static struct settings *saved_settings[MAX_SAVED_SETTINGS];
1077 static int n_saved_settings;
1080 cmd_preserve (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
1082 if (n_saved_settings < MAX_SAVED_SETTINGS)
1084 saved_settings[n_saved_settings++] = settings_get ();
1089 msg (SE, _("Too many %s commands without a %s: at most "
1090 "%d levels of saved settings are allowed."),
1091 "PRESERVE", "RESTORE",
1092 MAX_SAVED_SETTINGS);
1093 return CMD_CASCADING_FAILURE;
1098 cmd_restore (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
1100 if (n_saved_settings > 0)
1102 struct settings *s = saved_settings[--n_saved_settings];
1104 settings_destroy (s);
1109 msg (SE, _("%s without matching %s."), "RESTORE", "PRESERVE");