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