source: git/Singular/attrib.cc @ 3cbcea

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