source: git/Singular/febase.h @ 48aa42

spielwiese
Last change on this file since 48aa42 was ec7aac, checked in by Olaf Bachmann <obachman@…>, 24 years ago
* replaced prProcs by fast poly procs * fixed various memory leaks * added dError stuff git-svn-id: file:///usr/local/Singular/svn/trunk@4565 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 7.6 KB
Line 
1#ifndef FEBASE_H
2#define FEBASE_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: febase.h,v 1.48 2000-09-04 13:38:56 obachman Exp $ */
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#ifdef macintosh
16#  define  DIR_SEP ':'
17#  define  DIR_SEPP ":"
18#  define  UP_DIR ""
19#else  /* unix , WINNT */
20#  define  DIR_SEP '/'
21#  define  DIR_SEPP "/"
22#  define  UP_DIR ".."
23#endif  /* macintosh */
24// this might still get reset by feInitResources
25extern char fePathSep;
26
27/* define MAXPATHLEN */
28#ifdef HAVE_SYS_PARAM_H
29#include <sys/param.h>
30#endif
31
32#include <limits.h>
33
34#ifndef MAXPATHLEN
35#define MAXPATHLEN 1024
36#endif
37
38#ifdef HAVE_DYN_RL
39  #undef HAVE_READLINE
40  #define HAVE_FEREAD 1
41#elif ! defined(HAVE_READLINE)
42  #define HAVE_FEREAD
43#endif
44
45/*
46// These are our versions of fopen and fread They are very similar to
47// the usual fopen and fread, except that on reading, they always
48// convert "\r\n" into " \n" and "\r" into "\n".
49//
50// IMPORTANT: do only use myfopen and myfread when reading text,
51// do never use fopen and fread
52*/
53#ifndef unix
54FILE *myfopen(char *path, char *mode);
55#else
56#define myfopen fopen
57#endif
58size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream);
59
60
61extern char*  feErrors;
62extern char*  feArgv0;
63extern int    feErrorsLen;
64extern FILE*  feProtFile;
65extern FILE*  feFilePending; /*temp. storage for grammar.y */
66extern char   fe_promptstr[];
67extern int    si_echo, printlevel;
68extern int    pagelength, colmax;
69extern int    yy_blocklineno;
70extern int    yy_noeof;
71extern char   prompt_char;
72extern const char feNotImplemented[];
73#ifdef HAVE_TCL
74extern BOOLEAN tclmode;
75#endif
76extern BOOLEAN errorreported;
77extern BOOLEAN feProt;
78extern BOOLEAN feWarn;
79extern BOOLEAN feOut;
80
81
82#define PROT_NONE 0
83#define PROT_I    1
84#define PROT_O    2
85#define PROT_IO   3
86
87/* the C-part: */
88#define mflush() fflush(stdout)
89
90#ifdef __cplusplus
91extern "C" {
92#endif
93
94void    Werror(char *fmt, ...);
95void    WerrorS(const char *s);
96void    Print(char* fmt, ...);
97void    PrintLn();
98#ifdef HAVE_TCL
99void    PrintTCLS(const char c, const char * s);
100#else
101#define PrintTCLS(A,B) Print("TCL-ErrS:%s",B)
102#endif
103void    PrintS(char* s);
104char*   feGetResource(const char id);
105
106#ifdef HAVE_FEREAD
107extern BOOLEAN fe_is_raw_tty;
108void           fe_temp_reset (void);
109#endif
110
111#ifdef __cplusplus
112}
113/* the C++-part: */
114
115enum   feBufferTypes
116{
117  BT_none  = 0,  // entry level
118  BT_break = 1,  // while, for
119  BT_proc,       // proc
120  BT_example,    // example
121  BT_file,       // <"file"
122  BT_execute,    // execute
123  BT_if,         // if
124  BT_else        // else
125};
126
127enum   feBufferInputs
128{
129  BI_stdin = 1,
130  BI_buffer,
131  BI_file
132};
133
134/*****************************************************************
135 *
136 * Resource management (feResources.cc)
137 *
138 *****************************************************************/
139// returns value of Resource as read-only string, or NULL
140// if Resource not found
141// issues warning, if explicitely requested (warn > 0), or
142// if warn < 0 and Resource is gotten for the first time
143// Always quiet if warn == 0
144char* feResource(const char id, int warn = -1);
145char* feResource(const char* key, int warn = -1);
146// This needs to be called before the first call to feResource
147// Initializes Resources, SearchPath, and extends PATH
148void feInitResources(char* argv0);
149// Re-inits resources, should be called after changing env. variables
150void feReInitResources();
151// Prints resources into string with StringAppend, etc
152void feStringAppendResources(int warn = -1);
153
154/*****************************************************************
155 *
156 * help system (fehelp.cc)
157 *
158 *****************************************************************/
159// if str != NULL display help for str
160// display general help, otherwise
161void feHelp(char* str = NULL);
162// if browser != NULL or feOpt("browser") != NULL
163//    set HelpBrowser to browser
164// otherwise, if browser was already set, leave as is,
165//            if not, choose first available browser
166// return string identifying current browser
167// keeps feOpt("browser") up-to-date
168// Optional warn argument is as in feResource
169char* feHelpBrowser(char* browser = NULL, int warn = -1);
170void feStringAppendBrowsers(int warn = -1);
171
172/*****************************************************************
173 *
174 * version Id
175 *
176 *****************************************************************/
177extern unsigned long feVersionId;
178
179/*****************************************************************
180 *
181 * File Stuff
182 *
183 *****************************************************************/
184FILE *  feFopen(char *path, char *mode, char *where=NULL, int useWerror=FALSE,
185                int path_only=FALSE);
186
187#ifndef __MWERKS__
188#ifdef HAVE_TCL
189
190inline void PrintTCL(const char c, int l,const char *s)
191{
192  if (s!=NULL) printf("%c:%d:%s",c,l,s);
193  else if(l==0) printf("%c:0:",c);
194  else printf("%c:1:%c",c,'0'+l);
195  fflush(stdout);
196}
197#else
198#define PrintTCL(A,B,C) Print("TCL-Err:%s",C)
199#endif /* HAVE_TCL */
200#endif /* __MWERKS__ */
201
202char *  StringAppend(char *fmt, ...);
203char *  StringAppendS(char *s);
204char *  StringSetS(char* s);
205const  char * VoiceName();
206void    VoiceBackTrack();
207void    WarnS(const char *s);
208void    Warn(const char *fmt, ...);
209BOOLEAN contBuffer(feBufferTypes typ);
210char *  eati(char *s, int *i);
211BOOLEAN exitBuffer(feBufferTypes typ);
212BOOLEAN exitVoice();
213void    monitor(char* s,int mode);
214BOOLEAN newFile(char* fname, FILE *f=NULL);
215void    newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0);
216void *  myynewbuffer();
217void    myyoldbuffer(void * oldb);
218
219class Voice
220{
221  public:
222    Voice  * next;
223    Voice  * prev;
224    char   * filename;    // file name or proc name
225    procinfo * pi;        // proc info
226    void   * oldb;        // internal scanner buffer
227    // for files only:
228    FILE * files;         // file handle
229    // for buffers only:
230    char * buffer;        // buffer pointer
231    long   fptr;          // current position in buffer
232
233    int    start_lineno;  // lineno, to restore in recursion
234    int    curr_lineno;   // current lineno
235    feBufferInputs   sw;  // BI_stdin: read from STDIN
236                          // BI_buffer: buffer
237                          // BI_file: files
238    char   ifsw;          // if-switch:
239            /*1 ifsw==0: no if statement, else is invalid
240            *       ==1: if (0) processed, execute else
241            *       ==2: if (1) processed, else allowed but not executed
242            */
243    feBufferTypes   typ;  // buffer type: see BT_..
244
245  Voice() { memset(this,0,sizeof(*this));}
246  feBufferTypes Typ();
247  void Next();
248} ;
249
250extern Voice  *currentVoice;
251
252Voice * feInitStdin();
253
254/* feread.cc: */
255
256/* the interface for reading: */
257extern  char * (*fe_fgets_stdin)(char *pr,char *s, int size);
258
259#ifdef HAVE_FEREAD
260char * fe_fgets_stdin_drl(char *pr,char *s, int size);
261#endif
262
263void fe_reset_input_mode();
264
265#ifndef MSDOS
266extern "C" {
267#ifndef HAVE_ATEXIT
268void fe_reset_fe (int i, void *v);
269#else
270void fe_reset_fe (void);
271#endif
272}
273#endif
274
275
276/* possible implementations: */
277
278  /* readline, linked in: */
279  char * fe_fgets_stdin_rl(char *pr,char *s, int size);
280
281  /* emulated readline: */
282  char * fe_fgets_stdin_emu(char *pr,char *s, int size);
283
284  /* fgets: */
285  char * fe_fgets(char *pr,char *s, int size);
286
287  #ifdef HAVE_TCL
288  /* tcl: */
289  char * fe_fgets_tcl(char *pr,char *s, int size);
290  #endif
291
292  /* dummy (for batch mode): */
293  char * fe_fgets_dummy(char *pr,char *s, int size);
294
295#endif /* c++ only */
296
297/* everything in between calls to these procedures is printed into a string
298 * which is returned by SprintEnd()
299 */
300void SPrintStart();
301char* SPrintEnd();
302
303
304#endif /* ifndef FEBASE_H */
Note: See TracBrowser for help on using the repository browser.