source: git/kernel/febase.h @ 5a9e7b

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