introduce a tobool(cond) abstraction¹ and switch bool to char if !stdbool.h
① currently: ((cond) ? true : false) but (!!(cond)) and casting to bool, the latter only if stdbool.h, would also work – which performs best on (and across) all supported systems?
This commit is contained in:
parent
009d4c7b75
commit
5f8075fc82
4
edit.c
4
edit.c
@ -25,7 +25,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.204 2011/02/09 13:08:16 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.205 2011/03/07 20:30:35 tg Exp $");
|
||||
|
||||
/*
|
||||
* in later versions we might use libtermcap for this, but since external
|
||||
@ -2444,7 +2444,7 @@ x_bind(const char *a1, const char *a2,
|
||||
return (1);
|
||||
}
|
||||
#ifndef MKSH_SMALL
|
||||
hastilde = *m1;
|
||||
hastilde = tobool(*m1);
|
||||
#endif
|
||||
afree(m2, ATEMP);
|
||||
|
||||
|
7
eval.c
7
eval.c
@ -22,7 +22,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.94 2011/01/21 22:25:32 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.95 2011/03/07 20:30:36 tg Exp $");
|
||||
|
||||
/*
|
||||
* string expansion
|
||||
@ -507,8 +507,9 @@ expand(const char *cp, /* input word */
|
||||
while (p >= sbeg) {
|
||||
bool gotmatch;
|
||||
|
||||
c = *p; *p = '\0';
|
||||
gotmatch = gmatchx(sbeg, tpat0, false);
|
||||
c = *p;
|
||||
*p = '\0';
|
||||
gotmatch = tobool(gmatchx(sbeg, tpat0, false));
|
||||
*p = c;
|
||||
if (gotmatch)
|
||||
break;
|
||||
|
8
funcs.c
8
funcs.c
@ -38,7 +38,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.174 2011/03/05 21:48:08 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.175 2011/03/07 20:30:37 tg Exp $");
|
||||
|
||||
#if HAVE_KILLPG
|
||||
/*
|
||||
@ -381,7 +381,7 @@ int
|
||||
c_cd(const char **wp)
|
||||
{
|
||||
int optc, rv, phys_path;
|
||||
bool physical = Flag(FPHYSICAL) ? true : false;
|
||||
bool physical = tobool(Flag(FPHYSICAL));
|
||||
/* was a node from cdpath added in? */
|
||||
int cdnode;
|
||||
/* print where we cd'd? */
|
||||
@ -539,7 +539,7 @@ int
|
||||
c_pwd(const char **wp)
|
||||
{
|
||||
int optc;
|
||||
bool physical = Flag(FPHYSICAL) ? true : false;
|
||||
bool physical = tobool(Flag(FPHYSICAL));
|
||||
char *p, *allocd = NULL;
|
||||
|
||||
while ((optc = ksh_getopt(wp, &builtin_opt, "LP")) != -1)
|
||||
@ -1112,7 +1112,7 @@ c_typeset(const char **wp)
|
||||
for (i = builtin_opt.optind; wp[i]; i++) {
|
||||
if (func) {
|
||||
f = findfunc(wp[i], hash(wp[i]),
|
||||
(fset&UCASEV_AL) ? true : false);
|
||||
tobool(fset & UCASEV_AL));
|
||||
if (!f) {
|
||||
/* AT&T ksh does ++rv: bogus */
|
||||
rv = 1;
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.107 2011/02/09 19:32:15 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.108 2011/03/07 20:30:38 tg Exp $");
|
||||
|
||||
/*-
|
||||
* MirOS: This is the default mapping type, and need not be specified.
|
||||
@ -204,7 +204,7 @@ c_fc(const char **wp)
|
||||
* when range is specified; AT&T ksh and pdksh allow out
|
||||
* of bounds for -l as well.
|
||||
*/
|
||||
hfirst = hist_get(first, (lflag || last) ? true : false, lflag);
|
||||
hfirst = hist_get(first, tobool(lflag || last), lflag);
|
||||
if (!hfirst)
|
||||
return (1);
|
||||
hlast = last ? hist_get(last, true, lflag) :
|
||||
|
10
lex.c
10
lex.c
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.127 2011/03/07 20:09:34 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.128 2011/03/07 20:30:39 tg Exp $");
|
||||
|
||||
/*
|
||||
* states while lexing word
|
||||
@ -54,7 +54,7 @@ __RCSID("$MirOS: src/bin/mksh/lex.c,v 1.127 2011/03/07 20:09:34 tg Exp $");
|
||||
typedef struct lex_state {
|
||||
union {
|
||||
/* point to the next state block */
|
||||
Lex_state *base;
|
||||
struct lex_state *base;
|
||||
/* marks start of $(( in output string */
|
||||
int start;
|
||||
/* SBQUOTE: true if in double quotes: "`...`" */
|
||||
@ -90,7 +90,7 @@ static int getsc_bn(void);
|
||||
static int s_get(void);
|
||||
static void s_put(int);
|
||||
static char *get_brace_var(XString *, char *);
|
||||
static int arraysub(char **);
|
||||
static bool arraysub(char **);
|
||||
static const char *ungetsc(int);
|
||||
static void gethere(bool);
|
||||
static Lex_state *push_state_(State_info *, Lex_state *);
|
||||
@ -1641,7 +1641,7 @@ get_brace_var(XString *wsp, char *wp)
|
||||
* if eof or newline was found.
|
||||
* (Returned string double null terminated)
|
||||
*/
|
||||
static int
|
||||
static bool
|
||||
arraysub(char **strp)
|
||||
{
|
||||
XString ws;
|
||||
@ -1664,7 +1664,7 @@ arraysub(char **strp)
|
||||
*wp++ = '\0';
|
||||
*strp = Xclose(ws, wp);
|
||||
|
||||
return (depth == 0 ? 1 : 0);
|
||||
return (tobool(depth == 0));
|
||||
}
|
||||
|
||||
/* Unget a char: handles case when we are already at the start of the buffer */
|
||||
|
4
misc.c
4
misc.c
@ -29,7 +29,7 @@
|
||||
#include <grp.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.152 2011/03/05 21:43:17 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.153 2011/03/07 20:30:39 tg Exp $");
|
||||
|
||||
/* type bits for unsigned char */
|
||||
unsigned char chtypes[UCHAR_MAX + 1];
|
||||
@ -433,7 +433,7 @@ parse_args(const char **argv,
|
||||
xstrcmp);
|
||||
}
|
||||
if (arrayset)
|
||||
go.optind += set_array(array, arrayset > 0 ? true : false,
|
||||
go.optind += set_array(array, tobool(arrayset > 0),
|
||||
argv + go.optind);
|
||||
|
||||
return (go.optind);
|
||||
|
14
sh.h
14
sh.h
@ -154,7 +154,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.438 2011/03/06 17:08:13 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.439 2011/03/07 20:30:40 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R39 2011/03/06"
|
||||
|
||||
@ -187,11 +187,17 @@ typedef void (*sig_t)(int);
|
||||
|
||||
#if !HAVE_STDBOOL_H
|
||||
/* kludge, but enough for mksh */
|
||||
typedef int bool;
|
||||
typedef unsigned char bool;
|
||||
#define false 0
|
||||
#define true 1
|
||||
#endif
|
||||
|
||||
/* choose the one that is optimised on most platforms? */
|
||||
#define tobool(cond) ((cond) ? true : false)
|
||||
/*#define tobool(cond) (!!(cond))*/
|
||||
/* the following only with <stdbool.h> and even then sometimes buggy */
|
||||
/*#define tobool(cond) ((bool)(cond))*/
|
||||
|
||||
#if !HAVE_CAN_INTTYPES
|
||||
#if !HAVE_CAN_UCBINTS
|
||||
typedef signed int int32_t;
|
||||
@ -778,9 +784,9 @@ EXTERN int really_exit;
|
||||
|
||||
extern unsigned char chtypes[];
|
||||
|
||||
#define ctype(c, t) !!( ((t) == C_SUBOP2) ? \
|
||||
#define ctype(c, t) tobool( ((t) == C_SUBOP2) ? \
|
||||
(((c) == '#' || (c) == '%') ? 1 : 0) : \
|
||||
(chtypes[(unsigned char)(c)]&(t)) )
|
||||
(chtypes[(unsigned char)(c)] & (t)) )
|
||||
#define ksh_isalphx(c) ctype((c), C_ALPHA)
|
||||
#define ksh_isalnux(c) ctype((c), C_ALPHA | C_DIGIT)
|
||||
|
||||
|
4
var.c
4
var.c
@ -26,7 +26,7 @@
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.116 2011/02/11 01:18:23 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.117 2011/03/07 20:30:41 tg Exp $");
|
||||
|
||||
/*
|
||||
* Variables
|
||||
@ -726,7 +726,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
|
||||
strcmp(tvar, "ENV") == 0 || strcmp(tvar, "SHELL") == 0))
|
||||
errorf("%s: %s", tvar, "restricted");
|
||||
|
||||
vp = (set&LOCAL) ? local(tvar, (set & LOCAL_COPY) ? true : false) :
|
||||
vp = (set&LOCAL) ? local(tvar, tobool(set & LOCAL_COPY)) :
|
||||
global(tvar);
|
||||
if (set_refflag == 2 && (vp->flag & (ARRAY|ASSOC)) == ASSOC)
|
||||
vp->flag &= ~ASSOC;
|
||||
|
Loading…
x
Reference in New Issue
Block a user