1 | #ifndef FEBASE_H |
---|
2 | #define FEBASE_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* $Id: febase.h,v 1.17 1998-05-25 21:28:31 obachman Exp $ */ |
---|
7 | /* |
---|
8 | * ABSTRACT |
---|
9 | */ |
---|
10 | #include <stdio.h> |
---|
11 | #include <string.h> |
---|
12 | #include "structs.h" |
---|
13 | |
---|
14 | |
---|
15 | /* |
---|
16 | // These are our versions of fopen and fread They are very similar to |
---|
17 | // the usual fopen and fread, except that on reading, they always |
---|
18 | // convert "\r\n" into " \n" and "\r" into "\n". |
---|
19 | // |
---|
20 | // IMPORTANT: do only use myfopen and myfread when reading text, |
---|
21 | // do never use fopen and fread |
---|
22 | */ |
---|
23 | #ifndef unix |
---|
24 | extern FILE *myfopen(char *path, char *mode); |
---|
25 | #else |
---|
26 | #define myfopen fopen |
---|
27 | #endif |
---|
28 | extern size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream); |
---|
29 | |
---|
30 | extern char* feErrors; |
---|
31 | extern int feErrorsLen; |
---|
32 | extern FILE* feProtFile; |
---|
33 | extern FILE* feFilePending; /*temp. storage for grammar.y */ |
---|
34 | extern char fe_promptstr[]; |
---|
35 | extern int si_echo, printlevel; |
---|
36 | extern int pagelength, colmax; |
---|
37 | extern int yy_blocklineno; |
---|
38 | extern int yy_noeof; |
---|
39 | extern char prompt_char; |
---|
40 | extern const char feNotImplemented[]; |
---|
41 | #ifdef HAVE_TCL |
---|
42 | extern BOOLEAN tclmode; |
---|
43 | #endif |
---|
44 | extern BOOLEAN errorreported; |
---|
45 | extern BOOLEAN fe_use_fgets; |
---|
46 | extern BOOLEAN feBatch; |
---|
47 | extern BOOLEAN feProt; |
---|
48 | |
---|
49 | #define PROT_NONE 0 |
---|
50 | #define PROT_I 1 |
---|
51 | #define PROT_O 2 |
---|
52 | #define PROT_IO 3 |
---|
53 | |
---|
54 | /* the C-part: */ |
---|
55 | #ifdef __cplusplus |
---|
56 | extern "C" { |
---|
57 | #endif |
---|
58 | |
---|
59 | void Werror(char *fmt, ...); |
---|
60 | void WerrorS(const char *s); |
---|
61 | |
---|
62 | #ifdef __cplusplus |
---|
63 | } |
---|
64 | /* the C++-part: */ |
---|
65 | |
---|
66 | enum feBufferTypes |
---|
67 | { |
---|
68 | BT_none = 0, // entry level |
---|
69 | BT_break = 1, // while, for |
---|
70 | BT_proc, // proc |
---|
71 | BT_example, // example |
---|
72 | BT_file, // <"file" |
---|
73 | BT_execute, // execute |
---|
74 | BT_if, // if |
---|
75 | BT_else // else |
---|
76 | }; |
---|
77 | |
---|
78 | enum feBufferInputs |
---|
79 | { |
---|
80 | BI_stdin = 1, |
---|
81 | BI_buffer, |
---|
82 | BI_file |
---|
83 | }; |
---|
84 | |
---|
85 | char* feGetSearchPath(const char* argv0 = NULL); |
---|
86 | char* feGetExpandedExecutable(const char* argv0 = NULL); |
---|
87 | FILE * feFopen(char *path, char *mode, char *where=NULL, int useWerror=FALSE); |
---|
88 | void fePause(void); |
---|
89 | void Print(char* fmt, ...); |
---|
90 | void PrintS(char* s); |
---|
91 | void PrintLn(); |
---|
92 | void PrintTCLS(char c, char * s); |
---|
93 | #ifndef macintosh |
---|
94 | inline void PrintTCL(char c, int l,char *s) |
---|
95 | { |
---|
96 | #ifdef HAVE_TCL |
---|
97 | if (s!=NULL) printf("%c:%d:%s\n",c,l,s); |
---|
98 | else printf("%c:%d:\n",c,l); |
---|
99 | fflush(stdout); |
---|
100 | #endif |
---|
101 | } |
---|
102 | #endif |
---|
103 | |
---|
104 | char * StringAppend(char *fmt, ...); |
---|
105 | char * StringAppendS(char *s); |
---|
106 | char * StringSet(char *fmt, ...); |
---|
107 | char * StringSetS(char* s); |
---|
108 | const char * VoiceName(); |
---|
109 | void VoiceBackTrack(); |
---|
110 | void WarnS(const char *s); |
---|
111 | void Warn(const char *fmt, ...); |
---|
112 | BOOLEAN contBuffer(feBufferTypes typ); |
---|
113 | char * eati(char *s, int *i); |
---|
114 | BOOLEAN exitBuffer(feBufferTypes typ); |
---|
115 | BOOLEAN exitVoice(); |
---|
116 | #define mflush() fflush(stdout) |
---|
117 | void monitor(char* s,int mode); |
---|
118 | BOOLEAN newFile(char* fname, FILE *f=NULL); |
---|
119 | void newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0); |
---|
120 | void * myynewbuffer(); |
---|
121 | void myyoldbuffer(void * oldb); |
---|
122 | |
---|
123 | /* assume(x) -- a handy macro for assumptions */ |
---|
124 | #ifdef NDEBUG |
---|
125 | /* empty macro, if NDEBUG */ |
---|
126 | #define assume(x) ((void*) 0) |
---|
127 | #else /* ! NDEBUG */ |
---|
128 | #define assume(x) _assume(x, __FILE__, __LINE__) |
---|
129 | #define _assume(x, f, l) \ |
---|
130 | do \ |
---|
131 | { \ |
---|
132 | if (! (x)) \ |
---|
133 | { \ |
---|
134 | Warn("Internal assume violation: file %s line %d\n", f, l); \ |
---|
135 | } \ |
---|
136 | } \ |
---|
137 | while (0) |
---|
138 | #endif /* NDEBUG */ |
---|
139 | |
---|
140 | class Voice |
---|
141 | { |
---|
142 | public: |
---|
143 | Voice * next; |
---|
144 | Voice * prev; |
---|
145 | char * filename; // file name or proc name |
---|
146 | procinfo * pi; // proc info |
---|
147 | void * oldb; // internal scanner buffer |
---|
148 | int start_lineno; // lineno, to restore in recursion |
---|
149 | int curr_lineno; // current lineno |
---|
150 | feBufferInputs sw; // BI_stdin: read from STDIN |
---|
151 | // BI_buffer: buffer |
---|
152 | // BI_file: files |
---|
153 | char ifsw; // if-switch: |
---|
154 | /*1 ifsw==0: no if statement, else is invalid |
---|
155 | * ==1: if (0) processed, execute else |
---|
156 | * ==2: if (1) processed, else allowed but not executed |
---|
157 | */ |
---|
158 | feBufferTypes typ; // buffer type: see BT_.. |
---|
159 | // for files only: |
---|
160 | FILE * files; // file handle |
---|
161 | // for buffers only: |
---|
162 | char * buffer; // buffer pointer |
---|
163 | long fptr; // current position in buffer |
---|
164 | |
---|
165 | Voice() { memset(this,0,sizeof(*this));} |
---|
166 | feBufferTypes Typ(); |
---|
167 | void Next(); |
---|
168 | } ; |
---|
169 | |
---|
170 | extern Voice *currentVoice; |
---|
171 | |
---|
172 | Voice * feInitStdin(); |
---|
173 | |
---|
174 | /* feread.cc: */ |
---|
175 | #ifdef HAVE_FEREAD |
---|
176 | void fe_set_input_mode (void); |
---|
177 | void fe_temp_set (void); |
---|
178 | void fe_temp_reset (void); |
---|
179 | char * fe_fgets_stdin(char *s, int size); |
---|
180 | #ifndef MSDOS |
---|
181 | #ifdef HAVE_ATEXIT |
---|
182 | void fe_reset_input_mode (void); |
---|
183 | #else |
---|
184 | void fe_reset_input_mode (int i, void *v); |
---|
185 | #endif |
---|
186 | #else |
---|
187 | #define fe_reset_input_mode() |
---|
188 | #endif |
---|
189 | #else |
---|
190 | #ifdef HAVE_READLINE |
---|
191 | void fe_set_input_mode (void); |
---|
192 | void fe_reset_input_mode (void); |
---|
193 | char * fe_fgets_stdin_rl(char *pr,char *s, int size); |
---|
194 | #define fe_fgets_stdin(A,B) fe_fgets_stdin_rl(fe_promptstr,A,B) |
---|
195 | #else |
---|
196 | #define fe_fgets_stdin(A,B) fgets(A,B,stdin) |
---|
197 | #endif |
---|
198 | #endif |
---|
199 | #endif |
---|
200 | #endif |
---|