Lines Matching refs:np
41 char *nv_getv(Namval_t *np, register Namfun_t *nfp) in nv_getv() argument
52 if(!nv_isattr(np,NV_NODISC) || fp==(Namfun_t*)nv_arrayptr(np)) in nv_getv()
56 cp = (*fp->disc->getval)(np,fp); in nv_getv()
59 sfprintf(sh.strbuf,"%.*Lg",12,(*fp->disc->getnum)(np,fp)); in nv_getv()
65 cp = nv_getval(np); in nv_getv()
73 Sfdouble_t nv_getn(Namval_t *np, register Namfun_t *nfp) in nv_getn() argument
85 if(!fp->disc->getnum && nv_isattr(np,NV_INTEGER)) in nv_getn()
87 if(!nv_isattr(np,NV_NODISC) || fp==(Namfun_t*)nv_arrayptr(np)) in nv_getn()
91 d = (*fp->disc->getnum)(np,fp); in nv_getn()
92 else if(nv_isattr(np,NV_INTEGER)) in nv_getn()
95 d = nv_getnum(np); in nv_getn()
100 str = (*fp->disc->getval)(np,fp); in nv_getn()
102 str = nv_getv(np,fp?fp:nfp); in nv_getn()
116 void nv_putv(Namval_t *np, const char *value, int flags, register Namfun_t *nfp) in nv_putv() argument
132 nv_disc(np,fp,NV_POP); in nv_putv()
138 if(!nv_isattr(np,NV_NODISC) || fp==(Namfun_t*)nv_arrayptr(np)) in nv_putv()
142 (*fp->disc->putval)(np,value, flags, fp); in nv_putv()
147 nv_putval(np, value, flags); in nv_putv()
149 _nv_unset(np, flags&(NV_RDONLY|NV_EXPORT)); in nv_putv()
169 Namval_t *np; member
184 static struct blocked *block_info(Namval_t *np, struct blocked *pp) in block_info() argument
189 if(nv_isarray(np) && (isub=nv_aindex(np)) < 0) in block_info()
190 sub = nv_associative(np,(const char*)0,NV_ACURRENT); in block_info()
193 if(bp->np==np && bp->sub==sub && bp->isub==isub) in block_info()
198 pp->np = np; in block_info()
212 nv_putsub(bp->np, bp->sub,(bp->isub<0?0:bp->isub)|ARRAY_SETSUB); in block_done()
218 static void chktfree(register Namval_t *np, register struct vardisc *vp) in chktfree() argument
230 if((fp=nv_stack(np, NIL(Namfun_t*))) && !(fp->nofree&1)) in chktfree()
238 static void assign(Namval_t *np,const char* val,int flags,Namfun_t *handle) in assign() argument
243 struct blocked block, *bp = block_info(np, &block); in assign()
245 union Value *up = np->nvalue.up; in assign()
248 …if(val && (tp=nv_type(np)) && (nr=nv_open(val,sh.var_tree,NV_VARNAME|NV_ARRAY|NV_NOADD|NV_NOFAIL))… in assign()
250 char *sub = nv_getsub(np); in assign()
251 nv_unset(np); in assign()
254 nv_putsub(np, sub, ARRAY_ADD); in assign()
255 nv_putval(np,nv_getval(nr), 0); in assign()
258 nv_clone(nr,np,0); in assign()
266 nv_putv(np,val,flags,handle); in assign()
287 sh_fun(nq,np,(char**)0); in assign()
292 chktfree(np,vp); in assign()
294 if(nv_isarray(np)) in assign()
295 np->nvalue.up = up; in assign()
312 nv_putv(np,cp,flags|NV_RDONLY,handle); in assign()
320 nv_putv(np,val,flags,handle); in assign()
328 nv_putv(np, val, flags, handle); in assign()
331 if(nv_isarray(np) && (ap=nv_arrayptr(np)) && ap->nelem>0) in assign()
342 nv_disc(np,handle,NV_POP); in assign()
355 static char* lookup(Namval_t *np, int type, Sfdouble_t *dp,Namfun_t *handle) in lookup() argument
358 struct blocked block, *bp = block_info(np, &block); in lookup()
362 union Value *up = np->nvalue.up; in lookup()
377 sh_fun(nq,np,(char**)0); in lookup()
380 chktfree(np,vp); in lookup()
395 if(nv_isarray(np)) in lookup()
396 np->nvalue.up = up; in lookup()
400 cp = nv_getv(np,handle); in lookup()
402 *dp = nv_getn(np,handle); in lookup()
409 static char* lookups(Namval_t *np, Namfun_t *handle) in lookups() argument
411 return(lookup(np,LOOKUPS,(Sfdouble_t*)0,handle)); in lookups()
414 static Sfdouble_t lookupn(Namval_t *np, Namfun_t *handle) in lookupn() argument
417 lookup(np,LOOKUPN, &d ,handle); in lookupn()
429 char *nv_setdisc(register Namval_t* np,register const char *event,Namval_t *action,register Namfun_… in nv_setdisc() argument
431 register struct vardisc *vp = (struct vardisc*)np->nvfun; in nv_setdisc()
442 if(np == (Namval_t*)fp) in nv_setdisc()
470 return((*fp->disc->setdisc)(np,event,action,fp)); in nv_setdisc()
478 if(np != (Namval_t*)fp) in nv_setdisc()
484 return((*fp->disc->setdisc)(np,event,action,fp)); in nv_setdisc()
494 if(action==np) in nv_setdisc()
503 if(nv_isarray(np) && !nv_arrayptr(np)) in nv_setdisc()
504 nv_putsub(np,(char*)0, 1); in nv_setdisc()
505 nv_stack(np, (Namfun_t*)vp); in nv_setdisc()
507 if(action==np) in nv_setdisc()
526 if(!(bp=block_info(np,(struct blocked*)0)) || !isblocked(bp,UNASSIGN)) in nv_setdisc()
527 chktfree(np,vp); in nv_setdisc()
539 static char *setdisc(register Namval_t* np,register const char *event,Namval_t *action,register Nam… in setdisc() argument
565 return(nv_setdisc(np,event,action,fp)); in setdisc()
569 if(action==np) in setdisc()
581 static void putdisc(Namval_t* np, const char* val, int flag, Namfun_t* fp) in putdisc() argument
583 nv_putv(np,val,flag,fp); in putdisc()
602 nv_disc(np,fp,NV_POP); in putdisc()
627 int nv_adddisc(Namval_t *np, const char **names, Namval_t **funs) in nv_adddisc() argument
648 nv_stack(np,&vp->fun); in nv_adddisc()
660 Namfun_t *nv_disc(register Namval_t *np, register Namfun_t* fp, int mode) in nv_disc() argument
663 if(nv_isref(np)) in nv_disc()
670 if((lp=np->nvfun)==fp) in nv_disc()
675 return(np->nvfun=lp); in nv_disc()
679 np->nvfun = lp->next; in nv_disc()
686 lpp = &np->nvfun; in nv_disc()
715 nv_offattr(np,NV_NODISC); in nv_disc()
729 return(np->nvfun); in nv_disc()
731 for(lp=np->nvfun; lp; fp=lp,lp=lp->next); in nv_disc()
732 else if(fp = np->nvfun) in nv_disc()
733 np->nvfun = fp->next; in nv_disc()
742 Namfun_t *nv_hasdisc(Namval_t *np, const Namdisc_t *dp) in nv_hasdisc() argument
745 for(fp=np->nvfun; fp; fp = fp->next) in nv_hasdisc()
759 static void put_notify(Namval_t* np,const char *val,int flags,Namfun_t *fp) in put_notify() argument
762 nv_putv(np,val,flags,fp); in put_notify()
763 nv_stack(np,fp); in put_notify()
764 nv_stack(np,(Namfun_t*)0); in put_notify()
772 int nv_unsetnotify(Namval_t *np, char **addr) in nv_unsetnotify() argument
775 for(fp=np->nvfun;fp;fp=fp->next) in nv_unsetnotify()
779 nv_stack(np,fp); in nv_unsetnotify()
780 nv_stack(np,(Namfun_t*)0); in nv_unsetnotify()
789 int nv_setnotify(Namval_t *np, char **addr) in nv_setnotify() argument
796 nv_stack(np,&pp->hdr); in nv_setnotify()
803 register Namval_t *np = newof(0,Namval_t,1,s=strlen(name)+1); in newnode() local
804 if(np) in newnode()
806 np->nvname = (char*)np+sizeof(Namval_t); in newnode()
807 memcpy(np->nvname,name,s); in newnode()
809 return((void*)np); in newnode()
816 static void *num_clone(register Namval_t *np, void *val) in num_clone() argument
822 if(nv_isattr(np,NV_DOUBLE)==NV_DOUBLE) in num_clone()
824 if(nv_isattr(np,NV_LONG)) in num_clone()
826 else if(nv_isattr(np,NV_SHORT)) in num_clone()
833 if(nv_isattr(np,NV_LONG)) in num_clone()
835 else if(nv_isattr(np,NV_SHORT)) in num_clone()
837 if(nv_isattr(np,NV_INT16P)==NV_INT16P) in num_clone()
840 return((void*)np->nvalue.ip); in num_clone()
851 void clone_all_disc( Namval_t *np, Namval_t *mp, int flags) in clone_all_disc() argument
854 for(fp=np->nvfun; fp;fp=fpnext) in clone_all_disc()
862 nfp = (*fp->disc->clonef)(np,mp,flags,fp); in clone_all_disc()
883 int nv_clone(Namval_t *np, Namval_t *mp, int flags) in nv_clone() argument
898 if(fp=np->nvfun) in nv_clone()
905 if(!(flags&NV_COMVAR) && !nv_isattr(np,NV_MINIMAL) && np->nvenv && !(nv_isattr(mp,NV_MINIMAL))) in nv_clone()
906 mp->nvenv = np->nvenv; in nv_clone()
908 mp->nvflag |= np->nvflag&~(NV_ARRAY|NV_MINIMAL|NV_NOFREE); in nv_clone()
910 clone_all_disc(np, mp, flags); in nv_clone()
915 nv_setsize(mp,nv_size(np)); in nv_clone()
917 mp->nvflag = (np->nvflag&~(NV_MINIMAL))|(mp->nvflag&NV_MINIMAL); in nv_clone()
918 if(nv_isattr(np,NV_EXPORT)) in nv_clone()
919 mp->nvflag |= (np->nvflag&NV_MINIMAL); in nv_clone()
920 if(mp->nvalue.cp==val && !nv_isattr(np,NV_INTEGER)) in nv_clone()
922 if(np->nvalue.cp && np->nvalue.cp!=Empty && (flags&NV_COMVAR) && !(flags&NV_MOVE)) in nv_clone()
925 mp->nvalue.cp = (char*)memdup(np->nvalue.cp,size); in nv_clone()
927 mp->nvalue.cp = strdup(np->nvalue.cp); in nv_clone()
930 else if(!(mp->nvalue.cp = np->nvalue.cp)) in nv_clone()
935 if(nv_isattr(np,NV_INTEGER)) in nv_clone()
936 mp->nvalue.ip = np->nvalue.ip; in nv_clone()
937 np->nvfun = 0; in nv_clone()
938 np->nvalue.cp = 0; in nv_clone()
939 if(!nv_isattr(np,NV_MINIMAL) || nv_isattr(mp,NV_EXPORT)) in nv_clone()
941 mp->nvenv = np->nvenv; in nv_clone()
942 np->nvenv = 0; in nv_clone()
943 np->nvflag = 0; in nv_clone()
946 np->nvflag &= NV_MINIMAL; in nv_clone()
947 nv_setsize(np,0); in nv_clone()
950 if(nv_isattr(np,NV_INTEGER) && mp->nvalue.ip!=np->nvalue.ip) in nv_clone()
952 mp->nvalue.ip = (int*)num_clone(np,(void*)np->nvalue.ip); in nv_clone()
956 nv_onattr(np,NV_NOFREE); in nv_clone()
963 static char* clone_getv(Namval_t *np, Namfun_t *handle) in clone_getv() argument
965 return(np->nvalue.np?nv_getval(np->nvalue.np):0); in clone_getv()
968 static Sfdouble_t clone_getn(Namval_t *np, Namfun_t *handle) in clone_getn() argument
970 return(np->nvalue.np?nv_getnum(np->nvalue.np):0); in clone_getn()
973 static void clone_putv(Namval_t *np,const char* val,int flags,Namfun_t *handle) in clone_putv() argument
975 Namfun_t *dp = nv_stack(np,(Namfun_t*)0); in clone_putv()
976 Namval_t *mp = np->nvalue.np; in clone_putv()
980 nv_clone(mp,np,NV_NOFREE); in clone_putv()
981 np->nvalue.cp = 0; in clone_putv()
982 nv_putval(np,val,flags); in clone_putv()
995 Namval_t *np; in nv_mkclone() local
997 np = newof(0,Namval_t,1,0); in nv_mkclone()
998 np->nvflag = mp->nvflag; in nv_mkclone()
999 np->nvsize = mp->nvsize; in nv_mkclone()
1000 np->nvname = mp->nvname; in nv_mkclone()
1001 np->nvalue.np = mp; in nv_mkclone()
1002 np->nvflag = mp->nvflag; in nv_mkclone()
1005 nv_stack(np,dp); in nv_mkclone()
1006 dtinsert(nv_dict(sh.namespace),np); in nv_mkclone()
1007 return(np); in nv_mkclone()
1013 register Namval_t *np; in nv_search() local
1020 if(!(np = dtsearch(root,mp)) && (mode&NV_ADD)) in nv_search()
1027 np = dtmatch(root,(void*)name); in nv_search()
1029 if(!np && (mode&NV_ADD)) in nv_search()
1039 np = (Namval_t*)dtinsert(root,newnode(name)); in nv_search()
1043 return(np); in nv_search()
1059 Namval_t *np, *nq; in nv_bfsearch() local
1106 np = 0; in nv_bfsearch()
1111 np = nq; in nv_bfsearch()
1120 return(np); in nv_bfsearch()
1136 register Namval_t *np, *nq=0; in sh_addbuiltin() local
1140 if(np = nv_search(path,sh.bltin_tree,0)) in sh_addbuiltin()
1145 if(np->nvfun && !nv_isattr(np,NV_NOFREE)) in sh_addbuiltin()
1146 free((void*)np->nvfun); in sh_addbuiltin()
1147 dtdelete(sh.bltin_tree,np); in sh_addbuiltin()
1151 return(np); in sh_addbuiltin()
1153 else for(np=(Namval_t*)dtfirst(sh.bltin_tree);np;np=(Namval_t*)dtnext(sh.bltin_tree,np)) in sh_addbuiltin()
1155 if(strcmp(name,path_basename(nv_name(np)))) in sh_addbuiltin()
1158 if(strcmp(path,nv_name(np))) in sh_addbuiltin()
1160 if(nv_isattr(np,BLT_SPC)) in sh_addbuiltin()
1161 return(np); in sh_addbuiltin()
1163 bltin = np->nvalue.bfp; in sh_addbuiltin()
1164 if(np->nvenv) in sh_addbuiltin()
1165 dtdelete(sh.bltin_tree,np); in sh_addbuiltin()
1168 np = 0; in sh_addbuiltin()
1172 if(!np && !(np = nv_search(path,sh.bltin_tree,bltin?NV_ADD:0))) in sh_addbuiltin()
1174 if(nv_isattr(np,BLT_SPC)) in sh_addbuiltin()
1177 np->nvfun = (Namfun_t*)extra; in sh_addbuiltin()
1178 return(np); in sh_addbuiltin()
1180 np->nvenv = 0; in sh_addbuiltin()
1181 np->nvfun = 0; in sh_addbuiltin()
1184 np->nvalue.bfp = bltin; in sh_addbuiltin()
1185 nv_onattr(np,NV_BLTIN|NV_NOFREE); in sh_addbuiltin()
1186 np->nvfun = (Namfun_t*)extra; in sh_addbuiltin()
1190 cp=nv_setdisc(nq,cp+1,np,(Namfun_t*)nq); in sh_addbuiltin()
1197 return(np); in sh_addbuiltin()
1201 extern Namfun_t *nv_stack(register Namval_t *np, register Namfun_t* fp) in nv_stack() argument
1203 return(nv_disc(np,fp,0)); in nv_stack()
1214 static Namval_t *next_table(register Namval_t* np, Dt_t *root,Namfun_t *fp) in next_table() argument
1218 return((Namval_t*)dtnext(root,np)); in next_table()
1223 static Namval_t *create_table(Namval_t *np,const char *name,int flags,Namfun_t *fp) in create_table() argument
1226 tp->shp->last_table = np; in create_table()
1230 static Namfun_t *clone_table(Namval_t* np, Namval_t *mp, int flags, Namfun_t *fp) in clone_table() argument
1240 for(np=(Namval_t*)dtfirst(oroot);np;np=(Namval_t*)dtnext(oroot,np)) in clone_table()
1242 mp = (Namval_t*)dtinsert(nroot,newnode(np->nvname)); in clone_table()
1243 nv_clone(np,mp,flags); in clone_table()
1248 static void put_table(register Namval_t* np, const char* val, int flags, Namfun_t* fp) in put_table() argument
1253 nv_putv(np,val,flags,fp); in put_table()
1256 if(nv_isarray(np) && (ap=nv_arrayptr(np)) && array_elem(ap)) in put_table()
1273 static char *get_table(Namval_t *np, Namfun_t *fp) in get_table() argument
1283 for(np=(Namval_t*)dtfirst(root);np;np=(Namval_t*)dtnext(root,np)) in get_table()
1285 if(!nv_isnull(np) || np->nvfun || nv_isattr(np,~NV_NOFREE)) in get_table()
1291 sfputr(out,np->nvname,-1); in get_table()
1313 Namval_t *nv_parent(Namval_t *np) in nv_parent() argument
1315 struct table *tp = (struct table *)nv_hasdisc(np,&table_disc); in nv_parent()
1321 Dt_t *nv_dict(Namval_t* np) in nv_dict() argument
1323 struct table *tp = (struct table*)nv_hasdisc(np,&table_disc); in nv_dict()
1326 np = sh.last_table; in nv_dict()
1327 while(np) in nv_dict()
1329 if(tp = (struct table*)nv_hasdisc(np,&table_disc)) in nv_dict()
1332 np = nv_create(np,(const char*)0, NV_FIRST, (Namfun_t*)0); in nv_dict()
1343 Namval_t *nv_mount(Namval_t *np, const char *name, Dt_t *dict) in nv_mount() argument
1349 if(nv_istable(np)) in nv_mount()
1350 pp = np; in nv_mount()
1362 mp = np; in nv_mount()
1386 int nv_hasget(Namval_t *np) in nv_hasget() argument
1389 for(fp=np->nvfun; fp; fp=fp->next) in nv_hasget()