source: git/kernel/febase.h @ 68349d

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