mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Introduce usage of __builtin_unreachable() and noreturn (#248)
This commit adds an UNREACHABLE() macro that expands to either the __builtin_unreachable() compiler builtin (for release builds) or abort(3) (for development builds). This is used to mark code paths that are never to be reached. It also adds the 'noreturn' attribute to functions that never return: path_exec(), sh_done() and sh_syntax(). The UNREACHABLE() macro is not added after calling these. The purpose of these is: * to slightly improve GCC/Clang compiler optimizations; * to fix a few compiler warnings; * to add code clarity. Changes of note: src/cmd/ksh93/sh/io.c: outexcept(): - Avoid using __builtin_unreachable() here since errormsg can return despite using ERROR_system(1), as shp->jmplist->mode is temporarily set to 0. See: https://github.com/att/ast/issues/1336 src/cmd/ksh93/tests/io.sh: - Add a regression test for the ksh2020 bug referenced above. src/lib/libast/features/common: - Detect the existence of either the C11 stdnoreturn.h header or the GCC noreturn attribute, preferring the former when available. - Test for the existence of __builtin_unreachable(). Use it for release builds. On development builds, use abort() instead, which crahses reliably for debugging when unreachable code is reached. Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
parent
56913f8c2a
commit
c4f980eb29
87 changed files with 1170 additions and 122 deletions
|
|
@ -256,19 +256,25 @@ int b_alarm(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argc -= opt_info.index;
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(argc==0)
|
||||
{
|
||||
print_alarms(shp->st.timetrap);
|
||||
return(0);
|
||||
}
|
||||
if(argc!=2)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
np = nv_open(argv[0],shp->var_tree,NV_NOARRAY|NV_VARNAME|NV_NOASSIGN);
|
||||
if(!nv_isnull(np))
|
||||
nv_unset(np);
|
||||
|
|
|
|||
|
|
@ -60,7 +60,10 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
|
|||
static char *oldpwd;
|
||||
Namval_t *opwdnod, *pwdnod;
|
||||
if(sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted+4);
|
||||
UNREACHABLE();
|
||||
}
|
||||
while((rval = optget(argv,sh_optcd))) switch(rval)
|
||||
{
|
||||
case 'L':
|
||||
|
|
@ -74,13 +77,16 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
argc -= opt_info.index;
|
||||
dir = argv[0];
|
||||
if(error_info.errors>0 || argc >2)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(oldpwd && oldpwd!=shp->pwd && oldpwd!=e_dot)
|
||||
free(oldpwd);
|
||||
oldpwd = path_pwd(shp,0);
|
||||
|
|
@ -98,7 +104,10 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
|
|||
else if(*dir == '-' && dir[1]==0)
|
||||
dir = nv_getval(opwdnod);
|
||||
if(!dir || *dir==0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),argc==2?e_subst+4:e_direct);
|
||||
UNREACHABLE();
|
||||
}
|
||||
/*
|
||||
* If sh_subshell() in subshell.c cannot use fchdir(2) to restore the PWD using a saved file descriptor,
|
||||
* we must fork any virtual subshell now to avoid the possibility of ending up in the wrong PWD on exit.
|
||||
|
|
@ -193,6 +202,7 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
|
|||
if(saverrno)
|
||||
errno = saverrno;
|
||||
errormsg(SH_DICT,ERROR_system(1),"%s:",dir);
|
||||
UNREACHABLE();
|
||||
}
|
||||
success:
|
||||
if(dir == nv_getval(opwdnod) || argc==2)
|
||||
|
|
@ -204,6 +214,7 @@ success:
|
|||
{
|
||||
dir = stakptr(PATH_OFFSET);
|
||||
errormsg(SH_DICT,ERROR_system(1),"%s:",dir);
|
||||
UNREACHABLE();
|
||||
}
|
||||
stakseek(dir-stakptr(0));
|
||||
}
|
||||
|
|
@ -245,12 +256,18 @@ int b_pwd(int argc, char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(*(cp = path_pwd(shp,0)) != '/')
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1), e_pwd);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(flag)
|
||||
{
|
||||
cp = strcpy(stakseek(strlen(cp)+PATH_MAX),cp);
|
||||
|
|
|
|||
|
|
@ -61,7 +61,10 @@ int b_return(register int n, register char *argv[],Shbltin_t *context)
|
|||
}
|
||||
done:
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
pp->mode = (**argv=='e'?SH_JMPEXIT:SH_JMPFUN);
|
||||
argv += opt_info.index;
|
||||
n = (arg = *argv) ? (int)strtol(arg, (char**)0, 10) : shp->savexit;
|
||||
|
|
@ -98,14 +101,20 @@ int b_break(register int n, register char *argv[],Shbltin_t *context)
|
|||
return(2);
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
n=1;
|
||||
if(arg= *argv)
|
||||
{
|
||||
n = (int)strtol(arg,&arg,10);
|
||||
if(n<=0 || *arg)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_nolabels,*argv);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if(shp->st.loopcnt)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -150,6 +150,7 @@ static void put_enum(Namval_t* np,const char *val,int flags,Namfun_t *fp)
|
|||
i++;
|
||||
}
|
||||
error(ERROR_exit(1), "%s: invalid value %s",nv_name(np),val);
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
static char* get_enum(register Namval_t* np, Namfun_t *fp)
|
||||
|
|
@ -196,8 +197,8 @@ int b_enum(int argc, char** argv, Shbltin_t *context)
|
|||
iflag = 'i';
|
||||
continue;
|
||||
case '?':
|
||||
error(ERROR_USAGE|4, "%s", opt_info.arg);
|
||||
break;
|
||||
error(ERROR_usage(2), "%s", opt_info.arg);
|
||||
UNREACHABLE();
|
||||
case ':':
|
||||
error(2, "%s", opt_info.arg);
|
||||
break;
|
||||
|
|
@ -213,7 +214,10 @@ int b_enum(int argc, char** argv, Shbltin_t *context)
|
|||
while(cp = *argv++)
|
||||
{
|
||||
if(!(np = nv_open(cp, (void*)0, NV_VARNAME|NV_NOADD)) || !(ap=nv_arrayptr(np)) || ap->fun || (sz=ap->nelem&(((1L<<ARRAY_BITS)-1))) < 2)
|
||||
error(ERROR_exit(1), "%s must name an array containing at least two elements",cp);
|
||||
{
|
||||
error(ERROR_exit(1), "%s must name an array containing at least two elements",cp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
n = staktell();
|
||||
sfprintf(stkstd,"%s.%s%c",NV_CLASS,np->nvname,0);
|
||||
tp = nv_open(stakptr(n), shp->var_tree, NV_VARNAME);
|
||||
|
|
|
|||
|
|
@ -84,12 +84,15 @@ int b_getopts(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
argc -= opt_info.index;
|
||||
if(error_info.errors || argc<2)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
error_info.context->flags |= ERROR_SILENT;
|
||||
error_info.id = options;
|
||||
options = argv[0];
|
||||
|
|
@ -126,7 +129,10 @@ int b_getopts(int argc,char *argv[],Shbltin_t *context)
|
|||
{
|
||||
case '?':
|
||||
if(mode==0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
UNREACHABLE();
|
||||
}
|
||||
opt_info.option[1] = '?';
|
||||
/* FALLTHROUGH */
|
||||
case ':':
|
||||
|
|
@ -160,7 +166,10 @@ int b_getopts(int argc,char *argv[],Shbltin_t *context)
|
|||
optget(com,options);
|
||||
opt_info.index = flag;
|
||||
if(!mode && strchr(options,' '))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
opt_info.arg = 0;
|
||||
options = value;
|
||||
|
|
|
|||
|
|
@ -57,7 +57,10 @@ int b_hist(int argc,char *argv[], Shbltin_t *context)
|
|||
Histloc_t location;
|
||||
NOT_USED(argc);
|
||||
if(!sh_histinit((void*)shp))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_histopen);
|
||||
UNREACHABLE();
|
||||
}
|
||||
hp = shp->gd->hist_ptr;
|
||||
while((flag = optget(argv,sh_opthist))) switch(flag)
|
||||
{
|
||||
|
|
@ -95,10 +98,13 @@ int b_hist(int argc,char *argv[], Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += (opt_info.index-1);
|
||||
#if SHOPT_HISTEXPAND
|
||||
if(pflag)
|
||||
|
|
@ -147,7 +153,10 @@ int b_hist(int argc,char *argv[], Shbltin_t *context)
|
|||
/* search for last line starting with string */
|
||||
location = hist_find(hp,argv[1],hist_max(hp)-1,0,-1);
|
||||
if((range[++flag] = location.hist_command) < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_found,argv[1]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
if(flag <0)
|
||||
|
|
@ -174,9 +183,15 @@ int b_hist(int argc,char *argv[], Shbltin_t *context)
|
|||
range[1] = flag;
|
||||
/* check for valid ranges */
|
||||
if(range[1]<index2 || range[0]>=flag)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badrange,range[0],range[1]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(edit && *edit=='-' && range[0]!=range[1])
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_eneedsarg);
|
||||
UNREACHABLE();
|
||||
}
|
||||
/* now list commands from range[flag] to range[1-flag] */
|
||||
incr = 1;
|
||||
flag = rflag>0;
|
||||
|
|
@ -190,9 +205,15 @@ int b_hist(int argc,char *argv[], Shbltin_t *context)
|
|||
else
|
||||
{
|
||||
if(!(fname=pathtmp(NIL(char*),0,0,NIL(int*))))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_create,"");
|
||||
UNREACHABLE();
|
||||
}
|
||||
if((fdo=open(fname,O_CREAT|O_RDWR,S_IRUSR|S_IWUSR)) < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_create,fname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
outfile= sfnew(NIL(Sfio_t*),shp->outbuff,IOBSIZE,fdo,SF_WRITE);
|
||||
arg = "\n";
|
||||
nflag++;
|
||||
|
|
@ -219,7 +240,10 @@ int b_hist(int argc,char *argv[], Shbltin_t *context)
|
|||
{
|
||||
arg = (char*)e_defedit;
|
||||
if(*arg!='/')
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),"ed not found set FCEDIT");
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if(*arg != '-')
|
||||
{
|
||||
|
|
@ -246,7 +270,10 @@ int b_hist(int argc,char *argv[], Shbltin_t *context)
|
|||
Sfio_t *iop = sfnew(NIL(Sfio_t*),buff,IOBSIZE,fdo,SF_READ);
|
||||
/* read in and run the command */
|
||||
if(shp->hist_depth++ > HIST_RECURSE)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_toodeep,"history");
|
||||
UNREACHABLE();
|
||||
}
|
||||
sh_eval(iop,1);
|
||||
shp->hist_depth--;
|
||||
}
|
||||
|
|
@ -284,7 +311,10 @@ static void hist_subst(const char *command,int fd,char *replace)
|
|||
string[c] = 0;
|
||||
*newp++ = 0;
|
||||
if((sp=sh_substitute(string,replace,newp))==0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_subst,command);
|
||||
UNREACHABLE();
|
||||
}
|
||||
*(newp-1) = '=';
|
||||
sh_eval(sfopen(NIL(Sfio_t*),sp,"s"),1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,18 +113,27 @@ int b_exec(int argc,char *argv[], Shbltin_t *context)
|
|||
return(2);
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(*argv[0]=='r' && argv[opt_info.index]) /* 'redirect' supports no args */
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(2),"%s: %s",e_badsyntax,argv[opt_info.index]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(!*argv)
|
||||
return(0);
|
||||
|
||||
/* from here on, it's 'exec' with args, so we're replacing the shell */
|
||||
if(sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,argv[0]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
register struct argnod *arg=logdata.sh->envlist;
|
||||
register Namval_t* np;
|
||||
register char *cp;
|
||||
|
|
@ -157,7 +166,6 @@ int b_exec(int argc,char *argv[], Shbltin_t *context)
|
|||
sh_sigreset(2);
|
||||
sh_freeup(logdata.sh);
|
||||
path_exec(logdata.sh,pname,argv,NIL(struct argnod*));
|
||||
sh_done(logdata.sh,0);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
|
@ -175,11 +183,14 @@ int b_let(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors || !*argv)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
while(arg= *argv++)
|
||||
r = !sh_arith(shp,arg);
|
||||
return(r);
|
||||
|
|
@ -200,7 +211,10 @@ int b_eval(int argc,char *argv[], Shbltin_t *context)
|
|||
return(2);
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(*argv && **argv)
|
||||
{
|
||||
|
|
@ -236,9 +250,15 @@ int b_dot_cmd(register int n,char *argv[],Shbltin_t *context)
|
|||
argv += opt_info.index;
|
||||
script = *argv;
|
||||
if(error_info.errors || !script)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(shp->dot_depth+1 > DOTMAX)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_toodeep,script);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!(np=shp->posix_fun))
|
||||
{
|
||||
/* check for KornShell style function first */
|
||||
|
|
@ -254,7 +274,10 @@ int b_dot_cmd(register int n,char *argv[],Shbltin_t *context)
|
|||
np = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_found,script);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -262,7 +285,10 @@ int b_dot_cmd(register int n,char *argv[],Shbltin_t *context)
|
|||
if(!np)
|
||||
{
|
||||
if((fd=path_open(shp,script,path_get(shp,script))) < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_open,script);
|
||||
UNREACHABLE();
|
||||
}
|
||||
filename = path_fullname(shp,stkptr(shp->stk,PATH_OFFSET));
|
||||
}
|
||||
}
|
||||
|
|
@ -362,11 +388,17 @@ int b_shift(register int n, register char *argv[], Shbltin_t *context)
|
|||
return(2);
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
n = ((arg= *argv)?(int)sh_arith(shp,arg):1);
|
||||
if(n<0 || shp->st.dolc<n)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_number,arg);
|
||||
UNREACHABLE();
|
||||
}
|
||||
else
|
||||
{
|
||||
shp->st.dolv += n;
|
||||
|
|
@ -385,10 +417,13 @@ int b_wait(int n,register char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
job_bwait(argv);
|
||||
return(shp->exitval);
|
||||
|
|
@ -416,20 +451,26 @@ int b_bg(register int n,register char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(!sh_isstate(SH_MONITOR))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_no_jctl);
|
||||
return(1);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(flag=='d' && *argv==0)
|
||||
argv = (char**)0;
|
||||
if(job_walk(sfstdout,job_switch,flag,argv))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_no_job);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(shp->exitval);
|
||||
}
|
||||
|
||||
|
|
@ -453,15 +494,21 @@ int b_jobs(register int n,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(*argv==0)
|
||||
argv = (char**)0;
|
||||
if(job_walk(sfstdout,job_list,flag,argv))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_no_job);
|
||||
UNREACHABLE();
|
||||
}
|
||||
job_wait((pid_t)0);
|
||||
return(shp->exitval);
|
||||
}
|
||||
|
|
@ -527,12 +574,16 @@ int b_times(int argc, char *argv[], Shbltin_t *context)
|
|||
case ':':
|
||||
errormsg(SH_DICT, 2, "%s", opt_info.arg);
|
||||
errormsg(SH_DICT, ERROR_usage(2), "%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
default:
|
||||
errormsg(SH_DICT, ERROR_usage(0), "%s", opt_info.arg);
|
||||
return(2);
|
||||
}
|
||||
if (argv[opt_info.index])
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(2), e_toomanyops);
|
||||
UNREACHABLE();
|
||||
}
|
||||
/* Get & print the times */
|
||||
print_cpu_times();
|
||||
return(0);
|
||||
|
|
@ -555,21 +606,30 @@ int b_universe(int argc, char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
argc -= opt_info.index;
|
||||
if(error_info.errors || argc>1)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(arg = argv[0])
|
||||
{
|
||||
if(!astconf("UNIVERSE",0,arg))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1), e_badname,arg);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!(arg=astconf("UNIVERSE",0,0)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_nouniverse);
|
||||
UNREACHABLE();
|
||||
}
|
||||
else
|
||||
sfputr(sfstdout,arg,'\n');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -421,13 +421,16 @@ int b_mkservice(int argc, char** argv, Shbltin_t *context)
|
|||
continue;
|
||||
case '?':
|
||||
error(ERROR_usage(2), opt_info.arg);
|
||||
continue;
|
||||
UNREACHABLE();
|
||||
}
|
||||
break;
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if (error_info.errors || !(var = *argv++) || !(path = *argv++) || *argv)
|
||||
{
|
||||
error(ERROR_usage(2), optusage(NiL));
|
||||
UNREACHABLE();
|
||||
}
|
||||
sp = sh_newof(0, Service_t, 1, 0);
|
||||
sp->acceptf = Accept;
|
||||
sp->actionf = Action;
|
||||
|
|
@ -440,6 +443,7 @@ int b_mkservice(int argc, char** argv, Shbltin_t *context)
|
|||
{
|
||||
free((void*)sp);
|
||||
error(ERROR_exit(1), "%s: cannot start service", path);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if((sp->fd = fcntl(fd, F_DUPFD, 10))>=10)
|
||||
close(fd);
|
||||
|
|
@ -472,13 +476,16 @@ int b_eloop(int argc, char** argv, Shbltin_t *context)
|
|||
continue;
|
||||
case '?':
|
||||
error(ERROR_usage(2), opt_info.arg);
|
||||
continue;
|
||||
UNREACHABLE();
|
||||
}
|
||||
break;
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if (error_info.errors || *argv)
|
||||
{
|
||||
error(ERROR_usage(2), optusage(NiL));
|
||||
UNREACHABLE();
|
||||
}
|
||||
while(1)
|
||||
{
|
||||
if(waitnotify(-1, timeout, 0)==0)
|
||||
|
|
|
|||
|
|
@ -214,7 +214,10 @@ int b_print(int argc, char *argv[], Shbltin_t *context)
|
|||
case 's':
|
||||
/* print to history file */
|
||||
if(!sh_histinit((void*)shp))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_history);
|
||||
UNREACHABLE();
|
||||
}
|
||||
fd = sffileno(shp->gd->hist_ptr->histfp);
|
||||
sh_onstate(SH_HISTORY);
|
||||
sflag++;
|
||||
|
|
@ -266,13 +269,19 @@ int b_print(int argc, char *argv[], Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors || (argc<0 && !(format = *argv++)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(vflag && format)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"-%c and -f are mutually exclusive",vflag);
|
||||
UNREACHABLE();
|
||||
}
|
||||
skip:
|
||||
if(format)
|
||||
format = genformat(format);
|
||||
|
|
@ -293,6 +302,7 @@ skip2:
|
|||
if(fd==1)
|
||||
return(1);
|
||||
errormsg(SH_DICT,ERROR_system(1),msg);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!(outfile=shp->sftable[fd]))
|
||||
{
|
||||
|
|
@ -545,7 +555,10 @@ static ssize_t fmtbase64(Sfio_t *iop, char *string, int alt)
|
|||
if(!np || nv_isnull(np))
|
||||
{
|
||||
if(sh_isoption(SH_NOUNSET))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_notset,string);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
if(nv_isattr(np,NV_INTEGER))
|
||||
|
|
@ -755,7 +768,10 @@ static int extend(Sfio_t* sp, void* v, Sffmt_t* fe)
|
|||
break;
|
||||
default:
|
||||
if(!strchr("DdXxoUu",format))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_formspec,format);
|
||||
UNREACHABLE();
|
||||
}
|
||||
fe->fmt = 'd';
|
||||
value->ll = 0;
|
||||
break;
|
||||
|
|
@ -934,7 +950,7 @@ static int extend(Sfio_t* sp, void* v, Sffmt_t* fe)
|
|||
fe->fmt = 'd';
|
||||
fe->size = sizeof(value->ll);
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_formspec,format);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if (format == '.')
|
||||
value->i = value->ll;
|
||||
|
|
@ -980,13 +996,19 @@ static int extend(Sfio_t* sp, void* v, Sffmt_t* fe)
|
|||
case 'P':
|
||||
s = fmtmatch(value->s);
|
||||
if(!s || *s==0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badregexp,value->s);
|
||||
UNREACHABLE();
|
||||
}
|
||||
value->s = s;
|
||||
break;
|
||||
case 'R':
|
||||
s = fmtre(value->s);
|
||||
if(!s || *s==0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badregexp,value->s);
|
||||
UNREACHABLE();
|
||||
}
|
||||
value->s = s;
|
||||
break;
|
||||
case 'Q':
|
||||
|
|
|
|||
|
|
@ -109,7 +109,10 @@ int b_read(int argc,char *argv[], Shbltin_t *context)
|
|||
break;
|
||||
case 'p':
|
||||
if((fd = shp->cpipe[0])<=0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_query);
|
||||
UNREACHABLE();
|
||||
}
|
||||
break;
|
||||
case 'n': case 'N':
|
||||
flags &= ((1<<D_FLAG)-1);
|
||||
|
|
@ -129,7 +132,10 @@ int b_read(int argc,char *argv[], Shbltin_t *context)
|
|||
case 'u':
|
||||
fd = (int)opt_info.num;
|
||||
if(opt_info.num<0 || opt_info.num>INT_MAX || (fd>=shp->gd->lim.open_max && !sh_iovalidfd(shp,fd)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_file,opt_info.arg); /* reject invalid file descriptors */
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(sh_inuse(shp,fd))
|
||||
fd = -1;
|
||||
break;
|
||||
|
|
@ -141,15 +147,21 @@ int b_read(int argc,char *argv[], Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!((r=shp->fdstatus[fd])&IOREAD) || !(r&(IOSEEK|IONOSEEK)))
|
||||
r = sh_iocheckfd(shp,fd);
|
||||
if(fd<0 || !(r&IOREAD))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_file+4);
|
||||
UNREACHABLE();
|
||||
}
|
||||
/* look for prompt */
|
||||
if((name = *argv) && (name=strchr(name,'?')) && (r&IOTTY))
|
||||
r = strlen(name++);
|
||||
|
|
@ -485,7 +497,10 @@ int sh_readline(register Shell_t *shp,char **names, volatile int fd, int flags,s
|
|||
{
|
||||
c = sfvalue(iop)+1;
|
||||
if(!sferror(iop) && sfgetc(iop) >=0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_overlimit,"line length");
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if(timeslot)
|
||||
timerdel(timeslot);
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@ int b___regress__(int argc, char** argv, Shbltin_t *context)
|
|||
{
|
||||
case '?':
|
||||
errormsg(SH_DICT, ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
case ':':
|
||||
errormsg(SH_DICT, 2, "%s", opt_info.arg);
|
||||
break;
|
||||
|
|
@ -332,7 +332,10 @@ int b___regress__(int argc, char** argv, Shbltin_t *context)
|
|||
break;
|
||||
}
|
||||
if (error_info.errors || *(argv + opt_info.index))
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NiL));
|
||||
UNREACHABLE();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,10 +60,13 @@ int b_sleep(register int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(cp = *argv)
|
||||
{
|
||||
|
|
@ -93,16 +96,25 @@ int b_sleep(register int argc,char *argv[],Shbltin_t *context)
|
|||
ns = tmxdate(pp, &last, now);
|
||||
}
|
||||
if(*last)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_number,*argv);
|
||||
UNREACHABLE();
|
||||
}
|
||||
d = ns - now;
|
||||
d /= TMX_RESOLUTION;
|
||||
}
|
||||
skip:
|
||||
if(argv[1])
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_oneoperand);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
else if(!sflag)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_oneoperand);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(d > .10)
|
||||
{
|
||||
time(&tloc);
|
||||
|
|
|
|||
|
|
@ -141,7 +141,10 @@ int b_test(int argc, char *argv[],Shbltin_t *context)
|
|||
{
|
||||
cp = argv[--argc];
|
||||
if(!c_eq(cp, ']'))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_missing,"']'");
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if(argc <= 1)
|
||||
{
|
||||
|
|
@ -192,6 +195,7 @@ int b_test(int argc, char *argv[],Shbltin_t *context)
|
|||
goto done;
|
||||
}
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_badop,cp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
exitval = (test_binop(tdata.sh,op,argv[1],argv[3])^(argc!=5));
|
||||
goto done;
|
||||
|
|
@ -218,7 +222,7 @@ int b_test(int argc, char *argv[],Shbltin_t *context)
|
|||
av[2] = 0;
|
||||
optget(av,sh_opttest);
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
|
||||
return(2);
|
||||
UNREACHABLE();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -276,6 +280,7 @@ static int expr(struct test *tp,register int flag)
|
|||
if(flag==0)
|
||||
break;
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_badsyntax);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(r);
|
||||
}
|
||||
|
|
@ -290,6 +295,7 @@ static char *nxtarg(struct test *tp,int mt)
|
|||
return(0);
|
||||
}
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_argument);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(tp->av[tp->ap++]);
|
||||
}
|
||||
|
|
@ -308,7 +314,10 @@ static int e3(struct test *tp)
|
|||
op = expr(tp,1);
|
||||
cp = nxtarg(tp,0);
|
||||
if(!cp || !c_eq(cp, ')'))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_missing,"')'");
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(op);
|
||||
}
|
||||
cp = nxtarg(tp,1);
|
||||
|
|
@ -340,6 +349,7 @@ static int e3(struct test *tp)
|
|||
if(op==0 || !strchr(test_opchars+10,op))
|
||||
return(1);
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_argument);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(strchr(test_opchars,op))
|
||||
return(test_unop(tp->sh,op,cp));
|
||||
|
|
@ -354,7 +364,10 @@ skip:
|
|||
if(!(op&TEST_BINOP))
|
||||
cp = nxtarg(tp,0);
|
||||
if(!op)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_badop,binop);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(op==TEST_AND || op==TEST_OR)
|
||||
tp->ap--;
|
||||
return(test_binop(tp->sh,op,arg,cp));
|
||||
|
|
@ -491,8 +504,7 @@ int test_unop(Shell_t *shp,register int op,register const char *arg)
|
|||
static char a[3] = "-?";
|
||||
a[1]= op;
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_badop,a);
|
||||
/* NOTREACHED */
|
||||
return(0);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -553,8 +565,7 @@ int test_binop(Shell_t *shp,register int op,const char *left,const char *right)
|
|||
errormsg(SH_DICT, ERROR_exit(2), op==TEST_END ? e_badop : e_unsupported_op, shtab_testops[i].sh_name);
|
||||
}
|
||||
}
|
||||
/* NOTREACHED */
|
||||
return(0);
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -60,11 +60,13 @@ int b_trap(int argc,char *argv[],Shbltin_t *context)
|
|||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(0), "%s", opt_info.arg);
|
||||
return(2);
|
||||
break;
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(arg = *argv)
|
||||
{
|
||||
char *action = arg;
|
||||
|
|
@ -91,7 +93,10 @@ int b_trap(int argc,char *argv[],Shbltin_t *context)
|
|||
}
|
||||
}
|
||||
if(!argv[0])
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_condition);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
while(arg = *argv++)
|
||||
{
|
||||
|
|
@ -217,14 +222,17 @@ int b_kill(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
endopts:
|
||||
argv += opt_info.index;
|
||||
if(*argv && strcmp(*argv,"--")==0 && strcmp(*(argv-1),"--")!=0)
|
||||
argv++;
|
||||
if(error_info.errors || flag==(L_FLAG|S_FLAG) || (!(*argv) && !(flag&L_FLAG)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
/* just in case we send a kill -9 $$ */
|
||||
sfsync(sfstderr);
|
||||
if(flag&L_FLAG)
|
||||
|
|
@ -241,6 +249,7 @@ endopts:
|
|||
{
|
||||
shp->exitval = 2;
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_nosignal,signame);
|
||||
UNREACHABLE();
|
||||
}
|
||||
sfprintf(sfstdout,"%d\n",sig);
|
||||
}
|
||||
|
|
@ -250,7 +259,10 @@ endopts:
|
|||
if(flag&S_FLAG)
|
||||
{
|
||||
if((sig=sig_number(shp,signame)) < 0 || sig > shp->gd->sigmax)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_nosignal,signame);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if(job_walk(sfstdout,job_kill,sig,argv))
|
||||
shp->exitval = 1;
|
||||
|
|
@ -273,16 +285,28 @@ int b_suspend(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(error_info.errors) /* no options supported (except AST --man, etc.) */
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(argv[opt_info.index]) /* no operands supported */
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(2), e_toomanyops);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(sh_isoption(SH_LOGIN_SHELL))
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(1), "cannot suspend a login shell");
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(kill(context->shp->gd->pid, SIGSTOP) != 0)
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(1), "could not signal main shell at PID %d", context->shp->gd->pid);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
#endif /* defined(JOBS) && defined(SIGSTOP) */
|
||||
|
|
|
|||
|
|
@ -107,7 +107,10 @@ int b_readonly(int argc,char *argv[],Shbltin_t *context)
|
|||
return(2);
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),optusage(NIL(char*)));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += (opt_info.index-1);
|
||||
if(*command=='r')
|
||||
flag = (NV_ASSIGN|NV_RDONLY|NV_VARNAME);
|
||||
|
|
@ -166,7 +169,10 @@ int b_alias(int argc,register char *argv[],Shbltin_t *context)
|
|||
return(2);
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage(NIL(char*)));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += (opt_info.index-1);
|
||||
}
|
||||
/* 'alias -t', 'hash' */
|
||||
|
|
@ -222,7 +228,10 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
|
|||
else if(argv[0][0] == 'n') /* <n>ameref == typeset -n */
|
||||
new_argv[1] = "-n";
|
||||
else
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(128), "internal error");
|
||||
UNREACHABLE();
|
||||
}
|
||||
for (n = 1; n <= argc; n++)
|
||||
new_argv[n + 1] = argv[n];
|
||||
argc++;
|
||||
|
|
@ -305,7 +314,10 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
|
|||
if(tdata.argnum==0)
|
||||
tdata.argnum = (int)opt_info.num;
|
||||
if(tdata.argnum < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1), e_badfield, tdata.argnum);
|
||||
UNREACHABLE();
|
||||
}
|
||||
isadjust = 1;
|
||||
if(n=='Z')
|
||||
flag |= NV_ZFILL;
|
||||
|
|
@ -317,7 +329,10 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case 'M':
|
||||
if((tdata.wctname = opt_info.arg) && !nv_mapchar((Namval_t*)0,tdata.wctname))
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(1),e_unknownmap, tdata.wctname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(tdata.wctname && strcmp(tdata.wctname,e_tolower)==0)
|
||||
flag |= NV_UTOL;
|
||||
else
|
||||
|
|
@ -452,9 +467,15 @@ endargs:
|
|||
flag |= NV_STATICF;
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s", optusage(NIL(char*)));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(sizeof(char*)<8 && tdata.argnum > SHRT_MAX)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(2),"option argument cannot be greater than %d",SHRT_MAX);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(isfloat)
|
||||
flag |= NV_DOUBLE;
|
||||
if(sflag)
|
||||
|
|
@ -496,7 +517,10 @@ endargs:
|
|||
#endif /* SHOPT_NAMESPACE */
|
||||
stkseek(stkp,offset);
|
||||
if(!tdata.tp)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),"%s: unknown type",tdata.prefix);
|
||||
UNREACHABLE();
|
||||
}
|
||||
else if(nv_isnull(tdata.tp))
|
||||
nv_newtype(tdata.tp);
|
||||
tdata.tp->nvenv = tdata.help;
|
||||
|
|
@ -512,7 +536,10 @@ endargs:
|
|||
if(!tdata.sh->mktype)
|
||||
tdata.help = 0;
|
||||
if(tdata.aflag=='+' && (flag&(NV_ARRAY|NV_IARRAY|NV_COMVAR)) && argv[1])
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_nounattr);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(setall(argv,flag,troot,&tdata));
|
||||
}
|
||||
|
||||
|
|
@ -632,7 +659,10 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
|
|||
{
|
||||
/* Function names cannot be special builtin */
|
||||
if((np=nv_search(name,shp->bltin_tree,0)) && nv_isattr(np,BLT_SPC))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badfun,name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#if SHOPT_NAMESPACE
|
||||
if(shp->namespace)
|
||||
np = sh_fsearch(shp,name,NV_ADD|HASH_NOSCOPE);
|
||||
|
|
@ -705,7 +735,10 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
|
|||
if(nv_isnull(np) && !nv_isarray(np) && nv_isattr(np,NV_NOFREE))
|
||||
nv_offattr(np,NV_NOFREE);
|
||||
else if(tp->tp && !nv_isattr(np,NV_MINIMAL|NV_EXPORT) && (mp=(Namval_t*)np->nvenv) && (ap=nv_arrayptr(mp)) && (ap->nelem&ARRAY_TREE))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_typecompat,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
else if((ap=nv_arrayptr(np)) && nv_aindex(np)>0 && ap->nelem==1 && nv_getval(np)==Empty)
|
||||
{
|
||||
ap->nelem++;
|
||||
|
|
@ -713,7 +746,10 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
|
|||
ap->nelem--;
|
||||
}
|
||||
else if(iarray && ap && ap->fun)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),"cannot change associative array %s to indexed array",nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
else if( (iarray||(flag&NV_ARRAY)) && nv_isvtree(np) && !nv_type(np))
|
||||
_nv_unset(np,NV_EXPORT);
|
||||
if(tp->pflag)
|
||||
|
|
@ -804,7 +840,10 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
|
|||
Namfun_t *fp;
|
||||
char *cp;
|
||||
if(!tp->wctname)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_mapchararg,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
cp = (char*)nv_mapchar(np,0);
|
||||
if(fp=nv_mapchar(np,tp->wctname))
|
||||
{
|
||||
|
|
@ -828,7 +867,10 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
|
|||
if (tp->aflag == '-')
|
||||
{
|
||||
if((flag&NV_EXPORT) && (strchr(name,'.') || nv_isvtree(np)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badexport,name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#if SHOPT_BSH
|
||||
if(flag&NV_EXPORT)
|
||||
nv_offattr(np,NV_IMPORT);
|
||||
|
|
@ -849,7 +891,10 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
|
|||
else
|
||||
{
|
||||
if((flag&NV_RDONLY) && (curflag&NV_RDONLY))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_readonly,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
newflag = curflag & ~flag;
|
||||
}
|
||||
if (tp->aflag && (tp->argnum || (curflag!=newflag)))
|
||||
|
|
@ -1071,18 +1116,27 @@ int b_builtin(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s", optusage(NIL(char*)));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(arg || *argv)
|
||||
{
|
||||
if(sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,argv[-opt_info.index]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#if SHOPT_PFSH
|
||||
if(sh_isoption(SH_PFSH))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_pfsh,argv[-opt_info.index]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#endif
|
||||
if(tdata.sh->subshell && !tdata.sh->subshare)
|
||||
sh_subfork();
|
||||
|
|
@ -1244,7 +1298,10 @@ static int unall(int argc, char **argv, register Dt_t *troot, Shell_t* shp)
|
|||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors || (*argv==0 &&!all))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage(NIL(char*)));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!troot)
|
||||
return(1);
|
||||
r = 0;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@
|
|||
NOT_USED(argv);
|
||||
NOT_USED(context);
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_nosupport);
|
||||
return(0);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#else
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
opt_info.disc = 0;
|
||||
/* default to -f */
|
||||
|
|
@ -121,7 +121,10 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context)
|
|||
/* only one option at a time for setting */
|
||||
label = (hit&(hit-1));
|
||||
if(error_info.errors || (limit && label) || argc>opt_info.index+1)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(mode==0)
|
||||
mode = (HARD|SOFT);
|
||||
for(tp = shtab_limits; tp->option && hit; tp++,hit>>=1)
|
||||
|
|
@ -145,26 +148,41 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context)
|
|||
else if((i=strton(limit,&last,NiL,0))==INFINITY || *last)
|
||||
{
|
||||
if((i=sh_strnum(limit,&last,2))==INFINITY || *last)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_number,limit);
|
||||
UNREACHABLE();
|
||||
}
|
||||
i *= unit;
|
||||
}
|
||||
}
|
||||
if(nosupport)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_readonly,tp->name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef _lib_getrlimit
|
||||
if(getrlimit(n,&rlp) <0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_number,limit);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(mode&HARD)
|
||||
rlp.rlim_max = i;
|
||||
if(mode&SOFT)
|
||||
rlp.rlim_cur = i;
|
||||
if(setrlimit(n,&rlp) <0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_overlimit,limit);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#else
|
||||
if((i=vlimit(n,i)) < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_number,limit);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#endif /* _lib_getrlimit */
|
||||
}
|
||||
}
|
||||
|
|
@ -174,7 +192,10 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context)
|
|||
{
|
||||
#ifdef _lib_getrlimit
|
||||
if(getrlimit(n,&rlp) <0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_number,limit);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(mode&HARD)
|
||||
i = rlp.rlim_max;
|
||||
if(mode&SOFT)
|
||||
|
|
@ -185,7 +206,10 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context)
|
|||
# endif /* _lib_ulimit */
|
||||
i = -1;
|
||||
if((i=vlimit(n,i)) < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_number,limit);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#endif /* _lib_getrlimit */
|
||||
}
|
||||
if(label)
|
||||
|
|
|
|||
|
|
@ -53,10 +53,13 @@ int b_umask(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(mask = *argv)
|
||||
{
|
||||
|
|
@ -68,7 +71,10 @@ int b_umask(int argc,char *argv[],Shbltin_t *context)
|
|||
if (c>='0' && c<='7')
|
||||
flag = (flag<<3) + (c-'0');
|
||||
else
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_number,*argv);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -80,6 +86,7 @@ int b_umask(int argc,char *argv[],Shbltin_t *context)
|
|||
{
|
||||
umask(flag);
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_format,mask);
|
||||
UNREACHABLE();
|
||||
}
|
||||
flag = (~c&0777);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,10 @@ int b_command(register int argc,char *argv[],Shbltin_t *context)
|
|||
{
|
||||
case 'p':
|
||||
if(sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,"-p");
|
||||
UNREACHABLE();
|
||||
}
|
||||
sh_onstate(SH_DEFPATH);
|
||||
break;
|
||||
case 'v':
|
||||
|
|
@ -79,7 +82,7 @@ int b_command(register int argc,char *argv[],Shbltin_t *context)
|
|||
if(argc==0)
|
||||
return(0);
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(argc==0)
|
||||
{
|
||||
|
|
@ -91,7 +94,10 @@ int b_command(register int argc,char *argv[],Shbltin_t *context)
|
|||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors || !*argv)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(whence(shp,argv, flags));
|
||||
}
|
||||
|
||||
|
|
@ -128,11 +134,14 @@ int b_whence(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors || !*argv)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(whence(shp, argv, flags));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue