source: git/Singular/ipid.cc @ 91c978

fieker-DuValspielwiese
Last change on this file since 91c978 was 9bc0b8, checked in by Hans Schönemann <hannes@…>, 19 years ago
*hannes; mpr_* ->kernel git-svn-id: file:///usr/local/Singular/svn/trunk@7671 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 22.5 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: ipid.cc,v 1.70 2005-01-18 15:41:58 Singular Exp $ */
5
6/*
7* ABSTRACT: identfier handling
8*/
9
10#include <string.h>
11
12#include "mod2.h"
13#include "static.h"
14#include "omalloc.h"
15#include "tok.h"
16#include "ipshell.h"
17#include "intvec.h"
18#include "febase.h"
19#include "numbers.h"
20#include "polys.h"
21#include "ring.h"
22#include "ideals.h"
23#include "matpol.h"
24#include "lists.h"
25#include "attrib.h"
26#include "silink.h"
27#include "syz.h"
28#include "ipid.h"
29
30#ifdef HAVE_DYNAMIC_LOADING
31#include "mod_raw.h"
32#endif /* HAVE_DYNAMIC_LOADING */
33
34omBin sip_command_bin = omGetSpecBin(sizeof(sip_command));
35omBin ip_command_bin = omGetSpecBin(sizeof(ip_command));
36omBin sip_package_bin = omGetSpecBin(sizeof(sip_package));
37omBin ip_package_bin = omGetSpecBin(sizeof(ip_package));
38omBin idrec_bin = omGetSpecBin(sizeof(idrec));
39
40proclevel *procstack=NULL;
41#define TEST
42idhdl idroot = NULL;
43
44#ifdef HAVE_NS
45idhdl currPackHdl = NULL;
46idhdl basePackHdl = NULL;
47package currPack =NULL;
48package basePack =NULL;
49#endif /* HAVE_NS */
50idhdl currRingHdl = NULL;
51ring  currRing = NULL;
52ideal currQuotient = NULL;
53char* iiNoName="_";
54
55void paCleanUp(package pack);
56
57/*0 implementation*/
58
59idhdl idrec::get(const char * s, int lev)
60{
61  assume(s!=NULL);
62  assume((lev>=0) && (lev<1000)); //not really, but if it isnt in that bounds..
63  idhdl h = this;
64  idhdl found=NULL;
65  int l;
66  char *id;
67  if (s[1]=='\0')
68  {
69    while (h!=NULL)
70    {
71      omCheckAddr(IDID(h));
72// =============================================================
73#if 0
74// timings: ratchwum: 515 s, wilde13: 373 s, nepomuck: 267 s, lukas 863 s
75    id=IDID(h);
76    l=IDLEV(h);
77    if ((l==0) && (*(short *)s==*(short *)id) && (0 == strcmp(s+1,id+1)))
78    {
79      found=h;
80    }
81    else if ((l==lev) && (*(short *)s==*(short *)id) && (0 == strcmp(s+1,id+1)))
82    {
83      return h;
84    }
85#endif
86// =============================================================
87#if 0
88// timings: ratchwum: 515 s, wilde13: 398 s, nepomuck: 269 s, lukas 834 s
89    id=IDID(h);
90    if (*(short *)s==*(short *)id)
91    {
92      l=IDLEV(h);
93      if ((l==0) && (0 == strcmp(s+1,id+1)))
94      {
95        found=h;
96      }
97      else if ((l==lev) && (0 == strcmp(s+1,id+1)))
98      {
99        return h;
100      }
101    }
102#endif
103// =============================================================
104#if 1
105// timings: ratchwum: 501 s, wilde13: 357 s, nepomuck: 267 s, lukas 816 s
106// timings bug4: ratchwum: s, wilde13: s, nepomuck: 379.74 s, lukas s
107    l=IDLEV(h);
108    if ((l==0)||(l==lev))
109    {
110      id=IDID(h);
111      if (*(short *)s==*(short *)id)
112      {
113        if (0 == strcmp(s+1,id+1))
114        {
115          if (l==lev) return h;
116          found=h;
117        }
118      }
119    }
120#endif
121// =============================================================
122#if 0
123// timings: ratchwum: s, wilde13: s, nepomuck: s, lukas s
124// timings bug4: ratchwum: s, wilde13: s, nepomuck: s, lukas s
125    l=IDLEV(h);
126    if ((l==0)||(l==lev))
127    {
128      id=IDID(h);
129      if (*(short *)s==*(short *)id)
130      {
131        if (l==lev) return h;
132        found=h;
133      }
134    }
135#endif
136// =============================================================
137    h = IDNEXT(h);
138  }
139  }
140  else
141  {
142  while (h!=NULL)
143  {
144    omCheckAddr(IDID(h));
145// =============================================================
146#if 0
147// timings: ratchwum: 515 s, wilde13: 373 s, nepomuck: 267 s, lukas 863 s
148    id=IDID(h);
149    l=IDLEV(h);
150    if ((l==0) && (*(short *)s==*(short *)id) && (0 == strcmp(s+1,id+1)))
151    {
152      found=h;
153    }
154    else if ((l==lev) && (*(short *)s==*(short *)id) && (0 == strcmp(s+1,id+1)))
155    {
156      return h;
157    }
158#endif
159// =============================================================
160#if 0
161// timings: ratchwum: 515 s, wilde13: 398 s, nepomuck: 269 s, lukas 834 s
162    id=IDID(h);
163    if (*(short *)s==*(short *)id)
164    {
165      l=IDLEV(h);
166      if ((l==0) && (0 == strcmp(s+1,id+1)))
167      {
168        found=h;
169      }
170      else if ((l==lev) && (0 == strcmp(s+1,id+1)))
171      {
172        return h;
173      }
174    }
175#endif
176// =============================================================
177#if 0
178// timings: ratchwum: 501 s, wilde13: 357 s, nepomuck: 267 s, lukas 816 s
179// timings bug4: ratchwum: s, wilde13: s, nepomuck: 379.74 s, lukas s
180    l=IDLEV(h);
181    if ((l==0)||(l==lev))
182    {
183      id=IDID(h);
184      if (*(short *)s==*(short *)id)
185      {
186        if (0 == strcmp(s+1,id+1))
187        {
188          if (l==lev) return h;
189          found=h;
190        }
191      }
192    }
193#endif
194// =============================================================
195#if 1
196// timings: ratchwum: s, wilde13: s, nepomuck: s, lukas s
197// timings bug4: ratchwum: s, wilde13: s, nepomuck: s, lukas s
198    l=IDLEV(h);
199    if ((l==0)||(l==lev))
200    {
201      id=IDID(h);
202      if (*(short *)s==*(short *)id)
203      {
204        if (0 == strcmp(s+2,id+2))
205        {
206          if (l==lev) return h;
207          found=h;
208        }
209      }
210    }
211#endif
212// =============================================================
213    h = IDNEXT(h);
214  }
215  }
216  return found;
217}
218
219//idrec::~idrec()
220//{
221//  if (id!=NULL)
222//  {
223//    omFree((ADDRESS)id);
224//    id=NULL;
225//  }
226//  /* much more !! */
227//}
228
229idhdl idrec::set(char * s, int lev, idtyp t, BOOLEAN init)
230{
231  //printf("define %s, %x, lev: %d, typ: %d\n", s,s,lev,t);
232  idhdl h = (idrec *)omAlloc0Bin(idrec_bin);
233  int   len = 0;
234  IDID(h)   = s;
235  IDTYP(h)  = t;
236  IDLEV(h)  = lev;
237  IDNEXT(h) = this;
238  if (init)
239  {
240    switch (t)
241    {
242      //the type with init routines:
243      case INTVEC_CMD:
244      case INTMAT_CMD:
245        IDINTVEC(h) = new intvec();
246        break;
247      case NUMBER_CMD:
248        IDNUMBER(h) = nInit(0);
249        break;
250      case IDEAL_CMD:
251      case MODUL_CMD:
252        IDFLAG(h) = Sy_bit(FLAG_STD);
253      case MATRIX_CMD:
254        IDIDEAL(h) = idInit(1,1);
255        break;
256      case MAP_CMD:
257        IDIDEAL(h) = idInit(1,1);
258        IDMAP(h)->preimage = omStrDup(IDID(currRingHdl));
259        break;
260      case STRING_CMD:
261        IDSTRING(h) = omStrDup("");
262        break;
263      case LIST_CMD:
264        IDLIST(h)=(lists)omAllocBin(slists_bin);
265        IDLIST(h)->Init();
266        break;
267      case LINK_CMD:
268        IDLINK(h)=(si_link) omAlloc0Bin(sip_link_bin);
269        break;
270      case RING_CMD:
271      case QRING_CMD:
272        IDRING(h) = (ring) omAlloc0Bin(sip_sring_bin);
273        break;
274      case PACKAGE_CMD:
275        IDPACKAGE(h) = (package) omAlloc0Bin(sip_package_bin);
276        break;
277      case PROC_CMD:
278        IDPROC(h) = (procinfo*) omAlloc0Bin(procinfo_bin);
279        break;
280        //the types with the standard init: set the struct to zero
281      case RESOLUTION_CMD:
282        len=sizeof(ssyStrategy);
283        break;
284    //other types: without init (int,script,poly,def,package)
285    }
286    if (len!=0)
287    {
288      IDSTRING(h) = (char *)omAlloc0(len);
289    }
290    // additional settings:--------------------------------------
291#if 0
292    // this leads to a memory leak
293    if (t == QRING_CMD)
294    {
295      // IDRING(h)=rCopy(currRing);
296      /* QRING_CMD is ring dep => currRing !=NULL */
297    }
298    else
299#endif
300      if (t == PROC_CMD)
301    {
302      IDPROC(h)->language=LANG_NONE;
303    }
304    else if (t == PACKAGE_CMD)
305    {
306      IDPACKAGE(h)->language=LANG_NONE;
307      IDPACKAGE(h)->loaded = FALSE;
308    }
309  }
310  // --------------------------------------------------------
311  return  h;
312}
313
314char * idrec::String()
315{
316  sleftv tmp;
317  memset(&tmp,0,sizeof(sleftv));
318  tmp.rtyp=IDTYP(this);
319  tmp.data=IDDATA(this);
320  tmp.name=IDID(this);
321  return tmp.String();
322}
323
324//#define KAI
325idhdl enterid(char * s, int lev, idtyp t, idhdl* root, BOOLEAN init)
326{
327  idhdl h;
328  s=omStrDup(s);
329  // is it already defined in root ?
330  if ((h=(*root)->get(s,lev))!=NULL)
331  {
332    if (IDLEV(h)==lev)
333    {
334    if ((IDTYP(h) == t)||(t==DEF_CMD))
335    {
336      if ((IDTYP(h)==PACKAGE_CMD)
337      && (strcmp(s,"Top")==0))
338      {
339        goto errlabel;
340      } 
341      if (BVERBOSE(V_REDEFINE))
342        Warn("redefining %s **",s);
343      if (s==IDID(h)) IDID(h)=NULL;
344      killhdl2(h,root,currRing);
345    }
346    else
347      goto errlabel;
348    }
349  }
350  // is it already defined in idroot ?
351  else if (*root != IDROOT)
352  {
353    if ((h=IDROOT->get(s,lev))!=NULL)
354    {
355      if (IDLEV(h)==lev)
356      {
357      if ((IDTYP(h) == t)||(t==DEF_CMD))
358      {
359        if (BVERBOSE(V_REDEFINE))
360          Warn("redefining %s **",s);
361        if (s==IDID(h)) IDID(h)=NULL;
362        killhdl2(h,&IDROOT,NULL);
363      }
364      else
365        goto errlabel;
366      }
367    }
368  }
369  // is it already defined in currRing->idroot ?
370  else if ((currRing!=NULL)&&((*root) != currRing->idroot))
371  {
372    if ((h=currRing->idroot->get(s,lev))!=NULL)
373    {
374      if (IDLEV(h)==lev)
375      {
376      if ((IDTYP(h) == t)||(t==DEF_CMD))
377      {
378        if (BVERBOSE(V_REDEFINE))
379          Warn("redefining %s **",s);
380        IDID(h)=NULL;
381        killhdl2(h,&currRing->idroot,currRing);
382      }
383      else
384        goto errlabel;
385      }
386    }
387  }
388  *root = (*root)->set(s, lev, t, init);
389#ifdef HAVE_NS
390  checkall();
391#endif
392  return *root;
393
394  errlabel:
395    //Werror("identifier `%s` in use(lev h=%d,typ=%d,t=%d, curr=%d)",s,IDLEV(h),IDTYP(h),t,lev);
396    Werror("identifier `%s` in use",s);
397#ifdef HAVE_NS
398    //listall();
399#endif
400    omFree(s);
401    return NULL;
402}
403
404void killid(char * id, idhdl * ih)
405{
406  if (id!=NULL)
407  {
408    idhdl h = (*ih)->get(id,myynest);
409
410    // id not found in global list, is it defined in current ring ?
411    if (h==NULL)
412    {
413      if ((currRing!=NULL) && (*ih != (currRing->idroot)))
414      {
415        h = currRing->idroot->get(id,myynest);
416        if (h!=NULL)
417        {
418          killhdl2(h,&(currRing->idroot),currRing);
419          return;
420        }
421      }
422      Werror("`%s` is not defined",id);
423      return;
424    }
425    killhdl2(h,ih,currRing);
426  }
427  else
428    Werror("kill what ?");
429}
430
431void killhdl(idhdl h)
432{
433  int t=IDTYP(h);
434  if ((BEGIN_RING<t) && (t<END_RING) && (t!=QRING_CMD))
435    killhdl2(h,&currRing->idroot,currRing);
436  else
437  {
438#ifdef HAVE_NS
439    if(t==PACKAGE_CMD)
440    {
441      killhdl2(h,&(basePack->idroot),NULL);
442    }
443    else
444    {
445      idhdl s=currPack->idroot;
446      while ((s!=h) && (s!=NULL)) s=s->next;
447      if (s!=NULL)
448        killhdl2(h,&(currPack->idroot),NULL);
449      else if (basePack!=currPack)
450      {
451        idhdl s=basePack->idroot;
452        while ((s!=h) && (s!=NULL)) s=s->next;
453        if (s!=NULL)
454          killhdl2(h,&(basePack->idroot),currRing);
455        else
456          killhdl2(h,&(currRing->idroot),currRing);
457       }
458    }
459#else /* HAVE_NS */
460    {
461      idhdl s=IDROOT;
462      while ((s!=h) && (s!=NULL)) s=s->next;
463      if (s==NULL) killhdl2(h,&(currRing->idroot),currRing);
464      else killhdl2(h,&IDROOT,currRing);
465    }
466#endif /* HAVE_NS */
467  }
468}
469
470#ifdef HAVE_NS
471void killhdl(idhdl h, package proot)
472{
473  int t=IDTYP(h);
474  if ((BEGIN_RING<t) && (t<END_RING) && (t!=QRING_CMD))
475    killhdl2(h,&currRing->idroot,currRing);
476  else
477  {
478    if(t==PACKAGE_CMD)
479    {
480      killhdl2(h,&(basePack->idroot),NULL);
481    }
482    else
483    {
484      idhdl s=proot->idroot;
485      while ((s!=h) && (s!=NULL)) s=s->next;
486      if (s!=NULL)
487        killhdl2(h,&(proot->idroot),NULL);
488      else if (basePack!=proot)
489      {
490        idhdl s=basePack->idroot;
491        while ((s!=h) && (s!=NULL)) s=s->next;
492        if (s!=NULL)
493          killhdl2(h,&(basePack->idroot),currRing);
494        else
495          killhdl2(h,&(currRing->idroot),currRing);
496       }
497    }
498  }
499}
500#endif /* HAVE_NS */
501
502void killhdl2(idhdl h, idhdl * ih, ring r)
503{
504  //printf("kill %s, id %x, typ %d lev: %d\n",IDID(h),(int)IDID(h),IDTYP(h),IDLEV(h));
505  idhdl hh;
506
507  if (h->attribute!=NULL)
508  {
509    atKillAll(h);
510    //h->attribute=NULL;
511  }
512  if ((IDTYP(h) == PACKAGE_CMD) && (strcmp(IDID(h),"Top")==0))
513  {
514    WarnS("can not kill `Top`");
515    return;
516  }
517  // ring / qring  --------------------------------------------------------
518  if ((IDTYP(h) == RING_CMD) || (IDTYP(h) == QRING_CMD))
519  {
520    // any objects defined for this ring ?
521    // Hmm ... why only for rings and not for qrings??
522    // if (((IDTYP(h)==RING_CMD) && (IDRING(h)->ref<=0))
523    if ((IDRING(h)->ref<=0)  &&  (IDRING(h)->idroot!=NULL))
524    {
525      idhdl * hd = &IDRING(h)->idroot;
526      idhdl  hdh = IDNEXT(*hd);
527      idhdl  temp;
528      if (IDRING(h)==currRing) //we are not killing the base ring, so switch
529      {
530        // we are killing the basering, so: make sure that
531        // sLastPrinted is killed before this ring is destroyed
532        if (((sLastPrinted.rtyp>BEGIN_RING) && (sLastPrinted.rtyp<END_RING))
533        || ((sLastPrinted.rtyp==LIST_CMD)&&(lRingDependend((lists)sLastPrinted.data))))
534        {
535          sLastPrinted.CleanUp();
536        }
537      }
538      while (hdh!=NULL)
539      {
540        temp = IDNEXT(hdh);
541        killhdl2(hdh,&(IDRING(h)->idroot),IDRING(h));
542        hdh = temp;
543      }
544      killhdl2(*hd,hd,IDRING(h));
545    }
546    rKill(h);
547  }
548#ifdef HAVE_NS
549  // package -------------------------------------------------------------
550  else if (IDTYP(h) == PACKAGE_CMD)
551  {
552    // any objects defined for this package ?
553    if ((IDPACKAGE(h)->ref<=0)  &&  (IDPACKAGE(h)->idroot!=NULL))
554    {
555      if (currPack==IDPACKAGE(h))
556      {
557        currPack=basePack;
558        currPackHdl=NULL;
559      }
560      idhdl * hd = &IDRING(h)->idroot;
561      idhdl  hdh = IDNEXT(*hd);
562      idhdl  temp;
563      while (hdh!=NULL)
564      {
565        temp = IDNEXT(hdh);
566        killhdl2(hdh,&(IDPACKAGE(h)->idroot),NULL);
567        hdh = temp;
568      }
569      killhdl2(*hd,hd,NULL);
570    }
571    paKill(IDPACKAGE(h));
572    if (currPackHdl==h) currPackHdl=packFindHdl(currPack);
573    iiCheckPack(currPack);
574  }
575#endif /* HAVE_NS */
576  // poly / vector -------------------------------------------------------
577  else if ((IDTYP(h) == POLY_CMD) || (IDTYP(h) == VECTOR_CMD))
578  {
579    assume(r!=NULL);
580    p_Delete(&IDPOLY(h),r);
581  }
582  // ideal / module/ matrix / map ----------------------------------------
583  else if ((IDTYP(h) == IDEAL_CMD)
584           || (IDTYP(h) == MODUL_CMD)
585           || (IDTYP(h) == MATRIX_CMD)
586           || (IDTYP(h) == MAP_CMD))
587  {
588    assume(r!=NULL);
589    ideal iid = IDIDEAL(h);
590    if (IDTYP(h) == MAP_CMD)
591    {
592      map im = IDMAP(h);
593      omFree((ADDRESS)im->preimage);
594    }
595    id_Delete(&iid,r);
596  }
597  // string -------------------------------------------------------------
598  else if (IDTYP(h) == STRING_CMD)
599  {
600    omFree((ADDRESS)IDSTRING(h));
601    //IDSTRING(h)=NULL;
602  }
603  // proc ---------------------------------------------------------------
604  else if (IDTYP(h) == PROC_CMD)
605  {
606    if (piKill(IDPROC(h))) return;
607  }
608  // number -------------------------------------------------------------
609  else if (IDTYP(h) == NUMBER_CMD)
610  {
611    assume(r!=NULL);
612    n_Delete(&IDNUMBER(h),r);
613  }
614  // intvec / intmat  ---------------------------------------------------
615  else if ((IDTYP(h) == INTVEC_CMD)||(IDTYP(h) == INTMAT_CMD))
616  {
617    delete IDINTVEC(h);
618  }
619  // list  -------------------------------------------------------------
620  else if (IDTYP(h)==LIST_CMD)
621  {
622    IDLIST(h)->Clean(r);
623    //omFreeSize((ADDRESS)IDLIST(h)->m, (IDLIST(h)->nr+1)*sizeof(sleftv));
624    //omFreeBin((ADDRESS)IDLIST(h),  slists_bin);
625  }
626  // link  -------------------------------------------------------------
627  else if (IDTYP(h)==LINK_CMD)
628  {
629    slKill(IDLINK(h));
630  }
631  else if(IDTYP(h)==RESOLUTION_CMD)
632  {
633    assume(r!=NULL);
634    if (IDDATA(h)!=NULL)
635      syKillComputation((syStrategy)IDDATA(h),r);
636  }
637#ifdef TEST
638  else if ((IDTYP(h)!= INT_CMD)&&(IDTYP(h)!=DEF_CMD) && (IDTYP(h)!=NONE))
639    Warn("unknown type to kill: %s(%d)",Tok2Cmdname(IDTYP(h)),IDTYP(h));
640#endif
641
642  //  general  -------------------------------------------------------------
643  // now dechain it and delete idrec
644#ifdef KAI
645  if(h->next != NULL)
646    Print("=======>%s(%x) -> %s<====\n", IDID(h), IDID(h), IDID(h->next));
647  else
648    Print("=======>%s(%x)<====\n", IDID(h), IDID(h));
649#endif
650
651  if (IDID(h)) // OB: ?????
652    omFree((ADDRESS)IDID(h));
653  IDID(h)=NULL;
654  IDDATA(h)=NULL;
655  if (h == (*ih))
656  {
657    // h is at the beginning of the list
658    *ih = IDNEXT(h) /* ==*ih */;
659  }
660  else if (ih!=NULL)
661  {
662    // h is somethere in the list:
663    hh = *ih;
664    loop
665    {
666      if (hh==NULL)
667      {
668        PrintS(">>?<< not found for kill\n");
669        return;
670      }
671      idhdl hhh = IDNEXT(hh);
672      if (hhh == h)
673      {
674        IDNEXT(hh) = IDNEXT(hhh);
675        break;
676      }
677      hh = hhh;
678    }
679  }
680  omFreeBin((ADDRESS)h, idrec_bin);
681}
682
683idhdl ggetid(const char *n, BOOLEAN local, idhdl *packhdl)
684{
685  idhdl h = IDROOT->get(n,myynest);
686  idhdl h2=NULL;
687  *packhdl = NULL;
688  if ((currRing!=NULL) && ((h==NULL)||(IDLEV(h)!=myynest)))
689  {
690    h2 = currRing->idroot->get(n,myynest);
691  }
692  if (h2==NULL) return h;
693  return h2;
694}
695
696idhdl ggetid(const char *n, BOOLEAN local)
697{
698  idhdl h = IDROOT->get(n,myynest);
699  if ((h!=NULL)&&(IDLEV(h)==myynest)) return h;
700  idhdl h2=NULL;
701  if (currRing!=NULL)
702  {
703    h2 = currRing->idroot->get(n,myynest);
704  }
705  if (h2!=NULL) return h2;
706  if (h!=NULL) return h;
707#ifdef HAVE_NS 
708  if (basePack!=currPack)
709    return basePack->idroot->get(n,myynest);
710#endif     
711  return NULL; 
712}
713
714void ipListFlag(idhdl h)
715{
716  if (hasFlag(h,FLAG_STD)) PrintS(" (SB)");
717#ifdef HAVE_PLURAL 
718  if (hasFlag(h,FLAG_TWOSTD)) PrintS(" (2SB)");
719#endif 
720}
721
722lists ipNameList(idhdl root)
723{
724  idhdl h=root;
725  /* compute the length */
726  int l=0;
727  while (h!=NULL) { l++; h=IDNEXT(h); }
728  /* allocate list */
729  lists L=(lists)omAllocBin(slists_bin);
730  L->Init(l);
731  /* copy names */
732  h=root;
733  l=0;
734  while (h!=NULL)
735  {
736    /* list is initialized with 0 => no need to clear anything */
737    L->m[l].rtyp=STRING_CMD;
738    L->m[l].data=omStrDup(IDID(h));
739    l++;
740    h=IDNEXT(h);
741  }
742  return L;
743}
744
745/*
746* move 'tomove' from root1 list to root2 list
747*/
748static int ipSwapId(idhdl tomove, idhdl &root1, idhdl &root2)
749{
750  idhdl h;
751  /* search 'tomove' in root2 : if found -> do nothing */
752  h=root2;
753  while ((h!=NULL) && (h!=tomove)) h=IDNEXT(h);
754  if (h!=NULL) return FALSE; /*okay */
755  /* search predecessor of h in root1, remove 'tomove' */
756  h=root1;
757  if (tomove==h)
758  {
759    root1=IDNEXT(h);
760  }
761  else
762  {
763    while ((h!=NULL) && (IDNEXT(h)!=tomove)) h=IDNEXT(h);
764    if (h==NULL) return TRUE; /* not in the list root1 -> do nothing */
765    IDNEXT(h)=IDNEXT(tomove);
766  }
767  /* add to root2 list */
768  IDNEXT(tomove)=root2;
769  root2=tomove;
770  return FALSE;
771}
772
773void  ipMoveId(idhdl tomove)
774{
775  if ((currRing!=NULL)&&(tomove!=NULL))
776  {
777    if (((QRING_CMD!=IDTYP(tomove)) && RingDependend(IDTYP(tomove)))
778    || ((IDTYP(tomove)==LIST_CMD) && (lRingDependend(IDLIST(tomove)))))
779    {
780      /*move 'tomove' to ring id's*/
781#ifdef HAVE_NS
782      if (ipSwapId(tomove,IDROOT,currRing->idroot))
783      ipSwapId(tomove,basePack->idroot,currRing->idroot);
784#else
785      ipSwapId(tomove,IDROOT,currRing->idroot);
786#endif
787    }
788    else
789    {
790      /*move 'tomove' to global id's*/
791      ipSwapId(tomove,currRing->idroot,IDROOT);
792    }
793  }
794}
795
796char * piProcinfo(procinfov pi, char *request)
797{
798  if(pi == NULL) return "empty proc";
799  else if (strcmp(request, "libname")  == 0) return pi->libname;
800  else if (strcmp(request, "procname") == 0) return pi->procname;
801  else if (strcmp(request, "type")     == 0)
802  {
803    switch (pi->language)
804    {
805      case LANG_SINGULAR: return "singular"; break;
806      case LANG_C:        return "object";   break;
807      case LANG_NONE:     return "none";     break;
808      default:            return "unknow language";
809    }
810  }
811  else if (strcmp(request, "ref")      == 0)
812  {
813    char p[8];
814    sprintf(p, "%d", pi->ref);
815    return omStrDup(p);  // MEMORY-LEAK
816  }
817  return "??";
818}
819
820void piCleanUp(procinfov pi)
821{
822  (pi->ref)--;
823  if (pi->ref <= 0)
824  {
825    if (pi->libname != NULL) // OB: ????
826      omFree((ADDRESS)pi->libname);
827    if (pi->procname != NULL) // OB: ????
828      omFree((ADDRESS)pi->procname);
829
830    if( pi->language == LANG_SINGULAR)
831    {
832      if (pi->data.s.body != NULL) // OB: ????
833        omFree((ADDRESS)pi->data.s.body);
834    }
835    if( pi->language == LANG_C)
836    {
837    }
838    memset((void *) pi, 0, sizeof(procinfo));
839    pi->language=LANG_NONE;
840  }
841}
842
843BOOLEAN piKill(procinfov pi)
844{
845  Voice *p=currentVoice;
846  while (p!=NULL)
847  {
848    if (p->pi==pi && pi->ref <= 1)
849    {
850      Warn("`%s` in use, can not be killed",pi->procname);
851      return TRUE;
852    }
853    p=p->next;
854  }
855  piCleanUp(pi);
856  if (pi->ref <= 0)
857    omFreeBin((ADDRESS)pi,  procinfo_bin);
858  return FALSE;
859}
860
861void paCleanUp(package pack)
862{
863  (pack->ref)--;
864  if (pack->ref < 0)
865  {
866#ifndef HAVE_STATIC
867    if( pack->language == LANG_C)
868    {
869      Print("//dlclose(%s)\n",pack->libname);
870#ifdef HAVE_DYNAMIC_LOADING
871      dynl_close (pack->handle);
872#endif /* HAVE_DYNAMIC_LOADING */
873    }
874#endif /* HAVE_STATIC */
875    omfree((ADDRESS)pack->libname);
876    memset((void *) pack, 0, sizeof(sip_package));
877    pack->language=LANG_NONE;
878  }
879}
880
881char *idhdl2id(idhdl pck, idhdl h)
882{
883  char *name = (char *)omAlloc(strlen(pck->id) + strlen(h->id) + 3);
884  sprintf(name, "%s::%s", pck->id, h->id);
885  return(name);
886}
887
888void iiname2hdl(const char *name, idhdl *pck, idhdl *h)
889{
890  const char *q = strchr(name, ':');
891  char *p, *i;
892
893  if(q==NULL)
894  {
895    p = omStrDup("");
896    i = (char *)omAlloc(strlen(name)+1);
897    *i = '\0';
898    sscanf(name, "%s", i);
899  }
900  else {
901    if( *(q+1) != ':') return;
902    i = (char *)omAlloc(strlen(name)+1);
903    *i = '\0';
904    if(name == q)
905    {
906      p = omStrDup("");
907      sscanf(name, "::%s", i);
908    }
909    else
910    {
911      p = (char *)omAlloc(strlen(name)+1);
912      sscanf(name, "%[^:]::%s", p, i);
913    }
914  }
915  //printf("Package: '%s'\n", p);
916  //printf("Id Rec : '%s'\n", i);
917  omFree(p);
918  omFree(i);
919}
920
921#if 0
922char *getnamelev()
923{
924  char buf[256];
925  sprintf(buf, "(%s:%d)", namespaceroot->name,namespaceroot->lev);
926  return(buf);
927}
928// warning: address of local variable `buf' returned
929#endif
930
931void proclevel::push(char *n)
932{
933  //Print("push %s\n",n);
934  proclevel *p=(proclevel*)omAlloc0(sizeof(proclevel));
935  p->cRing=currRing;
936  p->cRingHdl=currRingHdl;
937  p->name=n;
938  #ifdef HAVE_NS
939  p->cPackHdl=currPackHdl;
940  p->cPack=currPack;
941  #endif
942  p->next=this;
943  procstack=p;
944}
945void proclevel::pop()
946{
947  //Print("pop %s\n",name);
948  //if (currRing!=::currRing) PrintS("currRing wrong\n");;
949  //::currRing=this->currRing;
950  //if (r==NULL) Print("set ring to NULL at lev %d(%s)\n",myynest,name);
951  //::currRingHdl=this->currRingHdl;
952  //if((::currRingHdl==NULL)||(IDRING(::currRingHdl)!=(::currRing)))
953  //  ::currRingHdl=rFindHdl(::currRing,NULL,NULL);
954  #ifdef HAVE_NS
955  //Print("restore pack=%s,1.obj=%s\n",IDID(currPackHdl),IDID(currPack->idroot));
956  currPackHdl=this->cPackHdl;
957  currPack=this->cPack;
958  iiCheckPack(currPack);
959  #endif
960  proclevel *p=this;
961  procstack=next;
962  omFreeSize(p,sizeof(proclevel));
963}
964
965#ifdef HAVE_NS
966idhdl packFindHdl(package r)
967{
968  idhdl h=basePack->idroot;
969  while (h!=NULL)
970  {
971    if ((IDTYP(h)==PACKAGE_CMD)
972        && (IDPACKAGE(h)==r))
973      return h;
974    h=IDNEXT(h);
975  }
976  return NULL;
977}
978#endif
Note: See TracBrowser for help on using the repository browser.