source: git/Singular/ipid.cc @ 77ff8e

spielwiese
Last change on this file since 77ff8e was 77ff8e, checked in by Kai Krüger <krueger@…>, 26 years ago
* ChangeLog extra.cc grammar.y ipid.cc ipid.h iplib.cc * ipshell.cc ipshell.h mod2.h.in ring.cc structs.h tesths.cc Replaced ring *iiLocalRing[] by a stack (class namerec) To use old method define USE_IILOCALRING in mod2.h Old method incompatible with HAVE_NAMESPACES! git-svn-id: file:///usr/local/Singular/svn/trunk@2577 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 18.1 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: ipid.cc,v 1.18 1998-10-15 14:08:31 krueger Exp $ */
5
6/*
7* ABSTRACT: identfier handling
8*/
9
10#include <string.h>
11
12#include "mod2.h"
13#include "tok.h"
14#include "ipshell.h"
15#include "intvec.h"
16#include "febase.h"
17#include "mmemory.h"
18#include "numbers.h"
19#include "polys.h"
20#include "ring.h"
21#include "ideals.h"
22#include "matpol.h"
23#include "lists.h"
24#include "attrib.h"
25#include "silink.h"
26#include "syz.h"
27#include "ipid.h"
28
29namehdl namespaceroot = NULL;
30#define TEST
31#ifndef HAVE_NAMESPACES
32idhdl idroot = NULL;
33#endif /* HAVE_NAMESPACES */
34idhdl currRingHdl = NULL;
35ring  currRing = NULL;
36ideal currQuotient = NULL;
37char* iiNoName="_";
38
39/*0 implementation*/
40
41idhdl idrec::get(const char * s, int lev)
42{
43  idhdl h = this;
44  idhdl found=NULL;
45  int l;
46  while (h!=NULL)
47  {
48    l=IDLEV(h);
49    mmTestLP(IDID(h));
50    if ((l==lev) && (0 == strcmp(s,IDID(h)))) return h;
51    if ((l==0) && (found==NULL) && (0 == strcmp(s,IDID(h))))
52    {
53      found=h;
54    }
55    h = IDNEXT(h);
56  }
57  return found;
58}
59
60//idrec::~idrec()
61//{
62//  if (id!=NULL)
63//  {
64//    FreeL((ADDRESS)id);
65//    id=NULL;
66//  }
67//  /* much more !! */
68//}
69
70idhdl idrec::set(char * s, int lev, idtyp t, BOOLEAN init)
71{
72  //printf("define %s, %x, lev: %d, typ: %d\n", s,s,lev,t);
73  idhdl h = (idrec *)Alloc0(sizeof(idrec));
74  int   len = 0;
75  IDID(h)   = s;
76  IDTYP(h)  = t;
77  IDLEV(h)  = lev;
78#ifdef HAVE_NAMESPACES
79  h->ref    = 0;
80#endif /* HAVE_NAMESPACES */
81  IDNEXT(h) = this;
82  if (init)
83  {
84    switch (t)
85    {
86    //the type with init routines:
87      case INTVEC_CMD:
88      case INTMAT_CMD:
89        IDINTVEC(h) = new intvec();
90        break;
91      case NUMBER_CMD:
92        IDNUMBER(h) = nInit(0);
93        break;
94      case IDEAL_CMD:
95      case MODUL_CMD:
96        IDFLAG(h) = Sy_bit(FLAG_STD);
97      case MATRIX_CMD:
98        IDIDEAL(h) = idInit(1,1);
99        break;
100      case MAP_CMD:
101        IDIDEAL(h) = idInit(1,1);
102        IDMAP(h)->preimage = mstrdup(IDID(currRingHdl));
103        break;
104      case STRING_CMD:
105        IDSTRING(h) = mstrdup("");
106        break;
107      case LIST_CMD:
108        IDLIST(h)=(lists)Alloc(sizeof(slists));
109        IDLIST(h)->Init();
110        break;
111    //the types with the standard init: set the struct to zero
112      case LINK_CMD:
113        len=sizeof(ip_link);
114        break;
115      case RING_CMD:
116      case QRING_CMD:
117        len = sizeof(ip_sring);
118        break;
119      case PACKAGE_CMD:
120        len = sizeof(ip_package);
121        break;
122      case RESOLUTION_CMD:
123        len=sizeof(ssyStrategy);
124        break;
125      case PROC_CMD:
126        len=sizeof(procinfo);
127        break;
128    //other types: without init (int,script,poly,def,package)
129    }
130    if (len!=0)
131    {
132      IDSTRING(h) = (char *)Alloc0(len);
133    }
134    // additional settings:--------------------------------------
135    if (t == QRING_CMD)
136    {
137      IDRING(h)=rCopy(currRing);
138      /* QRING_CMD is ring dep => currRing !=NULL */
139    }
140    else if (t == PROC_CMD)
141    {
142      IDPROC(h)->language=LANG_NONE;
143    }
144  }
145  // --------------------------------------------------------
146  return  h;
147}
148
149/* #define KAI */
150idhdl enterid(char * s, int lev, idtyp t, idhdl* root, BOOLEAN init)
151{
152  idhdl h;
153  // is it the currRing - id ?
154#ifdef HAVE_NAMESPACES
155  namehdl topnsroot = namespaceroot->root;
156#endif
157  if ((currRingHdl!=NULL)
158  &&(IDLEV(currRingHdl)!=lev)
159  &&(s==IDID(currRingHdl)))
160  {
161    s=mstrdup(s);
162  }
163  // is it already defined in root ?
164  else if ((h=(*root)->get(s,lev))!=NULL)
165  {
166    if (IDLEV(h)!=lev)
167    {
168      s=mstrdup(s);
169    }
170    else if ((IDTYP(h) == t)||(t==DEF_CMD))
171    {
172      if (BVERBOSE(V_REDEFINE))
173#ifdef KAI
174        Warn("1 redefining %s **",s);
175#else
176        Warn(" redefining %s **",s);
177#endif
178        if (s==IDID(h))
179        IDID(h)=NULL;
180      killhdl(h,root);
181    }
182    else
183      goto errlabel;
184  }
185  // is it already defined in idroot ?
186  else if (*root != IDROOT)
187  {
188    if ((h=IDROOT->get(s,lev))!=NULL)
189    {
190      if (IDLEV(h)!=lev)
191      {
192        s=mstrdup(s);
193      }
194      else if ((IDTYP(h) == t)||(t==DEF_CMD))
195      {
196        if (BVERBOSE(V_REDEFINE))
197#ifdef KAI
198          Warn("2 redefining %s **",s);
199#else
200          Warn(" redefining %s **",s);
201#endif
202        IDID(h)=NULL;
203        killhdl(h,&IDROOT);
204      }
205      else
206      {
207        goto errlabel;
208      }
209    }
210  }
211#ifdef HAVE_NAMESPACES
212  // is it already defined in toplevel idroot ?
213  else if (*root != NSROOT(topnsroot))
214  {
215    if ((h=topnsroot->get(s,lev))!=NULL)
216    {
217        s=mstrdup(s);
218    }
219  }
220#endif /* HAVE_NAMESPACES */
221  // is it already defined in currRing->idroot ?
222  else if ((currRing!=NULL)&&((*root) != currRing->idroot))
223  {
224    if ((h=currRing->idroot->get(s,lev))!=NULL)
225    {
226      if (IDLEV(h)!=lev)
227      {
228        s=mstrdup(s);
229      }
230      else if ((IDTYP(h) == t)||(t==DEF_CMD))
231      {
232        if (BVERBOSE(V_REDEFINE))
233#ifdef KAI
234          Warn("3 redefining %s **",s);
235#else
236          Warn(" redefining %s **",s);
237#endif
238        IDID(h)=NULL;
239        killhdl(h,&currRing->idroot);
240      }
241      else
242      {
243        goto errlabel;
244      }
245    }
246  }
247  return *root = (*root)->set(s, lev, t, init);
248
249  errlabel:
250    Werror("identifier `%s` in use",s);
251    return NULL;
252}
253
254void killid(char * id, idhdl * ih)
255{
256  if (id!=NULL)
257  {
258    idhdl h = (*ih)->get(id,myynest);
259
260    // id not found in global list, is it defined in current ring ?
261    if (h==NULL)
262    {
263      if ((currRing!=NULL) && (*ih != (currRing->idroot)))
264      {
265        h = currRing->idroot->get(id,myynest);
266        if (h!=NULL)
267        {
268          killhdl(h,&(currRing->idroot));
269          return;
270        }
271      }
272      Werror("`%s` is not defined",id);
273      return;
274    }
275    killhdl(h,ih);
276  }
277  else
278    Werror("kill what ?");
279}
280
281void killhdl(idhdl h)
282{
283  int t=IDTYP(h);
284  if ((BEGIN_RING<t) && (t<END_RING) && (t!=QRING_CMD))
285    killhdl(h,&currRing->idroot);
286  else
287  {
288    //if(t==PACKAGE_CMD) printf("Achtung\n");
289    idhdl s=IDROOT;
290    while ((s!=h) && (s!=NULL)) s=s->next;
291    if (s==NULL) killhdl(h,&currRing->idroot);
292    else killhdl(h,&IDROOT);
293  }
294}
295
296void killhdl(idhdl h, idhdl * ih)
297{
298  //printf("kill %s, id %x, typ %d lev: %d\n",IDID(h),(int)IDID(h),IDTYP(h),IDLEV(h));
299  idhdl hh;
300  BOOLEAN killOtherRing = TRUE;
301  BOOLEAN needResetRing = FALSE;
302
303  if (h->attribute!=NULL)
304  {
305    atKillAll(h);
306    //h->attribute=NULL;
307  }
308  // ring / qring  --------------------------------------------------------
309  // package  -------------------------------------------------------------
310  if ((IDTYP(h) == RING_CMD) || (IDTYP(h) == QRING_CMD)
311  || (IDTYP(h) == PACKAGE_CMD) /*|| (IDTYP(h) == POINTER_CMD)*/)
312  {
313    idhdl savecurrRingHdl = currRingHdl;
314    ring  savecurrRing = currRing;
315
316    // any objects defined for this ring ?
317    if (((IDTYP(h)==RING_CMD) && (IDRING(h)->ref<=0))
318    &&  (IDRING(h)->idroot!=NULL))
319    {
320      idhdl * hd = &IDRING(h)->idroot;
321      idhdl  hdh = IDNEXT(*hd);
322      idhdl  temp;
323      killOtherRing=(IDTYP(h)!=PACKAGE_CMD) && (IDRING(h)!=currRing);
324      if (killOtherRing) //we are not killing the base ring, so switch
325      {
326        needResetRing=TRUE;
327        rSetHdl(h,FALSE);
328        /* no complete init*/
329      }
330      while (hdh!=NULL)
331      {
332        temp = IDNEXT(hdh);
333        killhdl(hdh,&(IDRING(h)->idroot));
334        hdh = temp;
335      }
336      killhdl(*hd,hd);
337    }
338    // reset currRing ?
339    if (needResetRing) // && (killOtherRing)
340    {
341      //we have to switch back to the base ring
342      //currRing = savecurrRing;
343      //currRingHdl = savecurrRingHdl;
344      if (savecurrRing!=NULL)
345      {
346        rSetHdl(savecurrRingHdl,TRUE);
347      }
348    }
349#ifdef HAVE_NAMESPACES
350    if((IDTYP(h)==PACKAGE_CMD) || (IDTYP(h)==POINTER_CMD))
351      Print(">>>>>>Free package\n");
352    else
353#endif /* HAVE_NAMESPACES */
354      rKill(h);
355  }
356  // poly / vector -------------------------------------------------------
357  else if ((IDTYP(h) == POLY_CMD) || (IDTYP(h) == VECTOR_CMD))
358  {
359    pDelete(&IDPOLY(h));
360  }
361  // ideal / module/ matrix / map ----------------------------------------
362  else if ((IDTYP(h) == IDEAL_CMD)
363           || (IDTYP(h) == MODUL_CMD)
364           || (IDTYP(h) == MATRIX_CMD)
365           || (IDTYP(h) == MAP_CMD))
366  {
367    ideal iid = IDIDEAL(h);
368    if (IDTYP(h) == MAP_CMD)
369    {
370      map im = IDMAP(h);
371      FreeL((ADDRESS)im->preimage);
372    }
373    idDelete(&iid);
374  }
375  // string -------------------------------------------------------------
376  else if (IDTYP(h) == STRING_CMD)
377  {
378    FreeL((ADDRESS)IDSTRING(h));
379    //IDSTRING(h)=NULL;
380  }
381  // proc ---------------------------------------------------------------
382  else if (IDTYP(h) == PROC_CMD)
383  {
384    piKill(IDPROC(h));
385  }
386  // number -------------------------------------------------------------
387  else if (IDTYP(h) == NUMBER_CMD)
388  {
389    nDelete(&IDNUMBER(h));
390  }
391  // intvec / intmat  ---------------------------------------------------
392  else if ((IDTYP(h) == INTVEC_CMD)||(IDTYP(h) == INTMAT_CMD))
393  {
394    delete IDINTVEC(h);
395  }
396  // list  -------------------------------------------------------------
397  else if (IDTYP(h)==LIST_CMD)
398  {
399    IDLIST(h)->Clean();
400    //Free((ADDRESS)IDLIST(h)->m, (IDLIST(h)->nr+1)*sizeof(sleftv));
401    //Free((ADDRESS)IDLIST(h), sizeof(slists));
402  }
403  // link  -------------------------------------------------------------
404  else if (IDTYP(h)==LINK_CMD)
405  {
406    slKill(IDLINK(h));
407  }
408  else if((IDTYP(h)==RESOLUTION_CMD)&&(IDDATA(h)!=NULL))
409  {
410    syKillComputation((syStrategy)IDDATA(h));
411  }
412#ifdef TEST
413  else if ((IDTYP(h)!= INT_CMD)&&(IDTYP(h)!=DEF_CMD))
414    Warn("unknown type to kill: %s(%d)",Tok2Cmdname(IDTYP(h)),IDTYP(h));
415#endif
416
417  //  general  -------------------------------------------------------------
418  // now dechain it and delete idrec
419#ifdef KAI_
420  if(h->next != NULL)Print("=======>%s(%x) -> %s<====\n", IDID(h), IDID(h), IDID(h->next));
421  else Print("=======>%s(%x)<====\n", IDID(h), IDID(h));
422#endif
423
424  FreeL((ADDRESS)IDID(h));
425  //IDID(h)=NULL;
426  if (h == (*ih))
427  {
428    // h is at the beginning of the list
429    *ih = IDNEXT(*ih);
430  }
431  else
432  {
433    // h is somethere in the list:
434    hh = *ih;
435    loop
436    {
437      idhdl hhh = IDNEXT(hh);
438      if (hhh == h)
439      {
440        IDNEXT(hh) = IDNEXT(hhh);
441        break;
442      }
443      hh = hhh;
444    }
445  }
446  Free((ADDRESS)h,sizeof(idrec));
447}
448
449idhdl ggetid(const char *n, BOOLEAN local, idhdl *packhdl)
450{
451#ifdef HAVE_NAMESPACES
452  idhdl h =namespaceroot->get(n,myynest, TRUE); // search in toplevel namespace
453  idhdl h2=namespaceroot->get(n,myynest); // search in current namespace
454  idhdl h3=NULL;
455  if ((currRing!=NULL) && ((h2==NULL)||(IDLEV(h2)!=myynest)))
456  {
457    h3 = currRing->idroot->get(n,myynest);
458  }
459  if (h3==NULL) {
460    if (h2!=NULL) {
461      *packhdl=namespaceroot->get(namespaceroot->name,0, TRUE);
462      return h2;
463    }
464    if(!local) {
465      if(h!=NULL)*packhdl=namespaceroot->get("Top",0, TRUE);
466      return h;
467    }
468  }
469  if(h3!=NULL) *packhdl = currRingHdl;
470  else *packhdl = NULL;
471  return h3;
472#else /* HAVE_NAMESPACES */
473  idhdl h = idroot->get(n,myynest);
474  idhdl h2=NULL;
475  *packhdl = NULL;
476  if ((currRing!=NULL) && ((h==NULL)||(IDLEV(h)!=myynest)))
477  {
478    h2 = currRing->idroot->get(n,myynest);
479  }
480  if (h2==NULL) return h;
481  return h2;
482#endif /* HAVE_NAMESPACES */
483}
484
485idhdl ggetid(const char *n, BOOLEAN local)
486{
487#ifdef HAVE_NAMESPACES
488  idhdl h =namespaceroot->get(n,myynest, TRUE); // search in toplevel namespace
489  idhdl h2=namespaceroot->get(n,myynest); // search in current namespace
490  idhdl h3=NULL;
491  if ((currRing!=NULL) && ((h2==NULL)||(IDLEV(h2)!=myynest)))
492  {
493    h3 = currRing->idroot->get(n,myynest);
494  }
495  if (h3==NULL) {
496    if (h2!=NULL) return h2;
497    if(!local) return h;
498  }
499  return h3;
500#else /* HAVE_NAMESPACES */
501  idhdl h = idroot->get(n,myynest);
502  idhdl h2=NULL;
503  if ((currRing!=NULL) && ((h==NULL)||(IDLEV(h)!=myynest)))
504  {
505    h2 = currRing->idroot->get(n,myynest);
506  }
507  if (h2==NULL) return h;
508  return h2;
509#endif /* HAVE_NAMESPACES */
510}
511
512void ipListFlag(idhdl h)
513{
514  if (hasFlag(h,FLAG_STD)) PrintS(" (SB)");
515  if (hasFlag(h,FLAG_DRING)) PrintS(" (D)");
516}
517
518lists ipNameList(idhdl root)
519{
520  idhdl h=root;
521  /* compute the length */
522  int l=0;
523  while (h!=NULL) { l++; h=IDNEXT(h); }
524  /* allocate list */
525  lists L=(lists)Alloc(sizeof(slists));
526  L->Init(l);
527  /* copy names */
528  h=root;
529  l=0;
530  while (h!=NULL)
531  {
532    /* list is initialized with 0 => no need to clear anything */
533    L->m[l].rtyp=STRING_CMD;
534    L->m[l].data=mstrdup(IDID(h));
535    l++;
536    h=IDNEXT(h);
537  }
538  return L;
539}
540
541/*
542* move 'tomove' from root1 list to root2 list
543*/
544static void ipSwapId(idhdl tomove, idhdl &root1, idhdl &root2)
545{
546  idhdl h;
547  /* search 'tomove' in root2 : if found -> do nothing */
548  h=root2;
549  while ((h!=NULL) && (h!=tomove)) h=IDNEXT(h);
550  if (h!=NULL) return;
551  /* search predecessor of h in root1, remove 'tomove' */
552  h=root1;
553  if (tomove==h)
554  {
555    root1=IDNEXT(h);
556  }
557  else
558  {
559    while ((h!=NULL) && (IDNEXT(h)!=tomove)) h=IDNEXT(h);
560    if (h==NULL) return; /* not in the list root1 -> do nothing */
561    IDNEXT(h)=IDNEXT(tomove);
562  }
563  /* add to root2 list */
564  IDNEXT(tomove)=root2;
565  root2=tomove;
566}
567
568void  ipMoveId(idhdl tomove)
569{
570  if ((currRing!=NULL)&&(tomove!=NULL))
571  {
572    if (((QRING_CMD!=IDTYP(tomove)) && (BEGIN_RING<IDTYP(tomove)) && (IDTYP(tomove)<END_RING))
573    || ((IDTYP(tomove)==LIST_CMD) && (lRingDependend(IDLIST(tomove)))))
574    {
575      /*move 'tomove' to ring id's*/
576      ipSwapId(tomove,IDROOT,currRing->idroot);
577    }
578    else
579    {
580      /*move 'tomove' to global id's*/
581      ipSwapId(tomove,currRing->idroot,IDROOT);
582    }
583  }
584}
585
586char * piProcinfo(procinfov pi, char *request)
587{
588  if(pi == NULL) return "empty proc";
589  else if (strcmp(request, "libname")  == 0) return pi->libname;
590  else if (strcmp(request, "procname") == 0) return pi->procname;
591  else if (strcmp(request, "type")     == 0) {
592    switch (pi->language) {
593      case LANG_SINGULAR: return "singular"; break;
594      case LANG_C:        return "object";   break;
595      case LANG_NONE:     return "none";     break;
596      default:            return "unknow language";
597    }
598  } else if (strcmp(request, "ref")      == 0) {
599    char p[8];
600    sprintf(p, "%d", pi->ref);
601    return mstrdup(p);  // MEMORY-LEAK
602  }
603  return "??";
604}
605
606void piCleanUp(procinfov pi)
607{
608  (pi->ref)--;
609  if (pi->ref <= 0)
610  {
611    FreeL((ADDRESS)pi->libname);
612    FreeL((ADDRESS)pi->procname);
613    if( pi->language == LANG_SINGULAR)
614    {
615      FreeL((ADDRESS)pi->data.s.body);
616    }
617    if( pi->language == LANG_C)
618    {
619    }
620    memset((void *) pi, 0, sizeof(procinfo));
621    pi->language=LANG_NONE;
622  }
623}
624
625void piKill(procinfov pi)
626{
627  piCleanUp(pi);
628  if (pi->ref <= 0)
629    Free((ADDRESS)pi, sizeof(procinfo));
630}
631
632char *idhdl2id(idhdl pck, idhdl h)
633{
634  char *name = (char *)AllocL(strlen(pck->id) + strlen(h->id) + 3);
635  sprintf(name, "%s::%s", pck->id, h->id);
636  return(name);
637}
638
639void iiname2hdl(char *name, idhdl *pck, idhdl *h)
640{
641  char *q = index(name, ':');
642  char *p, *i;
643
644  if(q==NULL)
645  {
646    p = mstrdup("");
647    i = (char *)AllocL(strlen(name)+1);
648    *i = '\0';
649    sscanf(name, "%s", i);
650#ifdef HAVE_NAMESPACES
651    *h = namespaceroot->get(i, myynest);
652    if(*h == NULL) { *h = namespaceroot->get(i, myynest, TRUE); }
653#else /* HAVE_NAMESPACES */
654#endif /* HAVE_NAMESPACES */
655  }
656  else {
657    if( *(q+1) != ':') return;
658    i = (char *)AllocL(strlen(name)+1);
659    *i = '\0';
660    if(name == q)
661    {
662      p = mstrdup("");
663      sscanf(name, "::%s", i);
664#ifdef HAVE_NAMESPACES
665      *h =namespaceroot->get(i, myynest, TRUE); // search in toplevel namespace
666#else /* HAVE_NAMESPACES */
667#endif /* HAVE_NAMESPACES */
668    }
669    else
670    {
671      p = (char *)AllocL(strlen(name)+1);
672      sscanf(name, "%[^:]::%s", p, i);
673#ifdef HAVE_NAMESPACES
674      *pck =namespaceroot->get(p, myynest, TRUE); // search in toplevel namespace
675      namespaceroot->push(IDPACKAGE(*pck), IDID(*pck));
676      *h =namespaceroot->get(i, myynest); // search in toplevel namespace
677      namespaceroot->pop();
678#else /* HAVE_NAMESPACES */
679#endif /* HAVE_NAMESPACES */
680    }
681  }
682  //printf("Package: '%s'\n", p);
683  //printf("Id Rec : '%s'\n", i);
684  FreeL(p);
685  FreeL(i);
686}
687
688char *getnamelev()
689{
690  char buf[256];
691  sprintf(buf, "(%s:%d)", namespaceroot->name,namespaceroot->lev);
692  return(buf);
693}
694
695namehdl namerec::push(package pack, char *name, BOOLEAN init)
696{
697  //printf("PUSH: put entry (%s) on stack\n", name);
698  namehdl ns = (namerec *)Alloc0(sizeof(namerec));
699  extern int myynest;
700  ns->next   = this;
701  if(this==NULL && !init)
702  {
703    printf("PUSH: this is NULL and init not set.\n");
704    init=TRUE;
705  }
706  if(init)
707  {
708    ns->next    = NULL;
709#ifdef HAVE_NAMESPACES
710    ns->pack    = (ip_package *)Alloc0(sizeof(ip_package));
711#endif /* HAVE_NAMESPACES */
712    ns->isroot  = TRUE;
713    ns->lev     = 1;
714    ns->myynest = 0;
715  }
716  else
717  {
718    extern ring currRing;
719#ifdef HAVE_NAMESPACES
720    ns->pack   = pack;
721#endif /* HAVE_NAMESPACES */
722    ns->lev    = this->lev+1;
723    ns->myynest = myynest+1;
724    this->currRing = currRing;
725    //printf("Saving Ring %x, %x\n", this->currRing, currRing);
726  }
727  ns->name    = mstrdup(name);
728 
729 
730  //if(ns->isroot) Print("PUSH: Add root NameSpace\n");
731  //ns->currRing = currRing;
732  //ns->currRingHdl = currRingHdl;
733  //printf("Test 1\n");
734  if(ns->isroot) ns->root=ns; else ns->root = this->root;
735  namespaceroot = ns;
736#if 0
737  if(init && ns->isroot) {
738    idhdl pl = enterid( mstrdup("Top"),0, PACKAGE_CMD,
739                      &NSROOT(namespaceroot), TRUE );
740    if(pl != NULL) {
741      Free((ADDRESS)IDPACKAGE(pl), sizeof(ip_package));
742      IDPACKAGE(pl) = ns->pack;
743    }
744  }
745#endif
746  //Print("NSPUSH: done\n");
747  return(namespaceroot);
748}
749
750namehdl namerec::pop()
751{
752  namehdl ns;
753  //printf("POP: remove entry (%s)\n", this->name);
754  if(this==NULL) return NULL;
755  if(isroot) {
756    //printf("POP: base. woul'd do it.\n");
757    return this;
758  }
759  ns = this;
760  namespaceroot = this->next;
761  FreeL((ADDRESS)ns->name);
762  Free((ADDRESS)ns, sizeof(namerec));
763  return(namespaceroot);
764}
765
766#ifdef HAVE_NAMESPACES
767idhdl namerec::get(const char * s, int lev, BOOLEAN root)
768{
769  namehdl ns;
770  if(root) {
771    ns = this->root;
772  } else {
773    ns = this;
774  }
775  //printf("//====== namerec::get(%s, %d) from '%s'\n", s, lev, ns->name);
776  if(ns==NULL) {
777    //printf("//======== namerec::get() from null\n");
778    return NULL;
779  }
780  return( NSROOT(ns)->get(s, lev));
781}
782#endif /* HAVE_NAMESPACES */
Note: See TracBrowser for help on using the repository browser.