source: git/Singular/attrib.cc @ 6c22988

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