Changeset 057e93c in git for Singular/iplib.cc
- Timestamp:
- Feb 27, 1998, 3:06:27 PM (26 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- a18fae54e4f760ce0cd7832679f5171a88c3fde7
- Parents:
- 1c31dc7f319d025944d44dcc090983f7cb03be12
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/iplib.cc
r1c31dc r057e93c 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: iplib.cc,v 1. 9 1998-01-17 17:24:39Singular Exp $ */4 /* $Id: iplib.cc,v 1.10 1998-02-27 14:06:18 Singular Exp $ */ 5 5 /* 6 6 * ABSTRACT: interpreter: LIB and help … … 54 54 return s; 55 55 } 56 56 57 /*2 57 58 * given a line with args, return the argstr … … 123 124 124 125 fseek(fp, pi->data.s.proc_start, SEEK_SET); 125 if(part==0) { // load help string 126 if(part==0) 127 { // load help string 126 128 procbuflen = pi->data.s.body_start - pi->data.s.proc_start; 127 129 //Print("Help=%ld-%ld=%d\n", pi->data.s.body_start, … … 132 134 return(s); 133 135 } 134 if(part==1) { // load proc part 136 if(part==1) 137 { // load proc part 135 138 fgets(buf, sizeof(buf), fp); 136 139 char ct; … … 145 148 //Print("Body=%ld-%ld=%d\n", pi->data.s.body_end, 146 149 // pi->data.s.body_start, procbuflen); 147 if (pi->data.s.body==NULL) { 150 if (pi->data.s.body==NULL) 151 { 148 152 Werror( "unable to allocate proc buffer `%s`", pi->procname ); 149 153 return NULL; … … 156 160 fclose( fp ); 157 161 pi->data.s.body[procbuflen] = '\0'; 158 strcat( pi->data.s.body+procbuflen, "\n; \nRETURN();\n\n" );162 strcat( pi->data.s.body+procbuflen, "\n;return();\n\n" ); 159 163 strcat( pi->data.s.body+procbuflen+13,pi->libname); 160 164 s=strchr(pi->data.s.body,'{'); … … 162 166 return NULL; 163 167 } 164 if(part==2) { // load example 168 if(part==2) 169 { // load example 165 170 fseek(fp, pi->data.s.example_start, SEEK_SET); 166 171 fgets(buf, sizeof(buf), fp); … … 171 176 fread(s, procbuflen, 1, fp); 172 177 s[procbuflen] = '\0'; 173 strcat(s+procbuflen-3, "\n; RETURN();\n\n" );178 strcat(s+procbuflen-3, "\n;return();\n\n" ); 174 179 p=strchr(s,'{'); 175 180 if (p!=NULL) *s=' '; … … 180 185 181 186 /*2 182 * start either a proc or a file187 * start a proc 183 188 * parameters are built as exprlist 184 * if both procname and filename are defined, it is an interrupt ! 189 * TODO:interrupt 190 * return FALSE on success, TRUE if an error occurs 185 191 */ 186 BOOLEAN iiPStart(idhdl pn, char* filename,sleftv * v)192 BOOLEAN iiPStart(idhdl pn, sleftv * v) 187 193 { 188 194 char * str; 189 195 BOOLEAN err=FALSE; 196 int old_echo=si_echo; 190 197 191 198 /* init febase ======================================== */ 192 if (filename!=NULL) 193 { 194 FILE *fp=feFopen(filename,"r",NULL,TRUE); 195 if (fp==NULL) 196 { 197 return FALSE; 198 } 199 fseek(fp,0L,SEEK_END); 200 long len=ftell(fp); 201 fseek(fp,0L,SEEK_SET); 202 char *filedata=(char *)AllocL((int)len+1); 203 fread( filedata, len, 1, fp); 204 filedata[len]='\0'; 205 char *currpos=filedata; 206 char *found; 207 while ((found=strstr(currpos,"\\\n"))!=NULL) 208 { 209 register char *np=found; 210 register char *op; 211 if (*(currpos-1)=='\\') 212 op=np+1; 213 else 214 op=np+2; 215 do 216 { 217 *(np++)=*(op++); 218 } 219 while (*np!='\0'); 220 currpos=found; 221 } 222 str = filename; 223 newBuffer( filedata, BT_file, filename ); 224 fileVoice = voice; 225 } 226 else 227 { 228 /* we do not enter this case if filename != NULL !! */ 229 if (pn!=NULL) 230 { 231 procinfov pi; 232 pi = IDPROC(pn); 233 if(pi!=NULL) { 234 if( pi->data.s.body==NULL ) { 235 iiGetLibProcBuffer(IDPROC(pn)); 236 if (IDPROC(pn)->data.s.body==NULL) return TRUE; 237 } 238 newBuffer( mstrdup(IDPROC(pn)->data.s.body), BT_proc, IDID(pn) ); 239 } else { // for security only 240 newBuffer( mstrdup(IDSTRING(pn)), BT_proc, IDID(pn) ); 241 } 242 fileVoice = voice; 243 } 199 /* we do not enter this case if filename != NULL !! */ 200 if (pn!=NULL) 201 { 202 procinfov pi; 203 pi = IDPROC(pn); 204 if(pi!=NULL) 205 { 206 if( pi->data.s.body==NULL ) 207 { 208 iiGetLibProcBuffer(IDPROC(pn)); 209 if (IDPROC(pn)->data.s.body==NULL) return TRUE; 210 } 211 newBuffer( mstrdup(IDPROC(pn)->data.s.body), BT_proc, 212 pi, IDPROC(pn)->data.s.body_lineno ); 213 } 214 //else 215 //{ // for security only 216 // newBuffer( mstrdup(IDSTRING(pn)), BT_proc, IDID(pn) ); 217 //} 244 218 } 245 219 /* generate argument list ======================================*/ … … 255 229 } 256 230 /* start interpreter ======================================*/ 257 if (filename==NULL) //(pn) -> this is a proc call 258 { 259 void * oldb = myynewbuffer(); 260 myynest++; 261 err=yyparse(); 262 killlocals(myynest); 263 myynest--; 264 myyoldbuffer(oldb); 265 } 266 else // -> this is file input or interrupt 267 if (pn!=NULL) // interupt 268 { 269 myynest++; 270 err=yyparse(); 271 killlocals(myynest); 272 myynest--; 273 } 274 else // -> this is file input 275 { 276 void * oldb = myynewbuffer(); 277 err=yyparse(); 278 myyoldbuffer(oldb); 279 } 231 //Print("PStart <<%s>>\n",IDID(pn)); 232 myynest++; 233 err=yyparse(); 234 killlocals(myynest); 235 myynest--; 236 si_echo=old_echo; 237 //Print("PEnd <<%s>>\n",IDID(pn)); 238 280 239 return err; 281 240 } … … 338 297 #endif 339 298 #if 1 340 if(pi->language == LANG_SINGULAR) err=iiPStart(pn,NULL,sl); 341 if(pi->language == LANG_C) { 299 if(pi->language == LANG_SINGULAR) err=iiPStart(pn,sl); 300 if(pi->language == LANG_C) 301 { 342 302 leftv res = (leftv)Alloc0(sizeof(sleftv)); 343 303 err = (pi->data.o.function)(res, sl); … … 346 306 } 347 307 #else 348 switch (pi->language) { 349 case LANG_SINGULAR: err=iiPStart(pn,NULL,sl); break; 308 switch (pi->language) 309 { 310 case LANG_SINGULAR: err=iiPStart(pn,sl); break; 350 311 case LANG_C: leftv res = (leftv)Alloc0(sizeof(sleftv)); 351 312 err = (pi->data.o.function)(res, sl); … … 410 371 * destroys the string 'example' 411 372 */ 412 BOOLEAN iiEStart(char* example )373 BOOLEAN iiEStart(char* example, procinfo *pi) 413 374 { 414 375 BOOLEAN err; 415 416 newBuffer( example, BT_example, "example" ); 417 fileVoice = voice; 418 void * oldb = myynewbuffer(); 376 int old_echo=si_echo; 377 378 newBuffer( example, BT_example, pi, pi->data.s.example_lineno ); 419 379 iiCheckNest(); 420 380 iiLocalRing[myynest]=currRing; … … 428 388 killlocals(myynest); 429 389 myynest--; 430 myyoldbuffer(oldb);390 si_echo=old_echo; 431 391 if (traceit&TRACE_SHOW_PROC) 432 392 { … … 582 542 sprintf( buf, "LIB:%s", newlib); 583 543 #if 0 584 if(strcmp(proc, "_init")==0) { 544 if(strcmp(proc, "_init")==0) 545 { 585 546 char *p = iiConvName(newlib); 586 547 Print("Init found:%s;\n", p); … … 623 584 if (buf[0]=='{') 624 585 { 625 if(inBlock==IN_HEADER) { 586 if(inBlock==IN_HEADER) 587 { 626 588 IDPROC(h)->data.s.body_start = pos; 627 589 IDPROC(h)->data.s.body_lineno = lines-offset; … … 634 596 { 635 597 if (buf[0]=='}') 636 637 638 639 640 641 642 598 { 599 if(IDPROC(h)->data.s.example_start==0) 600 IDPROC(h)->data.s.example_start=pos; 601 if(IDPROC(h)->data.s.body_end==0) IDPROC(h)->data.s.body_end=pos; 602 IDPROC(h)->data.s.proc_end = pos; 603 inBlock=0; 604 } 643 605 } 644 606 } … … 666 628 pi->libname = mstrdup(libname); 667 629 668 if( strcmp(procname,"_init")==0) { 630 if( strcmp(procname,"_init")==0) 631 { 669 632 char *p = iiConvName(libname); 670 633 pi->procname = mstrdup(p); … … 691 654 char *q = mstrdup(libname); 692 655 char *r = q; 693 for(; *r!='\0'; r++) { 656 for(; *r!='\0'; r++) 657 { 694 658 if(*r=='.') *r='_'; 695 659 if(*r==':') *r='_'; … … 709 673 Print( "%-15s %20s %s,%s %s,%s %s,%s\n", "Library", "function", 710 674 "line", "start", "line", "body", "line", "example"); 711 for(h = idroot; h != NULL; h = IDNEXT(h)) { 712 if(IDTYP(h) == PROC_CMD) { 675 for(h = idroot; h != NULL; h = IDNEXT(h)) 676 { 677 if(IDTYP(h) == PROC_CMD) 678 { 713 679 proc = IDPROC(h); 714 if(strcmp(proc->procname, IDID(h))!=0) { 680 if(strcmp(proc->procname, IDID(h))!=0) 681 { 715 682 name = (char *)AllocL(strlen(IDID(h))+strlen(proc->procname)+4); 716 683 sprintf(name, "%s -> %s", IDID(h), proc->procname);
Note: See TracChangeset
for help on using the changeset viewer.