1 | #ifndef FEBASE_H |
---|
2 | #define FEBASE_H |
---|
3 | /**************************************** |
---|
4 | * * Computer Algebra System SINGULAR * |
---|
5 | * ****************************************/ |
---|
6 | /* $Id: febase.h 14137 2011-04-11 16:39:34Z hannes $ */ |
---|
7 | /* |
---|
8 | * * ABSTRACT: basic i/o |
---|
9 | * */ |
---|
10 | |
---|
11 | #include <reporter/reporter.h> |
---|
12 | #include <resources/feFopen.h> |
---|
13 | #include <resources/feResource.h> |
---|
14 | #include <kernel/structs.h> |
---|
15 | |
---|
16 | enum feBufferTypes |
---|
17 | { |
---|
18 | BT_none = 0, // entry level |
---|
19 | BT_break = 1, // while, for |
---|
20 | BT_proc, // proc |
---|
21 | BT_example, // example |
---|
22 | BT_file, // <"file" |
---|
23 | BT_execute, // execute |
---|
24 | BT_if, // if |
---|
25 | BT_else // else |
---|
26 | }; |
---|
27 | |
---|
28 | enum feBufferInputs |
---|
29 | { |
---|
30 | BI_stdin = 1, |
---|
31 | BI_buffer, |
---|
32 | BI_file |
---|
33 | }; |
---|
34 | enum noeof_t |
---|
35 | { |
---|
36 | noeof_brace = 1, |
---|
37 | noeof_asstring, |
---|
38 | noeof_block, |
---|
39 | noeof_bracket, |
---|
40 | noeof_comment, |
---|
41 | noeof_procname, |
---|
42 | noeof_string |
---|
43 | }; /* for scanner.l */ |
---|
44 | |
---|
45 | extern int myynest; |
---|
46 | extern int yylineno; |
---|
47 | extern char my_yylinebuf[80]; |
---|
48 | |
---|
49 | #ifdef __cplusplus |
---|
50 | |
---|
51 | /* the C++-part: */ |
---|
52 | |
---|
53 | typedef enum { LANG_NONE, LANG_TOP, LANG_SINGULAR, LANG_C, LANG_MAX} language_defs; |
---|
54 | // LANG_TOP : Toplevel package only |
---|
55 | // LANG_SINGULAR: |
---|
56 | // LANG_C : |
---|
57 | // |
---|
58 | |
---|
59 | class proc_singular |
---|
60 | { |
---|
61 | public: |
---|
62 | long proc_start; // position where proc is starting |
---|
63 | long def_end; // position where proc header is ending |
---|
64 | long help_start; // position where help is starting |
---|
65 | long help_end; // position where help is starting |
---|
66 | long body_start; // position where proc-body is starting |
---|
67 | long body_end; // position where proc-body is ending |
---|
68 | long example_start; // position where example is starting |
---|
69 | long proc_end; // position where proc is ending |
---|
70 | int proc_lineno; |
---|
71 | int body_lineno; |
---|
72 | int example_lineno; |
---|
73 | char *body; |
---|
74 | long help_chksum; |
---|
75 | }; |
---|
76 | |
---|
77 | struct proc_object |
---|
78 | { |
---|
79 | //public: |
---|
80 | BOOLEAN (*function)(leftv res, leftv v); |
---|
81 | }; |
---|
82 | union uprocinfodata |
---|
83 | { |
---|
84 | public: |
---|
85 | proc_singular s; // data of Singular-procedure |
---|
86 | struct proc_object o; // pointer to binary-function |
---|
87 | }; |
---|
88 | |
---|
89 | typedef union uprocinfodata procinfodata; |
---|
90 | |
---|
91 | class procinfo; |
---|
92 | typedef procinfo * procinfov; |
---|
93 | |
---|
94 | class procinfo |
---|
95 | { |
---|
96 | public: |
---|
97 | char *libname; |
---|
98 | char *procname; |
---|
99 | package pack; |
---|
100 | language_defs language; |
---|
101 | short ref; |
---|
102 | char is_static; // if set, proc not accessible for user |
---|
103 | char trace_flag; |
---|
104 | procinfodata data; |
---|
105 | }; |
---|
106 | |
---|
107 | class Voice |
---|
108 | { |
---|
109 | public: |
---|
110 | Voice * next; |
---|
111 | Voice * prev; |
---|
112 | char * filename; // file name or proc name |
---|
113 | procinfo * pi; // proc info |
---|
114 | void * oldb; // internal scanner buffer |
---|
115 | // for files only: |
---|
116 | FILE * files; // file handle |
---|
117 | // for buffers only: |
---|
118 | char * buffer; // buffer pointer |
---|
119 | long fptr; // current position in buffer |
---|
120 | |
---|
121 | int start_lineno; // lineno, to restore in recursion |
---|
122 | int curr_lineno; // current lineno |
---|
123 | feBufferInputs sw; // BI_stdin: read from STDIN |
---|
124 | // BI_buffer: buffer |
---|
125 | // BI_file: files |
---|
126 | char ifsw; // if-switch: |
---|
127 | /*1 ifsw==0: no if statement, else is invalid |
---|
128 | * ==1: if (0) processed, execute else |
---|
129 | * ==2: if (1) processed, else allowed but not executed |
---|
130 | */ |
---|
131 | feBufferTypes typ; // buffer type: see BT_.. |
---|
132 | |
---|
133 | Voice() { memset(this,0,sizeof(*this));} |
---|
134 | feBufferTypes Typ(); |
---|
135 | void Next(); |
---|
136 | } ; |
---|
137 | |
---|
138 | extern Voice *currentVoice; |
---|
139 | |
---|
140 | Voice * feInitStdin(Voice *pp); |
---|
141 | |
---|
142 | /* feread.cc: */ |
---|
143 | |
---|
144 | /* the interface for reading: */ |
---|
145 | extern char * (*fe_fgets_stdin)(const char *pr,char *s, int size); |
---|
146 | |
---|
147 | #ifdef HAVE_DYN_RL |
---|
148 | char * fe_fgets_stdin_drl(const char *pr,char *s, int size); |
---|
149 | #endif |
---|
150 | |
---|
151 | extern "C" void fe_reset_input_mode(); |
---|
152 | |
---|
153 | extern "C" { |
---|
154 | #ifndef HAVE_ATEXIT |
---|
155 | void fe_reset_fe (int i, void *v); |
---|
156 | #else |
---|
157 | void fe_reset_fe (void); |
---|
158 | #endif |
---|
159 | } |
---|
160 | |
---|
161 | /* possible implementations: */ |
---|
162 | extern "C" |
---|
163 | { |
---|
164 | /* readline, linked in: */ |
---|
165 | char * fe_fgets_stdin_rl(const char *pr,char *s, int size); |
---|
166 | |
---|
167 | /* emulated readline: */ |
---|
168 | char * fe_fgets_stdin_emu(const char *pr,char *s, int size); |
---|
169 | |
---|
170 | /* fgets: */ |
---|
171 | char * fe_fgets(const char *pr,char *s, int size); |
---|
172 | |
---|
173 | /* dummy (for batch mode): */ |
---|
174 | char * fe_fgets_dummy(const char *pr,char *s, int size); |
---|
175 | |
---|
176 | } |
---|
177 | const char * VoiceName(); |
---|
178 | void VoiceBackTrack(); |
---|
179 | BOOLEAN contBuffer(feBufferTypes typ); |
---|
180 | const char * eati(const char *s, int *i); |
---|
181 | BOOLEAN exitBuffer(feBufferTypes typ); |
---|
182 | BOOLEAN exitVoice(); |
---|
183 | void monitor(void *F, int mode); /* FILE*, int */ |
---|
184 | BOOLEAN newFile(char* fname, FILE *f=NULL); |
---|
185 | void newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0); |
---|
186 | void * myynewbuffer(); |
---|
187 | void myyoldbuffer(void * oldb); |
---|
188 | |
---|
189 | #endif |
---|
190 | #endif |
---|
191 | |
---|