source: git/Singular/febase.h @ 50cbdc

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