Changeset d931f8 in git
- Timestamp:
- Sep 9, 1997, 11:15:03 AM (26 years ago)
- Branches:
- (u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
- Children:
- e6da16580a6a7ea5df19aa6083e6487b4e69477f
- Parents:
- de12f8a7cc8001c77e0e08efe38b6febf34b82af
- Location:
- Singular
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/ChangeLog
rde12f8 rd931f8 1 Tue Sep 9 11:05:28 MET DST 1997 2 * hannes: flex-staff is now in febase.inc 3 changed tutorial (doc/examples.doc, version-no: doc/tutor.tex) 4 1 5 Fri Aug 15 11:44:13 MESZ 1997 Kai Krueger <krueger@mathematik.uni-kl.de> 2 6 * ndbm.cc: fix open-bug for dos -
Singular/febase.cc
rde12f8 rd931f8 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: febase.cc,v 1.2 1 1997-07-16 11:31:41Singular Exp $ */4 /* $Id: febase.cc,v 1.22 1997-09-09 09:15:02 Singular Exp $ */ 5 5 /* 6 * ABSTRACT: i/o system , handling of 'voices'6 * ABSTRACT: i/o system 7 7 */ 8 8 … … 35 35 #endif 36 36 37 class Voices38 {39 private:40 void Init()41 {42 memset(this,0,sizeof(*this));43 v_lineno = 1;44 }45 public:46 int v_lineno; // lineno, to restore in recursion47 int v_oldlineno; // lineno, to restore at exit48 int typ; // buffer type: see BT_..49 int v_echo; // echo, to restore in recursion50 int v_fileVoice; // to be restored in recursion51 int v_inputswitch; // ??52 FILE * files; // file handle53 long fptr; // file | buffer seek54 char* filename; // file name55 char * buffer; // buffer pointer56 57 void Next();58 Voices() { Init(); }59 Voices * VFile(char* fname);60 Voices * Buffer(char* buf, int t);61 int Exit();62 } ;63 64 65 extern FILE* yyin;66 67 37 #define INITIAL_PRINT_BUFFER 24*1024 68 38 static int feBufferLength=INITIAL_PRINT_BUFFER; 69 39 static char * feBuffer=(char *)Alloc(INITIAL_PRINT_BUFFER); 70 40 71 #define START_LEVMAX 3272 int levmax = START_LEVMAX;73 Voices *currentVoice = NULL;74 Voices *FileAttribs =(Voices *)Alloc0(START_LEVMAX*sizeof(Voices));75 short *ifswitch =(short *)Alloc0(START_LEVMAX*sizeof(short));76 /*1 ifswitch==0: no if statement, else is invalid77 * ==1: if (0) processed, execute else78 * ==2: if (1) processed, else allowed but not executed79 */80 41 int si_echo = 0; 81 42 int printlevel = 0; 82 int fileVoice = 0;83 43 #ifndef macintosh 84 44 int pagelength = 24; … … 87 47 #endif 88 48 int colmax = 80; 89 int voice = 0;90 int inputswitch = 0;91 int blocklineno = 0;92 49 char prompt_char = '>'; /*1 either '>' or '.'*/ 93 50 BITSET verbose = 1 … … 119 76 */ 120 77 78 #include "febase.inc" 79 121 80 /*2 122 81 * fopen, but use 'SINGULARPATH' from environment and SINGULARDATADIR … … 222 181 } 223 182 224 /*2225 * the name of the current 'voice': the procname (or filename)226 */227 const char * VoiceName()228 {229 if (FileAttribs[fileVoice].filename!=NULL)230 return FileAttribs[fileVoice].filename;231 return sNoName;232 }233 234 /*2235 * the name of the 'voice' number 'i': the procname (or filename)236 */237 const char * VoiceName(int i)238 {239 if (FileAttribs[i].filename!=NULL)240 return FileAttribs[i].filename;241 return sNoName;242 }243 244 /*2245 * the type of the current voice:BT_proc, BT_example, BT_file246 */247 int VoiceType()248 {249 int i=fileVoice;250 while ((FileAttribs[i].typ!=BT_proc)251 &&(FileAttribs[i].typ!=BT_example)252 &&(FileAttribs[i].typ!=BT_file)253 &&(i>0))254 i--;255 return FileAttribs[i].typ;256 }257 /*2258 * start the file 'fname' (STDIN is stdin) in the current voice (cf.newVoice)259 */260 Voices * Voices::VFile(char* fname)261 {262 if (strcmp(fname,"STDIN") == 0)263 {264 yyin = stdin;265 v_inputswitch = 0;266 }267 else268 {269 yyin = feFopen(fname,"r",NULL,TRUE);270 v_inputswitch = -1;271 }272 files = yyin;273 filename = mstrdup(fname);274 v_echo = si_echo;275 fileVoice = voice;276 yylineno = 1;277 if (files==NULL)278 {279 inputswitch = 0;280 exitVoice();281 return NULL;282 }283 inputswitch= v_inputswitch;284 return this;285 }286 287 /*3288 * increment voice counter, allocate new memory289 */290 static inline void inc_voice()291 {292 voice++;293 if (voice >= levmax)294 {295 FileAttribs=(Voices *)ReAlloc(FileAttribs,296 levmax*sizeof(Voices),297 (levmax+16)*sizeof(Voices));298 memset(&FileAttribs[levmax],0,16*sizeof(Voices));299 ifswitch=(short *)ReAlloc(ifswitch,300 levmax*sizeof(short),301 (levmax+16)*sizeof(short));302 memset(&ifswitch[levmax],0,16*sizeof(short));303 levmax+=16;304 }305 }306 307 /*2308 * init a new voice similiar to the current309 */310 void Voices::Next()311 {312 v_oldlineno = yylineno;313 v_echo = si_echo;314 v_fileVoice = fileVoice;315 inc_voice();316 317 currentVoice = &FileAttribs[voice];318 currentVoice->Init();319 }320 321 /*2322 * start the file 'fname' (STDIN is stdin) as a new voice (cf.VFile)323 */324 int newVoice(char* s)325 {326 currentVoice->Next();327 return (int)currentVoice->VFile((char *)s);328 }329 330 void newBuffer(char* s, int t, char* pname)331 {332 currentVoice->Next();333 currentVoice->Buffer(s,t);334 if (pname) currentVoice->filename = mstrdup(pname);335 //printf("start buffer %d typ %d\n",voice,t);336 }337 338 Voices * Voices::Buffer(char* buf, int t)339 {340 inputswitch = v_inputswitch = t;341 buffer = buf;342 typ = t;343 //si_echo = 0;344 switch (t)345 {346 case BT_example:347 case BT_proc: v_lineno = yylineno; ::yylineno = 3; break;348 case BT_file: v_lineno = yylineno; ::yylineno = 1; break;349 case BT_if:350 case BT_else: ::yylineno = v_lineno = blocklineno - 1; break;351 case BT_break: ::yylineno = v_lineno = blocklineno - 2; break;352 }353 return this;354 }355 356 /*2357 * after leaving a voice:358 * setup everything from the this level359 */360 int Voices::Exit()361 {362 if (voice >= 0)363 {364 si_echo = v_echo;365 fileVoice = v_fileVoice;366 yyin = files;367 yylineno = v_oldlineno;368 inputswitch = v_inputswitch;369 return 0;370 }371 //Print("Exit:%d\n",voice);372 return 1;373 }374 375 /*2376 * exit Buffer of type 'typ':377 * returns 1 if buffer type could not be found378 */379 int exitBuffer(int typ)380 {381 //printf("exitBuffer: %d\n",typ);382 if (typ == BT_break) // valid inside for, while. may skip if, else383 {384 /*4 first check for valid buffer type, skip if/else*/385 for (int i=voice; i>0; i--)386 {387 if ((FileAttribs[i].typ == BT_if)388 ||(FileAttribs[i].typ == BT_else)) continue;389 if (FileAttribs[i].typ == BT_break /*typ*/)390 {391 while ((/*typ*/ BT_break != currentVoice->typ)392 && (voice > 0))393 {394 exitVoice();395 }396 return exitVoice();397 }398 else return 1;399 }400 /*4 break not inside a for/while: return an error*/401 if (/*typ*/ BT_break != currentVoice->typ) return 1;402 return exitVoice();403 }404 405 if ((typ == BT_proc)406 || (typ == BT_example))407 {408 for (int i=voice; i>0; i--)409 {410 if (FileAttribs[i].typ == 0) break;411 if ((FileAttribs[i].typ == BT_proc)412 || (FileAttribs[i].typ == BT_example))413 {414 while ((BT_proc != currentVoice->typ)415 && (BT_example != currentVoice->typ)416 && (voice > 0))417 {418 exitVoice();419 }420 return exitVoice();421 }422 }423 }424 /*4 return not inside a proc: return an error*/425 return 1;426 }427 428 /*2429 * jump to the beginning of a buffer430 */431 int contBuffer(int typ)432 {433 if (typ == BT_break) // valid inside for, while. may skip if, else434 {435 // first check for valid buffer type436 for (int i=voice; i>0; i--)437 {438 if ((FileAttribs[i].typ == BT_if)439 ||(FileAttribs[i].typ == BT_else)) continue;440 if (FileAttribs[i].typ == BT_break /*typ*/)441 {442 while (/*typ*/ BT_break != currentVoice->typ && (voice > i))443 {444 exitVoice();445 }446 currentVoice->fptr = 0L;447 yylineno = currentVoice->v_lineno;448 return 0;449 }450 else return 1;451 }452 }453 return 1;454 }455 456 /*2457 * leave a voice: kill local variables458 * setup everything from the previous level (via Exit)459 */460 int exitVoice()461 {462 if (voice <= 0)463 {464 if (feBatch) return 1;465 else m2_end(0);466 }467 //printf("exitVoice %d, typ %d\n",voice,FileAttribs[voice].typ);468 if (FileAttribs[voice].typ==BT_if)469 {470 ifswitch[voice-1]=2;471 }472 else473 {474 ifswitch[voice-1]=0;475 //if ((FileAttribs[voice].typ==BT_proc)476 //||(FileAttribs[voice].typ==BT_example)477 //||(FileAttribs[voice].typ==0))478 //{479 // killlocals(myynest);480 // printf("killlocals %d\n",myynest);481 //}482 }483 if (inputswitch == -1)484 {485 fclose(yyin);486 }487 else if (inputswitch > 0)488 {489 if (FileAttribs[voice].filename!=NULL)490 {491 FreeL((ADDRESS)FileAttribs[voice].filename);492 FileAttribs[voice].filename=NULL;493 }494 if (FileAttribs[voice].buffer!=NULL)495 {496 FreeL((ADDRESS)FileAttribs[voice].buffer);497 FileAttribs[voice].buffer=NULL;498 }499 }500 currentVoice = &FileAttribs[--voice];501 return currentVoice->Exit();502 }503 504 int readbuf(char* buf, int l)505 {506 char *s;507 char * t = buf;508 int i = 0;509 long fl = currentVoice->fptr;510 if (fl == -1L)511 {512 t[0] = '\0';513 exitVoice();514 return 0;515 }516 517 s = currentVoice->buffer + fl;518 while (l > 0)519 {520 fl++;521 i++;522 l--;523 *t++ = *s;524 if (*s == '\n')525 {526 *t = '\0';527 if ((si_echo > voice) || (inputswitch == 0) || (traceit&TRACE_SHOW_LINE)528 || (traceit&TRACE_SHOW_LINE1))529 {530 if (currentVoice->filename==NULL)531 Print("(none) %3d%c ",yylineno,prompt_char);532 else if (VoiceType()!=BT_example)533 Print("%s %3d%c ",currentVoice->filename,yylineno,prompt_char);534 prompt_char = '.';535 }536 if (*(s+1) == '\0')537 {538 currentVoice->fptr = -1;539 FreeL((ADDRESS)(currentVoice->buffer));540 currentVoice->buffer=NULL;541 FileAttribs[voice].buffer = NULL;542 exitVoice();543 }544 else545 currentVoice->fptr = fl;546 return i;547 }548 else if (*s == '\0')549 {550 if ((si_echo > voice) || (inputswitch == 0) || (traceit&TRACE_SHOW_LINE)551 || (traceit&TRACE_SHOW_LINE1))552 {553 if (currentVoice->filename==NULL)554 Print("(none) %3d%c ",yylineno,prompt_char);555 else556 Print("%s %3d%c ",currentVoice->filename,yylineno,prompt_char);557 prompt_char = '.';558 }559 currentVoice->fptr = -1;560 FreeL((ADDRESS)(currentVoice->buffer));561 currentVoice->buffer = NULL;562 exitVoice();563 return i-1;564 }565 s++;566 }567 currentVoice->fptr = fl;568 return i;569 }570 571 /*2572 * init all data structures573 */574 void I_FEbase(void)575 {576 currentVoice = FileAttribs[0].VFile("STDIN");577 }578 579 183 static char * feBufferStart; 580 184 /* only used in StringSet(S)/StringAppend(S)*/
Note: See TracChangeset
for help on using the changeset viewer.