1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
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.
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.
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
29 #include "dictionary.h"
30 #include "line-buffer.h"
45 #else /* !HAVE_TERMCAP_H */
46 int tgetent (char *, const char *);
47 int tgetnum (const char *);
48 #endif /* !HAVE_TERMCAP_H */
49 #endif /* !HAVE_LIBTERMCAP */
52 #define _(msgid) gettext (msgid)
57 block=string "x==1" "one character long";
58 boxstring=string "x==3 || x==11" "3 or 11 characters long";
59 case=size:upper/uplow;
65 compression=compress:on/off;
66 cpi=integer "x>0" "%s must be greater than 0";
68 decimal=dec:dot/comma;
72 endcmd=string "x==1" "one character long";
74 errorbreak=errbrk:on/off;
75 errors=errors:on/off/terminal/listing/both/none;
77 headers=headers:no/yes/blank;
79 histogram=string "x==1" "one character long";
84 lowres=lores:auto/on/off;
85 lpi=integer "x>0" "%s must be greater than 0";
86 menus=menus:standard/extended;
87 messages=messages:on/off/terminal/listing/both/none;
89 miterate=integer "x>0" "%s must be greater than 0";
90 mnest=integer "x>0" "%s must be greater than 0";
92 mxerrs=integer "x >= 1" "%s must be at least 1";
93 mxloops=integer "x >=1" "%s must be at least 1";
97 printback=prtbck:on/off;
99 results=res:on/off/terminal/listing/both/none;
101 scompression=scompress:on/off;
102 scripttab=string "x==1" "one character long";
104 tb1=string "x==3 || x==11" "3 or 11 characters long";
106 undefined=undef:warn/nowarn;
108 workspace=integer "x>=1024" "%s must be at least 1 MB";
116 static bool do_cc (const char *cc_string, int idx);
124 if (!parse_set (&cmd))
128 ok = ok && do_cc (cmd.s_cca, 0);
130 ok = ok && do_cc (cmd.s_ccb, 1);
132 ok = ok && do_cc (cmd.s_ccc, 2);
134 ok = ok && do_cc (cmd.s_ccd, 3);
136 ok = ok && do_cc (cmd.s_cce, 4);
139 getl_set_prompt (GETL_PROMPT_FIRST, cmd.s_prompt);
141 getl_set_prompt (GETL_PROMPT_LATER, cmd.s_cprompt);
143 getl_set_prompt (GETL_PROMPT_DATA, cmd.s_dprompt);
146 set_decimal (cmd.dec == STC_DOT ? '.' : ',');
148 set_echo (cmd.echo == STC_ON);
150 set_endcmd (cmd.s_endcmd[0]);
151 if (cmd.sbc_errorbreak)
152 set_errorbreak (cmd.errbrk == STC_ON);
154 set_include (cmd.inc == STC_ON);
156 set_mxerrs (cmd.n_mxerrs[0]);
158 set_mxwarns (cmd.n_mxwarns[0]);
160 set_nulline (cmd.null == STC_ON);
163 if (cmd.sbc_scompression)
164 set_scompression (cmd.scompress == STC_ON);
165 if (cmd.sbc_undefined)
166 set_undefined (cmd.undef == STC_WARN);
167 if (cmd.sbc_workspace)
168 set_workspace (cmd.n_workspace[0] * 1024L);
171 msg (SW, _("%s is obsolete."),"BLOCK");
172 if (cmd.sbc_boxstring)
173 msg (SW, _("%s is obsolete."),"BOXSTRING");
174 if (cmd.sbc_histogram)
175 msg (MW, _("%s is obsolete."),"HISTOGRAM");
177 msg (MW, _("%s is obsolete."),"MENUS");
179 msg (SW, _("%s is obsolete."),"XSORT");
180 if (cmd.sbc_mxmemory )
181 msg (SE, _("%s is obsolete."),"MXMEMORY");
182 if (cmd.sbc_scripttab)
183 msg (SE, _("%s is obsolete."),"SCRIPTTAB");
185 msg (SW, _("%s is obsolete."),"TBFONTS");
186 if (cmd.sbc_tb1 && cmd.s_tb1)
187 msg (SW, _("%s is obsolete."),"TB1");
190 msg (SW, _("%s is not implemented."), "CASE");
192 if (cmd.sbc_compression)
193 msg (MW, _("Active file compression is not implemented."));
198 /* Find the grouping characters in CC_STRING and set CC's
199 grouping and decimal members appropriately. Returns true if
200 successful, false otherwise. */
202 find_cc_separators (const char *cc_string, struct custom_currency *cc)
205 int comma_cnt, dot_cnt;
207 /* Count commas and periods. There must be exactly three of
208 one or the other, except that an apostrophe acts escapes a
209 following comma or period. */
210 comma_cnt = dot_cnt = 0;
211 for (sp = cc_string; *sp; sp++)
216 else if (*sp == '\'' && (sp[1] == '.' || sp[1] == ',' || sp[1] == '\''))
219 if ((comma_cnt == 3) == (dot_cnt == 3))
235 /* Extracts a token from IN into TOKEn. Tokens are delimited by
236 GROUPING. The token is truncated to at most CC_WIDTH
237 characters (including null terminator). Returns the first
238 character following the token. */
240 extract_cc_token (const char *in, int grouping, char token[CC_WIDTH])
244 for (; *in != '\0' && *in != grouping; in++)
246 if (*in == '\'' && in[1] == grouping)
248 if (out < &token[CC_WIDTH - 1])
258 /* Sets custom currency specifier CC having name CC_NAME ('A' through
259 'E') to correspond to the settings in CC_STRING. */
261 do_cc (const char *cc_string, int idx)
263 struct custom_currency cc;
265 /* Determine separators. */
266 if (!find_cc_separators (cc_string, &cc))
268 msg (SE, _("CC%c: Custom currency string `%s' does not contain "
269 "exactly three periods or commas (not both)."),
270 "ABCDE"[idx], cc_string);
274 cc_string = extract_cc_token (cc_string, cc.grouping, cc.neg_prefix);
275 cc_string = extract_cc_token (cc_string, cc.grouping, cc.prefix);
276 cc_string = extract_cc_token (cc_string, cc.grouping, cc.suffix);
277 cc_string = extract_cc_token (cc_string, cc.grouping, cc.neg_suffix);
284 /* Parses the BLANKS subcommand, which controls the value that
285 completely blank fields in numeric data imply. X, Wnd: Syntax is
286 SYSMIS or a numeric value. */
288 stc_custom_blanks (struct cmd_set *cmd UNUSED)
291 if ((token == T_ID && lex_id_match ("SYSMIS", tokid)))
298 if (!lex_force_num ())
300 set_blanks (lex_number ());
306 /* Parses the EPOCH subcommand, which controls the epoch used for
307 parsing 2-digit years. */
309 stc_custom_epoch (struct cmd_set *cmd UNUSED)
312 if (lex_match_id ("AUTOMATIC"))
314 else if (lex_is_integer ())
316 int new_epoch = lex_integer ();
318 if (new_epoch < 1500)
320 msg (SE, _("EPOCH must be 1500 or later."));
323 set_epoch (new_epoch);
327 lex_error (_("expecting AUTOMATIC or year"));
335 stc_custom_length (struct cmd_set *cmd UNUSED)
340 if (lex_match_id ("NONE"))
344 if (!lex_force_int ())
346 if (lex_integer () < 1)
348 msg (SE, _("LENGTH must be at least 1."));
351 page_length = lex_integer ();
355 if (page_length != -1)
356 set_viewlength (page_length);
362 stc_custom_seed (struct cmd_set *cmd UNUSED)
365 if (lex_match_id ("RANDOM"))
369 if (!lex_force_num ())
371 set_rng (lex_number ());
379 stc_custom_width (struct cmd_set *cmd UNUSED)
382 if (lex_match_id ("NARROW"))
384 else if (lex_match_id ("WIDE"))
388 if (!lex_force_int ())
390 if (lex_integer () < 40)
392 msg (SE, _("WIDTH must be at least 40."));
395 set_viewwidth (lex_integer ());
402 /* Parses FORMAT subcommand, which consists of a numeric format
405 stc_custom_format (struct cmd_set *cmd UNUSED)
410 if (!parse_format_specifier (&fmt, 0))
412 if ((formats[fmt.type].cat & FCAT_STRING) != 0)
414 msg (SE, _("FORMAT requires numeric output format as an argument. "
415 "Specified format %s is of type string."),
416 fmt_to_string (&fmt));
425 stc_custom_journal (struct cmd_set *cmd UNUSED)
428 if (!lex_match_id ("ON") && !lex_match_id ("OFF"))
430 if (token == T_STRING)
442 stc_custom_listing (struct cmd_set *cmd UNUSED)
447 if (lex_match_id ("ON") || lex_match_id ("YES"))
449 else if (lex_match_id ("OFF") || lex_match_id ("NO"))
456 outp_enable_device (listing, OUTP_DEV_LISTING);
462 stc_custom_disk (struct cmd_set *cmd UNUSED)
464 return stc_custom_listing (cmd);
470 if (get_blanks () == SYSMIS)
471 msg (MM, _("BLANKS is SYSMIS."));
473 msg (MM, _("BLANKS is %g."), get_blanks ());
478 format_cc (const char *in, char grouping, char *out)
482 if (*in == grouping || *in == '\'')
492 const struct custom_currency *cc = get_cc (idx);
493 char cc_string[CC_WIDTH * 4 * 2 + 3 + 1];
496 out = format_cc (cc->neg_prefix, cc->grouping, cc_string);
497 *out++ = cc->grouping;
498 out = format_cc (cc->prefix, cc->grouping, out);
499 *out++ = cc->grouping;
500 out = format_cc (cc->suffix, cc->grouping, out);
501 *out++ = cc->grouping;
502 out = format_cc (cc->neg_suffix, cc->grouping, out);
505 msg (MM, _("CC%c is \"%s\"."), "ABCDE"[idx], cc_string);
542 msg (MM, _("DECIMAL is \"%c\"."), get_decimal ());
548 msg (MM, _("ENDCMD is \"%c\"."), get_endcmd ());
554 msg (MM, _("FORMAT is %s."), fmt_to_string (get_format ()));
560 msg (MM, _("LENGTH is %d."), get_viewlength ());
566 msg (MM, _("MXERRS is %d."), get_mxerrs ());
572 msg (MM, _("MXLOOPS is %d."), get_mxloops ());
578 msg (MM, _("MXWARNS is %d."), get_mxwarns ());
582 show_scompression (void)
584 if (get_scompression ())
585 msg (MM, _("SCOMPRESSION is ON."));
587 msg (MM, _("SCOMPRESSION is OFF."));
591 show_undefined (void)
593 if (get_undefined ())
594 msg (MM, _("UNDEFINED is WARN."));
596 msg (MM, _("UNDEFINED is NOWARN."));
602 struct variable *var = dict_get_weight (default_dict);
604 msg (MM, _("WEIGHT is off."));
606 msg (MM, _("WEIGHT is variable %s."), var->name);
612 msg (MM, _("WIDTH is %d."), get_viewwidth ());
618 void (*function) (void);
621 struct show_sbc show_table[] =
623 {"BLANKS", show_blanks},
629 {"DECIMALS", show_decimals},
630 {"ENDCMD", show_endcmd},
631 {"FORMAT", show_format},
632 {"LENGTH", show_length},
633 {"MXERRS", show_mxerrs},
634 {"MXLOOPS", show_mxloops},
635 {"MXWARNS", show_mxwarns},
636 {"SCOMPRESSION", show_scompression},
637 {"UNDEFINED", show_undefined},
638 {"WEIGHT", show_weight},
639 {"WIDTH", show_width},
647 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
648 show_table[i].function ();
656 for (i = 0; i < 5; i++)
663 msg (MM, lack_of_warranty);
683 if (lex_match (T_ALL))
685 else if (lex_match_id ("CC"))
687 else if (lex_match_id ("WARRANTY"))
689 else if (lex_match_id ("COPYING"))
691 else if (token == T_ID)
695 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
696 if (lex_match_id (show_table[i].name))
698 show_table[i].function ();
702 return CMD_PART_SUCCESS_MAYBE;
709 return CMD_PART_SUCCESS_MAYBE;
714 while (token != '.');