Separate random numbers from other settings because of GSL dependency.
[pspp] / src / glob.c
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
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.
9
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.
14
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
18    02110-1301, USA. */
19
20 #include <config.h>
21 #include "glob.h"
22 #include "error.h"
23 #include "progname.h"
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <time.h>
27
28 #if HAVE_LIBHISTORY
29 #if HAVE_READLINE_HISTORY_H
30 #include <readline/history.h>
31 #else /* no readline/history.h */
32 extern void using_history ();
33 extern int read_history ();
34 extern void stifle_history ();
35 #endif /* no readline/history.h */
36 #endif /* -lhistory */
37
38 #if HAVE_FPU_CONTROL_H
39 #include <fpu_control.h>
40 #elif __BORLANDC__
41 #include <float.h>
42 #include <math.h>
43 #endif
44
45 #if __DJGPP__
46 #include <conio.h>
47 #elif defined (__WIN32__) && defined (__BORLANDC__)
48 #undef gettext
49 #include <conio.h>
50 #define gettext(STRING)                         \
51         STRING
52 #endif
53
54 #if HAVE_LOCALE_H
55 #include <locale.h>
56 #endif
57
58 #if HAVE_FENV_H
59 #include <fenv.h>
60 #endif
61
62 #include "alloc.h"
63 #include "calendar.h"
64 #include "command.h"
65 #include "dictionary.h"
66 #include "error.h"
67 #include "file-handle.h"
68 #include "filename.h"
69 #include "getl.h"
70 #include "hash.h"
71 #include "lexer.h"
72 #include "magic.h"
73 #include "main.h"
74 #include "random.h"
75 #include "settings.h"
76 #include "str.h"
77 #include "var.h"
78 #include "version.h"
79 #include "vfm.h"
80
81 #include "gettext.h"
82
83 /* var.h */
84 struct dictionary *default_dict;
85 struct expression *process_if_expr;
86
87 struct transformation *t_trns;
88 size_t n_trns, m_trns, f_trns;
89
90 int FILTER_before_TEMPORARY;
91
92 struct file_handle *default_handle;
93
94 /* log.h */
95 char *logfn;
96 FILE *logfile;
97 int logging;
98 \f
99 /* Functions. */
100
101 static void get_date (void);
102
103
104 void
105 init_glob (int argc UNUSED, char **argv)
106 {
107   set_program_name (argv[0]);
108
109   /* FIXME: Allow i18n of other locale items (besides LC_MESSAGES). */
110 #if ENABLE_NLS
111 #if HAVE_LC_MESSAGES
112   setlocale (LC_MESSAGES, "");
113 #endif
114   setlocale (LC_MONETARY, "");
115   bindtextdomain (PACKAGE, locale_dir);
116   textdomain (PACKAGE);
117 #endif /* ENABLE_NLS */
118
119   fn_init ();
120   fh_init ();
121   getl_initialize ();
122
123   /* PORTME: If your system/OS has the nasty tendency to halt with a
124      SIGFPE whenever there's a floating-point overflow (or other
125      exception), be sure to mask off those bits in the FPU here.
126      PSPP wants a guarantee that, no matter what boneheaded
127      floating-point operation it performs, the process will not halt.  */
128 #if HAVE_FEHOLDEXCEPT
129   {
130     fenv_t foo;
131
132     feholdexcept (&foo);
133   }
134 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
135   __setfpucw (_FPU_IEEE);
136 #elif __BORLANDC__
137   _control87 (0xffff, 0x137f);
138 #endif
139
140   /* var.h */
141   default_dict = dict_create ();
142
143   last_vfm_invocation = time (NULL);
144
145   /* lexer.h */
146   ds_init (&tokstr, 64);
147
148   /* common.h */
149   {
150     char *cp;
151     
152     pgmname = argv[0];
153     for (;;)
154       {
155         cp = strchr (pgmname, DIR_SEPARATOR);
156         if (!cp)
157           break;
158         pgmname = &cp[1];
159       }
160     cur_proc = NULL;
161   }
162
163
164   init_settings ();
165   random_init ();
166
167   /* log.h */
168   logging = 1;
169   logfn = xstrdup ("pspp.log");
170   logfile = NULL;
171
172   get_date ();
173 }
174
175 void
176 done_glob(void)
177 {
178   cancel_transformations ();
179   dict_destroy (default_dict);
180   free (logfn);
181   random_done ();
182   done_settings ();
183   ds_destroy (&tokstr);
184
185   fh_done();
186 }
187
188 static void
189 get_date (void)
190 {
191
192   time_t t;
193   struct tm *tmp;
194
195   if ((time_t) -1 == time (&t))
196     {
197       strcpy (curdate, "?? ??? 2???");
198       return;
199     }
200   tmp = localtime (&t);
201
202   strftime (curdate, 12, "%d %b %Y",tmp);
203 }
204
205 #if __BORLANDC__
206 int
207 _RTLENTRY _EXPFUNC _matherr (struct exception _FAR *__e)
208 {
209   return 1;
210 }
211
212 int
213 _RTLENTRY _EXPFUNC _matherrl (struct _exceptionl _FAR *__e)
214 {
215   return 1;
216 }
217 #endif