Skip to content

Commit

Permalink
cleanup: remove another old and unused experiment
Browse files Browse the repository at this point in the history
This experiment, the initialisation of which was disabled with '#if
0', defines a bunch of integer type commands as special builtins.
Most are boring as they define variables just like normal integers:
pid_t, size_t, etc.

One is interesting: mode_t is a type that automatically converts
from a octal permission bits (e.g. 755) to a mode string like
u+rwx,g+rw,o+rw. That's not a compelling enough use case to
permanently define a special and immutable builtin though.

stat_t is odd: it takes a file name as an argument and fills the
variable with stat information, but it is base64 encoded binary
data and there doesn't seem to be anything that can parse it.

Anyway, none of this is going to be enabled, so we should get rid.
  • Loading branch information
McDutchie committed Apr 8, 2021
1 parent a28507e commit d0a5cab
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 92 deletions.
56 changes: 0 additions & 56 deletions src/cmd/ksh93/sh/init.c
Expand Up @@ -1174,46 +1174,6 @@ int sh_type(register const char *path)
}


static char *get_mode(Namval_t* np, Namfun_t* nfp)
{
mode_t mode = nv_getn(np,nfp);
return(fmtperm(mode));
}

static void put_mode(Namval_t* np, const char* val, int flag, Namfun_t* nfp)
{
if(val)
{
mode_t mode;
char *last=0;
if(flag&NV_INTEGER)
{
if(flag&NV_LONG)
mode = *(Sfdouble_t*)val;
else
mode = *(double*)val;
}
else
mode = strperm(val, &last,0);
if(*last)
{
errormsg(SH_DICT,ERROR_exit(1),"%s: invalid mode string",val);
UNREACHABLE();
}
nv_putv(np,(char*)&mode,NV_INTEGER,nfp);
}
else
nv_putv(np,val,flag,nfp);
}

static const Namdisc_t modedisc =
{
0,
put_mode,
get_mode,
};


/*
* initialize the shell
*/
Expand Down Expand Up @@ -1510,22 +1470,6 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit)
shp->bltindata.shgetenv = sh_getenv;
shp->bltindata.shsetenv = sh_setenviron;
astintercept(&shp->bltindata,1);
#if 0
#define NV_MKINTTYPE(x,y,z) nv_mkinttype(#x,sizeof(x),(x)-1<0,(y),(Namdisc_t*)z);
NV_MKINTTYPE(pid_t,"process id",0);
NV_MKINTTYPE(gid_t,"group id",0);
NV_MKINTTYPE(uid_t,"user id",0);
NV_MKINTTYPE(size_t,(const char*)0,0);
NV_MKINTTYPE(ssize_t,(const char*)0,0);
NV_MKINTTYPE(off_t,"offset in bytes",0);
NV_MKINTTYPE(ino_t,"\ai-\anode number",0);
NV_MKINTTYPE(mode_t,(const char*)0,&modedisc);
NV_MKINTTYPE(dev_t,"device id",0);
NV_MKINTTYPE(nlink_t,"hard link count",0);
NV_MKINTTYPE(blkcnt_t,"block count",0);
NV_MKINTTYPE(time_t,"seconds since the epoch",0);
nv_mkstat();
#endif
if(shp->userinit=userinit)
(*userinit)(shp, 0);
shp->exittrap = 0;
Expand Down
36 changes: 0 additions & 36 deletions src/cmd/ksh93/sh/nvtype.c
Expand Up @@ -1531,42 +1531,6 @@ Namval_t *nv_mkstruct(const char *name, int rsize, Fields_t *fields)
return(mp);
}

static void put_stat(Namval_t* np, const char* val, int flag, Namfun_t* nfp)
{
if(val)
{
if(stat(val,(struct stat*)np->nvalue.cp)<0)
sfprintf(sfstderr,"stat of %s failed\n",val);
return;
}
nv_putv(np,val,flag,nfp);
nv_disc(np,nfp,NV_POP);
if(!(nfp->nofree&1))
free((void*)nfp);
}

static const Namdisc_t stat_disc =
{
0,
put_stat
};


void nv_mkstat(void)
{
Namval_t *tp;
Namfun_t *fp;
tp = nv_mkstruct("stat_t", sizeof(struct stat), foo);
nv_offattr(tp,NV_RDONLY);
nv_setvtree(tp);
fp = sh_newof(NiL,Namfun_t,1,0);
fp->type = tp;
fp->disc = &stat_disc;
nv_disc(tp,fp,NV_FIRST);
nv_putval(tp,e_devnull,0);
nv_onattr(tp,NV_RDONLY);
}

static void write_indent(Sfio_t *out,char *str,int n,int indent)
{
register int c, first=1;
Expand Down

0 comments on commit d0a5cab

Please sign in to comment.