7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin/***********************************************************************
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* This software is part of the ast package *
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner* Copyright (c) 1982-2010 AT&T Intellectual Property *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* and is licensed under the *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* Common Public License, Version 1.0 *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* by AT&T Intellectual Property *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* A copy of the License is available at *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* Information and Software Systems Research *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* AT&T Research *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* Florham Park NJ *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* David Korn <dgk@research.att.com> *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin***********************************************************************/
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin * David Korn
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin"[-1c?\n@(#)$Id: type (AT&T Labs Research) 2008-07-01 $\n]"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin"[+NAME?\f?\f - set the type of variables to \b\f?\f\b]"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin"[+DESCRIPTION?\b\f?\f\b sets the type on each of the variables specified "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "by \aname\a to \b\f?\f\b. If \b=\b\avalue\a is specified, "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "the variable \aname\a is set to \avalue\a before the variable "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "is converted to \b\f?\f\b.]"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin"[+?If no \aname\as are specified then the names and values of all "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "variables of this type are written to standard output.]"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin"[+?\b\f?\f\b is built-in to the shell as a declaration command so that "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "field splitting and pathname expansion are not performed on "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "the arguments. Tilde expansion occurs on \avalue\a.]"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin"[r?Enables readonly. Once enabled, the value cannot be changed or unset.]"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin"[a]:?[type?Indexed array. Each \aname\a will converted to an index "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "array of type \b\f?\f\b. If a variable already exists, the current "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "value will become index \b0\b. If \b[\b\atype\a\b]]\b is "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "specified, each subscript is interpreted as a value of enumeration "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "type \atype\a.]"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin"[A?Associative array. Each \aname\a will converted to an associate "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "array of type \b\f?\f\b. If a variable already exists, the current "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "value will become subscript \b0\b.]"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin"[h]:[string?Used within a type definition to provide a help string "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "for variable \aname\a. Otherwise, it is ignored.]"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin"[S?Used with a type definition to indicate that the variable is shared by "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "each instance of the type. When used inside a function defined "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "with the \bfunction\b reserved word, the specified variables "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "will have function static scope. Otherwise, the variable is "
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "unset prior to processing the assignment list.]"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin"[+DETAILS]\ftypes\f"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin"\n[name[=value]...]\n"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin"[+EXIT STATUS?]{"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "[+0?Successful completion.]"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin "[+>0?An error occurred.]"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin"[+SEE ALSO?\fother\f \breadonly\b(1), \btypeset\b(1)]"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin unsigned short ndisc;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin unsigned short current;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin unsigned short nref;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chintypedef struct
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#define alignof(t) ((char*)&((_Align_*)0)->_d##t-(char*)&((_Align_*)0)->_c##t)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic void put_type(Namval_t*, const char*, int, Namfun_t*);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic Namval_t* create_type(Namval_t*, const char*, int, Namfun_t*);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic Namfun_t* clone_type(Namval_t*, Namval_t*, int, Namfun_t*);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic Namval_t* next_type(Namval_t*, Dt_t*, Namfun_t*);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic size_t datasize(Namval_t *np, size_t *offset)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin s = sizeof(float);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin s = sizeof(double);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin s = sizeof(short);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin s = sizeof(long);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin else if(nv_isattr(np, NV_BINARY) || nv_isattr(np,NV_LJUST|NV_RJUST|NV_ZFILL))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic char *name_chtype(Namval_t *np, Namfun_t *fp)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(nv_isattr(np,NV_REF|NV_TAGGED)==(NV_REF|NV_TAGGED))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if((ap = nv_arrayptr(nq)) && !(ap->nelem&ARRAY_UNDEF) && (sub= nv_getsub(nq)))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(sh.strbuf,"%s[%s].%s",cp,sub,np->nvname);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic void put_chtype(Namval_t* np, const char* val, int flag, Namfun_t* fp)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin size_t dsize=0,offset = (char*)np-(char*)pp->ptype;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin Namval_t *mp = (Namval_t*)((char*)pp->ttype+offset);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(mp->nvalue.cp >= pp->ttype->data && mp->nvalue.cp < (char*)pp+pp->ttype->fun.dsize)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin np->nvalue.cp = pp->ptype->data + (mp->nvalue.cp-pp->ptype->data);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin memcpy((char*)np->nvalue.cp,mp->nvalue.cp,dsize);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzstatic Namfun_t *clone_chtype(Namval_t* np, Namval_t *mp, int flags, Namfun_t *fp)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin while(--i>0)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic int fixnode(Namtype_t *dp, Namtype_t *pp, int i, struct Namref *nrp,int flag)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin nq->nvalue.nrp->np = nv_namptr(pp->childfun.ttype->nodes,i);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(nq->nvalue.cp >= pp->data && nq->nvalue.cp < (char*)pp +pp->fun.dsize)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin nq->nvalue.cp = dp->data + (nq->nvalue.cp-pp->data);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(data >= pp->data && data < (char*)pp +pp->fun.dsize)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin else if(!nq->nvfun && pp->childfun.ttype!=pp->childfun.ptype)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin Namval_t *nr = nv_namptr( pp->childfun.ttype->nodes,i);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic Namfun_t *clone_type(Namval_t* np, Namval_t *mp, int flags, Namfun_t *fp)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin register int i;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(size==0 && (!fp->disc || (size=fp->disc->dsize)==0))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin dp = (Namtype_t*)malloc(size+pp->nref*sizeof(struct Namref));
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin memset((void*)nrp,0,pp->nref*sizeof(struct Namref));
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin dp->childfun.ttype = (Namtype_t*)nv_hasdisc(dp->fun.type,&type_disc);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if(nq->nvalue.cp || !nv_isvtree(nq) || nv_isattr(nq,NV_RDONLY))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin /* see if default value has been overwritten */
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin nr = nv_create(stakptr(offset),root,NV_VARNAME|NV_NOADD,fp);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(nv_isattr(nq,NV_RDONLY) && (nq->nvalue.cp || nv_isattr(nq,NV_INTEGER)))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin errormsg(SH_DICT,ERROR_exit(1),e_readonly, nq->nvname);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if((size = datasize(nr,(size_t*)0)) && size==datasize(nq,(size_t*)0))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin nv_putsub(nr,NIL(char*),ARRAY_SCAN|ARRAY_NOSCOPE);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin cp = (char*)((*ap->fun)(nr,NIL(char*),NV_ANAME));
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin Namval_t *mp = (Namval_t*)((*ap->fun)(nr,NIL(char*),NV_ACURRENT));
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin Namval_t *mq = (Namval_t*)((*ap->fun)(nq,NIL(char*),NV_ACURRENT));
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#endif /* SHOPT_TYPEDEF */
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin else if(nv_isattr(nq,NV_RDONLY) && !nq->nvalue.cp && !nv_isattr(nq,NV_INTEGER))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin errormsg(SH_DICT,ERROR_exit(1),e_required,nq->nvname,nv_name(mp));
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin * return Namval_t* corresponding to child <name> in <np>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic Namval_t *create_type(Namval_t *np,const char *name,int flag,Namfun_t *fp)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin register int i=0,n;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin while((n=*cp++) && n != '=' && n != '+' && n!='[');
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin while((nq=nv_namptr(base,++i)) && memcmp(nq->nvname,np->nvname,m)==0)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(nq->nvname[m]=='.' && memcmp(name,&nq->nvname[m+1],n)==0 && nq->nvname[m+n+1]==0)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if((n==0||memcmp(name,nq->nvname,n)==0) && nq->nvname[n]==0)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if((memcmp(name,dp->names[i],n)==0) && dp->names[i][n]==0)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin errormsg(SH_DICT,ERROR_exit(1),e_notelem,n,name,nv_name(np));
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic void put_type(Namval_t* np, const char* val, int flag, Namfun_t* fp)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(val && (nq=nv_open(val,sh.var_tree,NV_VARNAME|NV_ARRAY|NV_NOADD|NV_NOFAIL)))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if((pp=nv_hasdisc(nq,fp->disc)) && pp->type==fp->type)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(nv_isarray(np) && (ap=nv_arrayptr(np)) && ap->nelem>0)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin _nv_unset(nq,flag|NV_TYPE|nv_isattr(nq,NV_RDONLY));
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic Namval_t *next_type(register Namval_t* np, Dt_t *root,Namfun_t *fp)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic Namfun_t *clone_inttype(Namval_t* np, Namval_t *mp, int flags, Namfun_t *fp)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin memcpy((void*)mp->nvalue.cp,np->nvalue.cp, fp->dsize-sizeof(*fp));
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic int typeinfo(Opt_t* op, Sfio_t *out, const char *str, Optdisc_t *fp)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin np = nv_open(stakptr(offset), sh.var_tree, NV_NOADD|NV_VARNAME);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(sfstderr,"%s: no such variable\n",np->nvname);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(sfstderr,"%s: not a type\n",np->nvname);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(out,"[+?\b%s\b is a %s.]\n", tp->nvname, np->nvenv);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(out,"[+?\b%s\b is a %n ", tp->nvname, &i);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(out," with default value \b%s\b.]",nv_getval(np));
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(bp=(Nambfun_t*)nv_hasdisc(np,nv_discfun(NV_DCADD)))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(out,"\b%s.%s\b(3), ",np->nvname,bp->bnames[i]);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sp = sfnew((Sfio_t*)0,buffer,sizeof(buffer),-1,SF_STRING|SF_WRITE);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(out,"[+?\b%s\b defines the following fields:]{\n",np->nvname);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(out,"\t[+%s?%s.\n",nq->nvname,tp->nvname);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin while((cp=nv_namptr(dp->nodes,i+1)->nvname) && memcmp(cp,nq->nvname,n)==0 && cp[n]=='.')
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin for(n=strlen(buffer); n>0 && buffer[n-1]==' '; n--);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(out,"\t[+%s?%s, default value is %s.\n",nq->nvname,*buffer?buffer:"string",cp);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(out,"\t[+%s?%s.\n",nq->nvname,*buffer?buffer:"string");
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(out,"[+?\b%s\b defines the following discipline functions:]{\n",np->nvname);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if((nq = nv_search(stakptr(offset),sh.fun_tree,0)) && nq->nvalue.cp)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(out,"\t[+%s?%s]\n",dp->names[i],cp?cp:Empty);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin register const char *sp, *cp = strrchr(mp->nvname,'.');
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin register int i;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(memcmp(sp=mp->nvname,NV_CLASS,sizeof(NV_CLASS)-1)==0)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(sfstderr," nvsetdisc failed name=%s sp=%s cp=%s\n",np->nvname,sp,cp);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(sfstderr,"can't set discipline %s cp=%s \n",sp,cp);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinvoid nv_addtype(Namval_t *np, const char *optstr, Optdisc_t *op, size_t optsz)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin Namdecl_t *cp = newof((Namdecl_t*)0,Namdecl_t,1,optsz);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if((bp=nv_search(name,shp->fun_tree,NV_NOSCOPE)) && !bp->nvalue.ip)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin bp = sh_addbuiltin(name, mp->nvalue.bfp, (void*)cp);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin nv_addtype(mp,sh_opttype, &optdisc.opt, sizeof(optdisc));
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin * This function creates a type out of the <numnodes> nodes in the
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin * array <nodes>. The first node is the name for the type
7c2fbfb345896881c631598ee3852ce9ce33fb07April ChinNamval_t *nv_mktype(Namval_t **nodes, int numnodes)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin Namval_t *mp=nodes[0], *bp=0, *np, *nq, **mnodes=nodes;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(memcmp(np->nvname,NV_CLASS,sizeof(NV_CLASS)-1)==0)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(strcmp(&np->nvname[m],NV_DATA)==0 && !nv_type(np))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin { /* delete duplicates */
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(name && memcmp(&name[m],&np->nvname[m],n)==0 && np->nvname[m+n]=='.')
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin offset -= sizeof(char*);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(!nv_isarray(np) && (dp=(Namtype_t*)nv_hasdisc(np, &type_disc)))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(np->nvname[m]=='_' && np->nvname[m+1]==0 && (bp=nv_type(np)))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin size += n + dp->numnodes*(strlen(&np->nvname[m])+1);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin while((i+1) < numnodes && (cp=nodes[i+1]->nvname) && memcmp(cp,np->nvname,n)==0 && cp[n]=='.')
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin k = roundof(sizeof(Namtype_t),sizeof(Sfdouble_t)) - sizeof(Namtype_t);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin pp = newof(NiL, Namtype_t, 1, nnodes*NV_MINSZ + offset + size + (nnodes+nd)*sizeof(char*) + iref*sizeof(struct Namref)+k);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin pp->fun.dsize = sizeof(Namtype_t)+nnodes*NV_MINSZ +offset+k;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(memcmp(np->nvname,NV_CLASS,sizeof(NV_CLASS)-1)==0)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin /* see if discipline already defined */
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin for(j=0; j< nd; j++)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin for(j=0; j < k ; j++)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(sfstderr,"initialization not implemented\n");
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(strcmp(&np->nvname[m],NV_DATA)==0 && !nv_type(np))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin nv_putval(nq,(val?val:0),nv_isattr(np,~(NV_IMPORT|NV_EXPORT|NV_ARRAY)));
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin dp = (Namtype_t*)nv_hasdisc(nv_type(np), &type_disc);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin memcpy(pp->nodes,dp->nodes,dp->numnodes*NV_MINSZ);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(!nv_isattr(nr,NV_REF) && !nv_hasdisc(nr,&type_disc))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin memcpy((char*)nq->nvalue.cp,nr->nvalue.cp,size=datasize(nr,(size_t*)0));
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(bp=(Nambfun_t*)nv_hasdisc(np,nv_discfun(NV_DCADD)))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin /* need to save the string pointer */
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(name && memcmp(name,&np->nvname[m],n)==0 && np->nvname[m+n]=='.')
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin offset -= sizeof(char*);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin nq->nvflag = (np->nvflag&~(NV_IMPORT|NV_EXPORT))|NV_NOFREE|NV_MINIMAL;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin * If field is a type, mark the type by setting
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin * strsize<0. This changes create_type()
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin Namchld_t *xp = (Namchld_t*)nv_hasdisc(nr,&chtype_disc);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(xp && nr->nvalue.cp >= xp->ptype->data && nr->nvalue.cp < xp->ptype->data+xp->ptype->fun.dsize)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin memcpy((char*)nq->nvalue.cp,nr->nvalue.cp,dsize);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin while((i+1) < numnodes && (cname=&nodes[i+1]->nvname[m]) && memcmp(cname,&np->nvname[m],n)==0 && cname[n]=='.')
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin while(j < k)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin sfprintf(sfstderr,"%s found at k=%d\n",nq->nvname,k);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(nq->nvalue.cp>=pp->data && nq->nvalue.cp< (char*)pp->names)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin memcpy((char*)nq->nvalue.cp,np->nvalue.cp,datasize(np,0));
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if(!nq->nvalue.cp && nq->nvfun== &pp->childfun.fun)
7c2fbfb345896881c631598ee3852ce9ce33fb07April ChinNamval_t *nv_mkinttype(char *name, size_t size, int sign, const char *help, Namdisc_t *ep)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin mp = nv_open(stakptr(offset), sh.var_tree, NV_VARNAME);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin mp->nvalue.cp = (char*)(fp+1) + sizeof(Namdisc_t);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin nv_onattr(mp,NV_NOFREE|NV_RDONLY|NV_INTEGER|NV_EXPORT);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if((dp = (Namtype_t*)nv_hasdisc(tp,&type_disc)) && dp->bp)
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if(nv_isattr(np,NV_BLTIN|BLT_DCL)==(NV_BLTIN|BLT_DCL))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(fp->disc && fp->disc->typef && (np= (*fp->disc->typef)(np,fp)))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin * call any and all create functions
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin Namtype_t *dp, *pp=(Namtype_t*)nv_hasdisc(np,&type_disc);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if((dp=(Namtype_t*)nv_hasdisc(nq,&type_disc)) && dp->cp)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin * This function turns variable <np> to the type <tp>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinint nv_settype(Namval_t* np, Namval_t *tp, int flags)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin errormsg(SH_DICT,ERROR_exit(1),e_redef,nv_name(np));
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#endif /*SHOPT_TYPEDEF */
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#define S(x) #x
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#define FIELD(x,y) { S(y##x), S(x##_t), offsetof(struct stat,st_##y##x) }
7c2fbfb345896881c631598ee3852ce9ce33fb07April ChinNamval_t *nv_mkstruct(const char *name, int rsize, Fields_t *fields)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin mp = nv_open(stakptr(offset), sh.var_tree, NV_VARNAME);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin tp = nv_open(stakptr(offset), sh.var_tree, NV_VARNAME|NV_NOADD|NV_NOFAIL);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin errormsg(SH_DICT,ERROR_exit(1),e_unknowntype,strlen(fp->type),fp->type);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin pp = newof(NiL,Namtype_t, 1, nnodes*NV_MINSZ + rsize + size);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin pp->fun.dsize = sizeof(Namtype_t)+nnodes*NV_MINSZ +rsize;
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin tp = nv_open(stakptr(offset), sh.var_tree, NV_VARNAME);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if(nr->nvalue.cp>=dp->data && nr->nvalue.cp < (char*)pp + pp->fun.dsize)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinstatic void put_stat(Namval_t* np, const char* val, int flag, Namfun_t* nfp)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin tp = nv_mkstruct("stat_t", sizeof(struct stat), foo);