1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

[shp cleanup 01..20] all the rest (re: 2d3ec8b6)

This combines 20 cleanup commits from the dev branch.

All changed files:
- Clean up pointer defererences to sh.
- Remove shp arguments from functions.

Other notable changes:

src/cmd/ksh93/include/shell.h,
src/cmd/ksh93/sh/init.c:
- On second thought, get rid of the function version of
  sh_getinterp() as libshell ABI compatibility is moot. We've
  already been breaking that by reordering the sh struct, so there
  is no way it's going to work without recompiling.

src/cmd/ksh93/sh/name.c:
- De-obfuscate the relationship between nv_scan() and scanfilter().
  The former just calls the latter as a static function, there's no
  need to do that via a function pointer and void* type conversions.

src/cmd/ksh93/bltins/typeset.c,
src/cmd/ksh93/sh/name.c,
src/cmd/ksh93/sh/nvdisc.c:
- 'struct adata' and 'struct tdata', defined as local struct types
  in these files, need to have their first three fields in common,
  the first being a pointer to sh. This is because scanfilter() in
  name.c accesses these fields via a type conversion. So the sh
  field needed to be removed in all three at the same time.
  TODO: de-obfuscate: good practice definition via a header file.

src/cmd/ksh93/sh/path.c:
- Naming consistency: reserve the path_ function name prefix for
  externs and rename statics with that prefix.
- The default path was sometimes referred to as the standard path.
  To use one term, rename std_path to defpath and onstdpath() to
  ondefpath().
- De-obfuscate SHOPT_PFSH conditional code by only calling
  pf_execve() (was path_pfexecve()) if that is compiled in.

src/cmd/ksh93/include/streval.h,
src/cmd/ksh93/sh/streval.c:
- Rename extern strval() to arith_strval() for consistency.

src/cmd/ksh93/sh/string.c:
- Remove outdated/incorrect isxdigit() fallback; '#ifnded isxdigit'
  is not a correct test as isxdigit() is specified as a function.
  Plus, it's part of C89/C90 which we now require. (re: ac8991e5)

src/cmd/ksh93/sh/suid_exec.c:
- Replace an incorrect reference to shgd->current_pid with
  getpid(); it cannot work as (contrary to its misleading directory
  placement) suid_exec is an independent libast program with no
  link to ksh or libshell at all. However, no one noticed because
  this was in fallback code for ancient systems without
  setreuid(2). Since that standard function was specified in POSIX
  Issue 4 Version 2 from 1994, we should remove that fallback code
  sometime as part of another obsolete code cleanup operation to
  avoid further bit rot. (re: 843b546c)

src/cmd/ksh93/bltins/print.c: genformat():
- Remove preformat[] which was always empty and had no effect.

src/cmd/ksh93/shell.3:
- Minor copy-edit.
- Remove documentation for nonexistent sh.infile_name. A search
  through ast-open-archive[*] reveals this never existed at all.
- Document sh.savexit (== $?).

src/cmd/ksh93/shell.3,
src/cmd/ksh93/include/shell.h,
src/cmd/ksh93/sh/init.c:
- Remove sh.gd/shgd; this is now unused and was never documented
  or exposed in the shell.h public interface.
- sh_sigcheck() was documented in shell.3 as taking no arguments
  whereas in the actual code it took a shp argument. I decided to
  go with the documentation.
- That leaves sh_parse() as the only documented function that still
  takes an shp argument. I'm just going to go ahead and remove it
  for consistency, reverting sh_parse() to its pre-2003 spec.
- Remove undocumented/unused sh_bltin_tree() function which simply
  returned sh.bltin_tree.
- Bump SH_VERSION to 20220106.
This commit is contained in:
Martijn Dekker 2022-01-07 16:16:31 +00:00
parent 01da863154
commit b590a9f155
68 changed files with 3674 additions and 3935 deletions

View file

@ -148,11 +148,11 @@ static const char bellchr[] = "\a"; /* bell char */
*/
int tty_check(int fd)
{
register Edit_t *ep = (Edit_t*)(shgd->ed_context);
register Edit_t *ep = (Edit_t*)(sh.ed_context);
struct termios tty;
Sfio_t *sp;
ep->e_savefd = -1;
if(fd < 0 || fd > shgd->lim.open_max || sh.fdstatus[fd] == IOCLOSE
if(fd < 0 || fd > sh.lim.open_max || sh.fdstatus[fd] == IOCLOSE
|| (sp = sh.sftable[fd]) && (sfset(sp,0,0) & SF_STRING))
return(0);
return(tty_get(fd,&tty)==0);
@ -166,7 +166,7 @@ int tty_check(int fd)
int tty_get(register int fd, register struct termios *tty)
{
register Edit_t *ep = (Edit_t*)(shgd->ed_context);
register Edit_t *ep = (Edit_t*)(sh.ed_context);
if(fd == ep->e_savefd)
*tty = ep->e_savetty;
else
@ -194,7 +194,7 @@ int tty_get(register int fd, register struct termios *tty)
int tty_set(int fd, int action, struct termios *tty)
{
register Edit_t *ep = (Edit_t*)(shgd->ed_context);
register Edit_t *ep = (Edit_t*)(sh.ed_context);
if(fd >=0)
{
while(tcsetattr(fd, action, tty) == SYSERR)
@ -218,9 +218,9 @@ int tty_set(int fd, int action, struct termios *tty)
void tty_cooked(register int fd)
{
register Edit_t *ep = (Edit_t*)(shgd->ed_context);
if(ep->sh->st.trap[SH_KEYTRAP] && savelex)
memcpy(ep->sh->lex_context,savelex,sizeof(Lex_t));
register Edit_t *ep = (Edit_t*)(sh.ed_context);
if(sh.st.trap[SH_KEYTRAP] && savelex)
memcpy(sh.lex_context,savelex,sizeof(Lex_t));
ep->e_keytrap = 0;
if(ep->e_raw==0)
return;
@ -257,7 +257,7 @@ int tty_raw(register int fd, int echomode)
#ifdef L_MASK
struct ltchars lchars;
#endif /* L_MASK */
register Edit_t *ep = (Edit_t*)(shgd->ed_context);
register Edit_t *ep = (Edit_t*)(sh.ed_context);
if(ep->e_raw==RAWMODE)
return(echo?-1:0);
else if(ep->e_raw==ECHOMODE)
@ -381,7 +381,7 @@ int tty_raw(register int fd, int echomode)
# ifdef TIOCGETC
int tty_alt(register int fd)
{
register Edit_t *ep = (Edit_t*)(shgd->ed_context);
register Edit_t *ep = (Edit_t*)(sh.ed_context);
int mask;
struct tchars ttychars;
switch(ep->e_raw)
@ -429,7 +429,7 @@ int tty_alt(register int fd)
int tty_alt(register int fd)
{
register Edit_t *ep = (Edit_t*)(shgd->ed_context);
register Edit_t *ep = (Edit_t*)(sh.ed_context);
switch(ep->e_raw)
{
case ECHOMODE:
@ -580,7 +580,6 @@ void ed_crlf(register Edit_t *ep)
void ed_setup(register Edit_t *ep, int fd, int reedit)
{
Shell_t *shp = ep->sh;
register char *pp;
register char *last, *prev;
char *ppmax;
@ -590,16 +589,16 @@ void ed_setup(register Edit_t *ep, int fd, int reedit)
ep->e_fd = fd;
ep->e_multiline = sh_isoption(SH_MULTILINE)!=0;
#ifdef SIGWINCH
if(!(shp->sigflag[SIGWINCH]&SH_SIGFAULT))
if(!(sh.sigflag[SIGWINCH]&SH_SIGFAULT))
{
signal(SIGWINCH,sh_fault);
shp->sigflag[SIGWINCH] |= SH_SIGFAULT;
sh.sigflag[SIGWINCH] |= SH_SIGFAULT;
}
pp = shp->st.trapcom[SIGWINCH];
shp->st.trapcom[SIGWINCH] = 0;
pp = sh.st.trapcom[SIGWINCH];
sh.st.trapcom[SIGWINCH] = 0;
sh_fault(SIGWINCH);
shp->st.trapcom[SIGWINCH] = pp;
ep->sh->winch = 0;
sh.st.trapcom[SIGWINCH] = pp;
sh.winch = 0;
#endif
#if SHOPT_EDPREDICT
ep->hlist = 0;
@ -608,12 +607,12 @@ void ed_setup(register Edit_t *ep, int fd, int reedit)
#endif /* SHOPT_EDPREDICT */
ep->e_stkoff = staktell();
ep->e_stkptr = stakfreeze(0);
if(!(last = shp->prompt))
if(!(last = sh.prompt))
last = "";
shp->prompt = 0;
if(shp->gd->hist_ptr)
sh.prompt = 0;
if(sh.hist_ptr)
{
register History_t *hp = shp->gd->hist_ptr;
register History_t *hp = sh.hist_ptr;
ep->e_hismax = hist_max(hp);
ep->e_hismin = hist_min(hp);
}
@ -795,10 +794,10 @@ void ed_setup(register Edit_t *ep, int fd, int reedit)
#if defined(_pth_tput) && (_tput_terminfo || _tput_termcap)
char *term;
if(!ep->e_term)
ep->e_term = nv_search("TERM",shp->var_tree,0);
ep->e_term = nv_search("TERM",sh.var_tree,0);
if(ep->e_term && (term=nv_getval(ep->e_term)) && strlen(term)<sizeof(ep->e_termname) && strcmp(term,ep->e_termname))
{
Shopt_t o = shp->options;
Shopt_t o = sh.options;
sigblock(SIGINT);
sh_offoption(SH_RESTRICTED);
sh_offoption(SH_VERBOSE);
@ -817,7 +816,7 @@ void ed_setup(register Edit_t *ep, int fd, int reedit)
CURSOR_UP[0] = '\0'; /* no escape sequence is better than a faulty one */
nv_unset(SH_SUBSCRNOD);
strcpy(ep->e_termname,term);
shp->options = o;
sh.options = o;
sigrelease(SIGINT);
}
#endif
@ -833,11 +832,11 @@ void ed_setup(register Edit_t *ep, int fd, int reedit)
ep->e_lbuf[n] = *pp++;
ep->e_default = 0;
}
if(ep->sh->st.trap[SH_KEYTRAP])
if(sh.st.trap[SH_KEYTRAP])
{
if(!savelex)
savelex = (Lex_t*)sh_malloc(sizeof(Lex_t));
memcpy(savelex, ep->sh->lex_context, sizeof(Lex_t));
memcpy(savelex, sh.lex_context, sizeof(Lex_t));
}
}
#endif /* SHOPT_ESH || SHOPT_VSH */
@ -871,9 +870,8 @@ int ed_read(void *context, int fd, char *buff, int size, int reedit)
register Edit_t *ep = (Edit_t*)context;
register int rv= -1;
register int delim = ((ep->e_raw&RAWMODE)?nttyparm.c_cc[VEOL]:'\n');
Shell_t *shp = ep->sh;
int mode = -1;
int (*waitevent)(int,long,int) = shp->gd->waitevent;
int (*waitevent)(int,long,int) = sh.waitevent;
/* sfpkrd must use select(2) to intercept SIGWINCH for ed_read */
if(ep->e_raw==ALTMODE)
mode = 2;
@ -884,17 +882,17 @@ int ed_read(void *context, int fd, char *buff, int size, int reedit)
}
sh_onstate(SH_TTYWAIT);
errno = EINTR;
shp->gd->waitevent = 0;
sh.waitevent = 0;
while(rv<0 && errno==EINTR)
{
if(shp->trapnote&(SH_SIGSET|SH_SIGTRAP))
if(sh.trapnote&(SH_SIGSET|SH_SIGTRAP))
goto done;
#if SHOPT_ESH && SHOPT_VSH
if(shp->winch && sh_isstate(SH_INTERACTIVE) && (sh_isoption(SH_VI) || sh_isoption(SH_EMACS) || sh_isoption(SH_GMACS)))
if(sh.winch && sh_isstate(SH_INTERACTIVE) && (sh_isoption(SH_VI) || sh_isoption(SH_EMACS) || sh_isoption(SH_GMACS)))
#elif SHOPT_ESH
if(shp->winch && sh_isstate(SH_INTERACTIVE) && (sh_isoption(SH_EMACS) || sh_isoption(SH_GMACS)))
if(sh.winch && sh_isstate(SH_INTERACTIVE) && (sh_isoption(SH_EMACS) || sh_isoption(SH_GMACS)))
#elif SHOPT_VSH
if(shp->winch && sh_isstate(SH_INTERACTIVE) && sh_isoption(SH_VI))
if(sh.winch && sh_isstate(SH_INTERACTIVE) && sh_isoption(SH_VI))
#else
if(0)
#endif
@ -941,7 +939,7 @@ int ed_read(void *context, int fd, char *buff, int size, int reedit)
emacs_redraw(ep->e_emacs);
#endif
}
shp->winch = 0;
sh.winch = 0;
/* an interrupt that should be ignored */
errno = 0;
if(!waitevent || (rv=(*waitevent)(fd,-1L,0))>=0)
@ -976,7 +974,7 @@ int ed_read(void *context, int fd, char *buff, int size, int reedit)
rv = read(fd,buff,size);
if(rv>=0 || errno!=EINTR)
break;
if(shp->trapnote&(SH_SIGSET|SH_SIGTRAP))
if(sh.trapnote&(SH_SIGSET|SH_SIGTRAP))
goto done;
/* an interrupt that should be ignored */
fixtime();
@ -985,7 +983,7 @@ int ed_read(void *context, int fd, char *buff, int size, int reedit)
else if(rv>=0 && mode>0)
rv = read(fd,buff,rv>0?rv:1);
done:
shp->gd->waitevent = waitevent;
sh.waitevent = waitevent;
sh_offstate(SH_TTYWAIT);
return(rv);
}
@ -1114,7 +1112,7 @@ int ed_getchar(register Edit_t *ep,int mode)
killpg(getpgrp(),SIGINT);
siglongjmp(ep->e_env, UINTR);
}
if(mode<=0 && ep->sh->st.trap[SH_KEYTRAP])
if(mode<=0 && sh.st.trap[SH_KEYTRAP])
{
ep->e_keytrap = 1;
n=1;
@ -1559,7 +1557,7 @@ int ed_genlen(register const genchar *str)
int tcgetattr(int fd, struct termios *tt)
{
register Edit_t *ep = (Edit_t*)(shgd->ed_context);
register Edit_t *ep = (Edit_t*)(sh.ed_context);
register int r,i;
ep->e_tcgeta = 0;
ep->e_echoctl = (ECHOCTL!=0);
@ -1581,7 +1579,7 @@ int tcgetattr(int fd, struct termios *tt)
int tcsetattr(int fd,int mode,struct termios *tt)
{
register Edit_t *ep = (Edit_t*)(shgd->ed_context);
register Edit_t *ep = (Edit_t*)(sh.ed_context);
register int r;
if(ep->e_tcgeta)
{
@ -1626,7 +1624,6 @@ static int keytrap(Edit_t *ep,char *inbuff,register int insize, int bufsize, int
{
register char *cp;
int savexit;
Shell_t *shp = ep->sh;
#if SHOPT_MULTIBYTE
char buff[MAXLINE];
ed_external(ep->e_inbuf,cp=buff);
@ -1646,9 +1643,9 @@ static int keytrap(Edit_t *ep,char *inbuff,register int insize, int bufsize, int
nv_putval(ED_COLNOD,(char*)&ep->e_col,NV_NOFREE|NV_INTEGER);
nv_putval(ED_TXTNOD,(char*)cp,NV_NOFREE);
nv_putval(ED_MODENOD,ep->e_vi_insert,NV_NOFREE);
savexit = shp->savexit;
sh_trap(shp->st.trap[SH_KEYTRAP],0);
shp->savexit = savexit;
savexit = sh.savexit;
sh_trap(sh.st.trap[SH_KEYTRAP],0);
sh.savexit = savexit;
if((cp = nv_getval(ED_CHRNOD)) == inbuff)
nv_unset(ED_CHRNOD);
else if(bufsize>0)
@ -1723,7 +1720,7 @@ int ed_histgen(Edit_t *ep,const char *pattern)
size_t m;
char *cp, **argv=0, **av, **ar;
static int maxmatch;
if(!(hp=ep->sh->gd->hist_ptr) && (!nv_getval(HISTFILE) || !sh_histinit(ep->sh)))
if(!(hp=sh.hist_ptr) && (!nv_getval(HISTFILE) || !sh_histinit()))
return(0);
if(ep->e_cur <=2)
maxmatch = 0;
@ -1733,7 +1730,7 @@ int ed_histgen(Edit_t *ep,const char *pattern)
ep->hfirst = 0;
return(0);
}
hp = ep->sh->gd->hist_ptr;
hp = sh.hist_ptr;
if(*pattern=='#' && *++pattern=='#')
return(0);
cp = stakalloc(m=strlen(pattern)+6);
@ -1881,10 +1878,9 @@ void ed_histlist(Edit_t *ep,int n)
#endif /* SHOPT_EDPREDICT */
void *ed_open(Shell_t *shp)
void *ed_open(void)
{
Edit_t *ed = sh_newof(0,Edit_t,1,0);
ed->sh = shp;
strcpy(ed->e_macro,"_??");
return((void*)ed);
}