source: git/kernel/old.febase.h @ cc7302

spielwiese
Last change on this file since cc7302 was cc7302, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
ADD: expose feStringAppendBrowsers (moved to Singular/fehelp.*)
  • Property mode set to 100644
File size: 7.4 KB
Line 
1#ifndef FEBASE_H
2#define FEBASE_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id$ */
7/*
8* ABSTRACT: basic i/o
9*/
10#include <stdio.h>
11#include <string.h>
12#include <kernel/structs.h>
13
14/* define DIR_SEPP, etc */
15/* unix , WINNT */
16#  define  DIR_SEP '/'
17#  define  DIR_SEPP "/"
18#  define  UP_DIR ".."
19// this might still get reset by feInitResources
20extern char fePathSep;
21
22/* define MAXPATHLEN */
23#ifdef HAVE_SYS_PARAM_H
24#include <sys/param.h>
25#endif
26
27/* the are versions of limits.h with incorrect values (IRIX_6)
28* let's include our own */
29
30#include <omalloc/mylimits.h>
31
32/* OSF/1 and AIX_4 are missing the header for setenv, but the proc exists */
33#if defined(DecAlpha_OSF1) || defined(AIX_4)
34#ifdef __cplusplus
35extern "C"
36{
37#endif
38  int setenv(const char *name, const char *value, int overwrite);
39#ifdef __cplusplus
40}
41#endif
42#endif
43
44#ifndef MAXPATHLEN
45#define MAXPATHLEN 1024
46#endif
47
48#ifdef HAVE_LIBREADLINE
49  #define HAVE_READLINE 1
50#endif
51
52#ifdef HAVE_DYN_RL
53  #undef HAVE_READLINE
54  #define HAVE_FEREAD 1
55#elif ! defined(HAVE_READLINE)
56#ifndef ix86_Win
57  #define HAVE_FEREAD 1
58#endif
59#endif
60#ifdef ix86_Linux
61  // FEREAD stuff does not work with glibc2
62  #undef HAVE_FEREAD
63#endif
64
65enum noeof_t
66{
67  noeof_brace = 1,
68  noeof_asstring,
69  noeof_block,
70  noeof_bracket,
71  noeof_comment,
72  noeof_procname,
73  noeof_string
74};  /* for scanner.l */
75
76extern char*  feErrors;
77extern char*  feArgv0;
78extern int    feErrorsLen;
79extern FILE*  feProtFile;
80extern FILE*  feFilePending; /*temp. storage for grammar.y */
81extern char   fe_promptstr[];
82extern int    si_echo, printlevel;
83extern int    colmax;
84extern int    yy_blocklineno;
85extern int    yy_noeof;
86extern char   prompt_char;
87extern const char feNotImplemented[];
88extern BOOLEAN errorreported;
89extern int     feProt;
90extern BOOLEAN feWarn;
91extern BOOLEAN feOut;
92extern int  traceit ;
93#define TRACE_SHOW_PROC   1
94#define TRACE_SHOW_LINENO 2
95#define TRACE_SHOW_LINE   4
96#define TRACE_SHOW_RINGS  8
97#define TRACE_SHOW_LINE1  16
98#define TRACE_BREAKPOINT  32
99#define TRACE_TMP_BREAKPOINT  64
100extern int myynest;
101extern int yylineno;
102extern char     my_yylinebuf[80];
103
104#define PROT_NONE 0
105#define PROT_I    1
106#define PROT_O    2
107#define PROT_IO   3
108
109/* the C-part: */
110#define mflush() fflush(stdout)
111
112#ifdef __cplusplus
113extern "C" {
114#endif
115#ifndef __GNUC__
116#undef __attribute__
117#define __attribute__(A)
118#endif
119
120extern void (*WerrorS_callback)(const char *s);
121
122void    Werror(const char *fmt, ...) __attribute__((format(printf,1,2)));
123void    WerrorS(const char *s);
124void    WarnS(const char *s);
125void    Print(const char* fmt, ...) __attribute__((format(printf,1,2)));
126/* Print should not produce more than strlen(fmt)+510 characters! */
127
128void    PrintNSpaces(const int n);
129void    PrintLn();
130void    PrintS(const char* s);
131char*   feGetResource(const char id);
132
133#ifdef HAVE_FEREAD
134extern BOOLEAN fe_is_raw_tty;
135void           fe_temp_reset (void);
136#endif
137
138#ifdef __cplusplus
139}
140/* the C++-part: */
141
142typedef enum { LANG_NONE, LANG_TOP, LANG_SINGULAR, LANG_C, LANG_MAX} language_defs;
143// LANG_TOP     : Toplevel package only
144// LANG_SINGULAR:
145// LANG_C       :
146//
147
148class proc_singular
149{
150public:
151  long   proc_start;       // position where proc is starting
152  long   def_end;          // position where proc header is ending
153  long   help_start;       // position where help is starting
154  long   help_end;         // position where help is starting
155  long   body_start;       // position where proc-body is starting
156  long   body_end;         // position where proc-body is ending
157  long   example_start;    // position where example is starting
158  long   proc_end;         // position where proc is ending
159  int    proc_lineno;
160  int    body_lineno;
161  int    example_lineno;
162  char   *body;
163  long help_chksum;
164};
165
166struct proc_object
167{
168//public:
169  BOOLEAN (*function)(leftv res, leftv v);
170};
171union uprocinfodata
172{
173public:
174  proc_singular  s;        // data of Singular-procedure
175  struct proc_object    o; // pointer to binary-function
176};
177
178typedef union uprocinfodata procinfodata;
179
180class procinfo;
181typedef procinfo *         procinfov;
182
183class procinfo
184{
185public:
186  char          *libname;
187  char          *procname;
188  package       pack;
189  language_defs language;
190  short         ref;
191  char          is_static;        // if set, proc not accessible for user
192  char          trace_flag;
193  procinfodata  data;
194};
195enum   feBufferTypes
196{
197  BT_none  = 0,  // entry level
198  BT_break = 1,  // while, for
199  BT_proc,       // proc
200  BT_example,    // example
201  BT_file,       // <"file"
202  BT_execute,    // execute
203  BT_if,         // if
204  BT_else        // else
205};
206
207enum   feBufferInputs
208{
209  BI_stdin = 1,
210  BI_buffer,
211  BI_file
212};
213
214
215/*****************************************************************
216 *
217 * version Id
218 *
219 *****************************************************************/
220/* extern unsigned long feVersionId; */
221
222char *  StringAppend(const char *fmt, ...);
223char *  StringAppendS(const char *s);
224char *  StringSetS(const char* s);
225const  char * VoiceName();
226void    VoiceBackTrack();
227void    Warn(const char *fmt, ...);
228BOOLEAN contBuffer(feBufferTypes typ);
229BOOLEAN exitBuffer(feBufferTypes typ);
230BOOLEAN exitVoice();
231void    monitor(void *F, int mode); /* FILE*, int */
232BOOLEAN newFile(char* fname, FILE *f=NULL);
233void    newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0);
234void *  myynewbuffer();
235void    myyoldbuffer(void * oldb);
236
237class Voice
238{
239  public:
240    Voice  * next;
241    Voice  * prev;
242    char   * filename;    // file name or proc name
243    procinfo * pi;        // proc info
244    void   * oldb;        // internal scanner buffer
245    // for files only:
246    FILE * files;         // file handle
247    // for buffers only:
248    char * buffer;        // buffer pointer
249    long   fptr;          // current position in buffer
250
251    int    start_lineno;  // lineno, to restore in recursion
252    int    curr_lineno;   // current lineno
253    feBufferInputs   sw;  // BI_stdin: read from STDIN
254                          // BI_buffer: buffer
255                          // BI_file: files
256    char   ifsw;          // if-switch:
257            /*1 ifsw==0: no if statement, else is invalid
258            *       ==1: if (0) processed, execute else
259            *       ==2: if (1) processed, else allowed but not executed
260            */
261    feBufferTypes   typ;  // buffer type: see BT_..
262
263  Voice() { memset(this,0,sizeof(*this));}
264  feBufferTypes Typ();
265  void Next();
266} ;
267
268extern Voice  *currentVoice;
269
270Voice * feInitStdin(Voice *pp);
271
272/* feread.cc: */
273
274/* the interface for reading: */
275extern  char * (*fe_fgets_stdin)(const char *pr,char *s, int size);
276
277#ifdef HAVE_DYN_RL
278char * fe_fgets_stdin_drl(const char *pr,char *s, int size);
279#endif
280
281extern "C" void fe_reset_input_mode();
282
283extern "C" {
284#ifndef HAVE_ATEXIT
285void fe_reset_fe (int i, void *v);
286#else
287void fe_reset_fe (void);
288#endif
289}
290
291
292/* possible implementations: */
293#ifdef __cplusplus
294extern "C"
295{
296#endif
297  /* readline, linked in: */
298  char * fe_fgets_stdin_rl(const char *pr,char *s, int size);
299
300  /* emulated readline: */
301  char * fe_fgets_stdin_emu(const char *pr,char *s, int size);
302
303  /* fgets: */
304  char * fe_fgets(const char *pr,char *s, int size);
305
306  /* dummy (for batch mode): */
307  char * fe_fgets_dummy(const char *pr,char *s, int size);
308
309#ifdef __cplusplus
310}
311#endif
312#endif /* c++ only */
313
314/* everything in between calls to these procedures is printed into a string
315 * which is returned by SprintEnd()
316 */
317void SPrintStart();
318char* SPrintEnd();
319
320
321#endif /* ifndef FEBASE_H */
Note: See TracBrowser for help on using the repository browser.