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 format_cc (struct string *out, const char *in, char grouping)
664 if (c == grouping || c == '\'')
665 ds_put_byte (out, '\'');
667 ds_put_byte (out, '"');
668 ds_put_byte (out, c);
673 show_cc (enum fmt_type type)
675 const struct fmt_number_style *cc = settings_get_style (type);
678 ds_init_empty (&out);
679 format_cc (&out, cc->neg_prefix.s, cc->grouping);
680 ds_put_byte (&out, cc->grouping);
681 format_cc (&out, cc->prefix.s, cc->grouping);
682 ds_put_byte (&out, cc->grouping);
683 format_cc (&out, cc->suffix.s, cc->grouping);
684 ds_put_byte (&out, cc->grouping);
685 format_cc (&out, cc->neg_suffix.s, cc->grouping);
687 return ds_cstr (&out);
691 show_cca (const struct dataset *ds UNUSED)
693 return show_cc (FMT_CCA);
697 show_ccb (const struct dataset *ds UNUSED)
699 return show_cc (FMT_CCB);
703 show_ccc (const struct dataset *ds UNUSED)
705 return show_cc (FMT_CCC);
709 show_ccd (const struct dataset *ds UNUSED)
711 return show_cc (FMT_CCD);
715 show_cce (const struct dataset *ds UNUSED)
717 return show_cc (FMT_CCE);
721 show_decimals (const struct dataset *ds UNUSED)
723 return xasprintf ("`%c'", settings_get_decimal_char (FMT_F));
727 show_errors (const struct dataset *ds UNUSED)
729 return show_output_routing (SETTINGS_OUTPUT_ERROR);
733 show_format (const struct dataset *ds UNUSED)
735 char str[FMT_STRING_LEN_MAX + 1];
736 return xstrdup (fmt_to_string (settings_get_format (), str));
740 show_fuzzbits (const struct dataset *ds UNUSED)
742 return xasprintf ("%d", settings_get_fuzzbits ());
746 show_journal (const struct dataset *ds UNUSED)
748 return (journal_is_enabled ()
749 ? xasprintf ("\"%s\"", journal_get_file_name ())
750 : xstrdup ("disabled"));
754 show_length (const struct dataset *ds UNUSED)
756 return xasprintf ("%d", settings_get_viewlength ());
760 show_locale (const struct dataset *ds UNUSED)
762 return xstrdup (get_default_encoding ());
766 show_messages (const struct dataset *ds UNUSED)
768 return show_output_routing (SETTINGS_OUTPUT_NOTE);
772 show_printback (const struct dataset *ds UNUSED)
774 return show_output_routing (SETTINGS_OUTPUT_SYNTAX);
778 show_results (const struct dataset *ds UNUSED)
780 return show_output_routing (SETTINGS_OUTPUT_RESULT);
784 show_mxerrs (const struct dataset *ds UNUSED)
786 return xasprintf ("%d", settings_get_max_messages (MSG_S_ERROR));
790 show_mxloops (const struct dataset *ds UNUSED)
792 return xasprintf ("%d", settings_get_mxloops ());
796 show_mxwarns (const struct dataset *ds UNUSED)
798 return xasprintf ("%d", settings_get_max_messages (MSG_S_WARNING));
801 /* Returns a name for the given INTEGER_FORMAT value. */
803 show_integer_format (enum integer_format integer_format)
805 return xasprintf ("%s (%s)",
806 (integer_format == INTEGER_MSB_FIRST ? "MSBFIRST"
807 : integer_format == INTEGER_LSB_FIRST ? "LSBFIRST"
809 integer_format == INTEGER_NATIVE ? "NATIVE" : "nonnative");
812 /* Returns a name for the given FLOAT_FORMAT value. */
814 show_float_format (enum float_format float_format)
816 const char *format_name = "";
818 switch (float_format)
820 case FLOAT_IEEE_SINGLE_LE:
821 format_name = _("ISL (32-bit IEEE 754 single, little-endian)");
823 case FLOAT_IEEE_SINGLE_BE:
824 format_name = _("ISB (32-bit IEEE 754 single, big-endian)");
826 case FLOAT_IEEE_DOUBLE_LE:
827 format_name = _("IDL (64-bit IEEE 754 double, little-endian)");
829 case FLOAT_IEEE_DOUBLE_BE:
830 format_name = _("IDB (64-bit IEEE 754 double, big-endian)");
834 format_name = _("VF (32-bit VAX F, VAX-endian)");
837 format_name = _("VD (64-bit VAX D, VAX-endian)");
840 format_name = _("VG (64-bit VAX G, VAX-endian)");
844 format_name = _("ZS (32-bit IBM Z hexadecimal short, big-endian)");
847 format_name = _("ZL (64-bit IBM Z hexadecimal long, big-endian)");
855 return xasprintf ("%s (%s)", format_name,
856 (float_format == FLOAT_NATIVE_DOUBLE
857 ? "NATIVE" : "nonnative"));
861 show_rib (const struct dataset *ds UNUSED)
863 return show_integer_format (settings_get_input_integer_format ());
867 show_rrb (const struct dataset *ds UNUSED)
869 return show_float_format (settings_get_input_float_format ());
873 show_scompression (const struct dataset *ds UNUSED)
875 return xstrdup (settings_get_scompression () ? "ON" : "OFF");
879 show_undefined (const struct dataset *ds UNUSED)
881 return xstrdup (settings_get_undefined () ? "WARN" : "NOWARN");
885 show_weight (const struct dataset *ds)
887 const struct variable *var = dict_get_weight (dataset_dict (ds));
888 return xstrdup (var != NULL ? var_get_name (var) : "OFF");
892 show_wib (const struct dataset *ds UNUSED)
894 return show_integer_format (settings_get_output_integer_format ());
898 show_wrb (const struct dataset *ds UNUSED)
900 return show_float_format (settings_get_output_float_format ());
904 show_width (const struct dataset *ds UNUSED)
906 return xasprintf ("%d", settings_get_viewwidth ());
910 show_workspace (const struct dataset *ds UNUSED)
912 size_t ws = settings_get_workspace () / 1024L;
913 return xasprintf ("%zu", ws);
917 show_current_directory (const struct dataset *ds UNUSED)
926 buf = xrealloc (buf, len);
928 while (NULL == (wd = getcwd (buf, len)));
934 show_tempdir (const struct dataset *ds UNUSED)
936 return strdup (temp_dir_name ());
940 show_version (const struct dataset *ds UNUSED)
942 return strdup (announced_version);
946 show_system (const struct dataset *ds UNUSED)
948 return strdup (host_system);
952 show_n (const struct dataset *ds)
957 const struct casereader *reader = dataset_source (ds);
960 return strdup (_("Unknown"));
962 n = casereader_count_cases (reader);
964 return asnprintf (NULL, &l, "%ld", n);
971 char *(*function) (const struct dataset *);
974 const struct show_sbc show_table[] =
976 {"BLANKS", show_blanks},
982 {"DECIMALS", show_decimals},
983 {"DIRECTORY", show_current_directory},
984 {"ENVIRONMENT", show_system},
985 {"ERRORS", show_errors},
986 {"FORMAT", show_format},
987 {"FUZZBITS", show_fuzzbits},
988 {"JOURNAL", show_journal},
989 {"LENGTH", show_length},
990 {"LOCALE", show_locale},
991 {"MESSAGES", show_messages},
992 {"MXERRS", show_mxerrs},
993 {"MXLOOPS", show_mxloops},
994 {"MXWARNS", show_mxwarns},
996 {"PRINTBACk", show_printback},
997 {"RESULTS", show_results},
1000 {"SCOMPRESSION", show_scompression},
1001 {"TEMPDIR", show_tempdir},
1002 {"UNDEFINED", show_undefined},
1003 {"VERSION", show_version},
1004 {"WEIGHT", show_weight},
1007 {"WIDTH", show_width},
1008 {"WORKSPACE", show_workspace},
1012 do_show (const struct dataset *ds, const struct show_sbc *sbc)
1014 char *value = sbc->function (ds);
1015 msg (SN, _("%s is %s."), sbc->name, value);
1020 show_all (const struct dataset *ds)
1024 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1025 do_show (ds, &show_table[i]);
1029 show_all_cc (const struct dataset *ds)
1033 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1035 const struct show_sbc *sbc = &show_table[i];
1036 if (!strncmp (sbc->name, "CC", 2))
1042 show_warranty (const struct dataset *ds UNUSED)
1044 fputs (lack_of_warranty, stdout);
1048 show_copying (const struct dataset *ds UNUSED)
1050 fputs (copyleft, stdout);
1055 cmd_show (struct lexer *lexer, struct dataset *ds)
1057 if (lex_token (lexer) == T_ENDCMD)
1065 if (lex_match (lexer, T_ALL))
1067 else if (lex_match_id (lexer, "CC"))
1069 else if (lex_match_id (lexer, "WARRANTY"))
1071 else if (lex_match_id (lexer, "COPYING") || lex_match_id (lexer, "LICENSE"))
1073 else if (lex_token (lexer) == T_ID)
1077 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
1079 const struct show_sbc *sbc = &show_table[i];
1080 if (lex_match_id (lexer, sbc->name))
1086 lex_error (lexer, NULL);
1093 lex_error (lexer, NULL);
1097 lex_match (lexer, T_SLASH);
1099 while (lex_token (lexer) != T_ENDCMD);
1104 #define MAX_SAVED_SETTINGS 5
1106 static struct settings *saved_settings[MAX_SAVED_SETTINGS];
1107 static int n_saved_settings;
1110 cmd_preserve (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
1112 if (n_saved_settings < MAX_SAVED_SETTINGS)
1114 saved_settings[n_saved_settings++] = settings_get ();
1119 msg (SE, _("Too many %s commands without a %s: at most "
1120 "%d levels of saved settings are allowed."),
1121 "PRESERVE", "RESTORE",
1122 MAX_SAVED_SETTINGS);
1123 return CMD_CASCADING_FAILURE;
1128 cmd_restore (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
1130 if (n_saved_settings > 0)
1132 struct settings *s = saved_settings[--n_saved_settings];
1134 settings_destroy (s);
1139 msg (SE, _("%s without matching %s."), "RESTORE", "PRESERVE");