source: git/Singular/attrib.cc @ ba5e9e

spielwiese
Last change on this file since ba5e9e 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
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4
5/*
6* ABSTRACT: attributes to leftv and idhdl
7*/
8
9#include <stdlib.h>
10#include <stdio.h>
11#include <string.h>
12#include <ctype.h>
13#include <unistd.h>
14
15#ifdef HAVE_CONFIG_H
16#include "singularconfig.h"
17#endif /* HAVE_CONFIG_H */
18#include <kernel/mod2.h>
19#include <omalloc/omalloc.h>
20#include <misc/options.h>
21#include <Singular/tok.h>
22#include <Singular/ipid.h>
23#include <misc/intvec.h>
24#include <kernel/polys.h>
25#include <kernel/ideals.h>
26#include <polys/matpol.h>
27#include <Singular/ipshell.h>
28#include <Singular/attrib.h>
29
30static omBin sattr_bin = omGetSpecBin(sizeof(sattr));
31
32void sattr::Print()
33{
34  omCheckAddrSize(this,sizeof(sattr));
35  ::Print("attr:%s, type %s \n",name,Tok2Cmdname(atyp));
36  if (next!=NULL) next->Print();
37}
38
39attr sattr::Copy()
40{
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;
53  }
54  else
55    return NULL;
56}
57
58// in subexr.cc:
59//void * sattr::CopyA()
60//{
61//  omCheckAddrSize(this,sizeof(sattr));
62//  return s_internalCopy(atyp,data);
63//}
64
65static void attr_free(attr h, const ring r=currRing)
66{
67  s_internalDelete(h->atyp,h->data,r);
68  h->data=NULL;
69}
70
71attr sattr::set(const char * s, void * d, int t)
72{
73  attr h = get(s);
74  attr result=this;
75  if (h!=NULL)
76  {
77    attr_free(h);
78  }
79  else
80  {
81    h = (attr)omAlloc0Bin(sattr_bin);
82    h->next = this;
83    result=h;
84  }
85  h->name = s;
86  h->data = d;
87  h->atyp = t;
88#ifdef TEST
89  //::Print("set attr >>%s<< of type %s\n",h->name, Tok2Cmdname(t));
90#endif
91  return  result;
92}
93
94attr sattr::get(const char * s)
95{
96  attr h = this;
97  while (h!=NULL)
98  {
99    if (0 == strcmp(s,h->name))
100    {
101#ifdef TEST
102      //::Print("get attr >>%s<< of type %s\n",h->name, Tok2Cmdname(h->atyp));
103#endif
104      return h;
105    }
106    h = h->next;
107  }
108  return NULL;
109}
110
111void * atGet(idhdl root,const char * name)
112{
113  attr temp = root->attribute->get(name);
114  if (temp!=NULL)
115    return temp->data;
116  else
117    return NULL;
118}
119
120void * atGet(leftv root,const char * name)
121{
122  attr temp;
123  attr a=*(root->Attribute());
124  temp = a->get(name);
125  if (temp!=NULL)
126    return temp->data;
127  else
128    return NULL;
129}
130
131void * atGet(idhdl root,const char * name, int t, void *defaultReturnValue)
132{
133  attr temp = root->attribute->get(name);
134  if ((temp!=NULL) && (temp->atyp==t))
135    return temp->data;
136  else
137    return defaultReturnValue;
138}
139
140void * atGet(leftv root,const char * name, int t)
141{
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  }
149  return NULL;
150}
151
152void atSet(idhdl root,const char * name,void * data,int typ)
153{
154  if (root!=NULL)
155  {
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");
160    else
161      root->attribute=root->attribute->set(name,data,typ);
162  }
163}
164
165void atSet(leftv root,const char * name,void * data,int typ)
166{
167  if (root!=NULL)
168  {
169    attr *a=root->Attribute();
170    int rt=root->Typ();
171    if (a==NULL)
172      WerrorS("cannot set attributes of this object");
173    else if ((rt!=RING_CMD)
174    && (rt!=QRING_CMD)
175    && (!RingDependend(rt))&&(RingDependend(typ)))
176      WerrorS("cannot set ring-dependend objects at this type");
177    else
178    {
179      *a=(*a)->set(name,data,typ);
180    }
181  }
182}
183
184void sattr::kill(const ring r)
185{
186  attr_free(this,r);
187  omFree((ADDRESS)name);
188  name=NULL;
189  omFreeBin((ADDRESS)this, sattr_bin);
190}
191
192void sattr::killAll(const ring r)
193{
194  attr temp = this,temp1;
195
196  while (temp!=NULL)
197  {
198    temp1 = temp->next;
199    omCheckAddr(temp);
200    temp->kill(r);
201    temp = temp1;
202  }
203}
204
205void at_Kill(idhdl root,const char * name, const ring r)
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    }
221    temp->kill(r);
222  }
223}
224
225void at_KillAll(idhdl root, const ring r)
226{
227  root->attribute->killAll(r);
228  root->attribute = NULL;
229}
230void at_KillAll(leftv root, const ring r)
231{
232  root->attribute->killAll(r);
233  root->attribute = NULL;
234}
235
236BOOLEAN atATTRIB1(leftv res,leftv v)
237{
238  int t;
239  attr *aa=(v->Attribute());
240  if (aa==NULL)
241  {
242    WerrorS("this object cannot have attributes");
243    return TRUE;
244  }
245  attr a=*aa;
246  BOOLEAN haveNoAttribute=TRUE;
247  if (v->e==NULL)
248  {
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    }
264  }
265  else
266  {
267    leftv at=v->LData();
268    return atATTRIB1(res,at);
269  }
270  if (a!=NULL)                    a->Print();
271  else  if(haveNoAttribute)       PrintS("no attributes\n");
272  return FALSE;
273}
274BOOLEAN atATTRIB2(leftv res,leftv v,leftv b)
275{
276  char *name=(char *)b->Data();
277  int t;
278  leftv at=NULL;
279  if (v->e!=NULL)
280    at=v->LData();
281  if (strcmp(name,"isSB")==0)
282  {
283    res->rtyp=INT_CMD;
284    res->data=(void *)(long)hasFlag(v,FLAG_STD);
285    if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_STD)||(hasFlag(at,FLAG_STD)));
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  }
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  }
298  else if (strcmp(name,"qringNF")==0)
299  {
300    res->rtyp=INT_CMD;
301    res->data=(void *)(long)hasFlag(v,FLAG_QRING);
302    if (at!=NULL) res->data=(void *)(long)(hasFlag(v,FLAG_QRING)||(hasFlag(at,FLAG_QRING)));
303  }
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;
309    res->data=(void *)(long)(((ring)v->Data())->isLPring);
310  }
311#endif
312  else
313  {
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)
323    {
324      res->rtyp=a->atyp;
325      res->data=a->CopyA();
326    }
327    else
328    {
329      res->rtyp=STRING_CMD;
330      res->data=omStrDup("");
331    }
332  }
333  return FALSE;
334}
335BOOLEAN atATTRIB3(leftv /*res*/,leftv v,leftv b,leftv c)
336{
337  idhdl h=(idhdl)v->data;
338  int t;
339  if (v->e!=NULL)
340  {
341    v=v->LData();
342    if (v==NULL) return TRUE;
343    h=NULL;
344  }
345  else if (v->rtyp!=IDHDL) h=NULL;
346
347  char *name=(char *)b->Data();
348  if (strcmp(name,"isSB")==0)
349  {
350    if (c->Typ()!=INT_CMD)
351    {
352      WerrorS("attribute isSB must be int");
353      return TRUE;
354    }
355    if (((long)c->Data())!=0L)
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  }
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  }
384  else if ((strcmp(name,"rank")==0)&&(v->Typ()==MODUL_CMD))
385  {
386    if (c->Typ()!=INT_CMD)
387    {
388      WerrorS("attribute `rank` must be int");
389      return TRUE;
390    }
391    ideal I=(ideal)v->Data();
392    I->rank=si_max((int)I->rank,(int)((long)c->Data()));
393  }
394  else if ((strcmp(name,"global")==0)
395  &&(((t=v->Typ())==RING_CMD)||(t==QRING_CMD)))
396  {
397    WerrorS("can not set attribute `global`");
398    return TRUE;
399  }
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
413  else
414  {
415    int typ=c->Typ();
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()*/);
418  }
419  return FALSE;
420}
421
422BOOLEAN atKILLATTR1(leftv /*res*/,leftv a)
423{
424  idhdl h=NULL;
425  if ((a->rtyp==IDHDL)&&(a->e==NULL))
426  {
427    h=(idhdl)a->data;
428    resetFlag((idhdl)a->data,FLAG_STD);
429  }
430  resetFlag(a,FLAG_STD);
431  if (h->attribute!=NULL)
432  {
433    atKillAll(h);
434    a->attribute=NULL;
435  }
436  else atKillAll(a);
437  return FALSE;
438}
439BOOLEAN atKILLATTR2(leftv /*res*/,leftv a,leftv b)
440{
441  if ((a->rtyp!=IDHDL)||(a->e!=NULL))
442  {
443    WerrorS("object must have a name");
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  }
452  else if (strcmp(name,"global")==0)
453  {
454    WerrorS("can not set attribut `global`");
455    return TRUE;
456  }
457  else
458  {
459    atKill((idhdl)a->data,name);
460  }
461  return FALSE;
462}
463
Note: See TracBrowser for help on using the repository browser.