Lines Matching refs:np

43 char *nv_getv(Namval_t *np, register Namfun_t *nfp)  in nv_getv()  argument
54 if(!nv_isattr(np,NV_NODISC) || fp==(Namfun_t*)nv_arrayptr(np)) in nv_getv()
58 cp = (*fp->disc->getval)(np,fp); in nv_getv()
61 sfprintf(sh.strbuf,"%.*Lg",12,(*fp->disc->getnum)(np,fp)); in nv_getv()
67 cp = nv_getval(np); in nv_getv()
75 Sfdouble_t nv_getn(Namval_t *np, register Namfun_t *nfp) in nv_getn() argument
88 if(!fp->disc->getnum && nv_isattr(np,NV_INTEGER)) in nv_getn()
90 if(!nv_isattr(np,NV_NODISC) || fp==(Namfun_t*)nv_arrayptr(np)) in nv_getn()
94 d = (*fp->disc->getnum)(np,fp); in nv_getn()
95 else if(nv_isattr(np,NV_INTEGER)) in nv_getn()
98 d = nv_getnum(np); in nv_getn()
103 str = (*fp->disc->getval)(np,fp); in nv_getn()
105 str = nv_getv(np,fp?fp:nfp); in nv_getn()
108 if(nv_isattr(np,NV_LJUST|NV_RJUST) || (*str=='0' && !(str[1]=='x'||str[1]=='X'))) in nv_getn()
122 void nv_putv(Namval_t *np, const char *value, int flags, register Namfun_t *nfp) in nv_putv() argument
136 if(!value && (!(ap=nv_arrayptr(np)) || ap->nelem==0)) in nv_putv()
139 nv_disc(np,fp,NV_POP); in nv_putv()
145 if(!nv_isattr(np,NV_NODISC) || fp==(Namfun_t*)nv_arrayptr(np)) in nv_putv()
151 (*fp->disc->putval)(np,value, flags, fp); in nv_putv()
156 nv_putval(np, value, flags); in nv_putv()
158 _nv_unset(np, flags&(NV_RDONLY|NV_EXPORT)); in nv_putv()
178 Namval_t *np; member
193 static struct blocked *block_info(Namval_t *np, struct blocked *pp) in block_info() argument
198 if(nv_isarray(np) && (isub=nv_aindex(np)) < 0) in block_info()
199 sub = nv_associative(np,(const char*)0,NV_ACURRENT); in block_info()
202 if(bp->np==np && bp->sub==sub && bp->isub==isub) in block_info()
207 pp->np = np; in block_info()
221 nv_putsub(bp->np, bp->sub,(bp->isub<0?0:bp->isub)|ARRAY_SETSUB); in block_done()
227 static void chktfree(register Namval_t *np, register struct vardisc *vp) in chktfree() argument
239 if((fp=nv_stack(np, NIL(Namfun_t*))) && !(fp->nofree&1)) in chktfree()
247 static void assign(Namval_t *np,const char* val,int flags,Namfun_t *handle) in assign() argument
252 struct blocked block, *bp = block_info(np, &block); in assign()
254 union Value *up = np->nvalue.up; in assign()
257 …if(val && (tp=nv_type(np)) && (nr=nv_open(val,sh.var_tree,NV_VARNAME|NV_ARRAY|NV_NOADD|NV_NOFAIL))… in assign()
259 char *sub = nv_getsub(np); in assign()
260 _nv_unset(np,0); in assign()
263 nv_putsub(np, sub, ARRAY_ADD); in assign()
264 nv_putval(np,nv_getval(nr), 0); in assign()
267 nv_clone(nr,np,0); in assign()
275 nv_putv(np,val,flags,handle); in assign()
296 sh_fun(nq,np,(char**)0); in assign()
301 chktfree(np,vp); in assign()
303 if(nv_isarray(np)) in assign()
304 np->nvalue.up = up; in assign()
321 nv_putv(np,cp,flags|NV_RDONLY,handle); in assign()
326 else if(sh_isstate(SH_INIT) || np==SH_FUNNAMENOD) in assign()
329 nv_putv(np,val,flags,handle); in assign()
337 nv_disc(np,handle,NV_POP); in assign()
338 nv_putv(np, val, flags, handle); in assign()
341 if(nv_isarray(np) && (ap=nv_arrayptr(np)) && ap->nelem>0) in assign()
369 static char* lookup(Namval_t *np, int type, Sfdouble_t *dp,Namfun_t *handle) in lookup() argument
372 struct blocked block, *bp = block_info(np, &block); in lookup()
376 union Value *up = np->nvalue.up; in lookup()
391 sh_fun(nq,np,(char**)0); in lookup()
394 chktfree(np,vp); in lookup()
409 if(nv_isarray(np)) in lookup()
410 np->nvalue.up = up; in lookup()
414 cp = nv_getv(np,handle); in lookup()
416 *dp = nv_getn(np,handle); in lookup()
428 static char* lookups(Namval_t *np, Namfun_t *handle) in lookups() argument
430 return(lookup(np,LOOKUPS,(Sfdouble_t*)0,handle)); in lookups()
433 static Sfdouble_t lookupn(Namval_t *np, Namfun_t *handle) in lookupn() argument
436 lookup(np,LOOKUPN, &d ,handle); in lookupn()
448 char *nv_setdisc(register Namval_t* np,register const char *event,Namval_t *action,register Namfun_… in nv_setdisc() argument
450 register struct vardisc *vp = (struct vardisc*)np->nvfun; in nv_setdisc()
461 if(np == (Namval_t*)fp) in nv_setdisc()
489 return((*fp->disc->setdisc)(np,event,action,fp)); in nv_setdisc()
497 if(np != (Namval_t*)fp) in nv_setdisc()
503 return((*fp->disc->setdisc)(np,event,action,fp)); in nv_setdisc()
513 if(action==np) in nv_setdisc()
522 if(nv_isarray(np) && !nv_arrayptr(np)) in nv_setdisc()
523 nv_putsub(np,(char*)0, 1); in nv_setdisc()
524 nv_stack(np, (Namfun_t*)vp); in nv_setdisc()
526 if(action==np) in nv_setdisc()
545 if(!(bp=block_info(np,(struct blocked*)0)) || !isblocked(bp,UNASSIGN)) in nv_setdisc()
546 chktfree(np,vp); in nv_setdisc()
558 static char *setdisc(register Namval_t* np,register const char *event,Namval_t *action,register Nam… in setdisc() argument
584 return(nv_setdisc(np,event,action,fp)); in setdisc()
588 if(action==np) in setdisc()
592 Namval_t *tp = nv_type(np); in setdisc()
593 if(tp && (np = (Namval_t*)vp->bltins[type]) && nv_isattr(np,NV_STATICF)) in setdisc()
605 static void putdisc(Namval_t* np, const char* val, int flag, Namfun_t* fp) in putdisc() argument
607 nv_putv(np,val,flag,fp); in putdisc()
626 nv_disc(np,fp,NV_POP); in putdisc()
651 int nv_adddisc(Namval_t *np, const char **names, Namval_t **funs) in nv_adddisc() argument
672 nv_stack(np,&vp->fun); in nv_adddisc()
684 Namfun_t *nv_disc(register Namval_t *np, register Namfun_t* fp, int mode) in nv_disc() argument
687 if(nv_isref(np)) in nv_disc()
694 if((lp=np->nvfun)==fp) in nv_disc()
699 return(np->nvfun=lp); in nv_disc()
703 np->nvfun = lp->next; in nv_disc()
710 lpp = &np->nvfun; in nv_disc()
739 nv_offattr(np,NV_NODISC); in nv_disc()
758 return(np->nvfun); in nv_disc()
760 for(lp=np->nvfun; lp; fp=lp,lp=lp->next); in nv_disc()
761 else if(fp = np->nvfun) in nv_disc()
762 np->nvfun = fp->next; in nv_disc()
771 Namfun_t *nv_hasdisc(Namval_t *np, const Namdisc_t *dp) in nv_hasdisc() argument
774 for(fp=np->nvfun; fp; fp = fp->next) in nv_hasdisc()
788 static void put_notify(Namval_t* np,const char *val,int flags,Namfun_t *fp) in put_notify() argument
791 nv_putv(np,val,flags,fp); in put_notify()
792 nv_stack(np,fp); in put_notify()
793 nv_stack(np,(Namfun_t*)0); in put_notify()
801 int nv_unsetnotify(Namval_t *np, char **addr) in nv_unsetnotify() argument
804 for(fp=np->nvfun;fp;fp=fp->next) in nv_unsetnotify()
808 nv_stack(np,fp); in nv_unsetnotify()
809 nv_stack(np,(Namfun_t*)0); in nv_unsetnotify()
818 int nv_setnotify(Namval_t *np, char **addr) in nv_setnotify() argument
825 nv_stack(np,&pp->hdr); in nv_setnotify()
832 register Namval_t *np = newof(0,Namval_t,1,s=strlen(name)+1); in newnode() local
833 if(np) in newnode()
835 np->nvname = (char*)np+sizeof(Namval_t); in newnode()
836 memcpy(np->nvname,name,s); in newnode()
838 return((void*)np); in newnode()
844 static void *num_clone(register Namval_t *np, void *val) in num_clone() argument
850 if(nv_isattr(np,NV_DOUBLE)==NV_DOUBLE) in num_clone()
852 if(nv_isattr(np,NV_LONG)) in num_clone()
854 else if(nv_isattr(np,NV_SHORT)) in num_clone()
861 if(nv_isattr(np,NV_LONG)) in num_clone()
863 else if(nv_isattr(np,NV_SHORT)) in num_clone()
865 if(nv_isattr(np,NV_INT16P)==NV_INT16P) in num_clone()
868 return((void*)np->nvalue.ip); in num_clone()
879 void clone_all_disc( Namval_t *np, Namval_t *mp, int flags) in clone_all_disc() argument
882 for(fp=np->nvfun; fp;fp=fpnext) in clone_all_disc()
890 nfp = (*fp->disc->clonef)(np,mp,flags,fp); in clone_all_disc()
911 int nv_clone(Namval_t *np, Namval_t *mp, int flags) in nv_clone() argument
926 if(fp=np->nvfun) in nv_clone()
933 if(!(flags&NV_COMVAR) && !nv_isattr(np,NV_MINIMAL) && np->nvenv && !(nv_isattr(mp,NV_MINIMAL))) in nv_clone()
934 mp->nvenv = np->nvenv; in nv_clone()
936 mp->nvflag |= np->nvflag&~(NV_ARRAY|NV_MINIMAL|NV_NOFREE); in nv_clone()
938 clone_all_disc(np, mp, flags); in nv_clone()
943 nv_setsize(mp,nv_size(np)); in nv_clone()
945 mp->nvflag = (np->nvflag&~(NV_MINIMAL))|(mp->nvflag&NV_MINIMAL); in nv_clone()
946 if(nv_isattr(np,NV_EXPORT)) in nv_clone()
947 mp->nvflag |= (np->nvflag&NV_MINIMAL); in nv_clone()
948 if(mp->nvalue.cp==val && !nv_isattr(np,NV_INTEGER)) in nv_clone()
950 if(np->nvalue.cp && np->nvalue.cp!=Empty && (flags&NV_COMVAR) && !(flags&NV_MOVE)) in nv_clone()
953 mp->nvalue.cp = (char*)memdup(np->nvalue.cp,size); in nv_clone()
955 mp->nvalue.cp = strdup(np->nvalue.cp); in nv_clone()
958 else if((np->nvfun || !nv_isattr(np,NV_ARRAY)) && !(mp->nvalue.cp = np->nvalue.cp)) in nv_clone()
963 if(nv_isattr(np,NV_INTEGER)) in nv_clone()
964 mp->nvalue.ip = np->nvalue.ip; in nv_clone()
965 np->nvfun = 0; in nv_clone()
966 np->nvalue.cp = 0; in nv_clone()
967 if(!nv_isattr(np,NV_MINIMAL) || nv_isattr(mp,NV_EXPORT)) in nv_clone()
969 mp->nvenv = np->nvenv; in nv_clone()
970 if(nv_isattr(np,NV_MINIMAL)) in nv_clone()
972 np->nvenv = 0; in nv_clone()
973 np->nvflag = NV_EXPORT; in nv_clone()
976 np->nvflag = 0; in nv_clone()
979 np->nvflag &= NV_MINIMAL; in nv_clone()
980 nv_setsize(np,0); in nv_clone()
983 else if((flags&NV_ARRAY) && !nv_isattr(np,NV_MINIMAL)) in nv_clone()
984 mp->nvenv = np->nvenv; in nv_clone()
985 if(nv_isattr(np,NV_INTEGER) && mp->nvalue.ip!=np->nvalue.ip && np->nvalue.cp!=Empty) in nv_clone()
987 mp->nvalue.ip = (int*)num_clone(np,(void*)np->nvalue.ip); in nv_clone()
990 else if((flags&NV_NOFREE) && !nv_arrayptr(np)) in nv_clone()
991 nv_onattr(np,NV_NOFREE); in nv_clone()
998 static char* clone_getv(Namval_t *np, Namfun_t *handle) in clone_getv() argument
1000 return(np->nvalue.np?nv_getval(np->nvalue.np):0); in clone_getv()
1003 static Sfdouble_t clone_getn(Namval_t *np, Namfun_t *handle) in clone_getn() argument
1005 return(np->nvalue.np?nv_getnum(np->nvalue.np):0); in clone_getn()
1008 static void clone_putv(Namval_t *np,const char* val,int flags,Namfun_t *handle) in clone_putv() argument
1010 Namfun_t *dp = nv_stack(np,(Namfun_t*)0); in clone_putv()
1011 Namval_t *mp = np->nvalue.np; in clone_putv()
1015 nv_clone(mp,np,NV_NOFREE); in clone_putv()
1016 np->nvalue.cp = 0; in clone_putv()
1017 nv_putval(np,val,flags); in clone_putv()
1030 Namval_t *np; in nv_mkclone() local
1032 np = newof(0,Namval_t,1,0); in nv_mkclone()
1033 np->nvflag = mp->nvflag; in nv_mkclone()
1034 np->nvsize = mp->nvsize; in nv_mkclone()
1035 np->nvname = mp->nvname; in nv_mkclone()
1036 np->nvalue.np = mp; in nv_mkclone()
1037 np->nvflag = mp->nvflag; in nv_mkclone()
1040 nv_stack(np,dp); in nv_mkclone()
1041 dtinsert(nv_dict(sh.namespace),np); in nv_mkclone()
1042 return(np); in nv_mkclone()
1047 register Namval_t *np; in nv_search() local
1054 if(!(np = dtsearch(root,mp)) && (mode&NV_ADD)) in nv_search()
1061 np = dtmatch(root,(void*)name); in nv_search()
1067 if(!np && (mode&NV_ADD)) in nv_search()
1077 np = (Namval_t*)dtinsert(root,newnode(name)); in nv_search()
1081 return(np); in nv_search()
1098 Namval_t *np, *nq; in nv_bfsearch() local
1138 np = 0; in nv_bfsearch()
1143 np = nq; in nv_bfsearch()
1161 np = nv_search(stakptr(offset),root,0); in nv_bfsearch()
1163 return(np); in nv_bfsearch()
1171 return(np); in nv_bfsearch()
1187 register Namval_t *np, *nq=0; in sh_addbuiltin() local
1200 if(np = nv_search(name,sh.bltin_tree,0)) in sh_addbuiltin()
1206 if(np->nvfun && !nv_isattr(np,NV_NOFREE)) in sh_addbuiltin()
1207 free((void*)np->nvfun); in sh_addbuiltin()
1208 dtdelete(sh.bltin_tree,np); in sh_addbuiltin()
1212 return(np); in sh_addbuiltin()
1214 else for(np=(Namval_t*)dtfirst(sh.bltin_tree);np;np=(Namval_t*)dtnext(sh.bltin_tree,np)) in sh_addbuiltin()
1216 if(strcmp(name,path_basename(nv_name(np)))) in sh_addbuiltin()
1219 if(strcmp(path,nv_name(np))) in sh_addbuiltin()
1221 if(nv_isattr(np,BLT_SPC)) in sh_addbuiltin()
1222 return(np); in sh_addbuiltin()
1224 bltin = (Shbltin_f)np->nvalue.bfp; in sh_addbuiltin()
1225 if(np->nvenv) in sh_addbuiltin()
1226 dtdelete(sh.bltin_tree,np); in sh_addbuiltin()
1229 np = 0; in sh_addbuiltin()
1233 if(!np && !(np = nv_search(path,sh.bltin_tree,bltin?NV_ADD:0))) in sh_addbuiltin()
1236 if(nv_isattr(np,BLT_SPC)) in sh_addbuiltin()
1239 np->nvfun = (Namfun_t*)extra; in sh_addbuiltin()
1240 return(np); in sh_addbuiltin()
1242 np->nvenv = 0; in sh_addbuiltin()
1243 np->nvfun = 0; in sh_addbuiltin()
1246 np->nvalue.bfp = (Nambfp_f)bltin; in sh_addbuiltin()
1247 nv_onattr(np,NV_BLTIN|NV_NOFREE); in sh_addbuiltin()
1248 np->nvfun = (Namfun_t*)extra; in sh_addbuiltin()
1252 cp=nv_setdisc(nq,cp+1,np,(Namfun_t*)nq); in sh_addbuiltin()
1259 return(np); in sh_addbuiltin()
1263 extern Namfun_t *nv_stack(register Namval_t *np, register Namfun_t* fp) in nv_stack() argument
1265 return(nv_disc(np,fp,0)); in nv_stack()
1276 static Namval_t *next_table(register Namval_t* np, Dt_t *root,Namfun_t *fp) in next_table() argument
1280 return((Namval_t*)dtnext(root,np)); in next_table()
1285 static Namval_t *create_table(Namval_t *np,const char *name,int flags,Namfun_t *fp) in create_table() argument
1288 tp->shp->last_table = np; in create_table()
1292 static Namfun_t *clone_table(Namval_t* np, Namval_t *mp, int flags, Namfun_t *fp) in clone_table() argument
1302 for(np=(Namval_t*)dtfirst(oroot);np;np=(Namval_t*)dtnext(oroot,np)) in clone_table()
1304 mp = (Namval_t*)dtinsert(nroot,newnode(np->nvname)); in clone_table()
1305 nv_clone(np,mp,flags); in clone_table()
1320 static void delete_fun(Namval_t *np, void *data) in delete_fun() argument
1323 nv_delete(np,shp->fun_tree,NV_NOFREE); in delete_fun()
1326 static void put_table(register Namval_t* np, const char* val, int flags, Namfun_t* fp) in put_table() argument
1334 nv_putv(np,val,flags,fp); in put_table()
1337 if(nv_isarray(np) && (ap=nv_arrayptr(np)) && array_elem(ap)) in put_table()
1340 data.mapname = nv_name(np); in put_table()
1354 np->nvfun = 0; in put_table()
1360 static char *get_table(Namval_t *np, Namfun_t *fp) in get_table() argument
1370 for(np=(Namval_t*)dtfirst(root);np;np=(Namval_t*)dtnext(root,np)) in get_table()
1372 if(!nv_isnull(np) || np->nvfun || nv_isattr(np,~NV_NOFREE)) in get_table()
1378 sfputr(out,np->nvname,-1); in get_table()
1400 Namval_t *nv_parent(Namval_t *np) in nv_parent() argument
1402 struct table *tp = (struct table *)nv_hasdisc(np,&table_disc); in nv_parent()
1408 Dt_t *nv_dict(Namval_t* np) in nv_dict() argument
1411 struct table *tp = (struct table*)nv_hasdisc(np,&table_disc); in nv_dict()
1414 np = shp->last_table; in nv_dict()
1415 while(np) in nv_dict()
1417 if(tp = (struct table*)nv_hasdisc(np,&table_disc)) in nv_dict()
1420 np = nv_create(np,(const char*)0, NV_FIRST, (Namfun_t*)0); in nv_dict()
1428 int nv_istable(Namval_t *np) in nv_istable() argument
1430 return(nv_hasdisc(np,&table_disc)!=0); in nv_istable()
1436 Namval_t *nv_mount(Namval_t *np, const char *name, Dt_t *dict) in nv_mount() argument
1440 if(nv_hasdisc(np,&table_disc)) in nv_mount()
1441 pp = np; in nv_mount()
1452 mp = np; in nv_mount()
1476 int nv_hasget(Namval_t *np) in nv_hasget() argument
1479 for(fp=np->nvfun; fp; fp=fp->next) in nv_hasget()