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