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"
44 #else /* !HAVE_TERMCAP_H */
45 int tgetent (char *, const char *);
46 int tgetnum (const char *);
47 #endif /* !HAVE_TERMCAP_H */
48 #endif /* !HAVE_LIBTERMCAP */
51 #define _(msgid) gettext (msgid)
56 block=string "x==1" "one character long";
57 boxstring=string "x==3 || x==11" "3 or 11 characters long";
58 case=size:upper/uplow;
64 compression=compress:on/off;
65 cpi=integer "x>0" "%s must be greater than 0";
67 decimal=dec:dot/comma;
71 endcmd=string "x==1" "one character long";
73 errorbreak=errbrk:on/off;
74 errors=errors:on/off/terminal/listing/both/none;
76 headers=headers:no/yes/blank;
78 histogram=string "x==1" "one character long";
83 lowres=lores:auto/on/off;
84 lpi=integer "x>0" "%s must be greater than 0";
85 menus=menus:standard/extended;
86 messages=messages:on/off/terminal/listing/both/none;
88 miterate=integer "x>0" "%s must be greater than 0";
89 mnest=integer "x>0" "%s must be greater than 0";
91 mxerrs=integer "x >= 1" "%s must be at least 1";
92 mxloops=integer "x >=1" "%s must be at least 1";
96 printback=prtbck:on/off;
98 results=res:on/off/terminal/listing/both/none;
100 scompression=scompress:on/off;
101 scripttab=string "x==1" "one character long";
103 tb1=string "x==3 || x==11" "3 or 11 characters long";
105 undefined=undef:warn/nowarn;
107 workspace=integer "x>=1024" "%s must be at least 1 MB";
115 static bool do_cc (const char *cc_string, int idx);
123 if (!parse_set (&cmd))
127 ok = ok && do_cc (cmd.s_cca, 0);
129 ok = ok && do_cc (cmd.s_ccb, 1);
131 ok = ok && do_cc (cmd.s_ccc, 2);
133 ok = ok && do_cc (cmd.s_ccd, 3);
135 ok = ok && do_cc (cmd.s_cce, 4);
138 set_prompt (cmd.s_prompt);
140 set_prompt (cmd.s_cprompt);
142 set_prompt (cmd.s_dprompt);
145 set_decimal (cmd.dec == STC_DOT ? '.' : ',');
147 set_echo (cmd.echo == STC_ON);
149 set_endcmd (cmd.s_endcmd[0]);
150 if (cmd.sbc_errorbreak)
151 set_errorbreak (cmd.errbrk == STC_ON);
153 set_include (cmd.inc == STC_ON);
155 set_mxerrs (cmd.n_mxerrs[0]);
157 set_mxwarns (cmd.n_mxwarns[0]);
159 set_nulline (cmd.null == STC_ON);
162 if (cmd.sbc_scompression)
163 set_scompression (cmd.scompress == STC_ON);
164 if (cmd.sbc_undefined)
165 set_undefined (cmd.undef == STC_WARN);
166 if (cmd.sbc_workspace)
167 set_workspace (cmd.n_workspace[0] * 1024L);
170 msg (SW, _("%s is obsolete."),"BLOCK");
171 if (cmd.sbc_boxstring)
172 msg (SW, _("%s is obsolete."),"BOXSTRING");
173 if (cmd.sbc_histogram)
174 msg (MW, _("%s is obsolete."),"HISTOGRAM");
176 msg (MW, _("%s is obsolete."),"MENUS");
178 msg (SW, _("%s is obsolete."),"XSORT");
179 if (cmd.sbc_mxmemory )
180 msg (SE, _("%s is obsolete."),"MXMEMORY");
181 if (cmd.sbc_scripttab)
182 msg (SE, _("%s is obsolete."),"SCRIPTTAB");
184 msg (SW, _("%s is obsolete."),"TBFONTS");
185 if (cmd.sbc_tb1 && cmd.s_tb1)
186 msg (SW, _("%s is obsolete."),"TB1");
189 msg (SW, _("%s is not implemented."), "CASE");
191 if (cmd.sbc_compression)
192 msg (MW, _("Active file compression is not implemented."));
197 /* Find the grouping characters in CC_STRING and set CC's
198 grouping and decimal members appropriately. Returns true if
199 successful, false otherwise. */
201 find_cc_separators (const char *cc_string, struct custom_currency *cc)
204 int comma_cnt, dot_cnt;
206 /* Count commas and periods. There must be exactly three of
207 one or the other, except that an apostrophe acts escapes a
208 following comma or period. */
209 comma_cnt = dot_cnt = 0;
210 for (sp = cc_string; *sp; sp++)
215 else if (*sp == '\'' && (sp[1] == '.' || sp[1] == ',' || sp[1] == '\''))
218 if ((comma_cnt == 3) == (dot_cnt == 3))
234 /* Extracts a token from IN into TOKEn. Tokens are delimited by
235 GROUPING. The token is truncated to at most CC_WIDTH
236 characters (including null terminator). Returns the first
237 character following the token. */
239 extract_cc_token (const char *in, int grouping, char token[CC_WIDTH])
243 for (; *in != '\0' && *in != grouping; in++)
245 if (*in == '\'' && in[1] == grouping)
247 if (out < &token[CC_WIDTH - 1])
257 /* Sets custom currency specifier CC having name CC_NAME ('A' through
258 'E') to correspond to the settings in CC_STRING. */
260 do_cc (const char *cc_string, int idx)
262 struct custom_currency cc;
264 /* Determine separators. */
265 if (!find_cc_separators (cc_string, &cc))
267 msg (SE, _("CC%c: Custom currency string `%s' does not contain "
268 "exactly three periods or commas (not both)."),
269 "ABCDE"[idx], cc_string);
273 cc_string = extract_cc_token (cc_string, cc.grouping, cc.neg_prefix);
274 cc_string = extract_cc_token (cc_string, cc.grouping, cc.prefix);
275 cc_string = extract_cc_token (cc_string, cc.grouping, cc.suffix);
276 cc_string = extract_cc_token (cc_string, cc.grouping, cc.neg_suffix);
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. */
287 stc_custom_blanks (struct cmd_set *cmd UNUSED)
290 if ((token == T_ID && lex_id_match ("SYSMIS", tokid)))
297 if (!lex_force_num ())
299 set_blanks (lex_number ());
305 /* Parses the EPOCH subcommand, which controls the epoch used for
306 parsing 2-digit years. */
308 stc_custom_epoch (struct cmd_set *cmd UNUSED)
311 if (lex_match_id ("AUTOMATIC"))
313 else if (lex_is_integer ())
315 int new_epoch = lex_integer ();
317 if (new_epoch < 1500)
319 msg (SE, _("EPOCH must be 1500 or later."));
322 set_epoch (new_epoch);
326 lex_error (_("expecting AUTOMATIC or year"));
334 stc_custom_length (struct cmd_set *cmd UNUSED)
339 if (lex_match_id ("NONE"))
343 if (!lex_force_int ())
345 if (lex_integer () < 1)
347 msg (SE, _("LENGTH must be at least 1."));
350 page_length = lex_integer ();
354 if (page_length != -1)
355 set_viewlength (page_length);
361 stc_custom_seed (struct cmd_set *cmd UNUSED)
364 if (lex_match_id ("RANDOM"))
368 if (!lex_force_num ())
370 set_rng (lex_number ());
378 stc_custom_width (struct cmd_set *cmd UNUSED)
381 if (lex_match_id ("NARROW"))
383 else if (lex_match_id ("WIDE"))
387 if (!lex_force_int ())
389 if (lex_integer () < 40)
391 msg (SE, _("WIDTH must be at least 40."));
394 set_viewwidth (lex_integer ());
401 /* Parses FORMAT subcommand, which consists of a numeric format
404 stc_custom_format (struct cmd_set *cmd UNUSED)
409 if (!parse_format_specifier (&fmt, 0))
411 if ((formats[fmt.type].cat & FCAT_STRING) != 0)
413 msg (SE, _("FORMAT requires numeric output format as an argument. "
414 "Specified format %s is of type string."),
415 fmt_to_string (&fmt));
424 stc_custom_journal (struct cmd_set *cmd UNUSED)
427 if (!lex_match_id ("ON") && !lex_match_id ("OFF"))
429 if (token == T_STRING)
441 stc_custom_listing (struct cmd_set *cmd UNUSED)
446 if (lex_match_id ("ON") || lex_match_id ("YES"))
448 else if (lex_match_id ("OFF") || lex_match_id ("NO"))
455 outp_enable_device (listing, OUTP_DEV_LISTING);
461 stc_custom_disk (struct cmd_set *cmd UNUSED)
463 return stc_custom_listing (cmd);
469 if (get_blanks () == SYSMIS)
470 msg (MM, _("BLANKS is SYSMIS."));
472 msg (MM, _("BLANKS is %g."), get_blanks ());
477 format_cc (const char *in, char grouping, char *out)
481 if (*in == grouping || *in == '\'')
491 const struct custom_currency *cc = get_cc (idx);
492 char cc_string[CC_WIDTH * 4 * 2 + 3 + 1];
495 out = format_cc (cc->neg_prefix, cc->grouping, cc_string);
496 *out++ = cc->grouping;
497 out = format_cc (cc->prefix, cc->grouping, out);
498 *out++ = cc->grouping;
499 out = format_cc (cc->suffix, cc->grouping, out);
500 *out++ = cc->grouping;
501 out = format_cc (cc->neg_suffix, cc->grouping, out);
504 msg (MM, _("CC%c is \"%s\"."), "ABCDE"[idx], cc_string);
541 msg (MM, _("DECIMAL is \"%c\"."), get_decimal ());
547 msg (MM, _("ENDCMD is \"%c\"."), get_endcmd ());
553 msg (MM, _("FORMAT is %s."), fmt_to_string (get_format ()));
559 msg (MM, _("LENGTH is %d."), get_viewlength ());
565 msg (MM, _("MXERRS is %d."), get_mxerrs ());
571 msg (MM, _("MXLOOPS is %d."), get_mxloops ());
577 msg (MM, _("MXWARNS is %d."), get_mxwarns ());
581 show_scompression (void)
583 if (get_scompression ())
584 msg (MM, _("SCOMPRESSION is ON."));
586 msg (MM, _("SCOMPRESSION is OFF."));
590 show_undefined (void)
592 if (get_undefined ())
593 msg (MM, _("UNDEFINED is WARN."));
595 msg (MM, _("UNDEFINED is NOWARN."));
601 struct variable *var = dict_get_weight (default_dict);
603 msg (MM, _("WEIGHT is off."));
605 msg (MM, _("WEIGHT is variable %s."), var->name);
611 msg (MM, _("WIDTH is %d."), get_viewwidth ());
617 void (*function) (void);
620 struct show_sbc show_table[] =
622 {"BLANKS", show_blanks},
628 {"DECIMALS", show_decimals},
629 {"ENDCMD", show_endcmd},
630 {"FORMAT", show_format},
631 {"LENGTH", show_length},
632 {"MXERRS", show_mxerrs},
633 {"MXLOOPS", show_mxloops},
634 {"MXWARNS", show_mxwarns},
635 {"SCOMPRESSION", show_scompression},
636 {"UNDEFINED", show_undefined},
637 {"WEIGHT", show_weight},
638 {"WIDTH", show_width},
646 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
647 show_table[i].function ();
655 for (i = 0; i < 5; i++)
662 msg (MM, lack_of_warranty);
682 if (lex_match (T_ALL))
684 else if (lex_match_id ("CC"))
686 else if (lex_match_id ("WARRANTY"))
688 else if (lex_match_id ("COPYING"))
690 else if (token == T_ID)
694 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
695 if (lex_match_id (show_table[i].name))
697 show_table[i].function ();
701 return CMD_PART_SUCCESS_MAYBE;
708 return CMD_PART_SUCCESS_MAYBE;
713 while (token != '.');