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