mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Yet another round of accumulated tweaks and cleanups
Notable changes:
- sh/timers.c: Rename timerdel() to sh_timerdel() for consistency;
we had timerdel() but sh_timeradd().
- include/shell.h: Remove unused sh struct members:
- sh.lastpath (this was still being saved/restored in several
places, but not actually used since 2008-06-02 ksh93t-)
- sh.lastbase (unused since 2000-10-31 ksh93k)
- sh.inpool (unused since libcoshell was removed in 3613da42
)
- sh/xec.c: sh_exec(): Add comments for the various command types.
This commit is contained in:
parent
d79a34b327
commit
8a0920ea0a
16 changed files with 88 additions and 48 deletions
|
@ -167,14 +167,13 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
|
||||||
dp = cdpath?cdpath->name:"";
|
dp = cdpath?cdpath->name:"";
|
||||||
cdpath = path_nextcomp(cdpath,dir,0);
|
cdpath = path_nextcomp(cdpath,dir,0);
|
||||||
#if _WINIX
|
#if _WINIX
|
||||||
if(*stakptr(PATH_OFFSET+1)==':' && isalpha(*stakptr(PATH_OFFSET)))
|
if(*stakptr(PATH_OFFSET+1)==':' && isalpha(*stakptr(PATH_OFFSET)))
|
||||||
{
|
{
|
||||||
*stakptr(PATH_OFFSET+1) = *stakptr(PATH_OFFSET);
|
*stakptr(PATH_OFFSET+1) = *stakptr(PATH_OFFSET);
|
||||||
*stakptr(PATH_OFFSET)='/';
|
*stakptr(PATH_OFFSET)='/';
|
||||||
}
|
}
|
||||||
#endif /* _WINIX */
|
#endif /* _WINIX */
|
||||||
if(*stakptr(PATH_OFFSET)!='/')
|
if(*stakptr(PATH_OFFSET)!='/')
|
||||||
|
|
||||||
{
|
{
|
||||||
char *last=(char*)stakfreeze(1);
|
char *last=(char*)stakfreeze(1);
|
||||||
stakseek(PATH_OFFSET);
|
stakseek(PATH_OFFSET);
|
||||||
|
|
|
@ -464,7 +464,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, long tim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(timeslot)
|
if(timeslot)
|
||||||
timerdel(timeslot);
|
sh_timerdel(timeslot);
|
||||||
if(binary && !((size=nv_size(np)) && nv_isarray(np) && c!=size))
|
if(binary && !((size=nv_size(np)) && nv_isarray(np) && c!=size))
|
||||||
{
|
{
|
||||||
if((c==size) && np->nvalue.cp && !nv_isarray(np))
|
if((c==size) && np->nvalue.cp && !nv_isarray(np))
|
||||||
|
@ -500,7 +500,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, long tim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(timeslot)
|
if(timeslot)
|
||||||
timerdel(timeslot);
|
sh_timerdel(timeslot);
|
||||||
if((flags&S_FLAG) && !sh.hist_ptr)
|
if((flags&S_FLAG) && !sh.hist_ptr)
|
||||||
{
|
{
|
||||||
sh_histinit();
|
sh_histinit();
|
||||||
|
|
|
@ -211,7 +211,7 @@ int tty_set(int fd, int action, struct termios *tty)
|
||||||
/*{ TTY_COOKED( fd )
|
/*{ TTY_COOKED( fd )
|
||||||
*
|
*
|
||||||
* This routine will set the tty in cooked mode.
|
* This routine will set the tty in cooked mode.
|
||||||
* It is also called by error.done().
|
* It is also called by sh_done().
|
||||||
*
|
*
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
|
@ -193,10 +193,10 @@ static int search(Vi_t*,int);
|
||||||
static void sync_cursor(Vi_t*);
|
static void sync_cursor(Vi_t*);
|
||||||
static int textmod(Vi_t*,int,int);
|
static int textmod(Vi_t*,int,int);
|
||||||
|
|
||||||
/*+ VI_READ( fd, shbuf, nchar )
|
/*+ ED_VIREAD( context, fd, shbuf, nchar, reedit )
|
||||||
*
|
*
|
||||||
* This routine implements a one line version of vi and is
|
* This routine implements a one line version of vi and is
|
||||||
* called by _filbuf.c
|
* called by slowread() in io.c
|
||||||
*
|
*
|
||||||
-*/
|
-*/
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ extern void sh_siginit(void);
|
||||||
extern void sh_sigtrap(int);
|
extern void sh_sigtrap(int);
|
||||||
extern void sh_sigreset(int);
|
extern void sh_sigreset(int);
|
||||||
extern void *sh_timeradd(unsigned long,int ,void (*)(void*),void*);
|
extern void *sh_timeradd(unsigned long,int ,void (*)(void*),void*);
|
||||||
extern void timerdel(void*);
|
extern void sh_timerdel(void*);
|
||||||
|
|
||||||
extern const char e_alarm[];
|
extern const char e_alarm[];
|
||||||
|
|
||||||
|
|
|
@ -207,10 +207,10 @@ struct sh_scoped
|
||||||
int ioset;
|
int ioset;
|
||||||
unsigned short trapmax;
|
unsigned short trapmax;
|
||||||
char trapdontexec; /* stop exec optimization if any non-DEBUG/SIGKILL/SIGSTOP trap is set and non-empty */
|
char trapdontexec; /* stop exec optimization if any non-DEBUG/SIGKILL/SIGSTOP trap is set and non-empty */
|
||||||
char *trap[SH_DEBUGTRAP+1];
|
char *trap[SH_DEBUGTRAP+1]; /* pseudosignals (except EXIT) */
|
||||||
char **otrap;
|
char **otrap; /* save parent pseudosignals for v=$(trap) */
|
||||||
char **trapcom;
|
char **trapcom; /* EXIT and signals */
|
||||||
char **otrapcom;
|
char **otrapcom; /* save parent EXIT and signals for v=$(trap) */
|
||||||
struct Ufunction *real_fun; /* current 'function name' function */
|
struct Ufunction *real_fun; /* current 'function name' function */
|
||||||
int repl_index;
|
int repl_index;
|
||||||
char *repl_arg;
|
char *repl_arg;
|
||||||
|
@ -276,7 +276,6 @@ struct Shell_s
|
||||||
Sfio_t *funlog; /* for logging function definitions */
|
Sfio_t *funlog; /* for logging function definitions */
|
||||||
int **fdptrs; /* pointer to file numbers */
|
int **fdptrs; /* pointer to file numbers */
|
||||||
char *lastarg;
|
char *lastarg;
|
||||||
char *lastpath; /* last absolute path found */
|
|
||||||
int path_err; /* last error on path search */
|
int path_err; /* last error on path search */
|
||||||
Dt_t *var_base; /* global level variables */
|
Dt_t *var_base; /* global level variables */
|
||||||
Dt_t *fun_base; /* global level functions */
|
Dt_t *fun_base; /* global level functions */
|
||||||
|
@ -308,7 +307,6 @@ struct Shell_s
|
||||||
unsigned char *sigflag; /* pointer to signal states */
|
unsigned char *sigflag; /* pointer to signal states */
|
||||||
char intrap;
|
char intrap;
|
||||||
char login_sh;
|
char login_sh;
|
||||||
char lastbase;
|
|
||||||
char forked;
|
char forked;
|
||||||
char binscript;
|
char binscript;
|
||||||
char funload;
|
char funload;
|
||||||
|
@ -375,7 +373,6 @@ struct Shell_s
|
||||||
Dt_t *prev_root;
|
Dt_t *prev_root;
|
||||||
Dt_t *fpathdict;
|
Dt_t *fpathdict;
|
||||||
Dt_t *typedict;
|
Dt_t *typedict;
|
||||||
Dt_t *inpool;
|
|
||||||
char ifstable[256];
|
char ifstable[256];
|
||||||
Shopt_t offoptions; /* options that were explicitly disabled by the user on the command line */
|
Shopt_t offoptions; /* options that were explicitly disabled by the user on the command line */
|
||||||
Shopt_t glob_options;
|
Shopt_t glob_options;
|
||||||
|
|
|
@ -650,7 +650,6 @@ char **sh_argbuild(int *nargs, const struct comnod *comptr,int flag)
|
||||||
*nargs = ap->dolnum;
|
*nargs = ap->dolnum;
|
||||||
return(ap->dolval+ap->dolbot);
|
return(ap->dolval+ap->dolbot);
|
||||||
}
|
}
|
||||||
sh.lastpath = 0;
|
|
||||||
*nargs = 0;
|
*nargs = 0;
|
||||||
if(ac)
|
if(ac)
|
||||||
{
|
{
|
||||||
|
|
|
@ -608,7 +608,6 @@ static void array_putval(Namval_t *np, const char *string, int flags, Namfun_t *
|
||||||
if(mp && mp!=np)
|
if(mp && mp!=np)
|
||||||
{
|
{
|
||||||
if(!is_associative(ap) && string && !(flags&NV_APPEND) && !nv_type(np) && nv_isvtree(mp) && !(ap->nelem&ARRAY_TREE))
|
if(!is_associative(ap) && string && !(flags&NV_APPEND) && !nv_type(np) && nv_isvtree(mp) && !(ap->nelem&ARRAY_TREE))
|
||||||
|
|
||||||
{
|
{
|
||||||
if(!nv_isattr(np,NV_NOFREE))
|
if(!nv_isattr(np,NV_NOFREE))
|
||||||
_nv_unset(mp,flags&NV_RDONLY);
|
_nv_unset(mp,flags&NV_RDONLY);
|
||||||
|
|
|
@ -1607,9 +1607,7 @@ static int io_heredoc(register struct ionod *iop, const char *name, int traceon)
|
||||||
}
|
}
|
||||||
if(!(iop->iofile&IOQUOTE))
|
if(!(iop->iofile&IOQUOTE))
|
||||||
{
|
{
|
||||||
char *lastpath = sh.lastpath;
|
|
||||||
sh_machere(infile,outfile,iop->ioname);
|
sh_machere(infile,outfile,iop->ioname);
|
||||||
sh.lastpath = lastpath;
|
|
||||||
if(infile)
|
if(infile)
|
||||||
sfclose(infile);
|
sfclose(infile);
|
||||||
}
|
}
|
||||||
|
@ -1989,7 +1987,7 @@ static ssize_t slowread(Sfio_t *iop,void *buff,register size_t size,Sfdisc_t *ha
|
||||||
timeout = (void*)sh_timeradd(sh_isstate(SH_GRACE)?1000L*TGRACE:1000L*sh.timeout,0,time_grace,&sh);
|
timeout = (void*)sh_timeradd(sh_isstate(SH_GRACE)?1000L*TGRACE:1000L*sh.timeout,0,time_grace,&sh);
|
||||||
rsize = (*readf)(sh.ed_context, fno, (char*)buff, size, reedit);
|
rsize = (*readf)(sh.ed_context, fno, (char*)buff, size, reedit);
|
||||||
if(timeout)
|
if(timeout)
|
||||||
timerdel(timeout);
|
sh_timerdel(timeout);
|
||||||
timeout=0;
|
timeout=0;
|
||||||
#if SHOPT_HISTEXPAND
|
#if SHOPT_HISTEXPAND
|
||||||
if(rsize && *(char*)buff != '\n' && sh.nextprompt==1 && sh_isoption(SH_HISTEXPAND))
|
if(rsize && *(char*)buff != '\n' && sh.nextprompt==1 && sh_isoption(SH_HISTEXPAND))
|
||||||
|
|
|
@ -2421,7 +2421,6 @@ static void table_unset(register Dt_t *root, int flags, Dt_t *oroot)
|
||||||
int len = strlen(np->nvname);
|
int len = strlen(np->nvname);
|
||||||
npnext = (Namval_t*)dtnext(root,np);
|
npnext = (Namval_t*)dtnext(root,np);
|
||||||
while((nq=npnext) && strncmp(np->nvname,nq->nvname,len)==0 && nq->nvname[len]=='.')
|
while((nq=npnext) && strncmp(np->nvname,nq->nvname,len)==0 && nq->nvname[len]=='.')
|
||||||
|
|
||||||
{
|
{
|
||||||
_nv_unset(nq,flags);
|
_nv_unset(nq,flags);
|
||||||
npnext = (Namval_t*)dtnext(root,nq);
|
npnext = (Namval_t*)dtnext(root,nq);
|
||||||
|
|
|
@ -532,7 +532,6 @@ static void put_type(Namval_t* np, const char* val, int flag, Namfun_t* fp)
|
||||||
{
|
{
|
||||||
Namfun_t *pp;
|
Namfun_t *pp;
|
||||||
if((pp=nv_hasdisc(nq,fp->disc)) && pp->type==fp->type)
|
if((pp=nv_hasdisc(nq,fp->disc)) && pp->type==fp->type)
|
||||||
|
|
||||||
{
|
{
|
||||||
if(!nq->nvenv)
|
if(!nq->nvenv)
|
||||||
flag |= NV_EXPORT;
|
flag |= NV_EXPORT;
|
||||||
|
|
|
@ -996,7 +996,7 @@ noreturn void path_exec(register const char *arg0,register char *argv[],struct a
|
||||||
pp=path_get(arg0);
|
pp=path_get(arg0);
|
||||||
sh.path_err= ENOENT;
|
sh.path_err= ENOENT;
|
||||||
sfsync(NIL(Sfio_t*));
|
sfsync(NIL(Sfio_t*));
|
||||||
timerdel(NIL(void*));
|
sh_timerdel(NIL(void*));
|
||||||
/* find first path that has a library component */
|
/* find first path that has a library component */
|
||||||
while(pp && (pp->flags&PATH_SKIP))
|
while(pp && (pp->flags&PATH_SKIP))
|
||||||
pp = pp->next;
|
pp = pp->next;
|
||||||
|
|
|
@ -229,7 +229,7 @@ void *sh_timeradd(unsigned long msec,int flags,void (*action)(void*),void *handl
|
||||||
/*
|
/*
|
||||||
* delete timer <tp>. If <tp> is NULL, all timers are deleted
|
* delete timer <tp>. If <tp> is NULL, all timers are deleted
|
||||||
*/
|
*/
|
||||||
void timerdel(void *handle)
|
void sh_timerdel(void *handle)
|
||||||
{
|
{
|
||||||
register Timer_t *tp = (Timer_t*)handle;
|
register Timer_t *tp = (Timer_t*)handle;
|
||||||
if(tp)
|
if(tp)
|
||||||
|
|
|
@ -916,6 +916,9 @@ static int check_exec_optimization(int type, int execflg, int execflg2, struct i
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Main execution function: execute any type of command.
|
||||||
|
*/
|
||||||
int sh_exec(register const Shnode_t *t, int flags)
|
int sh_exec(register const Shnode_t *t, int flags)
|
||||||
{
|
{
|
||||||
Stk_t *stkp = sh.stk;
|
Stk_t *stkp = sh.stk;
|
||||||
|
@ -953,9 +956,11 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
sh.exitval=0;
|
sh.exitval=0;
|
||||||
sh.lastsig = 0;
|
sh.lastsig = 0;
|
||||||
sh.chldexitsig = 0;
|
sh.chldexitsig = 0;
|
||||||
sh.lastpath = 0;
|
|
||||||
switch(type&COMMSK)
|
switch(type&COMMSK)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Simple command
|
||||||
|
*/
|
||||||
case TCOM:
|
case TCOM:
|
||||||
{
|
{
|
||||||
register struct argnod *argp;
|
register struct argnod *argp;
|
||||||
|
@ -1172,7 +1177,6 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
}
|
}
|
||||||
if(io)
|
if(io)
|
||||||
sfsync(sh.outpool);
|
sfsync(sh.outpool);
|
||||||
sh.lastpath = 0;
|
|
||||||
if(!np)
|
if(!np)
|
||||||
{
|
{
|
||||||
if(*com0 == '/' && !sh_isoption(SH_RESTRICTED))
|
if(*com0 == '/' && !sh_isoption(SH_RESTRICTED))
|
||||||
|
@ -1442,7 +1446,6 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
jmpval = sigsetjmp(buffp->buff,0);
|
jmpval = sigsetjmp(buffp->buff,0);
|
||||||
}
|
}
|
||||||
if(jmpval == 0)
|
if(jmpval == 0)
|
||||||
|
|
||||||
{
|
{
|
||||||
if(io)
|
if(io)
|
||||||
indx = sh_redirect(io,execflg);
|
indx = sh_redirect(io,execflg);
|
||||||
|
@ -1483,6 +1486,7 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
siglongjmp(*sh.jmplist,jmpval);
|
siglongjmp(*sh.jmplist,jmpval);
|
||||||
goto setexit;
|
goto setexit;
|
||||||
}
|
}
|
||||||
|
/* not a built-in or function: external command, fall through to TFORK */
|
||||||
}
|
}
|
||||||
else if(!io)
|
else if(!io)
|
||||||
{
|
{
|
||||||
|
@ -1497,6 +1501,10 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Any command that needs the shell to fork (e.g. background or external)
|
||||||
|
*/
|
||||||
case TFORK:
|
case TFORK:
|
||||||
{
|
{
|
||||||
register pid_t parent;
|
register pid_t parent;
|
||||||
|
@ -1650,7 +1658,7 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
fd = (type&FPIN) ? 0 : 1;
|
fd = (type&FPIN) ? 0 : 1;
|
||||||
fn = sh_open(sh.fifo,fd?O_WRONLY:O_RDONLY);
|
fn = sh_open(sh.fifo,fd?O_WRONLY:O_RDONLY);
|
||||||
save_errno = errno;
|
save_errno = errno;
|
||||||
timerdel(fifo_timer);
|
sh_timerdel(fifo_timer);
|
||||||
sh.fifo = 0;
|
sh.fifo = 0;
|
||||||
if(fn<0)
|
if(fn<0)
|
||||||
{
|
{
|
||||||
|
@ -1738,12 +1746,13 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSETIO:
|
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
|
* Redirection:
|
||||||
* don't create a new process, just
|
* don't create a new process, just
|
||||||
* save and restore io-streams
|
* save and restore io-streams
|
||||||
*/
|
*/
|
||||||
|
case TSETIO:
|
||||||
|
{
|
||||||
pid_t pid = 0;
|
pid_t pid = 0;
|
||||||
int jmpval, waitall = 0;
|
int jmpval, waitall = 0;
|
||||||
int simple = (t->fork.forktre->tre.tretyp&COMMSK)==TCOM;
|
int simple = (t->fork.forktre->tre.tretyp&COMMSK)==TCOM;
|
||||||
|
@ -1827,6 +1836,9 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parentheses subshell block
|
||||||
|
*/
|
||||||
case TPAR:
|
case TPAR:
|
||||||
echeck = 1;
|
echeck = 1;
|
||||||
flags &= ~OPTIMIZE_FLAG;
|
flags &= ~OPTIMIZE_FLAG;
|
||||||
|
@ -1861,13 +1873,13 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
sh_subshell(t->par.partre,flags,0);
|
sh_subshell(t->par.partre,flags,0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Pipe: command | command
|
||||||
|
* All elements of the pipe are started by the parent.
|
||||||
|
* The last element is executed in the current environment.
|
||||||
|
*/
|
||||||
case TFIL:
|
case TFIL:
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* This code sets up a pipe.
|
|
||||||
* All elements of the pipe are started by the parent.
|
|
||||||
* The last element executes in current environment
|
|
||||||
*/
|
|
||||||
int pvo[3]; /* old pipe for multi-stage */
|
int pvo[3]; /* old pipe for multi-stage */
|
||||||
int pvn[3]; /* current set up pipe */
|
int pvn[3]; /* current set up pipe */
|
||||||
int savepipe = pipejob;
|
int savepipe = pipejob;
|
||||||
|
@ -1976,9 +1988,11 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* List of semicolon-separated commands
|
||||||
|
*/
|
||||||
case TLST:
|
case TLST:
|
||||||
{
|
{
|
||||||
/* a list of commands is executed here */
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
sh_exec(t->lst.lstlef,errorflg|OPTIMIZE);
|
sh_exec(t->lst.lstlef,errorflg|OPTIMIZE);
|
||||||
|
@ -1993,6 +2007,9 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Logical and: command && command
|
||||||
|
*/
|
||||||
case TAND:
|
case TAND:
|
||||||
if(type&TTEST)
|
if(type&TTEST)
|
||||||
skipexitset++;
|
skipexitset++;
|
||||||
|
@ -2000,6 +2017,9 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
sh_exec(t->lst.lstrit,flags);
|
sh_exec(t->lst.lstrit,flags);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Logical or: command || command
|
||||||
|
*/
|
||||||
case TORF:
|
case TORF:
|
||||||
if(type&TTEST)
|
if(type&TTEST)
|
||||||
skipexitset++;
|
skipexitset++;
|
||||||
|
@ -2007,7 +2027,10 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
sh_exec(t->lst.lstrit,flags);
|
sh_exec(t->lst.lstrit,flags);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TFOR: /* for and select */
|
/*
|
||||||
|
* Loop: 'for' or 'select'
|
||||||
|
*/
|
||||||
|
case TFOR:
|
||||||
{
|
{
|
||||||
register char **args;
|
register char **args;
|
||||||
register int nargs;
|
register int nargs;
|
||||||
|
@ -2135,7 +2158,10 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TWH: /* while and until */
|
/*
|
||||||
|
* Loop: 'while' or 'until'
|
||||||
|
*/
|
||||||
|
case TWH:
|
||||||
{
|
{
|
||||||
volatile int r=0;
|
volatile int r=0;
|
||||||
int first = OPTIMIZE_FLAG;
|
int first = OPTIMIZE_FLAG;
|
||||||
|
@ -2226,7 +2252,11 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
#endif /* SHOPT_FILESCAN */
|
#endif /* SHOPT_FILESCAN */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TARITH: /* (( expression )) */
|
|
||||||
|
/*
|
||||||
|
* Arithmetic command: ((expression))
|
||||||
|
*/
|
||||||
|
case TARITH:
|
||||||
{
|
{
|
||||||
register char *trap;
|
register char *trap;
|
||||||
char *arg[4];
|
char *arg[4];
|
||||||
|
@ -2252,6 +2282,9 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Conditional block: if ... fi
|
||||||
|
*/
|
||||||
case TIF:
|
case TIF:
|
||||||
if(sh_exec(t->if_.iftre,OPTIMIZE)==0)
|
if(sh_exec(t->if_.iftre,OPTIMIZE)==0)
|
||||||
sh_exec(t->if_.thtre,flags);
|
sh_exec(t->if_.thtre,flags);
|
||||||
|
@ -2261,6 +2294,9 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
sh.exitval=0; /* force zero exit for if-then-fi */
|
sh.exitval=0; /* force zero exit for if-then-fi */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Switch block: case ... esac
|
||||||
|
*/
|
||||||
case TSW:
|
case TSW:
|
||||||
{
|
{
|
||||||
Shnode_t *tt = (Shnode_t*)t;
|
Shnode_t *tt = (Shnode_t*)t;
|
||||||
|
@ -2309,9 +2345,11 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The 'time' keyword: time a pipeline
|
||||||
|
*/
|
||||||
case TTIME:
|
case TTIME:
|
||||||
{
|
{
|
||||||
/* time the command */
|
|
||||||
const char *format = e_timeformat;
|
const char *format = e_timeformat;
|
||||||
struct timeval ta, tb;
|
struct timeval ta, tb;
|
||||||
#ifdef timeofday
|
#ifdef timeofday
|
||||||
|
@ -2391,6 +2429,10 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
p_time(sfstderr,sh_translate(format),tm);
|
p_time(sfstderr,sh_translate(format),tm);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function definition
|
||||||
|
*/
|
||||||
case TFUN:
|
case TFUN:
|
||||||
{
|
{
|
||||||
register Namval_t *np=0;
|
register Namval_t *np=0;
|
||||||
|
@ -2399,6 +2441,7 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
register char *cp = strrchr(fname,'.');
|
register char *cp = strrchr(fname,'.');
|
||||||
register Namval_t *npv=0,*mp;
|
register Namval_t *npv=0,*mp;
|
||||||
#if SHOPT_NAMESPACE
|
#if SHOPT_NAMESPACE
|
||||||
|
/* Namespace definition: a modified function definition */
|
||||||
if(t->tre.tretyp==TNSPACE)
|
if(t->tre.tretyp==TNSPACE)
|
||||||
{
|
{
|
||||||
Dt_t *root;
|
Dt_t *root;
|
||||||
|
@ -2572,7 +2615,9 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* new test compound command */
|
/*
|
||||||
|
* The [[ keyword: new test compound command
|
||||||
|
*/
|
||||||
case TTST:
|
case TTST:
|
||||||
{
|
{
|
||||||
register int n;
|
register int n;
|
||||||
|
@ -2703,6 +2748,11 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
return(sh.exitval);
|
return(sh.exitval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Public API function: run the command given by by the argument list argv,
|
||||||
|
* containing argn elements. If argv[0] does not contain a /, check for a
|
||||||
|
* built-in or function before performing a path search.
|
||||||
|
*/
|
||||||
int sh_run(int argn, char *argv[])
|
int sh_run(int argn, char *argv[])
|
||||||
{
|
{
|
||||||
register struct dolnod *dp;
|
register struct dolnod *dp;
|
||||||
|
@ -2830,7 +2880,7 @@ pid_t _sh_fork(register pid_t parent,int flags,int *jobid)
|
||||||
pause();
|
pause();
|
||||||
else if(forkcnt>1000L)
|
else if(forkcnt>1000L)
|
||||||
forkcnt /= 2;
|
forkcnt /= 2;
|
||||||
timerdel(timeout);
|
sh_timerdel(timeout);
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
}
|
}
|
||||||
return(-1);
|
return(-1);
|
||||||
|
@ -2895,7 +2945,7 @@ pid_t _sh_fork(register pid_t parent,int flags,int *jobid)
|
||||||
sh.outpipepid = ((flags&FPOU)?sh.current_pid:0);
|
sh.outpipepid = ((flags&FPOU)?sh.current_pid:0);
|
||||||
if(sh.trapnote&SH_SIGTERM)
|
if(sh.trapnote&SH_SIGTERM)
|
||||||
sh_exit(SH_EXITSIG|SIGTERM);
|
sh_exit(SH_EXITSIG|SIGTERM);
|
||||||
timerdel(NIL(void*));
|
sh_timerdel(NIL(void*));
|
||||||
#ifdef JOBS
|
#ifdef JOBS
|
||||||
if(sh_isstate(SH_MONITOR))
|
if(sh_isstate(SH_MONITOR))
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* *
|
* *
|
||||||
* This software is part of the ast package *
|
* This software is part of the ast package *
|
||||||
* Copyright (c) 1985-2011 AT&T Intellectual Property *
|
* Copyright (c) 1985-2011 AT&T Intellectual Property *
|
||||||
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
|
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
|
||||||
* and is licensed under the *
|
* and is licensed under the *
|
||||||
* Eclipse Public License, Version 1.0 *
|
* Eclipse Public License, Version 1.0 *
|
||||||
* by AT&T Intellectual Property *
|
* by AT&T Intellectual Property *
|
||||||
|
@ -518,13 +518,13 @@ extern struct mntent* getmntent(FILE*);
|
||||||
|
|
||||||
#if _lib_getmntent
|
#if _lib_getmntent
|
||||||
|
|
||||||
typedef struct
|
|
||||||
#if _mem_mnt_opts_mntent
|
#if _mem_mnt_opts_mntent
|
||||||
#define OPTIONS(p) ((p)->mnt_opts)
|
#define OPTIONS(p) ((p)->mnt_opts)
|
||||||
#else
|
#else
|
||||||
#define OPTIONS(p) NiL
|
#define OPTIONS(p) NiL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef struct
|
||||||
{
|
{
|
||||||
Header_t hdr;
|
Header_t hdr;
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* *
|
* *
|
||||||
* This software is part of the ast package *
|
* This software is part of the ast package *
|
||||||
* Copyright (c) 1985-2012 AT&T Intellectual Property *
|
* Copyright (c) 1985-2012 AT&T Intellectual Property *
|
||||||
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
|
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
|
||||||
* and is licensed under the *
|
* and is licensed under the *
|
||||||
* Eclipse Public License, Version 1.0 *
|
* Eclipse Public License, Version 1.0 *
|
||||||
* by AT&T Intellectual Property *
|
* by AT&T Intellectual Property *
|
||||||
|
@ -766,7 +766,7 @@ static int bestfree(Vmalloc_t* vm, void* data, int local )
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* bestresize(Vmalloc_t* vm, /* region allocating from */
|
static void* bestresize(Vmalloc_t* vm, /* region allocating from */
|
||||||
void* data, /* old block of data */
|
void* data, /* old block of data */
|
||||||
reg size_t size, /* new size */
|
reg size_t size, /* new size */
|
||||||
int type, /* !=0 to move, <0 for not copy */
|
int type, /* !=0 to move, <0 for not copy */
|
||||||
int local)
|
int local)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue