Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions src/cmd/ksh93/bltins/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ static inline int posix_andor(char *arg)

static int test_strmatch(const char *str, const char *pat)
{
int match[2*(MATCH_MAX+1)],n;
int c, m=0;
ssize_t match[2*(MATCH_MAX+1)],c;
ptrdiff_t n;
size_t m=0;
const char *cp=pat;
while(c = *cp++)
{
Expand All @@ -100,14 +101,14 @@ static int test_strmatch(const char *str, const char *pat)
m++;
else
match[0] = 0;
if(m > elementsof(match)/2)
if(m > elementsof(match)/2)
m = elementsof(match)/2;
n = strgrpmatch(str, pat, (ssize_t*)match, m, STR_GROUP|STR_MAXIMAL|STR_LEFT|STR_RIGHT|STR_INT);
n = strgrpmatch(str, pat, match, (ptrdiff_t)m, STR_GROUP|STR_MAXIMAL|STR_LEFT|STR_RIGHT);
if(m==0 && n==1)
match[1] = (int)strlen(str);
match[1] = (ssize_t)strlen(str);
if(n)
sh_setmatch(str, -1, n, match, 0);
return n;
return n != 0;
}

int b_test(int argc, char *argv[],Shbltin_t *context)
Expand Down Expand Up @@ -165,7 +166,7 @@ int b_test(int argc, char *argv[],Shbltin_t *context)
/* FALLTHROUGH */
case 4:
{
int op = sh_lookup(cp=argv[2],shtab_testops);
uint64_t op = sh_lookup(cp=argv[2],shtab_testops);
if(op&TEST_ANDOR)
{
if(sh_isoption(SH_POSIX))
Expand Down Expand Up @@ -292,6 +293,7 @@ static int e3(struct test *tp,int inparens)
{
char *arg, *cp;
int op;
uint64_t bop;
char *binop;
arg=nxtarg(tp,0);
/*
Expand Down Expand Up @@ -324,7 +326,7 @@ static int e3(struct test *tp,int inparens)
*/
if(cp)
{
op = strtol(cp,&binop, 10);
op = (int)strtol(cp,&binop, 10);
return *binop ? 0 : tty_check(op);
}
else
Expand All @@ -347,7 +349,7 @@ static int e3(struct test *tp,int inparens)
return *arg!=0;
}
skip:
if(!(op = sh_lookup(cp,shtab_testops)))
if(!(bop = sh_lookup(cp,shtab_testops)))
{
if(inparens && c_eq(cp,')'))
{
Expand All @@ -357,11 +359,11 @@ static int e3(struct test *tp,int inparens)
errormsg(SH_DICT,ERROR_exit(2),e_badop,cp);
UNREACHABLE();
}
if(op&TEST_ANDOR)
if(bop&TEST_ANDOR)
tp->ap--;
else
cp = nxtarg(tp,0);
return test_binop(op,arg,cp);
return test_binop(bop,arg,cp);
}

int test_unop(int op,const char *arg)
Expand Down Expand Up @@ -451,11 +453,11 @@ int test_unop(int op,const char *arg)
if(*arg=='?')
return sh_lookopt(arg+1,&f)>0;
op = sh_lookopt(arg,&f);
return op>0 && (f==(sh_isoption(op)!=0));
return op>0 && (f==(sh_isoption((uint64_t)op)!=0));
case 't':
{
char *last;
op = strtol(arg,&last, 10);
op = (int)strtol(arg,&last, 10);
return *last ? 0 : tty_check(op);
}
case 'v':
Expand Down Expand Up @@ -483,7 +485,7 @@ int test_unop(int op,const char *arg)
default:
{
static char a[3] = "-?";
a[1]= op;
a[1] = (char)op;
errormsg(SH_DICT,ERROR_exit(2),e_badop,a);
UNREACHABLE();
}
Expand All @@ -494,7 +496,7 @@ int test_unop(int op,const char *arg)
* This function handles binary operators for both the
* test/[ built-in and the [[ ... ]] compound command
*/
int test_binop(int op,const char *left,const char *right)
int test_binop(uint64_t op,const char *left,const char *right)
{
if(op&TEST_ARITH)
{
Expand Down Expand Up @@ -685,7 +687,7 @@ int sh_access(const char *name, int mode)
}
}
#endif /* _lib_getgroups */
if(statb.st_mode & mode)
if(statb.st_mode & (mode_t)mode)
return 0;
}
return -1;
Expand All @@ -702,7 +704,7 @@ static int test_mode(const char *file)
statb.st_mode = 0;
if(file && (*file==0 || test_stat(file,&statb)<0))
return 0;
return statb.st_mode;
return (int)statb.st_mode;
}

/*
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/ksh93/include/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ extern void *sh_arithcomp(char*);
extern pid_t sh_fork(int,int*);
extern pid_t _sh_fork(pid_t, int ,int*);
extern void sh_invalidate_ifs(void);
extern char *sh_mactrim(char*,int);
extern char *sh_mactrim(char*,char);
extern int sh_macexpand(struct argnod*,struct argnod**,int);
extern int sh_macfun(const char*,int);
extern int sh_macfun(const char*,ptrdiff_t);
extern void sh_machere(Sfio_t*, Sfio_t*, char*);
extern void *sh_macopen(void);
extern char *sh_macpat(struct argnod*,int);
Expand All @@ -126,7 +126,7 @@ extern int sh_mathstd(const char*);
extern void sh_printopts(Shopt_t,int,Shopt_t*);
extern int sh_readline(char**,volatile int,int,ssize_t,Sflong_t);
extern Sfio_t *sh_sfeval(char*[]);
extern void sh_setmatch(const char*,int,int,int[],int);
extern void sh_setmatch(const char*,ptrdiff_t,ptrdiff_t,ssize_t[],int);
extern void sh_scope(struct argnod*, int);
extern Namval_t *sh_scoped(Namval_t*);
extern Dt_t *sh_subtracktree(int);
Expand Down Expand Up @@ -157,7 +157,7 @@ extern void *sh_calloc(size_t nmemb, size_t size);
extern char *sh_strdup(const char *s);
extern void *sh_memdup(const void *s, size_t n);
extern char *sh_getcwd(void);
#define new_of(type,x) ((type*)sh_malloc((unsigned)sizeof(type)+(x)))
#define new_of(type,x) ((type*)sh_malloc(sizeof(type)+(x)))
#define sh_newof(p,t,n,x) ((p)?(t*)sh_realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)sh_calloc(1,sizeof(t)*(n)+(x)))

#define URI_RFC3986_UNRESERVED "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"
Expand All @@ -172,7 +172,7 @@ extern char *sh_getcwd(void);

#if SHOPT_SCRIPTONLY
#define is_option(s,x) ((x)==SH_INTERACTIVE || (x)==SH_HISTORY ? 0 : ((s)->v[((x)&WMASK)/WBITS] & ((uint64_t)1 << ((x) % WBITS))) )
#define on_option(s,x) ( (x)==SH_INTERACTIVE || (x)==SH_HISTORY ? errormsg(SH_DICT,ERROR_exit(1),e_scriptonly) : ((s)->v[((x)&WMASK)/WBITS] |= ((uint64_t)1 << ((x) % WBITS))) )
#define on_option(s,x) ( (x)==SH_INTERACTIVE || (x)==SH_HISTORY ? (uint64_t)errormsg(SH_DICT,ERROR_exit(1),e_scriptonly) : ((s)->v[((x)&WMASK)/WBITS] |= ((uint64_t)1 << ((x) % WBITS))) )
#define off_option(s,x) ((x)==SH_INTERACTIVE || (x)==SH_HISTORY ? 0 : ((s)->v[((x)&WMASK)/WBITS] &= ~((uint64_t)1 << ((x) % WBITS))) )
#else
#define is_option(s,x) ((s)->v[((x)&WMASK)/WBITS] & ((uint64_t)1 << ((x) % WBITS)))
Expand Down
22 changes: 11 additions & 11 deletions src/cmd/ksh93/include/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ struct sh_scoped

struct limits
{
clock_t clk_tck; /* number of ticks per second */
int open_max; /* maximum number of file descriptors */
int clk_tck; /* number of ticks per second */
int child_max; /* maximum number of children */
};

Expand Down Expand Up @@ -276,7 +276,7 @@ struct Shell_s
void *ed_context;
int sigmax;
Shwait_f waitevent;
int subshell; /* set for virtual subshell */
unsigned int subshell; /* set for virtual subshell */
int realsubshell; /* ${.sh.subshell}, actual subshell level (including virtual and forked) */
char nv_restore; /* set while restoring variables upon terminating a virtual subshell */
int32_t shlvl; /* $SHLVL, non-subshell child shell level */
Expand Down Expand Up @@ -325,8 +325,8 @@ struct Shell_s
char used_pos; /* used positional parameter */
char universe;
char winch; /* set upon window size change or 'set -b' notification */
unsigned short lines; /* current vertical terminal size */
unsigned short columns; /* current horizontal terminal size */
int32_t lines; /* current vertical terminal size */
int32_t columns; /* current horizontal terminal size */
short arithrecursion; /* current arithmetic recursion level */
char indebug; /* set when in debug trap */
unsigned char ignsig; /* ignored signal in subshell */
Expand All @@ -351,10 +351,10 @@ struct Shell_s
int16_t fn_depth; /* scoped ksh-style function call depth */
int16_t dot_depth; /* dot-script and POSIX function call depth */
char invoc_local; /* set when inside of an invocation-local scope */
int xargmin;
int xargmax;
ptrdiff_t xargmin;
ptrdiff_t xargmax;
int xargexit;
int save_env_n; /* number of saved pointers to environment variables with invalid names */
size_t save_env_n; /* number of saved pointers to environment variables with invalid names */
char **save_env; /* saved pointers to environment variables with invalid names */
mode_t mask;
void *init_context;
Expand All @@ -369,7 +369,7 @@ struct Shell_s
Shinit_f userinit;
Shbltin_f bltinfun;
Shbltin_t bltindata;
int offsets[10];
ptrdiff_t offsets[10];
Sfio_t **sftable;
unsigned char *fdstatus;
char *pwd;
Expand Down Expand Up @@ -480,9 +480,9 @@ extern Shwait_f sh_waitnotify(Shwait_f);
extern Shscope_t *sh_getscope(int,int);
extern Shscope_t *sh_setscope(Shscope_t*);
extern void sh_sigcheck(void);
extern uint64_t sh_isoption(int);
extern uint64_t sh_onoption(int);
extern uint64_t sh_offoption(int);
extern uint64_t sh_isoption(uint64_t);
extern uint64_t sh_onoption(uint64_t);
extern uint64_t sh_offoption(uint64_t);
extern int sh_exec(const Shnode_t*,int);

/*
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/include/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2023 Contributors to ksh 93u+m *
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -55,7 +55,7 @@

extern int test_unop(int, const char*);
extern int test_inode(const char*, const char*);
extern int test_binop(int, const char*, const char*);
extern int test_binop(uint64_t, const char*, const char*);

extern const char sh_opttest[];
extern const char test_opchars[];
Expand Down
Loading