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

View File

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

View File

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

13
cmp.c
View File

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

1
cols.c
View File

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

1
comm.c
View File

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

17
cp.c
View File

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

9
cut.c
View File

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

21
du.c
View File

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

5
echo.c
View File

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

View File

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

15
fold.c
View File

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

18
fs.h
View File

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

11
grep.c
View File

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

1
kill.c
View File

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

11
ln.c
View File

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

49
ls.c
View File

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

View File

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

View File

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

4
mv.c
View File

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

View File

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

View File

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

View File

@ -1,17 +1,16 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#include <sys/resource.h>
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#include <pwd.h> #include <pwd.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/resource.h>
#include "util.h" #include "util.h"
static int strtop(const char *); static int strtop(const char *);
static bool renice(int, int, long); static int renice(int, int, long);
static void static void
usage(void) usage(void)
@ -95,7 +94,7 @@ strtop(const char *s)
return (int)n; return (int)n;
} }
static bool static int
renice(int which, int who, long adj) renice(int which, int who, long adj)
{ {
errno = 0; errno = 0;
@ -103,15 +102,15 @@ renice(int which, int who, long adj)
if (errno != 0) { if (errno != 0) {
fprintf(stderr, "can't get %d nice level: %s\n", fprintf(stderr, "can't get %d nice level: %s\n",
who, strerror(errno)); who, strerror(errno));
return false; return 0;
} }
adj = MAX(-NZERO, MIN(adj, NZERO - 1)); adj = MAX(-NZERO, MIN(adj, NZERO - 1));
if (setpriority(which, who, (int)adj) == -1) { if (setpriority(which, who, (int)adj) == -1) {
fprintf(stderr, "can't set %d nice level: %s\n", fprintf(stderr, "can't set %d nice level: %s\n",
who, strerror(errno)); 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. */ /* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@ -19,18 +18,18 @@ main(int argc, char *argv[])
{ {
ARGBEGIN { ARGBEGIN {
case 'f': case 'f':
rm_fflag = true; rm_fflag = 1;
break; break;
case 'R': case 'R':
case 'r': case 'r':
rm_rflag = true; rm_rflag = 1;
break; break;
default: default:
usage(); usage();
} ARGEND; } ARGEND;
if (argc < 1) { if (argc < 1) {
if (rm_fflag == false) if (!rm_fflag)
usage(); usage();
else else
return 0; return 0;

11
seq.c
View File

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

View File

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

View File

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

View File

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

5
sort.c
View File

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

7
tar.c
View File

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

5
tee.c
View File

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

65
test.c
View File

@ -1,6 +1,5 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#include <errno.h> #include <errno.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -19,40 +18,40 @@ stoi(char *s, int *a)
enprintf(2, "bad integer %s\n", s); 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 int 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 int 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 int 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 int 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 int 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 int 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 int 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 int 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 int 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_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 int unary_n(char *s) { return strlen(s); }
static bool unary_z(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 int unary_e(char *s) { return access(s, F_OK); }
static bool unary_r(char *s) { return access(s, R_OK); } static int unary_r(char *s) { return access(s, R_OK); }
static bool unary_w(char *s) { return access(s, W_OK); } static int unary_w(char *s) { return access(s, W_OK); }
static bool unary_x(char *s) { return access(s, X_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 int 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_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 int 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 int 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 int 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 int 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 int 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_le(char *s1, char *s2) { int a, b; stoi(s1, &a); stoi(s2, &b); return a <= b; }
typedef struct { typedef struct {
char *name; char *name;
bool (*func)(); int (*func)();
} Test; } Test;
static Test unary[] = { static Test unary[] = {
@ -102,19 +101,19 @@ find_test(Test *tests, char *name)
return NULL; return NULL;
} }
static bool static int
noarg(char **argv) noarg(char **argv)
{ {
return 0; return 0;
} }
static bool static int
onearg(char **argv) onearg(char **argv)
{ {
return strlen(argv[0]); return strlen(argv[0]);
} }
static bool static int
twoarg(char **argv) twoarg(char **argv)
{ {
Test *t = find_test(unary, *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; return enprintf(2, "bad unary test %s\n", argv[0]), 0;
} }
static bool static int
threearg(char **argv) threearg(char **argv)
{ {
Test *t = find_test(binary, argv[1]); 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; return enprintf(2, "bad binary test %s\n", argv[1]), 0;
} }
static bool static int
fourarg(char **argv) fourarg(char **argv)
{ {
if (strcmp(argv[0], "!") == 0) if (strcmp(argv[0], "!") == 0)
@ -154,7 +153,7 @@ fourarg(char **argv)
int int
main(int argc, char **argv) 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]); int len = strlen(argv[0]);
if (len && argv[0][len - 1] == '[') if (len && argv[0][len - 1] == '[')

View File

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

1
tr.c
View File

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

25
uname.c
View File

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

View File

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

11
uniq.c
View File

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

View File

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

View File

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

View File

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

17
wc.c
View File

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