diff --git a/cal.c b/cal.c index 5b845fd..8b5244c 100644 --- a/cal.c +++ b/cal.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -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); } diff --git a/chmod.c b/chmod.c index e2a56de..4b2bc32 100644 --- a/chmod.c +++ b/chmod.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -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': /* diff --git a/chown.c b/chown.c index 906a2e8..066bd63 100644 --- a/chown.c +++ b/chown.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -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(); diff --git a/cmp.c b/cmp.c index 0d7e792..c9d38f3 100644 --- a/cmp.c +++ b/cmp.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -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; diff --git a/cols.c b/cols.c index 992d31a..9262ceb 100644 --- a/cols.c +++ b/cols.c @@ -1,6 +1,5 @@ /* See LICENSE file for copyright and license details. */ #include -#include #include #include #include diff --git a/comm.c b/comm.c index 29ffbe0..1864c9f 100644 --- a/comm.c +++ b/comm.c @@ -1,6 +1,5 @@ /* See LICENSE file for copyright and license details. */ #include -#include #include #include #include diff --git a/cp.c b/cp.c index 27b2011..f1c3d9b 100644 --- a/cp.c +++ b/cp.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include @@ -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(); diff --git a/cut.c b/cut.c index 5722bc5..c20a236 100644 --- a/cut.c +++ b/cut.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -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(); diff --git a/du.c b/du.c index b4421d0..46151ad 100644 --- a/du.c +++ b/du.c @@ -1,7 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include #include -#include #include #include #include @@ -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(); diff --git a/echo.c b/echo.c index 7ba5f05..6656ac4 100644 --- a/echo.c +++ b/echo.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include @@ -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(); diff --git a/expand.c b/expand.c index 3a51e86..aa88089 100644 --- a/expand.c +++ b/expand.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -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; } diff --git a/fold.c b/fold.c index 4f82d3a..92585af 100644 --- a/fold.c +++ b/fold.c @@ -1,6 +1,5 @@ /* See LICENSE file for copyright and license details. */ #include -#include #include #include #include @@ -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) diff --git a/fs.h b/fs.h index 2ac9574..18b7f4d 100644 --- a/fs.h +++ b/fs.h @@ -1,16 +1,14 @@ /* See LICENSE file for copyright and license details. */ -#include - -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 *); diff --git a/grep.c b/grep.c index 6a3951d..7352aae 100644 --- a/grep.c +++ b/grep.c @@ -1,6 +1,5 @@ /* See LICENSE file for copyright and license details. */ #include -#include #include #include #include @@ -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(); diff --git a/kill.c b/kill.c index 907eed6..04f86e2 100644 --- a/kill.c +++ b/kill.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include diff --git a/ln.c b/ln.c index 69e5b14..d8809ce 100644 --- a/ln.c +++ b/ln.c @@ -1,7 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include #include -#include #include #include #include @@ -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); diff --git a/ls.c b/ls.c index e4d7b20..2af7d45 100644 --- a/ls.c +++ b/ls.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -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; diff --git a/md5sum.c b/md5sum.c index 3f182df..0de1cb6 100644 --- a/md5sum.c +++ b/md5sum.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -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: diff --git a/mkdir.c b/mkdir.c index fed1bbf..ef31462 100644 --- a/mkdir.c +++ b/mkdir.c @@ -1,7 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include #include -#include #include #include #include @@ -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: diff --git a/mv.c b/mv.c index 81f778c..e705f40 100644 --- a/mv.c +++ b/mv.c @@ -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; diff --git a/paste.c b/paste.c index 997d308..918dea0 100644 --- a/paste.c +++ b/paste.c @@ -1,6 +1,5 @@ /* See LICENSE file for copyright and license details. */ #include -#include #include #include #include @@ -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()); diff --git a/readlink.c b/readlink.c index aa02d8f..2d6cc94 100644 --- a/readlink.c +++ b/readlink.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -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(); diff --git a/renice.c b/renice.c index cca6954..78ba233 100644 --- a/renice.c +++ b/renice.c @@ -1,17 +1,16 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include -#include #include #include #include +#include #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; } diff --git a/rm.c b/rm.c index 33958c1..a27dcb4 100644 --- a/rm.c +++ b/rm.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -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; diff --git a/seq.c b/seq.c index e165b2b..bff3af6 100644 --- a/seq.c +++ b/seq.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -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; } } diff --git a/sha1sum.c b/sha1sum.c index f6f9cf2..3438c7f 100644 --- a/sha1sum.c +++ b/sha1sum.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -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: diff --git a/sha256sum.c b/sha256sum.c index 943de2b..aa642a4 100644 --- a/sha256sum.c +++ b/sha256sum.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -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: diff --git a/sha512sum.c b/sha512sum.c index 83a5f27..ca835e8 100644 --- a/sha512sum.c +++ b/sha512sum.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -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: diff --git a/sort.c b/sort.c index 3da9ccf..5513442 100644 --- a/sort.c +++ b/sort.c @@ -1,6 +1,5 @@ /* See LICENSE file for copyright and license details. */ #include -#include #include #include #include @@ -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(); diff --git a/tar.c b/tar.c index 81634c1..65898d5 100644 --- a/tar.c +++ b/tar.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -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(); diff --git a/tee.c b/tee.c index 1c356aa..638e59f 100644 --- a/tee.c +++ b/tee.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -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(); diff --git a/test.c b/test.c index 0d771ef..ad2ca7d 100644 --- a/test.c +++ b/test.c @@ -1,6 +1,5 @@ /* See LICENSE file for copyright and license details. */ #include -#include #include #include #include @@ -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] == '[') diff --git a/touch.c b/touch.c index 0884ee9..90fa7db 100644 --- a/touch.c +++ b/touch.c @@ -1,7 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include #include -#include #include #include #include @@ -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); diff --git a/tr.c b/tr.c index 3c047fb..19598d3 100644 --- a/tr.c +++ b/tr.c @@ -1,6 +1,5 @@ /* See LICENSE file for copyright and license details. */ #include -#include #include #include #include diff --git a/uname.c b/uname.c index 12cff59..400ba2e 100644 --- a/uname.c +++ b/uname.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -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)) diff --git a/unexpand.c b/unexpand.c index 30ff57f..ecf6ba3 100644 --- a/unexpand.c +++ b/unexpand.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -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); diff --git a/uniq.c b/uniq.c index a9bbf99..7d4caba 100644 --- a/uniq.c +++ b/uniq.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -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); diff --git a/util/cp.c b/util/cp.c index be80a61..a5c3816 100644 --- a/util/cp.c +++ b/util/cp.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -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; diff --git a/util/putword.c b/util/putword.c index b5f3973..c460703 100644 --- a/util/putword.c +++ b/util/putword.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #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; } diff --git a/util/rm.c b/util/rm.c index ea84fa2..a89b11c 100644 --- a/util/rm.c +++ b/util/rm.c @@ -1,11 +1,11 @@ /* See LICENSE file for copyright and license details. */ -#include #include #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) diff --git a/wc.c b/wc.c index 2eb63ee..f2a7206 100644 --- a/wc.c +++ b/wc.c @@ -1,6 +1,5 @@ /* See LICENSE file for copyright and license details. */ #include -#include #include #include #include @@ -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++; } }