[35aab3] | 1 | #ifndef FEBASE_H |
---|
| 2 | #define FEBASE_H |
---|
| 3 | /**************************************** |
---|
| 4 | * Computer Algebra System SINGULAR * |
---|
| 5 | ****************************************/ |
---|
[f4d7837] | 6 | /* $Id: febase.h,v 1.2 2005-05-04 07:50:49 Singular Exp $ */ |
---|
[35aab3] | 7 | /* |
---|
| 8 | * ABSTRACT: basic i/o |
---|
| 9 | */ |
---|
| 10 | #include <stdio.h> |
---|
| 11 | #include <string.h> |
---|
| 12 | #include "structs.h" |
---|
| 13 | |
---|
| 14 | /* define DIR_SEPP, etc */ |
---|
| 15 | #ifdef macintosh /* mac os 9 */ |
---|
| 16 | # define DIR_SEP ':' |
---|
| 17 | # define DIR_SEPP ":" |
---|
| 18 | # define UP_DIR "" |
---|
| 19 | #else /* unix , WINNT */ |
---|
| 20 | # define DIR_SEP '/' |
---|
| 21 | # define DIR_SEPP "/" |
---|
| 22 | # define UP_DIR ".." |
---|
| 23 | #endif /* macintosh */ |
---|
| 24 | // this might still get reset by feInitResources |
---|
| 25 | extern char fePathSep; |
---|
| 26 | |
---|
| 27 | /* define MAXPATHLEN */ |
---|
| 28 | #ifdef HAVE_SYS_PARAM_H |
---|
| 29 | #include <sys/param.h> |
---|
| 30 | #endif |
---|
| 31 | |
---|
| 32 | /* the are versions of limits.h with incorrect values (IRIX_6) |
---|
| 33 | * let's include our own */ |
---|
| 34 | |
---|
| 35 | #include <mylimits.h> |
---|
| 36 | |
---|
| 37 | /* OSF/1 and AIX_4 are missing the header for setenv, but the proc exists */ |
---|
[f4d7837] | 38 | #if defined(DecAlpha_OSF1) || defined(AIX_4) |
---|
[35aab3] | 39 | #ifdef __cplusplus |
---|
| 40 | extern "C" |
---|
| 41 | { |
---|
| 42 | #endif |
---|
| 43 | int setenv(const char *name, const char *value, int overwrite); |
---|
| 44 | #ifdef __cplusplus |
---|
| 45 | } |
---|
| 46 | #endif |
---|
| 47 | #endif |
---|
| 48 | |
---|
| 49 | #ifndef MAXPATHLEN |
---|
| 50 | #define MAXPATHLEN 1024 |
---|
| 51 | #endif |
---|
| 52 | |
---|
| 53 | #ifdef HAVE_LIBREADLINE |
---|
| 54 | #define HAVE_READLINE 1 |
---|
| 55 | #endif |
---|
| 56 | |
---|
| 57 | #ifdef HAVE_DYN_RL |
---|
| 58 | #undef HAVE_READLINE |
---|
| 59 | #define HAVE_FEREAD 1 |
---|
| 60 | #elif ! defined(HAVE_READLINE) |
---|
| 61 | #ifndef ix86_Win |
---|
| 62 | #define HAVE_FEREAD 1 |
---|
| 63 | #endif |
---|
| 64 | #endif |
---|
| 65 | #ifdef ix86_Linux |
---|
| 66 | // FEREAD stuff does not work with glibc2 |
---|
| 67 | #undef HAVE_FEREAD |
---|
| 68 | #endif |
---|
| 69 | |
---|
| 70 | /* |
---|
| 71 | // These are our versions of fopen and fread They are very similar to |
---|
| 72 | // the usual fopen and fread, except that on reading, they always |
---|
| 73 | // convert "\r\n" into " \n" and "\r" into "\n". |
---|
| 74 | // |
---|
| 75 | // IMPORTANT: do only use myfopen and myfread when reading text, |
---|
| 76 | // do never use fopen and fread |
---|
| 77 | */ |
---|
| 78 | #ifdef ix86_Win |
---|
| 79 | FILE *myfopen(char *path, char *mode); |
---|
| 80 | #else |
---|
| 81 | #define myfopen fopen |
---|
| 82 | #endif |
---|
| 83 | size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream); |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | extern char* feErrors; |
---|
| 87 | extern char* feArgv0; |
---|
| 88 | extern int feErrorsLen; |
---|
| 89 | extern FILE* feProtFile; |
---|
| 90 | extern FILE* feFilePending; /*temp. storage for grammar.y */ |
---|
| 91 | extern char fe_promptstr[]; |
---|
| 92 | extern int si_echo, printlevel; |
---|
| 93 | extern int pagelength, colmax; |
---|
| 94 | extern int yy_blocklineno; |
---|
| 95 | extern int yy_noeof; |
---|
| 96 | extern char prompt_char; |
---|
| 97 | extern const char feNotImplemented[]; |
---|
| 98 | #ifdef HAVE_TCL |
---|
| 99 | extern BOOLEAN tclmode; |
---|
| 100 | #endif |
---|
| 101 | extern BOOLEAN errorreported; |
---|
| 102 | extern BOOLEAN feProt; |
---|
| 103 | extern BOOLEAN feWarn; |
---|
| 104 | extern BOOLEAN feOut; |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | #define PROT_NONE 0 |
---|
| 108 | #define PROT_I 1 |
---|
| 109 | #define PROT_O 2 |
---|
| 110 | #define PROT_IO 3 |
---|
| 111 | |
---|
| 112 | /* the C-part: */ |
---|
| 113 | #define mflush() fflush(stdout) |
---|
| 114 | |
---|
| 115 | #ifdef __cplusplus |
---|
| 116 | extern "C" { |
---|
| 117 | #endif |
---|
| 118 | |
---|
| 119 | void Werror(char *fmt, ...); |
---|
| 120 | void WerrorS(const char *s); |
---|
| 121 | void WarnS(const char *s); |
---|
| 122 | void Print(char* fmt, ...); |
---|
| 123 | void PrintLn(); |
---|
| 124 | #ifdef HAVE_TCL |
---|
| 125 | void PrintTCLS(const char c, const char * s); |
---|
| 126 | #else |
---|
| 127 | #define PrintTCLS(A,B) Print("TCL-ErrS:%s",B) |
---|
| 128 | #endif |
---|
| 129 | void PrintS(char* s); |
---|
| 130 | char* feGetResource(const char id); |
---|
| 131 | |
---|
| 132 | #ifdef HAVE_FEREAD |
---|
| 133 | extern BOOLEAN fe_is_raw_tty; |
---|
| 134 | void fe_temp_reset (void); |
---|
| 135 | #endif |
---|
| 136 | |
---|
| 137 | #ifdef __cplusplus |
---|
| 138 | } |
---|
| 139 | /* the C++-part: */ |
---|
| 140 | |
---|
| 141 | enum feBufferTypes |
---|
| 142 | { |
---|
| 143 | BT_none = 0, // entry level |
---|
| 144 | BT_break = 1, // while, for |
---|
| 145 | BT_proc, // proc |
---|
| 146 | BT_example, // example |
---|
| 147 | BT_file, // <"file" |
---|
| 148 | BT_execute, // execute |
---|
| 149 | BT_if, // if |
---|
| 150 | BT_else // else |
---|
| 151 | }; |
---|
| 152 | |
---|
| 153 | enum feBufferInputs |
---|
| 154 | { |
---|
| 155 | BI_stdin = 1, |
---|
| 156 | BI_buffer, |
---|
| 157 | BI_file |
---|
| 158 | }; |
---|
| 159 | |
---|
| 160 | /***************************************************************** |
---|
| 161 | * |
---|
| 162 | * Resource management (feResources.cc) |
---|
| 163 | * |
---|
| 164 | *****************************************************************/ |
---|
| 165 | // returns value of Resource as read-only string, or NULL |
---|
| 166 | // if Resource not found |
---|
| 167 | // issues warning, if explicitely requested (warn > 0), or |
---|
| 168 | // if warn < 0 and Resource is gotten for the first time |
---|
| 169 | // Always quiet if warn == 0 |
---|
| 170 | char* feResource(const char id, int warn = -1); |
---|
| 171 | char* feResource(const char* key, int warn = -1); |
---|
| 172 | // This needs to be called before the first call to feResource |
---|
| 173 | // Initializes Resources, SearchPath, and extends PATH |
---|
| 174 | void feInitResources(char* argv0); |
---|
| 175 | // Re-inits resources, should be called after changing env. variables |
---|
| 176 | void feReInitResources(); |
---|
| 177 | // Prints resources into string with StringAppend, etc |
---|
| 178 | void feStringAppendResources(int warn = -1); |
---|
| 179 | |
---|
| 180 | /***************************************************************** |
---|
| 181 | * |
---|
| 182 | * help system (fehelp.cc) |
---|
| 183 | * |
---|
| 184 | *****************************************************************/ |
---|
| 185 | // if str != NULL display help for str |
---|
| 186 | // display general help, otherwise |
---|
| 187 | void feHelp(char* str = NULL); |
---|
| 188 | // if browser != NULL or feOpt("browser") != NULL |
---|
| 189 | // set HelpBrowser to browser |
---|
| 190 | // otherwise, if browser was already set, leave as is, |
---|
| 191 | // if not, choose first available browser |
---|
| 192 | // return string identifying current browser |
---|
| 193 | // keeps feOpt("browser") up-to-date |
---|
| 194 | // Optional warn argument is as in feResource |
---|
| 195 | char* feHelpBrowser(char* browser = NULL, int warn = -1); |
---|
| 196 | void feStringAppendBrowsers(int warn = -1); |
---|
| 197 | |
---|
| 198 | /***************************************************************** |
---|
| 199 | * |
---|
| 200 | * version Id |
---|
| 201 | * |
---|
| 202 | *****************************************************************/ |
---|
| 203 | /* extern unsigned long feVersionId; */ |
---|
| 204 | |
---|
| 205 | /***************************************************************** |
---|
| 206 | * |
---|
| 207 | * File Stuff |
---|
| 208 | * |
---|
| 209 | *****************************************************************/ |
---|
| 210 | FILE * feFopen(char *path, char *mode, char *where=NULL, int useWerror=FALSE, |
---|
| 211 | int path_only=FALSE); |
---|
| 212 | |
---|
| 213 | #ifndef __MWERKS__ |
---|
| 214 | #ifdef HAVE_TCL |
---|
| 215 | |
---|
| 216 | inline void PrintTCL(const char c, int l,const char *s) |
---|
| 217 | { |
---|
| 218 | if (s!=NULL) printf("%c:%d:%s",c,l,s); |
---|
| 219 | else if(l==0) printf("%c:0:",c); |
---|
| 220 | else printf("%c:1:%c",c,'0'+l); |
---|
| 221 | fflush(stdout); |
---|
| 222 | } |
---|
| 223 | #else |
---|
| 224 | #define PrintTCL(A,B,C) Print("TCL-Err:%s",C) |
---|
| 225 | #endif /* HAVE_TCL */ |
---|
| 226 | #endif /* __MWERKS__ */ |
---|
| 227 | |
---|
| 228 | char * StringAppend(char *fmt, ...); |
---|
| 229 | char * StringAppendS(char *s); |
---|
| 230 | char * StringSetS(char* s); |
---|
| 231 | const char * VoiceName(); |
---|
| 232 | void VoiceBackTrack(); |
---|
| 233 | void Warn(const char *fmt, ...); |
---|
| 234 | BOOLEAN contBuffer(feBufferTypes typ); |
---|
| 235 | char * eati(char *s, int *i); |
---|
| 236 | BOOLEAN exitBuffer(feBufferTypes typ); |
---|
| 237 | BOOLEAN exitVoice(); |
---|
| 238 | void monitor(char* s,int mode); |
---|
| 239 | BOOLEAN newFile(char* fname, FILE *f=NULL); |
---|
| 240 | void newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0); |
---|
| 241 | void * myynewbuffer(); |
---|
| 242 | void myyoldbuffer(void * oldb); |
---|
| 243 | |
---|
| 244 | class Voice |
---|
| 245 | { |
---|
| 246 | public: |
---|
| 247 | Voice * next; |
---|
| 248 | Voice * prev; |
---|
| 249 | char * filename; // file name or proc name |
---|
| 250 | procinfo * pi; // proc info |
---|
| 251 | void * oldb; // internal scanner buffer |
---|
| 252 | // for files only: |
---|
| 253 | FILE * files; // file handle |
---|
| 254 | // for buffers only: |
---|
| 255 | char * buffer; // buffer pointer |
---|
| 256 | long fptr; // current position in buffer |
---|
| 257 | |
---|
| 258 | int start_lineno; // lineno, to restore in recursion |
---|
| 259 | int curr_lineno; // current lineno |
---|
| 260 | feBufferInputs sw; // BI_stdin: read from STDIN |
---|
| 261 | // BI_buffer: buffer |
---|
| 262 | // BI_file: files |
---|
| 263 | char ifsw; // if-switch: |
---|
| 264 | /*1 ifsw==0: no if statement, else is invalid |
---|
| 265 | * ==1: if (0) processed, execute else |
---|
| 266 | * ==2: if (1) processed, else allowed but not executed |
---|
| 267 | */ |
---|
| 268 | feBufferTypes typ; // buffer type: see BT_.. |
---|
| 269 | |
---|
| 270 | Voice() { memset(this,0,sizeof(*this));} |
---|
| 271 | feBufferTypes Typ(); |
---|
| 272 | void Next(); |
---|
| 273 | } ; |
---|
| 274 | |
---|
| 275 | extern Voice *currentVoice; |
---|
| 276 | |
---|
| 277 | Voice * feInitStdin(Voice *pp); |
---|
| 278 | |
---|
| 279 | /* feread.cc: */ |
---|
| 280 | |
---|
| 281 | /* the interface for reading: */ |
---|
| 282 | extern char * (*fe_fgets_stdin)(char *pr,char *s, int size); |
---|
| 283 | |
---|
| 284 | #ifdef HAVE_DYN_RL |
---|
| 285 | char * fe_fgets_stdin_drl(char *pr,char *s, int size); |
---|
| 286 | #endif |
---|
| 287 | |
---|
| 288 | extern "C" void fe_reset_input_mode(); |
---|
| 289 | |
---|
| 290 | #ifndef MSDOS |
---|
| 291 | extern "C" { |
---|
| 292 | #ifndef HAVE_ATEXIT |
---|
| 293 | void fe_reset_fe (int i, void *v); |
---|
| 294 | #else |
---|
| 295 | void fe_reset_fe (void); |
---|
| 296 | #endif |
---|
| 297 | } |
---|
| 298 | #endif |
---|
| 299 | |
---|
| 300 | |
---|
| 301 | /* possible implementations: */ |
---|
| 302 | #ifdef __cplusplus |
---|
| 303 | extern "C" |
---|
| 304 | { |
---|
| 305 | #endif |
---|
| 306 | /* readline, linked in: */ |
---|
| 307 | char * fe_fgets_stdin_rl(char *pr,char *s, int size); |
---|
| 308 | |
---|
| 309 | /* emulated readline: */ |
---|
| 310 | char * fe_fgets_stdin_emu(char *pr,char *s, int size); |
---|
| 311 | |
---|
| 312 | /* fgets: */ |
---|
| 313 | char * fe_fgets(char *pr,char *s, int size); |
---|
| 314 | |
---|
| 315 | #ifdef HAVE_TCL |
---|
| 316 | /* tcl: */ |
---|
| 317 | char * fe_fgets_tcl(char *pr,char *s, int size); |
---|
| 318 | #endif |
---|
| 319 | |
---|
| 320 | /* dummy (for batch mode): */ |
---|
| 321 | char * fe_fgets_dummy(char *pr,char *s, int size); |
---|
| 322 | |
---|
| 323 | #ifdef __cplusplus |
---|
| 324 | } |
---|
| 325 | #endif |
---|
| 326 | #endif /* c++ only */ |
---|
| 327 | |
---|
| 328 | /* everything in between calls to these procedures is printed into a string |
---|
| 329 | * which is returned by SprintEnd() |
---|
| 330 | */ |
---|
| 331 | void SPrintStart(); |
---|
| 332 | char* SPrintEnd(); |
---|
| 333 | |
---|
| 334 | |
---|
| 335 | #endif /* ifndef FEBASE_H */ |
---|