Separate settings and the SET command, for modularity.
[pspp-builds.git] / 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 "settings.h"
75 #include "str.h"
76 #include "var.h"
77 #include "version.h"
78 #include "vfm.h"
79
80 #include "gettext.h"
81
82 /* var.h */
83 struct dictionary *default_dict;
84 struct expression *process_if_expr;
85
86 struct transformation *t_trns;
87 size_t n_trns, m_trns, f_trns;
88
89 int FILTER_before_TEMPORARY;
90
91 struct file_handle *default_handle;
92
93 /* log.h */
94 char *logfn;
95 FILE *logfile;
96 int logging;
97 \f
98 /* Functions. */
99
100 static void get_date (void);
101
102
103 void
104 init_glob (int argc UNUSED, char **argv)
105 {
106   set_program_name (argv[0]);
107
108   /* FIXME: Allow i18n of other locale items (besides LC_MESSAGES). */
109 #if ENABLE_NLS
110 #if HAVE_LC_MESSAGES
111   setlocale (LC_MESSAGES, "");
112 #endif
113   setlocale (LC_MONETARY, "");
114   bindtextdomain (PACKAGE, locale_dir);
115   textdomain (PACKAGE);
116 #endif /* ENABLE_NLS */
117
118   fn_init ();
119   fh_init ();
120   getl_initialize ();
121
122   /* PORTME: If your system/OS has the nasty tendency to halt with a
123      SIGFPE whenever there's a floating-point overflow (or other
124      exception), be sure to mask off those bits in the FPU here.
125      PSPP wants a guarantee that, no matter what boneheaded
126      floating-point operation it performs, the process will not halt.  */
127 #if HAVE_FEHOLDEXCEPT
128   {
129     fenv_t foo;
130
131     feholdexcept (&foo);
132   }
133 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
134   __setfpucw (_FPU_IEEE);
135 #elif __BORLANDC__
136   _control87 (0xffff, 0x137f);
137 #endif
138
139   /* var.h */
140   default_dict = dict_create ();
141
142   last_vfm_invocation = time (NULL);
143
144   /* lexer.h */
145   ds_init (&tokstr, 64);
146
147   /* common.h */
148   {
149     char *cp;
150     
151     pgmname = argv[0];
152     for (;;)
153       {
154         cp = strchr (pgmname, DIR_SEPARATOR);
155         if (!cp)
156           break;
157         pgmname = &cp[1];
158       }
159     cur_proc = NULL;
160   }
161
162
163   init_settings();
164
165   /* log.h */
166   logging = 1;
167   logfn = xstrdup ("pspp.log");
168   logfile = NULL;
169
170   get_date ();
171 }
172
173 void
174 done_glob(void)
175 {
176   cancel_transformations ();
177   dict_destroy (default_dict);
178   free (logfn);
179   done_settings ();
180   ds_destroy (&tokstr);
181
182   fh_done();
183 }
184
185 static void
186 get_date (void)
187 {
188
189   time_t t;
190   struct tm *tmp;
191
192   if ((time_t) -1 == time (&t))
193     {
194       strcpy (curdate, "?? ??? 2???");
195       return;
196     }
197   tmp = localtime (&t);
198
199   strftime (curdate, 12, "%d %b %Y",tmp);
200 }
201
202 #if __BORLANDC__
203 int
204 _RTLENTRY _EXPFUNC _matherr (struct exception _FAR *__e)
205 {
206   return 1;
207 }
208
209 int
210 _RTLENTRY _EXPFUNC _matherrl (struct _exceptionl _FAR *__e)
211 {
212   return 1;
213 }
214 #endif