source: git/Singular/febase.h @ e665360

spielwiese
Last change on this file since e665360 was e665360, checked in by Olaf Bachmann <obachman@…>, 25 years ago
* minor bug fixes git-svn-id: file:///usr/local/Singular/svn/trunk@1987 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.4 KB
Line 
1#ifndef FEBASE_H
2#define FEBASE_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: febase.h,v 1.17 1998-05-25 21:28:31 obachman Exp $ */
7/*
8* ABSTRACT
9*/
10#include <stdio.h>
11#include <string.h>
12#include "structs.h"
13
14
15/*
16// These are our versions of fopen and fread They are very similar to
17// the usual fopen and fread, except that on reading, they always
18// convert "\r\n" into " \n" and "\r" into "\n".
19//
20// IMPORTANT: do only use myfopen and myfread when reading text,
21// do never use fopen and fread
22*/
23#ifndef unix
24extern FILE *myfopen(char *path, char *mode); 
25#else
26#define myfopen fopen
27#endif
28extern size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream);
29
30extern char*  feErrors;
31extern int    feErrorsLen;
32extern FILE*  feProtFile;
33extern FILE*  feFilePending; /*temp. storage for grammar.y */
34extern char   fe_promptstr[];
35extern int    si_echo, printlevel;
36extern int    pagelength, colmax;
37extern int    yy_blocklineno;
38extern int    yy_noeof;
39extern char   prompt_char;
40extern const char feNotImplemented[];
41#ifdef HAVE_TCL
42extern BOOLEAN tclmode;
43#endif
44extern BOOLEAN errorreported;
45extern BOOLEAN fe_use_fgets;
46extern BOOLEAN feBatch;
47extern BOOLEAN feProt;
48
49#define PROT_NONE 0
50#define PROT_I    1
51#define PROT_O    2
52#define PROT_IO   3
53
54/* the C-part: */
55#ifdef __cplusplus
56extern "C" {
57#endif
58
59void   Werror(char *fmt, ...);
60void   WerrorS(const char *s);
61
62#ifdef __cplusplus
63}
64/* the C++-part: */
65
66enum   feBufferTypes
67{
68  BT_none  = 0,  // entry level
69  BT_break = 1,  // while, for
70  BT_proc,       // proc
71  BT_example,    // example
72  BT_file,       // <"file"
73  BT_execute,    // execute
74  BT_if,         // if
75  BT_else        // else
76};
77
78enum   feBufferInputs
79{
80  BI_stdin = 1,
81  BI_buffer,
82  BI_file
83};
84
85char*   feGetSearchPath(const char* argv0 = NULL);
86char*   feGetExpandedExecutable(const char* argv0 = NULL);
87FILE *  feFopen(char *path, char *mode, char *where=NULL, int useWerror=FALSE);
88void    fePause(void);
89void    Print(char* fmt, ...);
90void    PrintS(char* s);
91void     PrintLn();
92void    PrintTCLS(char c, char * s);
93#ifndef macintosh
94inline void PrintTCL(char c, int l,char *s)
95{
96#ifdef HAVE_TCL
97  if (s!=NULL) printf("%c:%d:%s\n",c,l,s);
98  else         printf("%c:%d:\n",c,l);
99  fflush(stdout);
100#endif
101}
102#endif
103
104char *  StringAppend(char *fmt, ...);
105char *  StringAppendS(char *s);
106char *  StringSet(char *fmt, ...);
107char *  StringSetS(char* s);
108const  char * VoiceName();
109void    VoiceBackTrack();
110void    WarnS(const char *s);
111void    Warn(const char *fmt, ...);
112BOOLEAN contBuffer(feBufferTypes typ);
113char *  eati(char *s, int *i);
114BOOLEAN exitBuffer(feBufferTypes typ);
115BOOLEAN exitVoice();
116#define mflush() fflush(stdout)
117void    monitor(char* s,int mode);
118BOOLEAN newFile(char* fname, FILE *f=NULL);
119void    newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0);
120void *  myynewbuffer();
121void    myyoldbuffer(void * oldb);
122
123/* assume(x) -- a handy macro for assumptions */
124#ifdef NDEBUG
125/* empty macro, if NDEBUG */
126#define assume(x) ((void*) 0)
127#else /* ! NDEBUG */
128#define assume(x) _assume(x, __FILE__, __LINE__)
129#define _assume(x, f, l)                                        \
130do                                                              \
131{                                                               \
132  if (! (x))                                                    \
133  {                                                             \
134    Warn("Internal assume violation: file %s line %d\n", f, l); \
135  }                                                             \
136}                                                               \
137while (0)
138#endif /* NDEBUG */
139
140class Voice
141{
142  public:
143    Voice  * next;
144    Voice  * prev;
145    char   * filename;    // file name or proc name
146    procinfo * pi;        // proc info
147    void   * oldb;        // internal scanner buffer
148    int    start_lineno;  // lineno, to restore in recursion
149    int    curr_lineno;   // current lineno
150    feBufferInputs   sw;  // BI_stdin: read from STDIN
151                          // BI_buffer: buffer
152                          // BI_file: files
153    char   ifsw;          // if-switch:
154            /*1 ifsw==0: no if statement, else is invalid
155            *       ==1: if (0) processed, execute else
156            *       ==2: if (1) processed, else allowed but not executed
157            */
158    feBufferTypes   typ;  // buffer type: see BT_..
159    // for files only:
160    FILE * files;         // file handle
161    // for buffers only:
162    char * buffer;        // buffer pointer
163    long   fptr;          // current position in buffer
164
165  Voice() { memset(this,0,sizeof(*this));}
166  feBufferTypes Typ();
167  void Next();
168} ;
169
170extern Voice  *currentVoice;
171
172Voice * feInitStdin();
173
174/* feread.cc: */
175#ifdef HAVE_FEREAD
176  void fe_set_input_mode (void);
177  void fe_temp_set (void);
178  void fe_temp_reset (void);
179  char * fe_fgets_stdin(char *s, int size);
180  #ifndef MSDOS
181    #ifdef HAVE_ATEXIT
182      void fe_reset_input_mode (void);
183    #else
184      void fe_reset_input_mode (int i, void *v);
185    #endif
186  #else
187    #define fe_reset_input_mode()
188  #endif
189#else
190  #ifdef HAVE_READLINE
191    void fe_set_input_mode (void);
192    void fe_reset_input_mode (void);
193    char * fe_fgets_stdin_rl(char *pr,char *s, int size);
194    #define fe_fgets_stdin(A,B) fe_fgets_stdin_rl(fe_promptstr,A,B)
195  #else
196    #define fe_fgets_stdin(A,B) fgets(A,B,stdin)
197  #endif
198#endif
199#endif
200#endif
Note: See TracBrowser for help on using the repository browser.