Skip to content

Commit

Permalink
Yet another round of accumulated tweaks and cleanups
Browse files Browse the repository at this point in the history
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 3613da4)

- sh/xec.c: sh_exec(): Add comments for the various command types.
  • Loading branch information
McDutchie committed Jul 3, 2022
1 parent d79a34b commit 8a0920e
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 47 deletions.
5 changes: 2 additions & 3 deletions src/cmd/ksh93/bltins/cd_pwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,13 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
dp = cdpath?cdpath->name:"";
cdpath = path_nextcomp(cdpath,dir,0);
#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)='/';
}
#endif /* _WINIX */
if(*stakptr(PATH_OFFSET)!='/')

if(*stakptr(PATH_OFFSET)!='/')
{
char *last=(char*)stakfreeze(1);
stakseek(PATH_OFFSET);
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/bltins/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, long tim
}
}
if(timeslot)
timerdel(timeslot);
sh_timerdel(timeslot);
if(binary && !((size=nv_size(np)) && nv_isarray(np) && c!=size))
{
if((c==size) && np->nvalue.cp && !nv_isarray(np))
Expand Down Expand Up @@ -500,7 +500,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, long tim
}
}
if(timeslot)
timerdel(timeslot);
sh_timerdel(timeslot);
if((flags&S_FLAG) && !sh.hist_ptr)
{
sh_histinit();
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/edit/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ int tty_set(int fd, int action, struct termios *tty)
/*{ TTY_COOKED( fd )
*
* This routine will set the tty in cooked mode.
* It is also called by error.done().
* It is also called by sh_done().
*
}*/

Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/edit/vi.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ static int search(Vi_t*,int);
static void sync_cursor(Vi_t*);
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
* called by _filbuf.c
* called by slowread() in io.c
*
-*/

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/fault.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ extern void sh_siginit(void);
extern void sh_sigtrap(int);
extern void sh_sigreset(int);
extern void *sh_timeradd(unsigned long,int ,void (*)(void*),void*);
extern void timerdel(void*);
extern void sh_timerdel(void*);

extern const char e_alarm[];

Expand Down
11 changes: 4 additions & 7 deletions src/cmd/ksh93/include/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ struct sh_scoped
int ioset;
unsigned short trapmax;
char trapdontexec; /* stop exec optimization if any non-DEBUG/SIGKILL/SIGSTOP trap is set and non-empty */
char *trap[SH_DEBUGTRAP+1];
char **otrap;
char **trapcom;
char **otrapcom;
char *trap[SH_DEBUGTRAP+1]; /* pseudosignals (except EXIT) */
char **otrap; /* save parent pseudosignals for v=$(trap) */
char **trapcom; /* EXIT and signals */
char **otrapcom; /* save parent EXIT and signals for v=$(trap) */
struct Ufunction *real_fun; /* current 'function name' function */
int repl_index;
char *repl_arg;
Expand Down Expand Up @@ -276,7 +276,6 @@ struct Shell_s
Sfio_t *funlog; /* for logging function definitions */
int **fdptrs; /* pointer to file numbers */
char *lastarg;
char *lastpath; /* last absolute path found */
int path_err; /* last error on path search */
Dt_t *var_base; /* global level variables */
Dt_t *fun_base; /* global level functions */
Expand Down Expand Up @@ -308,7 +307,6 @@ struct Shell_s
unsigned char *sigflag; /* pointer to signal states */
char intrap;
char login_sh;
char lastbase;
char forked;
char binscript;
char funload;
Expand Down Expand Up @@ -375,7 +373,6 @@ struct Shell_s
Dt_t *prev_root;
Dt_t *fpathdict;
Dt_t *typedict;
Dt_t *inpool;
char ifstable[256];
Shopt_t offoptions; /* options that were explicitly disabled by the user on the command line */
Shopt_t glob_options;
Expand Down
1 change: 0 additions & 1 deletion src/cmd/ksh93/sh/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,6 @@ char **sh_argbuild(int *nargs, const struct comnod *comptr,int flag)
*nargs = ap->dolnum;
return(ap->dolval+ap->dolbot);
}
sh.lastpath = 0;
*nargs = 0;
if(ac)
{
Expand Down
1 change: 0 additions & 1 deletion src/cmd/ksh93/sh/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ static void array_putval(Namval_t *np, const char *string, int flags, Namfun_t *
if(mp && mp!=np)
{
if(!is_associative(ap) && string && !(flags&NV_APPEND) && !nv_type(np) && nv_isvtree(mp) && !(ap->nelem&ARRAY_TREE))

{
if(!nv_isattr(np,NV_NOFREE))
_nv_unset(mp,flags&NV_RDONLY);
Expand Down
4 changes: 1 addition & 3 deletions src/cmd/ksh93/sh/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1607,9 +1607,7 @@ static int io_heredoc(register struct ionod *iop, const char *name, int traceon)
}
if(!(iop->iofile&IOQUOTE))
{
char *lastpath = sh.lastpath;
sh_machere(infile,outfile,iop->ioname);
sh.lastpath = lastpath;
if(infile)
sfclose(infile);
}
Expand Down Expand Up @@ -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);
rsize = (*readf)(sh.ed_context, fno, (char*)buff, size, reedit);
if(timeout)
timerdel(timeout);
sh_timerdel(timeout);
timeout=0;
#if SHOPT_HISTEXPAND
if(rsize && *(char*)buff != '\n' && sh.nextprompt==1 && sh_isoption(SH_HISTEXPAND))
Expand Down
1 change: 0 additions & 1 deletion src/cmd/ksh93/sh/name.c
Original file line number Diff line number Diff line change
Expand Up @@ -2421,7 +2421,6 @@ static void table_unset(register Dt_t *root, int flags, Dt_t *oroot)
int len = strlen(np->nvname);
npnext = (Namval_t*)dtnext(root,np);
while((nq=npnext) && strncmp(np->nvname,nq->nvname,len)==0 && nq->nvname[len]=='.')

{
_nv_unset(nq,flags);
npnext = (Namval_t*)dtnext(root,nq);
Expand Down
1 change: 0 additions & 1 deletion src/cmd/ksh93/sh/nvtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ static void put_type(Namval_t* np, const char* val, int flag, Namfun_t* fp)
{
Namfun_t *pp;
if((pp=nv_hasdisc(nq,fp->disc)) && pp->type==fp->type)

{
if(!nq->nvenv)
flag |= NV_EXPORT;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/sh/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ noreturn void path_exec(register const char *arg0,register char *argv[],struct a
pp=path_get(arg0);
sh.path_err= ENOENT;
sfsync(NIL(Sfio_t*));
timerdel(NIL(void*));
sh_timerdel(NIL(void*));
/* find first path that has a library component */
while(pp && (pp->flags&PATH_SKIP))
pp = pp->next;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/sh/timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
void timerdel(void *handle)
void sh_timerdel(void *handle)
{
register Timer_t *tp = (Timer_t*)handle;
if(tp)
Expand Down
Loading

0 comments on commit 8a0920e

Please sign in to comment.