source: git/Singular/attrib.cc @ 5835ba4

fieker-DuValspielwiese
Last change on this file since 5835ba4 was 0fb34ba, checked in by Hans Schoenemann <hannes@…>, 13 years ago
start with dir Singular: fix includes and makefile
  • Property mode set to 100644
File size: 8.9 KB
RevLine 
[0e1846]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
[341696]4/* $Id$ */
[74f19d]5
[0e1846]6/*
[e2f1c7]7* ABSTRACT: attributes to leftv and idhdl
[0e1846]8*/
9
10#include <stdlib.h>
11#include <stdio.h>
12#include <string.h>
13#include <ctype.h>
14#include <unistd.h>
15
[b1dfaf]16#include <kernel/mod2.h>
17#include <omalloc/omalloc.h>
[0fb34ba]18#include <misc/options.h>
[599326]19#include <Singular/tok.h>
20#include <Singular/ipid.h>
[0fb34ba]21#include <misc/intvec.h>
22#include <polys/polys.h>
[599326]23#include <kernel/ideals.h>
[0fb34ba]24#include <polys/matpol.h>
[599326]25#include <Singular/ipshell.h>
26#include <Singular/attrib.h>
[c232af]27
28static omBin sattr_bin = omGetSpecBin(sizeof(sattr));
[0e1846]29
30void sattr::Print()
31{
[c232af]32  omCheckAddrSize(this,sizeof(sattr));
[0e1846]33  ::Print("attr:%s, type %s \n",name,Tok2Cmdname(atyp));
34  if (next!=NULL) next->Print();
35}
36
37attr sattr::Copy()
38{
[c227a2f]39  if (this!=NULL)
40  {
41    omCheckAddrSize(this,sizeof(sattr));
42    attr n=(attr)omAlloc0Bin(sattr_bin);
43    n->atyp=atyp;
44    if (name!=NULL) n->name=omStrDup(name);
45    n->data=CopyA();
46    if (next!=NULL)
47    {
48      n->next=next->Copy();
49    }
50    return n;
[0e1846]51  }
[c227a2f]52  else
53    return NULL;
[0e1846]54}
55
[f71681]56// in subexr.cc:
57//void * sattr::CopyA()
58//{
59//  omCheckAddrSize(this,sizeof(sattr));
60//  return s_internalCopy(atyp,data);
61//}
[0e1846]62
[3aa622a]63static void attr_free(attr h, const ring r=currRing)
64{
[c4dab4]65  s_internalDelete(h->atyp,h->data,r);
[3aa622a]66  h->data=NULL;
67}
68
[5f4463]69attr sattr::set(const char * s, void * d, int t)
[0e1846]70{
71  attr h = get(s);
[3aa622a]72  attr result=this;
[0e1846]73  if (h!=NULL)
74  {
[3aa622a]75    attr_free(h);
[0e1846]76  }
77  else
78  {
[3aa622a]79    h = (attr)omAlloc0Bin(sattr_bin);
80    h->next = this;
81    result=h;
[0e1846]82  }
[3aa622a]83  h->name = s;
[5f4463]84  h->data = d;
[0e1846]85  h->atyp = t;
[35b6ca]86#ifdef TEST
[57c64ff]87  //::Print("set attr >>%s<< of type %s\n",h->name, Tok2Cmdname(t));
[35b6ca]88#endif
[3aa622a]89  return  result;
[0e1846]90}
91
[85e68dd]92attr sattr::get(const char * s)
[0e1846]93{
94  attr h = this;
95  while (h!=NULL)
96  {
[c227a2f]97    if (0 == strcmp(s,h->name))
98    {
[35b6ca]99#ifdef TEST
[57c64ff]100      //::Print("get attr >>%s<< of type %s\n",h->name, Tok2Cmdname(h->atyp));
[35b6ca]101#endif
102      return h;
103    }
[0e1846]104    h = h->next;
105  }
106  return NULL;
107}
108
[85e68dd]109void * atGet(idhdl root,const char * name)
[0e1846]110{
111  attr temp = root->attribute->get(name);
112  if (temp!=NULL)
113    return temp->data;
114  else
115    return NULL;
116}
117
[85e68dd]118void * atGet(leftv root,const char * name)
[0e1846]119{
[71df1a]120  attr temp;
[c227a2f]121  attr a=*(root->Attribute());
122  temp = a->get(name);
[0e1846]123  if (temp!=NULL)
124    return temp->data;
125  else
126    return NULL;
127}
128
[85e68dd]129void * atGet(idhdl root,const char * name, int t)
[242d8f]130{
131  attr temp = root->attribute->get(name);
132  if ((temp!=NULL) && (temp->atyp==t))
133    return temp->data;
134  else
135    return NULL;
136}
137
[85e68dd]138void * atGet(leftv root,const char * name, int t)
[242d8f]139{
[c227a2f]140  attr a=*(root->Attribute());
141  attr temp = a->get(name);
[242d8f]142  if ((temp!=NULL) && (temp->atyp==t))
143    return temp->data;
144  else
145    return NULL;
146}
147
[85e68dd]148void atSet(idhdl root,const char * name,void * data,int typ)
[0e1846]149{
150  if (root!=NULL)
151  {
[c4dab4]152    if ((IDTYP(root)!=RING_CMD)
153    && (IDTYP(root)!=QRING_CMD)
154    && (!RingDependend(IDTYP(root)))&&(RingDependend(typ)))
155      WerrorS("cannot set ring-dependend objects at this type");
[c227a2f]156    else
[c4dab4]157      root->attribute=root->attribute->set(name,data,typ);
[0e1846]158  }
159}
160
[85e68dd]161void atSet(leftv root,const char * name,void * data,int typ)
[0e1846]162{
163  if (root!=NULL)
164  {
[c227a2f]165    attr *a=root->Attribute();
166    int rt=root->Typ();
167    if ((rt!=RING_CMD)
168    && (rt!=QRING_CMD)
169    && (!RingDependend(rt))&&(RingDependend(typ)))
170      WerrorS("cannot set ring-dependend objects at this type");
[0e1846]171    else
172    {
[c227a2f]173      *a=(*a)->set(name,data,typ);
[0e1846]174    }
175  }
176}
177
[2dbaba4]178void sattr::kill(const ring r)
[0e1846]179{
[35b6ca]180  attr_free(this,r);
[c232af]181  omFree((ADDRESS)name);
[0e1846]182  name=NULL;
[c232af]183  omFreeBin((ADDRESS)this, sattr_bin);
[0e1846]184}
185
[2dbaba4]186void sattr::killAll(const ring r)
[0e1846]187{
188  attr temp = this,temp1;
189
190  while (temp!=NULL)
191  {
192    temp1 = temp->next;
[c4dab4]193    omCheckAddr(temp);
[2dbaba4]194    temp->kill(r);
[0e1846]195    temp = temp1;
196  }
197}
198
[2dbaba4]199void at_Kill(idhdl root,const char * name, const ring r)
[0e1846]200{
201  attr temp = root->attribute->get(name);
202  if (temp!=NULL)
203  {
204    attr N = temp->next;
205    attr temp1 = root->attribute;
206    if (temp1==temp)
207    {
208      root->attribute = N;
209    }
210    else
211    {
212      while (temp1->next!=temp) temp1 = temp1->next;
213      temp1->next = N;
214    }
[2dbaba4]215    temp->kill(r);
[0e1846]216  }
217}
218
[2dbaba4]219void at_KillAll(idhdl root, const ring r)
[0e1846]220{
[2dbaba4]221  root->attribute->killAll(r);
[0e1846]222  root->attribute = NULL;
223}
[c227a2f]224void at_KillAll(leftv root, const ring r)
225{
226  root->attribute->killAll(r);
227  root->attribute = NULL;
228}
[0e1846]229
[c227a2f]230BOOLEAN atATTRIB1(leftv res,leftv v)
[0e1846]231{
[242d8f]232  int t;
[c227a2f]233  attr *aa=(v->Attribute());
234  if (aa==NULL)
[0e1846]235  {
[c227a2f]236    WerrorS("this object cannot have attributes");
237    return TRUE;
[6c22988]238  }
[c227a2f]239  attr a=*aa;
[3aa622a]240  BOOLEAN haveNoAttribute=TRUE;
[c227a2f]241  if (v->e==NULL)
[6c4db17]242  {
[c227a2f]243    if (hasFlag(v,FLAG_STD))
244    {
245      PrintS("attr:isSB, type int\n");
246      haveNoAttribute=FALSE;
247    }
248    if (hasFlag(v,FLAG_QRING))
249    {
250      PrintS("attr:qringNF, type int\n");
251      haveNoAttribute=FALSE;
252    }
253    if (((t=v->Typ())==RING_CMD)||(t==QRING_CMD))
254    {
255      PrintS("attr:global, type int\n");
256      haveNoAttribute=FALSE;
257    }
[6c4db17]258  }
[c227a2f]259  else
[242d8f]260  {
[c227a2f]261    leftv at=v->LData();
262    return atATTRIB1(res,at);
[0e1846]263  }
[c227a2f]264  if (a!=NULL)                    a->Print();
265  else  if(haveNoAttribute)       PrintS("no attributes\n");
[0e1846]266  return FALSE;
267}
[c227a2f]268BOOLEAN atATTRIB2(leftv res,leftv v,leftv b)
[0e1846]269{
270  char *name=(char *)b->Data();
[242d8f]271  int t;
[c227a2f]272  leftv at=NULL;
273  if (v->e!=NULL)
274    at=v->LData();
[0e1846]275  if (strcmp(name,"isSB")==0)
276  {
277    res->rtyp=INT_CMD;
[09bbf5]278    res->data=(void *)(long)hasFlag(v,FLAG_STD);
[c227a2f]279    if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_STD)||(hasFlag(at,FLAG_STD)));
[0e1846]280  }
281  else if ((strcmp(name,"rank")==0)&&(v->Typ()==MODUL_CMD))
282  {
283    res->rtyp=INT_CMD;
284    res->data=(void *)(((ideal)v->Data())->rank);
285  }
[242d8f]286  else if ((strcmp(name,"global")==0)
287  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
288  {
289    res->rtyp=INT_CMD;
290    res->data=(void *)(((ring)v->Data())->OrdSgn==1);
291  }
[6c4db17]292  else if (strcmp(name,"qringNF")==0)
293  {
294    res->rtyp=INT_CMD;
295    res->data=(void *)(long)hasFlag(v,FLAG_QRING);
[c227a2f]296    if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_QRING)||(hasFlag(at,FLAG_QRING)));
[6c4db17]297  }
[b27003e]298#ifdef HAVE_SHIFTBBA
299  else if ((strcmp(name,"isLPring")==0)
300  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
301  {
302    res->rtyp=INT_CMD;
[3ea5d2f]303    res->data=(void *)(long)(((ring)v->Data())->isLPring);
[b27003e]304  }
305#endif
[0e1846]306  else
307  {
[c227a2f]308    attr *aa=v->Attribute();
309    if (aa==NULL)
310    {
311      WerrorS("this object cannot have attributes");
312      return TRUE;
313    }
314    attr a=*aa;
315    a=a->get(name);
316    if (a!=NULL)
[0e1846]317    {
[c227a2f]318      res->rtyp=a->atyp;
319      res->data=a->CopyA();
[0e1846]320    }
321    else
322    {
323      res->rtyp=STRING_CMD;
[c232af]324      res->data=omStrDup("");
[0e1846]325    }
326  }
327  return FALSE;
328}
[c227a2f]329BOOLEAN atATTRIB3(leftv res,leftv v,leftv b,leftv c)
[0e1846]330{
[c227a2f]331  idhdl h=(idhdl)v->data;
[242d8f]332  int t;
[c227a2f]333  if (v->e!=NULL)
[0e1846]334  {
[c227a2f]335    v=v->LData();
[0e1846]336    if (v==NULL) return TRUE;
337    h=NULL;
338  }
[c227a2f]339  else if (v->rtyp!=IDHDL) h=NULL;
[6c22988]340
[0e1846]341  char *name=(char *)b->Data();
342  if (strcmp(name,"isSB")==0)
343  {
344    if (c->Typ()!=INT_CMD)
345    {
[b27003e]346      WerrorS("attribute isSB must be int");
[0e1846]347      return TRUE;
348    }
[7447d8]349    if (((long)c->Data())!=0L)
[0e1846]350    {
351      if (h!=NULL) setFlag(h,FLAG_STD);
352      setFlag(v,FLAG_STD);
353    }
354    else
355    {
356      if (h!=NULL) resetFlag(h,FLAG_STD);
357      resetFlag(v,FLAG_STD);
358    }
359  }
[6c4db17]360  else if (strcmp(name,"qringNF")==0)
361  {
362    if (c->Typ()!=INT_CMD)
363    {
364      WerrorS("attribute qringNF must be int");
365      return TRUE;
366    }
367    if (((long)c->Data())!=0L)
368    {
369      if (h!=NULL) setFlag(h,FLAG_QRING);
370      setFlag(v,FLAG_QRING);
371    }
372    else
373    {
374      if (h!=NULL) resetFlag(h,FLAG_QRING);
375      resetFlag(v,FLAG_QRING);
376    }
377  }
[0e1846]378  else if ((strcmp(name,"rank")==0)&&(v->Typ()==MODUL_CMD))
379  {
380    if (c->Typ()!=INT_CMD)
381    {
[b27003e]382      WerrorS("attribute `rank` must be int");
[0e1846]383      return TRUE;
384    }
385    ideal I=(ideal)v->Data();
[7447d8]386    I->rank=si_max((int)I->rank,(int)((long)c->Data()));
[0e1846]387  }
[242d8f]388  else if ((strcmp(name,"global")==0)
389  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
390  {
[b27003e]391    WerrorS("can not set attribute `global`");
[242d8f]392    return TRUE;
393  }
[b27003e]394#ifdef HAVE_SHIFTBBA
395  else if ((strcmp(name,"isLPring")==0)
396  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
397  {
398    if (c->Typ()==INT_CMD)
399      ((ring)v->Data())->isLPring=(int)(long)c->Data();
400    else
401    {
402      WerrorS("attribute `isLPring` must be int");
403      return TRUE;
404    }
405  }
406#endif
[0e1846]407  else
408  {
[2166ad3]409    int typ=c->Typ();
[6c22988]410    if (h!=NULL) atSet(h,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
411    else         atSet(v,omStrDup(name),c->CopyD(typ),typ/*c->T(yp()*/);
[0e1846]412  }
413  return FALSE;
414}
415
416BOOLEAN atKILLATTR1(leftv res,leftv a)
417{
[c227a2f]418  idhdl h=NULL;
419  if ((a->rtyp==IDHDL)&&(a->e==NULL))
[0e1846]420  {
[c227a2f]421    h=(idhdl)a->data;
422    resetFlag((idhdl)a->data,FLAG_STD);
[0e1846]423  }
424  resetFlag(a,FLAG_STD);
[c227a2f]425  if (h->attribute!=NULL)
[0e1846]426  {
[c227a2f]427    atKillAll(h);
[0e1846]428    a->attribute=NULL;
429  }
[c227a2f]430  else atKillAll(a);
[0e1846]431  return FALSE;
432}
433BOOLEAN atKILLATTR2(leftv res,leftv a,leftv b)
434{
435  if ((a->rtyp!=IDHDL)||(a->e!=NULL))
436  {
[da97958]437    WerrorS("object must have a name");
[0e1846]438    return TRUE;
439  }
440  char *name=(char *)b->Data();
441  if (strcmp(name,"isSB")==0)
442  {
443    resetFlag(a,FLAG_STD);
444    resetFlag((idhdl)a->data,FLAG_STD);
445  }
[242d8f]446  else if (strcmp(name,"global")==0)
447  {
448    WerrorS("can not set attribut `global`");
449    return TRUE;
450  }
[0e1846]451  else
452  {
453    atKill((idhdl)a->data,name);
454  }
455  return FALSE;
456}
[3aa622a]457
Note: See TracBrowser for help on using the repository browser.