source: git/Singular/febase.h @ 52d073

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