[0e1846] | 1 | #ifndef FEBASE_H |
---|
| 2 | #define FEBASE_H |
---|
| 3 | /**************************************** |
---|
| 4 | * Computer Algebra System SINGULAR * |
---|
| 5 | ****************************************/ |
---|
[97454d] | 6 | /* $Id: febase.h,v 1.11 1998-04-07 18:35:23 obachman Exp $ */ |
---|
[0e1846] | 7 | /* |
---|
| 8 | * ABSTRACT |
---|
| 9 | */ |
---|
| 10 | #include <stdio.h> |
---|
[057e93c] | 11 | #include <string.h> |
---|
[0e1846] | 12 | #include "structs.h" |
---|
| 13 | |
---|
[057e93c] | 14 | extern char* feErrors; |
---|
| 15 | extern FILE* feProtFile; |
---|
| 16 | extern FILE* feFilePending; /*temp. storage for grammar.y */ |
---|
| 17 | extern char fe_promptstr[]; |
---|
[0e1846] | 18 | extern int si_echo, printlevel; |
---|
| 19 | extern int pagelength, colmax; |
---|
[cc94b0a] | 20 | extern int yy_blocklineno; |
---|
| 21 | extern int yy_noeof; |
---|
[0e1846] | 22 | extern char prompt_char; |
---|
[057e93c] | 23 | #ifdef HAVE_TCL |
---|
[0e1846] | 24 | extern BOOLEAN tclmode; |
---|
[057e93c] | 25 | #endif |
---|
[0e1846] | 26 | extern BOOLEAN errorreported; |
---|
| 27 | extern BOOLEAN fe_use_fgets; |
---|
| 28 | extern BOOLEAN feBatch; |
---|
| 29 | extern BOOLEAN feProt; |
---|
| 30 | |
---|
| 31 | #define PROT_NONE 0 |
---|
| 32 | #define PROT_I 1 |
---|
| 33 | #define PROT_O 2 |
---|
| 34 | #define PROT_IO 3 |
---|
| 35 | |
---|
| 36 | /* the C-part: */ |
---|
| 37 | #ifdef __cplusplus |
---|
| 38 | extern "C" { |
---|
| 39 | #endif |
---|
| 40 | |
---|
| 41 | void Werror(char *fmt, ...); |
---|
[0da09b5] | 42 | void WerrorS(char *s); |
---|
[0e1846] | 43 | |
---|
| 44 | #ifdef __cplusplus |
---|
| 45 | } |
---|
| 46 | /* the C++-part: */ |
---|
| 47 | |
---|
[057e93c] | 48 | enum feBufferTypes |
---|
[0e1846] | 49 | { |
---|
[a18fae] | 50 | BT_none = 0, // entry level |
---|
[0e1846] | 51 | BT_break = 1, // while, for |
---|
[a18fae] | 52 | BT_proc, // proc |
---|
[0e1846] | 53 | BT_example, // example |
---|
| 54 | BT_file, // <"file" |
---|
| 55 | BT_execute, // execute |
---|
| 56 | BT_if, // if |
---|
| 57 | BT_else // else |
---|
| 58 | }; |
---|
| 59 | |
---|
[057e93c] | 60 | enum feBufferInputs |
---|
| 61 | { |
---|
| 62 | BI_stdin = 1, |
---|
| 63 | BI_buffer, |
---|
| 64 | BI_file |
---|
| 65 | }; |
---|
| 66 | |
---|
[1caa72] | 67 | char* feGetSearchPath(const char* argv0 = NULL); |
---|
[97454d] | 68 | char* feGetExpandedExecutable(const char* argv0 = NULL); |
---|
[057e93c] | 69 | FILE * feFopen(char *path, char *mode, char *where=NULL, int useWerror=FALSE); |
---|
| 70 | void fePause(void); |
---|
| 71 | void Print(char* fmt, ...); |
---|
| 72 | void PrintS(char* s); |
---|
| 73 | void PrintLn(); |
---|
| 74 | void PrintTCLS(char c, char * s); |
---|
[0e1846] | 75 | #ifndef macintosh |
---|
| 76 | inline void PrintTCL(char c, int l,char *s) |
---|
| 77 | { |
---|
| 78 | #ifdef HAVE_TCL |
---|
| 79 | if (s!=NULL) printf("%c:%d:%s\n",c,l,s); |
---|
| 80 | else printf("%c:%d:\n",c,l); |
---|
| 81 | fflush(stdout); |
---|
| 82 | #endif |
---|
| 83 | } |
---|
| 84 | #endif |
---|
| 85 | |
---|
[057e93c] | 86 | char * StringAppend(char *fmt, ...); |
---|
| 87 | char * StringAppendS(char *s); |
---|
| 88 | char * StringSet(char *fmt, ...); |
---|
| 89 | char * StringSetS(char* s); |
---|
[0e1846] | 90 | const char * VoiceName(); |
---|
[057e93c] | 91 | void VoiceBackTrack(); |
---|
| 92 | void WarnS(char *s); |
---|
| 93 | void Warn(char *fmt, ...); |
---|
| 94 | BOOLEAN contBuffer(feBufferTypes typ); |
---|
| 95 | char * eati(char *s, int *i); |
---|
| 96 | BOOLEAN exitBuffer(feBufferTypes typ); |
---|
| 97 | BOOLEAN exitVoice(); |
---|
[0e1846] | 98 | #define mflush() fflush(stdout) |
---|
[057e93c] | 99 | void monitor(char* s,int mode); |
---|
| 100 | BOOLEAN newFile(char* fname, FILE *f=NULL); |
---|
| 101 | void newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0); |
---|
| 102 | void * myynewbuffer(); |
---|
| 103 | void myyoldbuffer(void * oldb); |
---|
| 104 | |
---|
[f92fa13] | 105 | /* assume(x) -- a handy macro for assumptions */ |
---|
| 106 | #ifdef NDEBUG |
---|
| 107 | /* empty macro, if NDEBUG */ |
---|
| 108 | #define assume(x) ((void*) 0) |
---|
| 109 | #else /* ! NDEBUG */ |
---|
| 110 | #define assume(x) _assume(x, __FILE__, __LINE__) |
---|
| 111 | #define _assume(x, f, l) \ |
---|
| 112 | do \ |
---|
| 113 | { \ |
---|
| 114 | if (! (x)) \ |
---|
| 115 | { \ |
---|
| 116 | Warn("Internal assume violation: file %s line %d\n", f, l); \ |
---|
| 117 | } \ |
---|
| 118 | } \ |
---|
| 119 | while (0) |
---|
| 120 | #endif /* NDEBUG */ |
---|
[057e93c] | 121 | |
---|
| 122 | class Voice |
---|
| 123 | { |
---|
| 124 | public: |
---|
| 125 | Voice * next; |
---|
| 126 | Voice * prev; |
---|
| 127 | char * filename; // file name or proc name |
---|
| 128 | procinfo * pi; // proc info |
---|
| 129 | void * oldb; // internal scanner buffer |
---|
| 130 | int start_lineno; // lineno, to restore in recursion |
---|
| 131 | int curr_lineno; // current lineno |
---|
| 132 | feBufferInputs sw; // BI_stdin: read from STDIN |
---|
| 133 | // BI_buffer: buffer |
---|
| 134 | // BI_file: files |
---|
| 135 | char ifsw; // if-switch: |
---|
| 136 | /*1 ifsw==0: no if statement, else is invalid |
---|
| 137 | * ==1: if (0) processed, execute else |
---|
| 138 | * ==2: if (1) processed, else allowed but not executed |
---|
| 139 | */ |
---|
| 140 | feBufferTypes typ; // buffer type: see BT_.. |
---|
| 141 | // for files only: |
---|
| 142 | FILE * files; // file handle |
---|
| 143 | // for buffers only: |
---|
| 144 | char * buffer; // buffer pointer |
---|
| 145 | long fptr; // current position in buffer |
---|
| 146 | |
---|
| 147 | Voice() { memset(this,0,sizeof(*this));} |
---|
| 148 | feBufferTypes Typ(); |
---|
| 149 | void Next(); |
---|
| 150 | } ; |
---|
| 151 | |
---|
| 152 | extern Voice *currentVoice; |
---|
| 153 | |
---|
| 154 | Voice * feInitStdin(); |
---|
[0e1846] | 155 | |
---|
| 156 | /* feread.cc: */ |
---|
| 157 | #ifdef HAVE_FEREAD |
---|
| 158 | void fe_set_input_mode (void); |
---|
| 159 | void fe_temp_set (void); |
---|
| 160 | void fe_temp_reset (void); |
---|
| 161 | char * fe_fgets_stdin(char *s, int size); |
---|
| 162 | #ifndef MSDOS |
---|
| 163 | #ifdef HAVE_ATEXIT |
---|
| 164 | void fe_reset_input_mode (void); |
---|
| 165 | #else |
---|
| 166 | void fe_reset_input_mode (int i, void *v); |
---|
| 167 | #endif |
---|
| 168 | #else |
---|
| 169 | #define fe_reset_input_mode() |
---|
| 170 | #endif |
---|
| 171 | #else |
---|
| 172 | #ifdef HAVE_READLINE |
---|
| 173 | void fe_set_input_mode (void); |
---|
[057e93c] | 174 | void fe_reset_input_mode (void); |
---|
[0e1846] | 175 | char * fe_fgets_stdin_rl(char *pr,char *s, int size); |
---|
| 176 | #define fe_fgets_stdin(A,B) fe_fgets_stdin_rl(fe_promptstr,A,B) |
---|
| 177 | #else |
---|
| 178 | #define fe_fgets_stdin(A,B) fgets(A,B,stdin) |
---|
| 179 | #endif |
---|
| 180 | #endif |
---|
| 181 | #endif |
---|
| 182 | #endif |
---|