[0e1846] | 1 | #ifndef FEBASE_H |
---|
| 2 | #define FEBASE_H |
---|
| 3 | /**************************************** |
---|
| 4 | * Computer Algebra System SINGULAR * |
---|
| 5 | ****************************************/ |
---|
[d5f35ac] | 6 | /* $Id: febase.h,v 1.15 1998-04-27 12:34:13 obachman Exp $ */ |
---|
[0e1846] | 7 | /* |
---|
| 8 | * ABSTRACT |
---|
| 9 | */ |
---|
| 10 | #include <stdio.h> |
---|
[057e93c] | 11 | #include <string.h> |
---|
[0e1846] | 12 | #include "structs.h" |
---|
| 13 | |
---|
[d5f35ac] | 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 |
---|
| 22 | extern FILE *myfopen(char *path, char *mode); |
---|
| 23 | #else |
---|
| 24 | #define myfopen fopen |
---|
| 25 | #endif |
---|
| 26 | extern size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream); |
---|
| 27 | |
---|
[057e93c] | 28 | extern char* feErrors; |
---|
| 29 | extern FILE* feProtFile; |
---|
| 30 | extern FILE* feFilePending; /*temp. storage for grammar.y */ |
---|
| 31 | extern char fe_promptstr[]; |
---|
[0e1846] | 32 | extern int si_echo, printlevel; |
---|
| 33 | extern int pagelength, colmax; |
---|
[cc94b0a] | 34 | extern int yy_blocklineno; |
---|
| 35 | extern int yy_noeof; |
---|
[0e1846] | 36 | extern char prompt_char; |
---|
[0f678f] | 37 | extern const char feNotImplemented[]; |
---|
[057e93c] | 38 | #ifdef HAVE_TCL |
---|
[0e1846] | 39 | extern BOOLEAN tclmode; |
---|
[057e93c] | 40 | #endif |
---|
[0e1846] | 41 | extern BOOLEAN errorreported; |
---|
| 42 | extern BOOLEAN fe_use_fgets; |
---|
| 43 | extern BOOLEAN feBatch; |
---|
| 44 | extern 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 |
---|
| 53 | extern "C" { |
---|
| 54 | #endif |
---|
| 55 | |
---|
| 56 | void Werror(char *fmt, ...); |
---|
[4b5c87] | 57 | void WerrorS(const char *s); |
---|
[0e1846] | 58 | |
---|
| 59 | #ifdef __cplusplus |
---|
| 60 | } |
---|
| 61 | /* the C++-part: */ |
---|
| 62 | |
---|
[057e93c] | 63 | enum feBufferTypes |
---|
[0e1846] | 64 | { |
---|
[a18fae] | 65 | BT_none = 0, // entry level |
---|
[0e1846] | 66 | BT_break = 1, // while, for |
---|
[a18fae] | 67 | BT_proc, // proc |
---|
[0e1846] | 68 | BT_example, // example |
---|
| 69 | BT_file, // <"file" |
---|
| 70 | BT_execute, // execute |
---|
| 71 | BT_if, // if |
---|
| 72 | BT_else // else |
---|
| 73 | }; |
---|
| 74 | |
---|
[057e93c] | 75 | enum feBufferInputs |
---|
| 76 | { |
---|
| 77 | BI_stdin = 1, |
---|
| 78 | BI_buffer, |
---|
| 79 | BI_file |
---|
| 80 | }; |
---|
| 81 | |
---|
[1caa72] | 82 | char* feGetSearchPath(const char* argv0 = NULL); |
---|
[97454d] | 83 | char* feGetExpandedExecutable(const char* argv0 = NULL); |
---|
[057e93c] | 84 | FILE * feFopen(char *path, char *mode, char *where=NULL, int useWerror=FALSE); |
---|
| 85 | void fePause(void); |
---|
| 86 | void Print(char* fmt, ...); |
---|
| 87 | void PrintS(char* s); |
---|
| 88 | void PrintLn(); |
---|
| 89 | void PrintTCLS(char c, char * s); |
---|
[0e1846] | 90 | #ifndef macintosh |
---|
| 91 | inline 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 | |
---|
[057e93c] | 101 | char * StringAppend(char *fmt, ...); |
---|
| 102 | char * StringAppendS(char *s); |
---|
| 103 | char * StringSet(char *fmt, ...); |
---|
| 104 | char * StringSetS(char* s); |
---|
[0e1846] | 105 | const char * VoiceName(); |
---|
[057e93c] | 106 | void VoiceBackTrack(); |
---|
[356dc3d] | 107 | void WarnS(const char *s); |
---|
| 108 | void Warn(const char *fmt, ...); |
---|
[057e93c] | 109 | BOOLEAN contBuffer(feBufferTypes typ); |
---|
| 110 | char * eati(char *s, int *i); |
---|
| 111 | BOOLEAN exitBuffer(feBufferTypes typ); |
---|
| 112 | BOOLEAN exitVoice(); |
---|
[0e1846] | 113 | #define mflush() fflush(stdout) |
---|
[057e93c] | 114 | void monitor(char* s,int mode); |
---|
| 115 | BOOLEAN newFile(char* fname, FILE *f=NULL); |
---|
| 116 | void newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0); |
---|
| 117 | void * myynewbuffer(); |
---|
| 118 | void myyoldbuffer(void * oldb); |
---|
| 119 | |
---|
[f92fa13] | 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) \ |
---|
| 127 | do \ |
---|
| 128 | { \ |
---|
| 129 | if (! (x)) \ |
---|
| 130 | { \ |
---|
| 131 | Warn("Internal assume violation: file %s line %d\n", f, l); \ |
---|
| 132 | } \ |
---|
| 133 | } \ |
---|
| 134 | while (0) |
---|
| 135 | #endif /* NDEBUG */ |
---|
[057e93c] | 136 | |
---|
| 137 | class 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 | |
---|
| 167 | extern Voice *currentVoice; |
---|
| 168 | |
---|
| 169 | Voice * feInitStdin(); |
---|
[0e1846] | 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); |
---|
[057e93c] | 189 | void fe_reset_input_mode (void); |
---|
[0e1846] | 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 |
---|