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