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

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] == '[')