source: git/kernel/febase.h @ 098f98f

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