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

@ -331,7 +331,7 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count)
register int size='x';
while(cp>outbuff && ((size=cp[-1])==' ' || size=='\t'))
cp--;
if(!var && !strchr(ap->argval,'/') && (((cp==outbuff&&ep->sh->nextprompt==1) || (strchr(";&|(",size)) && (cp==outbuff+1||size=='('||cp[-2]!='>') && *begin!='~' )))
if(!var && !strchr(ap->argval,'/') && (((cp==outbuff&&sh.nextprompt==1) || (strchr(";&|(",size)) && (cp==outbuff+1||size=='('||cp[-2]!='>') && *begin!='~' )))
{
cmd_completion=1;
sh_onstate(SH_COMPLETE);
@ -345,14 +345,14 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count)
}
else
{
com = sh_argbuild(ep->sh,&narg,comptr,0);
com = sh_argbuild(&narg,comptr,0);
/* special handling for leading quotes */
if(begin>outbuff && (begin[-1]=='"' || begin[-1]=='\''))
begin--;
}
sh_offstate(SH_COMPLETE);
/* allow a search to be aborted */
if(ep->sh->trapnote&SH_SIGSET)
if(sh.trapnote&SH_SIGSET)
{
rval = -1;
goto done;
@ -461,7 +461,7 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count)
Namval_t *np;
/* add as tracked alias */
Pathcomp_t *pp;
if(*cp=='/' && (pp=path_dirfind(ep->sh->pathlist,cp,'/')) && (np=nv_search(begin,ep->sh->track_tree,NV_ADD)))
if(*cp=='/' && (pp=path_dirfind(sh.pathlist,cp,'/')) && (np=nv_search(begin,sh.track_tree,NV_ADD)))
path_alias(np,pp);
out = strcopy(begin,cp);
}
@ -552,7 +552,7 @@ int ed_macro(Edit_t *ep, register int i)
ep->e_macro[2] = ed_getchar(ep,1);
else
ep->e_macro[2] = 0;
if (isalnum(i)&&(np=nv_search(ep->e_macro,ep->sh->alias_tree,HASH_SCOPE))&&(out=nv_getval(np)))
if (isalnum(i)&&(np=nv_search(ep->e_macro,sh.alias_tree,HASH_SCOPE))&&(out=nv_getval(np)))
{
#if SHOPT_MULTIBYTE
/* copy to buff in internal representation */
@ -583,7 +583,7 @@ int ed_macro(Edit_t *ep, register int i)
int ed_fulledit(Edit_t *ep)
{
register char *cp;
if(!shgd->hist_ptr)
if(!sh.hist_ptr)
return(-1);
/* use EDITOR on current command */
if(ep->e_hline == ep->e_hismax)
@ -594,9 +594,9 @@ int ed_fulledit(Edit_t *ep)
ep->e_inbuf[ep->e_eol+1] = 0;
ed_external(ep->e_inbuf, (char *)ep->e_inbuf);
#endif /* SHOPT_MULTIBYTE */
sfwrite(shgd->hist_ptr->histfp,(char*)ep->e_inbuf,ep->e_eol+1);
sfwrite(sh.hist_ptr->histfp,(char*)ep->e_inbuf,ep->e_eol+1);
sh_onstate(SH_HISTORY);
hist_flush(shgd->hist_ptr);
hist_flush(sh.hist_ptr);
}
cp = strcopy((char*)ep->e_inbuf,e_runvi);
cp = strcopy(cp, fmtbase((long)ep->e_hline,10,0));

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);
}

View file

@ -263,7 +263,7 @@ int ed_emacsread(void *context, int fd,char *buff,int scend, int reedit)
#ifdef ESH_NFIRST
ed_ungetchar(ep->ed,cntl('N'));
#else
location = hist_locate(shgd->hist_ptr,location.hist_command,location.hist_line,1);
location = hist_locate(sh.hist_ptr,location.hist_command,location.hist_line,1);
if (location.hist_command < histlines)
{
hline = location.hist_command;
@ -350,7 +350,7 @@ int ed_emacsread(void *context, int fd,char *buff,int scend, int reedit)
continue;
#endif /* u370 */
case '\t':
if(cur>0 && ep->ed->sh->nextprompt)
if(cur>0 && sh.nextprompt)
{
if(ep->ed->e_tabcount==0)
{
@ -684,7 +684,7 @@ update:
hline = location.hist_command; /* start at saved position */
hloff = location.hist_line;
#endif /* ESH_NFIRST */
location = hist_locate(shgd->hist_ptr,hline,hloff,count);
location = hist_locate(sh.hist_ptr,hline,hloff,count);
if (location.hist_command > histlines)
{
beep();
@ -1348,7 +1348,7 @@ static void search(Emacs_t* ep,genchar *out,int direction)
}
else
direction = ep->prevdirection ;
location = hist_find(shgd->hist_ptr,(char*)lstring,hline,1,direction);
location = hist_find(sh.hist_ptr,(char*)lstring,hline,1,direction);
i = location.hist_command;
if(i>0)
{

View file

@ -303,8 +303,8 @@ getline:
{
/* search history for string */
hl = hist_find(shgd->hist_ptr, str,
shgd->hist_ptr->histind,
hl = hist_find(sh.hist_ptr, str,
sh.hist_ptr->histind,
flag&HIST_QUESTION, -1);
if((n = hl.hist_command) == -1)
n = 0; /* not found */
@ -312,10 +312,10 @@ getline:
if(n)
{
if(n < 0) /* determine index for backref */
n = shgd->hist_ptr->histind + n;
n = sh.hist_ptr->histind + n;
/* search and use history file if found */
if(n > 0 && hist_seek(shgd->hist_ptr, n) != -1)
ref = shgd->hist_ptr->histfp;
if(n > 0 && hist_seek(sh.hist_ptr, n) != -1)
ref = sh.hist_ptr->histfp;
}
if(!ref)

View file

@ -58,7 +58,6 @@
#endif
#define _HIST_PRIVATE \
void *histshell; \
off_t histcnt; /* offset into history file */\
off_t histmarker; /* offset of last command marker */ \
int histflush; /* set if flushed outside of hflush() */\
@ -107,7 +106,7 @@ static History_t *hist_ptr;
static int acctinit(History_t *hp)
{
register char *cp, *acctfile;
Namval_t *np = nv_search("ACCTFILE",((Shell_t*)hp->histshell)->var_tree,0);
Namval_t *np = nv_search("ACCTFILE",sh.var_tree,0);
if(!np || !(acctfile=nv_getval(np)))
return(0);
@ -169,9 +168,9 @@ static int sh_checkaudit(History_t *hp, const char *name, char *logbuf, size_t l
id1 = id2 = strtol(cp,&last,10);
if(*last=='-')
id1 = strtol(last+1,&last,10);
if(shgd->euserid >=id1 && shgd->euserid <= id2)
if(sh.euserid >=id1 && sh.euserid <= id2)
r |= 1;
if(shgd->userid >=id1 && shgd->userid <= id2)
if(sh.userid >=id1 && sh.userid <= id2)
r |= 2;
cp = last;
}
@ -198,9 +197,8 @@ static void hist_touch(void *handle)
* cleaned up.
* hist_open() returns 1, if history file is open
*/
int sh_histinit(void *sh_context)
int sh_histinit(void)
{
Shell_t *shp = (Shell_t*)sh_context;
register int fd;
register History_t *hp;
register char *histname;
@ -209,7 +207,7 @@ int sh_histinit(void *sh_context)
register char *cp;
register off_t hsize = 0;
if(shgd->hist_ptr=hist_ptr)
if(sh.hist_ptr=hist_ptr)
return(1);
if(!(histname = nv_getval(HISTFILE)))
{
@ -222,7 +220,7 @@ int sh_histinit(void *sh_context)
histname = stakptr(offset);
}
retry:
cp = path_relative(shp,histname);
cp = path_relative(histname);
if(!histinit)
histmode = S_IRUSR|S_IWUSR;
if((fd=open(cp,O_BINARY|O_APPEND|O_RDWR|O_CREAT|O_cloexec,histmode))>=0)
@ -250,7 +248,7 @@ retry:
if(fd < 0)
{
/* don't allow root a history_file in /tmp */
if(shgd->userid)
if(sh.userid)
{
if(!(fname = pathtmp(NIL(char*),0,0,NIL(int*))))
return(0);
@ -267,8 +265,7 @@ retry:
maxlines = HIST_DFLT;
for(histmask=16;histmask <= maxlines; histmask <<=1 );
hp = new_of(History_t,(--histmask)*sizeof(off_t));
shgd->hist_ptr = hist_ptr = hp;
hp->histshell = (void*)shp;
sh.hist_ptr = hist_ptr = hp;
hp->histsize = maxlines;
hp->histmask = histmask;
hp->histfp= sfnew(NIL(Sfio_t*),hp->histbuff,HIST_BSIZE,fd,SF_READ|SF_WRITE|SF_APPENDWR|SF_SHARE);
@ -319,7 +316,7 @@ retry:
if(hist_clean(fd) && hist_start>1 && hsize > HIST_MAX)
{
#ifdef DEBUG
sfprintf(sfstderr,"%d: hist_trim hsize=%d\n",shgd->current_pid,hsize);
sfprintf(sfstderr,"%d: hist_trim hsize=%d\n",sh.current_pid,hsize);
sfsync(sfstderr);
#endif /* DEBUG */
hp = hist_trim(hp,(int)hp->histind-maxlines);
@ -375,7 +372,7 @@ void hist_close(register History_t *hp)
#endif /* SHOPT_AUDIT */
free((char*)hp);
hist_ptr = 0;
shgd->hist_ptr = 0;
sh.hist_ptr = 0;
#if SHOPT_ACCTFILE
if(acctfd)
{
@ -450,7 +447,7 @@ static History_t* hist_trim(History_t *hp, int n)
histinit = 1;
histmode = statb.st_mode;
}
if(!sh_histinit(hp->histshell))
if(!sh_histinit())
{
/* use the old history file */
return hist_ptr = hist_old;
@ -722,7 +719,7 @@ void hist_flush(register History_t *hp)
if(sfsync(hp->histfp)<0)
{
hist_close(hp);
if(!sh_histinit(hp->histshell))
if(!sh_histinit())
sh_offoption(SH_HISTORY);
}
hp->histflush = 0;
@ -772,7 +769,9 @@ static ssize_t hist_write(Sfio_t *iop,const void *buff,register size_t insize,Sf
if(hp->auditfp)
{
time_t t=time((time_t*)0);
sfprintf(hp->auditfp,"%u;%lu;%s;%*s%c",sh_isoption(SH_PRIVILEGED)?shgd->euserid:shgd->userid,(unsigned long)t,hp->tty,size,buff,0);
sfprintf(hp->auditfp, "%u;%lu;%s;%*s%c",
sh_isoption(SH_PRIVILEGED) ? sh.euserid : sh.userid,
(unsigned long)t, hp->tty, size, buff, 0);
sfsync(hp->auditfp);
}
#endif /* SHOPT_AUDIT */
@ -933,7 +932,7 @@ Histloc_t hist_find(register History_t*hp,char *string,register int index1,int f
return(location);
}
/* allow a search to be aborted */
if(((Shell_t*)hp->histshell)->trapnote&SH_SIGSET)
if(sh.trapnote & SH_SIGSET)
break;
}
return(location);
@ -989,7 +988,7 @@ int hist_match(register History_t *hp,off_t offset,char *string,int *coffset)
int hist_copy(char *s1,int size,int command,int line)
{
register int c;
register History_t *hp = shgd->hist_ptr;
register History_t *hp = sh.hist_ptr;
register int count = 0;
register char *s1max = s1+size;
if(!hp)

View file

@ -217,7 +217,7 @@ int ed_viread(void *context, int fd, register char *shbuf, int nchar, int reedit
#if SHOPT_RAWONLY
# define viraw 1
#else
int viraw = (sh_isoption(SH_VIRAW) || ed->sh->st.trap[SH_KEYTRAP]);
int viraw = (sh_isoption(SH_VIRAW) || sh.st.trap[SH_KEYTRAP]);
# ifndef FIORDCHK
clock_t oldtime, newtime;
struct tms dummy;
@ -252,7 +252,7 @@ int ed_viread(void *context, int fd, register char *shbuf, int nchar, int reedit
oldtime = times(&dummy);
#endif /* FIORDCHK */
/* abort of interrupt has occurred */
if(ed->sh->trapnote&SH_SIGSET)
if(sh.trapnote&SH_SIGSET)
i = -1;
else
{
@ -1529,7 +1529,7 @@ static void getline(register Vi_t* vp,register int mode)
mode != SEARCH &&
last_virt >= 0 &&
(vp->ed->e_tabcount || !isblank(cur_virt)) &&
vp->ed->sh->nextprompt)
sh.nextprompt)
{
if(virtual[cur_virt]=='\\')
{
@ -2302,7 +2302,7 @@ static int search(register Vi_t* vp,register int mode)
i = INVALID;
if( new_direction==1 && curhline >= histmax )
curhline = histmin + 1;
location = hist_find(shgd->hist_ptr,((char*)virtual)+1, curhline, 1, new_direction);
location = hist_find(sh.hist_ptr,((char*)virtual)+1, curhline, 1, new_direction);
}
cur_virt = i;
strncpy(lsearch, ((char*)virtual)+1, SEARCHSIZE-1);