source: git/Singular/febase.h @ c06a32

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