source: git/Singular/febase.h @ f413ec5

fieker-DuValspielwiese
Last change on this file since f413ec5 was f413ec5, checked in by Hans Schönemann <hannes@…>, 25 years ago
* hannes: dynamic loading of readline (Makefile.in cntrlc.cc configure configure.in feResource.cc febase.cc febase.h febase.inc feread.cc misc.cc mod2.h.in) git-svn-id: file:///usr/local/Singular/svn/trunk@3549 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 6.9 KB
Line 
1#ifndef FEBASE_H
2#define FEBASE_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: febase.h,v 1.36 1999-08-25 16:02:46 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#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 OptionValue("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 OptionValue("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
160FILE *  feFopen(char *path, char *mode, char *where=NULL, int useWerror=FALSE);
161#ifndef __MWERKS__
162#ifdef HAVE_TCL
163
164inline void PrintTCL(const char c, int l,const char *s)
165{
166  if (s!=NULL) printf("%c:%d:%s",c,l,s);
167  else if(l==0) printf("%c:0:",c);
168  else printf("%c:1:%c",c,'0'+l);
169  fflush(stdout);
170}
171#else
172#define PrintTCL(A,B,C) Print("TCL-Err:%s",C)
173#endif /* HAVE_TCL */
174#endif /* __MWERKS__ */
175
176char *  StringAppend(char *fmt, ...);
177char *  StringAppendS(char *s);
178char *  StringSetS(char* s);
179const  char * VoiceName();
180void    VoiceBackTrack();
181void    WarnS(const char *s);
182void    Warn(const char *fmt, ...);
183BOOLEAN contBuffer(feBufferTypes typ);
184char *  eati(char *s, int *i);
185BOOLEAN exitBuffer(feBufferTypes typ);
186BOOLEAN exitVoice();
187void    monitor(char* s,int mode);
188BOOLEAN newFile(char* fname, FILE *f=NULL);
189void    newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0);
190void *  myynewbuffer();
191void    myyoldbuffer(void * oldb);
192
193class Voice
194{
195  public:
196    Voice  * next;
197    Voice  * prev;
198    char   * filename;    // file name or proc name
199    procinfo * pi;        // proc info
200    void   * oldb;        // internal scanner buffer
201    // for files only:
202    FILE * files;         // file handle
203    // for buffers only:
204    char * buffer;        // buffer pointer
205    long   fptr;          // current position in buffer
206
207    int    start_lineno;  // lineno, to restore in recursion
208    int    curr_lineno;   // current lineno
209    feBufferInputs   sw;  // BI_stdin: read from STDIN
210                          // BI_buffer: buffer
211                          // BI_file: files
212    char   ifsw;          // if-switch:
213            /*1 ifsw==0: no if statement, else is invalid
214            *       ==1: if (0) processed, execute else
215            *       ==2: if (1) processed, else allowed but not executed
216            */
217    feBufferTypes   typ;  // buffer type: see BT_..
218
219  Voice() { memset(this,0,sizeof(*this));}
220  feBufferTypes Typ();
221  void Next();
222} ;
223
224extern Voice  *currentVoice;
225
226Voice * feInitStdin();
227
228/* feread.cc: */
229
230/* the interface for reading: */
231extern  char * (*fe_fgets_stdin)(char *pr,char *s, int size);
232
233/* possible implementations: */
234
235  /* readline, linked in: */
236  char * fe_fgets_stdin_rl(char *pr,char *s, int size);
237
238  /* emulated readline: */
239  char * fe_fgets_stdin_emu(char *pr,char *s, int size);
240
241  /* fgets: */
242  char * fe_fgets(char *pr,char *s, int size);
243 
244  #ifdef HAVE_TCL
245  /* tcl: */
246  char * fe_fgets_tcl(char *pr,char *s, int size);
247  #endif
248
249  /* dummy (for batch mode): */
250  char * fe_fgets_dummy(char *pr,char *s, int size);
251
252#endif /* c++ only */
253
254/* everything in between calls to these procedures is printed into a string
255 * which is returned by SprintEnd()
256 */
257void SPrintStart();
258char* SPrintEnd();
259
260
261#ifdef HAVE_DYN_RL
262#undef HAVE_READLINE
263#define HAVE_FEREAD 1
264#endif
265
266#endif /* ifndef FEBASE_H */
Note: See TracBrowser for help on using the repository browser.