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
27 #include <data/dictionary.h>
28 #include <data/format.h>
29 #include <data/procedure.h>
30 #include <data/settings.h>
31 #include <data/variable.h>
32 #include <language/command.h>
33 #include <language/lexer/lexer.h>
34 #include <language/line-buffer.h>
35 #include <libpspp/alloc.h>
36 #include <libpspp/compiler.h>
37 #include <libpspp/copyleft.h>
38 #include <libpspp/magic.h>
39 #include <libpspp/message.h>
40 #include <math/random.h>
41 #include <output/output.h>
46 #else /* !HAVE_TERMCAP_H */
47 int tgetent (char *, const char *);
48 int tgetnum (const char *);
49 #endif /* !HAVE_TERMCAP_H */
50 #endif /* !HAVE_LIBTERMCAP */
53 #define _(msgid) gettext (msgid)
58 block=string "x==1" "one character long";
59 boxstring=string "x==3 || x==11" "3 or 11 characters long";
60 case=size:upper/uplow;
66 compression=compress:on/off;
67 cpi=integer "x>0" "%s must be greater than 0";
69 decimal=dec:dot/comma;
73 endcmd=string "x==1" "one character long";
75 errorbreak=errbrk:on/off;
76 errors=errors:on/off/terminal/listing/both/none;
78 headers=headers:no/yes/blank;
80 histogram=string "x==1" "one character long";
85 lowres=lores:auto/on/off;
86 lpi=integer "x>0" "%s must be greater than 0";
87 menus=menus:standard/extended;
88 messages=messages:on/off/terminal/listing/both/none;
90 miterate=integer "x>0" "%s must be greater than 0";
91 mnest=integer "x>0" "%s must be greater than 0";
93 mxerrs=integer "x >= 1" "%s must be at least 1";
94 mxloops=integer "x >=1" "%s must be at least 1";
98 printback=prtbck:on/off;
100 results=res:on/off/terminal/listing/both/none;
102 scompression=scompress:on/off;
103 scripttab=string "x==1" "one character long";
105 tb1=string "x==3 || x==11" "3 or 11 characters long";
107 undefined=undef:warn/nowarn;
109 workspace=integer "x>=1024" "%s must be at least 1 MB";
119 static bool do_cc (const char *cc_string, int idx);
127 if (!parse_set (&cmd, NULL))
131 ok = ok && do_cc (cmd.s_cca, 0);
133 ok = ok && do_cc (cmd.s_ccb, 1);
135 ok = ok && do_cc (cmd.s_ccc, 2);
137 ok = ok && do_cc (cmd.s_ccd, 3);
139 ok = ok && do_cc (cmd.s_cce, 4);
142 getl_set_prompt (GETL_PROMPT_FIRST, cmd.s_prompt);
144 getl_set_prompt (GETL_PROMPT_LATER, cmd.s_cprompt);
146 getl_set_prompt (GETL_PROMPT_DATA, cmd.s_dprompt);
149 set_decimal (cmd.dec == STC_DOT ? '.' : ',');
151 set_echo (cmd.echo == STC_ON);
153 set_endcmd (cmd.s_endcmd[0]);
154 if (cmd.sbc_errorbreak)
155 set_errorbreak (cmd.errbrk == STC_ON);
157 set_include (cmd.inc == STC_ON);
159 set_mxerrs (cmd.n_mxerrs[0]);
161 set_mxwarns (cmd.n_mxwarns[0]);
163 set_nulline (cmd.null == STC_ON);
166 if (cmd.sbc_scompression)
167 set_scompression (cmd.scompress == STC_ON);
168 if (cmd.sbc_undefined)
169 set_undefined (cmd.undef == STC_WARN);
170 if (cmd.sbc_workspace)
171 set_workspace (cmd.n_workspace[0] * 1024L);
174 msg (SW, _("%s is obsolete."), "BLOCK");
175 if (cmd.sbc_boxstring)
176 msg (SW, _("%s is obsolete."), "BOXSTRING");
177 if (cmd.sbc_histogram)
178 msg (SW, _("%s is obsolete."), "HISTOGRAM");
180 msg (SW, _("%s is obsolete."), "MENUS");
182 msg (SW, _("%s is obsolete."), "XSORT");
183 if (cmd.sbc_mxmemory)
184 msg (SE, _("%s is obsolete."), "MXMEMORY");
185 if (cmd.sbc_scripttab)
186 msg (SE, _("%s is obsolete."), "SCRIPTTAB");
188 msg (SW, _("%s is obsolete."), "TBFONTS");
189 if (cmd.sbc_tb1 && cmd.s_tb1)
190 msg (SW, _("%s is obsolete."), "TB1");
193 msg (SW, _("%s is not implemented."), "CASE");
195 if (cmd.sbc_compression)
196 msg (SW, _("Active file compression is not implemented."));
201 /* Find the grouping characters in CC_STRING and set CC's
202 grouping and decimal members appropriately. Returns true if
203 successful, false otherwise. */
205 find_cc_separators (const char *cc_string, struct custom_currency *cc)
208 int comma_cnt, dot_cnt;
210 /* Count commas and periods. There must be exactly three of
211 one or the other, except that an apostrophe acts escapes a
212 following comma or period. */
213 comma_cnt = dot_cnt = 0;
214 for (sp = cc_string; *sp; sp++)
219 else if (*sp == '\'' && (sp[1] == '.' || sp[1] == ',' || sp[1] == '\''))
222 if ((comma_cnt == 3) == (dot_cnt == 3))
238 /* Extracts a token from IN into TOKEn. Tokens are delimited by
239 GROUPING. The token is truncated to at most CC_WIDTH
240 characters (including null terminator). Returns the first
241 character following the token. */
243 extract_cc_token (const char *in, int grouping, char token[CC_WIDTH])
247 for (; *in != '\0' && *in != grouping; in++)
249 if (*in == '\'' && in[1] == grouping)
251 if (out < &token[CC_WIDTH - 1])
261 /* Sets custom currency specifier CC having name CC_NAME ('A' through
262 'E') to correspond to the settings in CC_STRING. */
264 do_cc (const char *cc_string, int idx)
266 struct custom_currency cc;
268 /* Determine separators. */
269 if (!find_cc_separators (cc_string, &cc))
271 msg (SE, _("CC%c: Custom currency string `%s' does not contain "
272 "exactly three periods or commas (not both)."),
273 "ABCDE"[idx], cc_string);
277 cc_string = extract_cc_token (cc_string, cc.grouping, cc.neg_prefix);
278 cc_string = extract_cc_token (cc_string, cc.grouping, cc.prefix);
279 cc_string = extract_cc_token (cc_string, cc.grouping, cc.suffix);
280 cc_string = extract_cc_token (cc_string, cc.grouping, cc.neg_suffix);
287 /* Parses the BLANKS subcommand, which controls the value that
288 completely blank fields in numeric data imply. X, Wnd: Syntax is
289 SYSMIS or a numeric value. */
291 stc_custom_blanks (struct cmd_set *cmd UNUSED, void *aux UNUSED)
294 if ((token == T_ID && lex_id_match ("SYSMIS", tokid)))
301 if (!lex_force_num ())
303 set_blanks (lex_number ());
309 /* Parses the EPOCH subcommand, which controls the epoch used for
310 parsing 2-digit years. */
312 stc_custom_epoch (struct cmd_set *cmd UNUSED, void *aux UNUSED)
315 if (lex_match_id ("AUTOMATIC"))
317 else if (lex_is_integer ())
319 int new_epoch = lex_integer ();
321 if (new_epoch < 1500)
323 msg (SE, _("EPOCH must be 1500 or later."));
326 set_epoch (new_epoch);
330 lex_error (_("expecting AUTOMATIC or year"));
338 stc_custom_length (struct cmd_set *cmd UNUSED, void *aux UNUSED)
343 if (lex_match_id ("NONE"))
347 if (!lex_force_int ())
349 if (lex_integer () < 1)
351 msg (SE, _("LENGTH must be at least 1."));
354 page_length = lex_integer ();
358 if (page_length != -1)
359 set_viewlength (page_length);
365 stc_custom_seed (struct cmd_set *cmd UNUSED, void *aux UNUSED)
368 if (lex_match_id ("RANDOM"))
372 if (!lex_force_num ())
374 set_rng (lex_number ());
382 stc_custom_width (struct cmd_set *cmd UNUSED, void *aux UNUSED)
385 if (lex_match_id ("NARROW"))
387 else if (lex_match_id ("WIDE"))
391 if (!lex_force_int ())
393 if (lex_integer () < 40)
395 msg (SE, _("WIDTH must be at least 40."));
398 set_viewwidth (lex_integer ());
405 /* Parses FORMAT subcommand, which consists of a numeric format
408 stc_custom_format (struct cmd_set *cmd UNUSED, void *aux UNUSED)
413 if (!parse_format_specifier (&fmt, 0))
415 if ((formats[fmt.type].cat & FCAT_STRING) != 0)
417 msg (SE, _("FORMAT requires numeric output format as an argument. "
418 "Specified format %s is of type string."),
419 fmt_to_string (&fmt));
428 stc_custom_journal (struct cmd_set *cmd UNUSED, void *aux UNUSED)
431 if (!lex_match_id ("ON") && !lex_match_id ("OFF"))
433 if (token == T_STRING)
445 stc_custom_listing (struct cmd_set *cmd UNUSED, void *aux UNUSED)
450 if (lex_match_id ("ON") || lex_match_id ("YES"))
452 else if (lex_match_id ("OFF") || lex_match_id ("NO"))
459 outp_enable_device (listing, OUTP_DEV_LISTING);
465 stc_custom_disk (struct cmd_set *cmd UNUSED, void *aux)
467 return stc_custom_listing (cmd, aux);
473 if (get_blanks () == SYSMIS)
474 msg (SN, _("BLANKS is SYSMIS."));
476 msg (SN, _("BLANKS is %g."), get_blanks ());
481 format_cc (const char *in, char grouping, char *out)
485 if (*in == grouping || *in == '\'')
495 const struct custom_currency *cc = get_cc (idx);
496 char cc_string[CC_WIDTH * 4 * 2 + 3 + 1];
499 out = format_cc (cc->neg_prefix, cc->grouping, cc_string);
500 *out++ = cc->grouping;
501 out = format_cc (cc->prefix, cc->grouping, out);
502 *out++ = cc->grouping;
503 out = format_cc (cc->suffix, cc->grouping, out);
504 *out++ = cc->grouping;
505 out = format_cc (cc->neg_suffix, cc->grouping, out);
508 msg (SN, _("CC%c is \"%s\"."), "ABCDE"[idx], cc_string);
545 msg (SN, _("DECIMAL is \"%c\"."), get_decimal ());
551 msg (SN, _("ENDCMD is \"%c\"."), get_endcmd ());
557 msg (SN, _("FORMAT is %s."), fmt_to_string (get_format ()));
563 msg (SN, _("LENGTH is %d."), get_viewlength ());
569 msg (SN, _("MXERRS is %d."), get_mxerrs ());
575 msg (SN, _("MXLOOPS is %d."), get_mxloops ());
581 msg (SN, _("MXWARNS is %d."), get_mxwarns ());
585 show_scompression (void)
587 if (get_scompression ())
588 msg (SN, _("SCOMPRESSION is ON."));
590 msg (SN, _("SCOMPRESSION is OFF."));
594 show_undefined (void)
596 if (get_undefined ())
597 msg (SN, _("UNDEFINED is WARN."));
599 msg (SN, _("UNDEFINED is NOWARN."));
605 struct variable *var = dict_get_weight (default_dict);
607 msg (SN, _("WEIGHT is off."));
609 msg (SN, _("WEIGHT is variable %s."), var->name);
615 msg (SN, _("WIDTH is %d."), get_viewwidth ());
621 void (*function) (void);
624 struct show_sbc show_table[] =
626 {"BLANKS", show_blanks},
632 {"DECIMALS", show_decimals},
633 {"ENDCMD", show_endcmd},
634 {"FORMAT", show_format},
635 {"LENGTH", show_length},
636 {"MXERRS", show_mxerrs},
637 {"MXLOOPS", show_mxloops},
638 {"MXWARNS", show_mxwarns},
639 {"SCOMPRESSION", show_scompression},
640 {"UNDEFINED", show_undefined},
641 {"WEIGHT", show_weight},
642 {"WIDTH", show_width},
650 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
651 show_table[i].function ();
659 for (i = 0; i < 5; i++)
666 msg (MN, lack_of_warranty);
686 if (lex_match (T_ALL))
688 else if (lex_match_id ("CC"))
690 else if (lex_match_id ("WARRANTY"))
692 else if (lex_match_id ("COPYING"))
694 else if (token == T_ID)
698 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
699 if (lex_match_id (show_table[i].name))
701 show_table[i].function ();
717 while (token != '.');