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

@ -69,6 +69,7 @@ local_iswblank(wchar_t wc)
#define poplevel(lp) (lp->lexd.lastc=lp->lexd.lex_match[--lp->lexd.level])
static char *fmttoken(Lex_t*, int);
static struct argnod *endword(int);
static int alias_exceptf(Sfio_t*, int, void*, Sfdisc_t*);
static void setupalias(Lex_t*,const char*, Namval_t*);
static int comsub(Lex_t*,int);
@ -81,8 +82,6 @@ static const Sfdisc_t alias_disc = { NULL, NULL, NULL, alias_exceptf, NULL };
static void refvar(Lex_t *lp, int type)
{
register Shell_t *shp = lp->sh;
register Stk_t *stkp = shp->stk;
off_t off = (fcseek(0)-(type+1))-(lp->lexd.first?lp->lexd.first:fcfirst());
unsigned long r;
if(lp->lexd.first)
@ -92,16 +91,16 @@ static void refvar(Lex_t *lp, int type)
}
else
{
int n,offset = stktell(stkp);
int n,offset = stktell(sh.stk);
char *savptr,*begin;
off = offset + (fcseek(0)-(type+1)) - fcfirst();
if(lp->lexd.kiaoff < offset)
{
/* variable starts on stak, copy remainder */
if(off>offset)
sfwrite(stkp,fcfirst()+type,off-offset);
n = stktell(stkp)-lp->lexd.kiaoff;
begin = stkptr(stkp,lp->lexd.kiaoff);
sfwrite(sh.stk,fcfirst()+type,off-offset);
n = stktell(sh.stk)-lp->lexd.kiaoff;
begin = stkptr(sh.stk,lp->lexd.kiaoff);
}
else
{
@ -109,11 +108,11 @@ static void refvar(Lex_t *lp, int type)
begin = fcfirst()+(type+lp->lexd.kiaoff-offset);
n = off-lp->lexd.kiaoff;
}
savptr = stkfreeze(stkp,0);
savptr = stkfreeze(sh.stk,0);
r=kiaentity(lp,begin,n,'v',-1,-1,lp->current,'v',0,"");
stkset(stkp,savptr,offset);
stkset(sh.stk,savptr,offset);
}
sfprintf(lp->kiatmp,"p;%..64d;v;%..64d;%d;%d;r;\n",lp->current,r,shp->inlineno,shp->inlineno);
sfprintf(lp->kiatmp,"p;%..64d;v;%..64d;%d;%d;r;\n",lp->current,r,sh.inlineno,sh.inlineno);
}
#endif /* SHOPT_KIA */
@ -124,14 +123,12 @@ static void refvar(Lex_t *lp, int type)
static void lex_advance(Sfio_t *iop, const char *buff, register int size, void *context)
{
register Lex_t *lp = (Lex_t*)context;
register Shell_t *shp = lp->sh;
register Sfio_t *log= shp->funlog;
Stk_t *stkp = shp->stk;
register Sfio_t *log= sh.funlog;
/* write to history file and to stderr if necessary */
if(iop && !sfstacked(iop))
{
if(sh_isstate(SH_HISTORY) && shp->gd->hist_ptr)
log = shp->gd->hist_ptr->histfp;
if(sh_isstate(SH_HISTORY) && sh.hist_ptr)
log = sh.hist_ptr->histfp;
sfwrite(log, (void*)buff, size);
if(sh_isstate(SH_VERBOSE))
sfwrite(sfstderr, buff, size);
@ -141,7 +138,7 @@ static void lex_advance(Sfio_t *iop, const char *buff, register int size, void *
if(lp->lexd.dolparen && lp->lexd.docword && lp->lexd.docend)
{
int n = size - (lp->lexd.docend-(char*)buff);
sfwrite(shp->strbuf,lp->lexd.docend,n);
sfwrite(sh.strbuf,lp->lexd.docend,n);
lp->lexd.docextra += n;
if(sffileno(iop)>=0)
lp->lexd.docend = sfsetbuf(iop,(void*)iop,0);
@ -153,14 +150,14 @@ static void lex_advance(Sfio_t *iop, const char *buff, register int size, void *
size -= (lp->lexd.first-(char*)buff);
buff = lp->lexd.first;
if(!lp->lexd.noarg)
lp->arg = (struct argnod*)stkseek(stkp,ARGVAL);
lp->arg = (struct argnod*)stkseek(sh.stk,ARGVAL);
#if SHOPT_KIA
lp->lexd.kiaoff += ARGVAL;
#endif /* SHOPT_KIA */
}
if(size>0 && (lp->arg||lp->lexd.noarg))
{
sfwrite(stkp,buff,size);
sfwrite(sh.stk,buff,size);
lp->lexd.first = 0;
}
}
@ -201,13 +198,10 @@ static int lexfill(Lex_t *lp)
/*
* mode=1 for reinitialization
*/
Lex_t *sh_lexopen(Lex_t *lp, Shell_t *sp, int mode)
Lex_t *sh_lexopen(Lex_t *lp, int mode)
{
if(!lp)
{
lp = (Lex_t*)sh_newof(0,Lex_t,1,0);
lp->sh = sp;
}
fcnotify(lex_advance,lp);
lp->lex.intest = lp->lex.incase = lp->lex.skipword = lp->lexd.warn = 0;
lp->comp_assign = 0;
@ -230,7 +224,6 @@ Lex_t *sh_lexopen(Lex_t *lp, Shell_t *sp, int mode)
extern int lextoken(Lex_t*);
int sh_lex(Lex_t *lp)
{
Shell_t *shp = lp->sh;
register int flag;
char *quoted, *macro, *split, *expand;
register int tok = lextoken(lp);
@ -244,7 +237,7 @@ int sh_lex(Lex_t *lp)
if(flag&ARG_QUOTED)
quoted = "quoted:";
}
sfprintf(sfstderr,"%d: line %d: %o:%s%s%s%s %s\n",shgd->current_pid,shp->inlineno,tok,quoted,
sfprintf(sfstderr,"%d: line %d: %o:%s%s%s%s %s\n",sh.current_pid,sh.inlineno,tok,quoted,
macro, split, expand, fmttoken(lp,tok));
return(tok);
}
@ -258,10 +251,8 @@ int sh_lex(Lex_t *lp)
*/
int sh_lex(Lex_t* lp)
{
register Shell_t *shp = lp->sh;
register const char *state;
register int n, c, mode=ST_BEGIN, wordflags=0;
Stk_t *stkp = shp->stk;
int inlevel=lp->lexd.level, assignment=0, ingrave=0;
int epatchar=0;
#if SHOPT_MULTIBYTE
@ -316,7 +307,7 @@ int sh_lex(Lex_t* lp)
else
lp->lexd.first = 0;
}
lp->lastline = lp->sh->inlineno;
lp->lastline = sh.inlineno;
while(1)
{
/* skip over characters in the current state */
@ -342,11 +333,11 @@ int sh_lex(Lex_t* lp)
/* check for zero byte in file */
if(n==0 && fcfile())
{
if(shp->readscript)
if(sh.readscript)
{
char *cp = error_info.id;
errno = ENOEXEC;
error_info.id = shp->readscript;
error_info.id = sh.readscript;
errormsg(SH_DICT,ERROR_system(ERROR_NOEXEC),e_exec,cp);
UNREACHABLE();
}
@ -400,10 +391,10 @@ int sh_lex(Lex_t* lp)
while(fcgetc(c)>0 && c!='\n');
if(c<=0 || lp->heredoc)
{
shp->inlineno++;
sh.inlineno++;
break;
}
while(shp->inlineno++,fcpeek(0)=='\n')
while(sh.inlineno++,fcpeek(0)=='\n')
fcseek(1);
while(state[c=fcpeek(0)]==0)
fcseek(1);
@ -413,7 +404,7 @@ int sh_lex(Lex_t* lp)
if(c<0)
return(lp->token=EOFSYM);
n = S_NLTOK;
shp->inlineno--;
sh.inlineno--;
/* FALLTHROUGH */
case S_NLTOK:
/* check for here-document */
@ -421,7 +412,7 @@ int sh_lex(Lex_t* lp)
{
if(!lp->lexd.dolparen)
lp->lexd.nocopy++;
c = shp->inlineno;
c = sh.inlineno;
if(here_copy(lp,lp->heredoc)<=0 && lp->lasttok)
{
lp->lasttok = IODOCSYM;
@ -439,7 +430,7 @@ int sh_lex(Lex_t* lp)
case S_NL:
/* skip over new-lines */
lp->lex.last_quote = 0;
while(shp->inlineno++,fcget()=='\n');
while(sh.inlineno++,fcget()=='\n');
fcseek(-LEN);
if(n==S_NLTOK)
{
@ -498,7 +489,7 @@ int sh_lex(Lex_t* lp)
if(lp->lex.intest)
return(c);
lp->lexd.nest=1;
lp->lastline = shp->inlineno;
lp->lastline = sh.inlineno;
lp->lexd.lex_state = ST_NESTED;
fcseek(1);
return(sh_lex(lp));
@ -568,7 +559,7 @@ int sh_lex(Lex_t* lp)
else
{
if(lp->lexd.warn && (n=fcpeek(0))!=RPAREN && n!=' ' && n!='\t')
errormsg(SH_DICT,ERROR_warn(0),e_lexspace,shp->inlineno,c,n);
errormsg(SH_DICT,ERROR_warn(0),e_lexspace,sh.inlineno,c,n);
}
}
if(c==LPAREN && lp->comp_assign && !lp->lex.intest && !lp->lex.incase)
@ -596,7 +587,7 @@ int sh_lex(Lex_t* lp)
{
Sfio_t *sp;
struct argnod *ap;
shp->inlineno++;
sh.inlineno++;
/* synchronize */
if(!(sp=fcfile()))
state=fcseek(0);
@ -607,8 +598,8 @@ int sh_lex(Lex_t* lp)
else
fcsopen((char*)state);
/* remove \new-line */
n = stktell(stkp)-c;
stkseek(stkp,n);
n = stktell(sh.stk)-c;
stkseek(sh.stk,n);
lp->arg = ap;
if(n<=ARGVAL)
{
@ -625,7 +616,7 @@ int sh_lex(Lex_t* lp)
endchar(lp)==RBRACE &&
sh_lexstates[ST_DOL][n]==S_DIG
)
errormsg(SH_DICT,ERROR_warn(0),e_lexfuture,shp->inlineno,n);
errormsg(SH_DICT,ERROR_warn(0),e_lexfuture,sh.inlineno,n);
#endif /* STR_MAXIMAL */
break;
case S_NAME:
@ -683,7 +674,7 @@ int sh_lex(Lex_t* lp)
/* skip new-line joining */
if(c=='\\' && fcpeek(0)=='\n')
{
shp->inlineno++;
sh.inlineno++;
fcseek(1);
continue;
}
@ -718,23 +709,23 @@ int sh_lex(Lex_t* lp)
if(oldmode(lp)==ST_QUOTE) /* $' within "" or `` */
{
if(lp->lexd.warn)
errormsg(SH_DICT,ERROR_warn(0),e_lexslash,shp->inlineno);
errormsg(SH_DICT,ERROR_warn(0),e_lexslash,sh.inlineno);
mode = ST_LIT;
}
}
if(mode!=ST_LIT)
{
if(lp->lexd.warn && lp->lex.last_quote && shp->inlineno > lp->lastline && fcpeek(-2)!='$')
if(lp->lexd.warn && lp->lex.last_quote && sh.inlineno > lp->lastline && fcpeek(-2)!='$')
errormsg(SH_DICT,ERROR_warn(0),e_lexlongquote,lp->lastline,lp->lex.last_quote);
lp->lex.last_quote = 0;
lp->lastline = shp->inlineno;
lp->lastline = sh.inlineno;
if(mode!=ST_DOL)
pushlevel(lp,'\'',mode);
mode = ST_LIT;
continue;
}
/* check for multi-line single-quoted string */
else if(shp->inlineno > lp->lastline)
else if(sh.inlineno > lp->lastline)
lp->lex.last_quote = '\'';
mode = oldmode(lp);
poplevel(lp);
@ -745,12 +736,12 @@ int sh_lex(Lex_t* lp)
{
fcgetc(n);
if(n=='\n')
shp->inlineno++;
sh.inlineno++;
}
continue;
case S_GRAVE:
if(lp->lexd.warn && (mode!=ST_QUOTE || endchar(lp)!='`'))
errormsg(SH_DICT,ERROR_warn(0),e_lexobsolete1,shp->inlineno);
errormsg(SH_DICT,ERROR_warn(0),e_lexobsolete1,sh.inlineno);
wordflags |=(ARG_MAC|ARG_EXP);
if(mode==ST_QUOTE)
ingrave = !ingrave;
@ -767,10 +758,10 @@ int sh_lex(Lex_t* lp)
{
if(c!='"' || mode!=ST_QNEST)
{
if(lp->lexd.warn && lp->lex.last_quote && shp->inlineno > lp->lastline)
if(lp->lexd.warn && lp->lex.last_quote && sh.inlineno > lp->lastline)
errormsg(SH_DICT,ERROR_warn(0),e_lexlongquote,lp->lastline,lp->lex.last_quote);
lp->lex.last_quote=0;
lp->lastline = shp->inlineno;
lp->lastline = sh.inlineno;
pushlevel(lp,c,mode);
}
ingrave ^= (c=='`');
@ -779,7 +770,7 @@ int sh_lex(Lex_t* lp)
}
else if((n=endchar(lp))==c)
{
if(shp->inlineno > lp->lastline)
if(sh.inlineno > lp->lastline)
lp->lex.last_quote = c;
mode = oldmode(lp);
poplevel(lp);
@ -795,7 +786,7 @@ int sh_lex(Lex_t* lp)
if(lp->lexd.first)
lp->lexd.kiaoff = fcseek(0)-lp->lexd.first;
else
lp->lexd.kiaoff = stktell(stkp)+fcseek(0)-fcfirst();
lp->lexd.kiaoff = stktell(sh.stk)+fcseek(0)-fcfirst();
#endif /* SHOPT_KIA */
pushlevel(lp,'$',mode);
mode = ST_DOL;
@ -826,7 +817,7 @@ int sh_lex(Lex_t* lp)
refvar(lp,0);
#endif /* SHOPT_KIA */
if(lp->lexd.warn && c==LBRACT && !lp->lex.intest && !lp->lexd.arith && oldmode(lp)!= ST_NESTED)
errormsg(SH_DICT,ERROR_warn(0),e_lexusebrace,shp->inlineno);
errormsg(SH_DICT,ERROR_warn(0),e_lexusebrace,sh.inlineno);
fcseek(-LEN);
mode = oldmode(lp);
poplevel(lp);
@ -957,7 +948,7 @@ int sh_lex(Lex_t* lp)
sh_syntax(lp);
}
else if(lp->lexd.warn)
errormsg(SH_DICT,ERROR_warn(0),e_lexquote,shp->inlineno,'%');
errormsg(SH_DICT,ERROR_warn(0),e_lexquote,sh.inlineno,'%');
}
}
}
@ -992,7 +983,7 @@ int sh_lex(Lex_t* lp)
else
{
if(lp->lexd.warn && c!='/' && sh_lexstates[ST_NORM][c]!=S_BREAK && (c!='"' || mode==ST_QUOTE))
errormsg(SH_DICT,ERROR_warn(0),e_lexslash,shp->inlineno);
errormsg(SH_DICT,ERROR_warn(0),e_lexslash,sh.inlineno);
else if(c=='"' && mode!=ST_QUOTE && !ingrave)
wordflags |= ARG_MESSAGE;
fcseek(-LEN);
@ -1000,7 +991,7 @@ int sh_lex(Lex_t* lp)
continue;
case S_META:
if(lp->lexd.warn && endchar(lp)==RBRACE && !lp->lexd.nested_tilde)
errormsg(SH_DICT,ERROR_warn(0),e_lexusequote,shp->inlineno,c);
errormsg(SH_DICT,ERROR_warn(0),e_lexusequote,sh.inlineno,c);
continue;
case S_PUSH:
fcgetc(n);
@ -1045,13 +1036,13 @@ int sh_lex(Lex_t* lp)
if(c==';' && n!=';')
{
if(lp->lexd.warn && n==RBRACE)
errormsg(SH_DICT,ERROR_warn(0),e_lexusequote,shp->inlineno,c);
errormsg(SH_DICT,ERROR_warn(0),e_lexusequote,sh.inlineno,c);
continue;
}
if(mode==ST_QNEST)
{
if(lp->lexd.warn)
errormsg(SH_DICT,ERROR_warn(0),e_lexescape,shp->inlineno,c);
errormsg(SH_DICT,ERROR_warn(0),e_lexescape,sh.inlineno,c);
continue;
}
mode = oldmode(lp);
@ -1075,7 +1066,7 @@ int sh_lex(Lex_t* lp)
/* backward compatibility */
{
if(lp->lexd.warn)
errormsg(SH_DICT,ERROR_warn(0),e_lexnested,shp->inlineno);
errormsg(SH_DICT,ERROR_warn(0),e_lexnested,sh.inlineno);
if(!(state=lp->lexd.first))
state = fcfirst();
else
@ -1135,7 +1126,7 @@ int sh_lex(Lex_t* lp)
{
if(mode==ST_NAME)
{
errormsg(SH_DICT,ERROR_exit(SYNBAD),e_lexsyntax1, shp->inlineno, "[]", "empty subscript");
errormsg(SH_DICT,ERROR_exit(SYNBAD),e_lexsyntax1, sh.inlineno, "[]", "empty subscript");
UNREACHABLE();
}
if(!epatchar || epatchar=='%')
@ -1224,7 +1215,7 @@ int sh_lex(Lex_t* lp)
continue;
}
if(lp->lexd.warn && c=='[' && n=='^')
errormsg(SH_DICT,ERROR_warn(0),e_lexcharclass,shp->inlineno);
errormsg(SH_DICT,ERROR_warn(0),e_lexcharclass,sh.inlineno);
if(n>0)
fcseek(-LEN);
if(n=='=' && c=='+' && mode==ST_NAME)
@ -1251,13 +1242,13 @@ breakloop:
state = fcfirst();
n = fcseek(0)-(char*)state;
if(!lp->arg)
lp->arg = (struct argnod*)stkseek(stkp,ARGVAL);
lp->arg = (struct argnod*)stkseek(sh.stk,ARGVAL);
if(n>0)
sfwrite(stkp,state,n);
sfputc(stkp,0);
stkseek(stkp,stktell(stkp)-1);
state = stkptr(stkp,ARGVAL);
n = stktell(stkp)-ARGVAL;
sfwrite(sh.stk,state,n);
sfputc(sh.stk,0);
stkseek(sh.stk,stktell(sh.stk)-1);
state = stkptr(sh.stk,ARGVAL);
n = stktell(sh.stk)-ARGVAL;
lp->lexd.first=0;
if(n==1)
{
@ -1284,8 +1275,8 @@ breakloop:
if(!strchr(state,','))
{
/* Redirection of the form {varname}>file, etc. */
stkseek(stkp,stktell(stkp)-1);
lp->arg = (struct argnod*)stkfreeze(stkp,1);
stkseek(sh.stk,stktell(sh.stk)-1);
lp->arg = (struct argnod*)stkfreeze(sh.stk,1);
return(lp->token=IOVNAME);
}
c = wordflags;
@ -1294,8 +1285,8 @@ breakloop:
c = wordflags;
if(assignment<0)
{
stkseek(stkp,stktell(stkp)-1);
lp->arg = (struct argnod*)stkfreeze(stkp,1);
stkseek(sh.stk,stktell(sh.stk)-1);
lp->arg = (struct argnod*)stkfreeze(sh.stk,1);
lp->lex.reservok = 1;
return(lp->token=LABLSYM);
}
@ -1306,23 +1297,23 @@ breakloop:
if(mode==ST_NONE)
{
/* eliminate trailing )) */
stkseek(stkp,stktell(stkp)-2);
stkseek(sh.stk,stktell(sh.stk)-2);
}
if(c&ARG_MESSAGE)
{
if(sh_isoption(SH_DICTIONARY))
lp->arg = sh_endword(shp,2);
lp->arg = endword(2);
c |= ARG_MAC;
}
if(c==0 || (c&(ARG_MAC|ARG_EXP|ARG_MESSAGE)))
{
lp->arg = (struct argnod*)stkfreeze(stkp,1);
lp->arg = (struct argnod*)stkfreeze(sh.stk,1);
lp->arg->argflag = (c?c:ARG_RAW);
}
else if(mode==ST_NONE)
lp->arg = sh_endword(shp,-1);
lp->arg = endword(-1);
else
lp->arg = sh_endword(shp,0);
lp->arg = endword(0);
state = lp->arg->argval;
lp->comp_assign = assignment;
if(assignment)
@ -1332,7 +1323,7 @@ breakloop:
{
char *cp = strchr(state, '=');
if(cp && strncmp(++cp, "$((", 3) == 0)
errormsg(SH_DICT, ERROR_warn(0), e_lexarithwarn, shp->inlineno,
errormsg(SH_DICT, ERROR_warn(0), e_lexarithwarn, sh.inlineno,
state, cp - state, state, cp + 3);
}
}
@ -1351,7 +1342,7 @@ breakloop:
strchr(test_opchars,state[1]))
{
if(lp->lexd.warn && state[1]=='a')
errormsg(SH_DICT,ERROR_warn(0),e_lexobsolete2,shp->inlineno);
errormsg(SH_DICT,ERROR_warn(0),e_lexobsolete2,sh.inlineno);
lp->digits = state[1];
lp->token = TESTUNOP;
}
@ -1381,7 +1372,7 @@ breakloop:
{
case TEST_SEQ:
if(lp->lexd.warn && state[1]==0)
errormsg(SH_DICT,ERROR_warn(0),e_lexobsolete3,shp->inlineno);
errormsg(SH_DICT,ERROR_warn(0),e_lexobsolete3,sh.inlineno);
/* FALLTHROUGH */
default:
if(lp->lex.testop2)
@ -1418,7 +1409,7 @@ breakloop:
break;
}
errormsg(SH_DICT, ERROR_warn(0), e_lexobsolete4,
shp->inlineno, state, alt);
sh.inlineno, state, alt);
}
if(c&TEST_STRCMP)
lp->lex.incase = 1;
@ -1442,7 +1433,7 @@ breakloop:
if(n==1 && (c=='{' || c=='}' || c=='!'))
{
if(lp->lexd.warn && c=='{' && lp->lex.incase==2)
errormsg(SH_DICT,ERROR_warn(0),e_lexobsolete6,shp->inlineno);
errormsg(SH_DICT,ERROR_warn(0),e_lexobsolete6,sh.inlineno);
if(lp->lex.incase==1 && c==RBRACE)
lp->lex.incase = 0;
return(lp->token=c);
@ -1494,7 +1485,7 @@ breakloop:
/* check for aliases */
Namval_t* np;
if(!lp->lex.incase && !assignment && fcpeek(0)!=LPAREN &&
(np=nv_search(state,shp->alias_tree,HASH_SCOPE))
(np=nv_search(state,sh.alias_tree,HASH_SCOPE))
&& !nv_isattr(np,NV_NOEXPAND)
&& (lp->aliasok!=2 || nv_isattr(np,BLT_DCL))
&& (!sh_isstate(SH_NOALIAS) || nv_isattr(np,NV_NOFREE))
@ -1520,14 +1511,14 @@ breakloop:
static int comsub(register Lex_t *lp, int endtok)
{
register int n,c,count=1;
register int line=lp->sh->inlineno;
register int line=sh.inlineno;
struct ionod *inheredoc = lp->heredoc;
char *first,*cp=fcseek(0),word[5];
int off, messages=0, assignok=lp->assignok, csub;
struct _shlex_pvt_lexstate_ save;
save = lp->lex;
csub = lp->comsub;
sh_lexopen(lp,lp->sh,1);
sh_lexopen(lp,1);
lp->lexd.dolparen++;
lp->lex.incase=0;
pushlevel(lp,0,0);
@ -1659,7 +1650,7 @@ done:
if(lp->heredoc && !inheredoc)
{
/* here-document isn't fully contained in command substitution */
errormsg(SH_DICT,ERROR_exit(SYNBAD),e_lexsyntax5,lp->sh->inlineno,lp->heredoc->ioname);
errormsg(SH_DICT,ERROR_exit(SYNBAD),e_lexsyntax5,sh.inlineno,lp->heredoc->ioname);
UNREACHABLE();
}
return(messages);
@ -1674,23 +1665,22 @@ static void nested_here(register Lex_t *lp)
register struct ionod *iop;
register int n=0,offset;
struct argnod *arg = lp->arg;
Stk_t *stkp = lp->sh->stk;
char *base;
if(offset=stktell(stkp))
base = stkfreeze(stkp,0);
if(offset=stktell(sh.stk))
base = stkfreeze(sh.stk,0);
if(lp->lexd.docend)
n = fcseek(0)-lp->lexd.docend;
iop = sh_newof(0,struct ionod,1,lp->lexd.docextra+n+ARGVAL);
iop->iolst = lp->heredoc;
stkseek(stkp,ARGVAL);
stkseek(sh.stk,ARGVAL);
if(lp->lexd.docextra)
{
sfseek(lp->sh->strbuf,(Sfoff_t)0, SEEK_SET);
sfmove(lp->sh->strbuf,stkp,lp->lexd.docextra,-1);
sfseek(lp->sh->strbuf,(Sfoff_t)0, SEEK_SET);
sfseek(sh.strbuf,(Sfoff_t)0, SEEK_SET);
sfmove(sh.strbuf,sh.stk,lp->lexd.docextra,-1);
sfseek(sh.strbuf,(Sfoff_t)0, SEEK_SET);
}
sfwrite(stkp,lp->lexd.docend,n);
lp->arg = sh_endword(lp->sh,0);
sfwrite(sh.stk,lp->lexd.docend,n);
lp->arg = endword(0);
iop->ioname = (char*)(iop+1);
strcpy(iop->ioname,lp->arg->argval);
iop->iofile = (IODOC|IORAW);
@ -1700,9 +1690,9 @@ static void nested_here(register Lex_t *lp)
lp->arg = arg;
lp->lexd.docword = 0;
if(offset)
stkset(stkp,base,offset);
stkset(sh.stk,base,offset);
else
stkseek(stkp,0);
stkseek(sh.stk,0);
}
/*
@ -1728,7 +1718,7 @@ void sh_lexskip(Lex_t *lp,int close, register int copy, int state)
if(!(cp=lp->lexd.first))
cp = fcfirst();
if((copy = fcseek(0)-cp) > 0)
sfwrite(lp->sh->stk,cp,copy);
sfwrite(sh.stk,cp,copy);
}
else
lp->lexd.nocopy--;
@ -1769,13 +1759,13 @@ static int here_copy(Lex_t *lp,register struct ionod *iop)
register const char *state;
register int c,n;
register char *bufp,*cp;
register Sfio_t *sp=lp->sh->heredocs, *funlog;
register Sfio_t *sp=sh.heredocs, *funlog;
int stripcol=0,stripflg, nsave, special=0;
if(funlog=lp->sh->funlog)
if(funlog=sh.funlog)
{
if(fcfill()>0)
fcseek(-LEN);
lp->sh->funlog = 0;
sh.funlog = 0;
}
if(iop->iolst)
here_copy(lp,iop->iolst);
@ -1881,7 +1871,7 @@ static int here_copy(Lex_t *lp,register struct ionod *iop)
switch(n)
{
case S_NL:
lp->sh->inlineno++;
sh.inlineno++;
if((stripcol && c==' ') || (stripflg && c=='\t'))
{
if(!lp->lexd.dolparen)
@ -1942,7 +1932,7 @@ static int here_copy(Lex_t *lp,register struct ionod *iop)
}
#endif /* SHOPT_CRNL */
if(c==NL)
lp->sh->inlineno++;
sh.inlineno++;
if(iop->iodelim[n]==0 && (c==NL||c==RPAREN))
{
if(!lp->lexd.dolparen && (n=cp-bufp))
@ -1950,7 +1940,7 @@ static int here_copy(Lex_t *lp,register struct ionod *iop)
if((n=sfwrite(sp,bufp,n))>0)
iop->iosize += n;
}
lp->sh->inlineno--;
sh.inlineno--;
if(c==RPAREN)
fcseek(-LEN);
goto done;
@ -1995,7 +1985,7 @@ static int here_copy(Lex_t *lp,register struct ionod *iop)
if(c==NL)
{
/* new-line joining */
lp->sh->inlineno++;
sh.inlineno++;
if(!lp->lexd.dolparen && (n=(fcseek(0)-bufp)-n)>=0)
{
if(n && (n=sfwrite(sp,bufp,n))>0)
@ -2016,7 +2006,7 @@ static int here_copy(Lex_t *lp,register struct ionod *iop)
n=0;
}
done:
lp->sh->funlog = funlog;
sh.funlog = funlog;
if(lp->lexd.dolparen)
free((void*)iop);
else if(!special)
@ -2088,7 +2078,6 @@ static char *fmttoken(Lex_t *lp, register int sym)
noreturn void sh_syntax(Lex_t *lp)
{
register Shell_t *shp = lp->sh;
register const char *cp = sh_translate(e_unexpected);
register char *tokstr;
register int tok = lp->token;
@ -2099,9 +2088,9 @@ noreturn void sh_syntax(Lex_t *lp)
cp = sh_translate(e_unmatched);
}
else
lp->lastline = shp->inlineno;
lp->lastline = sh.inlineno;
tokstr = fmttoken(lp,tok);
if((sp=fcfile()) || (shp->infd>=0 && (sp=shp->sftable[shp->infd])))
if((sp=fcfile()) || (sh.infd>=0 && (sp=sh.sftable[sh.infd])))
{
/* clear out any pending input */
register Sfio_t *top;
@ -2112,10 +2101,10 @@ noreturn void sh_syntax(Lex_t *lp)
}
else
fcclose();
shp->inlineno = lp->inlineno;
shp->st.firstline = lp->firstline;
sh.inlineno = lp->inlineno;
sh.st.firstline = lp->firstline;
/* reset lexer state */
sh_lexopen(lp, &sh, 0);
sh_lexopen(lp, 0);
if(!sh_isstate(SH_INTERACTIVE) && !sh_isstate(SH_PROFILE))
errormsg(SH_DICT,ERROR_exit(SYNBAD),e_lexsyntax1,lp->lastline,tokstr,cp);
else
@ -2123,15 +2112,15 @@ noreturn void sh_syntax(Lex_t *lp)
UNREACHABLE();
}
static char *stack_shift(Stk_t *stkp, register char *sp,char *dp)
static char *stack_shift(register char *sp,char *dp)
{
register char *ep;
register int offset = stktell(stkp);
register int left = offset-(sp-stkptr(stkp,0));
register int offset = stktell(sh.stk);
register int left = offset-(sp-stkptr(sh.stk,0));
register int shift = (dp+1-sp);
offset += shift;
stkseek(stkp,offset);
sp = stkptr(stkp,offset);
stkseek(sh.stk,offset);
sp = stkptr(sh.stk,offset);
ep = sp - shift;
while(left--)
*--sp = *--ep;
@ -2146,7 +2135,7 @@ static char *stack_shift(Stk_t *stkp, register char *sp,char *dp)
* The result is left on the stak
* If mode==2, the each $"" string is printed on standard output
*/
struct argnod *sh_endword(Shell_t *shp,int mode)
static struct argnod *endword(int mode)
{
register const char *state = sh_lexstates[ST_NESTED];
register int n;
@ -2155,9 +2144,8 @@ struct argnod *sh_endword(Shell_t *shp,int mode)
struct argnod* argp=0;
char *ep=0, *xp=0;
int bracket=0;
Stk_t *stkp=shp->stk;
sfputc(stkp,0);
sp = stkptr(stkp,ARGVAL);
sfputc(sh.stk,0);
sp = stkptr(sh.stk,ARGVAL);
if(mbwide())
{
do
@ -2196,10 +2184,10 @@ struct argnod *sh_endword(Shell_t *shp,int mode)
switch(n)
{
case S_EOF:
stkseek(stkp,dp-stkptr(stkp,0));
stkseek(sh.stk,dp-stkptr(sh.stk,0));
if(mode<=0)
{
argp = (struct argnod*)stkfreeze(stkp,0);
argp = (struct argnod*)stkfreeze(sh.stk,0);
argp->argflag = ARG_RAW|ARG_QUOTED;
}
return(argp);
@ -2243,7 +2231,7 @@ struct argnod *sh_endword(Shell_t *shp,int mode)
dp = ep+n;
if(sp-dp <= 1)
{
sp = stack_shift(stkp,sp,dp);
sp = stack_shift(sp,dp);
dp = sp-1;
ep = dp-n;
}
@ -2292,7 +2280,7 @@ struct argnod *sh_endword(Shell_t *shp,int mode)
{
if(dp>=sp)
{
sp = stack_shift(stkp,sp,dp+1);
sp = stack_shift(sp,dp+1);
dp = sp-2;
}
*dp++ = '\\';
@ -2328,7 +2316,7 @@ struct argnod *sh_endword(Shell_t *shp,int mode)
dp[-1] = '\\';
if(dp>=sp)
{
sp = stack_shift(stkp,sp,dp);
sp = stack_shift(sp,dp);
dp = sp-1;
}
*dp++ = ']';
@ -2344,7 +2332,7 @@ struct argnod *sh_endword(Shell_t *shp,int mode)
dp[-1] = '\\';
if(dp>=sp)
{
sp = stack_shift(stkp,sp,dp);
sp = stack_shift(sp,dp);
dp = sp-1;
}
*dp++ = '[';
@ -2455,7 +2443,7 @@ static void setupalias(Lex_t *lp, const char *string,Namval_t *np)
{
unsigned long r;
r=kiaentity(lp,nv_name(np),-1,'p',0,0,lp->current,'a',0,"");
sfprintf(lp->kiatmp,"p;%..64d;p;%..64d;%d;%d;e;\n",lp->current,r,lp->sh->inlineno,lp->sh->inlineno);
sfprintf(lp->kiatmp,"p;%..64d;p;%..64d;%d;%d;e;\n",lp->current,r,sh.inlineno,sh.inlineno);
}
#endif /* SHOPT_KIA */
if((ap->nextc=fcget())==0)