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