[a53ae5] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
| 4 | /* $Id$ */ |
---|
| 5 | |
---|
| 6 | /* |
---|
| 7 | * ABSTRACT: identfier handling |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #include <string.h> |
---|
| 11 | |
---|
| 12 | #include <kernel/mod2.h> |
---|
| 13 | #include <Singular/static.h> |
---|
| 14 | #include <omalloc/omalloc.h> |
---|
| 15 | #include <Singular/tok.h> |
---|
| 16 | #include <kernel/options.h> |
---|
| 17 | #include <Singular/ipshell.h> |
---|
| 18 | #include <kernel/intvec.h> |
---|
| 19 | #include <kernel/febase.h> |
---|
| 20 | #include <kernel/numbers.h> |
---|
| 21 | #include <kernel/longrat.h> |
---|
| 22 | #include <kernel/polys.h> |
---|
| 23 | #include <kernel/ring.h> |
---|
| 24 | #include <kernel/ideals.h> |
---|
| 25 | #include <kernel/matpol.h> |
---|
| 26 | #include <Singular/lists.h> |
---|
| 27 | #include <Singular/attrib.h> |
---|
| 28 | #include <Singular/silink.h> |
---|
| 29 | #include <kernel/syz.h> |
---|
| 30 | #include <Singular/ipid.h> |
---|
| 31 | |
---|
| 32 | #ifdef HAVE_FANS |
---|
| 33 | #include <gfanlib/gfanlib.h> |
---|
| 34 | #endif |
---|
| 35 | |
---|
| 36 | #ifdef HAVE_DYNAMIC_LOADING |
---|
| 37 | #include <kernel/mod_raw.h> |
---|
| 38 | #endif /* HAVE_DYNAMIC_LOADING */ |
---|
| 39 | |
---|
| 40 | omBin sip_command_bin = omGetSpecBin(sizeof(sip_command)); |
---|
| 41 | omBin sip_package_bin = omGetSpecBin(sizeof(sip_package)); |
---|
| 42 | //omBin ip_package_bin = omGetSpecBin(sizeof(ip_package)); |
---|
| 43 | omBin idrec_bin = omGetSpecBin(sizeof(idrec)); |
---|
| 44 | |
---|
| 45 | proclevel *procstack=NULL; |
---|
| 46 | #define TEST |
---|
| 47 | //idhdl idroot = NULL; |
---|
| 48 | |
---|
| 49 | idhdl currPackHdl = NULL; |
---|
| 50 | idhdl basePackHdl = NULL; |
---|
| 51 | package currPack =NULL; |
---|
| 52 | package basePack =NULL; |
---|
| 53 | idhdl currRingHdl = NULL; |
---|
| 54 | ring currRing = NULL; |
---|
| 55 | ideal currQuotient = NULL; |
---|
| 56 | const char* iiNoName="_"; |
---|
| 57 | |
---|
| 58 | void paCleanUp(package pack); |
---|
| 59 | |
---|
| 60 | /*0 implementation*/ |
---|
| 61 | |
---|
| 62 | int iiS2I(const char *s) |
---|
| 63 | { |
---|
| 64 | int i; |
---|
| 65 | i=s[0]; |
---|
| 66 | if (s[1]!='\0') |
---|
| 67 | { |
---|
| 68 | i=(i<<8)+s[1]; |
---|
| 69 | if (s[2]!='\0') |
---|
| 70 | { |
---|
| 71 | i=(i<<8)+s[2]; |
---|
| 72 | if (s[3]!='\0') |
---|
| 73 | { |
---|
| 74 | i=(i<<8)+s[3]; |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | return i; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | idhdl idrec::get(const char * s, int lev) |
---|
| 82 | { |
---|
| 83 | assume(s!=NULL); |
---|
| 84 | assume((lev>=0) && (lev<=1000)); //not really, but if it isnt in that bounds.. |
---|
| 85 | idhdl h = this; |
---|
| 86 | idhdl found=NULL; |
---|
| 87 | int l; |
---|
| 88 | const char *id; |
---|
| 89 | int i=iiS2I(s); |
---|
| 90 | int less4=(i < (1<<24)); |
---|
| 91 | while (h!=NULL) |
---|
| 92 | { |
---|
| 93 | omCheckAddr((ADDRESS)IDID(h)); |
---|
| 94 | l=IDLEV(h); |
---|
| 95 | if ((l==0)||(l==lev)) |
---|
| 96 | { |
---|
| 97 | if (i==h->id_i) |
---|
| 98 | { |
---|
| 99 | id=IDID(h); |
---|
| 100 | if (less4 || (0 == strcmp(s+4,id+4))) |
---|
| 101 | { |
---|
| 102 | if (l==lev) return h; |
---|
| 103 | found=h; |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | h = IDNEXT(h); |
---|
| 108 | } |
---|
| 109 | return found; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | //idrec::~idrec() |
---|
| 113 | //{ |
---|
| 114 | // if (id!=NULL) |
---|
| 115 | // { |
---|
| 116 | // omFree((ADDRESS)id); |
---|
| 117 | // id=NULL; |
---|
| 118 | // } |
---|
| 119 | // /* much more !! */ |
---|
| 120 | //} |
---|
| 121 | |
---|
| 122 | idhdl idrec::set(const char * s, int lev, int t, BOOLEAN init) |
---|
| 123 | { |
---|
| 124 | //printf("define %s, %x, lev: %d, typ: %d\n", s,s,lev,t); |
---|
| 125 | idhdl h = (idrec *)omAlloc0Bin(idrec_bin); |
---|
| 126 | int len = 0; |
---|
| 127 | IDID(h) = s; |
---|
| 128 | IDTYP(h) = t; |
---|
| 129 | IDLEV(h) = lev; |
---|
| 130 | IDNEXT(h) = this; |
---|
| 131 | h->id_i=iiS2I(s); |
---|
| 132 | if (init) |
---|
| 133 | { |
---|
| 134 | switch (t) |
---|
| 135 | { |
---|
| 136 | //the type with init routines: |
---|
| 137 | case INTVEC_CMD: |
---|
| 138 | case INTMAT_CMD: |
---|
| 139 | IDINTVEC(h) = new intvec(); |
---|
| 140 | break; |
---|
| 141 | case NUMBER_CMD: |
---|
| 142 | IDNUMBER(h) = nInit(0); |
---|
| 143 | break; |
---|
| 144 | case BIGINT_CMD: |
---|
| 145 | IDNUMBER(h) = nlInit(0, NULL /* dummy for nlInit*/); |
---|
| 146 | break; |
---|
| 147 | case IDEAL_CMD: |
---|
| 148 | case MODUL_CMD: |
---|
| 149 | IDFLAG(h) = Sy_bit(FLAG_STD); |
---|
| 150 | case MATRIX_CMD: |
---|
| 151 | IDIDEAL(h) = idInit(1,1); |
---|
| 152 | break; |
---|
| 153 | case MAP_CMD: |
---|
| 154 | IDIDEAL(h) = idInit(1,1); |
---|
| 155 | IDMAP(h)->preimage = omStrDup(IDID(currRingHdl)); |
---|
| 156 | break; |
---|
| 157 | case STRING_CMD: |
---|
| 158 | len=1; |
---|
| 159 | break; |
---|
| 160 | case LIST_CMD: |
---|
| 161 | IDLIST(h)=(lists)omAllocBin(slists_bin); |
---|
| 162 | IDLIST(h)->Init(); |
---|
| 163 | break; |
---|
| 164 | case LINK_CMD: |
---|
| 165 | IDLINK(h)=(si_link) omAlloc0Bin(sip_link_bin); |
---|
| 166 | break; |
---|
| 167 | case RING_CMD: |
---|
| 168 | IDRING(h) = (ring) omAlloc0Bin(sip_sring_bin); |
---|
| 169 | break; |
---|
| 170 | case PACKAGE_CMD: |
---|
| 171 | IDPACKAGE(h) = (package) omAlloc0Bin(sip_package_bin); |
---|
| 172 | break; |
---|
| 173 | case PROC_CMD: |
---|
| 174 | IDPROC(h) = (procinfo*) omAlloc0Bin(procinfo_bin); |
---|
| 175 | break; |
---|
| 176 | //the types with the standard init: set the struct to zero |
---|
| 177 | case RESOLUTION_CMD: |
---|
| 178 | len=sizeof(ssyStrategy); |
---|
| 179 | break; |
---|
| 180 | //other types: without init (int,script,poly,def,package) |
---|
| 181 | } |
---|
| 182 | if (len!=0) |
---|
| 183 | { |
---|
| 184 | IDSTRING(h) = (char *)omAlloc0(len); |
---|
| 185 | } |
---|
| 186 | // additional settings:-------------------------------------- |
---|
| 187 | #if 0 |
---|
| 188 | // this leads to a memory leak |
---|
| 189 | if (t == QRING_CMD) |
---|
| 190 | { |
---|
| 191 | // IDRING(h)=rCopy(currRing); |
---|
| 192 | /* QRING_CMD is ring dep => currRing !=NULL */ |
---|
| 193 | } |
---|
| 194 | else |
---|
| 195 | #endif |
---|
| 196 | if (t == PROC_CMD) |
---|
| 197 | { |
---|
| 198 | IDPROC(h)->language=LANG_NONE; |
---|
| 199 | } |
---|
| 200 | else if (t == PACKAGE_CMD) |
---|
| 201 | { |
---|
| 202 | IDPACKAGE(h)->language=LANG_NONE; |
---|
| 203 | IDPACKAGE(h)->loaded = FALSE; |
---|
| 204 | } |
---|
| 205 | #ifdef HAVE_FANS |
---|
| 206 | else if (t == FAN_CMD) |
---|
| 207 | { |
---|
[c4d065] | 208 | IDSTRING(h) = (char*)(new gfan::ZFan(0)); |
---|
| 209 | } |
---|
[a53ae5] | 210 | else if (t == CONE_CMD) |
---|
| 211 | { |
---|
| 212 | IDSTRING(h) = (char*)(new gfan::ZCone()); |
---|
| 213 | } |
---|
| 214 | #endif /* HAVE_FANS */ |
---|
| 215 | } |
---|
| 216 | // -------------------------------------------------------- |
---|
| 217 | return h; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | char * idrec::String() |
---|
| 221 | { |
---|
| 222 | sleftv tmp; |
---|
| 223 | memset(&tmp,0,sizeof(sleftv)); |
---|
| 224 | tmp.rtyp=IDTYP(this); |
---|
| 225 | tmp.data=IDDATA(this); |
---|
| 226 | tmp.name=IDID(this); |
---|
| 227 | return tmp.String(); |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | idhdl enterid(const char * s, int lev, int t, idhdl* root, BOOLEAN init, BOOLEAN search) |
---|
| 231 | { |
---|
| 232 | idhdl h; |
---|
| 233 | s=omStrDup(s); |
---|
| 234 | // is it already defined in root ? |
---|
| 235 | if ((h=(*root)->get(s,lev))!=NULL) |
---|
| 236 | { |
---|
| 237 | if (IDLEV(h)==lev) |
---|
| 238 | { |
---|
| 239 | if ((IDTYP(h) == t)||(t==DEF_CMD)) |
---|
| 240 | { |
---|
| 241 | if ((IDTYP(h)==PACKAGE_CMD) |
---|
| 242 | && (strcmp(s,"Top")==0)) |
---|
| 243 | { |
---|
| 244 | goto errlabel; |
---|
| 245 | } |
---|
| 246 | if (BVERBOSE(V_REDEFINE)) |
---|
| 247 | Warn("redefining %s **",s); |
---|
| 248 | if (s==IDID(h)) IDID(h)=NULL; |
---|
| 249 | killhdl2(h,root,currRing); |
---|
| 250 | } |
---|
| 251 | else |
---|
| 252 | goto errlabel; |
---|
| 253 | } |
---|
| 254 | } |
---|
| 255 | // is it already defined in currRing->idroot ? |
---|
| 256 | else if (search && (currRing!=NULL)&&((*root) != currRing->idroot)) |
---|
| 257 | { |
---|
| 258 | if ((h=currRing->idroot->get(s,lev))!=NULL) |
---|
| 259 | { |
---|
| 260 | if (IDLEV(h)==lev) |
---|
| 261 | { |
---|
| 262 | if ((IDTYP(h) == t)||(t==DEF_CMD)) |
---|
| 263 | { |
---|
| 264 | if (BVERBOSE(V_REDEFINE)) |
---|
| 265 | Warn("redefining %s **",s); |
---|
| 266 | IDID(h)=NULL; |
---|
| 267 | killhdl2(h,&currRing->idroot,currRing); |
---|
| 268 | } |
---|
| 269 | else |
---|
| 270 | goto errlabel; |
---|
| 271 | } |
---|
| 272 | } |
---|
| 273 | } |
---|
| 274 | // is it already defined in idroot ? |
---|
| 275 | else if (search && (*root != IDROOT)) |
---|
| 276 | { |
---|
| 277 | if ((h=IDROOT->get(s,lev))!=NULL) |
---|
| 278 | { |
---|
| 279 | if (IDLEV(h)==lev) |
---|
| 280 | { |
---|
| 281 | if ((IDTYP(h) == t)||(t==DEF_CMD)) |
---|
| 282 | { |
---|
| 283 | if (BVERBOSE(V_REDEFINE)) |
---|
| 284 | Warn("redefining `%s` **",s); |
---|
| 285 | if (s==IDID(h)) IDID(h)=NULL; |
---|
| 286 | killhdl2(h,&IDROOT,NULL); |
---|
| 287 | } |
---|
| 288 | else |
---|
| 289 | goto errlabel; |
---|
| 290 | } |
---|
| 291 | } |
---|
| 292 | } |
---|
| 293 | *root = (*root)->set(s, lev, t, init); |
---|
| 294 | #ifndef NDEBUG |
---|
| 295 | checkall(); |
---|
| 296 | #endif |
---|
| 297 | return *root; |
---|
| 298 | |
---|
| 299 | errlabel: |
---|
| 300 | //Werror("identifier `%s` in use(lev h=%d,typ=%d,t=%d, curr=%d)",s,IDLEV(h),IDTYP(h),t,lev); |
---|
| 301 | Werror("identifier `%s` in use",s); |
---|
| 302 | //listall(); |
---|
| 303 | omFree((ADDRESS)s); |
---|
| 304 | return NULL; |
---|
| 305 | } |
---|
| 306 | void killid(const char * id, idhdl * ih) |
---|
| 307 | { |
---|
| 308 | if (id!=NULL) |
---|
| 309 | { |
---|
| 310 | idhdl h = (*ih)->get(id,myynest); |
---|
| 311 | |
---|
| 312 | // id not found in global list, is it defined in current ring ? |
---|
| 313 | if (h==NULL) |
---|
| 314 | { |
---|
| 315 | if ((currRing!=NULL) && (*ih != (currRing->idroot))) |
---|
| 316 | { |
---|
| 317 | h = currRing->idroot->get(id,myynest); |
---|
| 318 | if (h!=NULL) |
---|
| 319 | { |
---|
| 320 | killhdl2(h,&(currRing->idroot),currRing); |
---|
| 321 | return; |
---|
| 322 | } |
---|
| 323 | } |
---|
| 324 | Werror("`%s` is not defined",id); |
---|
| 325 | return; |
---|
| 326 | } |
---|
| 327 | killhdl2(h,ih,currRing); |
---|
| 328 | } |
---|
| 329 | else |
---|
| 330 | Werror("kill what ?"); |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | void killhdl(idhdl h, package proot) |
---|
| 334 | { |
---|
| 335 | int t=IDTYP(h); |
---|
| 336 | if (((BEGIN_RING<t) && (t<END_RING) && (t!=QRING_CMD)) |
---|
| 337 | || ((t==LIST_CMD) && (lRingDependend((lists)IDDATA(h))))) |
---|
| 338 | killhdl2(h,&currRing->idroot,currRing); |
---|
| 339 | else |
---|
| 340 | { |
---|
| 341 | if(t==PACKAGE_CMD) |
---|
| 342 | { |
---|
| 343 | killhdl2(h,&(basePack->idroot),NULL); |
---|
| 344 | } |
---|
| 345 | else |
---|
| 346 | { |
---|
| 347 | idhdl s=proot->idroot; |
---|
| 348 | while ((s!=h) && (s!=NULL)) s=s->next; |
---|
| 349 | if (s!=NULL) |
---|
| 350 | killhdl2(h,&(proot->idroot),NULL); |
---|
| 351 | else if (basePack!=proot) |
---|
| 352 | { |
---|
| 353 | idhdl s=basePack->idroot; |
---|
| 354 | while ((s!=h) && (s!=NULL)) s=s->next; |
---|
| 355 | if (s!=NULL) |
---|
| 356 | killhdl2(h,&(basePack->idroot),currRing); |
---|
| 357 | else |
---|
| 358 | killhdl2(h,&(currRing->idroot),currRing); |
---|
| 359 | } |
---|
| 360 | } |
---|
| 361 | } |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | void killhdl2(idhdl h, idhdl * ih, ring r) |
---|
| 365 | { |
---|
| 366 | //printf("kill %s, id %x, typ %d lev: %d\n",IDID(h),(int)IDID(h),IDTYP(h),IDLEV(h)); |
---|
| 367 | idhdl hh; |
---|
| 368 | |
---|
| 369 | if (h->attribute!=NULL) |
---|
| 370 | { |
---|
| 371 | at_KillAll(h,r); |
---|
| 372 | //h->attribute=NULL; |
---|
| 373 | } |
---|
| 374 | if ((IDTYP(h) == PACKAGE_CMD) && (strcmp(IDID(h),"Top")==0)) |
---|
| 375 | { |
---|
| 376 | WarnS("can not kill `Top`"); |
---|
| 377 | return; |
---|
| 378 | } |
---|
| 379 | // ring / qring -------------------------------------------------------- |
---|
| 380 | if ((IDTYP(h) == RING_CMD) || (IDTYP(h) == QRING_CMD)) |
---|
| 381 | { |
---|
| 382 | // any objects defined for this ring ? -> done by rKill |
---|
| 383 | |
---|
| 384 | rKill(h); |
---|
| 385 | } |
---|
| 386 | // package ------------------------------------------------------------- |
---|
| 387 | else if (IDTYP(h) == PACKAGE_CMD) |
---|
| 388 | { |
---|
| 389 | // any objects defined for this package ? |
---|
| 390 | if ((IDPACKAGE(h)->ref<=0) && (IDPACKAGE(h)->idroot!=NULL)) |
---|
| 391 | { |
---|
| 392 | if (currPack==IDPACKAGE(h)) |
---|
| 393 | { |
---|
| 394 | currPack=basePack; |
---|
| 395 | currPackHdl=NULL; |
---|
| 396 | } |
---|
| 397 | idhdl * hd = &IDRING(h)->idroot; |
---|
| 398 | idhdl hdh = IDNEXT(*hd); |
---|
| 399 | idhdl temp; |
---|
| 400 | while (hdh!=NULL) |
---|
| 401 | { |
---|
| 402 | temp = IDNEXT(hdh); |
---|
| 403 | killhdl2(hdh,&(IDPACKAGE(h)->idroot),NULL); |
---|
| 404 | hdh = temp; |
---|
| 405 | } |
---|
| 406 | killhdl2(*hd,hd,NULL); |
---|
| 407 | if (IDPACKAGE(h)->libname!=NULL) omFree((ADDRESS)(IDPACKAGE(h)->libname)); |
---|
| 408 | } |
---|
| 409 | paKill(IDPACKAGE(h)); |
---|
| 410 | if (currPackHdl==h) currPackHdl=packFindHdl(currPack); |
---|
| 411 | iiCheckPack(currPack); |
---|
| 412 | } |
---|
| 413 | // poly / vector ------------------------------------------------------- |
---|
| 414 | else if ((IDTYP(h) == POLY_CMD) || (IDTYP(h) == VECTOR_CMD)) |
---|
| 415 | { |
---|
| 416 | assume(r!=NULL); |
---|
| 417 | p_Delete(&IDPOLY(h),r); |
---|
| 418 | } |
---|
| 419 | // ideal / module/ matrix / map ---------------------------------------- |
---|
| 420 | else if ((IDTYP(h) == IDEAL_CMD) |
---|
| 421 | || (IDTYP(h) == MODUL_CMD) |
---|
| 422 | || (IDTYP(h) == MATRIX_CMD) |
---|
| 423 | || (IDTYP(h) == MAP_CMD)) |
---|
| 424 | { |
---|
| 425 | assume(r!=NULL); |
---|
| 426 | ideal iid = IDIDEAL(h); |
---|
| 427 | if (IDTYP(h) == MAP_CMD) |
---|
| 428 | { |
---|
| 429 | map im = IDMAP(h); |
---|
| 430 | omFree((ADDRESS)im->preimage); |
---|
| 431 | } |
---|
| 432 | id_Delete(&iid,r); |
---|
| 433 | } |
---|
| 434 | // string ------------------------------------------------------------- |
---|
| 435 | else if (IDTYP(h) == STRING_CMD) |
---|
| 436 | { |
---|
| 437 | omFree((ADDRESS)IDSTRING(h)); |
---|
| 438 | //IDSTRING(h)=NULL; |
---|
| 439 | } |
---|
| 440 | // proc --------------------------------------------------------------- |
---|
| 441 | else if (IDTYP(h) == PROC_CMD) |
---|
| 442 | { |
---|
| 443 | if (piKill(IDPROC(h))) return; |
---|
| 444 | } |
---|
| 445 | // number ------------------------------------------------------------- |
---|
| 446 | else if (IDTYP(h) == NUMBER_CMD) |
---|
| 447 | { |
---|
| 448 | assume(r!=NULL); |
---|
| 449 | n_Delete(&IDNUMBER(h),r); |
---|
| 450 | } |
---|
| 451 | // bigint ------------------------------------------------------------- |
---|
| 452 | else if (IDTYP(h) == BIGINT_CMD) |
---|
| 453 | { |
---|
| 454 | nlDelete(&IDNUMBER(h),NULL); |
---|
| 455 | } |
---|
| 456 | // intvec / intmat --------------------------------------------------- |
---|
| 457 | else if ((IDTYP(h) == INTVEC_CMD)||(IDTYP(h) == INTMAT_CMD)) |
---|
| 458 | { |
---|
| 459 | delete IDINTVEC(h); |
---|
| 460 | } |
---|
| 461 | // list ------------------------------------------------------------- |
---|
| 462 | else if (IDTYP(h)==LIST_CMD) |
---|
| 463 | { |
---|
| 464 | IDLIST(h)->Clean(r); |
---|
| 465 | //IDLIST(h)=NULL; |
---|
| 466 | } |
---|
| 467 | // link ------------------------------------------------------------- |
---|
| 468 | else if (IDTYP(h)==LINK_CMD) |
---|
| 469 | { |
---|
| 470 | slKill(IDLINK(h)); |
---|
| 471 | } |
---|
| 472 | else if(IDTYP(h)==RESOLUTION_CMD) |
---|
| 473 | { |
---|
| 474 | assume(r!=NULL); |
---|
| 475 | if (IDDATA(h)!=NULL) |
---|
| 476 | syKillComputation((syStrategy)IDDATA(h),r); |
---|
| 477 | } |
---|
| 478 | #ifdef HAVE_FANS |
---|
| 479 | // fan ------------------------------------------------------------- |
---|
[c4d065] | 480 | else if (IDTYP(h) == FAN_CMD) |
---|
[a53ae5] | 481 | { |
---|
[c4d065] | 482 | gfan::ZFan* zf = (gfan::ZFan*)IDDATA(h); |
---|
| 483 | delete zf; |
---|
[a53ae5] | 484 | IDDATA(h) = NULL; |
---|
[c4d065] | 485 | } |
---|
[a53ae5] | 486 | // cone ------------------------------------------------------------ |
---|
| 487 | else if (IDTYP(h) == CONE_CMD) |
---|
| 488 | { |
---|
| 489 | gfan::ZCone* zc = (gfan::ZCone*)IDDATA(h); |
---|
| 490 | delete zc; |
---|
| 491 | IDDATA(h) = NULL; |
---|
| 492 | } |
---|
| 493 | #endif /* HAVE_FANS */ |
---|
| 494 | #ifdef TEST |
---|
| 495 | else if ((IDTYP(h)!= INT_CMD) |
---|
| 496 | &&(IDTYP(h)!=DEF_CMD) |
---|
| 497 | &&(IDTYP(h)!=ALIAS_CMD) |
---|
| 498 | &&(IDTYP(h)!=NONE)) |
---|
| 499 | Warn("unknown type to kill: %s(%d)",Tok2Cmdname(IDTYP(h)),IDTYP(h)); |
---|
| 500 | #endif |
---|
| 501 | |
---|
| 502 | // general ------------------------------------------------------------- |
---|
| 503 | // now dechain it and delete idrec |
---|
| 504 | if (IDID(h)!=NULL) // OB: ????? |
---|
| 505 | omFree((ADDRESS)IDID(h)); |
---|
| 506 | IDID(h)=NULL; |
---|
| 507 | IDDATA(h)=NULL; |
---|
| 508 | if (h == (*ih)) |
---|
| 509 | { |
---|
| 510 | // h is at the beginning of the list |
---|
| 511 | *ih = IDNEXT(h) /* ==*ih */; |
---|
| 512 | } |
---|
| 513 | else if (ih!=NULL) |
---|
| 514 | { |
---|
| 515 | // h is somethere in the list: |
---|
| 516 | hh = *ih; |
---|
| 517 | loop |
---|
| 518 | { |
---|
| 519 | if (hh==NULL) |
---|
| 520 | { |
---|
| 521 | PrintS(">>?<< not found for kill\n"); |
---|
| 522 | return; |
---|
| 523 | } |
---|
| 524 | idhdl hhh = IDNEXT(hh); |
---|
| 525 | if (hhh == h) |
---|
| 526 | { |
---|
| 527 | IDNEXT(hh) = IDNEXT(hhh); |
---|
| 528 | break; |
---|
| 529 | } |
---|
| 530 | hh = hhh; |
---|
| 531 | } |
---|
| 532 | } |
---|
| 533 | omFreeBin((ADDRESS)h, idrec_bin); |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | idhdl ggetid(const char *n, BOOLEAN local, idhdl *packhdl) |
---|
| 537 | { |
---|
| 538 | idhdl h = IDROOT->get(n,myynest); |
---|
| 539 | idhdl h2=NULL; |
---|
| 540 | *packhdl = NULL; |
---|
| 541 | if ((currRing!=NULL) && ((h==NULL)||(IDLEV(h)!=myynest))) |
---|
| 542 | { |
---|
| 543 | h2 = currRing->idroot->get(n,myynest); |
---|
| 544 | } |
---|
| 545 | if (h2==NULL) return h; |
---|
| 546 | return h2; |
---|
| 547 | } |
---|
| 548 | |
---|
| 549 | idhdl ggetid(const char *n) |
---|
| 550 | { |
---|
| 551 | idhdl h = IDROOT->get(n,myynest); |
---|
| 552 | if ((h!=NULL)&&(IDLEV(h)==myynest)) return h; |
---|
| 553 | idhdl h2=NULL; |
---|
| 554 | if (currRing!=NULL) |
---|
| 555 | { |
---|
| 556 | h2 = currRing->idroot->get(n,myynest); |
---|
| 557 | } |
---|
| 558 | if (h2!=NULL) return h2; |
---|
| 559 | if (h!=NULL) return h; |
---|
| 560 | if (basePack!=currPack) |
---|
| 561 | return basePack->idroot->get(n,myynest); |
---|
| 562 | return NULL; |
---|
| 563 | } |
---|
| 564 | |
---|
| 565 | void ipListFlag(idhdl h) |
---|
| 566 | { |
---|
| 567 | if (hasFlag(h,FLAG_STD)) PrintS(" (SB)"); |
---|
| 568 | #ifdef HAVE_PLURAL |
---|
| 569 | if (hasFlag(h,FLAG_TWOSTD)) PrintS(" (2SB)"); |
---|
| 570 | #endif |
---|
| 571 | } |
---|
| 572 | |
---|
| 573 | lists ipNameList(idhdl root) |
---|
| 574 | { |
---|
| 575 | idhdl h=root; |
---|
| 576 | /* compute the length */ |
---|
| 577 | int l=0; |
---|
| 578 | while (h!=NULL) { l++; h=IDNEXT(h); } |
---|
| 579 | /* allocate list */ |
---|
| 580 | lists L=(lists)omAllocBin(slists_bin); |
---|
| 581 | L->Init(l); |
---|
| 582 | /* copy names */ |
---|
| 583 | h=root; |
---|
| 584 | l=0; |
---|
| 585 | while (h!=NULL) |
---|
| 586 | { |
---|
| 587 | /* list is initialized with 0 => no need to clear anything */ |
---|
| 588 | L->m[l].rtyp=STRING_CMD; |
---|
| 589 | L->m[l].data=omStrDup(IDID(h)); |
---|
| 590 | l++; |
---|
| 591 | h=IDNEXT(h); |
---|
| 592 | } |
---|
| 593 | return L; |
---|
| 594 | } |
---|
| 595 | |
---|
| 596 | /* |
---|
| 597 | * move 'tomove' from root1 list to root2 list |
---|
| 598 | */ |
---|
| 599 | static int ipSwapId(idhdl tomove, idhdl &root1, idhdl &root2) |
---|
| 600 | { |
---|
| 601 | idhdl h; |
---|
| 602 | /* search 'tomove' in root2 : if found -> do nothing */ |
---|
| 603 | h=root2; |
---|
| 604 | while ((h!=NULL) && (h!=tomove)) h=IDNEXT(h); |
---|
| 605 | if (h!=NULL) return FALSE; /*okay */ |
---|
| 606 | /* search predecessor of h in root1, remove 'tomove' */ |
---|
| 607 | h=root1; |
---|
| 608 | if (tomove==h) |
---|
| 609 | { |
---|
| 610 | root1=IDNEXT(h); |
---|
| 611 | } |
---|
| 612 | else |
---|
| 613 | { |
---|
| 614 | while ((h!=NULL) && (IDNEXT(h)!=tomove)) h=IDNEXT(h); |
---|
| 615 | if (h==NULL) return TRUE; /* not in the list root1 -> do nothing */ |
---|
| 616 | IDNEXT(h)=IDNEXT(tomove); |
---|
| 617 | } |
---|
| 618 | /* add to root2 list */ |
---|
| 619 | IDNEXT(tomove)=root2; |
---|
| 620 | root2=tomove; |
---|
| 621 | return FALSE; |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | void ipMoveId(idhdl tomove) |
---|
| 625 | { |
---|
| 626 | if ((currRing!=NULL)&&(tomove!=NULL)) |
---|
| 627 | { |
---|
| 628 | if (((QRING_CMD!=IDTYP(tomove)) && RingDependend(IDTYP(tomove))) |
---|
| 629 | || ((IDTYP(tomove)==LIST_CMD) && (lRingDependend(IDLIST(tomove))))) |
---|
| 630 | { |
---|
| 631 | /*move 'tomove' to ring id's*/ |
---|
| 632 | if (ipSwapId(tomove,IDROOT,currRing->idroot)) |
---|
| 633 | ipSwapId(tomove,basePack->idroot,currRing->idroot); |
---|
| 634 | } |
---|
| 635 | else |
---|
| 636 | { |
---|
| 637 | /*move 'tomove' to global id's*/ |
---|
| 638 | ipSwapId(tomove,currRing->idroot,IDROOT); |
---|
| 639 | } |
---|
| 640 | } |
---|
| 641 | } |
---|
| 642 | |
---|
| 643 | const char * piProcinfo(procinfov pi, const char *request) |
---|
| 644 | { |
---|
| 645 | if(pi == NULL) return "empty proc"; |
---|
| 646 | else if (strcmp(request, "libname") == 0) return pi->libname; |
---|
| 647 | else if (strcmp(request, "procname") == 0) return pi->procname; |
---|
| 648 | else if (strcmp(request, "type") == 0) |
---|
| 649 | { |
---|
| 650 | switch (pi->language) |
---|
| 651 | { |
---|
| 652 | case LANG_SINGULAR: return "singular"; break; |
---|
| 653 | case LANG_C: return "object"; break; |
---|
| 654 | case LANG_NONE: return "none"; break; |
---|
| 655 | default: return "unknow language"; |
---|
| 656 | } |
---|
| 657 | } |
---|
| 658 | else if (strcmp(request, "ref") == 0) |
---|
| 659 | { |
---|
| 660 | char p[8]; |
---|
| 661 | sprintf(p, "%d", pi->ref); |
---|
| 662 | return omStrDup(p); // MEMORY-LEAK |
---|
| 663 | } |
---|
| 664 | return "??"; |
---|
| 665 | } |
---|
| 666 | |
---|
| 667 | void piCleanUp(procinfov pi) |
---|
| 668 | { |
---|
| 669 | (pi->ref)--; |
---|
| 670 | if (pi->ref <= 0) |
---|
| 671 | { |
---|
| 672 | if (pi->libname != NULL) // OB: ???? |
---|
| 673 | omFree((ADDRESS)pi->libname); |
---|
| 674 | if (pi->procname != NULL) // OB: ???? |
---|
| 675 | omFree((ADDRESS)pi->procname); |
---|
| 676 | |
---|
| 677 | if( pi->language == LANG_SINGULAR) |
---|
| 678 | { |
---|
| 679 | if (pi->data.s.body != NULL) // OB: ???? |
---|
| 680 | omFree((ADDRESS)pi->data.s.body); |
---|
| 681 | } |
---|
| 682 | if( pi->language == LANG_C) |
---|
| 683 | { |
---|
| 684 | } |
---|
| 685 | memset((void *) pi, 0, sizeof(procinfo)); |
---|
| 686 | pi->language=LANG_NONE; |
---|
| 687 | } |
---|
| 688 | } |
---|
| 689 | |
---|
| 690 | BOOLEAN piKill(procinfov pi) |
---|
| 691 | { |
---|
| 692 | Voice *p=currentVoice; |
---|
| 693 | while (p!=NULL) |
---|
| 694 | { |
---|
| 695 | if (p->pi==pi && pi->ref <= 1) |
---|
| 696 | { |
---|
| 697 | Warn("`%s` in use, can not be killed",pi->procname); |
---|
| 698 | return TRUE; |
---|
| 699 | } |
---|
| 700 | p=p->next; |
---|
| 701 | } |
---|
| 702 | piCleanUp(pi); |
---|
| 703 | if (pi->ref <= 0) |
---|
| 704 | omFreeBin((ADDRESS)pi, procinfo_bin); |
---|
| 705 | return FALSE; |
---|
| 706 | } |
---|
| 707 | |
---|
| 708 | void paCleanUp(package pack) |
---|
| 709 | { |
---|
| 710 | (pack->ref)--; |
---|
| 711 | if (pack->ref < 0) |
---|
| 712 | { |
---|
| 713 | #ifndef HAVE_STATIC |
---|
| 714 | if( pack->language == LANG_C) |
---|
| 715 | { |
---|
| 716 | Print("//dlclose(%s)\n",pack->libname); |
---|
| 717 | #ifdef HAVE_DYNAMIC_LOADING |
---|
| 718 | dynl_close (pack->handle); |
---|
| 719 | #endif /* HAVE_DYNAMIC_LOADING */ |
---|
| 720 | } |
---|
| 721 | #endif /* HAVE_STATIC */ |
---|
| 722 | omfree((ADDRESS)pack->libname); |
---|
| 723 | memset((void *) pack, 0, sizeof(sip_package)); |
---|
| 724 | pack->language=LANG_NONE; |
---|
| 725 | } |
---|
| 726 | } |
---|
| 727 | |
---|
| 728 | void proclevel::push(char *n) |
---|
| 729 | { |
---|
| 730 | //Print("push %s\n",n); |
---|
| 731 | proclevel *p=(proclevel*)omAlloc0(sizeof(proclevel)); |
---|
| 732 | p->cRing=currRing; |
---|
| 733 | p->cRingHdl=currRingHdl; |
---|
| 734 | p->name=n; |
---|
| 735 | p->cPackHdl=currPackHdl; |
---|
| 736 | p->cPack=currPack; |
---|
| 737 | p->next=this; |
---|
| 738 | procstack=p; |
---|
| 739 | } |
---|
| 740 | void proclevel::pop() |
---|
| 741 | { |
---|
| 742 | //Print("pop %s\n",name); |
---|
| 743 | //if (currRing!=::currRing) PrintS("currRing wrong\n");; |
---|
| 744 | //::currRing=this->currRing; |
---|
| 745 | //if (r==NULL) Print("set ring to NULL at lev %d(%s)\n",myynest,name); |
---|
| 746 | //::currRingHdl=this->currRingHdl; |
---|
| 747 | //if((::currRingHdl==NULL)||(IDRING(::currRingHdl)!=(::currRing))) |
---|
| 748 | // ::currRingHdl=rFindHdl(::currRing,NULL,NULL); |
---|
| 749 | //Print("restore pack=%s,1.obj=%s\n",IDID(currPackHdl),IDID(currPack->idroot)); |
---|
| 750 | currPackHdl=this->cPackHdl; |
---|
| 751 | currPack=this->cPack; |
---|
| 752 | iiCheckPack(currPack); |
---|
| 753 | proclevel *p=this; |
---|
| 754 | procstack=next; |
---|
| 755 | omFreeSize(p,sizeof(proclevel)); |
---|
| 756 | } |
---|
| 757 | |
---|
| 758 | idhdl packFindHdl(package r) |
---|
| 759 | { |
---|
| 760 | idhdl h=basePack->idroot; |
---|
| 761 | while (h!=NULL) |
---|
| 762 | { |
---|
| 763 | if ((IDTYP(h)==PACKAGE_CMD) |
---|
| 764 | && (IDPACKAGE(h)==r)) |
---|
| 765 | return h; |
---|
| 766 | h=IDNEXT(h); |
---|
| 767 | } |
---|
| 768 | return NULL; |
---|
| 769 | } |
---|