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