Changeset d67f97a in git for Singular/links


Ignore:
Timestamp:
Jun 2, 2016, 5:21:19 PM (8 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '38dfc5131670d387a89455159ed1e071997eec94')
Children:
c7afbd34f1aae46fbf47925ff2246e5f42f4ca08
Parents:
0151564fccc0217ec60e98c6a2303897a948c1b4
Message:
ascii dump revisited (fix tr. #647)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/links/asciiLink.cc

    r015156 rd67f97a  
    2727
    2828/* declarations */
    29 static BOOLEAN DumpAscii(FILE *fd, idhdl h);
    30 static BOOLEAN DumpAsciiIdhdl(FILE *fd, idhdl h);
     29static BOOLEAN DumpAscii(FILE *fd, idhdl h,char ***list_of_libs);
     30static BOOLEAN DumpAsciiIdhdl(FILE *fd, idhdl h,char ***list_of_libs);
    3131static const char* GetIdString(idhdl h);
    3232static int DumpRhs(FILE *fd, idhdl h);
    3333static BOOLEAN DumpQring(FILE *fd, idhdl h, const char *type_str);
    3434static BOOLEAN DumpAsciiMaps(FILE *fd, idhdl h, idhdl rhdl);
     35static BOOLEAN CollectLibs(FILE *fd, char *name, char ***list_of_libs);
     36static BOOLEAN DumpLibs(FILE *fd, char ***list_of_libs);
    3537
    3638extern si_link_extension si_link_root;
     
    213215  FILE *fd = (FILE *) l->data;
    214216  idhdl h = IDROOT, rh = currRingHdl;
    215   BOOLEAN status = DumpAscii(fd, h);
     217  char **list_of_libs=NULL;
     218  BOOLEAN status = DumpAscii(fd, h, &list_of_libs);
    216219
    217220  if (! status ) status = DumpAsciiMaps(fd, h, NULL);
     
    219222  if (currRingHdl != rh) rSetHdl(rh);
    220223  fprintf(fd, "option(set, intvec(%d, %d));\n", si_opt_1, si_opt_2);
     224  char **p=list_of_libs;
     225  if (p!=NULL)
     226  {
     227    while((*p!=NULL) && (*p!=(char*)1))
     228    {
     229      fprintf(fd,"load(\"%s\",\"try\");\n",*p);
     230      p++;
     231    }
     232    omFree(list_of_libs);
     233  }
    221234  fprintf(fd, "RETURN();\n");
    222235  fflush(fd);
     
    227240// we do that recursively, to dump ids in the the order in which they
    228241// were actually defined
    229 static BOOLEAN DumpAscii(FILE *fd, idhdl h)
     242static BOOLEAN DumpAscii(FILE *fd, idhdl h, char ***list_of_libs)
    230243{
    231244  if (h == NULL) return FALSE;
    232245
    233   if (DumpAscii(fd, IDNEXT(h))) return TRUE;
     246  if (DumpAscii(fd, IDNEXT(h),list_of_libs)) return TRUE;
    234247
    235248  // need to set the ring before writing it, otherwise we get in
     
    238251    rSetHdl(h);
    239252
    240   if (DumpAsciiIdhdl(fd, h)) return TRUE;
     253  if (DumpAsciiIdhdl(fd, h,list_of_libs)) return TRUE;
    241254
    242255  if (IDTYP(h) == RING_CMD || IDTYP(h) == QRING_CMD)
    243     return DumpAscii(fd, IDRING(h)->idroot);
     256    return DumpAscii(fd, IDRING(h)->idroot,list_of_libs);
    244257  else
    245258    return FALSE;
     
    275288}
    276289
    277 static BOOLEAN DumpAsciiIdhdl(FILE *fd, idhdl h)
     290static BOOLEAN DumpAsciiIdhdl(FILE *fd, idhdl h, char ***list_of_libs)
    278291{
    279292  const char *type_str = GetIdString(h);
    280293  int type_id = IDTYP(h);
    281294
    282   if ((type_id == PACKAGE_CMD) &&(strcmp(IDID(h), "Top") == 0))
    283     return FALSE;
     295  if (type_id == PACKAGE_CMD)
     296  {
     297    if (strcmp(IDID(h),"Top")==0) return FALSE;
     298    if (IDPACKAGE(h)->language==LANG_SINGULAR) return FALSE;
     299  }
    284300
    285301  // we do not throw an error if a wrong type was attempted to be dumped
     
    294310  if ((type_id == PROC_CMD) && (IDPROC(h)->language == LANG_C))
    295311    return FALSE;
     312
     313  // handle libraries
     314  if ((type_id == PROC_CMD)
     315  && (IDPROC(h)->language == LANG_SINGULAR)
     316  && (IDPROC(h)->libname!=NULL))
     317    return CollectLibs(fd,IDPROC(h)->libname,list_of_libs);
    296318
    297319  // put type and name
     
    333355  switch(type)
    334356  {
    335       case LIST_CMD:
    336       {
    337         lists l = IDLIST(h);
    338         int i, nl = l->nr + 1;
    339 
    340         for (i=0; i<nl; i++)
    341           if (GetIdString((idhdl) &(l->m[i])) == NULL) return NULL;
    342       }
    343       #ifdef SINGULAR_4_1
    344       case CRING_CMD:
    345       case CNUMBER_CMD:
    346       case CMATRIX_CMD:
    347       #endif
    348       case PACKAGE_CMD:
    349       case INT_CMD:
    350       case INTVEC_CMD:
    351       case INTMAT_CMD:
    352       case STRING_CMD:
    353       case RING_CMD:
    354       case QRING_CMD:
    355       case PROC_CMD:
    356       case NUMBER_CMD:
    357       case POLY_CMD:
    358       case IDEAL_CMD:
    359       case VECTOR_CMD:
    360       case MODUL_CMD:
    361       case MATRIX_CMD:
    362         return Tok2Cmdname(type);
    363 
    364       case MAP_CMD:
    365       case LINK_CMD:
    366         return NULL;
    367 
    368       default:
    369        Warn("Error dump data of type %s", Tok2Cmdname(IDTYP(h)));
     357    case LIST_CMD:
     358    {
     359      lists l = IDLIST(h);
     360      int i, nl = l->nr + 1;
     361
     362      for (i=0; i<nl; i++)
     363        if (GetIdString((idhdl) &(l->m[i])) == NULL) return NULL;
     364    }
     365    #ifdef SINGULAR_4_1
     366    case CRING_CMD:
     367    case CNUMBER_CMD:
     368    case CMATRIX_CMD:
     369    #endif
     370    case BIGINT_CMD:
     371    case PACKAGE_CMD:
     372    case INT_CMD:
     373    case INTVEC_CMD:
     374    case INTMAT_CMD:
     375    case STRING_CMD:
     376    case RING_CMD:
     377    case QRING_CMD:
     378    case PROC_CMD:
     379    case NUMBER_CMD:
     380    case POLY_CMD:
     381    case IDEAL_CMD:
     382    case VECTOR_CMD:
     383    case MODUL_CMD:
     384    case MATRIX_CMD:
     385      return Tok2Cmdname(type);
     386
     387    case MAP_CMD:
     388    case LINK_CMD:
     389      return NULL;
     390
     391    default:
     392      Warn("Error dump data of type %s", Tok2Cmdname(IDTYP(h)));
    370393       return NULL;
    371394  }
     
    391414}
    392415
     416static BOOLEAN CollectLibs(FILE *fd, char *name, char *** list_of_libs)
     417{
     418  if (*list_of_libs==NULL)
     419  {
     420    #define MAX_LIBS 256
     421    (*list_of_libs)=(char**)omalloc0(MAX_LIBS*sizeof(char**));
     422    (*list_of_libs)[0]=name;
     423    (*list_of_libs)[MAX_LIBS-1]=(char*)1;
     424    return FALSE;
     425  }
     426  else
     427  {
     428    char **p=*list_of_libs;
     429    while (((*p)!=NULL)&&((*p!=(char*)1)))
     430    {
     431      if (strcmp((*p),name)==0) return FALSE;
     432      p++;
     433    }
     434    if (*p==(char*)1)
     435    {
     436      WerrorS("too many libs");
     437      return TRUE;
     438    }
     439    else
     440    {
     441      *p=name;
     442    }
     443  }
     444  return FALSE;
     445}
     446
    393447
    394448static int DumpRhs(FILE *fd, idhdl h)
     
    431485    if (pi->language == LANG_SINGULAR)
    432486    {
    433       if( pi->data.s.body==NULL) iiGetLibProcBuffer(pi);
     487      /* pi-Libname==NULL */
    434488      char *pstr = pi->data.s.body;
    435489      fputc('"', fd);
     
    454508    else if (type_id == IDEAL_CMD) { fprintf(fd, "ideal(");need_klammer=TRUE; }
    455509    else if (type_id == MODUL_CMD) { fprintf(fd, "module(");need_klammer=TRUE; }
     510    else if (type_id == BIGINT_CMD) { fprintf(fd, "bigint(");need_klammer=TRUE; }
    456511
    457512    if (fprintf(fd, "%s", rhs) == EOF) return EOF;
Note: See TracChangeset for help on using the changeset viewer.