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