[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> |
---|
[599326] | 12 | #include <kernel/structs.h> |
---|
[35aab3] | 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 | |
---|
[b1dfaf] | 30 | #include <omalloc/mylimits.h> |
---|
[35aab3] | 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; |
---|
[3922503] | 99 | extern int colmax; |
---|
[35aab3] | 100 | extern int yy_blocklineno; |
---|
| 101 | extern int yy_noeof; |
---|
| 102 | extern char prompt_char; |
---|
| 103 | extern const char feNotImplemented[]; |
---|
| 104 | extern BOOLEAN errorreported; |
---|
[4840ebb] | 105 | extern int feProt; |
---|
[35aab3] | 106 | extern BOOLEAN feWarn; |
---|
| 107 | extern BOOLEAN feOut; |
---|
[460c65f] | 108 | extern int traceit ; |
---|
| 109 | #define TRACE_SHOW_PROC 1 |
---|
| 110 | #define TRACE_SHOW_LINENO 2 |
---|
| 111 | #define TRACE_SHOW_LINE 4 |
---|
| 112 | #define TRACE_SHOW_RINGS 8 |
---|
| 113 | #define TRACE_SHOW_LINE1 16 |
---|
| 114 | #define TRACE_BREAKPOINT 32 |
---|
| 115 | #define TRACE_TMP_BREAKPOINT 64 |
---|
[835d83] | 116 | extern int myynest; |
---|
| 117 | extern int yylineno; |
---|
| 118 | extern char my_yylinebuf[80]; |
---|
[35aab3] | 119 | |
---|
| 120 | #define PROT_NONE 0 |
---|
| 121 | #define PROT_I 1 |
---|
| 122 | #define PROT_O 2 |
---|
| 123 | #define PROT_IO 3 |
---|
| 124 | |
---|
| 125 | /* the C-part: */ |
---|
| 126 | #define mflush() fflush(stdout) |
---|
| 127 | |
---|
| 128 | #ifdef __cplusplus |
---|
| 129 | extern "C" { |
---|
| 130 | #endif |
---|
| 131 | |
---|
[5046ce] | 132 | |
---|
| 133 | extern void (*WerrorS_callback)(const char *s); |
---|
| 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(); |
---|
[a9d8e7] | 143 | void PrintS(const char* s); |
---|
[35aab3] | 144 | char* feGetResource(const char id); |
---|
| 145 | |
---|
| 146 | #ifdef HAVE_FEREAD |
---|
| 147 | extern BOOLEAN fe_is_raw_tty; |
---|
| 148 | void fe_temp_reset (void); |
---|
| 149 | #endif |
---|
| 150 | |
---|
| 151 | #ifdef __cplusplus |
---|
| 152 | } |
---|
| 153 | /* the C++-part: */ |
---|
| 154 | |
---|
[460c65f] | 155 | typedef enum { LANG_NONE, LANG_TOP, LANG_SINGULAR, LANG_C, LANG_MAX} language_defs; |
---|
| 156 | // LANG_TOP : Toplevel package only |
---|
| 157 | // LANG_SINGULAR: |
---|
| 158 | // LANG_C : |
---|
| 159 | // |
---|
| 160 | |
---|
| 161 | class proc_singular |
---|
| 162 | { |
---|
| 163 | public: |
---|
| 164 | long proc_start; // position where proc is starting |
---|
| 165 | long def_end; // position where proc header is ending |
---|
| 166 | long help_start; // position where help is starting |
---|
| 167 | long help_end; // position where help is starting |
---|
| 168 | long body_start; // position where proc-body is starting |
---|
| 169 | long body_end; // position where proc-body is ending |
---|
| 170 | long example_start; // position where example is starting |
---|
| 171 | long proc_end; // position where proc is ending |
---|
| 172 | int proc_lineno; |
---|
| 173 | int body_lineno; |
---|
| 174 | int example_lineno; |
---|
| 175 | char *body; |
---|
| 176 | long help_chksum; |
---|
| 177 | }; |
---|
| 178 | |
---|
| 179 | struct proc_object |
---|
| 180 | { |
---|
| 181 | //public: |
---|
| 182 | BOOLEAN (*function)(leftv res, leftv v); |
---|
| 183 | }; |
---|
| 184 | union uprocinfodata |
---|
| 185 | { |
---|
| 186 | public: |
---|
| 187 | proc_singular s; // data of Singular-procedure |
---|
| 188 | struct proc_object o; // pointer to binary-function |
---|
| 189 | }; |
---|
| 190 | |
---|
| 191 | typedef union uprocinfodata procinfodata; |
---|
| 192 | |
---|
| 193 | class procinfo; |
---|
| 194 | typedef procinfo * procinfov; |
---|
| 195 | |
---|
| 196 | class procinfo |
---|
| 197 | { |
---|
| 198 | public: |
---|
| 199 | char *libname; |
---|
| 200 | char *procname; |
---|
| 201 | package pack; |
---|
| 202 | language_defs language; |
---|
| 203 | short ref; |
---|
| 204 | char is_static; // if set, proc not accessible for user |
---|
| 205 | char trace_flag; |
---|
| 206 | procinfodata data; |
---|
| 207 | }; |
---|
[35aab3] | 208 | enum feBufferTypes |
---|
| 209 | { |
---|
| 210 | BT_none = 0, // entry level |
---|
| 211 | BT_break = 1, // while, for |
---|
| 212 | BT_proc, // proc |
---|
| 213 | BT_example, // example |
---|
| 214 | BT_file, // <"file" |
---|
| 215 | BT_execute, // execute |
---|
| 216 | BT_if, // if |
---|
| 217 | BT_else // else |
---|
| 218 | }; |
---|
| 219 | |
---|
| 220 | enum feBufferInputs |
---|
| 221 | { |
---|
| 222 | BI_stdin = 1, |
---|
| 223 | BI_buffer, |
---|
| 224 | BI_file |
---|
| 225 | }; |
---|
| 226 | |
---|
| 227 | /***************************************************************** |
---|
| 228 | * |
---|
| 229 | * Resource management (feResources.cc) |
---|
| 230 | * |
---|
| 231 | *****************************************************************/ |
---|
| 232 | // returns value of Resource as read-only string, or NULL |
---|
| 233 | // if Resource not found |
---|
| 234 | // issues warning, if explicitely requested (warn > 0), or |
---|
| 235 | // if warn < 0 and Resource is gotten for the first time |
---|
| 236 | // Always quiet if warn == 0 |
---|
| 237 | char* feResource(const char id, int warn = -1); |
---|
| 238 | char* feResource(const char* key, int warn = -1); |
---|
| 239 | // This needs to be called before the first call to feResource |
---|
| 240 | // Initializes Resources, SearchPath, and extends PATH |
---|
| 241 | void feInitResources(char* argv0); |
---|
| 242 | // Re-inits resources, should be called after changing env. variables |
---|
| 243 | void feReInitResources(); |
---|
| 244 | // Prints resources into string with StringAppend, etc |
---|
| 245 | void feStringAppendResources(int warn = -1); |
---|
| 246 | |
---|
| 247 | /***************************************************************** |
---|
| 248 | * |
---|
| 249 | * help system (fehelp.cc) |
---|
| 250 | * |
---|
| 251 | *****************************************************************/ |
---|
| 252 | // if str != NULL display help for str |
---|
| 253 | // display general help, otherwise |
---|
| 254 | void feHelp(char* str = NULL); |
---|
| 255 | // if browser != NULL or feOpt("browser") != NULL |
---|
| 256 | // set HelpBrowser to browser |
---|
| 257 | // otherwise, if browser was already set, leave as is, |
---|
| 258 | // if not, choose first available browser |
---|
| 259 | // return string identifying current browser |
---|
| 260 | // keeps feOpt("browser") up-to-date |
---|
| 261 | // Optional warn argument is as in feResource |
---|
[9db0567] | 262 | const char* feHelpBrowser(char* browser = NULL, int warn = -1); |
---|
[35aab3] | 263 | void feStringAppendBrowsers(int warn = -1); |
---|
| 264 | |
---|
| 265 | /***************************************************************** |
---|
| 266 | * |
---|
| 267 | * version Id |
---|
| 268 | * |
---|
| 269 | *****************************************************************/ |
---|
| 270 | /* extern unsigned long feVersionId; */ |
---|
| 271 | |
---|
| 272 | /***************************************************************** |
---|
| 273 | * |
---|
| 274 | * File Stuff |
---|
| 275 | * |
---|
| 276 | *****************************************************************/ |
---|
[85e68dd] | 277 | FILE * feFopen(const char *path, const char *mode, char *where=NULL, |
---|
| 278 | int useWerror=FALSE, int path_only=FALSE); |
---|
[35aab3] | 279 | |
---|
[a9d8e7] | 280 | char * StringAppend(const char *fmt, ...); |
---|
| 281 | char * StringAppendS(const char *s); |
---|
| 282 | char * StringSetS(const char* s); |
---|
[35aab3] | 283 | const char * VoiceName(); |
---|
| 284 | void VoiceBackTrack(); |
---|
| 285 | void Warn(const char *fmt, ...); |
---|
| 286 | BOOLEAN contBuffer(feBufferTypes typ); |
---|
[85e68dd] | 287 | const char * eati(const char *s, int *i); |
---|
[35aab3] | 288 | BOOLEAN exitBuffer(feBufferTypes typ); |
---|
| 289 | BOOLEAN exitVoice(); |
---|
[9539de6] | 290 | void monitor(void *F, int mode); /* FILE*, int */ |
---|
[35aab3] | 291 | BOOLEAN newFile(char* fname, FILE *f=NULL); |
---|
| 292 | void newBuffer(char* s, feBufferTypes t, procinfo *pname = NULL, int start_lineno = 0); |
---|
| 293 | void * myynewbuffer(); |
---|
| 294 | void myyoldbuffer(void * oldb); |
---|
| 295 | |
---|
| 296 | class Voice |
---|
| 297 | { |
---|
| 298 | public: |
---|
| 299 | Voice * next; |
---|
| 300 | Voice * prev; |
---|
| 301 | char * filename; // file name or proc name |
---|
| 302 | procinfo * pi; // proc info |
---|
| 303 | void * oldb; // internal scanner buffer |
---|
| 304 | // for files only: |
---|
| 305 | FILE * files; // file handle |
---|
| 306 | // for buffers only: |
---|
| 307 | char * buffer; // buffer pointer |
---|
| 308 | long fptr; // current position in buffer |
---|
| 309 | |
---|
| 310 | int start_lineno; // lineno, to restore in recursion |
---|
| 311 | int curr_lineno; // current lineno |
---|
| 312 | feBufferInputs sw; // BI_stdin: read from STDIN |
---|
| 313 | // BI_buffer: buffer |
---|
| 314 | // BI_file: files |
---|
| 315 | char ifsw; // if-switch: |
---|
| 316 | /*1 ifsw==0: no if statement, else is invalid |
---|
| 317 | * ==1: if (0) processed, execute else |
---|
| 318 | * ==2: if (1) processed, else allowed but not executed |
---|
| 319 | */ |
---|
| 320 | feBufferTypes typ; // buffer type: see BT_.. |
---|
| 321 | |
---|
| 322 | Voice() { memset(this,0,sizeof(*this));} |
---|
| 323 | feBufferTypes Typ(); |
---|
| 324 | void Next(); |
---|
| 325 | } ; |
---|
| 326 | |
---|
| 327 | extern Voice *currentVoice; |
---|
| 328 | |
---|
| 329 | Voice * feInitStdin(Voice *pp); |
---|
| 330 | |
---|
| 331 | /* feread.cc: */ |
---|
| 332 | |
---|
| 333 | /* the interface for reading: */ |
---|
[88d631] | 334 | extern char * (*fe_fgets_stdin)(const char *pr,char *s, int size); |
---|
[35aab3] | 335 | |
---|
| 336 | #ifdef HAVE_DYN_RL |
---|
[88d631] | 337 | char * fe_fgets_stdin_drl(const char *pr,char *s, int size); |
---|
[35aab3] | 338 | #endif |
---|
| 339 | |
---|
| 340 | extern "C" void fe_reset_input_mode(); |
---|
| 341 | |
---|
| 342 | extern "C" { |
---|
| 343 | #ifndef HAVE_ATEXIT |
---|
| 344 | void fe_reset_fe (int i, void *v); |
---|
| 345 | #else |
---|
| 346 | void fe_reset_fe (void); |
---|
| 347 | #endif |
---|
| 348 | } |
---|
| 349 | |
---|
| 350 | |
---|
| 351 | /* possible implementations: */ |
---|
| 352 | #ifdef __cplusplus |
---|
| 353 | extern "C" |
---|
| 354 | { |
---|
| 355 | #endif |
---|
| 356 | /* readline, linked in: */ |
---|
[88d631] | 357 | char * fe_fgets_stdin_rl(const char *pr,char *s, int size); |
---|
[35aab3] | 358 | |
---|
| 359 | /* emulated readline: */ |
---|
[88d631] | 360 | char * fe_fgets_stdin_emu(const char *pr,char *s, int size); |
---|
[35aab3] | 361 | |
---|
| 362 | /* fgets: */ |
---|
[88d631] | 363 | char * fe_fgets(const char *pr,char *s, int size); |
---|
[35aab3] | 364 | |
---|
| 365 | /* dummy (for batch mode): */ |
---|
[88d631] | 366 | char * fe_fgets_dummy(const char *pr,char *s, int size); |
---|
[35aab3] | 367 | |
---|
| 368 | #ifdef __cplusplus |
---|
| 369 | } |
---|
| 370 | #endif |
---|
| 371 | #endif /* c++ only */ |
---|
| 372 | |
---|
| 373 | /* everything in between calls to these procedures is printed into a string |
---|
| 374 | * which is returned by SprintEnd() |
---|
| 375 | */ |
---|
| 376 | void SPrintStart(); |
---|
| 377 | char* SPrintEnd(); |
---|
| 378 | |
---|
| 379 | |
---|
| 380 | #endif /* ifndef FEBASE_H */ |
---|