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

Fix more compiler warnings, typos and other minor issues (#260)

Many of these changes are minor typo fixes. The other changes
(which are mostly compiler warning fixes) are:

NEWS:
- The --globcasedetect shell option works on older Linux kernels
  when used with FAT32/VFAT file systems, so remove the note about
  it only working with 5.2+ kernels.

src/cmd/ksh93/COMPATIBILITY:
- Update the documentation on function scoping with an addition
  from ksh93v- (this does apply to ksh93u+).

src/cmd/ksh93/edit/emacs.c:
- Check for '_AST_ksh_release', not 'AST_ksh_release'.

src/cmd/INIT/mamake.c,
src/cmd/INIT/ratz.c,
src/cmd/INIT/release.c,
src/cmd/builtin/pty.c:
- Add more uses of UNREACHABLE() and noreturn, this time for the
  build system and pty.

src/cmd/builtin/pty.c,
src/cmd/builtin/array.c,
src/cmd/ksh93/sh/name.c,
src/cmd/ksh93/sh/nvtype.c,
src/cmd/ksh93/sh/suid_exec.c:
- Fix six -Wunused-variable warnings (the name.c nv_arrayptr()
  fixes are also in ksh93v-).
- Remove the unused 'tableval' function to fix a -Wunused-function
  warning.

src/cmd/ksh93/sh/lex.c:
- Remove unused 'SHOPT_DOS' code, which isn't enabled anywhere.
  https://github.com/att/ast/issues/272#issuecomment-354363112

src/cmd/ksh93/bltins/misc.c,
src/cmd/ksh93/bltins/trap.c,
src/cmd/ksh93/bltins/typeset.c:
- Add dictionary generator function declarations for former
  aliases that are now builtins (re: 1fbbeaa1, ef1621c1, 3ba4900e).
- For consistency with the rest of the codebase, use '(void)'
  instead of '()' for print_cpu_times.

src/cmd/ksh93/sh/init.c,
src/lib/libast/path/pathshell.c:
- Move the otherwise unused EXE macro to pathshell() and only
  search for 'sh.exe' on Windows.

src/cmd/ksh93/sh/xec.c,
src/lib/libast/include/ast.h:
- Add an empty definition for inline when compiling with C89.
  This allows the timeval_to_double() function to be inlined.

src/cmd/ksh93/include/shlex.h:
- Remove the unused 'PIPESYM2' macro.

src/cmd/ksh93/tests/pty.sh:
- Add '# err_exit #' to count the regression test added in
  commit 113a9392.

src/lib/libast/disc/sfdcdio.c:
- Move diordwr, dioread, diowrite and dioexcept behind
  '#ifdef F_DIOINFO' to fix one -Wunused-variable warning and
  multiple -Wunused-function warnings (sfdcdio() only uses these
  functions when F_DIOINFO is defined).

src/lib/libast/string/fmtdev.c:
- Fix two -Wimplicit-function-declaration warnings on Linux by
  including sys/sysmacros.h in fmtdev().
This commit is contained in:
Johnothan King 2021-04-08 11:58:07 -07:00 committed by GitHub
parent ecf260c282
commit a065558291
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
96 changed files with 299 additions and 282 deletions

View file

@ -768,7 +768,7 @@ struct argnod *sh_argprocsub(Shell_t *shp,struct argnod *argp)
sh_offstate(SH_INTERACTIVE);
sh_offstate(SH_MONITOR);
job.jobcontrol = 0;
/* do the process substitution */
/* run the process substitution */
shp->subshell = 0;
if(fd)
shp->inpipe = pv;

View file

@ -871,13 +871,8 @@ static struct index_array *array_grow(Namval_t *np, register struct index_array
}
}
else
if((ap->val[0].cp=np->nvalue.cp))
if((ap->val[0].cp=np->nvalue.cp) || (nv_isattr(np,NV_INTEGER) && !nv_isnull(np)))
i++;
else if(nv_isattr(np,NV_INTEGER) && !nv_isnull(np))
{
Sfdouble_t d= nv_getnum(np);
i++;
}
ap->header.nelem = i;
ap->header.hdr.disc = &array_disc;
nv_disc(np,(Namfun_t*)ap, NV_FIRST);
@ -1525,7 +1520,7 @@ char *nv_endsubscript(Namval_t *np, register char *cp, int mode)
{
Namarr_t *ap = nv_arrayptr(np);
/* Block an attempt to alter a readonly array via subscript assignment or by appending the array.
However need to allow instances of type variables. This exception is observed when np->nvflag
However instances of type variables must be allowed. This exception is observed when np->nvflag
has NV_BINARY and NV_LJUST set besides NV_RDONLY and NV_ARRAY. */
if(nv_isattr(np,NV_RDONLY) && nv_isattr(np,NV_ARRAY) && mode&NV_ASSIGN && np->nvflag&(NV_BINARY|NV_LJUST)^(NV_BINARY|NV_LJUST))
{

View file

@ -20,7 +20,7 @@
/*
* Ksh - AT&T Labs
* Written by David Korn
* This file defines all the read/write shell global variables
* This file defines all the read/write shell global variables
*/
#include "defs.h"

View file

@ -578,7 +578,7 @@ void sh_exit(register int xno)
shp->prefix = 0;
#if SHOPT_TYPEDEF
shp->mktype = 0;
#endif /* SHOPT_TYPEDEF*/
#endif /* SHOPT_TYPEDEF */
if(job.in_critical)
job_unlock();
if(pp->mode == SH_JMPSCRIPT && !pp->prev)

View file

@ -210,13 +210,6 @@ static char *env_init(Shell_t*);
static void env_import_attributes(Shell_t*,char*);
static Init_t *nv_init(Shell_t*);
static int shlvl;
#ifdef _WINIX
# define EXE "?(.exe)"
#else
# define EXE
#endif
static int rand_shift;
/*
@ -284,7 +277,7 @@ static void put_ed(register Namval_t* np,const char *val,int flags,Namfun_t *fp)
goto done;
if(!(cp=val) && (*name=='E' || !(cp=nv_getval(sh_scoped(shp,EDITNOD)))))
goto done;
/* turn on vi or emacs option if editor name is either*/
/* turn on vi or emacs option if editor name is either */
cp = path_basename(cp);
#if SHOPT_VSH
if(strmatch(cp,"*[Vv][Ii]*"))
@ -1970,7 +1963,7 @@ static void env_import_attributes(Shell_t *shp, char *next)
int size = *(unsigned char*)(cp+1)-' ';
if((flag&NV_INTEGER) && size==0)
{
/* check for floating*/
/* check for floating */
char *dp, *val = nv_getval(np);
strtol(val,&dp,10);
if(*dp=='.' || *dp=='e' || *dp=='E')

View file

@ -436,7 +436,7 @@ int job_reap(register int sig)
#ifdef DEBUG
sfprintf(sfstderr,"ksh: job line %4d: reap pid=%d critical=%d job %d with pid %d flags=%o complete with status=%x exit=%d\n",__LINE__,shgd->current_pid,job.in_critical,pw->p_job,pid,pw->p_flag,wstat,pw->p_exit);
sfsync(sfstderr);
#endif /* DEBUG*/
#endif /* DEBUG */
/* only top-level process in job should have notify set */
if(px && pw != px)
pw->p_flag &= ~P_NOTIFY;
@ -1461,7 +1461,7 @@ int job_wait(register pid_t pid)
sfprintf(sfstderr,"ksh: job line %4d: wait pid=%d critical=%d job=%d pid=%d\n",__LINE__,shgd->current_pid,job.in_critical,jobid,pid);
if(pw)
sfprintf(sfstderr,"ksh: job line %4d: wait pid=%d critical=%d flags=%o\n",__LINE__,shgd->current_pid,job.in_critical,pw->p_flag);
#endif /* DEBUG*/
#endif /* DEBUG */
errno = 0;
if(shp->coutpipe>=0 && lastpid && shp->cpid==lastpid)
{
@ -1704,7 +1704,7 @@ static void job_unstop(register struct process *px)
/*
* remove a job from table
* If all the processes have not completed, unpost first non-completed process
* If all the processes have not completed, unpost first non-completed process
* Otherwise the job is removed and job_unpost returns NULL.
* pwlist is reset if the first job is removed
* if <notify> is non-zero, then jobs with pending notifications are unposted

View file

@ -19,7 +19,7 @@
***********************************************************************/
#pragma prototyped
/*
* KornShell lexical analyzer
* KornShell lexical analyzer
*
* Written by David Korn
* AT&T Labs
@ -73,7 +73,7 @@ local_iswblank(wchar_t wc)
struct lexstate
{
char incase; /* 1 for case pattern, 2 after case */
char intest; /* 1 inside [[...]] */
char intest; /* 1 inside [[ ... ]] */
char testop1; /* 1 when unary test op legal */
char testop2; /* 1 when binary test op legal */
char reservok; /* >0 for reserved word legal */
@ -758,7 +758,7 @@ int sh_lex(Lex_t* lp)
mode = ST_NORM;
continue;
case S_LIT:
if(oldmode(lp)==ST_NONE && !lp->lexd.noarg) /* in ((...)) */
if(oldmode(lp)==ST_NONE && !lp->lexd.noarg) /* in ((...)) */
{
if((c=fcpeek(0))==LPAREN || c==RPAREN || c=='$' || c==LBRACE || c==RBRACE || c=='[' || c==']')
{
@ -813,7 +813,7 @@ int sh_lex(Lex_t* lp)
ingrave = !ingrave;
/* FALLTHROUGH */
case S_QUOTE:
if(oldmode(lp)==ST_NONE && lp->lexd.arith) /* in ((...)) */
if(oldmode(lp)==ST_NONE && lp->lexd.arith) /* in ((...)) */
{
if(n!=S_GRAVE || fcpeek(0)=='\'')
continue;
@ -2321,10 +2321,6 @@ struct argnod *sh_endword(Shell_t *shp,int mode)
break;
}
n = *sp;
#if SHOPT_DOS
if(!(inquote&1) && sh_lexstates[ST_NORM][n]==0)
break;
#endif /* SHOPT_DOS */
if(!(inquote&1) || (sh_lexstates[ST_QUOTE][n] && n!=RBRACE))
{
if(n=='\n')

View file

@ -53,7 +53,7 @@
#if _WINIX
static int Skip;
#endif /*_WINIX */
#endif /* _WINIX */
static int _c_;
typedef struct _mac_
@ -823,7 +823,7 @@ static void copyto(register Mac_t *mp,int endch, int newquote)
first = cp = fcseek(Skip);
Skip = 0;
}
#endif /*_WINIX */
#endif /* _WINIX */
tilde = -1;
c=0;
}

View file

@ -277,7 +277,7 @@ int sh_main(int ac, char *av[], Shinit_f userinit)
if(((type = sh_type(cp = av[0])) & SH_TYPE_SH) && (name = nv_getval(L_ARGNOD)) && (!((type = sh_type(cp = name)) & SH_TYPE_SH)))
{
av[0] = (type & SH_TYPE_LOGIN) ? cp : path_basename(cp);
/* exec to change $0 for ps */
/* exec to change $0 for ps */
execv(pathshell(),av);
/* exec fails */
shp->st.dolv[0] = av[0];
@ -480,7 +480,7 @@ static void exfile(register Shell_t *shp, register Sfio_t *iop,register int fno)
if(sh_isoption(SH_VERBOSE))
sh_onstate(SH_VERBOSE);
sh_onstate(SH_ERREXIT);
/* -eim flags don't apply to profiles */
/* -eim flags don't apply to profiles */
if(sh_isstate(SH_PROFILE))
{
sh_offstate(SH_INTERACTIVE);

View file

@ -37,7 +37,7 @@
static char *savesub = 0;
static char Null[1];
static Namval_t NullNode;
static Dt_t *Refdict;
static Dt_t *Refdict;
static Dtdisc_t _Refdisc =
{
offsetof(struct Namref,np),sizeof(struct Namval_t*),sizeof(struct Namref)
@ -280,7 +280,7 @@ void nv_setlist(register struct argnod *arg,register int flags, Namval_t *typ)
shtp.rp = 0;
shtp.nodes = (Namval_t**)sh_malloc(shtp.maxnodes*sizeof(Namval_t*));
}
#endif /* SHOPT_TYPEDEF*/
#endif /* SHOPT_TYPEDEF */
#if SHOPT_NAMESPACE
if(shp->namespace && nv_dict(shp->namespace)==shp->var_tree)
flags |= NV_NOSCOPE;
@ -734,9 +734,7 @@ Namval_t *nv_create(const char *name, Dt_t *root, int flags, Namfun_t *dp)
long mode, add=0;
int copy=0,isref,top=0,noscope=(flags&NV_NOSCOPE);
int nofree=0, level=0;
#if SHOPT_FIXEDARRAY
Namarr_t *ap;
#endif /* SHOPT_FIXEDARRAY */
if(root==shp->var_tree)
{
if(dtvnext(root))
@ -944,7 +942,7 @@ Namval_t *nv_create(const char *name, Dt_t *root, int flags, Namfun_t *dp)
{
if(flags&NV_ARRAY)
{
Namarr_t *ap = nv_arrayptr(np);
ap = nv_arrayptr(np);
nq = nv_opensub(np);
if((flags&NV_ASSIGN) && (!nq || nv_isnull(nq)))
ap->nelem++;
@ -1034,7 +1032,7 @@ Namval_t *nv_create(const char *name, Dt_t *root, int flags, Namfun_t *dp)
if(c=='[')
{
#if SHOPT_FIXEDARRAY
Namarr_t *ap = nv_arrayptr(np);
ap = nv_arrayptr(np);
#endif /* SHOPT_FIXEDARRAY */
n = mode|nv_isarray(np);
if(!mode && (flags&NV_ARRAY) && ((c=sp[1])=='*' || c=='@') && sp[2]==']')
@ -2073,7 +2071,7 @@ static void rightjust(char *str, int size, int fill)
* given physical size, return a logical size which reflects the
* screen width of multi-byte characters
* Multi-width characters replaced by spaces if they cross the boundary
* <type> is non-zero for right justified fields
* <type> is non-zero for right justified fields
*/
static int ja_size(char *str,int size,int type)
@ -2604,36 +2602,6 @@ Namval_t *sh_scoped(Shell_t *shp, register Namval_t *np)
return(dtsearch(shp->var_tree,np));
}
/*
* return space separated list of names of variables in given tree
*/
static char *tableval(Dt_t *root)
{
static Sfio_t *out;
register Namval_t *np;
register int first=1;
register Dt_t *base = dtview(root,0);
if(out)
sfseek(out,(Sfoff_t)0,SEEK_SET);
else
out = sfnew((Sfio_t*)0,(char*)0,-1,-1,SF_WRITE|SF_STRING);
for(np=(Namval_t*)dtfirst(root);np;np=(Namval_t*)dtnext(root,np))
{
if(!nv_isnull(np) || np->nvfun || nv_isattr(np,~NV_NOFREE))
{
if(!first)
sfputc(out,' ');
else
first = 0;
sfputr(out,np->nvname,-1);
}
}
sfputc(out,0);
if(base)
dtview(root,base);
return((char*)out->_data);
}
#if SHOPT_OPTIMIZE
struct optimize
{

View file

@ -41,12 +41,12 @@ static const char sh_opttype[] =
"field splitting and pathname expansion are not performed on "
"the arguments. Tilde expansion occurs on \avalue\a.]"
"[r?Enables readonly. Once enabled, the value cannot be changed or unset.]"
"[a]:?[type?Indexed array. Each \aname\a will converted to an indexed "
"[a]:?[type?Indexed array. Each \aname\a is converted to an indexed "
"array of type \b\f?\f\b. If a variable already exists, the current "
"value will become index \b0\b. If \b[\b\atype\a\b]]\b is "
"specified, each subscript is interpreted as a value of enumeration "
"type \atype\a.]"
"[A?Associative array. Each \aname\a will converted to an associative "
"[A?Associative array. Each \aname\a is converted to an associative "
"array of type \b\f?\f\b. If a variable already exists, the current "
"value will become subscript \b0\b.]"
"[h]:[string?Used within a type definition to provide a help string "
@ -666,7 +666,6 @@ static int typeinfo(Opt_t* op, Sfio_t *out, const char *str, Optdisc_t *fp)
nq = nv_namptr(dp->nodes,i);
if(tp=nv_type(nq))
{
Namfun_t *pp = nv_hasdisc(nq,&type_disc);
sfprintf(out,"\t[+%s?%s.\n",nq->nvname,tp->nvname);
n = strlen(nq->nvname);
while((cp=nv_namptr(dp->nodes,i+1)->nvname) && memcmp(cp,nq->nvname,n)==0 && cp[n]=='.')

View file

@ -682,7 +682,7 @@ static Shnode_t *arithfor(Lex_t *lexp,register Shnode_t *tf)
/* remove trailing white space */
while(offset>ARGVAL && ((c= *stkptr(stkp,offset-1)),isspace(c)))
offset--;
/* check for empty initialization expression */
/* check for empty initialization expression */
if(offset==ARGVAL && n==0)
continue;
stkseek(stkp,offset);

View file

@ -1261,7 +1261,7 @@ pid_t path_spawn(Shell_t *shp,const char *opath,register char **argv, char **env
/*
* File is executable but not machine code.
* Assume file is a Shell script and execute it.
* Assume file is a shell script and execute it.
*/
static noreturn void exscript(Shell_t *shp,register char *path,register char *argv[],char **envp)
@ -1285,7 +1285,7 @@ static noreturn void exscript(Shell_t *shp,register char *path,register char *ar
sh_setstate(sh_state(SH_FORKED));
sfsync(sfstderr);
#if SHOPT_SUID_EXEC && !SHOPT_PFSH
/* check if file cannot open for read or script is setuid/setgid */
/* check if file cannot open for read or script is setuid/setgid */
{
static char name[] = "/tmp/euidXXXXXXXXXX";
register int n;

View file

@ -239,7 +239,7 @@ found:
void sh_trim(register char *sp)
/*@
assume sp!=NULL;
promise strlen(in sp) <= in strlen(sp);
promise strlen(in sp) <= in strlen(sp);
@*/
{
register char *dp;

View file

@ -769,7 +769,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_t *t, volatile int flags, int comsub)
sfswap(sp->saveout,sfstdout);
else
sfstdout = &_Sfstdout;
/* check if standard output was preserved */
/* check if standard output was preserved */
if(sp->tmpfd>=0)
{
int err=errno;

View file

@ -30,7 +30,7 @@
*/
/* The file name of the script to execute is argv[0]
* Argv[1] is the program name
* Argv[1] is the program name
* The basic idea is to open the script as standard input, set the effective
* user and group id correctly, and then exec the shell.
* The complicated part is getting the effective uid of the caller and
@ -87,7 +87,9 @@ static const char version[] = "\n@(#)$Id: suid_exec "SH_RELEASE" $\n";
static const char badopen[] = "cannot open";
static const char badexec[] = "cannot exec";
static const char devfd[] = "/dev/fd/10"; /* must match FDIN above */
#ifndef _lib_setreuid
static char tmpname[] = "/tmp/SUIDXXXXXX";
#endif
static char **arglist;
static char *shell;

View file

@ -79,7 +79,7 @@ struct funenv
Namval_t **nref;
};
/* ======== command execution ========*/
/* ======== command execution ======== */
#if !SHOPT_DEVFD
static pid_t fifo_save_ppid;
@ -158,8 +158,7 @@ static void get_cpu_times(Shell_t *shp, struct timeval *tv_usr, struct timeval *
#endif /* _lib_getrusage */
#ifdef timeofday
/* 'inline' is commented out because C89 doesn't have it */
static /*inline*/ double timeval_to_double(struct timeval tv)
static inline double timeval_to_double(struct timeval tv)
{
return (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0);
}
@ -444,7 +443,7 @@ static int p_comarg(register struct comnod *com)
int n = p_arg(com->comset,ARG_ASSIGN);
if(com->comarg && (com->comtyp&COMSCAN))
n+= p_arg(com->comarg,0);
if(com->comstate && np)
if(com->comstate && np)
{
/* call builtin to cleanup state */
Shbltin_t *bp = &sh.bltindata;
@ -611,7 +610,7 @@ struct Level
/*
* this is for a debugger but it hasn't been tested yet
* if a debug script sets .sh.level it should set up the scope
* as if you were executing in that level
* as if you were executing in that level
*/
static void put_level(Namval_t* np,const char *val,int flags,Namfun_t *fp)
{
@ -1677,7 +1676,7 @@ int sh_exec(register const Shnode_t *t, int flags)
}
if(shp->topfd > topfd)
sh_iorestore(shp,topfd,0);
if(usepipe && tsetio && subdup && unpipe)
if(usepipe && tsetio && subdup && unpipe)
sh_iounpipe(shp);
if(!sh_isstate(SH_MONITOR))
{
@ -2072,7 +2071,7 @@ int sh_exec(register const Shnode_t *t, int flags)
case TLST:
{
/* a list of commands are executed here */
/* a list of commands are executed here */
do
{
sh_exec(t->lst.lstlef,errorflg|OPTIMIZE);