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