Fully implement arbitrary delimiters on DATA LIST, extending the half
[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 "do-ifP.h"
74 #include "error.h"
75 #include "expr.h"
76 #include "file-handle.h"
77 #include "filename.h"
78 #include "getline.h"
79 #include "hash.h"
80 #include "julcal/julcal.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   getl_initialize ();
130
131   /* PORTME: If your system/OS has the nasty tendency to halt with a
132      SIGFPE whenever there's a floating-point overflow (or other
133      exception), be sure to mask off those bits in the FPU here.
134      PSPP wants a guarantee that, no matter what boneheaded
135      floating-point operation it performs, the process will not halt.  */
136 #if HAVE_FEHOLDEXCEPT
137   {
138     fenv_t foo;
139
140     feholdexcept (&foo);
141   }
142 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
143   __setfpucw (_FPU_IEEE);
144 #elif __BORLANDC__
145   _control87 (0xffff, 0x137f);
146 #endif
147
148   /* var.h */
149   default_dict = dict_create ();
150
151   last_vfm_invocation = time (NULL);
152
153   /* lexer.h */
154   ds_init (&tokstr, 64);
155
156   /* common.h */
157   {
158     char *cp;
159     
160     pgmname = argv[0];
161     for (;;)
162       {
163         cp = strchr (pgmname, DIR_SEPARATOR);
164         if (!cp)
165           break;
166         pgmname = &cp[1];
167       }
168     cur_proc = NULL;
169   }
170
171
172   init_settings();
173
174   /* log.h */
175   logging = 1;
176   logfn = xstrdup ("pspp.log");
177   logfile = NULL;
178
179   /* file-handle.h */
180   fh_init_files ();
181   
182   get_date ();
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