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