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 "data/casereader.h"
27 #include "data/data-in.h"
28 #include "data/data-out.h"
29 #include "data/dataset.h"
30 #include "data/dictionary.h"
31 #include "data/format.h"
32 #include "data/settings.h"
33 #include "data/value.h"
34 #include "data/variable.h"
35 #include "language/command.h"
36 #include "language/lexer/format-parser.h"
37 #include "language/lexer/lexer.h"
38 #include "libpspp/assertion.h"
39 #include "libpspp/compiler.h"
40 #include "libpspp/copyleft.h"
41 #include "libpspp/temp-file.h"
42 #include "libpspp/version.h"
43 #include "libpspp/float-format.h"
44 #include "libpspp/i18n.h"
45 #include "libpspp/integer-format.h"
46 #include "libpspp/message.h"
47 #include "math/random.h"
48 #include "output/driver.h"
49 #include "output/journal.h"
50 #include "output/pivot-table.h"
52 #include "gl/ftoastr.h"
53 #include "gl/minmax.h"
54 #include "gl/relocatable.h"
55 #include "gl/vasnprintf.h"
56 #include "gl/xalloc.h"
59 #define _(msgid) gettext (msgid)
60 #define N_(msgid) (msgid)
65 bool (*set) (struct lexer *);
66 char *(*show) (const struct dataset *);
70 match_subcommand (struct lexer *lexer, const char *name)
72 if (lex_match_id (lexer, name))
74 lex_match (lexer, T_EQUALS);
82 parse_enum_valist (struct lexer *lexer, va_list args)
86 const char *name = va_arg (args, char *);
89 int value = va_arg (args, int);
91 if (lex_match_id (lexer, name))
96 #define parse_enum(...) parse_enum (__VA_ARGS__, NULL_SENTINEL)
97 static int SENTINEL(0)
98 (parse_enum) (struct lexer *lexer, ...)
102 va_start (args, lexer);
103 int retval = parse_enum_valist (lexer, args);
109 #define force_parse_enum(...) force_parse_enum (__VA_ARGS__, NULL_SENTINEL)
110 static int SENTINEL(0)
111 (force_parse_enum) (struct lexer *lexer, ...)
115 va_start (args, lexer);
116 int retval = parse_enum_valist (lexer, args);
121 enum { MAX_OPTIONS = 9 };
122 const char *options[MAX_OPTIONS];
125 va_start (args, lexer);
126 while (n < MAX_OPTIONS)
128 const char *name = va_arg (args, char *);
137 lex_error_expecting_array (lexer, options, n);
144 parse_bool (struct lexer *lexer)
146 return parse_enum (lexer,
147 "ON", true, "YES", true,
148 "OFF", false, "NO", false);
152 force_parse_bool (struct lexer *lexer)
154 return force_parse_enum (lexer,
155 "ON", true, "YES", true,
156 "OFF", false, "NO", false);
160 force_parse_int (struct lexer *lexer, int *integerp)
162 if (!lex_force_int (lexer))
164 *integerp = lex_integer (lexer);
170 parse_output_routing (struct lexer *lexer, enum settings_output_type type)
172 enum settings_output_devices devices;
173 if (lex_match_id (lexer, "ON") || lex_match_id (lexer, "BOTH"))
174 devices = SETTINGS_DEVICE_LISTING | SETTINGS_DEVICE_TERMINAL;
175 else if (lex_match_id (lexer, "TERMINAL"))
176 devices = SETTINGS_DEVICE_TERMINAL;
177 else if (lex_match_id (lexer, "LISTING"))
178 devices = SETTINGS_DEVICE_LISTING;
179 else if (lex_match_id (lexer, "OFF") || lex_match_id (lexer, "NONE"))
183 lex_error (lexer, NULL);
187 settings_set_output_routing (type, devices);
193 show_output_routing (enum settings_output_type type)
195 enum settings_output_devices devices;
198 devices = settings_get_output_routing (type);
199 if (devices & SETTINGS_DEVICE_LISTING)
200 s = devices & SETTINGS_DEVICE_TERMINAL ? "BOTH" : "LISTING";
201 else if (devices & SETTINGS_DEVICE_TERMINAL)
210 parse_integer_format (struct lexer *lexer,
211 void (*set_format) (enum integer_format))
213 int value = force_parse_enum (lexer,
214 "MSBFIRST", INTEGER_MSB_FIRST,
215 "LSBFIRST", INTEGER_LSB_FIRST,
217 "NATIVE", INTEGER_NATIVE);
223 /* Returns a name for the given INTEGER_FORMAT value. */
225 show_integer_format (enum integer_format integer_format)
227 return xasprintf ("%s (%s)",
228 (integer_format == INTEGER_MSB_FIRST ? "MSBFIRST"
229 : integer_format == INTEGER_LSB_FIRST ? "LSBFIRST"
231 integer_format == INTEGER_NATIVE ? "NATIVE" : "nonnative");
235 parse_real_format (struct lexer *lexer,
236 void (*set_format) (enum float_format))
238 int value = force_parse_enum (lexer,
239 "NATIVE", FLOAT_NATIVE_DOUBLE,
240 "ISL", FLOAT_IEEE_SINGLE_LE,
241 "ISB", FLOAT_IEEE_SINGLE_BE,
242 "IDL", FLOAT_IEEE_DOUBLE_LE,
243 "IDB", FLOAT_IEEE_DOUBLE_BE,
254 /* Returns a name for the given FLOAT_FORMAT value. */
256 show_real_format (enum float_format float_format)
258 const char *format_name = "";
260 switch (float_format)
262 case FLOAT_IEEE_SINGLE_LE:
263 format_name = _("ISL (32-bit IEEE 754 single, little-endian)");
265 case FLOAT_IEEE_SINGLE_BE:
266 format_name = _("ISB (32-bit IEEE 754 single, big-endian)");
268 case FLOAT_IEEE_DOUBLE_LE:
269 format_name = _("IDL (64-bit IEEE 754 double, little-endian)");
271 case FLOAT_IEEE_DOUBLE_BE:
272 format_name = _("IDB (64-bit IEEE 754 double, big-endian)");
276 format_name = _("VF (32-bit VAX F, VAX-endian)");
279 format_name = _("VD (64-bit VAX D, VAX-endian)");
282 format_name = _("VG (64-bit VAX G, VAX-endian)");
286 format_name = _("ZS (32-bit IBM Z hexadecimal short, big-endian)");
289 format_name = _("ZL (64-bit IBM Z hexadecimal long, big-endian)");
297 return xasprintf ("%s (%s)", format_name,
298 (float_format == FLOAT_NATIVE_DOUBLE
299 ? "NATIVE" : "nonnative"));
303 parse_unimplemented (struct lexer *lexer, const char *name)
305 msg (SW, _("%s is not yet implemented."), name);
306 if (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD)
312 parse_ccx (struct lexer *lexer, enum fmt_type ccx)
314 if (!lex_force_string (lexer))
317 settings_set_cc (lex_tokcstr (lexer), ccx);
323 parse_BASETEXTDIRECTION (struct lexer *lexer)
325 return parse_unimplemented (lexer, "BASETEXTDIRECTION");
329 parse_BLANKS (struct lexer *lexer)
331 if (lex_match_id (lexer, "SYSMIS"))
332 settings_set_blanks (SYSMIS);
335 if (!lex_force_num (lexer))
337 settings_set_blanks (lex_number (lexer));
344 show_BLANKS (const struct dataset *ds UNUSED)
346 return (settings_get_blanks () == SYSMIS
348 : xasprintf ("%.*g", DBL_DIG + 1, settings_get_blanks ()));
352 parse_BLOCK (struct lexer *lexer)
354 return parse_unimplemented (lexer, "BLOCK");
358 parse_BOX (struct lexer *lexer)
360 return parse_unimplemented (lexer, "BOX");
364 parse_CACHE (struct lexer *lexer)
366 return parse_unimplemented (lexer, "CACHE");
370 parse_CCA (struct lexer *lexer)
372 return parse_ccx (lexer, FMT_CCA);
376 parse_CCB (struct lexer *lexer)
378 return parse_ccx (lexer, FMT_CCB);
382 parse_CCC (struct lexer *lexer)
384 return parse_ccx (lexer, FMT_CCC);
388 parse_CCD (struct lexer *lexer)
390 return parse_ccx (lexer, FMT_CCD);
394 parse_CCE (struct lexer *lexer)
396 return parse_ccx (lexer, FMT_CCE);
400 show_cc (enum fmt_type type)
402 return fmt_number_style_to_string (fmt_settings_get_style (
403 settings_get_fmt_settings (), type));
407 show_CCA (const struct dataset *ds UNUSED)
409 return show_cc (FMT_CCA);
413 show_CCB (const struct dataset *ds UNUSED)
415 return show_cc (FMT_CCB);
419 show_CCC (const struct dataset *ds UNUSED)
421 return show_cc (FMT_CCC);
425 show_CCD (const struct dataset *ds UNUSED)
427 return show_cc (FMT_CCD);
431 show_CCE (const struct dataset *ds UNUSED)
433 return show_cc (FMT_CCE);
437 parse_CELLSBREAK (struct lexer *lexer)
439 return parse_unimplemented (lexer, "CELLSBREAK");
443 parse_CMPTRANS (struct lexer *lexer)
445 return parse_unimplemented (lexer, "CMPTRANS");
449 parse_COMPRESSION (struct lexer *lexer)
451 return parse_unimplemented (lexer, "COMPRESSION");
455 parse_CTEMPLATE (struct lexer *lexer)
457 return parse_unimplemented (lexer, "CTEMPLATE");
461 parse_DECIMAL (struct lexer *lexer)
463 int decimal_char = force_parse_enum (lexer,
466 if (decimal_char != -1)
467 settings_set_decimal_char (decimal_char);
468 return decimal_char != -1;
472 show_DECIMAL (const struct dataset *ds UNUSED)
474 return xasprintf ("`%c'", settings_get_fmt_settings ()->decimal);
478 parse_EPOCH (struct lexer *lexer)
480 if (lex_match_id (lexer, "AUTOMATIC"))
481 settings_set_epoch (-1);
482 else if (lex_is_integer (lexer))
484 if (!lex_force_int_range (lexer, "EPOCH", 1500, INT_MAX))
486 settings_set_epoch (lex_integer (lexer));
491 lex_error (lexer, _("expecting %s or year"), "AUTOMATIC");
499 show_EPOCH (const struct dataset *ds UNUSED)
501 return xasprintf ("%d", settings_get_epoch ());
505 parse_ERRORS (struct lexer *lexer)
507 return parse_output_routing (lexer, SETTINGS_OUTPUT_ERROR);
511 show_ERRORS (const struct dataset *ds UNUSED)
513 return show_output_routing (SETTINGS_OUTPUT_ERROR);
517 parse_FORMAT (struct lexer *lexer)
521 lex_match (lexer, T_EQUALS);
522 if (!parse_format_specifier (lexer, &fmt))
525 if (!fmt_check_output (&fmt))
528 if (fmt_is_string (fmt.type))
530 char str[FMT_STRING_LEN_MAX + 1];
531 msg (SE, _("%s requires numeric output format as an argument. "
532 "Specified format %s is of type string."),
534 fmt_to_string (&fmt, str));
538 settings_set_format (&fmt);
543 show_FORMAT (const struct dataset *ds UNUSED)
545 char str[FMT_STRING_LEN_MAX + 1];
546 return xstrdup (fmt_to_string (settings_get_format (), str));
550 parse_FUZZBITS (struct lexer *lexer)
552 if (!lex_force_int_range (lexer, "FUZZITS", 0, 20))
554 settings_set_fuzzbits (lex_integer (lexer));
560 show_FUZZBITS (const struct dataset *ds UNUSED)
562 return xasprintf ("%d", settings_get_fuzzbits ());
566 parse_HEADER (struct lexer *lexer)
568 return parse_unimplemented (lexer, "HEADER");
572 parse_INCLUDE (struct lexer *lexer)
574 int include = force_parse_bool (lexer);
576 settings_set_include (include);
577 return include != -1;
581 show_INCLUDE (const struct dataset *ds UNUSED)
583 return xstrdup (settings_get_include () ? "ON" : "OFF");
587 parse_JOURNAL (struct lexer *lexer)
589 int b = parse_bool (lexer);
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 show_JOURNAL (const struct dataset *ds UNUSED)
613 const char *enabled = journal_is_enabled () ? "ON" : "OFF";
614 const char *file_name = journal_get_file_name ();
616 ? xasprintf ("%s (%s)", enabled, file_name)
617 : xstrdup (enabled));
621 parse_LENGTH (struct lexer *lexer)
625 if (lex_match_id (lexer, "NONE"))
629 if (!lex_force_int_range (lexer, "LENGTH", 1, INT_MAX))
631 page_length = lex_integer (lexer);
635 if (page_length != -1)
636 settings_set_viewlength (page_length);
642 show_LENGTH (const struct dataset *ds UNUSED)
644 return xasprintf ("%d", settings_get_viewlength ());
648 parse_LOCALE (struct lexer *lexer)
650 if (!lex_force_string (lexer))
653 /* Try the argument as an encoding name, then as a locale name or alias. */
654 const char *s = lex_tokcstr (lexer);
655 if (valid_encoding (s))
656 set_default_encoding (s);
657 else if (!set_encoding_from_locale (s))
659 msg (ME, _("%s is not a recognized encoding or locale name"), s);
668 show_LOCALE (const struct dataset *ds UNUSED)
670 return xstrdup (get_default_encoding ());
674 parse_MDISPLAY (struct lexer *lexer)
676 int mdisplay = force_parse_enum (lexer,
677 "TEXT", SETTINGS_MDISPLAY_TEXT,
678 "TABLES", SETTINGS_MDISPLAY_TABLES);
680 settings_set_mdisplay (mdisplay);
681 return mdisplay >= 0;
685 show_MDISPLAY (const struct dataset *ds UNUSED)
687 return xstrdup (settings_get_mdisplay () == SETTINGS_MDISPLAY_TEXT
688 ? "TEXT" : "TABLES");
692 parse_MESSAGES (struct lexer *lexer)
694 return parse_output_routing (lexer, SETTINGS_OUTPUT_NOTE);
698 show_MESSAGES (const struct dataset *ds UNUSED)
700 return show_output_routing (SETTINGS_OUTPUT_NOTE);
704 parse_MEXPAND (struct lexer *lexer)
706 int mexpand = force_parse_bool (lexer);
708 settings_set_mexpand (mexpand);
709 return mexpand != -1;
713 show_MEXPAND (const struct dataset *ds UNUSED)
715 return xstrdup (settings_get_mexpand () ? "ON" : "OFF");
719 parse_MITERATE (struct lexer *lexer)
721 if (!lex_force_int_range (lexer, "MITERATE", 1, INT_MAX))
723 settings_set_miterate (lex_integer (lexer));
729 show_MITERATE (const struct dataset *ds UNUSED)
731 return xasprintf ("%d", settings_get_miterate ());
735 parse_MNEST (struct lexer *lexer)
737 if (!lex_force_int_range (lexer, "MNEST", 1, INT_MAX))
739 settings_set_mnest (lex_integer (lexer));
745 show_MNEST (const struct dataset *ds UNUSED)
747 return xasprintf ("%d", settings_get_mnest ());
751 parse_MPRINT (struct lexer *lexer)
753 int mprint = force_parse_bool (lexer);
755 settings_set_mprint (mprint);
760 show_MPRINT (const struct dataset *ds UNUSED)
762 return xstrdup (settings_get_mprint () ? "ON" : "OFF");
766 parse_MXERRS (struct lexer *lexer)
769 if (!force_parse_int (lexer, &n))
773 settings_set_max_messages (MSG_S_ERROR, n);
775 msg (SE, _("%s must be at least 1."), "MXERRS");
780 show_MXERRS (const struct dataset *ds UNUSED)
782 return xasprintf ("%d", settings_get_max_messages (MSG_S_ERROR));
786 parse_MXLOOPS (struct lexer *lexer)
789 if (!force_parse_int (lexer, &n))
793 settings_set_mxloops (n);
795 msg (SE, _("%s must be at least 1."), "MXLOOPS");
800 show_MXLOOPS (const struct dataset *ds UNUSED)
802 return xasprintf ("%d", settings_get_mxloops ());
806 parse_MXWARNS (struct lexer *lexer)
809 if (!force_parse_int (lexer, &n))
813 settings_set_max_messages (MSG_S_WARNING, n);
815 msg (SE, _("%s must not be negative."), "MXWARNS");
820 show_MXWARNS (const struct dataset *ds UNUSED)
822 return xasprintf ("%d", settings_get_max_messages (MSG_S_WARNING));
826 parse_PRINTBACK (struct lexer *lexer)
828 return parse_output_routing (lexer, SETTINGS_OUTPUT_SYNTAX);
832 show_PRINTBACK (const struct dataset *ds UNUSED)
834 return show_output_routing (SETTINGS_OUTPUT_SYNTAX);
838 parse_RESULTS (struct lexer *lexer)
840 return parse_output_routing (lexer, SETTINGS_OUTPUT_RESULT);
844 show_RESULTS (const struct dataset *ds UNUSED)
846 return show_output_routing (SETTINGS_OUTPUT_RESULT);
850 parse_RIB (struct lexer *lexer)
852 return parse_integer_format (lexer, settings_set_input_integer_format);
856 show_RIB (const struct dataset *ds UNUSED)
858 return show_integer_format (settings_get_input_integer_format ());
862 parse_RRB (struct lexer *lexer)
864 return parse_real_format (lexer, settings_set_input_float_format);
868 show_RRB (const struct dataset *ds UNUSED)
870 return show_real_format (settings_get_input_float_format ());
874 parse_SAFER (struct lexer *lexer)
876 bool ok = force_parse_enum (lexer, "ON", true, "YES", true) != -1;
878 settings_set_safer_mode ();
883 show_SAFER (const struct dataset *ds UNUSED)
885 return xstrdup (settings_get_safer_mode () ? "ON" : "OFF");
889 parse_SCOMPRESSION (struct lexer *lexer)
891 int value = force_parse_bool (lexer);
893 settings_set_scompression (value);
898 show_SCOMPRESSION (const struct dataset *ds UNUSED)
900 return xstrdup (settings_get_scompression () ? "ON" : "OFF");
904 parse_SEED (struct lexer *lexer)
906 if (lex_match_id (lexer, "RANDOM"))
910 if (!lex_force_num (lexer))
912 set_rng (lex_number (lexer));
920 parse_SMALL (struct lexer *lexer)
922 if (!lex_force_num (lexer))
924 settings_set_small (lex_number (lexer));
930 show_SMALL (const struct dataset *ds UNUSED)
932 char buf[DBL_BUFSIZE_BOUND];
933 if (dtoastr (buf, sizeof buf, 0, 0, settings_get_small ()) < 0)
935 return xstrdup (buf);
939 show_SUBTITLE (const struct dataset *ds UNUSED)
941 return xstrdup (output_get_subtitle ());
945 show_TEMPDIR (const struct dataset *ds UNUSED)
947 return xstrdup (temp_dir_name ());
951 show_TITLE (const struct dataset *ds UNUSED)
953 return xstrdup (output_get_title ());
957 parse_TNUMBERS (struct lexer *lexer)
959 int value = force_parse_enum (lexer,
960 "LABELS", SETTINGS_VALUE_SHOW_LABEL,
961 "VALUES", SETTINGS_VALUE_SHOW_VALUE,
962 "BOTH", SETTINGS_VALUE_SHOW_BOTH);
964 settings_set_show_values (value);
969 show_TNUMBERS (const struct dataset *ds UNUSED)
971 enum settings_value_show tnumbers = settings_get_show_values ();
972 return xstrdup (tnumbers == SETTINGS_VALUE_SHOW_LABEL ? "LABELS"
973 : tnumbers == SETTINGS_VALUE_SHOW_VALUE ? "VALUES"
978 parse_TVARS (struct lexer *lexer)
980 int value = force_parse_enum (lexer,
981 "LABELS", SETTINGS_VALUE_SHOW_LABEL,
982 "NAMES", SETTINGS_VALUE_SHOW_VALUE,
983 "BOTH", SETTINGS_VALUE_SHOW_BOTH);
985 settings_set_show_variables (value);
990 show_TVARS (const struct dataset *ds UNUSED)
992 enum settings_value_show tvars = settings_get_show_variables ();
993 return xstrdup (tvars == SETTINGS_VALUE_SHOW_LABEL ? "LABELS"
994 : tvars == SETTINGS_VALUE_SHOW_VALUE ? "NAMES"
999 parse_TLOOK (struct lexer *lexer)
1001 if (lex_match_id (lexer, "NONE"))
1002 pivot_table_look_set_default (pivot_table_look_builtin_default ());
1003 else if (lex_is_string (lexer))
1005 struct pivot_table_look *look;
1006 char *error = pivot_table_look_read (lex_tokcstr (lexer), &look);
1011 msg (SE, "%s", error);
1016 pivot_table_look_set_default (look);
1017 pivot_table_look_unref (look);
1024 parse_UNDEFINED (struct lexer *lexer)
1026 int value = force_parse_enum (lexer,
1030 settings_set_undefined (value);
1035 show_UNDEFINED (const struct dataset *ds UNUSED)
1037 return xstrdup (settings_get_undefined () ? "WARN" : "NOWARN");
1041 show_VERSION (const struct dataset *ds UNUSED)
1043 return strdup (announced_version);
1047 show_WEIGHT (const struct dataset *ds)
1049 const struct variable *var = dict_get_weight (dataset_dict (ds));
1050 return xstrdup (var != NULL ? var_get_name (var) : "OFF");
1054 parse_WIB (struct lexer *lexer)
1056 return parse_integer_format (lexer, settings_set_output_integer_format);
1060 show_WIB (const struct dataset *ds UNUSED)
1062 return show_integer_format (settings_get_output_integer_format ());
1066 parse_WRB (struct lexer *lexer)
1068 return parse_real_format (lexer, settings_set_output_float_format);
1072 show_WRB (const struct dataset *ds UNUSED)
1074 return show_real_format (settings_get_output_float_format ());
1078 parse_WIDTH (struct lexer *lexer)
1080 if (lex_match_id (lexer, "NARROW"))
1081 settings_set_viewwidth (79);
1082 else if (lex_match_id (lexer, "WIDE"))
1083 settings_set_viewwidth (131);
1086 if (!lex_force_int_range (lexer, "WIDTH", 40, INT_MAX))
1088 settings_set_viewwidth (lex_integer (lexer));
1096 show_WIDTH (const struct dataset *ds UNUSED)
1098 return xasprintf ("%d", settings_get_viewwidth ());
1102 parse_WORKSPACE (struct lexer *lexer)
1104 if (!lex_force_int_range (lexer, "WORKSPACE",
1105 settings_get_testing_mode () ? 1 : 1024,
1108 int workspace = lex_integer (lexer);
1110 settings_set_workspace (MIN (workspace, INT_MAX / 1024) * 1024);
1115 show_WORKSPACE (const struct dataset *ds UNUSED)
1117 size_t ws = settings_get_workspace () / 1024L;
1118 return xasprintf ("%zu", ws);
1122 show_DIRECTORY (const struct dataset *ds UNUSED)
1131 buf = xrealloc (buf, len);
1133 while (NULL == (wd = getcwd (buf, len)));
1139 show_N (const struct dataset *ds)
1141 const struct casereader *reader = dataset_source (ds);
1143 ? xasprintf ("%lld", (long long int) casereader_count_cases (reader))
1144 : xstrdup (_("Unknown")));
1148 do_show (const struct dataset *ds, const struct setting *s)
1150 char *value = s->show (ds);
1151 msg (SN, _("%s is %s."), s->name, value ? value : _("empty"));
1156 show_warranty (const struct dataset *ds UNUSED)
1158 fputs (lack_of_warranty, stdout);
1162 show_copying (const struct dataset *ds UNUSED)
1164 fputs (copyleft, stdout);
1168 add_row (struct pivot_table *table, const char *attribute,
1171 int row = pivot_category_create_leaf (table->dimensions[0]->root,
1172 pivot_value_new_text (attribute));
1174 pivot_table_put1 (table, row, pivot_value_new_user_text (value, -1));
1178 show_system (const struct dataset *ds UNUSED)
1180 struct pivot_table *table = pivot_table_create (N_("System Information"));
1181 pivot_dimension_create (table, PIVOT_AXIS_ROW, N_("Attribute"));
1183 add_row (table, N_("Version"), version);
1184 add_row (table, N_("Host System"), host_system);
1185 add_row (table, N_("Build System"), build_system);
1186 add_row (table, N_("Locale Directory"), relocate (locale_dir));
1187 add_row (table, N_("Compiler Version"),
1194 pivot_table_submit (table);
1197 static const struct setting settings[] = {
1198 { "BASETEXTDIRECTION", parse_BASETEXTDIRECTION, NULL },
1199 { "BLANKS", parse_BLANKS, show_BLANKS },
1200 { "BLOCK", parse_BLOCK, NULL },
1201 { "BOX", parse_BOX, NULL },
1202 { "CACHE", parse_CACHE, NULL },
1203 { "CCA", parse_CCA, show_CCA },
1204 { "CCB", parse_CCB, show_CCB },
1205 { "CCC", parse_CCC, show_CCC },
1206 { "CCD", parse_CCD, show_CCD },
1207 { "CCE", parse_CCE, show_CCE },
1208 { "CELLSBREAK", parse_CELLSBREAK, NULL },
1209 { "CMPTRANS", parse_CMPTRANS, NULL },
1210 { "COMPRESSION", parse_COMPRESSION, NULL },
1211 { "CTEMPLATE", parse_CTEMPLATE, NULL },
1212 { "DECIMAL", parse_DECIMAL, show_DECIMAL },
1213 { "DIRECTORY", NULL, show_DIRECTORY },
1214 { "EPOCH", parse_EPOCH, show_EPOCH },
1215 { "ERRORS", parse_ERRORS, show_ERRORS },
1216 { "FORMAT", parse_FORMAT, show_FORMAT },
1217 { "FUZZBITS", parse_FUZZBITS, show_FUZZBITS },
1218 { "HEADER", parse_HEADER, NULL },
1219 { "INCLUDE", parse_INCLUDE, show_INCLUDE },
1220 { "JOURNAL", parse_JOURNAL, show_JOURNAL },
1221 { "LENGTH", parse_LENGTH, show_LENGTH },
1222 { "LOCALE", parse_LOCALE, show_LOCALE },
1223 { "MDISPLAY", parse_MDISPLAY, show_MDISPLAY },
1224 { "MESSAGES", parse_MESSAGES, show_MESSAGES },
1225 { "MEXPAND", parse_MEXPAND, show_MEXPAND },
1226 { "MITERATE", parse_MITERATE, show_MITERATE },
1227 { "MNEST", parse_MNEST, show_MNEST },
1228 { "MPRINT", parse_MPRINT, show_MPRINT },
1229 { "MXERRS", parse_MXERRS, show_MXERRS },
1230 { "MXLOOPS", parse_MXLOOPS, show_MXLOOPS },
1231 { "MXWARNS", parse_MXWARNS, show_MXWARNS },
1232 { "N", NULL, show_N },
1233 { "PRINTBACK", parse_PRINTBACK, show_PRINTBACK },
1234 { "RESULTS", parse_RESULTS, show_RESULTS },
1235 { "RIB", parse_RIB, show_RIB },
1236 { "RRB", parse_RRB, show_RRB },
1237 { "SAFER", parse_SAFER, show_SAFER },
1238 { "SCOMPRESSION", parse_SCOMPRESSION, show_SCOMPRESSION },
1239 { "SEED", parse_SEED, NULL },
1240 { "SMALL", parse_SMALL, show_SMALL },
1241 { "TEMPDIR", NULL, show_TEMPDIR },
1242 { "TNUMBERS", parse_TNUMBERS, show_TNUMBERS },
1243 { "TVARS", parse_TVARS, show_TVARS },
1244 { "TLOOK", parse_TLOOK, NULL },
1245 { "UNDEFINED", parse_UNDEFINED, show_UNDEFINED },
1246 { "VERSION", NULL, show_VERSION },
1247 { "WEIGHT", NULL, show_WEIGHT },
1248 { "WIB", parse_WIB, show_WIB },
1249 { "WRB", parse_WRB, show_WRB },
1250 { "WIDTH", parse_WIDTH, show_WIDTH },
1251 { "WORKSPACE", parse_WORKSPACE, show_WORKSPACE },
1253 enum { N_SETTINGS = sizeof settings / sizeof *settings };
1256 parse_setting (struct lexer *lexer)
1258 for (size_t i = 0; i < N_SETTINGS; i++)
1259 if (settings[i].set && match_subcommand (lexer, settings[i].name))
1260 return settings[i].set (lexer);
1262 lex_error (lexer, NULL);
1267 cmd_set (struct lexer *lexer, struct dataset *ds UNUSED)
1271 lex_match (lexer, T_SLASH);
1272 if (lex_token (lexer) == T_ENDCMD)
1275 if (!parse_setting (lexer))
1283 show_all (const struct dataset *ds)
1285 for (size_t i = 0; i < sizeof settings / sizeof *settings; i++)
1286 if (settings[i].show)
1287 do_show (ds, &settings[i]);
1291 show_all_cc (const struct dataset *ds)
1293 for (size_t i = 0; i < sizeof settings / sizeof *settings; i++)
1295 const struct setting *s = &settings[i];
1296 if (s->show && !strncmp (s->name, "CC", 2))
1302 cmd_show (struct lexer *lexer, struct dataset *ds)
1304 if (lex_token (lexer) == T_ENDCMD)
1312 if (lex_match (lexer, T_ALL))
1314 else if (lex_match_id (lexer, "CC"))
1316 else if (lex_match_id (lexer, "WARRANTY"))
1318 else if (lex_match_id (lexer, "COPYING") || lex_match_id (lexer, "LICENSE"))
1320 else if (lex_match_id (lexer, "SYSTEM"))
1322 else if (lex_match_id (lexer, "TITLE"))
1324 struct setting s = { .name = "TITLE", .show = show_TITLE };
1327 else if (lex_match_id (lexer, "SUBTITLE"))
1329 struct setting s = { .name = "SUBTITLE", .show = show_SUBTITLE };
1332 else if (lex_token (lexer) == T_ID)
1336 for (i = 0; i < sizeof settings / sizeof *settings; i++)
1338 const struct setting *s = &settings[i];
1339 if (s->show && lex_match_id (lexer, s->name))
1345 lex_error (lexer, NULL);
1352 lex_error (lexer, NULL);
1356 lex_match (lexer, T_SLASH);
1358 while (lex_token (lexer) != T_ENDCMD);
1363 #define MAX_SAVED_SETTINGS 5
1365 static struct settings *saved_settings[MAX_SAVED_SETTINGS];
1366 static int n_saved_settings;
1369 cmd_preserve (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
1371 if (n_saved_settings < MAX_SAVED_SETTINGS)
1373 saved_settings[n_saved_settings++] = settings_get ();
1378 msg (SE, _("Too many %s commands without a %s: at most "
1379 "%d levels of saved settings are allowed."),
1380 "PRESERVE", "RESTORE",
1381 MAX_SAVED_SETTINGS);
1382 return CMD_CASCADING_FAILURE;
1387 cmd_restore (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
1389 if (n_saved_settings > 0)
1391 struct settings *s = saved_settings[--n_saved_settings];
1393 settings_destroy (s);
1398 msg (SE, _("%s without matching %s."), "RESTORE", "PRESERVE");