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