Changeset 057e93c in git for Singular/iplib.cc


Ignore:
Timestamp:
Feb 27, 1998, 3:06:27 PM (26 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
a18fae54e4f760ce0cd7832679f5171a88c3fde7
Parents:
1c31dc7f319d025944d44dcc090983f7cb03be12
Message:
* Fri Feb 27 15:02:10 MET 1998 hannes
  new input scheme: many modifications to febase.h, febase.inc,
      febase.cc, scanner.l, grammar.y, iplib.cc, ipshell.{h,cc}


git-svn-id: file:///usr/local/Singular/svn/trunk@1183 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/iplib.cc

    r1c31dc r057e93c  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: iplib.cc,v 1.9 1998-01-17 17:24:39 Singular Exp $ */
     4/* $Id: iplib.cc,v 1.10 1998-02-27 14:06:18 Singular Exp $ */
    55/*
    66* ABSTRACT: interpreter: LIB and help
     
    5454  return s;
    5555}
     56
    5657/*2
    5758* given a line with args, return the argstr
     
    123124
    124125  fseek(fp, pi->data.s.proc_start, SEEK_SET);
    125   if(part==0) { // load help string
     126  if(part==0)
     127  { // load help string
    126128    procbuflen = pi->data.s.body_start - pi->data.s.proc_start;
    127129    //Print("Help=%ld-%ld=%d\n", pi->data.s.body_start,
     
    132134    return(s);
    133135  }
    134   if(part==1) { // load proc part
     136  if(part==1)
     137  { // load proc part
    135138    fgets(buf, sizeof(buf), fp);
    136139    char ct;
     
    145148    //Print("Body=%ld-%ld=%d\n", pi->data.s.body_end,
    146149    //    pi->data.s.body_start, procbuflen);
    147     if (pi->data.s.body==NULL) {
     150    if (pi->data.s.body==NULL)
     151    {
    148152      Werror( "unable to allocate proc buffer `%s`", pi->procname );
    149153      return NULL;
     
    156160    fclose( fp );
    157161    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" );
    159163    strcat( pi->data.s.body+procbuflen+13,pi->libname);
    160164    s=strchr(pi->data.s.body,'{');
     
    162166    return NULL;
    163167  }
    164   if(part==2) { // load example
     168  if(part==2)
     169  { // load example
    165170    fseek(fp, pi->data.s.example_start, SEEK_SET);
    166171    fgets(buf, sizeof(buf), fp);
     
    171176    fread(s, procbuflen, 1, fp);
    172177    s[procbuflen] = '\0';
    173     strcat(s+procbuflen-3, "\n;RETURN();\n\n" );
     178    strcat(s+procbuflen-3, "\n;return();\n\n" );
    174179    p=strchr(s,'{');
    175180    if (p!=NULL) *s=' ';
     
    180185
    181186/*2
    182 * start either a proc or a file
     187* start a proc
    183188* 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
    185191*/
    186 BOOLEAN iiPStart(idhdl pn, char* filename, sleftv  * v)
     192BOOLEAN iiPStart(idhdl pn, sleftv  * v)
    187193{
    188194  char * str;
    189195  BOOLEAN err=FALSE;
     196  int old_echo=si_echo;
    190197
    191198  /* 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    //}
    244218  }
    245219  /* generate argument list ======================================*/
     
    255229  }
    256230  /* 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 
    280239  return err;
    281240}
     
    338297#endif
    339298#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  {
    342302    leftv res = (leftv)Alloc0(sizeof(sleftv));
    343303    err = (pi->data.o.function)(res, sl);
     
    346306  }
    347307#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;
    350311    case LANG_C: leftv res = (leftv)Alloc0(sizeof(sleftv));
    351312      err = (pi->data.o.function)(res, sl);
     
    410371* destroys the string 'example'
    411372*/
    412 BOOLEAN iiEStart(char* example)
     373BOOLEAN iiEStart(char* example, procinfo *pi)
    413374{
    414375  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 );
    419379  iiCheckNest();
    420380  iiLocalRing[myynest]=currRing;
     
    428388  killlocals(myynest);
    429389  myynest--;
    430   myyoldbuffer(oldb);
     390  si_echo=old_echo;
    431391  if (traceit&TRACE_SHOW_PROC)
    432392  {
     
    582542          sprintf( buf, "LIB:%s", newlib);
    583543#if 0
    584           if(strcmp(proc, "_init")==0) {
     544          if(strcmp(proc, "_init")==0)
     545          {
    585546            char *p =  iiConvName(newlib);
    586547            Print("Init found:%s;\n", p);
     
    623584        if (buf[0]=='{')
    624585        {
    625           if(inBlock==IN_HEADER) {
     586          if(inBlock==IN_HEADER)
     587          {
    626588            IDPROC(h)->data.s.body_start = pos;
    627589            IDPROC(h)->data.s.body_lineno = lines-offset;
     
    634596      {
    635597        if (buf[0]=='}')
    636           {
    637             if(IDPROC(h)->data.s.example_start==0)
    638               IDPROC(h)->data.s.example_start=pos;
    639             if(IDPROC(h)->data.s.body_end==0) IDPROC(h)->data.s.body_end=pos;
    640             IDPROC(h)->data.s.proc_end = pos;
    641             inBlock=0;
    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        }
    643605      }
    644606    }
     
    666628  pi->libname = mstrdup(libname);
    667629
    668   if( strcmp(procname,"_init")==0) {
     630  if( strcmp(procname,"_init")==0)
     631  {
    669632    char *p = iiConvName(libname);
    670633    pi->procname = mstrdup(p);
     
    691654  char *q = mstrdup(libname);
    692655  char *r = q;
    693   for(; *r!='\0'; r++) {
     656  for(; *r!='\0'; r++)
     657  {
    694658    if(*r=='.') *r='_';
    695659    if(*r==':') *r='_';
     
    709673  Print( "%-15s  %20s      %s,%s  %s,%s   %s,%s\n", "Library", "function",
    710674         "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    {
    713679      proc = IDPROC(h);
    714       if(strcmp(proc->procname, IDID(h))!=0) {
     680      if(strcmp(proc->procname, IDID(h))!=0)
     681      {
    715682        name = (char *)AllocL(strlen(IDID(h))+strlen(proc->procname)+4);
    716683        sprintf(name, "%s -> %s", IDID(h), proc->procname);
Note: See TracChangeset for help on using the changeset viewer.