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