Changeset 88ece17 in git
- Timestamp:
- Aug 4, 2011, 2:55:24 PM (12 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'f875bbaccd0831e36aaed09ff6adeb3eb45aeb94')
- Children:
- 6d9d85c1fd472850e2c09503b3ffc7317679da3d
- Parents:
- 6b71e2e0fbb9b8414f3974f377296c7d9c8e6a88
- git-author:
- Hans Schoenemann <hannes@mathematik.uni-kl.de>2011-08-04 14:55:24+02:00
- git-committer:
- Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 13:14:26+01:00
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/grammar.cc
r6b71e2 r88ece17 407 407 extern FILE* yyin; 408 408 409 char my_yylinebuf[80];410 409 const char * currid; 411 410 BOOLEAN yyInRingConstruction=FALSE; -
Singular/grammar.y
r6b71e2 r88ece17 103 103 extern FILE* yyin; 104 104 105 char my_yylinebuf[80];106 105 const char * currid; 107 106 BOOLEAN yyInRingConstruction=FALSE; -
Singular/ipshell.cc
r6b71e2 r88ece17 62 62 leftv iiCurrArgs=NULL; 63 63 idhdl iiCurrProc=NULL; 64 int traceit = 0;65 64 const char *lastreserved=NULL; 66 67 int myynest = -1;68 65 69 66 static BOOLEAN iiNoKeepRing=TRUE; -
Singular/ipshell.h
r6b71e2 r88ece17 207 207 void checkall(); 208 208 #endif 209 #endif 210 209 void rSetHdl(idhdl h); 210 211 #endif 212 -
Singular/makefile
r6b71e2 r88ece17 78 78 feOpt.cc\ 79 79 fehelp.cc\ 80 fevoices.cc \ 80 81 fglm.cc\ 81 82 gentable.cc\ -
Singular/scanner.cc
r6b71e2 r88ece17 571 571 int feReadLine(char* b, int l); 572 572 #define ALLOC(a) omAlloc((a)) 573 int yylineno = 0;574 573 int blocknest = 0; 575 574 extern char * yytext; -
Singular/scanner.l
r6b71e2 r88ece17 19 19 #define ALLOC(a) omAlloc((a)) 20 20 #ifndef NEW_FLEX 21 int yylineno = 0;22 21 #endif /* NEW_LEX */ 23 22 int blocknest = 0; -
Singular/ssiLink.cc
r6b71e2 r88ece17 49 49 #endif 50 50 51 struct snumber_dummy 52 { 53 mpz_t z; 54 mpz_t n; 55 #if defined(LDEBUG) 56 int debug; 57 #endif 58 BOOLEAN s; 59 }; 60 typedef struct snumber_dummy *number_dummy; 61 51 62 //#if (_POSIX_C_SOURCE >= 200112L) || (_XOPEN_SOURCE >= 600) 52 63 //#define HAVE_PSELECT … … 74 85 #define SSI_BLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_sigmask, &ssi_oldmask) 75 86 #define SSI_UNBLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_oldmask, NULL) 87 88 #define SR_INT 1L 89 #define SR_HDL(A) ((long)(A)) 90 #define SR_TO_INT(SR) (((long)SR) >> 2) 76 91 77 92 // the helper functions: … … 115 130 // or 3 3 <mpz_t nominator> 116 131 SSI_BLOCK_CHLD; 117 if( SR_HDL(n) & SR_INT)132 if((long)(n) & SR_INT) 118 133 { 119 134 fprintf(d->f_write,"4 %ld ",SR_TO_INT(n)); 120 135 //if (d->f_debug!=NULL) fprintf(d->f_debug,"bigint: short \"%ld\" ",SR_TO_INT(n)); 121 136 } 122 else if ( n->s==3)137 else if (((number_dummy)n)->s==3) 123 138 { 124 139 fputs("3 ",d->f_write); 125 mpz_out_str(d->f_write,10, n->z);140 mpz_out_str(d->f_write,10,((number_dummy)n)->z); 126 141 fputc(' ',d->f_write); 127 142 //gmp_fprintf(d->f_write,"3 %Zd ",n->z); … … 156 171 //if (d->f_debug!=NULL) fprintf(d->f_debug,"number: short \"%ld\" ",SR_TO_INT(n)); 157 172 } 158 else if ( n->s<2)173 else if (((number_dummy)n)->s<2) 159 174 { 160 175 //gmp_fprintf(d->f_write,"%d %Zd %Zd ",n->s,n->z,n->n); 161 fprintf(d->f_write,"%d ", n->s+5);162 mpz_out_str (d->f_write,32, n->z);176 fprintf(d->f_write,"%d ",((number_dummy)n)->s+5); 177 mpz_out_str (d->f_write,32, ((number_dummy)n)->z); 163 178 fputc(' ',d->f_write); 164 mpz_out_str (d->f_write,32, n->n);179 mpz_out_str (d->f_write,32, ((number_dummy)n)->n); 165 180 fputc(' ',d->f_write); 166 181 … … 171 186 //gmp_fprintf(d->f_write,"3 %Zd ",n->z); 172 187 fputs("8 ",d->f_write); 173 mpz_out_str (d->f_write,32, n->z);188 mpz_out_str (d->f_write,32, ((number_dummy)n)->z); 174 189 fputc(' ',d->f_write); 175 190 … … 334 349 number n=nlRInit(0); 335 350 SSI_BLOCK_CHLD; 336 mpz_inp_str( n->z,d->f_read,0);351 mpz_inp_str(((number_dummy)n)->z,d->f_read,0); 337 352 SSI_UNBLOCK_CHLD; 338 n->s=sub_type;353 ((number_dummy)n)->s=sub_type; 339 354 return n; 340 355 } … … 367 382 {// read mpz_t, mpz_t 368 383 number n=nlRInit(0); 369 mpz_init( n->n);384 mpz_init(((number_dummy)n)->n); 370 385 SSI_BLOCK_CHLD; 371 gmp_fscanf(d->f_read,"%Zd %Zd", n->z,n->n);386 gmp_fscanf(d->f_read,"%Zd %Zd",((number_dummy)n)->z,((number_dummy)n)->n); 372 387 SSI_UNBLOCK_CHLD; 373 n->s=sub_type;388 ((number_dummy)n)->s=sub_type; 374 389 return n; 375 390 } … … 379 394 number n=nlRInit(0); 380 395 SSI_BLOCK_CHLD; 381 gmp_fscanf(d->f_read,"%Zd", n->z);396 gmp_fscanf(d->f_read,"%Zd",((number_dummy)n)->z); 382 397 SSI_UNBLOCK_CHLD; 383 n->s=3; /*sub_type*/398 ((number_dummy)n)->s=3; /*sub_type*/ 384 399 return n; 385 400 } … … 396 411 {// read raw mpz_t, mpz_t 397 412 number n=nlRInit(0); 398 mpz_init( n->n);413 mpz_init(((number_dummy)n)->n); 399 414 SSI_BLOCK_CHLD; 400 mpz_inp_str ( n->z, d->f_read, 32);401 mpz_inp_str ( n->n, d->f_read, 32);415 mpz_inp_str (((number_dummy)n)->z, d->f_read, 32); 416 mpz_inp_str (((number_dummy)n)->n, d->f_read, 32); 402 417 SSI_UNBLOCK_CHLD; 403 n->s=sub_type-5;418 ((number_dummy)n)->s=sub_type-5; 404 419 return n; 405 420 } … … 408 423 number n=nlRInit(0); 409 424 SSI_BLOCK_CHLD; 410 mpz_inp_str ( n->z, d->f_read, 32);425 mpz_inp_str (((number_dummy)n)->z, d->f_read, 32); 411 426 SSI_UNBLOCK_CHLD; 412 n->s=sub_type=3; /*subtype-5*/427 ((number_dummy)n)->s=sub_type=3; /*subtype-5*/ 413 428 return n; 414 429 } -
kernel/febase.cc
r6b71e2 r88ece17 35 35 36 36 // output/print buffer: 37 #define INITIAL_PRINT_BUFFER 24*1024L38 37 // line buffer for reading: 39 38 // minimal value for MAX_FILE_BUFFER: 4*4096 - see Tst/Long/gcd0_l.tst 40 39 // this is an upper limit for the size of monomials/numbers read via the interpreter 41 40 #define MAX_FILE_BUFFER 4*4096 42 static long feBufferLength=INITIAL_PRINT_BUFFER;43 static char * feBuffer=(char *)omAlloc(INITIAL_PRINT_BUFFER);44 41 45 42 int si_echo = 0; … … 47 44 int colmax = 80; 48 45 char prompt_char = '>'; /*1 either '>' or '.'*/ 49 extern "C" { 50 BITSET test=(BITSET)0; 51 BITSET verbose = Sy_bit(V_QUIET) 52 //| Sy_bit(V_QRING) // not default, as speed drops by 10 % 53 | Sy_bit(V_REDEFINE) 54 | Sy_bit(V_LOAD_LIB) 55 | Sy_bit(V_SHOW_USE) 56 | Sy_bit(V_PROMPT) 57 /* | Sy_bit(V_DEBUG_MEM) */ 58 ;} 59 BOOLEAN errorreported = FALSE; 60 char * feErrors=NULL; 61 int feErrorsLen=0; 62 BOOLEAN feWarn = TRUE; 63 BOOLEAN feOut = TRUE; 46 int yylineno = 0; 47 int myynest = -1; 48 int traceit = 0; 49 char my_yylinebuf[80]; 64 50 65 const char feNotImplemented[]="not implemented";66 67 void (*WerrorS_callback)(const char *s) = NULL;68 69 int feProt = FALSE;70 FILE* feProtFile;71 72 73 /**************************************************************************74 * handling of 'voices'75 **************************************************************************/76 77 extern int blocknest; /* scaner.l internal */78 79 int yy_noeof=0; // the scanner "state"80 int yy_blocklineno; // to get the lineno of the block start from scanner81 Voice *currentVoice = NULL;82 FILE *feFilePending; /*temp. storage for grammar.y */83 84 //static const char * BT_name[]={"BT_none","BT_break","BT_proc","BT_example",85 // "BT_file","BT_execute","BT_if","BT_else"};86 /*287 * the name of the current 'Voice': the procname (or filename)88 */89 const char * sNoName_fe="_";90 const char * VoiceName()91 {92 if ((currentVoice!=NULL)93 && (currentVoice->filename!=NULL))94 return currentVoice->filename;95 return sNoName_fe;96 }97 98 /*299 * the calling chain of Voices100 */101 void VoiceBackTrack()102 {103 Voice *p=currentVoice;104 while (p->prev!=NULL)105 {106 p=p->prev;107 char *s=p->filename;108 if (s==NULL)109 PrintS("-- called from ? --\n");110 else111 Print("-- called from %s --\n",s);112 }113 }114 115 /*2116 * init a new voice similiar to the current117 */118 void Voice::Next()119 {120 Voice *p=new Voice;121 // OB: ???122 // Hmm... when Singular is used as batch file123 // then this voice is never freed124 omMarkAsStaticAddr(p);125 if (currentVoice != NULL)126 {127 currentVoice->curr_lineno=yylineno;128 currentVoice->next=p;129 }130 p->prev=currentVoice;131 currentVoice=p;132 //Print("Next:");133 }134 135 feBufferTypes Voice::Typ()136 {137 switch(typ)138 {139 case BT_proc:140 case BT_example:141 case BT_file:142 return typ;143 default:144 if (prev==NULL) return (feBufferTypes)0;145 return prev->Typ();146 }147 }148 149 /*2150 * start the file 'fname' (STDIN is stdin) as a new voice (cf.VFile)151 * return FALSE on success, TRUE if an error occurs (file cannot be opened)152 */153 BOOLEAN newFile(char *fname,FILE* f)154 {155 currentVoice->Next();156 //Print(":File%d(%s):%s(%x)\n",157 // currentVoice->typ,BT_name[currentVoice->typ],fname,currentVoice);158 currentVoice->filename = omStrDup(fname);159 omMarkAsStaticAddr(currentVoice->filename);160 if (strcmp(fname,"STDIN") == 0)161 {162 currentVoice->files = stdin;163 currentVoice->sw = BI_stdin;164 currentVoice->start_lineno = 1;165 }166 else167 {168 currentVoice->sw = BI_file; /* needed by exitVoice below */169 if (f!=NULL)170 currentVoice->files = f;171 else172 {173 currentVoice->files = feFopen(fname,"r",NULL,TRUE);174 if (currentVoice->files==NULL)175 {176 exitVoice();177 return TRUE;178 }179 }180 currentVoice->start_lineno = 0;181 }182 yylineno=currentVoice->start_lineno;183 //Voice *p=currentVoice;184 //Print("-----------------\ncurr:");185 //do186 //{187 //Print("voice fn:%s\n",p->filename);188 //p=p->prev;189 //}190 //while (p!=NULL);191 //Print("----------------\n");192 return FALSE;193 }194 195 void newBuffer(char* s, feBufferTypes t, procinfo* pi, int lineno)196 {197 currentVoice->Next();198 //Print(":Buffer%d(%s):%s(%x)\n",199 // t,BT_name[t],pname,currentVoice);200 if (pi!=NULL)201 {202 long l=strlen(pi->procname);203 if (pi->libname!=NULL) l+=strlen(pi->libname);204 currentVoice->filename = (char *)omAlloc(l+3);205 *currentVoice->filename='\0';206 if (pi->libname!=NULL) strcat(currentVoice->filename,pi->libname);207 strcat(currentVoice->filename,"::");208 strcat(currentVoice->filename,pi->procname);209 currentVoice->pi = pi;210 }211 else212 {213 currentVoice->filename = omStrDup(currentVoice->prev->filename);214 currentVoice->pi = currentVoice->prev->pi;215 }216 currentVoice->buffer = s;217 currentVoice->sw = BI_buffer;218 currentVoice->typ = t;219 switch (t)220 {221 case BT_execute:222 yylineno-=2;223 break;224 case BT_proc:225 case BT_example:226 currentVoice->oldb=myynewbuffer();227 yylineno = lineno+1;228 break;229 case BT_if:230 case BT_else:231 case BT_break:232 yylineno = yy_blocklineno-1;233 break;234 //case BT_file:235 default:236 yylineno = 1;237 break;238 }239 //Print("start body (%s) at line %d\n",BT_name[t],yylineno);240 currentVoice->start_lineno = yylineno;241 //printf("start buffer typ %d\n",t);242 //Voice *p=currentVoice;243 //Print("-----------------\ncurr:");244 //do245 //{246 //Print("voice fn:%s\n",p->filename);247 //p=p->prev;248 //}249 //while (p!=NULL);250 //Print("----------------\n");251 }252 253 /*2254 * exit Buffer of type 'typ':255 * returns 1 if buffer type could not be found256 */257 BOOLEAN exitBuffer(feBufferTypes typ)258 {259 //printf("exitBuffer: %d(%s),(%x)\n",260 // typ,BT_name[typ], currentVoice);261 //Voice *p=currentVoice;262 //Print("-----------------\ncurr:");263 //do264 //{265 //Print("voice fn:%s\n",p->filename);266 //p=p->prev;267 //}268 //while (p!=NULL);269 //Print("----------------\n");270 if (typ == BT_break) // valid inside for, while. may skip if, else271 {272 /*4 first check for valid buffer type, skip if/else*/273 Voice *p=currentVoice;274 loop275 {276 if ((p->typ != BT_if)277 &&(p->typ != BT_else))278 {279 if (p->typ == BT_break /*typ*/)280 {281 while (p != currentVoice)282 {283 exitVoice();284 }285 exitVoice();286 return FALSE;287 }288 else return TRUE;289 }290 if (p->prev==NULL) break;291 p=p->prev;292 }293 /*4 break not inside a for/while: return an error*/294 if (/*typ*/ BT_break != currentVoice->typ) return 1;295 return exitVoice();296 }297 298 if ((typ == BT_proc)299 || (typ == BT_example))300 {301 Voice *p=currentVoice;302 loop303 {304 if ((p->typ == BT_proc)305 || (p->typ == BT_example))306 {307 while (p != currentVoice)308 {309 exitVoice();310 }311 exitVoice();312 return FALSE;313 }314 if (p->prev==NULL) break;315 p=p->prev;316 }317 }318 /*4 return not inside a proc: return an error*/319 return TRUE;320 }321 322 /*2323 * jump to the beginning of a buffer324 */325 BOOLEAN contBuffer(feBufferTypes typ)326 {327 //printf("contBuffer: %d(%s),(%x)\n",328 // typ,BT_name[typ], currentVoice);329 if (typ == BT_break) // valid inside for, while. may skip if, else330 {331 // first check for valid buffer type332 Voice *p=currentVoice;333 loop334 {335 if ((p->typ != BT_if)336 &&(p->typ != BT_else))337 {338 if (p->typ == BT_break /*typ*/)339 {340 while (p != currentVoice)341 {342 exitVoice();343 }344 yylineno = currentVoice->start_lineno;345 currentVoice->fptr=0;346 return FALSE;347 }348 else return TRUE;349 }350 if (p->prev==NULL) break;351 p=p->prev;352 }353 }354 return TRUE;355 }356 357 /*2358 * leave a voice: kill local variables359 * setup everything from the previous level360 * return 1 if leaving the top level, 0 otherwise361 */362 BOOLEAN exitVoice()363 {364 //printf("exitVoice: %d(%s),(%x)\n",365 // currentVoice->typ,BT_name[currentVoice->typ], currentVoice);366 //{367 //Voice *p=currentVoice;368 //Print("-----------------\ncurr:");369 //do370 //{371 //Print("voice fn:%s\n",p->filename);372 //p=p->prev;373 //}374 //while (p!=NULL);375 //Print("----------------\n");376 //}377 if (currentVoice!=NULL)378 {379 if (currentVoice->oldb!=NULL)380 {381 myyoldbuffer(currentVoice->oldb);382 currentVoice->oldb=NULL;383 }384 if ((currentVoice->prev==NULL)&&(currentVoice->sw==BI_file))385 {386 currentVoice->prev=feInitStdin(currentVoice);387 }388 if (currentVoice->prev!=NULL)389 {390 //printf("exitVoice typ %d(%s)\n",391 // currentVoice->typ,BT_name[currentVoice->typ]);392 if (currentVoice->typ==BT_if)393 {394 currentVoice->prev->ifsw=2;395 }396 else397 {398 currentVoice->prev->ifsw=0;399 }400 if ((currentVoice->sw == BI_file)401 && (currentVoice->files!=NULL))402 {403 fclose(currentVoice->files);404 }405 if (currentVoice->filename!=NULL)406 {407 omFree((ADDRESS)currentVoice->filename);408 currentVoice->filename=NULL;409 }410 if (currentVoice->buffer!=NULL)411 {412 omFree((ADDRESS)currentVoice->buffer);413 currentVoice->buffer=NULL;414 }415 yylineno=currentVoice->prev->curr_lineno;416 currentVoice->prev->next=NULL;417 }418 Voice *p=currentVoice->prev;419 delete currentVoice;420 currentVoice=p;421 }422 return currentVoice==NULL;423 }424 425 /*2426 * set prompt_char427 * only called with currentVoice->sw == BI_stdin428 */429 static void feShowPrompt(void)430 {431 fe_promptstr[0]=prompt_char;432 }433 434 /*2435 * print echo (si_echo or TRACE), set my_yylinebuf436 */437 static int fePrintEcho(char *anf, char *b)438 {439 char *ss=strrchr(anf,'\n');440 int len_s;441 if (ss==NULL)442 {443 len_s=strlen(anf);444 }445 else446 {447 len_s=ss-anf+1;448 }449 // my_yylinebuf:450 int mrc=si_min(len_s,79)-1;451 strcpy(my_yylinebuf,anf+(len_s-1)-mrc);452 if (my_yylinebuf[mrc] == '\n') my_yylinebuf[mrc] = '\0';453 mrc--;454 // handle echo:455 if (((si_echo>myynest)456 && ((currentVoice->typ==BT_proc)457 || (currentVoice->typ==BT_example)458 || (currentVoice->typ==BT_file)459 || (currentVoice->typ==BT_none)460 )461 && (strncmp(anf,";return();",10)!=0)462 )463 || (traceit&TRACE_SHOW_LINE)464 || (traceit&TRACE_SHOW_LINE1))465 {466 if (currentVoice->typ!=BT_example)467 {468 if (currentVoice->filename==NULL)469 Print("(none) %3d%c ",yylineno,prompt_char);470 else471 Print("%s %3d%c ",currentVoice->filename,yylineno,prompt_char);472 }473 {474 fwrite(anf,1,len_s,stdout);475 mflush();476 }477 if (traceit&TRACE_SHOW_LINE)478 {479 while(fgetc(stdin)!='\n');480 }481 }482 else if (traceit&TRACE_SHOW_LINENO)483 {484 Print("{%d}",yylineno);485 mflush();486 }487 #ifdef HAVE_SDB488 if ((blocknest==0)489 && (currentVoice->pi!=NULL)490 && (currentVoice->pi->trace_flag!=0))491 {492 sdb(currentVoice, anf, len_s);493 }494 #endif495 prompt_char = '.';496 return len_s;497 }498 499 int feReadLine(char* b, int l)500 {501 char *s=NULL;502 int offset = 0; /* will not be used if s==NULL*/503 // try to read from the buffer into b, max l chars504 if (currentVoice!=NULL)505 {506 if((currentVoice->buffer!=NULL)507 && (currentVoice->buffer[currentVoice->fptr]!='\0'))508 {509 NewBuff:510 register int i=0;511 long startfptr=currentVoice->fptr;512 long tmp_ptr=currentVoice->fptr;513 l--;514 loop515 {516 register char c=517 b[i]=currentVoice->buffer[tmp_ptr/*currentVoice->fptr*/];518 i++;519 if (yy_noeof==noeof_block)520 {521 if (c<' ') yylineno++;522 else if (c=='}') break;523 }524 else525 {526 if ((c<' ') ||527 (c==';') ||528 (c==')')529 )530 break;531 }532 if (i>=l) break;533 tmp_ptr++;/*currentVoice->fptr++;*/534 if(currentVoice->buffer[tmp_ptr/*currentVoice->fptr*/]=='\0') break;535 }536 currentVoice->fptr=tmp_ptr;537 b[i]='\0';538 if (currentVoice->sw==BI_buffer)539 {540 if (startfptr==0)541 {542 char *anf=currentVoice->buffer;543 const char *ss=strchr(anf,'\n');544 long len;545 if (ss==NULL) len=strlen(anf);546 else len=ss-anf;547 char *s=(char *)omAlloc(len+2);548 strncpy(s,anf,len+2);549 s[len+1]='\0';550 fePrintEcho(s,b);551 omFree((ADDRESS)s);552 }553 else if (/*(startfptr>0) &&*/554 (currentVoice->buffer[startfptr-1]=='\n'))555 {556 char *anf=currentVoice->buffer+startfptr;557 const char *ss=strchr(anf,'\n');558 long len;559 if (ss==NULL) len=strlen(anf);560 else len=ss-anf;561 char *s=(char *)omAlloc(len+2);562 strncpy(s,anf,len+2);563 s[len+1]='\0';564 yylineno++;565 fePrintEcho(s,b);566 omFree((ADDRESS)s);567 }568 }569 currentVoice->fptr++;570 return i;571 }572 // no buffer there or e-o-buffer or eoln:573 if (currentVoice->sw!=BI_buffer)574 {575 currentVoice->fptr=0;576 if (currentVoice->buffer==NULL)577 {578 currentVoice->buffer=(char *)omAlloc(MAX_FILE_BUFFER-sizeof(ADDRESS));579 omMarkAsStaticAddr(currentVoice->buffer);580 }581 }582 offset=0;583 NewRead:584 yylineno++;585 if (currentVoice->sw==BI_stdin)586 {587 feShowPrompt();588 s=fe_fgets_stdin(fe_promptstr,589 &(currentVoice->buffer[offset]),590 omSizeOfAddr(currentVoice->buffer)-1-offset);591 //int i=0;592 //if (s!=NULL)593 // while((s[i]!='\0') /*&& (i<MAX_FILE_BUFFER)*/) {s[i] &= (char)127;i++;}594 }595 else if (currentVoice->sw==BI_file)596 {597 s=fgets(currentVoice->buffer+offset,(MAX_FILE_BUFFER-1-sizeof(ADDRESS))-offset,598 currentVoice->files);599 }600 //else /* BI_buffer */ s==NULL => return 0601 // done by the default return602 }603 if (s!=NULL)604 {605 // handle prot:606 if (feProt&PROT_I)607 {608 fputs(s,feProtFile);609 }610 int rc=fePrintEcho(s,b)+1;611 //s[strlen(s)+1]='\0'; add an second \0 at the end of the string612 s[rc]='\0';613 // handel \\ :614 rc-=3;615 if ((s[rc]=='\\')&&(currentVoice->sw!=BI_buffer))616 {617 s[rc]='\0';618 offset+=rc;619 if (offset<(int)omSizeOfAddr(currentVoice->buffer)) goto NewRead;620 }621 goto NewBuff;622 }623 /* else if (s==NULL) */624 {625 const char *err;626 switch(yy_noeof)627 {628 case noeof_brace:629 case noeof_block:630 err="{...}";631 break;632 case noeof_asstring:633 err="till `.`";634 break;635 case noeof_string:636 err="string";637 break;638 case noeof_bracket:639 err="(...)";640 break;641 case noeof_procname:642 err="proc";643 break;644 case noeof_comment:645 err="/*...*/";646 break;647 default:648 return 0;649 }650 Werror("premature end of file while reading %s",err);651 return 0;652 }653 }654 655 /*2656 * init all data structures657 */658 #ifndef STDIN_FILENO659 #define STDIN_FILENO 0660 #endif661 Voice * feInitStdin(Voice *pp)662 {663 Voice *p = new Voice;664 p->files = stdin;665 p->sw = (isatty(STDIN_FILENO)) ? BI_stdin : BI_file;666 if ((pp!=NULL) && (pp->files==stdin))667 {668 p->files=freopen("/dev/tty","r",stdin);669 //stdin=p->files;670 p->sw = BI_stdin;671 }672 p->filename = omStrDup("STDIN");673 p->start_lineno = 1;674 omMarkAsStaticAddr(p);675 omMarkAsStaticAddr(p->filename);676 return p;677 }678 679 static char * feBufferStart;680 /* only used in StringSet(S)/StringAppend(S)*/681 char * StringAppend(const char *fmt, ...)682 {683 va_list ap;684 char *s = feBufferStart; /*feBuffer + strlen(feBuffer);*/685 int vs;686 long more;687 va_start(ap, fmt);688 if ((more=feBufferStart-feBuffer+strlen(fmt)+100)>feBufferLength)689 {690 more = ((more + (8*1024-1))/(8*1024))*(8*1024);691 int l=s-feBuffer;692 feBuffer=(char *)omReallocSize((ADDRESS)feBuffer,feBufferLength,693 more);694 omMarkAsStaticAddr(feBuffer);695 feBufferLength=more;696 s=feBuffer+l;697 #ifndef BSD_SPRINTF698 feBufferStart=s;699 #endif700 }701 #ifdef BSD_SPRINTF702 vsprintf(s, fmt, ap);703 while (*s!='\0') s++;704 feBufferStart =s;705 #else706 #ifdef HAVE_VSNPRINTF707 vs = vsnprintf(s, feBufferLength - (feBufferStart - feBuffer), fmt, ap);708 if (vs == -1)709 {710 assume(0);711 feBufferStart = feBuffer + feBufferLength -1;712 }713 else714 {715 feBufferStart += vs;716 }717 #else718 feBufferStart += vsprintf(s, fmt, ap);719 #endif720 #endif721 omCheckAddrSize(feBuffer, feBufferLength);722 va_end(ap);723 return feBuffer;724 }725 726 char * StringAppendS(const char *st)727 {728 if (*st!='\0')729 {730 /* feBufferStart is feBuffer + strlen(feBuffer);*/731 int l;732 long more;733 int ll=feBufferStart-feBuffer;734 if ((more=ll+2+(l=strlen(st)))>feBufferLength)735 {736 more = ((more + (8*1024-1))/(8*1024))*(8*1024);737 feBuffer=(char *)omReallocSize((ADDRESS)feBuffer,feBufferLength,738 more);739 feBufferLength=more;740 feBufferStart=feBuffer+ll;741 }742 strcat(feBufferStart, st);743 feBufferStart +=l;744 }745 return feBuffer;746 }747 748 char * StringSetS(const char *st)749 {750 int l;751 long more;752 if ((l=strlen(st))>feBufferLength)753 {754 more = ((l + (4*1024-1))/(4*1024))*(4*1024);755 feBuffer=(char *)omReallocSize((ADDRESS)feBuffer,feBufferLength,756 more);757 feBufferLength=more;758 }759 strcpy(feBuffer,st);760 feBufferStart=feBuffer+l;761 return feBuffer;762 }763 764 extern "C" {765 void WerrorS(const char *s)766 {767 #ifdef HAVE_MPSR768 if (fe_fgets_stdin==fe_fgets_dummy)769 {770 if (feErrors==NULL)771 {772 feErrors=(char *)omAlloc(256);773 feErrorsLen=256;774 *feErrors = '\0';775 }776 else777 {778 if (((int)(strlen((char *)s)+ 20 +strlen(feErrors)))>=feErrorsLen)779 {780 feErrors=(char *)omReallocSize(feErrors,feErrorsLen,feErrorsLen+256);781 feErrorsLen+=256;782 }783 }784 strcat(feErrors, "Singular error: ");785 strcat(feErrors, (char *)s);786 }787 else788 #endif789 {790 {791 if (WerrorS_callback == NULL)792 {793 fwrite(" ? ",1,5,stderr);794 fwrite((char *)s,1,strlen((char *)s),stderr);795 fwrite("\n",1,1,stderr);796 fflush(stderr);797 }798 else799 {800 WerrorS_callback(s);801 }802 if (feProt&PROT_O)803 {804 fwrite(" ? ",1,5,feProtFile);805 fwrite((char *)s,1,strlen((char *)s),feProtFile);806 fwrite("\n",1,1,feProtFile);807 }808 }809 }810 errorreported = TRUE;811 #ifdef HAVE_FACTORY812 // libfac:813 extern int libfac_interruptflag;814 libfac_interruptflag=1;815 #endif816 }817 818 void Werror(const char *fmt, ...)819 {820 va_list ap;821 va_start(ap, fmt);822 char *s=(char *)omAlloc(256);823 vsprintf(s, fmt, ap);824 WerrorS(s);825 omFreeSize(s,256);826 va_end(ap);827 }828 829 void WarnS(const char *s)830 {831 #define warn_str "// ** "832 if (feWarn) /* ignore warnings if option --no-warn was given */833 {834 fwrite(warn_str,1,6,stdout);835 fwrite(s,1,strlen(s),stdout);836 fwrite("\n",1,1,stdout);837 fflush(stdout);838 if (feProt&PROT_O)839 {840 fwrite(warn_str,1,6,feProtFile);841 fwrite(s,1,strlen(s),feProtFile);842 fwrite("\n",1,1,feProtFile);843 }844 }845 }846 } /* end extern "C" */847 848 void Warn(const char *fmt, ...)849 {850 va_list ap;851 va_start(ap, fmt);852 char *s=(char *)omAlloc(256);853 vsprintf(s, fmt, ap);854 WarnS(s);855 omFreeSize(s,256);856 va_end(ap);857 }858 859 860 // some routines which redirect the output of print to a string861 static char* sprint = NULL;862 static char* sprint_backup = NULL;863 void SPrintStart()864 {865 if (sprint!=NULL)866 {867 if (sprint_backup!=NULL) WerrorS("internal error: SPrintStart");868 else sprint_backup=sprint;869 }870 sprint = omStrDup("");871 }872 873 static void SPrintS(const char* s)874 {875 omCheckAddr(sprint);876 if ((s == NULL)||(*s == '\0')) return;877 int ls = strlen(s);878 879 char* ns;880 int l = strlen(sprint);881 ns = (char*) omAlloc((l + ls + 1)*sizeof(char));882 if (l > 0) strcpy(ns, sprint);883 884 strcpy(&(ns[l]), s);885 omFree(sprint);886 sprint = ns;887 omCheckAddr(sprint);888 }889 890 char* SPrintEnd()891 {892 char* ns = sprint;893 sprint = sprint_backup;894 sprint_backup=NULL;895 omCheckAddr(ns);896 return ns;897 }898 899 // Print routines900 extern "C" {901 void PrintS(const char *s)902 {903 if (sprint != NULL)904 {905 SPrintS(s);906 return;907 }908 else if (feOut) /* do not print when option --no-out was given */909 {910 {911 fwrite(s,1,strlen(s),stdout);912 fflush(stdout);913 if (feProt&PROT_O)914 {915 fwrite(s,1,strlen(s),feProtFile);916 }917 }918 }919 }920 921 void PrintLn()922 {923 PrintS("\n");924 }925 926 void Print(const char *fmt, ...)927 {928 if (sprint != NULL)929 {930 va_list ap;931 va_start(ap, fmt);932 omCheckAddr(sprint);933 int ls = strlen(fmt);934 if (fmt != NULL && ls > 0)935 {936 char* ns;937 int l = strlen(sprint);938 ns = (char*) omAlloc(sizeof(char)*(ls + l + 512));939 if (l > 0) strcpy(ns, sprint);940 941 #ifdef HAVE_VSNPRINTF942 l = vsnprintf(&(ns[l]), ls+511, fmt, ap);943 assume(l != -1);944 #else945 vsprintf(&(ns[l]), fmt, ap);946 #endif947 omCheckAddr(ns);948 omFree(sprint);949 sprint = ns;950 }951 va_end(ap);952 return;953 }954 else if (feOut)955 {956 va_list ap;957 va_start(ap, fmt);958 int l;959 long ls=strlen(fmt);960 char *s=(char *)omAlloc(ls+512);961 #ifdef HAVE_VSNPRINTF962 l = vsnprintf(s, ls+511, fmt, ap);963 if ((l==-1)||(s[l]!='\0')||(l!=(int)strlen(s)))964 {965 printf("Print problem: l=%d, fmt=>>%s<<\n",l,fmt);966 s[l]='\0';967 }968 #else969 vsprintf(s, fmt, ap);970 #endif971 PrintS(s);972 omFree(s);973 va_end(ap);974 }975 }976 void PrintNSpaces(const int n)977 {978 int l=n-1;979 while(l>=0) { PrintS(" "); l--; }980 }981 982 /* end extern "C" */983 }984 51 985 52 #if 0 -
libpolys/misc/options.c
r6b71e2 r88ece17 1 1 // the following initialization is needed for linkage on Mac OS X, 2 2 // since initialized variables will be "D" (uninit. go to "C") segments 3 #include <misc/options.h> 3 4 unsigned test = 0; 4 unsigned verbose = 0; 5 unsigned verbose = Sy_bit(V_QUIET) 6 //| Sy_bit(V_QRING) // not default, as speed drops by 10 % 7 | Sy_bit(V_REDEFINE) 8 | Sy_bit(V_LOAD_LIB) 9 | Sy_bit(V_SHOW_USE) 10 | Sy_bit(V_PROMPT) 11 ; 5 12 -
libpolys/reporter/reporter.cc
r6b71e2 r88ece17 42 42 BOOLEAN feWarn = TRUE; 43 43 BOOLEAN feOut = TRUE; 44 void (*WerrorS_callback)(const char *s) = NULL; 44 45 45 46 const char feNotImplemented[]="not implemented"; … … 180 181 #endif 181 182 { 182 fwrite(" ? ",1,5,stderr); 183 fwrite((char *)s,1,strlen((char *)s),stderr); 184 fwrite("\n",1,1,stderr); 185 fflush(stderr); 183 if (WerrorS_callback == NULL) 184 { 185 fwrite(" ? ",1,5,stderr); 186 fwrite((char *)s,1,strlen((char *)s),stderr); 187 fwrite("\n",1,1,stderr); 188 fflush(stderr); 189 } 190 else 191 { 192 WerrorS_callback(s); 193 } 186 194 if (feProt&PROT_O) 187 195 {
Note: See TracChangeset
for help on using the changeset viewer.