source: git/Singular/febase.h @ 8d12f5

spielwiese
Last change on this file since 8d12f5 was 5892d27, checked in by Hans Schönemann <hannes@…>, 26 years ago
* hannes: change comment from // to /* ..*/ (it is a C-file) git-svn-id: file:///usr/local/Singular/svn/trunk@1591 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.16 1998-05-04 13:44:47 Singular 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 FILE*  feProtFile;
32extern FILE*  feFilePending; /*temp. storage for grammar.y */
33extern char   fe_promptstr[];
34extern int    si_echo, printlevel;
35extern int    pagelength, colmax;
36extern int    yy_blocklineno;
37extern int    yy_noeof;
38extern char   prompt_char;
39extern const char feNotImplemented[];
40#ifdef HAVE_TCL
41extern BOOLEAN tclmode;
42#endif
43extern BOOLEAN errorreported;
44extern BOOLEAN fe_use_fgets;
45extern BOOLEAN feBatch;
46extern BOOLEAN feProt;
47
48#define PROT_NONE 0
49#define PROT_I    1
50#define PROT_O    2
51#define PROT_IO   3
52
53/* the C-part: */
54#ifdef __cplusplus
55extern "C" {
56#endif
57
58void   Werror(char *fmt, ...);
59void   WerrorS(const char *s);
60
61#ifdef __cplusplus
62}
63/* the C++-part: */
64
65enum   feBufferTypes
66{
67  BT_none  = 0,  // entry level
68  BT_break = 1,  // while, for
69  BT_proc,       // proc
70  BT_example,    // example
71  BT_file,       // <"file"
72  BT_execute,    // execute
73  BT_if,         // if
74  BT_else        // else
75};
76
77enum   feBufferInputs
78{
79  BI_stdin = 1,
80  BI_buffer,
81  BI_file
82};
83
84char*   feGetSearchPath(const char* argv0 = NULL);
85char*   feGetExpandedExecutable(const char* argv0 = NULL);
86FILE *  feFopen(char *path, char *mode, char *where=NULL, int useWerror=FALSE);
87void    fePause(void);
88void    Print(char* fmt, ...);
89void    PrintS(char* s);
90void     PrintLn();
91void    PrintTCLS(char c, char * s);
92#ifndef macintosh
93inline void PrintTCL(char c, int l,char *s)
94{
95#ifdef HAVE_TCL
96  if (s!=NULL) printf("%c:%d:%s\n",c,l,s);
97  else         printf("%c:%d:\n",c,l);
98  fflush(stdout);
99#endif
100}
101#endif
102
103char *  StringAppend(char *fmt, ...);
104char *  StringAppendS(char *s);
105char *  StringSet(char *fmt, ...);
106char *  StringSetS(char* s);
107const  char * VoiceName();
108void    VoiceBackTrack();
109void    WarnS(const char *s);
110void    Warn(const char *fmt, ...);
111BOOLEAN contBuffer(feBufferTypes typ);
112char *  eati(char *s, int *i);
113BOOLEAN exitBuffer(feBufferTypes typ);
114BOOLEAN exitVoice();
115#define mflush() fflush(stdout)
116void    monitor(char* s,int mode);
117BOOLEAN newFile(char* fname, FILE *f=NULL);
118void    newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0);
119void *  myynewbuffer();
120void    myyoldbuffer(void * oldb);
121
122/* assume(x) -- a handy macro for assumptions */
123#ifdef NDEBUG
124/* empty macro, if NDEBUG */
125#define assume(x) ((void*) 0)
126#else /* ! NDEBUG */
127#define assume(x) _assume(x, __FILE__, __LINE__)
128#define _assume(x, f, l)                                        \
129do                                                              \
130{                                                               \
131  if (! (x))                                                    \
132  {                                                             \
133    Warn("Internal assume violation: file %s line %d\n", f, l); \
134  }                                                             \
135}                                                               \
136while (0)
137#endif /* NDEBUG */
138
139class Voice
140{
141  public:
142    Voice  * next;
143    Voice  * prev;
144    char   * filename;    // file name or proc name
145    procinfo * pi;        // proc info
146    void   * oldb;        // internal scanner buffer
147    int    start_lineno;  // lineno, to restore in recursion
148    int    curr_lineno;   // current lineno
149    feBufferInputs   sw;  // BI_stdin: read from STDIN
150                          // BI_buffer: buffer
151                          // BI_file: files
152    char   ifsw;          // if-switch:
153            /*1 ifsw==0: no if statement, else is invalid
154            *       ==1: if (0) processed, execute else
155            *       ==2: if (1) processed, else allowed but not executed
156            */
157    feBufferTypes   typ;  // buffer type: see BT_..
158    // for files only:
159    FILE * files;         // file handle
160    // for buffers only:
161    char * buffer;        // buffer pointer
162    long   fptr;          // current position in buffer
163
164  Voice() { memset(this,0,sizeof(*this));}
165  feBufferTypes Typ();
166  void Next();
167} ;
168
169extern Voice  *currentVoice;
170
171Voice * feInitStdin();
172
173/* feread.cc: */
174#ifdef HAVE_FEREAD
175  void fe_set_input_mode (void);
176  void fe_temp_set (void);
177  void fe_temp_reset (void);
178  char * fe_fgets_stdin(char *s, int size);
179  #ifndef MSDOS
180    #ifdef HAVE_ATEXIT
181      void fe_reset_input_mode (void);
182    #else
183      void fe_reset_input_mode (int i, void *v);
184    #endif
185  #else
186    #define fe_reset_input_mode()
187  #endif
188#else
189  #ifdef HAVE_READLINE
190    void fe_set_input_mode (void);
191    void fe_reset_input_mode (void);
192    char * fe_fgets_stdin_rl(char *pr,char *s, int size);
193    #define fe_fgets_stdin(A,B) fe_fgets_stdin_rl(fe_promptstr,A,B)
194  #else
195    #define fe_fgets_stdin(A,B) fgets(A,B,stdin)
196  #endif
197#endif
198#endif
199#endif
Note: See TracBrowser for help on using the repository browser.