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
25 #if TIME_WITH_SYS_TIME
39 #else /* !HAVE_TERMCAP_H */
40 int tgetent (char *, char *);
42 #endif /* !HAVE_TERMCAP_H */
43 #endif /* !HAVE_LIBTERMCAP */
46 #if HAVE_READLINE_HISTORY_H
47 #include <readline/history.h>
48 #else /* no readline/history.h */
49 extern void using_history ();
50 extern int read_history ();
51 extern void stifle_history ();
52 #endif /* no readline/history.h */
53 #endif /* -lhistory */
55 #if HAVE_FPU_CONTROL_H
56 #include <fpu_control.h>
64 #elif __WIN32__ && __BORLANDC__
67 #define gettext(STRING) \
87 #include "julcal/julcal.h"
97 struct dictionary default_dict;
98 struct expression *process_if_expr;
100 struct ccase *temp_case;
102 struct trns_header **t_trns;
107 int FILTER_before_TEMPORARY;
109 struct file_handle *default_handle;
111 void (*read_active_file) (void);
112 void (*cancel_input_pgm) (void);
114 struct ctl_stmt *ctl_stack;
123 static void get_date (void);
125 #if HAVE_LIBTERMCAP && !__CHECKER__
126 static char *term_buffer;
130 init_glob (int argc unused, char **argv)
132 /* FIXME: Allow i18n of other locale items (besides LC_MESSAGES). */
135 setlocale (LC_MESSAGES, "");
137 setlocale (LC_MONETARY, "");
138 bindtextdomain (PACKAGE, locale_dir);
139 textdomain (PACKAGE);
140 #endif /* ENABLE_NLS */
142 /* Workable defaults before we determine the real terminal size. */
149 /* PORTME: If your system/OS has the nasty tendency to halt with a
150 SIGFPE whenever there's a floating-point overflow (or other
151 exception), be sure to mask off those bits in the FPU here.
152 PSPP wants a guarantee that, no matter what boneheaded
153 floating-point operation it performs, the process will not halt. */
154 #if HAVE_FEHOLDEXCEPT
160 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
161 __setfpucw (_FPU_IEEE);
163 _control87 (0xffff, 0x137f);
168 /* Test for endianness borrowed from acspecific.m4, which was in
169 turn borrowed from Harbison&Steele. */
173 char c[sizeof (long)];
178 if (u.c[sizeof u.l - 1] == 1)
180 else if (u.c[0] == 1)
183 msg (FE, _("Your machine does not appear to be either big- or little-"
184 "endian. At the moment, PSPP only supports machines of "
185 "these standard endiannesses. If you want to hack in "
186 "others, contact the author."));
190 /* PORTME: Set the value for second_lowest_value, which is the
191 "second lowest" possible value for a double. This is the value
192 for LOWEST on MISSING VALUES, etc. */
193 #ifndef SECOND_LOWEST_VALUE
194 #if FPREP == FPREP_IEEE754
201 second_lowest_little = {{0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0xff}},
202 second_lowest_big = {{0xff, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe}};
204 if (endian == LITTLE)
205 second_lowest_value = second_lowest_little.d;
206 else if (endian == BIG)
207 second_lowest_value = second_lowest_big.d;
209 #else /* FPREP != FPREP_IEEE754 */
210 #error Unknown floating-point representation.
211 #endif /* FPREP != FPREP_IEEE754 */
212 #endif /* !SECOND_LOWEST_VALUE */
215 default_dict.var_by_name = avl_create (NULL, cmp_variable, NULL);
217 vec_init (&reinit_sysmis);
218 vec_init (&reinit_blanks);
219 vec_init (&init_zero);
220 vec_init (&init_blanks);
222 last_vfm_invocation = time (NULL);
225 ds_init (NULL, &tokstr, 64);
234 cp = strchr (pgmname, DIR_SEPARATOR);
243 #if !USE_INTERNAL_PAGER
247 pager = getenv ("STAT_PAGER");
249 pager = getenv ("PAGER");
251 set_pager = xstrdup (pager);
254 set_pager = xstrdup (DEFAULT_PAGER);
255 #endif /* DEFAULT_PAGER */
257 #endif /* !USE_INTERNAL_PAGER */
260 set_scompression = 1;
261 set_format.type = FMT_F;
266 set_results_file = xstrdup ("pspp.prc");
267 set_dprompt = xstrdup (_("data> "));
272 for (i = 0; i < 5; i++)
274 struct set_cust_currency *cc = &set_cc[i];
275 strcpy (cc->buf, "-");
276 cc->neg_prefix = cc->buf;
277 cc->prefix = &cc->buf[1];
278 cc->suffix = &cc->buf[1];
279 cc->neg_suffix = &cc->buf[1];
289 set_journal = xstrdup ("pspp.jnl");
298 set_cprompt = xstrdup (" > ");
305 set_prompt = xstrdup ("PSPP> ");
308 #if __DJGPP__ || __BORLANDC__
313 set_viewlength = max (ti.screenheight, 25);
314 set_viewwidth = max (ti.screenwidth, 79);
316 #elif HAVE_LIBTERMCAP
321 /* This code stolen from termcap.info, though modified. */
323 term_buffer = xmalloc (2048);
326 termtype = getenv ("TERM");
328 msg (FE, _("Specify a terminal type with `setenv TERM <yourtype>'."));
331 success = tgetent (NULL, termtype);
333 success = tgetent (term_buffer, termtype);
339 msg (IE, _("Could not access the termcap data base."));
341 msg (IE, _("Terminal type `%s' is not defined."), termtype);
342 msg (MM, _("Assuming screen of size 79x25."));
348 set_viewlength = tgetnum ("li");
349 set_viewwidth = tgetnum ("co") - 1;
352 #else /* !HAVE_LIBTERMCAP */
355 #endif /* !HAVE_LIBTERMCAP */
359 logfn = xstrdup ("pspp.log");
364 extern void fh_init_files (void);
375 static const char *months[12] =
377 N_("Jan"), N_("Feb"), N_("Mar"), N_("Apr"), N_("May"), N_("Jun"),
378 N_("Jul"), N_("Aug"), N_("Sep"), N_("Oct"), N_("Nov"), N_("Dec"),
385 if ((time_t) -1 == time (&t))
387 strcpy (curdate, "1 Jan 1970");
390 tmp = localtime (&t);
404 yr = tmp->tm_year + 1900;
410 sprintf (curdate, "%2d %s %04d", dy, gettext (months[mn]), yr);
414 cmp_variable (const void *a, const void *b, void *foo unused)
416 return strcmp (((struct variable *) a)->name, ((struct variable *) b)->name);
421 _RTLENTRY _EXPFUNC _matherr (struct exception _FAR *__e)
427 _RTLENTRY _EXPFUNC _matherrl (struct _exceptionl _FAR *__e)