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., 59 Temple Place - Suite 330, Boston, MA
26 #if TIME_WITH_SYS_TIME
40 #else /* !HAVE_TERMCAP_H */
41 int tgetent (char *, char *);
43 #endif /* !HAVE_TERMCAP_H */
44 #endif /* !HAVE_LIBTERMCAP */
47 #if HAVE_READLINE_HISTORY_H
48 #include <readline/history.h>
49 #else /* no readline/history.h */
50 extern void using_history ();
51 extern int read_history ();
52 extern void stifle_history ();
53 #endif /* no readline/history.h */
54 #endif /* -lhistory */
56 #if HAVE_FPU_CONTROL_H
57 #include <fpu_control.h>
65 #elif __WIN32__ && __BORLANDC__
68 #define gettext(STRING) \
88 #include "julcal/julcal.h"
98 struct dictionary default_dict;
99 struct expression *process_if_expr;
101 struct ccase *temp_case;
103 struct trns_header **t_trns;
108 int FILTER_before_TEMPORARY;
110 struct file_handle *default_handle;
112 void (*read_active_file) (void);
113 void (*cancel_input_pgm) (void);
115 struct ctl_stmt *ctl_stack;
124 static void get_date (void);
126 #if HAVE_LIBTERMCAP && !__CHECKER__
127 static char *term_buffer;
131 init_glob (int argc unused, char **argv)
133 /* FIXME: Allow i18n of other locale items (besides LC_MESSAGES). */
136 setlocale (LC_MESSAGES, "");
138 setlocale (LC_MONETARY, "");
139 bindtextdomain (PACKAGE, locale_dir);
140 textdomain (PACKAGE);
141 #endif /* ENABLE_NLS */
143 /* Workable defaults before we determine the real terminal size. */
150 /* PORTME: If your system/OS has the nasty tendency to halt with a
151 SIGFPE whenever there's a floating-point overflow (or other
152 exception), be sure to mask off those bits in the FPU here.
153 PSPP wants a guarantee that, no matter what boneheaded
154 floating-point operation it performs, the process will not halt. */
155 #if HAVE_FEHOLDEXCEPT
161 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
162 __setfpucw (_FPU_IEEE);
164 _control87 (0xffff, 0x137f);
169 /* Test for endianness borrowed from acspecific.m4, which was in
170 turn borrowed from Harbison&Steele. */
174 char c[sizeof (long)];
179 if (u.c[sizeof u.l - 1] == 1)
181 else if (u.c[0] == 1)
184 msg (FE, _("Your machine does not appear to be either big- or little-"
185 "endian. At the moment, PSPP only supports machines of "
186 "these standard endiannesses. If you want to hack in "
187 "others, contact the author."));
191 /* PORTME: Set the value for second_lowest_value, which is the
192 "second lowest" possible value for a double. This is the value
193 for LOWEST on MISSING VALUES, etc. */
194 #ifndef SECOND_LOWEST_VALUE
195 #if FPREP == FPREP_IEEE754
202 second_lowest_little = {{0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0xff}},
203 second_lowest_big = {{0xff, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe}};
205 if (endian == LITTLE)
206 second_lowest_value = second_lowest_little.d;
207 else if (endian == BIG)
208 second_lowest_value = second_lowest_big.d;
210 #else /* FPREP != FPREP_IEEE754 */
211 #error Unknown floating-point representation.
212 #endif /* FPREP != FPREP_IEEE754 */
213 #endif /* !SECOND_LOWEST_VALUE */
216 default_dict.var_by_name = avl_create (NULL, cmp_variable, NULL);
218 vec_init (&reinit_sysmis);
219 vec_init (&reinit_blanks);
220 vec_init (&init_zero);
221 vec_init (&init_blanks);
223 last_vfm_invocation = time (NULL);
226 ds_init (NULL, &tokstr, 64);
235 cp = strchr (pgmname, DIR_SEPARATOR);
244 #if !USE_INTERNAL_PAGER
248 pager = getenv ("STAT_PAGER");
250 pager = getenv ("PAGER");
252 set_pager = xstrdup (pager);
255 set_pager = xstrdup (DEFAULT_PAGER);
256 #endif /* DEFAULT_PAGER */
258 #endif /* !USE_INTERNAL_PAGER */
261 set_scompression = 1;
262 set_format.type = FMT_F;
267 set_results_file = xstrdup ("pspp.prc");
268 set_dprompt = xstrdup (_("data> "));
273 for (i = 0; i < 5; i++)
275 struct set_cust_currency *cc = &set_cc[i];
276 strcpy (cc->buf, "-");
277 cc->neg_prefix = cc->buf;
278 cc->prefix = &cc->buf[1];
279 cc->suffix = &cc->buf[1];
280 cc->neg_suffix = &cc->buf[1];
290 set_journal = xstrdup ("pspp.jnl");
299 set_cprompt = xstrdup (" > ");
306 set_prompt = xstrdup ("PSPP> ");
309 #if __DJGPP__ || __BORLANDC__
314 set_viewlength = max (ti.screenheight, 25);
315 set_viewwidth = max (ti.screenwidth, 79);
317 #elif HAVE_LIBTERMCAP
322 /* This code stolen from termcap.info, though modified. */
324 term_buffer = xmalloc (2048);
327 termtype = getenv ("TERM");
329 msg (FE, _("Specify a terminal type with `setenv TERM <yourtype>'."));
332 success = tgetent (NULL, termtype);
334 success = tgetent (term_buffer, termtype);
340 msg (IE, _("Could not access the termcap data base."));
342 msg (IE, _("Terminal type `%s' is not defined."), termtype);
343 msg (MM, _("Assuming screen of size 79x25."));
349 set_viewlength = tgetnum ("li");
350 set_viewwidth = tgetnum ("co") - 1;
353 #else /* !HAVE_LIBTERMCAP */
356 #endif /* !HAVE_LIBTERMCAP */
360 logfn = xstrdup ("pspp.log");
365 extern void fh_init_files (void);
376 static const char *months[12] =
378 N_("Jan"), N_("Feb"), N_("Mar"), N_("Apr"), N_("May"), N_("Jun"),
379 N_("Jul"), N_("Aug"), N_("Sep"), N_("Oct"), N_("Nov"), N_("Dec"),
386 if ((time_t) -1 == time (&t))
388 strcpy (curdate, "1 Jan 1970");
391 tmp = localtime (&t);
405 yr = tmp->tm_year + 1900;
411 sprintf (curdate, "%2d %s %04d", dy, gettext (months[mn]), yr);
415 cmp_variable (const void *a, const void *b, void *foo unused)
417 return strcmp (((struct variable *) a)->name, ((struct variable *) b)->name);
422 _RTLENTRY _EXPFUNC _matherr (struct exception _FAR *__e)
428 _RTLENTRY _EXPFUNC _matherrl (struct _exceptionl _FAR *__e)