source: git/Singular/febase.h @ fdc537

spielwiese
Last change on this file since fdc537 was a70441f, checked in by Olaf Bachmann <obachman@…>, 24 years ago
Windows and gcc 2.95 porting git-svn-id: file:///usr/local/Singular/svn/trunk@4273 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 7.8 KB
Line 
1#ifndef FEBASE_H
2#define FEBASE_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: febase.h,v 1.46 2000-04-27 10:07:07 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;
71#ifdef MTRACK
72extern BOOLEAN feRes_works;
73#endif
74extern char   prompt_char;
75extern const char feNotImplemented[];
76#ifdef HAVE_TCL
77extern BOOLEAN tclmode;
78#endif
79extern BOOLEAN errorreported;
80extern BOOLEAN feProt;
81extern BOOLEAN feWarn;
82extern BOOLEAN feOut;
83
84
85#define PROT_NONE 0
86#define PROT_I    1
87#define PROT_O    2
88#define PROT_IO   3
89
90/* the C-part: */
91#define mflush() fflush(stdout)
92
93#ifdef __cplusplus
94extern "C" {
95#endif
96
97void    Werror(char *fmt, ...);
98void    WerrorS(const char *s);
99void    Print(char* fmt, ...);
100void    PrintLn();
101#ifdef HAVE_TCL
102void    PrintTCLS(const char c, const char * s);
103#else
104#define PrintTCLS(A,B) Print("TCL-ErrS:%s",B)
105#endif
106void    PrintS(char* s);
107#define feReportBug(s) fePrintReportBug(s, __FILE__, __LINE__)
108void    fePrintReportBug(char* msg, char* file, int line);
109char*   feGetResource(const char id);
110
111#ifdef HAVE_FEREAD
112extern BOOLEAN fe_is_raw_tty;
113void           fe_temp_reset (void);
114#endif
115
116#ifdef __cplusplus
117}
118/* the C++-part: */
119
120enum   feBufferTypes
121{
122  BT_none  = 0,  // entry level
123  BT_break = 1,  // while, for
124  BT_proc,       // proc
125  BT_example,    // example
126  BT_file,       // <"file"
127  BT_execute,    // execute
128  BT_if,         // if
129  BT_else        // else
130};
131
132enum   feBufferInputs
133{
134  BI_stdin = 1,
135  BI_buffer,
136  BI_file
137};
138
139/*****************************************************************
140 *
141 * Resource management (feResources.cc)
142 *
143 *****************************************************************/
144// returns value of Resource as read-only string, or NULL
145// if Resource not found
146// issues warning, if explicitely requested (warn > 0), or
147// if warn < 0 and Resource is gotten for the first time
148// Always quiet if warn == 0
149char* feResource(const char id, int warn = -1);
150char* feResource(const char* key, int warn = -1);
151// This needs to be called before the first call to feResource
152// Initializes Resources, SearchPath, and extends PATH
153void feInitResources(char* argv0);
154// Re-inits resources, should be called after changing env. variables
155void feReInitResources();
156// Prints resources into string with StringAppend, etc
157void feStringAppendResources(int warn = -1);
158
159/*****************************************************************
160 *
161 * help system (fehelp.cc)
162 *
163 *****************************************************************/
164// if str != NULL display help for str
165// display general help, otherwise
166void feHelp(char* str = NULL);
167// if browser != NULL or feOpt("browser") != NULL
168//    set HelpBrowser to browser
169// otherwise, if browser was already set, leave as is,
170//            if not, choose first available browser
171// return string identifying current browser
172// keeps feOpt("browser") up-to-date
173// Optional warn argument is as in feResource
174char* feHelpBrowser(char* browser = NULL, int warn = -1);
175void feStringAppendBrowsers(int warn = -1);
176
177/*****************************************************************
178 *
179 * version Id
180 *
181 *****************************************************************/
182extern unsigned long feVersionId;
183
184/*****************************************************************
185 *
186 * File Stuff
187 *
188 *****************************************************************/
189FILE *  feFopen(char *path, char *mode, char *where=NULL, int useWerror=FALSE,
190                int path_only=FALSE);
191
192#ifndef __MWERKS__
193#ifdef HAVE_TCL
194
195inline void PrintTCL(const char c, int l,const char *s)
196{
197  if (s!=NULL) printf("%c:%d:%s",c,l,s);
198  else if(l==0) printf("%c:0:",c);
199  else printf("%c:1:%c",c,'0'+l);
200  fflush(stdout);
201}
202#else
203#define PrintTCL(A,B,C) Print("TCL-Err:%s",C)
204#endif /* HAVE_TCL */
205#endif /* __MWERKS__ */
206
207char *  StringAppend(char *fmt, ...);
208char *  StringAppendS(char *s);
209char *  StringSetS(char* s);
210const  char * VoiceName();
211void    VoiceBackTrack();
212void    WarnS(const char *s);
213void    Warn(const char *fmt, ...);
214BOOLEAN contBuffer(feBufferTypes typ);
215char *  eati(char *s, int *i);
216BOOLEAN exitBuffer(feBufferTypes typ);
217BOOLEAN exitVoice();
218void    monitor(char* s,int mode);
219BOOLEAN newFile(char* fname, FILE *f=NULL);
220void    newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0);
221void *  myynewbuffer();
222void    myyoldbuffer(void * oldb);
223
224class Voice
225{
226  public:
227    Voice  * next;
228    Voice  * prev;
229    char   * filename;    // file name or proc name
230    procinfo * pi;        // proc info
231    void   * oldb;        // internal scanner buffer
232    // for files only:
233    FILE * files;         // file handle
234    // for buffers only:
235    char * buffer;        // buffer pointer
236    long   fptr;          // current position in buffer
237
238    int    start_lineno;  // lineno, to restore in recursion
239    int    curr_lineno;   // current lineno
240    feBufferInputs   sw;  // BI_stdin: read from STDIN
241                          // BI_buffer: buffer
242                          // BI_file: files
243    char   ifsw;          // if-switch:
244            /*1 ifsw==0: no if statement, else is invalid
245            *       ==1: if (0) processed, execute else
246            *       ==2: if (1) processed, else allowed but not executed
247            */
248    feBufferTypes   typ;  // buffer type: see BT_..
249
250  Voice() { memset(this,0,sizeof(*this));}
251  feBufferTypes Typ();
252  void Next();
253} ;
254
255extern Voice  *currentVoice;
256
257Voice * feInitStdin();
258
259/* feread.cc: */
260
261/* the interface for reading: */
262extern  char * (*fe_fgets_stdin)(char *pr,char *s, int size);
263
264#ifdef HAVE_FEREAD
265char * fe_fgets_stdin_drl(char *pr,char *s, int size);
266#endif
267
268void fe_reset_input_mode();
269
270#ifndef MSDOS
271extern "C" {
272#ifndef HAVE_ATEXIT
273void fe_reset_fe (int i, void *v);
274#else
275void fe_reset_fe (void);
276#endif
277}
278#endif
279
280
281/* possible implementations: */
282
283  /* readline, linked in: */
284  char * fe_fgets_stdin_rl(char *pr,char *s, int size);
285
286  /* emulated readline: */
287  char * fe_fgets_stdin_emu(char *pr,char *s, int size);
288
289  /* fgets: */
290  char * fe_fgets(char *pr,char *s, int size);
291
292  #ifdef HAVE_TCL
293  /* tcl: */
294  char * fe_fgets_tcl(char *pr,char *s, int size);
295  #endif
296
297  /* dummy (for batch mode): */
298  char * fe_fgets_dummy(char *pr,char *s, int size);
299
300#endif /* c++ only */
301
302/* everything in between calls to these procedures is printed into a string
303 * which is returned by SprintEnd()
304 */
305void SPrintStart();
306char* SPrintEnd();
307
308
309#endif /* ifndef FEBASE_H */
Note: See TracBrowser for help on using the repository browser.