1 | #ifndef FEBASE_H |
---|
2 | #define FEBASE_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* $Id: febase.h,v 1.14 2008-09-12 14:13:32 Singular Exp $ */ |
---|
7 | /* |
---|
8 | * ABSTRACT: basic i/o |
---|
9 | */ |
---|
10 | #include <stdio.h> |
---|
11 | #include <string.h> |
---|
12 | #include "structs.h" |
---|
13 | |
---|
14 | /* define DIR_SEPP, etc */ |
---|
15 | /* unix , WINNT */ |
---|
16 | # define DIR_SEP '/' |
---|
17 | # define DIR_SEPP "/" |
---|
18 | # define UP_DIR ".." |
---|
19 | // this might still get reset by feInitResources |
---|
20 | extern char fePathSep; |
---|
21 | |
---|
22 | /* define MAXPATHLEN */ |
---|
23 | #ifdef HAVE_SYS_PARAM_H |
---|
24 | #include <sys/param.h> |
---|
25 | #endif |
---|
26 | |
---|
27 | /* the are versions of limits.h with incorrect values (IRIX_6) |
---|
28 | * let's include our own */ |
---|
29 | |
---|
30 | #include <mylimits.h> |
---|
31 | |
---|
32 | /* OSF/1 and AIX_4 are missing the header for setenv, but the proc exists */ |
---|
33 | #if defined(DecAlpha_OSF1) || defined(AIX_4) |
---|
34 | #ifdef __cplusplus |
---|
35 | extern "C" |
---|
36 | { |
---|
37 | #endif |
---|
38 | int setenv(const char *name, const char *value, int overwrite); |
---|
39 | #ifdef __cplusplus |
---|
40 | } |
---|
41 | #endif |
---|
42 | #endif |
---|
43 | |
---|
44 | #ifndef MAXPATHLEN |
---|
45 | #define MAXPATHLEN 1024 |
---|
46 | #endif |
---|
47 | |
---|
48 | #ifdef HAVE_LIBREADLINE |
---|
49 | #define HAVE_READLINE 1 |
---|
50 | #endif |
---|
51 | |
---|
52 | #ifdef HAVE_DYN_RL |
---|
53 | #undef HAVE_READLINE |
---|
54 | #define HAVE_FEREAD 1 |
---|
55 | #elif ! defined(HAVE_READLINE) |
---|
56 | #ifndef ix86_Win |
---|
57 | #define HAVE_FEREAD 1 |
---|
58 | #endif |
---|
59 | #endif |
---|
60 | #ifdef ix86_Linux |
---|
61 | // FEREAD stuff does not work with glibc2 |
---|
62 | #undef HAVE_FEREAD |
---|
63 | #endif |
---|
64 | |
---|
65 | /* |
---|
66 | // These are our versions of fopen and fread They are very similar to |
---|
67 | // the usual fopen and fread, except that on reading, they always |
---|
68 | // convert "\r\n" into " \n" and "\r" into "\n". |
---|
69 | // |
---|
70 | // IMPORTANT: do only use myfopen and myfread when reading text, |
---|
71 | // do never use fopen and fread |
---|
72 | */ |
---|
73 | #ifdef ix86_Win |
---|
74 | FILE *myfopen(const char *path, const char *mode); |
---|
75 | #else |
---|
76 | #define myfopen fopen |
---|
77 | #endif |
---|
78 | size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream); |
---|
79 | |
---|
80 | |
---|
81 | extern char* feErrors; |
---|
82 | extern char* feArgv0; |
---|
83 | extern int feErrorsLen; |
---|
84 | extern FILE* feProtFile; |
---|
85 | extern FILE* feFilePending; /*temp. storage for grammar.y */ |
---|
86 | extern char fe_promptstr[]; |
---|
87 | extern int si_echo, printlevel; |
---|
88 | extern int pagelength, colmax; |
---|
89 | extern int yy_blocklineno; |
---|
90 | extern int yy_noeof; |
---|
91 | extern char prompt_char; |
---|
92 | extern const char feNotImplemented[]; |
---|
93 | #ifdef HAVE_TCL |
---|
94 | extern BOOLEAN tclmode; |
---|
95 | #endif |
---|
96 | extern BOOLEAN errorreported; |
---|
97 | extern int feProt; |
---|
98 | extern BOOLEAN feWarn; |
---|
99 | extern BOOLEAN feOut; |
---|
100 | |
---|
101 | |
---|
102 | #define PROT_NONE 0 |
---|
103 | #define PROT_I 1 |
---|
104 | #define PROT_O 2 |
---|
105 | #define PROT_IO 3 |
---|
106 | |
---|
107 | /* the C-part: */ |
---|
108 | #define mflush() fflush(stdout) |
---|
109 | |
---|
110 | #ifdef __cplusplus |
---|
111 | extern "C" { |
---|
112 | #endif |
---|
113 | |
---|
114 | void Werror(const char *fmt, ...) __attribute__((format(printf,1,2))); |
---|
115 | void WerrorS(const char *s); |
---|
116 | void WarnS(const char *s); |
---|
117 | void Print(const char* fmt, ...) __attribute__((format(printf,1,2))); |
---|
118 | /* Print should not produce more than strlen(fmt)+510 characters! */ |
---|
119 | |
---|
120 | void PrintNSpaces(const int n); |
---|
121 | void PrintLn(); |
---|
122 | #ifdef HAVE_TCL |
---|
123 | void PrintTCLS(const char c, const char * s); |
---|
124 | #else |
---|
125 | #define PrintTCLS(A,B) Print("TCL-ErrS:%s",B) |
---|
126 | #endif |
---|
127 | void PrintS(const char* s); |
---|
128 | char* feGetResource(const char id); |
---|
129 | |
---|
130 | #ifdef HAVE_FEREAD |
---|
131 | extern BOOLEAN fe_is_raw_tty; |
---|
132 | void fe_temp_reset (void); |
---|
133 | #endif |
---|
134 | |
---|
135 | #ifdef __cplusplus |
---|
136 | } |
---|
137 | /* the C++-part: */ |
---|
138 | |
---|
139 | enum feBufferTypes |
---|
140 | { |
---|
141 | BT_none = 0, // entry level |
---|
142 | BT_break = 1, // while, for |
---|
143 | BT_proc, // proc |
---|
144 | BT_example, // example |
---|
145 | BT_file, // <"file" |
---|
146 | BT_execute, // execute |
---|
147 | BT_if, // if |
---|
148 | BT_else // else |
---|
149 | }; |
---|
150 | |
---|
151 | enum feBufferInputs |
---|
152 | { |
---|
153 | BI_stdin = 1, |
---|
154 | BI_buffer, |
---|
155 | BI_file |
---|
156 | }; |
---|
157 | |
---|
158 | /***************************************************************** |
---|
159 | * |
---|
160 | * Resource management (feResources.cc) |
---|
161 | * |
---|
162 | *****************************************************************/ |
---|
163 | // returns value of Resource as read-only string, or NULL |
---|
164 | // if Resource not found |
---|
165 | // issues warning, if explicitely requested (warn > 0), or |
---|
166 | // if warn < 0 and Resource is gotten for the first time |
---|
167 | // Always quiet if warn == 0 |
---|
168 | char* feResource(const char id, int warn = -1); |
---|
169 | char* feResource(const char* key, int warn = -1); |
---|
170 | // This needs to be called before the first call to feResource |
---|
171 | // Initializes Resources, SearchPath, and extends PATH |
---|
172 | void feInitResources(char* argv0); |
---|
173 | // Re-inits resources, should be called after changing env. variables |
---|
174 | void feReInitResources(); |
---|
175 | // Prints resources into string with StringAppend, etc |
---|
176 | void feStringAppendResources(int warn = -1); |
---|
177 | |
---|
178 | /***************************************************************** |
---|
179 | * |
---|
180 | * help system (fehelp.cc) |
---|
181 | * |
---|
182 | *****************************************************************/ |
---|
183 | // if str != NULL display help for str |
---|
184 | // display general help, otherwise |
---|
185 | void feHelp(char* str = NULL); |
---|
186 | // if browser != NULL or feOpt("browser") != NULL |
---|
187 | // set HelpBrowser to browser |
---|
188 | // otherwise, if browser was already set, leave as is, |
---|
189 | // if not, choose first available browser |
---|
190 | // return string identifying current browser |
---|
191 | // keeps feOpt("browser") up-to-date |
---|
192 | // Optional warn argument is as in feResource |
---|
193 | const char* feHelpBrowser(char* browser = NULL, int warn = -1); |
---|
194 | void feStringAppendBrowsers(int warn = -1); |
---|
195 | |
---|
196 | /***************************************************************** |
---|
197 | * |
---|
198 | * version Id |
---|
199 | * |
---|
200 | *****************************************************************/ |
---|
201 | /* extern unsigned long feVersionId; */ |
---|
202 | |
---|
203 | /***************************************************************** |
---|
204 | * |
---|
205 | * File Stuff |
---|
206 | * |
---|
207 | *****************************************************************/ |
---|
208 | FILE * feFopen(const char *path, const char *mode, char *where=NULL, |
---|
209 | int useWerror=FALSE, int path_only=FALSE); |
---|
210 | |
---|
211 | #ifdef HAVE_TCL |
---|
212 | |
---|
213 | inline void PrintTCL(const char c, int l,const char *s) |
---|
214 | { |
---|
215 | if (s!=NULL) printf("%c:%d:%s",c,l,s); |
---|
216 | else if(l==0) printf("%c:0:",c); |
---|
217 | else printf("%c:1:%c",c,'0'+l); |
---|
218 | fflush(stdout); |
---|
219 | } |
---|
220 | #else |
---|
221 | #define PrintTCL(A,B,C) Print("TCL-Err:%s",C) |
---|
222 | #endif /* HAVE_TCL */ |
---|
223 | |
---|
224 | char * StringAppend(const char *fmt, ...); |
---|
225 | char * StringAppendS(const char *s); |
---|
226 | char * StringSetS(const char* s); |
---|
227 | const char * VoiceName(); |
---|
228 | void VoiceBackTrack(); |
---|
229 | void Warn(const char *fmt, ...); |
---|
230 | BOOLEAN contBuffer(feBufferTypes typ); |
---|
231 | const char * eati(const char *s, int *i); |
---|
232 | BOOLEAN exitBuffer(feBufferTypes typ); |
---|
233 | BOOLEAN exitVoice(); |
---|
234 | void monitor(void *F, int mode); /* FILE*, int */ |
---|
235 | BOOLEAN newFile(char* fname, FILE *f=NULL); |
---|
236 | void newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0); |
---|
237 | void * myynewbuffer(); |
---|
238 | void myyoldbuffer(void * oldb); |
---|
239 | |
---|
240 | class Voice |
---|
241 | { |
---|
242 | public: |
---|
243 | Voice * next; |
---|
244 | Voice * prev; |
---|
245 | char * filename; // file name or proc name |
---|
246 | procinfo * pi; // proc info |
---|
247 | void * oldb; // internal scanner buffer |
---|
248 | // for files only: |
---|
249 | FILE * files; // file handle |
---|
250 | // for buffers only: |
---|
251 | char * buffer; // buffer pointer |
---|
252 | long fptr; // current position in buffer |
---|
253 | |
---|
254 | int start_lineno; // lineno, to restore in recursion |
---|
255 | int curr_lineno; // current lineno |
---|
256 | feBufferInputs sw; // BI_stdin: read from STDIN |
---|
257 | // BI_buffer: buffer |
---|
258 | // BI_file: files |
---|
259 | char ifsw; // if-switch: |
---|
260 | /*1 ifsw==0: no if statement, else is invalid |
---|
261 | * ==1: if (0) processed, execute else |
---|
262 | * ==2: if (1) processed, else allowed but not executed |
---|
263 | */ |
---|
264 | feBufferTypes typ; // buffer type: see BT_.. |
---|
265 | |
---|
266 | Voice() { memset(this,0,sizeof(*this));} |
---|
267 | feBufferTypes Typ(); |
---|
268 | void Next(); |
---|
269 | } ; |
---|
270 | |
---|
271 | extern Voice *currentVoice; |
---|
272 | |
---|
273 | Voice * feInitStdin(Voice *pp); |
---|
274 | |
---|
275 | /* feread.cc: */ |
---|
276 | |
---|
277 | /* the interface for reading: */ |
---|
278 | extern char * (*fe_fgets_stdin)(const char *pr,char *s, int size); |
---|
279 | |
---|
280 | #ifdef HAVE_DYN_RL |
---|
281 | char * fe_fgets_stdin_drl(const char *pr,char *s, int size); |
---|
282 | #endif |
---|
283 | |
---|
284 | extern "C" void fe_reset_input_mode(); |
---|
285 | |
---|
286 | extern "C" { |
---|
287 | #ifndef HAVE_ATEXIT |
---|
288 | void fe_reset_fe (int i, void *v); |
---|
289 | #else |
---|
290 | void fe_reset_fe (void); |
---|
291 | #endif |
---|
292 | } |
---|
293 | |
---|
294 | |
---|
295 | /* possible implementations: */ |
---|
296 | #ifdef __cplusplus |
---|
297 | extern "C" |
---|
298 | { |
---|
299 | #endif |
---|
300 | /* readline, linked in: */ |
---|
301 | char * fe_fgets_stdin_rl(const char *pr,char *s, int size); |
---|
302 | |
---|
303 | /* emulated readline: */ |
---|
304 | char * fe_fgets_stdin_emu(const char *pr,char *s, int size); |
---|
305 | |
---|
306 | /* fgets: */ |
---|
307 | char * fe_fgets(const char *pr,char *s, int size); |
---|
308 | |
---|
309 | #ifdef HAVE_TCL |
---|
310 | /* tcl: */ |
---|
311 | char * fe_fgets_tcl(const char *pr,char *s, int size); |
---|
312 | #endif |
---|
313 | |
---|
314 | /* dummy (for batch mode): */ |
---|
315 | char * fe_fgets_dummy(const char *pr,char *s, int size); |
---|
316 | |
---|
317 | #ifdef __cplusplus |
---|
318 | } |
---|
319 | #endif |
---|
320 | #endif /* c++ only */ |
---|
321 | |
---|
322 | /* everything in between calls to these procedures is printed into a string |
---|
323 | * which is returned by SprintEnd() |
---|
324 | */ |
---|
325 | void SPrintStart(); |
---|
326 | char* SPrintEnd(); |
---|
327 | |
---|
328 | |
---|
329 | #endif /* ifndef FEBASE_H */ |
---|