Lines Matching refs:np

47 char *nv_getv(Namval_t *np, register Namfun_t *nfp)
58 if(!nv_isattr(np,NV_NODISC) || fp==(Namfun_t*)nv_arrayptr(np))
62 cp = (*fp->disc->getval)(np,fp);
65 sfprintf(sh.strbuf,"%.*Lg",12,(*fp->disc->getnum)(np,fp));
71 cp = nv_getval(np);
79 Sfdouble_t nv_getn(Namval_t *np, register Namfun_t *nfp)
92 if(!fp->disc->getnum && nv_isattr(np,NV_INTEGER))
94 if(!nv_isattr(np,NV_NODISC) || fp==(Namfun_t*)nv_arrayptr(np))
98 d = (*fp->disc->getnum)(np,fp);
99 else if(nv_isattr(np,NV_INTEGER))
102 d = nv_getnum(np);
107 str = (*fp->disc->getval)(np,fp);
109 str = nv_getv(np,fp?fp:nfp);
112 if(nv_isattr(np,NV_LJUST|NV_RJUST) || (*str=='0' && !(str[1]=='x'||str[1]=='X')))
126 void nv_putv(Namval_t *np, const char *value, int flags, register Namfun_t *nfp)
140 if(!value && (!(ap=nv_arrayptr(np)) || ap->nelem==0))
143 nv_disc(np,fp,NV_POP);
149 if(!nv_isattr(np,NV_NODISC) || fp==(Namfun_t*)nv_arrayptr(np))
155 (*fp->disc->putval)(np,value, flags, fp);
160 nv_putval(np, value, flags);
162 _nv_unset(np, flags&(NV_RDONLY|NV_EXPORT));
182 Namval_t *np;
197 static struct blocked *block_info(Namval_t *np, struct blocked *pp)
202 if(nv_isarray(np) && (isub=nv_aindex(np)) < 0)
203 sub = nv_associative(np,(const char*)0,NV_ACURRENT);
206 if(bp->np==np && bp->sub==sub && bp->isub==isub)
211 pp->np = np;
225 nv_putsub(bp->np, bp->sub,(bp->isub<0?0:bp->isub)|ARRAY_SETSUB);
231 static void chktfree(register Namval_t *np, register struct vardisc *vp)
243 if((fp=nv_stack(np, NIL(Namfun_t*))) && !(fp->nofree&1))
249 * This function performs an assignment disc on the given node <np>
251 static void assign(Namval_t *np,const char* val,int flags,Namfun_t *handle)
256 struct blocked block, *bp = block_info(np, &block);
258 union Value *up = np->nvalue.up;
261 if(val && (tp=nv_type(np)) && (nr=nv_open(val,sh.var_tree,NV_VARNAME|NV_ARRAY|NV_NOADD|NV_NOFAIL)) && tp==nv_type(nr))
263 char *sub = nv_getsub(np);
264 _nv_unset(np,0);
267 nv_putsub(np, sub, ARRAY_ADD);
268 nv_putval(np,nv_getval(nr), 0);
271 nv_clone(nr,np,0);
279 nv_putv(np,val,flags,handle);
300 sh_fun(nq,np,(char**)0);
305 chktfree(np,vp);
307 if(nv_isarray(np))
308 np->nvalue.up = up;
325 nv_putv(np,cp,flags|NV_RDONLY,handle);
333 nv_putv(np,val,flags,handle);
341 nv_disc(np,handle,NV_POP);
342 nv_putv(np, val, flags, handle);
345 if(nv_isarray(np) && (ap=nv_arrayptr(np)) && ap->nelem>0)
366 * the lookup on the given node <np>
368 static char* lookup(Namval_t *np, int type, Sfdouble_t *dp,Namfun_t *handle)
371 struct blocked block, *bp = block_info(np, &block);
375 union Value *up = np->nvalue.up;
390 sh_fun(nq,np,(char**)0);
393 chktfree(np,vp);
412 if(nv_isarray(np))
413 np->nvalue.up = up;
417 cp = nv_getv(np,handle);
419 *dp = nv_getn(np,handle);
426 static char* lookups(Namval_t *np, Namfun_t *handle)
428 return(lookup(np,LOOKUPS,(Sfdouble_t*)0,handle));
431 static Sfdouble_t lookupn(Namval_t *np, Namfun_t *handle)
434 lookup(np,LOOKUPN, &d ,handle);
441 * If action==np, the current disc is returned
442 * A null return value indicates that no <event> is known for <np>
446 char *nv_setdisc(register Namval_t* np,register const char *event,Namval_t *action,register Namfun_t *fp)
448 register struct vardisc *vp = (struct vardisc*)np->nvfun;
459 if(np == (Namval_t*)fp)
487 return((*fp->disc->setdisc)(np,event,action,fp));
495 if(np != (Namval_t*)fp)
501 return((*fp->disc->setdisc)(np,event,action,fp));
511 if(action==np)
520 if(nv_isarray(np) && !nv_arrayptr(np))
521 nv_putsub(np,(char*)0, 1);
522 nv_stack(np, (Namfun_t*)vp);
524 if(action==np)
543 if(!(bp=block_info(np,(struct blocked*)0)) || !isblocked(bp,UNASSIGN))
544 chktfree(np,vp);
551 * If action==np, the current disc is returned
552 * A null return value indicates that no <event> is known for <np>
556 static char *setdisc(register Namval_t* np,register const char *event,Namval_t *action,register Namfun_t *fp)
582 return(nv_setdisc(np,event,action,fp));
586 if(action==np)
590 Namval_t *tp = nv_type(np);
591 if(tp && (np = (Namval_t*)vp->bltins[type]) && nv_isattr(np,NV_STATICF))
603 static void putdisc(Namval_t* np, const char* val, int flag, Namfun_t* fp)
605 nv_putv(np,val,flag,fp);
624 nv_disc(np,fp,NV_POP);
649 int nv_adddisc(Namval_t *np, const char **names, Namval_t **funs)
670 nv_stack(np,&vp->fun);
675 * push, pop, clne, or reorder disciplines onto node <np>
682 Namfun_t *nv_disc(register Namval_t *np, register Namfun_t* fp, int mode)
685 if(nv_isref(np))
692 if((lp=np->nvfun)==fp)
697 return(np->nvfun=lp);
701 np->nvfun = lp->next;
708 lpp = &np->nvfun;
737 nv_offattr(np,NV_NODISC);
751 return(np->nvfun);
753 for(lp=np->nvfun; lp; fp=lp,lp=lp->next);
754 else if(fp = np->nvfun)
755 np->nvfun = fp->next;
764 Namfun_t *nv_hasdisc(Namval_t *np, const Namdisc_t *dp)
767 for(fp=np->nvfun; fp; fp = fp->next)
781 static void put_notify(Namval_t* np,const char *val,int flags,Namfun_t *fp)
784 nv_putv(np,val,flags,fp);
785 nv_stack(np,fp);
786 nv_stack(np,(Namfun_t*)0);
794 int nv_unsetnotify(Namval_t *np, char **addr)
797 for(fp=np->nvfun;fp;fp=fp->next)
801 nv_stack(np,fp);
802 nv_stack(np,(Namfun_t*)0);
811 int nv_setnotify(Namval_t *np, char **addr)
818 nv_stack(np,&pp->hdr);
825 register Namval_t *np = newof(0,Namval_t,1,s=strlen(name)+1);
826 if(np)
828 np->nvname = (char*)np+sizeof(Namval_t);
829 memcpy(np->nvname,name,s);
831 return((void*)np);
838 static void *num_clone(register Namval_t *np, void *val)
844 if(nv_isattr(np,NV_DOUBLE)==NV_DOUBLE)
846 if(nv_isattr(np,NV_LONG))
848 else if(nv_isattr(np,NV_SHORT))
855 if(nv_isattr(np,NV_LONG))
857 else if(nv_isattr(np,NV_SHORT))
859 if(nv_isattr(np,NV_INT16P)==NV_INT16P)
862 return((void*)np->nvalue.ip);
873 void clone_all_disc( Namval_t *np, Namval_t *mp, int flags)
876 for(fp=np->nvfun; fp;fp=fpnext)
884 nfp = (*fp->disc->clonef)(np,mp,flags,fp);
898 * clone <mp> from <np> flags can be one of the following
899 * NV_APPEND - append <np> onto <mp>
900 * NV_MOVE - move <np> to <mp>
905 int nv_clone(Namval_t *np, Namval_t *mp, int flags)
920 if(fp=np->nvfun)
927 if(!(flags&NV_COMVAR) && !nv_isattr(np,NV_MINIMAL) && np->nvenv && !(nv_isattr(mp,NV_MINIMAL)))
928 mp->nvenv = np->nvenv;
930 mp->nvflag |= np->nvflag&~(NV_ARRAY|NV_MINIMAL|NV_NOFREE);
932 clone_all_disc(np, mp, flags);
937 nv_setsize(mp,nv_size(np));
939 mp->nvflag = (np->nvflag&~(NV_MINIMAL))|(mp->nvflag&NV_MINIMAL);
940 if(nv_isattr(np,NV_EXPORT))
941 mp->nvflag |= (np->nvflag&NV_MINIMAL);
942 if(mp->nvalue.cp==val && !nv_isattr(np,NV_INTEGER))
944 if(np->nvalue.cp && np->nvalue.cp!=Empty && (flags&NV_COMVAR) && !(flags&NV_MOVE))
947 mp->nvalue.cp = (char*)memdup(np->nvalue.cp,size);
949 mp->nvalue.cp = strdup(np->nvalue.cp);
952 else if(!(mp->nvalue.cp = np->nvalue.cp))
957 if(nv_isattr(np,NV_INTEGER))
958 mp->nvalue.ip = np->nvalue.ip;
959 np->nvfun = 0;
960 np->nvalue.cp = 0;
961 if(!nv_isattr(np,NV_MINIMAL) || nv_isattr(mp,NV_EXPORT))
963 mp->nvenv = np->nvenv;
964 np->nvenv = 0;
965 np->nvflag = 0;
968 np->nvflag &= NV_MINIMAL;
969 nv_setsize(np,0);
972 if(nv_isattr(np,NV_INTEGER) && mp->nvalue.ip!=np->nvalue.ip && np->nvalue.cp!=Empty)
974 mp->nvalue.ip = (int*)num_clone(np,(void*)np->nvalue.ip);
978 nv_onattr(np,NV_NOFREE);
985 static char* clone_getv(Namval_t *np, Namfun_t *handle)
987 return(np->nvalue.np?nv_getval(np->nvalue.np):0);
990 static Sfdouble_t clone_getn(Namval_t *np, Namfun_t *handle)
992 return(np->nvalue.np?nv_getnum(np->nvalue.np):0);
995 static void clone_putv(Namval_t *np,const char* val,int flags,Namfun_t *handle)
997 Namfun_t *dp = nv_stack(np,(Namfun_t*)0);
998 Namval_t *mp = np->nvalue.np;
1002 nv_clone(mp,np,NV_NOFREE);
1003 np->nvalue.cp = 0;
1004 nv_putval(np,val,flags);
1017 Namval_t *np;
1019 np = newof(0,Namval_t,1,0);
1020 np->nvflag = mp->nvflag;
1021 np->nvsize = mp->nvsize;
1022 np->nvname = mp->nvname;
1023 np->nvalue.np = mp;
1024 np->nvflag = mp->nvflag;
1027 nv_stack(np,dp);
1028 dtinsert(nv_dict(sh.namespace),np);
1029 return(np);
1035 register Namval_t *np;
1042 if(!(np = dtsearch(root,mp)) && (mode&NV_ADD))
1049 np = dtmatch(root,(void*)name);
1055 if(!np && (mode&NV_ADD))
1065 np = (Namval_t*)dtinsert(root,newnode(name));
1069 return(np);
1086 Namval_t *np, *nq;
1126 np = 0;
1131 np = nq;
1144 return(np);
1160 register Namval_t *np, *nq=0;
1164 if(np = nv_search(path,sh.bltin_tree,0))
1169 if(np->nvfun && !nv_isattr(np,NV_NOFREE))
1170 free((void*)np->nvfun);
1171 dtdelete(sh.bltin_tree,np);
1175 return(np);
1177 else for(np=(Namval_t*)dtfirst(sh.bltin_tree);np;np=(Namval_t*)dtnext(sh.bltin_tree,np))
1179 if(strcmp(name,path_basename(nv_name(np))))
1182 if(strcmp(path,nv_name(np)))
1184 if(nv_isattr(np,BLT_SPC))
1185 return(np);
1187 bltin = np->nvalue.bfp;
1188 if(np->nvenv)
1189 dtdelete(sh.bltin_tree,np);
1192 np = 0;
1196 if(!np && !(np = nv_search(path,sh.bltin_tree,bltin?NV_ADD:0)))
1198 if(nv_isattr(np,BLT_SPC))
1201 np->nvfun = (Namfun_t*)extra;
1202 return(np);
1204 np->nvenv = 0;
1205 np->nvfun = 0;
1208 np->nvalue.bfp = bltin;
1209 nv_onattr(np,NV_BLTIN|NV_NOFREE);
1210 np->nvfun = (Namfun_t*)extra;
1214 cp=nv_setdisc(nq,cp+1,np,(Namfun_t*)nq);
1221 return(np);
1225 extern Namfun_t *nv_stack(register Namval_t *np, register Namfun_t* fp)
1227 return(nv_disc(np,fp,0));
1238 static Namval_t *next_table(register Namval_t* np, Dt_t *root,Namfun_t *fp)
1242 return((Namval_t*)dtnext(root,np));
1247 static Namval_t *create_table(Namval_t *np,const char *name,int flags,Namfun_t *fp)
1250 tp->shp->last_table = np;
1254 static Namfun_t *clone_table(Namval_t* np, Namval_t *mp, int flags, Namfun_t *fp)
1264 for(np=(Namval_t*)dtfirst(oroot);np;np=(Namval_t*)dtnext(oroot,np))
1266 mp = (Namval_t*)dtinsert(nroot,newnode(np->nvname));
1267 nv_clone(np,mp,flags);
1272 static void put_table(register Namval_t* np, const char* val, int flags, Namfun_t* fp)
1277 nv_putv(np,val,flags,fp);
1280 if(nv_isarray(np) && (ap=nv_arrayptr(np)) && array_elem(ap))
1292 np->nvfun = 0;
1298 static char *get_table(Namval_t *np, Namfun_t *fp)
1308 for(np=(Namval_t*)dtfirst(root);np;np=(Namval_t*)dtnext(root,np))
1310 if(!nv_isnull(np) || np->nvfun || nv_isattr(np,~NV_NOFREE))
1316 sfputr(out,np->nvname,-1);
1338 Namval_t *nv_parent(Namval_t *np)
1340 struct table *tp = (struct table *)nv_hasdisc(np,&table_disc);
1346 Dt_t *nv_dict(Namval_t* np)
1349 struct table *tp = (struct table*)nv_hasdisc(np,&table_disc);
1352 np = shp->last_table;
1353 while(np)
1355 if(tp = (struct table*)nv_hasdisc(np,&table_disc))
1358 np = nv_create(np,(const char*)0, NV_FIRST, (Namfun_t*)0);
1366 int nv_istable(Namval_t *np)
1368 return(nv_hasdisc(np,&table_disc)!=0);
1374 Namval_t *nv_mount(Namval_t *np, const char *name, Dt_t *dict)
1378 if(nv_hasdisc(np,&table_disc))
1379 pp = np;
1390 mp = np;
1414 int nv_hasget(Namval_t *np)
1417 for(fp=np->nvfun; fp; fp=fp->next)