Lines Matching refs:np
92 Namval_t *np; member
138 void sh_envput(Env_t* ep,Namval_t *np) in sh_envput() argument
141 Namarr_t *ap = nv_arrayptr(np); in sh_envput()
146 nv_putsub(np,"0",0L); in sh_envput()
147 else if(!(val=nv_getsub(np)) || strcmp(val,"0")) in sh_envput()
150 if(!(val = nv_getval(np))) in sh_envput()
152 stakputs(nv_name(np)); in sh_envput()
204 Namval_t *nv_addnode(Namval_t* np, int remove) in nv_addnode() argument
209 if(sp->numnodes==0 && !nv_isnull(np) && sh.last_table) in nv_addnode()
213 sp->rp = np; in nv_addnode()
214 nv_delete(np,root,NV_NOFREE); in nv_addnode()
215 np = nv_search(sp->rp->nvname,root,NV_ADD); in nv_addnode()
217 if(sp->numnodes && memcmp(np->nvname,NV_CLASS,sizeof(NV_CLASS)-1)) in nv_addnode()
221 if(memcmp(np->nvname,name,i)) in nv_addnode()
222 return(np); in nv_addnode()
227 if(name && np->nvname[i]=='.' && np->nvname[i+1]=='_' && np->nvname[i+2]==0) in nv_addnode()
239 if(np == sp->nodes[i]) in nv_addnode()
247 return(np); in nv_addnode()
251 return(np); in nv_addnode()
257 sp->nodes[sp->numnodes++] = np; in nv_addnode()
258 return(np); in nv_addnode()
290 register Namval_t *np, *mp; in nv_setlist() local
350 np = nv_open(prefix,shp->var_tree,flag); in nv_setlist()
352 if(np) in nv_setlist()
354 if(nv_isvtree(np) && !nv_isarray(np)) in nv_setlist()
360 nv_close(np); in nv_setlist()
363 np = nv_open(cp,shp->var_tree,flag|NV_ASSIGN); in nv_setlist()
364 if(typ && !array && (nv_isnull(np) || nv_isarray(np))) in nv_setlist()
365 nv_settype(np,typ,0); in nv_setlist()
366 if((flags&NV_STATIC) && !nv_isnull(np)) in nv_setlist()
372 if(array && (!(ap=nv_arrayptr(np)) || !ap->hdr.type)) in nv_setlist()
375 nv_unset(np); in nv_setlist()
378 nv_setarray(np,nv_associative); in nv_setlist()
382 nv_onattr(np,NV_ARRAY); in nv_setlist()
401 if(shp->mktype && shp->dot_depth==0 && np==((struct sh_type*)shp->mktype)->nodes[0]) in nv_setlist()
409 if(!nv_isarray(np) || ((ap=nv_arrayptr(np)) && (ap->nelem&ARRAY_MASK))) in nv_setlist()
410 nv_unset(np); in nv_setlist()
412 nv_setvec(np,(arg->argflag&ARG_APPEND),argc,argv); in nv_setlist()
416 char *name = nv_name(np); in nv_setlist()
444 cp = stakcopy(nv_name(np)); in nv_setlist()
448 if((arg->argflag&ARG_APPEND) && (!nv_isarray(np) || (nv_aindex(np)>=0))) in nv_setlist()
449 nv_unset(np); in nv_setlist()
451 nv_setarray(np,nv_associative); in nv_setlist()
456 nv_setvtree(np); in nv_setlist()
457 nv_close(np); in nv_setlist()
466 nv_close(np); in nv_setlist()
467 np = nv_open(cp,shp->var_tree,flag); in nv_setlist()
471 if(nv_isarray(np)) in nv_setlist()
473 if((sub=nv_aimax(np)) < 0 && nv_arrayptr(np)) in nv_setlist()
474 errormsg(SH_DICT,ERROR_exit(1),e_badappend,nv_name(np)); in nv_setlist()
478 if(!nv_isnull(np) && np->nvalue.cp!=Empty && !nv_isvtree(np)) in nv_setlist()
481 else if(np->nvalue.cp && np->nvalue.cp!=Empty && !nv_type(np)) in nv_setlist()
483 _nv_unset(np,NV_EXPORT); in nv_setlist()
489 _nv_unset(np,NV_EXPORT); in nv_setlist()
490 if(!sh_isoption(SH_BASH) && !(array&NV_IARRAY) && !nv_isarray(np)) in nv_setlist()
491 nv_setarray(np,nv_associative); in nv_setlist()
496 sfprintf(stkstd,"%s[%d]",prefix?nv_name(np):cp,sub); in nv_setlist()
498 nv_putsub(np,(char*)0,ARRAY_ADD|ARRAY_FILL|sub); in nv_setlist()
501 shp->prefix = stakcopy(nv_name(np)); in nv_setlist()
509 sfprintf(stkstd,"%s%s",nv_name(L_ARGNOD->nvalue.nrp->np),shp->prefix+1); in nv_setlist()
515 nr.np = np; in nv_setlist()
531 if(nv_isarray(np) && (mp=nv_opensub(np))) in nv_setlist()
532 np = mp; in nv_setlist()
540 …if(!nv_isarray(np) && !typ && (tp->com.comarg || !tp->com.comset || tp->com.comset->argval[0]!='['… in nv_setlist()
542 nv_setvtree(np); in nv_setlist()
544 np->nvfun->dsize = 0; in nv_setlist()
555 np = nv_open(cp,shp->var_tree,flags); in nv_setlist()
556 if(!np->nvfun && (flags&NV_NOREF)) in nv_setlist()
559 nv_onattr(np,NV_PARAM); in nv_setlist()
561 nv_offattr(np,NV_PARAM); in nv_setlist()
566 char *name=nv_name(np); in nv_setlist()
569 if(nv_isarray(np)) in nv_setlist()
603 np = nv_mktype(shtp.nodes,shtp.numnodes); in nv_setlist()
608 if(nr.np == np) in nv_setlist()
690 register Namval_t *np=0, *nq=0; in nv_create() local
713 return(np); in nv_create()
744 np=0; in nv_create()
755 if(np = nv_search(name,shp->var_tree,0)) in nv_create()
759 nq = np; in nv_create()
766 nv_delete(np,(Dt_t*)0,0); in nv_create()
767 np = 0; in nv_create()
781 if(np && shp->var_tree->walk==shp->var_tree) in nv_create()
783 _nv_unset(np,0); in nv_create()
784 nv_delete(np,shp->var_tree,0); in nv_create()
785 np = 0; in nv_create()
787 if(!np || shp->var_tree->walk!=root) in nv_create()
788 np = nv_search(name,root,HASH_NOSCOPE|NV_ADD); in nv_create()
791 if(np || (np = nv_search(name,root,mode))) in nv_create()
793 isref = nv_isref(np); in nv_create()
796 if(nq==np) in nv_create()
803 if(nv_isnull(np) && c!='.' && (np->nvfun=nv_cover(nq))) in nv_create()
804 np->nvname = nq->nvname; in nv_create()
808 else if(add && nv_isnull(np) && c=='.' && cp[1]!='.') in nv_create()
809 nv_setvtree(np); in nv_create()
825 nv_unref(np); in nv_create()
826 return(np); in nv_create()
828 while(nv_isref(np) && np->nvalue.cp) in nv_create()
830 root = nv_reftree(np); in nv_create()
832 shp->last_table = nv_reftable(np); in nv_create()
833 sub = nv_refsub(np); in nv_create()
834 np = nv_refnode(np); in nv_create()
836 nv_putsub(np,sub,0L); in nv_create()
840 if(nv_isref(np) && (c=='[' || c=='.' || !(flags&NV_ASSIGN))) in nv_create()
841 errormsg(SH_DICT,ERROR_exit(1),e_noref,nv_name(np)); in nv_create()
843 return(np); in nv_create()
844 if(np==nq) in nv_create()
849 copy = strlen(cp=nv_name(np)); in nv_create()
859 if(nv_isnull(np)) in nv_create()
860 nv_onattr(np,NV_NOFREE); in nv_create()
869 return(np); in nv_create()
875 if(!np) in nv_create()
888 return(np); in nv_create()
890 if(c=='[' || (c=='.' && nv_isarray(np))) in nv_create()
898 Namarr_t *ap = nv_arrayptr(np); in nv_create()
901 n = mode|nv_isarray(np); in nv_create()
906 return(np); in nv_create()
912 cp = nv_endsubscript(np,sp,n|(flags&NV_ASSIGN)); in nv_create()
915 nv_putsub(np,NIL(char*),ARRAY_SCAN); in nv_create()
920 if((c = *cp)=='.' || (c=='[' && nv_isarray(np)) || (n&ARRAY_FILL) || (flags&NV_ARRAY)) in nv_create()
924 sub = m?nv_getsub(np):0; in nv_create()
963 else if(c==0 && mode && (n=nv_aindex(np))>0) in nv_create()
964 nv_putsub(np,(char*)0,n); in nv_create()
965 else if(n==0 && (c==0 || (c=='[' && !nv_isarray(np)))) in nv_create()
977 if(nv_isarray(np) && (c=='[' || c=='.' || (flags&NV_ARRAY))) in nv_create()
980 if(!(nq = nv_opensub(np))) in nv_create()
982 Namarr_t *ap = nv_arrayptr(np); in nv_create()
988 nv_putsub(np,sub,ARRAY_FILL); in nv_create()
989 ap = nv_arrayptr(np); in nv_create()
994 nq->nvenv = (char*)np; in nv_create()
996 nq = nv_arraychild(np,nq,c); in nv_create()
1006 np = nq; in nv_create()
1018 else if(nv_isarray(np)) in nv_create()
1021 return(np); in nv_create()
1022 nv_putsub(np,NIL(char*),ARRAY_UNDEF); in nv_create()
1024 if(c=='.' && (fp=np->nvfun)) in nv_create()
1033 if((nq = (*fp->disc->createf)(np,cp+1,flags,fp)) == np) in nv_create()
1039 else if(np=nq) in nv_create()
1043 if(nv_isarray(np) && sp[-1]!=']') in nv_create()
1044 nv_putsub(np,NIL(char*),ARRAY_UNDEF); in nv_create()
1045 return(np); in nv_create()
1053 return(np); in nv_create()
1059 return(np); in nv_create()
1064 return(np); in nv_create()
1072 void nv_delete(Namval_t* np, Dt_t *root, int flags) in nv_delete() argument
1079 if(xp->np==np) in nv_delete()
1085 if(dtdelete(root,np)) in nv_delete()
1087 if(!(flags&NV_NOFREE) && ((flags&NV_FUNCTION) || !nv_subsaved(np))) in nv_delete()
1088 free((void*)np); in nv_delete()
1093 sfprintf(sfstderr,"%s not deleted\n",nv_name(np)); in nv_delete()
1120 register Namval_t *np; in nv_open() local
1141 if((np=shp->namespace) || strchr(name,'.')) in nv_open()
1143 name = cp = copystack(np?nv_name(np):0,name,(const char*)0); in nv_open()
1157 np = nv_search(name,root,mode); in nv_open()
1158 if(np && !(flags&NV_REF)) in nv_open()
1160 while(nv_isref(np)) in nv_open()
1162 shp->last_table = nv_reftable(np); in nv_open()
1163 np = nv_refnode(np); in nv_open()
1166 return(np); in nv_open()
1183 np = nv_search(name, root, (flags&NV_NOADD)?0:NV_ADD); in nv_open()
1208 np = xp->np; in nv_open()
1210 if(nv_isarray(np)) in nv_open()
1211 nv_putsub(np,NIL(char*),ARRAY_UNDEF); in nv_open()
1219 np = nv_create(name, root, flags, &fun); in nv_open()
1222 if(np && nvcache.ok && cp[-1]!=']') in nv_open()
1246 xp->np = np; in nv_open()
1259 np = nv_search(name, funroot, c); in nv_open()
1278 if(np && shp->mktype) in nv_open()
1279 np = nv_addnode(np,0); in nv_open()
1281 if(c=='=' && np && (flags&NV_ASSIGN)) in nv_open()
1286 nv_putval(np, cp, NV_RDONLY); in nv_open()
1287 if(np==PWDNOD) in nv_open()
1288 nv_onattr(np,NV_TAGGED); in nv_open()
1297 if(!nv_isnull(np)) in nv_open()
1300 return(np); in nv_open()
1303 isref = nv_isref(np); in nv_open()
1304 if(sh_isoption(SH_XTRACE) && nv_isarray(np)) in nv_open()
1305 sub = nv_getsub(np); in nv_open()
1308 nv_offattr(np,NV_REF); in nv_open()
1311 nv_offattr(np,NV_LJUST|NV_RJUST|NV_ZFILL); in nv_open()
1312 np->nvsize = 0; in nv_open()
1314 nv_putval(np, cp, c); in nv_open()
1317 if(nv_search((char*)np,shp->var_base,HASH_BUCKET)) in nv_open()
1319 nv_setref(np,(Dt_t*)0,NV_VARNAME); in nv_open()
1324 nv_onattr(np, flags&NV_ATTRIBUTES); in nv_open()
1338 return(np); in nv_open()
1357 void nv_putval(register Namval_t *np, const char *string, int flags) in nv_putval() argument
1366 if(!(flags&NV_RDONLY) && nv_isattr (np, NV_RDONLY)) in nv_putval()
1367 errormsg(SH_DICT,ERROR_exit(1),e_readonly, nv_name(np)); in nv_putval()
1373 np = sh_assignok(np,1); in nv_putval()
1374 if(np->nvfun && np->nvfun->disc && !(flags&NV_NODISC) && !nv_isref(np)) in nv_putval()
1380 nv_putv(np,sp,flags,np->nvfun); in nv_putval()
1381 if(sp && ((flags&NV_EXPORT) || nv_isattr(np,NV_EXPORT))) in nv_putval()
1382 sh_envput(sh.env,np); in nv_putval()
1391 if(np->nvalue.cp && np->nvalue.cp!=sp && !nv_isattr(np,NV_NOFREE)) in nv_putval()
1392 free((void*)np->nvalue.cp); in nv_putval()
1393 np->nvalue.cp = (char*)sp; in nv_putval()
1394 nv_setattr(np,(flags&~NV_RDONLY)|NV_NOFREE); in nv_putval()
1397 up= &np->nvalue; in nv_putval()
1398 if(nv_isattr(np,NV_INT16P) == NV_INT16) in nv_putval()
1400 if(!np->nvalue.up || !nv_isarray(np)) in nv_putval()
1403 up->up = &np->nvalue; in nv_putval()
1406 else if(np->nvalue.up && nv_isarray(np) && nv_arrayptr(np)) in nv_putval()
1407 up = np->nvalue.up; in nv_putval()
1410 if(nv_isattr(np,NV_EXPORT)) in nv_putval()
1411 nv_offattr(np,NV_IMPORT); in nv_putval()
1412 if(nv_isattr (np, NV_INTEGER)) in nv_putval()
1414 if(nv_isattr(np, NV_DOUBLE) == NV_DOUBLE) in nv_putval()
1416 if(nv_isattr(np, NV_LONG) && sizeof(double)<sizeof(Sfdouble_t)) in nv_putval()
1459 if(nv_isattr(np, NV_LONG) && sizeof(int32_t)<sizeof(Sflong_t)) in nv_putval()
1473 else if(nv_isattr(np,NV_UNSIGN)) in nv_putval()
1516 else if(nv_isattr(np,NV_UNSIGN)) in nv_putval()
1543 if(nv_size(np) <= 1) in nv_putval()
1544 nv_setsize(np,10); in nv_putval()
1545 if(nv_isattr (np, NV_SHORT)) in nv_putval()
1551 nv_onattr(np,NV_NOFREE); in nv_putval()
1596 if(nv_isattr(np, NV_HOST|NV_INTEGER)==NV_HOST && sp) in nv_putval()
1614 else if((nv_isattr(np, NV_RJUST|NV_ZFILL|NV_LJUST)) && sp) in nv_putval()
1617 if((nv_isattr(np,NV_ZFILL)) && (nv_isattr(np,NV_LJUST))) in nv_putval()
1619 size = nv_size(np); in nv_putval()
1622 size = ja_size((char*)sp,size,nv_isattr(np,NV_RJUST|NV_ZFILL)); in nv_putval()
1627 if((flags&NV_APPEND) && !nv_isattr(np,NV_BINARY)) in nv_putval()
1635 if(!nv_isattr(np, NV_NOFREE)) in nv_putval()
1640 if(nv_isattr(np,NV_BINARY) && !(flags&NV_RAW)) in nv_putval()
1642 if(nv_isattr(np,NV_LJUST|NV_RJUST) && nv_isattr(np,NV_LJUST|NV_RJUST)!=(NV_LJUST|NV_RJUST)) in nv_putval()
1648 if(nv_isattr(np,NV_BINARY)) in nv_putval()
1650 int oldsize = (flags&NV_APPEND)?nv_size(np):0; in nv_putval()
1656 nv_offattr(np,NV_NOFREE); in nv_putval()
1662 if(nv_isattr(np,NV_ZFILL)) in nv_putval()
1663 size = nv_size(np); in nv_putval()
1667 nv_offattr(np,NV_NOFREE); in nv_putval()
1675 if(!nv_isattr(np,NV_ZFILL) || nv_size(np)==0) in nv_putval()
1676 nv_setsize(np,dot); in nv_putval()
1677 else if(nv_isattr(np,NV_ZFILL) && (size>dot)) in nv_putval()
1683 if(size==0 && nv_isattr(np,NV_HOST)!=NV_HOST &&nv_isattr(np,NV_LJUST|NV_RJUST|NV_ZFILL)) in nv_putval()
1684 nv_setsize(np,size=dot); in nv_putval()
1687 else if(nv_isattr(np,NV_LJUST|NV_RJUST)==NV_LJUST && dot>size) in nv_putval()
1693 nv_offattr(np,NV_NOFREE); in nv_putval()
1705 if(nv_isattr(np, NV_LTOU)) in nv_putval()
1707 else if(nv_isattr (np, NV_UTOL)) in nv_putval()
1710 if(nv_isattr(np, NV_RJUST) && nv_isattr(np, NV_ZFILL)) in nv_putval()
1712 else if(nv_isattr(np, NV_LJUST|NV_RJUST)==NV_RJUST) in nv_putval()
1714 else if(nv_isattr(np, NV_LJUST|NV_RJUST)==NV_LJUST) in nv_putval()
1732 if(!was_local && ((flags&NV_EXPORT) || nv_isattr(np,NV_EXPORT))) in nv_putval()
1733 sh_envput(sh.env,np); in nv_putval()
1845 static char *staknam(register Namval_t *np, char *value) in staknam() argument
1848 q = stakalloc(strlen(nv_name(np))+(value?strlen(value):0)+2); in staknam()
1849 p=strcopy(q,nv_name(np)); in staknam()
1863 static void attstore(register Namval_t *np, void *data) in attstore() argument
1867 if(!(nv_isattr(np,NV_EXPORT))) in attstore()
1869 flag = nv_isattr(np,NV_RDONLY|NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER); in attstore()
1880 c += nv_size(np); in attstore()
1883 stakputs(nv_name(np)); in attstore()
1886 static void attstore(register Namval_t *np, void *data) in attstore() argument
1888 register int flag = np->nvflag; in attstore()
1906 *ap->attval = ' ' + nv_size(np); in attstore()
1910 ap->attval = strcopy(++ap->attval,nv_name(np)); in attstore()
1915 static void pushnam(Namval_t *np, void *data) in pushnam() argument
1921 if(nv_isattr(np,NV_IMPORT) && np->nvenv) in pushnam()
1922 *ap->argnam++ = np->nvenv; in pushnam()
1923 else if(value=nv_getval(np)) in pushnam()
1924 *ap->argnam++ = staknam(np,value); in pushnam()
1925 if(nv_isattr(np,NV_RDONLY|NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER)) in pushnam()
1926 ap->attsize += (strlen(nv_name(np))+4); in pushnam()
1993 register Namval_t *np = (Namval_t*)arg; in scanfilter() local
1994 register int k=np->nvflag; in scanfilter()
1999 if(!is_abuiltin(np) && tp && tp->tp && nv_type(np)!=tp->tp) in scanfilter()
2004 if(!np->nvalue.cp && !np->nvfun && !nv_isattr(np,~NV_DEFAULT)) in scanfilter()
2008 if(nv_isarray(np)) in scanfilter()
2009 nv_putsub(np,NIL(char*),0L); in scanfilter()
2010 (*sp->scanfn)(np,sp->scandata); in scanfilter()
2077 void sh_envnolocal (register Namval_t *np, void *data) in sh_envnolocal() argument
2081 if(np==VERSIONNOD && nv_isref(np)) in sh_envnolocal()
2083 if(np==L_ARGNOD) in sh_envnolocal()
2085 if(nv_isattr(np,NV_EXPORT) && nv_isarray(np)) in sh_envnolocal()
2087 nv_putsub(np,NIL(char*),0); in sh_envnolocal()
2088 if(cp = nv_getval(np)) in sh_envnolocal()
2091 if(nv_isattr(np,NV_EXPORT|NV_NOFREE)) in sh_envnolocal()
2093 if(nv_isref(np) && np!=VERSIONNOD) in sh_envnolocal()
2095 nv_offattr(np,NV_NOFREE|NV_REF); in sh_envnolocal()
2096 free((void*)np->nvalue.nrp); in sh_envnolocal()
2097 np->nvalue.cp = 0; in sh_envnolocal()
2102 if(nv_isarray(np)) in sh_envnolocal()
2103 nv_putsub(np,NIL(char*),ARRAY_UNDEF); in sh_envnolocal()
2104 _nv_unset(np,NV_RDONLY); in sh_envnolocal()
2105 nv_setattr(np,0); in sh_envnolocal()
2108 nv_putval(np,cp,0); in sh_envnolocal()
2117 void nv_close(Namval_t *np) in nv_close() argument
2119 NOT_USED(np); in nv_close()
2124 register Namval_t *np,*nq, *npnext; in table_unset() local
2125 for(np=(Namval_t*)dtfirst(root);np;np=npnext) in table_unset()
2127 if(nv_isref(np)) in table_unset()
2129 free((void*)np->nvalue.nrp); in table_unset()
2130 np->nvalue.cp = 0; in table_unset()
2131 np->nvflag = 0; in table_unset()
2133 if(nq=dtsearch(oroot,np)) in table_unset()
2149 np->nvfun = 0; in table_unset()
2154 npnext = (Namval_t*)dtnext(root,np); in table_unset()
2157 if(nv_isvtree(np)) in table_unset()
2159 int len = strlen(np->nvname); in table_unset()
2160 while((nq=npnext) && memcmp(np->nvname,nq->nvname,len)==0 && nq->nvname[len]=='.') in table_unset()
2168 _nv_unset(np,flags); in table_unset()
2169 nv_delete(np,root,0); in table_unset()
2183 void _nv_unset(register Namval_t *np,int flags) in _nv_unset() argument
2187 if(!(flags&NV_RDONLY) && nv_isattr (np,NV_RDONLY)) in _nv_unset()
2188 errormsg(SH_DICT,ERROR_exit(1),e_readonly, nv_name(np)); in _nv_unset()
2189 if(is_afunction(np) && np->nvalue.ip) in _nv_unset()
2191 register struct slnod *slp = (struct slnod*)(np->nvenv); in _nv_unset()
2192 if(slp && !nv_isattr(np,NV_NOFREE)) in _nv_unset()
2194 struct Ufunction *rq,*rp = np->nvalue.rp; in _nv_unset()
2196 register char *name=nv_name(np),*cp= strrchr(name,'.'); in _nv_unset()
2210 if(rq->np != np) in _nv_unset()
2229 free((void*)np->nvalue.ip); in _nv_unset()
2230 np->nvalue.ip = 0; in _nv_unset()
2234 if(shp->subshell && !nv_isnull(np)) in _nv_unset()
2235 np = sh_assignok(np,0); in _nv_unset()
2236 nv_offattr(np,NV_NODISC); in _nv_unset()
2237 if(np->nvfun && !nv_isref(np)) in _nv_unset()
2243 nv_putv(np,NIL(char*),flags,np->nvfun); in _nv_unset()
2250 if(nv_isattr(np,NV_INT16P) == NV_INT16) in _nv_unset()
2252 np->nvalue.cp = nv_isarray(np)?Empty:0; in _nv_unset()
2255 if(nv_isarray(np) && np->nvalue.cp!=Empty && np->nvfun) in _nv_unset()
2256 up = np->nvalue.up; in _nv_unset()
2258 up = &np->nvalue; in _nv_unset()
2261 if(up->cp!=Empty && !nv_isattr(np, NV_NOFREE)) in _nv_unset()
2266 if(!nv_isarray(np) || !nv_arrayptr(np)) in _nv_unset()
2268 if(nv_isref(np) && !nv_isattr(np,NV_EXPORT)) in _nv_unset()
2269 free((void*)np->nvalue.nrp); in _nv_unset()
2270 nv_setsize(np,0); in _nv_unset()
2271 if(!nv_isattr(np,NV_MINIMAL) || nv_isattr(np,NV_EXPORT)) in _nv_unset()
2273 if(nv_isattr(np,NV_EXPORT) && !strchr(np->nvname,'[')) in _nv_unset()
2274 env_delete(shp->env,nv_name(np)); in _nv_unset()
2275 if(!(flags&NV_EXPORT) || nv_isattr(np,NV_IMPORT|NV_EXPORT)==(NV_IMPORT|NV_EXPORT)) in _nv_unset()
2276 np->nvenv = 0; in _nv_unset()
2277 nv_setattr(np,0); in _nv_unset()
2281 nv_setattr(np,NV_MINIMAL); in _nv_unset()
2282 nv_delete(np,(Dt_t*)0,0); in _nv_unset()
2290 Namval_t *sh_scoped(Shell_t *shp, register Namval_t *np) in sh_scoped() argument
2293 return(np); in sh_scoped()
2294 return(dtsearch(shp->var_tree,np)); in sh_scoped()
2304 register Namval_t *np; in tableval() local
2311 for(np=(Namval_t*)dtfirst(root);np;np=(Namval_t*)dtnext(root,np)) in tableval()
2313 if(!nv_isnull(np) || np->nvfun || nv_isattr(np,~NV_NOFREE)) in tableval()
2319 sfputr(out,np->nvname,-1); in tableval()
2336 Namval_t *np; member
2341 static void optimize_clear(Namval_t* np, Namfun_t *fp) in optimize_clear() argument
2344 nv_stack(np,fp); in optimize_clear()
2345 nv_stack(np,(Namfun_t*)0); in optimize_clear()
2346 for(;op && op->np==np; op=op->next) in optimize_clear()
2356 static void put_optimize(Namval_t* np,const char *val,int flags,Namfun_t *fp) in put_optimize() argument
2358 nv_putv(np,val,flags,fp); in put_optimize()
2359 optimize_clear(np,fp); in put_optimize()
2362 static Namfun_t *clone_optimize(Namval_t* np, Namval_t *mp, int flags, Namfun_t *fp) in clone_optimize() argument
2369 void nv_optimize(Namval_t *np) in nv_optimize() argument
2375 if(np==SH_LINENO) in nv_optimize()
2380 for(fp=np->nvfun; fp; fp = fp->next) in nv_optimize()
2397 op->np = np; in nv_optimize()
2409 nv_stack(np,&op->hdr); in nv_optimize()
2422 nv_stack(op->np,&op->hdr); in sh_optclear()
2423 nv_stack(op->np,(Namfun_t*)0); in sh_optclear()
2432 # define optimize_clear(np,fp) argument
2446 char *nv_getval(register Namval_t *np) in nv_getval() argument
2448 register union Value *up= &np->nvalue; in nv_getval()
2452 nv_optimize(np); in nv_getval()
2454 if((!np->nvfun || !np->nvfun->disc) && !nv_isattr(np,NV_ARRAY|NV_INTEGER|NV_FUNCT|NV_REF|NV_TABLE)) in nv_getval()
2456 if(nv_isref(np)) in nv_getval()
2458 if(!np->nvalue.cp) in nv_getval()
2460 sh.last_table = nv_reftable(np); in nv_getval()
2461 return(nv_name(nv_refnode(np))); in nv_getval()
2463 if(np->nvfun && np->nvfun->disc) in nv_getval()
2468 return(nv_getv(np, np->nvfun)); in nv_getval()
2472 numeric = ((nv_isattr (np, NV_INTEGER)) != 0); in nv_getval()
2478 if(nv_isattr (np,NV_DOUBLE)==NV_DOUBLE) in nv_getval()
2483 if(nv_isattr(np,NV_LONG)) in nv_getval()
2486 if(nv_isattr (np,NV_EXPNOTE)) in nv_getval()
2488 else if(nv_isattr (np,NV_HEXFLOAT)) in nv_getval()
2492 sfprintf(sh.strbuf,format,nv_size(np),ld); in nv_getval()
2497 if(nv_isattr (np,NV_EXPNOTE)) in nv_getval()
2499 else if(nv_isattr (np,NV_HEXFLOAT)) in nv_getval()
2503 sfprintf(sh.strbuf,format,nv_size(np),d); in nv_getval()
2507 else if(nv_isattr(np,NV_UNSIGN)) in nv_getval()
2509 if(nv_isattr (np,NV_LONG)) in nv_getval()
2511 else if(nv_isattr (np,NV_SHORT)) in nv_getval()
2513 if(nv_isattr(np,NV_INT16P)==NV_INT16P) in nv_getval()
2521 else if(nv_isattr (np,NV_LONG)) in nv_getval()
2523 else if(nv_isattr (np,NV_SHORT)) in nv_getval()
2525 if(nv_isattr(np,NV_INT16P)==NV_INT16P) in nv_getval()
2532 if((numeric=nv_size(np))==10) in nv_getval()
2534 if(nv_isattr(np,NV_UNSIGN)) in nv_getval()
2549 if(up->cp && nv_isattr(np,NV_BINARY) && !nv_isattr(np,NV_RAW)) in nv_getval()
2553 int size= nv_size(np), insize=(4*size)/3+size/45+8; in nv_getval()
2559 if((numeric=nv_size(np)) && up->cp && up->cp[numeric]) in nv_getval()
2569 Sfdouble_t nv_getnum(register Namval_t *np) in nv_getnum() argument
2576 nv_optimize(np); in nv_getnum()
2578 if(nv_istable(np)) in nv_getnum()
2579 errormsg(SH_DICT,ERROR_exit(1),e_number,nv_name(np)); in nv_getnum()
2580 if(np->nvfun && np->nvfun->disc) in nv_getnum()
2585 return(nv_getn(np, np->nvfun)); in nv_getnum()
2589 if(nv_isref(np)) in nv_getnum()
2591 str = nv_refsub(np); in nv_getnum()
2592 np = nv_refnode(np); in nv_getnum()
2594 nv_putsub(np,str,0L); in nv_getnum()
2596 if(nv_isattr (np, NV_INTEGER)) in nv_getnum()
2598 up= &np->nvalue; in nv_getnum()
2601 else if(nv_isattr(np, NV_DOUBLE)==NV_DOUBLE) in nv_getnum()
2603 if(nv_isattr(np, NV_LONG)) in nv_getnum()
2608 else if(nv_isattr(np, NV_UNSIGN)) in nv_getnum()
2610 if(nv_isattr(np, NV_LONG)) in nv_getnum()
2612 else if(nv_isattr(np, NV_SHORT)) in nv_getnum()
2614 if(nv_isattr(np,NV_INT16P)==NV_INT16P) in nv_getnum()
2624 if(nv_isattr(np, NV_LONG)) in nv_getnum()
2626 else if(nv_isattr(np, NV_SHORT)) in nv_getnum()
2628 if(nv_isattr(np,NV_INT16P)==NV_INT16P) in nv_getnum()
2637 else if((str=nv_getval(np)) && *str!=0) in nv_getnum()
2639 if(np->nvfun || nv_isattr(np,NV_LJUST|NV_RJUST|NV_ZFILL)) in nv_getnum()
2653 void nv_newattr (register Namval_t *np, unsigned newatts, int size) in nv_newattr() argument
2660 Namfun_t *fp= (newatts&NV_NODISC)?np->nvfun:0; in nv_newattr()
2665 …if(sh_isoption(SH_RESTRICTED) && ((sp=nv_name(np))==nv_name(PATHNOD) || sp==nv_name(SHELLNOD) || s… in nv_newattr()
2666 errormsg(SH_DICT,ERROR_exit(1),e_restricted,nv_name(np)); in nv_newattr()
2668 n = np->nvflag; in nv_newattr()
2670 nv_offattr(np,NV_IMPORT); in nv_newattr()
2675 env_delete(sh.env,nv_name(np)); in nv_newattr()
2677 sh_envput(sh.env,np); in nv_newattr()
2679 oldsize = nv_size(np); in nv_newattr()
2683 nv_setsize(np,size); in nv_newattr()
2684 nv_offattr(np, ~NV_NOFREE); in nv_newattr()
2685 nv_onattr(np, newatts); in nv_newattr()
2689 if((ap=nv_arrayptr(np)) && ap->nelem>0) in nv_newattr()
2690 nv_putsub(np,NIL(char*),ARRAY_SCAN); in nv_newattr()
2691 oldsize = nv_size(np); in nv_newattr()
2692 oldatts = np->nvflag; in nv_newattr()
2694 np->nvfun = 0; in nv_newattr()
2699 nv_setsize(np,oldsize); in nv_newattr()
2700 np->nvflag = oldatts; in nv_newattr()
2701 if (sp = nv_getval(np)) in nv_newattr()
2703 if(nv_isattr(np,NV_ZFILL)) in nv_newattr()
2711 if(mp=nv_opensub(np)) in nv_newattr()
2717 nv_unset(np); in nv_newattr()
2721 nv_unset(np); in nv_newattr()
2726 nv_unset(np); in nv_newattr()
2727 nv_setsize(np,size); in nv_newattr()
2728 np->nvflag &= NV_ARRAY; in nv_newattr()
2729 np->nvflag |= newatts; in nv_newattr()
2732 nv_putval (np, cp, NV_RDONLY); in nv_newattr()
2736 while(ap && nv_nextsub(np)); in nv_newattr()
2738 np->nvfun = fp; in nv_newattr()
2774 register Namval_t *np; in sh_getenv() local
2782 else if((np = nv_search(name,sh.var_tree,0)) && nv_isattr(np,NV_EXPORT)) in sh_getenv()
2783 return(nv_getval(np)); in sh_getenv()
2805 register Namval_t *np; in putenv() local
2808 np = nv_open(name,sh.var_tree,NV_EXPORT|NV_IDENT|NV_NOARRAY|NV_ASSIGN); in putenv()
2810 nv_unset(np); in putenv()
2820 register Namval_t *np; in sh_setenviron() local
2823 np = nv_open(name,sh.var_tree,NV_EXPORT|NV_IDENT|NV_NOARRAY|NV_ASSIGN); in sh_setenviron()
2825 return(nv_getval(np)); in sh_setenviron()
2826 nv_unset(np); in sh_setenviron()
2900 int nv_rename(register Namval_t *np, int flags) in nv_rename() argument
2910 if(nv_isattr(np,NV_PARAM) && shp->st.prevst) in nv_rename()
2915 if(!(cp=nv_getval(np))) in nv_rename()
2921 if(lastdot(cp,0) && nv_isattr(np,NV_MINIMAL)) in nv_rename()
2922 errormsg(SH_DICT,ERROR_exit(1),e_varname,nv_name(np)); in nv_rename()
2923 if(nv_isarray(np) && !(mp=nv_opensub(np))) in nv_rename()
2924 index=nv_aindex(np); in nv_rename()
2937 if(!nv_isvtree(np)) in nv_rename()
2938 _nv_unset(np,0); in nv_rename()
2943 sfprintf(shp->strbuf,"%s[%d]%c",nv_name(np),index,0); in nv_rename()
2946 mp->nvenv = (void*)np; in nv_rename()
2950 nvenv = (char*)np; in nv_rename()
2951 np = mp; in nv_rename()
2953 if(nr==np) in nv_rename()
2957 if(cp = nv_getval(np)) in nv_rename()
2960 _nv_unset(np,0); in nv_rename()
2961 if(!nv_isattr(np,NV_MINIMAL)) in nv_rename()
2962 np->nvenv = nvenv; in nv_rename()
2963 if(nr==np) in nv_rename()
2965 nv_putsub(np,(char*)0, index); in nv_rename()
2966 nv_putval(np,cp,0); in nv_rename()
2974 nv_clone(nr,np,(flags&NV_MOVE)|NV_COMVAR); in nv_rename()
2983 void nv_setref(register Namval_t *np, Dt_t *hp, int flags) in nv_setref() argument
2990 if(nv_isref(np)) in nv_setref()
2992 if(nv_isarray(np)) in nv_setref()
2993 errormsg(SH_DICT,ERROR_exit(1),e_badref,nv_name(np)); in nv_setref()
2994 if(!(cp=nv_getval(np))) in nv_setref()
2996 nv_unset(np); in nv_setref()
2997 nv_onattr(np,NV_REF); in nv_setref()
3000 if((ep = lastdot(cp,0)) && nv_isattr(np,NV_MINIMAL)) in nv_setref()
3001 errormsg(SH_DICT,ERROR_exit(1),e_badref,nv_name(np)); in nv_setref()
3017 _nv_unset(np,NV_RDONLY); in nv_setref()
3018 nv_onattr(np,NV_REF); in nv_setref()
3019 errormsg(SH_DICT,ERROR_exit(1),e_globalref,nv_name(np)); in nv_setref()
3021 if(nr==np) in nv_setref()
3024 errormsg(SH_DICT,ERROR_exit(1),e_selfref,nv_name(np)); in nv_setref()
3026 if(!(hp=dtvnext(hp)) || (nq=nv_search((char*)np,hp,NV_ADD|HASH_BUCKET))==np) in nv_setref()
3027 errormsg(SH_DICT,ERROR_exit(1),e_selfref,nv_name(np)); in nv_setref()
3047 nv_unset(np); in nv_setref()
3048 nv_delete(np,(Dt_t*)0,0); in nv_setref()
3049 np->nvalue.nrp = newof(0,struct Namref,1,0); in nv_setref()
3050 np->nvalue.nrp->np = nq; in nv_setref()
3051 np->nvalue.nrp->root = hp; in nv_setref()
3053 np->nvalue.nrp->sub = strdup(ep); in nv_setref()
3054 np->nvalue.nrp->table = shp->last_table; in nv_setref()
3055 nv_onattr(np,NV_REF|NV_NOFREE); in nv_setref()
3120 void nv_unref(register Namval_t *np) in nv_unref() argument
3123 if(!nv_isref(np)) in nv_unref()
3125 nv_offattr(np,NV_NOFREE|NV_REF); in nv_unref()
3126 if(!np->nvalue.nrp) in nv_unref()
3128 nq = nv_refnode(np); in nv_unref()
3129 free((void*)np->nvalue.nrp); in nv_unref()
3130 np->nvalue.cp = strdup(nv_name(nq)); in nv_unref()
3175 Namval_t *np = (Namval_t*)obj; in hashname() local
3176 return(np->nvname); in hashname()
3187 char *nv_name(register Namval_t *np) in nv_name() argument
3192 if(is_abuiltin(np) || is_afunction(np)) in nv_name()
3193 return(np->nvname); in nv_name()
3194 if(!nv_isattr(np,NV_MINIMAL|NV_EXPORT) && np->nvenv) in nv_name()
3196 Namval_t *nq= sh.last_table, *mp= (Namval_t*)np->nvenv; in nv_name()
3197 if(np==sh.last_table) in nv_name()
3200 sfprintf(sh.strbuf,"%s[%s]",nv_name(mp),np->nvname); in nv_name()
3202 sfprintf(sh.strbuf,"%s.%s",nv_name(mp),np->nvname); in nv_name()
3206 if(nv_istable(np)) in nv_name()
3208 sh.last_table = nv_parent(np); in nv_name()
3210 sh.last_table = nv_create(np,0, NV_LAST,(Namfun_t*)0); in nv_name()
3212 else if(!nv_isref(np)) in nv_name()
3214 for(fp= np->nvfun ; fp; fp=fp->next) in nv_name()
3217 if(np==sh.last_table) in nv_name()
3219 return((*fp->disc->namef)(np,fp)); in nv_name()
3222 if(!(table=sh.last_table) || *np->nvname=='.' || table==sh.namespace || np==table) in nv_name()
3223 return(np->nvname); in nv_name()
3225 sfprintf(sh.strbuf,"%s.%s",cp,np->nvname); in nv_name()
3238 void *nv_context(Namval_t *np) in nv_context() argument
3240 return((void*)np->nvfun); in nv_context()
3245 int nv_isnull DISABLE (register Namval_t *np) in DISABLE() argument
3247 return(nv_isnull(np)); in DISABLE()
3251 int nv_setsize(register Namval_t *np, int size) in nv_setsize() argument
3253 int oldsize = nv_size(np); in nv_setsize()
3255 np->nvsize = size; in nv_setsize()
3259 Shell_t *nv_shell(Namval_t *np) in nv_shell() argument
3262 for(fp=np->nvfun;fp;fp=fp->next) in nv_shell()
3272 void nv_unset(register Namval_t *np) in nv_unset() argument
3274 _nv_unset(np,0); in nv_unset()