[35aab3] | 1 | #ifndef FEBASE_H |
---|
| 2 | #define FEBASE_H |
---|
| 3 | /**************************************** |
---|
| 4 | * Computer Algebra System SINGULAR * |
---|
| 5 | ****************************************/ |
---|
[341696] | 6 | /* $Id$ */ |
---|
[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 */ |
---|
[dcb1b7] | 15 | /* unix , WINNT */ |
---|
[35aab3] | 16 | # define DIR_SEP '/' |
---|
| 17 | # define DIR_SEPP "/" |
---|
| 18 | # define UP_DIR ".." |
---|
| 19 | // this might still get reset by feInitResources |
---|
| 20 | extern char fePathSep; |
---|
| 21 | |
---|
| 22 | /* define MAXPATHLEN */ |
---|
| 23 | #ifdef HAVE_SYS_PARAM_H |
---|
| 24 | #include <sys/param.h> |
---|
| 25 | #endif |
---|
| 26 | |
---|
| 27 | /* the are versions of limits.h with incorrect values (IRIX_6) |
---|
| 28 | * let's include our own */ |
---|
| 29 | |
---|
| 30 | #include <mylimits.h> |
---|
| 31 | |
---|
| 32 | /* OSF/1 and AIX_4 are missing the header for setenv, but the proc exists */ |
---|
[f4d7837] | 33 | #if defined(DecAlpha_OSF1) || defined(AIX_4) |
---|
[35aab3] | 34 | #ifdef __cplusplus |
---|
| 35 | extern "C" |
---|
| 36 | { |
---|
| 37 | #endif |
---|
| 38 | int setenv(const char *name, const char *value, int overwrite); |
---|
| 39 | #ifdef __cplusplus |
---|
| 40 | } |
---|
| 41 | #endif |
---|
| 42 | #endif |
---|
| 43 | |
---|
| 44 | #ifndef MAXPATHLEN |
---|
| 45 | #define MAXPATHLEN 1024 |
---|
| 46 | #endif |
---|
| 47 | |
---|
| 48 | #ifdef HAVE_LIBREADLINE |
---|
| 49 | #define HAVE_READLINE 1 |
---|
| 50 | #endif |
---|
| 51 | |
---|
| 52 | #ifdef HAVE_DYN_RL |
---|
| 53 | #undef HAVE_READLINE |
---|
| 54 | #define HAVE_FEREAD 1 |
---|
| 55 | #elif ! defined(HAVE_READLINE) |
---|
| 56 | #ifndef ix86_Win |
---|
| 57 | #define HAVE_FEREAD 1 |
---|
| 58 | #endif |
---|
| 59 | #endif |
---|
| 60 | #ifdef ix86_Linux |
---|
| 61 | // FEREAD stuff does not work with glibc2 |
---|
| 62 | #undef HAVE_FEREAD |
---|
| 63 | #endif |
---|
| 64 | |
---|
| 65 | /* |
---|
| 66 | // These are our versions of fopen and fread They are very similar to |
---|
| 67 | // the usual fopen and fread, except that on reading, they always |
---|
| 68 | // convert "\r\n" into " \n" and "\r" into "\n". |
---|
| 69 | // |
---|
| 70 | // IMPORTANT: do only use myfopen and myfread when reading text, |
---|
| 71 | // do never use fopen and fread |
---|
| 72 | */ |
---|
| 73 | #ifdef ix86_Win |
---|
[d3006b] | 74 | FILE *myfopen(const char *path, const char *mode); |
---|
[35aab3] | 75 | #else |
---|
| 76 | #define myfopen fopen |
---|
| 77 | #endif |
---|
[00303d0] | 78 | |
---|
[35aab3] | 79 | size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream); |
---|
| 80 | |
---|
[b07ba77] | 81 | enum noeof_t |
---|
| 82 | { |
---|
| 83 | noeof_brace = 1, |
---|
| 84 | noeof_asstring, |
---|
| 85 | noeof_block, |
---|
| 86 | noeof_bracket, |
---|
| 87 | noeof_comment, |
---|
| 88 | noeof_procname, |
---|
| 89 | noeof_string |
---|
| 90 | }; /* for scanner.l */ |
---|
[35aab3] | 91 | |
---|
| 92 | extern char* feErrors; |
---|
| 93 | extern char* feArgv0; |
---|
| 94 | extern int feErrorsLen; |
---|
| 95 | extern FILE* feProtFile; |
---|
| 96 | extern FILE* feFilePending; /*temp. storage for grammar.y */ |
---|
| 97 | extern char fe_promptstr[]; |
---|
| 98 | extern int si_echo, printlevel; |
---|
| 99 | extern int pagelength, colmax; |
---|
| 100 | extern int yy_blocklineno; |
---|
| 101 | extern int yy_noeof; |
---|
| 102 | extern char prompt_char; |
---|
| 103 | extern const char feNotImplemented[]; |
---|
| 104 | #ifdef HAVE_TCL |
---|
| 105 | extern BOOLEAN tclmode; |
---|
| 106 | #endif |
---|
| 107 | extern BOOLEAN errorreported; |
---|
[4840ebb] | 108 | extern int feProt; |
---|
[35aab3] | 109 | extern BOOLEAN feWarn; |
---|
| 110 | extern BOOLEAN feOut; |
---|
[460c65f] | 111 | extern int traceit ; |
---|
| 112 | #define TRACE_SHOW_PROC 1 |
---|
| 113 | #define TRACE_SHOW_LINENO 2 |
---|
| 114 | #define TRACE_SHOW_LINE 4 |
---|
| 115 | #define TRACE_SHOW_RINGS 8 |
---|
| 116 | #define TRACE_SHOW_LINE1 16 |
---|
| 117 | #define TRACE_BREAKPOINT 32 |
---|
| 118 | #define TRACE_TMP_BREAKPOINT 64 |
---|
[835d83] | 119 | extern int myynest; |
---|
| 120 | extern int yylineno; |
---|
| 121 | extern char my_yylinebuf[80]; |
---|
[35aab3] | 122 | |
---|
| 123 | #define PROT_NONE 0 |
---|
| 124 | #define PROT_I 1 |
---|
| 125 | #define PROT_O 2 |
---|
| 126 | #define PROT_IO 3 |
---|
| 127 | |
---|
| 128 | /* the C-part: */ |
---|
| 129 | #define mflush() fflush(stdout) |
---|
| 130 | |
---|
| 131 | #ifdef __cplusplus |
---|
| 132 | extern "C" { |
---|
| 133 | #endif |
---|
| 134 | |
---|
[fb0d9a] | 135 | void Werror(const char *fmt, ...) __attribute__((format(printf,1,2))); |
---|
[35aab3] | 136 | void WerrorS(const char *s); |
---|
| 137 | void WarnS(const char *s); |
---|
[fb0d9a] | 138 | void Print(const char* fmt, ...) __attribute__((format(printf,1,2))); |
---|
[490a23b] | 139 | /* Print should not produce more than strlen(fmt)+510 characters! */ |
---|
| 140 | |
---|
| 141 | void PrintNSpaces(const int n); |
---|
[35aab3] | 142 | void PrintLn(); |
---|
| 143 | #ifdef HAVE_TCL |
---|
| 144 | void PrintTCLS(const char c, const char * s); |
---|
| 145 | #else |
---|
| 146 | #define PrintTCLS(A,B) Print("TCL-ErrS:%s",B) |
---|
| 147 | #endif |
---|
[a9d8e7] | 148 | void PrintS(const char* s); |
---|
[35aab3] | 149 | char* feGetResource(const char id); |
---|
| 150 | |
---|
| 151 | #ifdef HAVE_FEREAD |
---|
| 152 | extern BOOLEAN fe_is_raw_tty; |
---|
| 153 | void fe_temp_reset (void); |
---|
| 154 | #endif |
---|
| 155 | |
---|
| 156 | #ifdef __cplusplus |
---|
| 157 | } |
---|
| 158 | /* the C++-part: */ |
---|
| 159 | |
---|
[460c65f] | 160 | typedef enum { LANG_NONE, LANG_TOP, LANG_SINGULAR, LANG_C, LANG_MAX} language_defs; |
---|
| 161 | // LANG_TOP : Toplevel package only |
---|
| 162 | // LANG_SINGULAR: |
---|
| 163 | // LANG_C : |
---|
| 164 | // |
---|
| 165 | |
---|
| 166 | class proc_singular |
---|
| 167 | { |
---|
| 168 | public: |
---|
| 169 | long proc_start; // position where proc is starting |
---|
| 170 | long def_end; // position where proc header is ending |
---|
| 171 | long help_start; // position where help is starting |
---|
| 172 | long help_end; // position where help is starting |
---|
| 173 | long body_start; // position where proc-body is starting |
---|
| 174 | long body_end; // position where proc-body is ending |
---|
| 175 | long example_start; // position where example is starting |
---|
| 176 | long proc_end; // position where proc is ending |
---|
| 177 | int proc_lineno; |
---|
| 178 | int body_lineno; |
---|
| 179 | int example_lineno; |
---|
| 180 | char *body; |
---|
| 181 | long help_chksum; |
---|
| 182 | }; |
---|
| 183 | |
---|
| 184 | struct proc_object |
---|
| 185 | { |
---|
| 186 | //public: |
---|
| 187 | BOOLEAN (*function)(leftv res, leftv v); |
---|
| 188 | }; |
---|
| 189 | union uprocinfodata |
---|
| 190 | { |
---|
| 191 | public: |
---|
| 192 | proc_singular s; // data of Singular-procedure |
---|
| 193 | struct proc_object o; // pointer to binary-function |
---|
| 194 | }; |
---|
| 195 | |
---|
| 196 | typedef union uprocinfodata procinfodata; |
---|
| 197 | |
---|
| 198 | class procinfo; |
---|
| 199 | typedef procinfo * procinfov; |
---|
| 200 | |
---|
| 201 | class procinfo |
---|
| 202 | { |
---|
| 203 | public: |
---|
| 204 | char *libname; |
---|
| 205 | char *procname; |
---|
| 206 | package pack; |
---|
| 207 | language_defs language; |
---|
| 208 | short ref; |
---|
| 209 | char is_static; // if set, proc not accessible for user |
---|
| 210 | char trace_flag; |
---|
| 211 | procinfodata data; |
---|
| 212 | }; |
---|
[35aab3] | 213 | enum feBufferTypes |
---|
| 214 | { |
---|
| 215 | BT_none = 0, // entry level |
---|
| 216 | BT_break = 1, // while, for |
---|
| 217 | BT_proc, // proc |
---|
| 218 | BT_example, // example |
---|
| 219 | BT_file, // <"file" |
---|
| 220 | BT_execute, // execute |
---|
| 221 | BT_if, // if |
---|
| 222 | BT_else // else |
---|
| 223 | }; |
---|
| 224 | |
---|
| 225 | enum feBufferInputs |
---|
| 226 | { |
---|
| 227 | BI_stdin = 1, |
---|
| 228 | BI_buffer, |
---|
| 229 | BI_file |
---|
| 230 | }; |
---|
| 231 | |
---|
| 232 | /***************************************************************** |
---|
| 233 | * |
---|
| 234 | * Resource management (feResources.cc) |
---|
| 235 | * |
---|
| 236 | *****************************************************************/ |
---|
| 237 | // returns value of Resource as read-only string, or NULL |
---|
| 238 | // if Resource not found |
---|
| 239 | // issues warning, if explicitely requested (warn > 0), or |
---|
| 240 | // if warn < 0 and Resource is gotten for the first time |
---|
| 241 | // Always quiet if warn == 0 |
---|
| 242 | char* feResource(const char id, int warn = -1); |
---|
| 243 | char* feResource(const char* key, int warn = -1); |
---|
| 244 | // This needs to be called before the first call to feResource |
---|
| 245 | // Initializes Resources, SearchPath, and extends PATH |
---|
| 246 | void feInitResources(char* argv0); |
---|
| 247 | // Re-inits resources, should be called after changing env. variables |
---|
| 248 | void feReInitResources(); |
---|
| 249 | // Prints resources into string with StringAppend, etc |
---|
| 250 | void feStringAppendResources(int warn = -1); |
---|
| 251 | |
---|
| 252 | /***************************************************************** |
---|
| 253 | * |
---|
| 254 | * help system (fehelp.cc) |
---|
| 255 | * |
---|
| 256 | *****************************************************************/ |
---|
| 257 | // if str != NULL display help for str |
---|
| 258 | // display general help, otherwise |
---|
| 259 | void feHelp(char* str = NULL); |
---|
| 260 | // if browser != NULL or feOpt("browser") != NULL |
---|
| 261 | // set HelpBrowser to browser |
---|
| 262 | // otherwise, if browser was already set, leave as is, |
---|
| 263 | // if not, choose first available browser |
---|
| 264 | // return string identifying current browser |
---|
| 265 | // keeps feOpt("browser") up-to-date |
---|
| 266 | // Optional warn argument is as in feResource |
---|
[9db0567] | 267 | const char* feHelpBrowser(char* browser = NULL, int warn = -1); |
---|
[35aab3] | 268 | void feStringAppendBrowsers(int warn = -1); |
---|
| 269 | |
---|
| 270 | /***************************************************************** |
---|
| 271 | * |
---|
| 272 | * version Id |
---|
| 273 | * |
---|
| 274 | *****************************************************************/ |
---|
| 275 | /* extern unsigned long feVersionId; */ |
---|
| 276 | |
---|
| 277 | /***************************************************************** |
---|
| 278 | * |
---|
| 279 | * File Stuff |
---|
| 280 | * |
---|
| 281 | *****************************************************************/ |
---|
[85e68dd] | 282 | FILE * feFopen(const char *path, const char *mode, char *where=NULL, |
---|
| 283 | int useWerror=FALSE, int path_only=FALSE); |
---|
[35aab3] | 284 | |
---|
| 285 | #ifdef HAVE_TCL |
---|
| 286 | |
---|
| 287 | inline void PrintTCL(const char c, int l,const char *s) |
---|
| 288 | { |
---|
| 289 | if (s!=NULL) printf("%c:%d:%s",c,l,s); |
---|
| 290 | else if(l==0) printf("%c:0:",c); |
---|
| 291 | else printf("%c:1:%c",c,'0'+l); |
---|
| 292 | fflush(stdout); |
---|
| 293 | } |
---|
| 294 | #else |
---|
| 295 | #define PrintTCL(A,B,C) Print("TCL-Err:%s",C) |
---|
| 296 | #endif /* HAVE_TCL */ |
---|
| 297 | |
---|
[a9d8e7] | 298 | char * StringAppend(const char *fmt, ...); |
---|
| 299 | char * StringAppendS(const char *s); |
---|
| 300 | char * StringSetS(const char* s); |
---|
[35aab3] | 301 | const char * VoiceName(); |
---|
| 302 | void VoiceBackTrack(); |
---|
| 303 | void Warn(const char *fmt, ...); |
---|
| 304 | BOOLEAN contBuffer(feBufferTypes typ); |
---|
[85e68dd] | 305 | const char * eati(const char *s, int *i); |
---|
[35aab3] | 306 | BOOLEAN exitBuffer(feBufferTypes typ); |
---|
| 307 | BOOLEAN exitVoice(); |
---|
[9539de6] | 308 | void monitor(void *F, int mode); /* FILE*, int */ |
---|
[35aab3] | 309 | BOOLEAN newFile(char* fname, FILE *f=NULL); |
---|
| 310 | void newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0); |
---|
| 311 | void * myynewbuffer(); |
---|
| 312 | void myyoldbuffer(void * oldb); |
---|
| 313 | |
---|
| 314 | class Voice |
---|
| 315 | { |
---|
| 316 | public: |
---|
| 317 | Voice * next; |
---|
| 318 | Voice * prev; |
---|
| 319 | char * filename; // file name or proc name |
---|
| 320 | procinfo * pi; // proc info |
---|
| 321 | void * oldb; // internal scanner buffer |
---|
| 322 | // for files only: |
---|
| 323 | FILE * files; // file handle |
---|
| 324 | // for buffers only: |
---|
| 325 | char * buffer; // buffer pointer |
---|
| 326 | long fptr; // current position in buffer |
---|
| 327 | |
---|
| 328 | int start_lineno; // lineno, to restore in recursion |
---|
| 329 | int curr_lineno; // current lineno |
---|
| 330 | feBufferInputs sw; // BI_stdin: read from STDIN |
---|
| 331 | // BI_buffer: buffer |
---|
| 332 | // BI_file: files |
---|
| 333 | char ifsw; // if-switch: |
---|
| 334 | /*1 ifsw==0: no if statement, else is invalid |
---|
| 335 | * ==1: if (0) processed, execute else |
---|
| 336 | * ==2: if (1) processed, else allowed but not executed |
---|
| 337 | */ |
---|
| 338 | feBufferTypes typ; // buffer type: see BT_.. |
---|
| 339 | |
---|
| 340 | Voice() { memset(this,0,sizeof(*this));} |
---|
| 341 | feBufferTypes Typ(); |
---|
| 342 | void Next(); |
---|
| 343 | } ; |
---|
| 344 | |
---|
| 345 | extern Voice *currentVoice; |
---|
| 346 | |
---|
| 347 | Voice * feInitStdin(Voice *pp); |
---|
| 348 | |
---|
| 349 | /* feread.cc: */ |
---|
| 350 | |
---|
| 351 | /* the interface for reading: */ |
---|
[88d631] | 352 | extern char * (*fe_fgets_stdin)(const char *pr,char *s, int size); |
---|
[35aab3] | 353 | |
---|
| 354 | #ifdef HAVE_DYN_RL |
---|
[88d631] | 355 | char * fe_fgets_stdin_drl(const char *pr,char *s, int size); |
---|
[35aab3] | 356 | #endif |
---|
| 357 | |
---|
| 358 | extern "C" void fe_reset_input_mode(); |
---|
| 359 | |
---|
| 360 | extern "C" { |
---|
| 361 | #ifndef HAVE_ATEXIT |
---|
| 362 | void fe_reset_fe (int i, void *v); |
---|
| 363 | #else |
---|
| 364 | void fe_reset_fe (void); |
---|
| 365 | #endif |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | |
---|
| 369 | /* possible implementations: */ |
---|
| 370 | #ifdef __cplusplus |
---|
| 371 | extern "C" |
---|
| 372 | { |
---|
| 373 | #endif |
---|
| 374 | /* readline, linked in: */ |
---|
[88d631] | 375 | char * fe_fgets_stdin_rl(const char *pr,char *s, int size); |
---|
[35aab3] | 376 | |
---|
| 377 | /* emulated readline: */ |
---|
[88d631] | 378 | char * fe_fgets_stdin_emu(const char *pr,char *s, int size); |
---|
[35aab3] | 379 | |
---|
| 380 | /* fgets: */ |
---|
[88d631] | 381 | char * fe_fgets(const char *pr,char *s, int size); |
---|
[35aab3] | 382 | |
---|
| 383 | #ifdef HAVE_TCL |
---|
| 384 | /* tcl: */ |
---|
[88d631] | 385 | char * fe_fgets_tcl(const char *pr,char *s, int size); |
---|
[35aab3] | 386 | #endif |
---|
| 387 | |
---|
| 388 | /* dummy (for batch mode): */ |
---|
[88d631] | 389 | char * fe_fgets_dummy(const char *pr,char *s, int size); |
---|
[35aab3] | 390 | |
---|
| 391 | #ifdef __cplusplus |
---|
| 392 | } |
---|
| 393 | #endif |
---|
| 394 | #endif /* c++ only */ |
---|
| 395 | |
---|
| 396 | /* everything in between calls to these procedures is printed into a string |
---|
| 397 | * which is returned by SprintEnd() |
---|
| 398 | */ |
---|
| 399 | void SPrintStart(); |
---|
| 400 | char* SPrintEnd(); |
---|
| 401 | |
---|
| 402 | |
---|
| 403 | #endif /* ifndef FEBASE_H */ |
---|