source: git/kernel/febase.h @ bafaec0

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