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