Un-boolify sbase

It actually makes the binaries smaller, the code easier to read
(gems like "val == true", "val == false" are gone) and actually
predictable in the sense of that we actually know what we're
working with (one bitwise operator was quite adventurous and
should now be fixed).

This is also more consistent with the other suckless projects
around which don't use boolean types.
This commit is contained in:
FRIGN 2014-11-13 21:24:47 +01:00 committed by sin
parent 7d2683ddf2
commit ec8246bbc6
41 changed files with 215 additions and 257 deletions

11
cal.c
View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@ -10,7 +9,7 @@
static void drawcal(int, int, int, int, int, int);
static int dayofweek(int, int, int, int);
static bool isleap(int);
static int isleap(int);
static void usage(void);
static void
@ -59,7 +58,7 @@ drawcal(int year, int month, int day, int ncols, int nmons, int fday)
cur = moff % 12;
yoff = year + moff / 12;
ndays = mdays[cur] + ((cur == 1) & isleap(yoff));
ndays = mdays[cur] + ((cur == 1) && isleap(yoff));
day1 = dayofweek(year, cur, 1, fday);
for (d = 0; d < 7; d++) {
@ -87,13 +86,13 @@ dayofweek(int year, int month, int day, int fday)
return (year + year / 4 - year / 100 + year / 400 + t[month] + day) % 7;
}
static bool
static int
isleap(int year)
{
if (year % 400 == 0)
return true;
return 1;
if (year % 100 == 0)
return false;
return 0;
return (year % 4 == 0);
}

View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
@ -9,7 +8,7 @@
static void chmodr(const char *);
static bool rflag = false;
static int rflag = 0;
static char *modestr = "";
static mode_t mask = 0;
static int ret = 0;
@ -30,7 +29,7 @@ main(int argc, char *argv[])
while ((c = *++argv[0])) {
switch (c) {
case 'R':
rflag = true;
rflag = 1;
break;
case 'r': case 'w': case 'x': case 's': case 't':
/*

View File

@ -2,7 +2,6 @@
#include <errno.h>
#include <grp.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@ -11,7 +10,7 @@
static void chownpwgr(const char *);
static bool rflag = false;
static int rflag = 0;
static uid_t uid = -1;
static gid_t gid = -1;
static int ret = 0;
@ -32,7 +31,7 @@ main(int argc, char *argv[])
ARGBEGIN {
case 'R':
case 'r':
rflag = true;
rflag = 1;
break;
default:
usage();

13
cmp.c
View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -17,19 +16,19 @@ usage(void)
int
main(int argc, char *argv[])
{
bool lflag = false;
bool sflag = false;
bool same = true;
int lflag = 0;
int sflag = 0;
int same = 1;
int b[2], i;
long line = 1, n = 1;
FILE *fp[2];
ARGBEGIN {
case 'l':
lflag = true;
lflag = 1;
break;
case 's':
sflag = true;
sflag = 1;
break;
default:
usage();
@ -80,7 +79,7 @@ main(int argc, char *argv[])
exit(Diff);
} else {
printf("%4ld %3o %3o\n", n, b[0], b[1]);
same = false;
same = 0;
}
}
return same ? Same : Diff;

1
cols.c
View File

@ -1,6 +1,5 @@
/* See LICENSE file for copyright and license details. */
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

1
comm.c
View File

@ -1,6 +1,5 @@
/* See LICENSE file for copyright and license details. */
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

17
cp.c
View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdlib.h>
#include <sys/stat.h>
@ -19,26 +18,24 @@ main(int argc, char *argv[])
ARGBEGIN {
case 'a':
cp_aflag = true; /* implies -dpr */
cp_dflag = true;
cp_pflag = true;
cp_rflag = true;
/* implies -dpr */
cp_aflag = cp_dflag = cp_pflag = cp_rflag = 1;
break;
case 'd':
cp_dflag = true;
cp_dflag = 1;
break;
case 'p':
cp_pflag = true;
cp_pflag = 1;
break;
case 'f':
cp_fflag = true;
cp_fflag = 1;
break;
case 'R':
case 'r':
cp_rflag = true;
cp_rflag = 1;
break;
case 'v':
cp_vflag = true;
cp_vflag = 1;
break;
default:
usage();

9
cut.c
View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -23,8 +22,8 @@ typedef struct Range {
static Range *list = NULL;
static char mode = 0;
static char delim = '\t';
static bool nflag = false;
static bool sflag = false;
static int nflag = 0;
static int sflag = 0;
static void
insert(Range *r)
@ -164,10 +163,10 @@ main(int argc, char *argv[])
delim = *ARGF();
break;
case 'n':
nflag = true;
nflag = 1;
break;
case 's':
sflag = true;
sflag = 1;
break;
default:
usage();

21
du.c
View File

@ -1,7 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include <dirent.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -16,11 +15,11 @@ static char file[PATH_MAX];
static long depth = -1;
static long curdepth = 0;
static bool aflag = false;
static bool dflag = false;
static bool sflag = false;
static bool kflag = false;
static bool hflag = false;
static int aflag = 0;
static int dflag = 0;
static int sflag = 0;
static int kflag = 0;
static int hflag = 0;
static long du(const char *);
static void print(long n, char *path);
@ -50,20 +49,20 @@ main(int argc, char *argv[])
ARGBEGIN {
case 'a':
aflag = true;
aflag = 1;
break;
case 'd':
dflag = true;
dflag = 1;
depth = estrtol(EARGF(usage()), 0);
break;
case 's':
sflag = true;
sflag = 1;
break;
case 'k':
kflag = true;
kflag = 1;
break;
case 'h':
hflag = true;
hflag = 1;
break;
default:
usage();

5
echo.c
View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@ -14,11 +13,11 @@ usage(void)
int
main(int argc, char *argv[])
{
bool nflag = false;
int nflag = 0;
ARGBEGIN {
case 'n':
nflag = true;
nflag = 1;
break;
default:
usage();

View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
@ -13,7 +12,7 @@ typedef struct {
static int expand(Fdescr *f, int tabstop);
static bool iflag = false;
static int iflag = 0;
static void
usage(void)
@ -30,7 +29,7 @@ main(int argc, char *argv[])
ARGBEGIN {
case 'i':
iflag = true;
iflag = 1;
break;
case 't':
tabstop = estrtol(EARGF(usage()), 0);
@ -82,7 +81,7 @@ expand(Fdescr *dsc, int tabstop)
{
int col = 0;
wint_t c;
bool bol = true;
int bol = 1;
for (;;) {
c = in(dsc);
@ -104,18 +103,18 @@ expand(Fdescr *dsc, int tabstop)
case '\b':
if (col)
col--;
bol = false;
bol = 0;
out(c);
break;
case '\n':
col = 0;
bol = true;
bol = 1;
out(c);
break;
default:
col++;
if (c != ' ')
bol = false;
bol = 0;
out(c);
break;
}

15
fold.c
View File

@ -1,6 +1,5 @@
/* See LICENSE file for copyright and license details. */
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -11,8 +10,8 @@
static void fold(FILE *, long);
static void foldline(const char *, long);
static bool bflag = false;
static bool sflag = false;
static int bflag = 0;
static int sflag = 0;
static void
usage(void)
@ -28,10 +27,10 @@ main(int argc, char *argv[])
ARGBEGIN {
case 'b':
bflag = true;
bflag = 1;
break;
case 's':
sflag = true;
sflag = 1;
break;
case 'w':
width = estrtol(EARGF(usage()), 0);
@ -73,19 +72,19 @@ fold(FILE *fp, long width)
static void
foldline(const char *str, long width)
{
bool space;
int space;
long col, j;
size_t i = 0, n = 0;
int c;
do {
space = false;
space = 0;
for (j = i, col = 0; str[j] && col <= width; j++) {
c = str[j];
if (!UTF8_POINT(c) && !bflag)
continue;
if (sflag && isspace(c)) {
space = true;
space = 1;
n = j+1;
}
else if (!space)

18
fs.h
View File

@ -1,16 +1,14 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
extern bool cp_aflag;
extern bool cp_dflag;
extern bool cp_fflag;
extern bool cp_pflag;
extern bool cp_rflag;
extern bool cp_vflag;
extern int cp_aflag;
extern int cp_dflag;
extern int cp_fflag;
extern int cp_pflag;
extern int cp_rflag;
extern int cp_vflag;
extern int cp_status;
extern bool rm_fflag;
extern bool rm_rflag;
extern int rm_fflag;
extern int rm_rflag;
int cp(const char *, const char *);
void rm(const char *);

11
grep.c
View File

@ -1,6 +1,5 @@
/* See LICENSE file for copyright and license details. */
#include <regex.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -14,9 +13,9 @@ enum { Match = 0, NoMatch = 1, Error = 2 };
static void addpattern(const char *);
static int grep(FILE *, const char *);
static bool eflag = false;
static bool vflag = false;
static bool many;
static int eflag = 0;
static int vflag = 0;
static int many;
static char mode = 0;
static struct plist {
@ -45,7 +44,7 @@ main(int argc, char *argv[])
break;
case 'e':
addpattern(EARGF(usage()));
eflag = true;
eflag = 1;
break;
case 'c':
case 'l':
@ -57,7 +56,7 @@ main(int argc, char *argv[])
flags |= REG_ICASE;
break;
case 'v':
vflag = true;
vflag = 1;
break;
default:
usage();

1
kill.c
View File

@ -2,7 +2,6 @@
#include <ctype.h>
#include <errno.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

11
ln.c
View File

@ -1,7 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include <errno.h>
#include <libgen.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -20,15 +19,15 @@ main(int argc, char *argv[])
{
int (*flink)(const char *, const char *);
char *fname, *to;
bool sflag = false;
bool fflag = false;
int sflag = 0;
int fflag = 0;
ARGBEGIN {
case 'f':
fflag = true;
fflag = 1;
break;
case 's':
sflag = true;
sflag = 1;
break;
default:
usage();
@ -47,7 +46,7 @@ main(int argc, char *argv[])
to = argc < 2 ? basename(argv[0]) : argv[1];
if (fflag == true)
if (fflag)
remove(to);
if (flink(argv[0], to) < 0)
eprintf("%s %s <- %s:", fname, argv[0], to);

49
ls.c
View File

@ -3,7 +3,6 @@
#include <errno.h>
#include <grp.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -27,20 +26,20 @@ typedef struct {
static int entcmp(const void *, const void *);
static void ls(Entry *);
static void lsdir(const char *);
static void mkent(Entry *, char *, bool);
static void mkent(Entry *, char *, int);
static void output(Entry *);
static bool aflag = false;
static bool dflag = false;
static bool Fflag = false;
static bool hflag = false;
static bool iflag = false;
static bool lflag = false;
static bool rflag = false;
static bool tflag = false;
static bool Uflag = false;
static bool first = true;
static bool many;
static int aflag = 0;
static int dflag = 0;
static int Fflag = 0;
static int hflag = 0;
static int iflag = 0;
static int lflag = 0;
static int rflag = 0;
static int tflag = 0;
static int Uflag = 0;
static int first = 1;
static int many;
static void
usage(void)
@ -59,31 +58,31 @@ main(int argc, char *argv[])
/* ignore */
break;
case 'a':
aflag = true;
aflag = 1;
break;
case 'd':
dflag = true;
dflag = 1;
break;
case 'F':
Fflag = true;
Fflag = 1;
break;
case 'h':
hflag = true;
hflag = 1;
break;
case 'i':
iflag = true;
iflag = 1;
break;
case 'l':
lflag = true;
lflag = 1;
break;
case 'r':
rflag = true;
rflag = 1;
break;
case 't':
tflag = true;
tflag = 1;
break;
case 'U':
Uflag = true;
Uflag = 1;
break;
default:
usage();
@ -96,7 +95,7 @@ main(int argc, char *argv[])
if (!(ents = malloc(argc * sizeof *ents)))
eprintf("malloc:");
for (i = 0; i < argc; i++)
mkent(&ents[i], argv[i], true);
mkent(&ents[i], argv[i], 1);
qsort(ents, argc, sizeof *ents, entcmp);
for (i = 0; i < argc; i++)
ls(&ents[rflag ? argc-i-1 : i]);
@ -145,7 +144,7 @@ lsdir(const char *path)
if (!first)
putchar('\n');
printf("%s:\n", path);
first = false;
first = 0;
}
while ((d = readdir(dp))) {
@ -178,7 +177,7 @@ lsdir(const char *path)
}
static void
mkent(Entry *ent, char *path, bool dostat)
mkent(Entry *ent, char *path, int dostat)
{
struct stat st;

View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@ -27,11 +26,11 @@ main(int argc, char *argv[])
{
uint8_t md[MD5_DIGEST_LENGTH];
char *checkfile = NULL;
bool cflag = false;
int cflag = 0;
ARGBEGIN {
case 'c':
cflag = true;
cflag = 1;
checkfile = ARGF();
break;
default:

View File

@ -1,7 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
@ -20,16 +19,16 @@ usage(void)
int
main(int argc, char *argv[])
{
bool pflag = false;
bool mflag = false;
int pflag = 0;
int mflag = 0;
int mode;
ARGBEGIN {
case 'p':
pflag = true;
pflag = 1;
break;
case 'm':
mflag = true;
mflag = 1;
mode = estrtol(EARGF(usage()), 8);
break;
default:

4
mv.c
View File

@ -44,8 +44,8 @@ mv(const char *s1, const char *s2)
if (rename(s1, s2) == 0)
return 0;
if (errno == EXDEV) {
cp_rflag = true;
rm_rflag = true;
cp_rflag = 1;
rm_rflag = 1;
cp(s1, s2);
rm(s1);
return 0;

View File

@ -1,6 +1,5 @@
/* See LICENSE file for copyright and license details. */
#include <locale.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -30,7 +29,7 @@ int
main(int argc, char *argv[])
{
const char *adelim = NULL;
bool seq = false;
int seq = 0;
wchar_t *delim = NULL;
size_t len;
Fdescr *dsc = NULL;
@ -40,7 +39,7 @@ main(int argc, char *argv[])
ARGBEGIN {
case 's':
seq = true;
seq = 1;
break;
case 'd':
adelim = EARGF(usage());

View File

@ -2,7 +2,6 @@
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -19,8 +18,8 @@ int
main(int argc, char *argv[])
{
char buf[PATH_MAX];
bool nflag = false;
bool fflag = false;
int nflag = 0;
int fflag = 0;
ssize_t n;
ARGBEGIN {
@ -28,10 +27,10 @@ main(int argc, char *argv[])
case 'm':
eprintf("not implemented\n");
case 'f':
fflag = true;
fflag = 1;
break;
case 'n':
nflag = true;
nflag = 1;
break;
default:
usage();

View File

@ -1,17 +1,16 @@
/* See LICENSE file for copyright and license details. */
#include <sys/resource.h>
#include <errno.h>
#include <limits.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
#include "util.h"
static int strtop(const char *);
static bool renice(int, int, long);
static int renice(int, int, long);
static void
usage(void)
@ -95,7 +94,7 @@ strtop(const char *s)
return (int)n;
}
static bool
static int
renice(int which, int who, long adj)
{
errno = 0;
@ -103,15 +102,15 @@ renice(int which, int who, long adj)
if (errno != 0) {
fprintf(stderr, "can't get %d nice level: %s\n",
who, strerror(errno));
return false;
return 0;
}
adj = MAX(-NZERO, MIN(adj, NZERO - 1));
if (setpriority(which, who, (int)adj) == -1) {
fprintf(stderr, "can't set %d nice level: %s\n",
who, strerror(errno));
return false;
return 0;
}
return true;
return 1;
}

7
rm.c
View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -19,18 +18,18 @@ main(int argc, char *argv[])
{
ARGBEGIN {
case 'f':
rm_fflag = true;
rm_fflag = 1;
break;
case 'R':
case 'r':
rm_rflag = true;
rm_rflag = 1;
break;
default:
usage();
} ARGEND;
if (argc < 1) {
if (rm_fflag == false)
if (!rm_fflag)
usage();
else
return 0;

11
seq.c
View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -9,7 +8,7 @@
static int digitsleft(const char *);
static int digitsright(const char *);
static bool validfmt(const char *);
static int validfmt(const char *);
static void
usage(void)
@ -22,7 +21,7 @@ int
main(int argc, char *argv[])
{
const char *starts = "1", *steps = "1", *ends = "1", *sep = "\n";
bool wflag = false;
int wflag = 0;
char *tmp, ftmp[BUFSIZ], *fmt = ftmp;
double start, step, end, out, dir;
int left, right;
@ -37,7 +36,7 @@ main(int argc, char *argv[])
sep = EARGF(usage());
break;
case 'w':
wflag = true;
wflag = 1;
break;
default:
usage();
@ -116,7 +115,7 @@ digitsright(const char *d)
return MAX(0, after - shift);
}
static bool
static int
validfmt(const char *fmt)
{
int occur = 0;
@ -149,6 +148,6 @@ format:
occur++;
goto literal;
default:
return false;
return 0;
}
}

View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@ -27,11 +26,11 @@ main(int argc, char *argv[])
{
uint8_t md[SHA1_DIGEST_LENGTH];
char *checkfile = NULL;
bool cflag = false;
int cflag = 0;
ARGBEGIN {
case 'c':
cflag = true;
cflag = 1;
checkfile = ARGF();
break;
default:

View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@ -27,11 +26,11 @@ main(int argc, char *argv[])
{
uint8_t md[SHA256_DIGEST_LENGTH];
char *checkfile = NULL;
bool cflag = false;
int cflag = 0;
ARGBEGIN {
case 'c':
cflag = true;
cflag = 1;
checkfile = ARGF();
break;
default:

View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@ -27,11 +26,11 @@ main(int argc, char *argv[])
{
uint8_t md[SHA512_DIGEST_LENGTH];
char *checkfile = NULL;
bool cflag = false;
int cflag = 0;
ARGBEGIN {
case 'c':
cflag = true;
cflag = 1;
checkfile = ARGF();
break;
default:

5
sort.c
View File

@ -1,6 +1,5 @@
/* See LICENSE file for copyright and license details. */
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -41,7 +40,7 @@ static int parse_keydef(struct keydef *, char *, int);
static char *nextcol(char *);
static char *columns(char *, const struct keydef *);
static bool uflag = false;
static int uflag = 0;
static char *fieldsep = NULL;
static void
@ -77,7 +76,7 @@ main(int argc, char *argv[])
usage();
break;
case 'u':
uflag = true;
uflag = 1;
break;
default:
usage();

7
tar.c
View File

@ -2,7 +2,6 @@
#include <grp.h>
#include <limits.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -53,7 +52,7 @@ static FILE *tarfile;
static ino_t tarinode;
static dev_t tardev;
static bool mflag = false;
static int mflag = 0;
static void
usage(void)
@ -86,7 +85,7 @@ main(int argc, char *argv[])
file = EARGF(usage());
break;
case 'm':
mflag = true;
mflag = 1;
break;
default:
usage();
@ -118,7 +117,7 @@ main(int argc, char *argv[])
dir = argv[0];
break;
case 'm':
mflag = true;
mflag = 1;
break;
default:
usage();

5
tee.c
View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -15,7 +14,7 @@ usage(void)
int
main(int argc, char *argv[])
{
bool aflag = false;
int aflag = 0;
char buf[BUFSIZ];
int i, nfps;
size_t n;
@ -23,7 +22,7 @@ main(int argc, char *argv[])
ARGBEGIN {
case 'a':
aflag = true;
aflag = 1;
break;
default:
usage();

65
test.c
View File

@ -1,6 +1,5 @@
/* See LICENSE file for copyright and license details. */
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -19,40 +18,40 @@ stoi(char *s, int *a)
enprintf(2, "bad integer %s\n", s);
}
static bool unary_b(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISBLK (buf.st_mode); }
static bool unary_c(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISCHR (buf.st_mode); }
static bool unary_d(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISDIR (buf.st_mode); }
static bool unary_f(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISREG (buf.st_mode); }
static bool unary_g(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISGID & buf.st_mode ; }
static bool unary_h(char *s) { struct stat buf; if (lstat(s, &buf)) return 0; return S_ISLNK (buf.st_mode); }
static bool unary_p(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISFIFO (buf.st_mode); }
static bool unary_S(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISSOCK (buf.st_mode); }
static bool unary_s(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return buf.st_size ; }
static bool unary_u(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISUID & buf.st_mode ; }
static int unary_b(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISBLK (buf.st_mode); }
static int unary_c(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISCHR (buf.st_mode); }
static int unary_d(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISDIR (buf.st_mode); }
static int unary_f(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISREG (buf.st_mode); }
static int unary_g(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISGID & buf.st_mode ; }
static int unary_h(char *s) { struct stat buf; if (lstat(s, &buf)) return 0; return S_ISLNK (buf.st_mode); }
static int unary_p(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISFIFO (buf.st_mode); }
static int unary_S(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISSOCK (buf.st_mode); }
static int unary_s(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return buf.st_size ; }
static int unary_u(char *s) { struct stat buf; if ( stat(s, &buf)) return 0; return S_ISUID & buf.st_mode ; }
static bool unary_n(char *s) { return strlen(s); }
static bool unary_z(char *s) { return !strlen(s); }
static int unary_n(char *s) { return strlen(s); }
static int unary_z(char *s) { return !strlen(s); }
static bool unary_e(char *s) { return access(s, F_OK); }
static bool unary_r(char *s) { return access(s, R_OK); }
static bool unary_w(char *s) { return access(s, W_OK); }
static bool unary_x(char *s) { return access(s, X_OK); }
static int unary_e(char *s) { return access(s, F_OK); }
static int unary_r(char *s) { return access(s, R_OK); }
static int unary_w(char *s) { return access(s, W_OK); }
static int unary_x(char *s) { return access(s, X_OK); }
static bool unary_t(char *s) { int fd; stoi(s, &fd); return isatty(fd); }
static int unary_t(char *s) { int fd; stoi(s, &fd); return isatty(fd); }
static bool binary_se(char *s1, char *s2) { return strcmp(s1, s2) == 0; }
static bool binary_sn(char *s1, char *s2) { return strcmp(s1, s2) != 0; }
static int binary_se(char *s1, char *s2) { return strcmp(s1, s2) == 0; }
static int binary_sn(char *s1, char *s2) { return strcmp(s1, s2) != 0; }
static bool binary_eq(char *s1, char *s2) { int a, b; stoi(s1, &a); stoi(s2, &b); return a == b; }
static bool binary_ne(char *s1, char *s2) { int a, b; stoi(s1, &a); stoi(s2, &b); return a != b; }
static bool binary_gt(char *s1, char *s2) { int a, b; stoi(s1, &a); stoi(s2, &b); return a > b; }
static bool binary_ge(char *s1, char *s2) { int a, b; stoi(s1, &a); stoi(s2, &b); return a >= b; }
static bool binary_lt(char *s1, char *s2) { int a, b; stoi(s1, &a); stoi(s2, &b); return a < b; }
static bool binary_le(char *s1, char *s2) { int a, b; stoi(s1, &a); stoi(s2, &b); return a <= b; }
static int binary_eq(char *s1, char *s2) { int a, b; stoi(s1, &a); stoi(s2, &b); return a == b; }
static int binary_ne(char *s1, char *s2) { int a, b; stoi(s1, &a); stoi(s2, &b); return a != b; }
static int binary_gt(char *s1, char *s2) { int a, b; stoi(s1, &a); stoi(s2, &b); return a > b; }
static int binary_ge(char *s1, char *s2) { int a, b; stoi(s1, &a); stoi(s2, &b); return a >= b; }
static int binary_lt(char *s1, char *s2) { int a, b; stoi(s1, &a); stoi(s2, &b); return a < b; }
static int binary_le(char *s1, char *s2) { int a, b; stoi(s1, &a); stoi(s2, &b); return a <= b; }
typedef struct {
char *name;
bool (*func)();
int (*func)();
} Test;
static Test unary[] = {
@ -102,19 +101,19 @@ find_test(Test *tests, char *name)
return NULL;
}
static bool
static int
noarg(char **argv)
{
return 0;
}
static bool
static int
onearg(char **argv)
{
return strlen(argv[0]);
}
static bool
static int
twoarg(char **argv)
{
Test *t = find_test(unary, *argv);
@ -128,7 +127,7 @@ twoarg(char **argv)
return enprintf(2, "bad unary test %s\n", argv[0]), 0;
}
static bool
static int
threearg(char **argv)
{
Test *t = find_test(binary, argv[1]);
@ -142,7 +141,7 @@ threearg(char **argv)
return enprintf(2, "bad binary test %s\n", argv[1]), 0;
}
static bool
static int
fourarg(char **argv)
{
if (strcmp(argv[0], "!") == 0)
@ -154,7 +153,7 @@ fourarg(char **argv)
int
main(int argc, char **argv)
{
bool (*narg[])(char**) = { noarg, onearg, twoarg, threearg, fourarg };
int (*narg[])(char**) = { noarg, onearg, twoarg, threearg, fourarg };
int len = strlen(argv[0]);
if (len && argv[0][len - 1] == '[')

View File

@ -1,7 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <time.h>
@ -12,7 +11,7 @@
static void touch(const char *);
static bool cflag = false;
static int cflag = 0;
static time_t t;
static void
@ -28,7 +27,7 @@ main(int argc, char *argv[])
ARGBEGIN {
case 'c':
cflag = true;
cflag = 1;
break;
case 't':
t = estrtol(EARGF(usage()), 0);

1
tr.c
View File

@ -1,6 +1,5 @@
/* See LICENSE file for copyright and license details. */
#include <locale.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

25
uname.c
View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/utsname.h>
@ -16,36 +15,36 @@ usage(void)
int
main(int argc, char *argv[])
{
bool mflag = false;
bool nflag = false;
bool rflag = false;
bool sflag = false;
bool vflag = false;
int mflag = 0;
int nflag = 0;
int rflag = 0;
int sflag = 0;
int vflag = 0;
struct utsname u;
ARGBEGIN {
case 'a':
mflag = nflag = rflag = sflag = vflag = true;
mflag = nflag = rflag = sflag = vflag = 1;
break;
case 'm':
mflag = true;
mflag = 1;
break;
case 'n':
nflag = true;
nflag = 1;
break;
case 'r':
rflag = true;
rflag = 1;
break;
case 's':
sflag = true;
sflag = 1;
break;
case 'v':
vflag = true;
vflag = 1;
break;
default:
usage();
} ARGEND;
if (uname(&u) == -1)
if (uname(&u) < 0)
eprintf("uname:");
if (sflag || !(nflag || rflag || vflag || mflag))

View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
@ -13,7 +12,7 @@ typedef struct {
static void unexpand(Fdescr *dsc);
static bool aflag = false;
static int aflag = 0;
static int tabsize = 8;
static void
@ -35,7 +34,7 @@ main(int argc, char *argv[])
eprintf("unexpand: invalid tabsize\n", argv[0]);
/* Fallthrough: -t implies -a */
case 'a':
aflag = true;
aflag = 1;
break;
default:
usage();
@ -98,7 +97,7 @@ static void
unexpand(Fdescr *dsc)
{
unsigned int n = 0, col = 0;
bool bol = true;
int bol = 1;
wint_t c;
while ((c = in(dsc)) != EOF) {
@ -118,20 +117,20 @@ unexpand(Fdescr *dsc)
unexpandspan(n, col);
col -= (col > 0);
n = 0;
bol = false;
bol = 0;
break;
case '\n':
if (bol || aflag)
unexpandspan(n, col);
n = col = 0;
bol = true;
bol = 1;
break;
default:
if (bol || aflag)
unexpandspan(n, col);
n = 0;
col++;
bol = false;
bol = 0;
}
if ((c != ' ' && c != '\t') || (!aflag && !bol))
out(c);

11
uniq.c
View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -13,8 +12,8 @@ static void uniq(FILE *, const char *);
static void uniqfinish(void);
static const char *countfmt = "";
static bool dflag = false;
static bool uflag = false;
static int dflag = 0;
static int uflag = 0;
static char *prevline = NULL;
static long prevlinecount = 0;
@ -37,10 +36,10 @@ main(int argc, char *argv[])
countfmt = "%7ld ";
break;
case 'd':
dflag = true;
dflag = 1;
break;
case 'u':
uflag = true;
uflag = 1;
break;
default:
usage();
@ -63,7 +62,7 @@ main(int argc, char *argv[])
static void
uniqline(char *l)
{
bool linesequel = ((l == NULL) || (prevline == NULL))
int linesequel = ((l == NULL) || (prevline == NULL))
? l == prevline
: !strcmp(l, prevline);

View File

@ -3,7 +3,6 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -16,12 +15,12 @@
#include "../text.h"
#include "../util.h"
bool cp_aflag = false;
bool cp_dflag = false;
bool cp_fflag = false;
bool cp_pflag = false;
bool cp_rflag = false;
bool cp_vflag = false;
int cp_aflag = 0;
int cp_dflag = 0;
int cp_fflag = 0;
int cp_pflag = 0;
int cp_rflag = 0;
int cp_vflag = 0;
int cp_status = 0;
int
@ -40,15 +39,15 @@ cp(const char *s1, const char *s2)
if (cp_vflag)
printf("'%s' -> '%s'\n", s1, s2);
if (cp_dflag == true)
if (cp_dflag)
r = lstat(s1, &st);
else
r = stat(s1, &st);
if (r == 0) {
if (cp_dflag == true && S_ISLNK(st.st_mode)) {
if (cp_dflag && S_ISLNK(st.st_mode)) {
if (readlink(s1, buf, sizeof(buf) - 1) >= 0) {
if (cp_fflag == true);
if (cp_fflag);
unlink(s2);
if (symlink(buf, s2) != 0) {
weprintf("%s: can't create '%s'\n", argv0, s2);
@ -92,7 +91,7 @@ cp(const char *s1, const char *s2)
}
}
if (cp_aflag == true) {
if (cp_aflag) {
if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode) ||
S_ISSOCK(st.st_mode) || S_ISFIFO(st.st_mode)) {
unlink(s2);
@ -112,7 +111,7 @@ cp(const char *s1, const char *s2)
}
if (!(f2 = fopen(s2, "w"))) {
if (cp_fflag == true) {
if (cp_fflag) {
unlink(s2);
if (!(f2 = fopen(s2, "w"))) {
weprintf("fopen %s:", s2);
@ -131,7 +130,7 @@ cp(const char *s1, const char *s2)
fclose(f1);
preserve:
if (cp_aflag == true || cp_pflag == true) {
if (cp_aflag || cp_pflag) {
if (!(S_ISLNK(st.st_mode))) {
/* timestamp */
ut.actime = st.st_atime;

View File

@ -1,5 +1,4 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include "../util.h"
@ -7,11 +6,11 @@
void
putword(const char *s)
{
static bool first = true;
static int first = 1;
if (!first)
putchar(' ');
fputs(s, stdout);
first = false;
first = 0;
}

View File

@ -1,11 +1,11 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include "../fs.h"
#include "../util.h"
bool rm_fflag = false, rm_rflag = false;
int rm_fflag = 0;
int rm_rflag = 0;
void
rm(const char *path)

17
wc.c
View File

@ -1,6 +1,5 @@
/* See LICENSE file for copyright and license details. */
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -10,8 +9,8 @@
static void output(const char *, long, long, long);
static void wc(FILE *, const char *);
static bool lflag = false;
static bool wflag = false;
static int lflag = 0;
static int wflag = 0;
static char cmode = 0;
static long tc = 0, tl = 0, tw = 0;
@ -35,10 +34,10 @@ main(int argc, char *argv[])
cmode = 'm';
break;
case 'l':
lflag = true;
lflag = 1;
break;
case 'w':
wflag = true;
wflag = 1;
break;
default:
usage();
@ -64,7 +63,7 @@ main(int argc, char *argv[])
void
output(const char *str, long nc, long nl, long nw)
{
bool noflags = !cmode && !lflag && !wflag;
int noflags = !cmode && !lflag && !wflag;
if (lflag || noflags)
printf(" %5ld", nl);
@ -80,7 +79,7 @@ output(const char *str, long nc, long nl, long nw)
void
wc(FILE *fp, const char *str)
{
bool word = false;
int word = 0;
int c;
long nc = 0, nl = 0, nw = 0;
@ -90,9 +89,9 @@ wc(FILE *fp, const char *str)
if (c == '\n')
nl++;
if (!isspace(c))
word = true;
word = 1;
else if (word) {
word = false;
word = 0;
nw++;
}
}