d264a00ef95880dc4a16155eb1305f6836f77e64
[pspp-builds.git] / src / language / utilities / set.q
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2006, 2009 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #include <config.h>
18
19 #include <stdio.h>
20 #include <errno.h>
21 #include <stdlib.h>
22 #include <time.h>
23
24 #include <data/data-in.h>
25 #include <data/data-out.h>
26 #include <data/dictionary.h>
27 #include <data/format.h>
28 #include <data/procedure.h>
29 #include <data/settings.h>
30 #include <data/value.h>
31 #include <data/variable.h>
32 #include <language/command.h>
33 #include <language/lexer/format-parser.h>
34 #include <language/lexer/lexer.h>
35 #include <language/prompt.h>
36 #include <libpspp/compiler.h>
37 #include <libpspp/copyleft.h>
38 #include <libpspp/float-format.h>
39 #include <libpspp/integer-format.h>
40 #include <libpspp/message.h>
41 #include <libpspp/i18n.h>
42 #include <math/random.h>
43 #include <output/journal.h>
44 #include <output/output.h>
45
46 #if HAVE_LIBTERMCAP
47 #if HAVE_TERMCAP_H
48 #include <termcap.h>
49 #else /* !HAVE_TERMCAP_H */
50 int tgetent (char *, const char *);
51 int tgetnum (const char *);
52 #endif /* !HAVE_TERMCAP_H */
53 #endif /* !HAVE_LIBTERMCAP */
54
55 #include "xalloc.h"
56
57 #include "gettext.h"
58 #define _(msgid) gettext (msgid)
59
60 /* (specification)
61    "SET" (stc_):
62      blanks=custom;
63      block=string "x==1" "one character long";
64      boxstring=string "x==3 || x==11" "3 or 11 characters long";
65      case=size:upper/uplow;
66      cca=string;
67      ccb=string;
68      ccc=string;
69      ccd=string;
70      cce=string;
71      compression=compress:on/off;
72      cpi=integer "x>0" "%s must be greater than 0";
73      cprompt=string;
74      decimal=dec:dot/comma;
75      disk=custom;
76      dprompt=string;
77      echo=echo:on/off;
78      endcmd=string "x==1" "one character long";
79      epoch=custom;
80      errorbreak=errbrk:on/off;
81      errors=errors:terminal/listing/both/on/none/off;
82      format=custom;
83      headers=headers:no/yes/blank;
84      highres=hires:on/off;
85      histogram=string "x==1" "one character long";
86      include=inc:on/off;
87      journal=custom;
88      log=custom;
89      length=custom;
90      locale=custom;
91      listing=custom;
92      lowres=lores:auto/on/off;
93      lpi=integer "x>0" "%s must be greater than 0";
94      menus=menus:standard/extended;
95      messages=messages:on/off/terminal/listing/both/on/none/off;
96      mexpand=mexp:on/off;
97      miterate=integer "x>0" "%s must be greater than 0";
98      mnest=integer "x>0" "%s must be greater than 0";
99      mprint=mprint:on/off;
100      mxerrs=integer "x >= 1" "%s must be at least 1";
101      mxloops=integer "x >=1" "%s must be at least 1";
102      mxmemory=integer;
103      mxwarns=integer;
104      nulline=null:on/off;
105      printback=prtbck:on/off;
106      prompt=string;
107      results=res:on/off/terminal/listing/both/on/none/off;
108      rib=rib:msbfirst/lsbfirst/vax/native;
109      rrb=rrb:native/isl/isb/idl/idb/vf/vd/vg/zs/zl;
110      safer=safe:on;
111      scompression=scompress:on/off;
112      scripttab=string "x==1" "one character long";
113      seed=custom;
114      tb1=string "x==3 || x==11" "3 or 11 characters long";
115      tbfonts=string;
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;
119      width=custom;
120      workspace=integer "x>0" "%s must be positive";
121      xsort=xsort:yes/no.
122 */
123
124 /* (headers) */
125
126 /* (declarations) */
127
128 /* (functions) */
129
130 static enum integer_format stc_to_integer_format (int stc);
131 static enum float_format stc_to_float_format (int stc);
132
133 int
134 cmd_set (struct lexer *lexer, struct dataset *ds)
135 {
136   struct cmd_set cmd;
137
138   if (!parse_set (lexer, ds, &cmd, NULL))
139     {
140       free_set (&cmd);
141       return CMD_FAILURE;
142     }
143
144   if (cmd.sbc_cca)
145     settings_set_cc ( cmd.s_cca, FMT_CCA);
146   if (cmd.sbc_ccb)
147     settings_set_cc ( cmd.s_ccb, FMT_CCB);
148   if (cmd.sbc_ccc)
149     settings_set_cc ( cmd.s_ccc, FMT_CCC);
150   if (cmd.sbc_ccd)
151     settings_set_cc ( cmd.s_ccd, FMT_CCD);
152   if (cmd.sbc_cce)
153     settings_set_cc ( cmd.s_cce, FMT_CCE);
154
155   if (cmd.sbc_prompt)
156     prompt_set (PROMPT_FIRST, cmd.s_prompt);
157   if (cmd.sbc_cprompt)
158     prompt_set (PROMPT_LATER, cmd.s_cprompt);
159   if (cmd.sbc_dprompt)
160     prompt_set (PROMPT_DATA, cmd.s_dprompt);
161
162   if (cmd.sbc_decimal)
163     settings_set_decimal_char (cmd.dec == STC_DOT ? '.' : ',');
164
165   if (cmd.sbc_echo)
166     settings_set_echo (cmd.echo == STC_ON);
167   if (cmd.sbc_endcmd)
168     settings_set_endcmd (cmd.s_endcmd[0]);
169   if (cmd.sbc_errorbreak)
170     settings_set_errorbreak (cmd.errbrk == STC_ON);
171   if (cmd.sbc_errors)
172     {
173       bool both = cmd.errors == STC_BOTH || cmd.errors == STC_ON;
174       settings_set_error_routing_to_terminal (cmd.errors == STC_TERMINAL || both);
175       settings_set_error_routing_to_listing (cmd.errors == STC_LISTING || both);
176     }
177   if (cmd.sbc_include)
178     settings_set_include (cmd.inc == STC_ON);
179   if (cmd.sbc_mxerrs)
180     settings_set_mxerrs (cmd.n_mxerrs[0]);
181   if (cmd.sbc_mxwarns)
182     settings_set_mxwarns (cmd.n_mxwarns[0]);
183   if (cmd.sbc_nulline)
184     settings_set_nulline (cmd.null == STC_ON);
185   if (cmd.sbc_rib)
186     settings_set_input_integer_format (stc_to_integer_format (cmd.rib));
187   if (cmd.sbc_rrb)
188     settings_set_input_float_format (stc_to_float_format (cmd.rrb));
189   if (cmd.sbc_safer)
190     settings_set_safer_mode ();
191   if (cmd.sbc_scompression)
192     settings_set_scompression (cmd.scompress == STC_ON);
193   if (cmd.sbc_undefined)
194     settings_set_undefined (cmd.undef == STC_WARN);
195   if (cmd.sbc_wib)
196     settings_set_output_integer_format (stc_to_integer_format (cmd.wib));
197   if (cmd.sbc_wrb)
198     settings_set_output_float_format (stc_to_float_format (cmd.wrb));
199   if (cmd.sbc_workspace)
200     {
201       if ( cmd.n_workspace[0] < 1024 && ! settings_get_testing_mode ())
202         msg (SE, _("WORKSPACE must be at least 1MB"));
203       else
204         settings_set_workspace (cmd.n_workspace[0] * 1024L);
205     }
206
207   if (cmd.sbc_block)
208     msg (SW, _("%s is obsolete."), "BLOCK");
209   if (cmd.sbc_boxstring)
210     msg (SW, _("%s is obsolete."), "BOXSTRING");
211   if (cmd.sbc_histogram)
212     msg (SW, _("%s is obsolete."), "HISTOGRAM");
213   if (cmd.sbc_menus)
214     msg (SW, _("%s is obsolete."), "MENUS");
215   if (cmd.sbc_xsort)
216     msg (SW, _("%s is obsolete."), "XSORT");
217   if (cmd.sbc_mxmemory)
218     msg (SE, _("%s is obsolete."), "MXMEMORY");
219   if (cmd.sbc_scripttab)
220     msg (SE, _("%s is obsolete."), "SCRIPTTAB");
221   if (cmd.sbc_tbfonts)
222     msg (SW, _("%s is obsolete."), "TBFONTS");
223   if (cmd.sbc_tb1 && cmd.s_tb1)
224     msg (SW, _("%s is obsolete."), "TB1");
225
226   if (cmd.sbc_case)
227     msg (SW, _("%s is not implemented."), "CASE");
228
229   if (cmd.sbc_compression)
230     msg (SW, _("Active file compression is not implemented."));
231
232   free_set (&cmd);
233
234   return CMD_SUCCESS;
235 }
236
237 /* Returns the integer_format value corresponding to STC,
238    which should be the value of cmd.rib or cmd.wib. */
239 static enum integer_format
240 stc_to_integer_format (int stc)
241 {
242   return (stc == STC_MSBFIRST ? INTEGER_MSB_FIRST
243           : stc == STC_LSBFIRST ? INTEGER_LSB_FIRST
244           : stc == STC_VAX ? INTEGER_VAX
245           : INTEGER_NATIVE);
246 }
247
248 /* Returns the float_format value corresponding to STC,
249    which should be the value of cmd.rrb or cmd.wrb. */
250 static enum float_format
251 stc_to_float_format (int stc)
252 {
253   switch (stc)
254     {
255     case STC_NATIVE:
256       return FLOAT_NATIVE_DOUBLE;
257
258     case STC_ISL:
259       return FLOAT_IEEE_SINGLE_LE;
260     case STC_ISB:
261       return FLOAT_IEEE_SINGLE_BE;
262     case STC_IDL:
263       return FLOAT_IEEE_DOUBLE_LE;
264     case STC_IDB:
265       return FLOAT_IEEE_DOUBLE_BE;
266
267     case STC_VF:
268       return FLOAT_VAX_F;
269     case STC_VD:
270       return FLOAT_VAX_D;
271     case STC_VG:
272       return FLOAT_VAX_G;
273
274     case STC_ZS:
275       return FLOAT_Z_SHORT;
276     case STC_ZL:
277       return FLOAT_Z_LONG;
278     }
279
280   NOT_REACHED ();
281 }
282
283
284
285 /* Parses the BLANKS subcommand, which controls the value that
286    completely blank fields in numeric data imply.  X, Wnd: Syntax is
287    SYSMIS or a numeric value. */
288 static int
289 stc_custom_blanks (struct lexer *lexer,
290                    struct dataset *ds UNUSED,
291                    struct cmd_set *cmd UNUSED, void *aux UNUSED)
292 {
293   lex_match (lexer, '=');
294   if (lex_match_id (lexer, "SYSMIS"))
295     {
296       lex_get (lexer);
297       settings_set_blanks (SYSMIS);
298     }
299   else
300     {
301       if (!lex_force_num (lexer))
302         return 0;
303       settings_set_blanks (lex_number (lexer));
304       lex_get (lexer);
305     }
306   return 1;
307 }
308
309 /* Parses the EPOCH subcommand, which controls the epoch used for
310    parsing 2-digit years. */
311 static int
312 stc_custom_epoch (struct lexer *lexer,
313                   struct dataset *ds UNUSED,
314                   struct cmd_set *cmd UNUSED, void *aux UNUSED)
315 {
316   lex_match (lexer, '=');
317   if (lex_match_id (lexer, "AUTOMATIC"))
318     settings_set_epoch (-1);
319   else if (lex_is_integer (lexer))
320     {
321       int new_epoch = lex_integer (lexer);
322       lex_get (lexer);
323       if (new_epoch < 1500)
324         {
325           msg (SE, _("EPOCH must be 1500 or later."));
326           return 0;
327         }
328       settings_set_epoch (new_epoch);
329     }
330   else
331     {
332       lex_error (lexer, _("expecting AUTOMATIC or year"));
333       return 0;
334     }
335
336   return 1;
337 }
338
339 static int
340 stc_custom_length (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
341 {
342   int page_length;
343
344   lex_match (lexer, '=');
345   if (lex_match_id (lexer, "NONE"))
346     page_length = -1;
347   else
348     {
349       if (!lex_force_int (lexer))
350         return 0;
351       if (lex_integer (lexer) < 1)
352         {
353           msg (SE, _("LENGTH must be at least 1."));
354           return 0;
355         }
356       page_length = lex_integer (lexer);
357       lex_get (lexer);
358     }
359
360   if (page_length != -1)
361     settings_set_viewlength (page_length);
362
363   return 1;
364 }
365
366 static int
367 stc_custom_locale (struct lexer *lexer, struct dataset *ds UNUSED,
368                    struct cmd_set *cmd UNUSED, void *aux UNUSED)
369 {
370   const struct string *s;
371
372   lex_match (lexer, '=');
373
374   if ( !lex_force_string (lexer))
375     return 0;
376
377   s = lex_tokstr (lexer);
378
379   /* First try this string as an encoding name */
380   if ( valid_encoding (ds_cstr (s)))
381     set_default_encoding (ds_cstr (s));
382
383   /* Now try as a locale name (or alias) */
384   else if (set_encoding_from_locale (ds_cstr (s)))
385     {
386     }
387   else
388     {
389       msg (ME, _("%s is not a recognised encoding or locale name"),
390            ds_cstr (s));
391       return 0;
392     }
393
394   lex_get (lexer);
395
396   return 1;
397 }
398
399
400
401 static int
402 stc_custom_seed (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
403 {
404   lex_match (lexer, '=');
405   if (lex_match_id (lexer, "RANDOM"))
406     set_rng (time (0));
407   else
408     {
409       if (!lex_force_num (lexer))
410         return 0;
411       set_rng (lex_number (lexer));
412       lex_get (lexer);
413     }
414
415   return 1;
416 }
417
418 static int
419 stc_custom_width (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
420 {
421   lex_match (lexer, '=');
422   if (lex_match_id (lexer, "NARROW"))
423     settings_set_viewwidth (79);
424   else if (lex_match_id (lexer, "WIDE"))
425     settings_set_viewwidth (131);
426   else
427     {
428       if (!lex_force_int (lexer))
429         return 0;
430       if (lex_integer (lexer) < 40)
431         {
432           msg (SE, _("WIDTH must be at least 40."));
433           return 0;
434         }
435       settings_set_viewwidth (lex_integer (lexer));
436       lex_get (lexer);
437     }
438
439   return 1;
440 }
441
442 /* Parses FORMAT subcommand, which consists of a numeric format
443    specifier. */
444 static int
445 stc_custom_format (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
446 {
447   struct fmt_spec fmt;
448
449   lex_match (lexer, '=');
450   if (!parse_format_specifier (lexer, &fmt))
451     return 0;
452   if (fmt_is_string (fmt.type))
453     {
454       char str[FMT_STRING_LEN_MAX + 1];
455       msg (SE, _("FORMAT requires numeric output format as an argument.  "
456                  "Specified format %s is of type string."),
457            fmt_to_string (&fmt, str));
458       return 0;
459     }
460
461   settings_set_format (&fmt);
462   return 1;
463 }
464
465 static int
466 stc_custom_journal (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
467 {
468   lex_match (lexer, '=');
469   if (lex_match_id (lexer, "ON") || lex_match_id (lexer, "YES"))
470     journal_enable ();
471   else if (lex_match_id (lexer, "OFF") || lex_match_id (lexer, "NO"))
472     journal_disable ();
473   else if (lex_token (lexer) == T_STRING || lex_token (lexer) == T_ID)
474     {
475       journal_set_file_name (ds_cstr (lex_tokstr (lexer)));
476       lex_get (lexer);
477     }
478   else
479     {
480       lex_error (lexer, NULL);
481       return 0;
482     }
483   return 1;
484 }
485
486 static int
487 stc_custom_log (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
488 {
489   return stc_custom_journal (lexer, ds, cmd, aux);
490 }
491
492 static int
493 stc_custom_listing (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
494 {
495   bool listing;
496
497   lex_match (lexer, '=');
498   if (lex_match_id (lexer, "ON") || lex_match_id (lexer, "YES"))
499     listing = true;
500   else if (lex_match_id (lexer, "OFF") || lex_match_id (lexer, "NO"))
501     listing = false;
502   else
503     {
504       /* FIXME */
505       return 0;
506     }
507   outp_enable_device (listing, OUTP_DEV_LISTING);
508
509   return 1;
510 }
511
512 static int
513 stc_custom_disk (struct lexer *lexer, struct dataset *ds, struct cmd_set *cmd UNUSED, void *aux)
514 {
515   return stc_custom_listing (lexer, ds, cmd, aux);
516 }
517 \f
518 static void
519 show_blanks (const struct dataset *ds UNUSED)
520 {
521   if (settings_get_blanks () == SYSMIS)
522     msg (SN, _("BLANKS is SYSMIS."));
523   else
524     msg (SN, _("BLANKS is %g."), settings_get_blanks ());
525
526 }
527
528 static char *
529 format_cc (struct substring in, char grouping, char *out)
530 {
531   while (!ss_is_empty (in))
532     {
533       char c = ss_get_char (&in);
534       if (c == grouping || c == '\'')
535         *out++ = '\'';
536       else if (c == '"')
537         *out++ = '"';
538       *out++ = c;
539     }
540   return out;
541 }
542
543 static void
544 show_cc (enum fmt_type type)
545 {
546   const struct fmt_number_style *cc = settings_get_style (type);
547   char cc_string[FMT_STYLE_AFFIX_MAX * 4 * 2 + 3 + 1];
548   char *out;
549
550   out = format_cc (cc->neg_prefix, cc->grouping, cc_string);
551   *out++ = cc->grouping;
552   out = format_cc (cc->prefix, cc->grouping, out);
553   *out++ = cc->grouping;
554   out = format_cc (cc->suffix, cc->grouping, out);
555   *out++ = cc->grouping;
556   out = format_cc (cc->neg_suffix, cc->grouping, out);
557   *out = '\0';
558
559   msg (SN, _("%s is \"%s\"."), fmt_name (type), cc_string);
560 }
561
562 static void
563 show_cca (const struct dataset *ds UNUSED)
564 {
565   show_cc (FMT_CCA);
566 }
567
568 static void
569 show_ccb (const struct dataset *ds UNUSED)
570 {
571   show_cc (FMT_CCB);
572 }
573
574 static void
575 show_ccc (const struct dataset *ds UNUSED)
576 {
577   show_cc (FMT_CCC);
578 }
579
580 static void
581 show_ccd (const struct dataset *ds UNUSED)
582 {
583   show_cc (FMT_CCD);
584 }
585
586 static void
587 show_cce (const struct dataset *ds UNUSED)
588 {
589   show_cc (FMT_CCE);
590 }
591
592 static void
593 show_decimals (const struct dataset *ds UNUSED)
594 {
595   msg (SN, _("DECIMAL is \"%c\"."), settings_get_decimal_char (FMT_F));
596 }
597
598 static void
599 show_endcmd (const struct dataset *ds UNUSED)
600 {
601   msg (SN, _("ENDCMD is \"%c\"."), settings_get_endcmd ());
602 }
603
604 static void
605 show_errors (const struct dataset *ds UNUSED)
606 {
607   bool terminal = settings_get_error_routing_to_terminal ();
608   bool listing = settings_get_error_routing_to_listing ();
609   msg (SN, _("ERRORS is \"%s\"."),
610        terminal && listing ? "BOTH"
611        : terminal ? "TERMINAL"
612        : listing ? "LISTING"
613        : "NONE");
614 }
615
616 static void
617 show_format (const struct dataset *ds UNUSED)
618 {
619   char str[FMT_STRING_LEN_MAX + 1];
620   msg (SN, _("FORMAT is %s."), fmt_to_string (settings_get_format (), str));
621 }
622
623 static void
624 show_length (const struct dataset *ds UNUSED)
625 {
626   msg (SN, _("LENGTH is %d."), settings_get_viewlength ());
627 }
628
629 static void
630 show_locale (const struct dataset *ds UNUSED)
631 {
632   msg (SN, _("LOCALE is %s"), get_default_encoding ());
633 }
634
635 static void
636 show_mxerrs (const struct dataset *ds UNUSED)
637 {
638   msg (SN, _("MXERRS is %d."), settings_get_mxerrs ());
639 }
640
641 static void
642 show_mxloops (const struct dataset *ds UNUSED)
643 {
644   msg (SN, _("MXLOOPS is %d."), settings_get_mxloops ());
645 }
646
647 static void
648 show_mxwarns (const struct dataset *ds UNUSED)
649 {
650   msg (SN, _("MXWARNS is %d."), settings_get_mxwarns ());
651 }
652
653 /* Outputs that SETTING has the given INTEGER_FORMAT value. */
654 static void
655 show_integer_format (const char *setting, enum integer_format integer_format)
656 {
657   msg (SN, _("%s is %s (%s)."),
658        setting,
659        (integer_format == INTEGER_MSB_FIRST ? "MSBFIRST"
660         : integer_format == INTEGER_LSB_FIRST ? "LSBFIRST"
661         : "VAX"),
662        integer_format == INTEGER_NATIVE ? "NATIVE" : "nonnative");
663 }
664
665 /* Outputs that SETTING has the given FLOAT_FORMAT value. */
666 static void
667 show_float_format (const char *setting, enum float_format float_format)
668 {
669   const char *format_name = "";
670
671   switch (float_format)
672     {
673     case FLOAT_IEEE_SINGLE_LE:
674       format_name = "ISL (32-bit IEEE 754 single, little-endian)";
675       break;
676     case FLOAT_IEEE_SINGLE_BE:
677       format_name = "ISB (32-bit IEEE 754 single, big-endian)";
678       break;
679     case FLOAT_IEEE_DOUBLE_LE:
680       format_name = "IDL (64-bit IEEE 754 double, little-endian)";
681       break;
682     case FLOAT_IEEE_DOUBLE_BE:
683       format_name = "IDB (64-bit IEEE 754 double, big-endian)";
684       break;
685
686     case FLOAT_VAX_F:
687       format_name = "VF (32-bit VAX F, VAX-endian)";
688       break;
689     case FLOAT_VAX_D:
690       format_name = "VD (64-bit VAX D, VAX-endian)";
691       break;
692     case FLOAT_VAX_G:
693       format_name = "VG (64-bit VAX G, VAX-endian)";
694       break;
695
696     case FLOAT_Z_SHORT:
697       format_name = "ZS (32-bit IBM Z hexadecimal short, big-endian)";
698       break;
699     case FLOAT_Z_LONG:
700       format_name = "ZL (64-bit IBM Z hexadecimal long, big-endian)";
701       break;
702
703     case FLOAT_FP:
704     case FLOAT_HEX:
705       NOT_REACHED ();
706     }
707
708   msg (SN, _("%s is %s (%s)."),
709        setting, format_name,
710        float_format == FLOAT_NATIVE_DOUBLE ? "NATIVE" : "nonnative");
711 }
712
713 static void
714 show_rib (const struct dataset *ds UNUSED)
715 {
716   show_integer_format ("RIB", settings_get_input_integer_format ());
717 }
718
719 static void
720 show_rrb (const struct dataset *ds UNUSED)
721 {
722   show_float_format ("RRB", settings_get_input_float_format ());
723 }
724
725 static void
726 show_scompression (const struct dataset *ds UNUSED)
727 {
728   if (settings_get_scompression ())
729     msg (SN, _("SCOMPRESSION is ON."));
730   else
731     msg (SN, _("SCOMPRESSION is OFF."));
732 }
733
734 static void
735 show_undefined (const struct dataset *ds UNUSED)
736 {
737   if (settings_get_undefined ())
738     msg (SN, _("UNDEFINED is WARN."));
739   else
740     msg (SN, _("UNDEFINED is NOWARN."));
741 }
742
743 static void
744 show_weight (const struct dataset *ds)
745 {
746   const struct variable *var = dict_get_weight (dataset_dict (ds));
747   if (var == NULL)
748     msg (SN, _("WEIGHT is off."));
749   else
750     msg (SN, _("WEIGHT is variable %s."), var_get_name (var));
751 }
752
753 static void
754 show_wib (const struct dataset *ds UNUSED)
755 {
756   show_integer_format ("WIB", settings_get_output_integer_format ());
757 }
758
759 static void
760 show_wrb (const struct dataset *ds UNUSED)
761 {
762   show_float_format ("WRB", settings_get_output_float_format ());
763 }
764
765 static void
766 show_width (const struct dataset *ds UNUSED)
767 {
768   msg (SN, _("WIDTH is %d."), settings_get_viewwidth ());
769 }
770
771 struct show_sbc
772   {
773     const char *name;
774     void (*function) (const struct dataset *);
775   };
776
777 const struct show_sbc show_table[] =
778   {
779     {"BLANKS", show_blanks},
780     {"CCA", show_cca},
781     {"CCB", show_ccb},
782     {"CCC", show_ccc},
783     {"CCD", show_ccd},
784     {"CCE", show_cce},
785     {"DECIMALS", show_decimals},
786     {"ENDCMD", show_endcmd},
787     {"ERRORS", show_errors},
788     {"FORMAT", show_format},
789     {"LENGTH", show_length},
790     {"LOCALE", show_locale},
791     {"MXERRS", show_mxerrs},
792     {"MXLOOPS", show_mxloops},
793     {"MXWARNS", show_mxwarns},
794     {"RIB", show_rib},
795     {"RRB", show_rrb},
796     {"SCOMPRESSION", show_scompression},
797     {"UNDEFINED", show_undefined},
798     {"WEIGHT", show_weight},
799     {"WIB", show_wib},
800     {"WRB", show_wrb},
801     {"WIDTH", show_width},
802   };
803
804 static void
805 show_all (const struct dataset *ds)
806 {
807   size_t i;
808
809   for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
810     show_table[i].function (ds);
811 }
812
813 static void
814 show_all_cc (void)
815 {
816   int i;
817
818   for (i = 0; i < 5; i++)
819     show_cc (i);
820 }
821
822 static void
823 show_warranty (const struct dataset *ds UNUSED)
824 {
825   fputs (lack_of_warranty, stdout);
826 }
827
828 static void
829 show_copying (const struct dataset *ds UNUSED)
830 {
831   fputs (copyleft, stdout);
832 }
833
834 int
835 cmd_show (struct lexer *lexer, struct dataset *ds)
836 {
837   if (lex_token (lexer) == '.')
838     {
839       show_all (ds);
840       return CMD_SUCCESS;
841     }
842
843   do
844     {
845       if (lex_match (lexer, T_ALL))
846         show_all (ds);
847       else if (lex_match_id (lexer, "CC"))
848         show_all_cc ();
849       else if (lex_match_id (lexer, "WARRANTY"))
850         show_warranty (ds);
851       else if (lex_match_id (lexer, "COPYING"))
852         show_copying (ds);
853       else if (lex_token (lexer) == T_ID)
854         {
855           int i;
856
857           for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
858             if (lex_match_id (lexer, show_table[i].name))
859               {
860                 show_table[i].function (ds);
861                 goto found;
862               }
863           lex_error (lexer, NULL);
864           return CMD_FAILURE;
865
866         found: ;
867         }
868       else
869         {
870           lex_error (lexer, NULL);
871           return CMD_FAILURE;
872         }
873
874       lex_match (lexer, '/');
875     }
876   while (lex_token (lexer) != '.');
877
878   return CMD_SUCCESS;
879 }
880
881 /*
882    Local Variables:
883    mode: c
884    End:
885 */