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