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";
117 static bool do_cc (const char *cc_string, int idx);
125 if (!parse_set (&cmd))
129 ok = ok && do_cc (cmd.s_cca, 0);
131 ok = ok && do_cc (cmd.s_ccb, 1);
133 ok = ok && do_cc (cmd.s_ccc, 2);
135 ok = ok && do_cc (cmd.s_ccd, 3);
137 ok = ok && do_cc (cmd.s_cce, 4);
140 getl_set_prompt (GETL_PROMPT_FIRST, cmd.s_prompt);
142 getl_set_prompt (GETL_PROMPT_LATER, cmd.s_cprompt);
144 getl_set_prompt (GETL_PROMPT_DATA, cmd.s_dprompt);
147 set_decimal (cmd.dec == STC_DOT ? '.' : ',');
149 set_echo (cmd.echo == STC_ON);
151 set_endcmd (cmd.s_endcmd[0]);
152 if (cmd.sbc_errorbreak)
153 set_errorbreak (cmd.errbrk == STC_ON);
155 set_include (cmd.inc == STC_ON);
157 set_mxerrs (cmd.n_mxerrs[0]);
159 set_mxwarns (cmd.n_mxwarns[0]);
161 set_nulline (cmd.null == STC_ON);
164 if (cmd.sbc_scompression)
165 set_scompression (cmd.scompress == STC_ON);
166 if (cmd.sbc_undefined)
167 set_undefined (cmd.undef == STC_WARN);
168 if (cmd.sbc_workspace)
169 set_workspace (cmd.n_workspace[0] * 1024L);
172 msg (SW, _("%s is obsolete."), "BLOCK");
173 if (cmd.sbc_boxstring)
174 msg (SW, _("%s is obsolete."), "BOXSTRING");
175 if (cmd.sbc_histogram)
176 msg (SW, _("%s is obsolete."), "HISTOGRAM");
178 msg (SW, _("%s is obsolete."), "MENUS");
180 msg (SW, _("%s is obsolete."), "XSORT");
181 if (cmd.sbc_mxmemory)
182 msg (SE, _("%s is obsolete."), "MXMEMORY");
183 if (cmd.sbc_scripttab)
184 msg (SE, _("%s is obsolete."), "SCRIPTTAB");
186 msg (SW, _("%s is obsolete."), "TBFONTS");
187 if (cmd.sbc_tb1 && cmd.s_tb1)
188 msg (SW, _("%s is obsolete."), "TB1");
191 msg (SW, _("%s is not implemented."), "CASE");
193 if (cmd.sbc_compression)
194 msg (SW, _("Active file compression is not implemented."));
199 /* Find the grouping characters in CC_STRING and set CC's
200 grouping and decimal members appropriately. Returns true if
201 successful, false otherwise. */
203 find_cc_separators (const char *cc_string, struct custom_currency *cc)
206 int comma_cnt, dot_cnt;
208 /* Count commas and periods. There must be exactly three of
209 one or the other, except that an apostrophe acts escapes a
210 following comma or period. */
211 comma_cnt = dot_cnt = 0;
212 for (sp = cc_string; *sp; sp++)
217 else if (*sp == '\'' && (sp[1] == '.' || sp[1] == ',' || sp[1] == '\''))
220 if ((comma_cnt == 3) == (dot_cnt == 3))
236 /* Extracts a token from IN into TOKEn. Tokens are delimited by
237 GROUPING. The token is truncated to at most CC_WIDTH
238 characters (including null terminator). Returns the first
239 character following the token. */
241 extract_cc_token (const char *in, int grouping, char token[CC_WIDTH])
245 for (; *in != '\0' && *in != grouping; in++)
247 if (*in == '\'' && in[1] == grouping)
249 if (out < &token[CC_WIDTH - 1])
259 /* Sets custom currency specifier CC having name CC_NAME ('A' through
260 'E') to correspond to the settings in CC_STRING. */
262 do_cc (const char *cc_string, int idx)
264 struct custom_currency cc;
266 /* Determine separators. */
267 if (!find_cc_separators (cc_string, &cc))
269 msg (SE, _("CC%c: Custom currency string `%s' does not contain "
270 "exactly three periods or commas (not both)."),
271 "ABCDE"[idx], cc_string);
275 cc_string = extract_cc_token (cc_string, cc.grouping, cc.neg_prefix);
276 cc_string = extract_cc_token (cc_string, cc.grouping, cc.prefix);
277 cc_string = extract_cc_token (cc_string, cc.grouping, cc.suffix);
278 cc_string = extract_cc_token (cc_string, cc.grouping, cc.neg_suffix);
285 /* Parses the BLANKS subcommand, which controls the value that
286 completely blank fields in numeric data imply. X, Wnd: Syntax is
287 SYSMIS or a numeric value. */
289 stc_custom_blanks (struct cmd_set *cmd UNUSED)
292 if ((token == T_ID && lex_id_match ("SYSMIS", tokid)))
299 if (!lex_force_num ())
301 set_blanks (lex_number ());
307 /* Parses the EPOCH subcommand, which controls the epoch used for
308 parsing 2-digit years. */
310 stc_custom_epoch (struct cmd_set *cmd UNUSED)
313 if (lex_match_id ("AUTOMATIC"))
315 else if (lex_is_integer ())
317 int new_epoch = lex_integer ();
319 if (new_epoch < 1500)
321 msg (SE, _("EPOCH must be 1500 or later."));
324 set_epoch (new_epoch);
328 lex_error (_("expecting AUTOMATIC or year"));
336 stc_custom_length (struct cmd_set *cmd UNUSED)
341 if (lex_match_id ("NONE"))
345 if (!lex_force_int ())
347 if (lex_integer () < 1)
349 msg (SE, _("LENGTH must be at least 1."));
352 page_length = lex_integer ();
356 if (page_length != -1)
357 set_viewlength (page_length);
363 stc_custom_seed (struct cmd_set *cmd UNUSED)
366 if (lex_match_id ("RANDOM"))
370 if (!lex_force_num ())
372 set_rng (lex_number ());
380 stc_custom_width (struct cmd_set *cmd UNUSED)
383 if (lex_match_id ("NARROW"))
385 else if (lex_match_id ("WIDE"))
389 if (!lex_force_int ())
391 if (lex_integer () < 40)
393 msg (SE, _("WIDTH must be at least 40."));
396 set_viewwidth (lex_integer ());
403 /* Parses FORMAT subcommand, which consists of a numeric format
406 stc_custom_format (struct cmd_set *cmd UNUSED)
411 if (!parse_format_specifier (&fmt, 0))
413 if ((formats[fmt.type].cat & FCAT_STRING) != 0)
415 msg (SE, _("FORMAT requires numeric output format as an argument. "
416 "Specified format %s is of type string."),
417 fmt_to_string (&fmt));
426 stc_custom_journal (struct cmd_set *cmd UNUSED)
429 if (!lex_match_id ("ON") && !lex_match_id ("OFF"))
431 if (token == T_STRING)
443 stc_custom_listing (struct cmd_set *cmd UNUSED)
448 if (lex_match_id ("ON") || lex_match_id ("YES"))
450 else if (lex_match_id ("OFF") || lex_match_id ("NO"))
457 outp_enable_device (listing, OUTP_DEV_LISTING);
463 stc_custom_disk (struct cmd_set *cmd UNUSED)
465 return stc_custom_listing (cmd);
471 if (get_blanks () == SYSMIS)
472 msg (SN, _("BLANKS is SYSMIS."));
474 msg (SN, _("BLANKS is %g."), get_blanks ());
479 format_cc (const char *in, char grouping, char *out)
483 if (*in == grouping || *in == '\'')
493 const struct custom_currency *cc = get_cc (idx);
494 char cc_string[CC_WIDTH * 4 * 2 + 3 + 1];
497 out = format_cc (cc->neg_prefix, cc->grouping, cc_string);
498 *out++ = cc->grouping;
499 out = format_cc (cc->prefix, cc->grouping, out);
500 *out++ = cc->grouping;
501 out = format_cc (cc->suffix, cc->grouping, out);
502 *out++ = cc->grouping;
503 out = format_cc (cc->neg_suffix, cc->grouping, out);
506 msg (SN, _("CC%c is \"%s\"."), "ABCDE"[idx], cc_string);
543 msg (SN, _("DECIMAL is \"%c\"."), get_decimal ());
549 msg (SN, _("ENDCMD is \"%c\"."), get_endcmd ());
555 msg (SN, _("FORMAT is %s."), fmt_to_string (get_format ()));
561 msg (SN, _("LENGTH is %d."), get_viewlength ());
567 msg (SN, _("MXERRS is %d."), get_mxerrs ());
573 msg (SN, _("MXLOOPS is %d."), get_mxloops ());
579 msg (SN, _("MXWARNS is %d."), get_mxwarns ());
583 show_scompression (void)
585 if (get_scompression ())
586 msg (SN, _("SCOMPRESSION is ON."));
588 msg (SN, _("SCOMPRESSION is OFF."));
592 show_undefined (void)
594 if (get_undefined ())
595 msg (SN, _("UNDEFINED is WARN."));
597 msg (SN, _("UNDEFINED is NOWARN."));
603 struct variable *var = dict_get_weight (default_dict);
605 msg (SN, _("WEIGHT is off."));
607 msg (SN, _("WEIGHT is variable %s."), var->name);
613 msg (SN, _("WIDTH is %d."), get_viewwidth ());
619 void (*function) (void);
622 struct show_sbc show_table[] =
624 {"BLANKS", show_blanks},
630 {"DECIMALS", show_decimals},
631 {"ENDCMD", show_endcmd},
632 {"FORMAT", show_format},
633 {"LENGTH", show_length},
634 {"MXERRS", show_mxerrs},
635 {"MXLOOPS", show_mxloops},
636 {"MXWARNS", show_mxwarns},
637 {"SCOMPRESSION", show_scompression},
638 {"UNDEFINED", show_undefined},
639 {"WEIGHT", show_weight},
640 {"WIDTH", show_width},
648 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
649 show_table[i].function ();
657 for (i = 0; i < 5; i++)
664 msg (MN, lack_of_warranty);
684 if (lex_match (T_ALL))
686 else if (lex_match_id ("CC"))
688 else if (lex_match_id ("WARRANTY"))
690 else if (lex_match_id ("COPYING"))
692 else if (token == T_ID)
696 for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
697 if (lex_match_id (show_table[i].name))
699 show_table[i].function ();
715 while (token != '.');