source: git/kernel/febase.h @ 538d63

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