source: git/kernel/febase.h @ f2b6f0b

spielwiese
Last change on this file since f2b6f0b was b1dfaf, checked in by Frank Seelisch <seelisch@…>, 14 years ago
patch from Kai (checked for problems under Windows OS: no problems) git-svn-id: file:///usr/local/Singular/svn/trunk@13210 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 9.7 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
65/*
66// These are our versions of fopen and fread They are very similar to
67// the usual fopen and fread, except that on reading, they always
68// convert "\r\n" into " \n" and "\r" into "\n".
69//
70// IMPORTANT: do only use myfopen and myfread when reading text,
71// do never use fopen and fread
72*/
73#ifdef ix86_Win
74FILE *myfopen(const char *path, const char *mode);
75#else
76#define myfopen fopen
77#endif
78
79size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream);
80
81enum noeof_t
82{
83  noeof_brace = 1,
84  noeof_asstring,
85  noeof_block,
86  noeof_bracket,
87  noeof_comment,
88  noeof_procname,
89  noeof_string
90};  /* for scanner.l */
91
92extern char*  feErrors;
93extern char*  feArgv0;
94extern int    feErrorsLen;
95extern FILE*  feProtFile;
96extern FILE*  feFilePending; /*temp. storage for grammar.y */
97extern char   fe_promptstr[];
98extern int    si_echo, printlevel;
99extern int    colmax;
100extern int    yy_blocklineno;
101extern int    yy_noeof;
102extern char   prompt_char;
103extern const char feNotImplemented[];
104extern BOOLEAN errorreported;
105extern int     feProt;
106extern BOOLEAN feWarn;
107extern BOOLEAN feOut;
108extern int  traceit ;
109#define TRACE_SHOW_PROC   1
110#define TRACE_SHOW_LINENO 2
111#define TRACE_SHOW_LINE   4
112#define TRACE_SHOW_RINGS  8
113#define TRACE_SHOW_LINE1  16
114#define TRACE_BREAKPOINT  32
115#define TRACE_TMP_BREAKPOINT  64
116extern int myynest;
117extern int yylineno;
118extern char     my_yylinebuf[80];
119
120#define PROT_NONE 0
121#define PROT_I    1
122#define PROT_O    2
123#define PROT_IO   3
124
125/* the C-part: */
126#define mflush() fflush(stdout)
127
128#ifdef __cplusplus
129extern "C" {
130#endif
131
132
133extern void (*WerrorS_callback)(const char *s);
134
135void    Werror(const char *fmt, ...) __attribute__((format(printf,1,2)));
136void    WerrorS(const char *s);
137void    WarnS(const char *s);
138void    Print(const char* fmt, ...) __attribute__((format(printf,1,2)));
139/* Print should not produce more than strlen(fmt)+510 characters! */
140
141void    PrintNSpaces(const int n);
142void    PrintLn();
143void    PrintS(const char* s);
144char*   feGetResource(const char id);
145
146#ifdef HAVE_FEREAD
147extern BOOLEAN fe_is_raw_tty;
148void           fe_temp_reset (void);
149#endif
150
151#ifdef __cplusplus
152}
153/* the C++-part: */
154
155typedef enum { LANG_NONE, LANG_TOP, LANG_SINGULAR, LANG_C, LANG_MAX} language_defs;
156// LANG_TOP     : Toplevel package only
157// LANG_SINGULAR:
158// LANG_C       :
159//
160
161class proc_singular
162{
163public:
164  long   proc_start;       // position where proc is starting
165  long   def_end;          // position where proc header is ending
166  long   help_start;       // position where help is starting
167  long   help_end;         // position where help is starting
168  long   body_start;       // position where proc-body is starting
169  long   body_end;         // position where proc-body is ending
170  long   example_start;    // position where example is starting
171  long   proc_end;         // position where proc is ending
172  int    proc_lineno;
173  int    body_lineno;
174  int    example_lineno;
175  char   *body;
176  long help_chksum;
177};
178
179struct proc_object
180{
181//public:
182  BOOLEAN (*function)(leftv res, leftv v);
183};
184union uprocinfodata
185{
186public:
187  proc_singular  s;        // data of Singular-procedure
188  struct proc_object    o; // pointer to binary-function
189};
190
191typedef union uprocinfodata procinfodata;
192
193class procinfo;
194typedef procinfo *         procinfov;
195
196class procinfo
197{
198public:
199  char          *libname;
200  char          *procname;
201  package       pack;
202  language_defs language;
203  short         ref;
204  char          is_static;        // if set, proc not accessible for user
205  char          trace_flag;
206  procinfodata  data;
207};
208enum   feBufferTypes
209{
210  BT_none  = 0,  // entry level
211  BT_break = 1,  // while, for
212  BT_proc,       // proc
213  BT_example,    // example
214  BT_file,       // <"file"
215  BT_execute,    // execute
216  BT_if,         // if
217  BT_else        // else
218};
219
220enum   feBufferInputs
221{
222  BI_stdin = 1,
223  BI_buffer,
224  BI_file
225};
226
227/*****************************************************************
228 *
229 * Resource management (feResources.cc)
230 *
231 *****************************************************************/
232// returns value of Resource as read-only string, or NULL
233// if Resource not found
234// issues warning, if explicitely requested (warn > 0), or
235// if warn < 0 and Resource is gotten for the first time
236// Always quiet if warn == 0
237char* feResource(const char id, int warn = -1);
238char* feResource(const char* key, int warn = -1);
239// This needs to be called before the first call to feResource
240// Initializes Resources, SearchPath, and extends PATH
241void feInitResources(char* argv0);
242// Re-inits resources, should be called after changing env. variables
243void feReInitResources();
244// Prints resources into string with StringAppend, etc
245void feStringAppendResources(int warn = -1);
246
247/*****************************************************************
248 *
249 * help system (fehelp.cc)
250 *
251 *****************************************************************/
252// if str != NULL display help for str
253// display general help, otherwise
254void feHelp(char* str = NULL);
255// if browser != NULL or feOpt("browser") != NULL
256//    set HelpBrowser to browser
257// otherwise, if browser was already set, leave as is,
258//            if not, choose first available browser
259// return string identifying current browser
260// keeps feOpt("browser") up-to-date
261// Optional warn argument is as in feResource
262const char* feHelpBrowser(char* browser = NULL, int warn = -1);
263void feStringAppendBrowsers(int warn = -1);
264
265/*****************************************************************
266 *
267 * version Id
268 *
269 *****************************************************************/
270/* extern unsigned long feVersionId; */
271
272/*****************************************************************
273 *
274 * File Stuff
275 *
276 *****************************************************************/
277FILE *  feFopen(const char *path, const char *mode, char *where=NULL,
278                int useWerror=FALSE, int path_only=FALSE);
279
280char *  StringAppend(const char *fmt, ...);
281char *  StringAppendS(const char *s);
282char *  StringSetS(const char* s);
283const  char * VoiceName();
284void    VoiceBackTrack();
285void    Warn(const char *fmt, ...);
286BOOLEAN contBuffer(feBufferTypes typ);
287const char *  eati(const char *s, int *i);
288BOOLEAN exitBuffer(feBufferTypes typ);
289BOOLEAN exitVoice();
290void    monitor(void *F, int mode); /* FILE*, int */
291BOOLEAN newFile(char* fname, FILE *f=NULL);
292void    newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0);
293void *  myynewbuffer();
294void    myyoldbuffer(void * oldb);
295
296class Voice
297{
298  public:
299    Voice  * next;
300    Voice  * prev;
301    char   * filename;    // file name or proc name
302    procinfo * pi;        // proc info
303    void   * oldb;        // internal scanner buffer
304    // for files only:
305    FILE * files;         // file handle
306    // for buffers only:
307    char * buffer;        // buffer pointer
308    long   fptr;          // current position in buffer
309
310    int    start_lineno;  // lineno, to restore in recursion
311    int    curr_lineno;   // current lineno
312    feBufferInputs   sw;  // BI_stdin: read from STDIN
313                          // BI_buffer: buffer
314                          // BI_file: files
315    char   ifsw;          // if-switch:
316            /*1 ifsw==0: no if statement, else is invalid
317            *       ==1: if (0) processed, execute else
318            *       ==2: if (1) processed, else allowed but not executed
319            */
320    feBufferTypes   typ;  // buffer type: see BT_..
321
322  Voice() { memset(this,0,sizeof(*this));}
323  feBufferTypes Typ();
324  void Next();
325} ;
326
327extern Voice  *currentVoice;
328
329Voice * feInitStdin(Voice *pp);
330
331/* feread.cc: */
332
333/* the interface for reading: */
334extern  char * (*fe_fgets_stdin)(const char *pr,char *s, int size);
335
336#ifdef HAVE_DYN_RL
337char * fe_fgets_stdin_drl(const char *pr,char *s, int size);
338#endif
339
340extern "C" void fe_reset_input_mode();
341
342extern "C" {
343#ifndef HAVE_ATEXIT
344void fe_reset_fe (int i, void *v);
345#else
346void fe_reset_fe (void);
347#endif
348}
349
350
351/* possible implementations: */
352#ifdef __cplusplus
353extern "C"
354{
355#endif
356  /* readline, linked in: */
357  char * fe_fgets_stdin_rl(const char *pr,char *s, int size);
358
359  /* emulated readline: */
360  char * fe_fgets_stdin_emu(const char *pr,char *s, int size);
361
362  /* fgets: */
363  char * fe_fgets(const char *pr,char *s, int size);
364
365  /* dummy (for batch mode): */
366  char * fe_fgets_dummy(const char *pr,char *s, int size);
367
368#ifdef __cplusplus
369}
370#endif
371#endif /* c++ only */
372
373/* everything in between calls to these procedures is printed into a string
374 * which is returned by SprintEnd()
375 */
376void SPrintStart();
377char* SPrintEnd();
378
379
380#endif /* ifndef FEBASE_H */
Note: See TracBrowser for help on using the repository browser.