summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorC. McEnroe <june@causal.agency>2018-11-12 22:37:15 -0500
committerC. McEnroe <june@causal.agency>2018-11-12 22:37:15 -0500
commit302196272521b66b71f2ab75cc3c9ea335ca5fff (patch)
tree54970ff525ebfe3053351ab97e41d580afca26e7
parentAdd \s sort binding and simplify \h and \a (diff)
downloadsrc-302196272521b66b71f2ab75cc3c9ea335ca5fff.tar.gz
src-302196272521b66b71f2ab75cc3c9ea335ca5fff.zip
Use typedefs uint and byte
-rw-r--r--bin/bri.c4
-rw-r--r--bin/hnel.c10
-rw-r--r--bin/modem.c7
-rw-r--r--bin/pbd.c6
-rw-r--r--bin/scheme.c47
-rw-r--r--bin/wake.c5
-rw-r--r--bin/xx.c13
7 files changed, 53 insertions, 39 deletions
diff --git a/bin/bri.c b/bin/bri.c
index 3e5ebf5e..7a076785 100644
--- a/bin/bri.c
+++ b/bin/bri.c
@@ -23,6 +23,8 @@
#include <sysexits.h>
#include <unistd.h>
+typedef unsigned uint;
+
static const char *Class = "/sys/class/backlight";
int main(int argc, char *argv[]) {
@@ -52,7 +54,7 @@ int main(int argc, char *argv[]) {
FILE *actual = fopen("actual_brightness", "r");
if (!actual) err(EX_OSFILE, "actual_brightness");
- unsigned value;
+ uint value;
int match = fscanf(actual, "%u", &value);
if (match == EOF) err(EX_IOERR, "actual_brightness");
if (match < 1) errx(EX_DATAERR, "actual_brightness");
diff --git a/bin/hnel.c b/bin/hnel.c
index 77332809..83f8dcb5 100644
--- a/bin/hnel.c
+++ b/bin/hnel.c
@@ -33,6 +33,8 @@
#include <util.h>
#endif
+typedef unsigned char byte;
+
static struct termios saveTerm;
static void restoreTerm(void) {
tcsetattr(STDIN_FILENO, TCSADRAIN, &saveTerm);
@@ -43,10 +45,10 @@ int main(int argc, char *argv[]) {
if (argc < 4) return EX_USAGE;
- char table[256] = {0};
+ byte table[256] = {0};
if (strlen(argv[1]) != strlen(argv[2])) return EX_USAGE;
for (const char *from = argv[1], *to = argv[2]; *from; ++from, ++to) {
- table[(unsigned)*from] = *to;
+ table[(byte)*from] = *to;
}
error = tcgetattr(STDERR_FILENO, &saveTerm);
@@ -73,7 +75,7 @@ int main(int argc, char *argv[]) {
bool enable = true;
- char buf[4096];
+ byte buf[4096];
struct pollfd fds[2] = {
{ .fd = STDIN_FILENO, .events = POLLIN },
{ .fd = pty, .events = POLLIN },
@@ -89,7 +91,7 @@ int main(int argc, char *argv[]) {
continue;
}
- unsigned char c = buf[0];
+ byte c = buf[0];
if (enable && table[c]) buf[0] = table[c];
}
diff --git a/bin/modem.c b/bin/modem.c
index f41cab45..f8733a2b 100644
--- a/bin/modem.c
+++ b/bin/modem.c
@@ -31,7 +31,10 @@
#include <util.h>
#endif
-static const int BaudRate = 19200;
+typedef unsigned uint;
+typedef unsigned char byte;
+
+static const uint BaudRate = 19200;
static struct termios saveTerm;
static void restoreTerm(void) {
@@ -65,7 +68,7 @@ int main(int argc, char *argv[]) {
err(EX_NOINPUT, "%s", argv[1]);
}
- char c;
+ byte c;
struct pollfd fds[2] = {
{ .events = POLLIN, .fd = STDIN_FILENO },
{ .events = POLLIN, .fd = pty },
diff --git a/bin/pbd.c b/bin/pbd.c
index 0d38334a..006281d1 100644
--- a/bin/pbd.c
+++ b/bin/pbd.c
@@ -27,6 +27,8 @@
#include <sysexits.h>
#include <unistd.h>
+typedef unsigned char byte;
+
static void spawn(const char *cmd, const char *arg, int dest, int src) {
pid_t pid = fork();
if (pid < 0) err(EX_OSERR, "fork");
@@ -106,7 +108,7 @@ static int pbdClient(char c) {
}
static void copy(int out, int in) {
- char buf[4096];
+ byte buf[4096];
ssize_t readSize;
while (0 < (readSize = read(in, buf, sizeof(buf)))) {
ssize_t writeSize = write(out, buf, readSize);
@@ -127,7 +129,7 @@ static int pbpaste(void) {
return EX_OK;
}
-static int open1(char *url) {
+static int open1(const char *url) {
if (!url) return EX_USAGE;
int client = pbdClient('o');
ssize_t size = write(client, url, strlen(url));
diff --git a/bin/scheme.c b/bin/scheme.c
index c7bec555..f4ef180d 100644
--- a/bin/scheme.c
+++ b/bin/scheme.c
@@ -25,6 +25,9 @@
#include <unistd.h>
#include <zlib.h>
+typedef unsigned uint;
+typedef unsigned char byte;
+
static const struct HSV { double h, s, v; }
R = { 0.0, 1.0, 1.0 },
Y = { 60.0, 1.0, 1.0 },
@@ -33,7 +36,7 @@ static const struct HSV { double h, s, v; }
B = { 240.0, 1.0, 1.0 },
M = { 300.0, 1.0, 1.0 };
-static struct RGB { uint8_t r, g, b; } toRGB(struct HSV hsv) {
+static struct RGB { byte r, g, b; } toRGB(struct HSV hsv) {
double c = hsv.v * hsv.s;
double h = hsv.h / 60.0;
double x = c * (1.0 - fabs(fmod(h, 2.0) - 1.0));
@@ -88,7 +91,7 @@ static void generate(void) {
scheme[Dark + Black] = x(scheme[Light + Black], 0.0, 1.0, 0.3);
scheme[Dark + White] = x(scheme[Light + White], 0.0, 1.0, 0.6);
- for (int i = Red; i < White; ++i) {
+ for (uint i = Red; i < White; ++i) {
scheme[Dark + i] = x(scheme[Light + i], 0.0, 1.0, 0.8);
}
@@ -99,7 +102,7 @@ static void generate(void) {
scheme[Cursor] = x(scheme[Dark + White], 0.0, 1.0, 0.8);
}
-static void swap(int a, int b) {
+static void swap(uint a, uint b) {
struct HSV t = scheme[a];
scheme[a] = scheme[b];
scheme[b] = t;
@@ -110,13 +113,13 @@ static void invert(void) {
swap(Light + Black, Dark + White);
}
-static void printHSV(int n) {
+static void printHSV(uint n) {
printf("%g,%g,%g\n", scheme[n].h, scheme[n].s, scheme[n].v);
}
-static void printRGB(int n) {
+static void printRGB(uint n) {
struct RGB rgb = toRGB(scheme[n]);
- printf("%02X%02X%02X\n", rgb.r, rgb.g, rgb.b);
+ printf("%02hhX%02hhX%02hhX\n", rgb.r, rgb.g, rgb.b);
}
static const char *CNames[SchemeLen] = {
@@ -145,17 +148,17 @@ static const char *CNames[SchemeLen] = {
static void printCHead(void) {
printf("enum {\n");
}
-static void printC(int n) {
+static void printC(uint n) {
struct RGB rgb = toRGB(scheme[n]);
- printf("\t%s = 0x%02X%02X%02X,\n", CNames[n], rgb.r, rgb.g, rgb.b);
+ printf("\t%s = 0x%02hhX%02hhX%02hhX,\n", CNames[n], rgb.r, rgb.g, rgb.b);
}
static void printCTail(void) {
printf("};\n");
}
-static void printLinux(int n) {
+static void printLinux(uint n) {
struct RGB rgb = toRGB(scheme[n]);
- printf("\x1B]P%X%02X%02X%02X", n, rgb.r, rgb.g, rgb.b);
+ printf("\x1B]P%X%02hhX%02hhX%02hhX", n, rgb.r, rgb.g, rgb.b);
}
static const char *MinttyNames[SchemeLen] = {
@@ -179,10 +182,10 @@ static const char *MinttyNames[SchemeLen] = {
[Foreground] = "ForegroundColour",
[Cursor] = "CursorColour",
};
-static void printMintty(int n) {
+static void printMintty(uint n) {
if (!MinttyNames[n]) return;
struct RGB rgb = toRGB(scheme[n]);
- printf("%s=%d,%d,%d\n", MinttyNames[n], rgb.r, rgb.g, rgb.b);
+ printf("%s=%hhd,%hhd,%hhd\n", MinttyNames[n], rgb.r, rgb.g, rgb.b);
}
static uint32_t crc;
@@ -201,7 +204,7 @@ static void pngChunk(const char *type, uint32_t size) {
pngWrite(type, 4);
}
-static void png(int at, int to) {
+static void png(uint at, uint to) {
if (to - at > 256) to = at + 256;
uint32_t len = to - at;
@@ -221,7 +224,7 @@ static void png(int at, int to) {
pngInt(crc);
pngChunk("PLTE", 3 * len);
- for (int i = at; i < to; ++i) {
+ for (uint i = at; i < to; ++i) {
struct RGB rgb = toRGB(scheme[i]);
pngWrite(&rgb, 3);
}
@@ -233,16 +236,16 @@ static void png(int at, int to) {
enum { None, Sub, Up, Average, Paeth };
data[y][0] = (y % swatchHeight) ? Up : Sub;
}
- for (int i = at; i < to; ++i) {
- int p = i - at;
+ for (uint i = at; i < to; ++i) {
+ uint p = i - at;
uint32_t y = swatchHeight * (p / cols);
uint32_t x = swatchWidth * (p % cols);
data[y][1 + x] = x ? 1 : p;
}
uLong size = compressBound(sizeof(data));
- uint8_t deflate[size];
- int error = compress(deflate, &size, (Byte *)data, sizeof(data));
+ byte deflate[size];
+ int error = compress(deflate, &size, (byte *)data, sizeof(data));
if (error != Z_OK) errx(EX_SOFTWARE, "compress: %d", error);
pngChunk("IDAT", size);
@@ -253,16 +256,16 @@ static void png(int at, int to) {
pngInt(crc);
}
-static void print(void (*fn)(int), int at, int to) {
- for (int i = at; i < to; ++i) {
+static void print(void (*fn)(uint), uint at, uint to) {
+ for (uint i = at; i < to; ++i) {
fn(i);
}
}
int main(int argc, char *argv[]) {
generate();
- int at = 0;
- int to = Background;
+ uint at = 0;
+ uint to = Background;
char out = 'x';
int opt;
diff --git a/bin/wake.c b/bin/wake.c
index cb5e5386..d1d66bb6 100644
--- a/bin/wake.c
+++ b/bin/wake.c
@@ -18,13 +18,14 @@
#include <err.h>
#include <netinet/in.h>
-#include <stdint.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sysexits.h>
+typedef unsigned char byte;
+
#define MAC 0x04, 0x7D, 0x7B, 0xD5, 0x6A, 0x53
-static const uint8_t Payload[102] = {
+static const byte Payload[102] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
MAC, MAC, MAC, MAC, MAC, MAC, MAC, MAC,
MAC, MAC, MAC, MAC, MAC, MAC, MAC, MAC,
diff --git a/bin/xx.c b/bin/xx.c
index ad62e924..654b0871 100644
--- a/bin/xx.c
+++ b/bin/xx.c
@@ -17,13 +17,14 @@
#include <ctype.h>
#include <err.h>
#include <stdbool.h>
-#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sysexits.h>
#include <unistd.h>
-static bool zero(const uint8_t *ptr, size_t size) {
+typedef unsigned char byte;
+
+static bool zero(const byte *ptr, size_t size) {
for (size_t i = 0; i < size; ++i) {
if (ptr[i]) return false;
}
@@ -41,7 +42,7 @@ static struct {
static void dump(FILE *file) {
bool skip = false;
- uint8_t buf[options.cols];
+ byte buf[options.cols];
size_t offset = 0;
for (
size_t size;
@@ -92,10 +93,10 @@ static void dump(FILE *file) {
}
static void undump(FILE *file) {
- uint8_t byte;
+ byte c;
int match;
- while (0 < (match = fscanf(file, " %hhx", &byte))) {
- printf("%c", byte);
+ while (0 < (match = fscanf(file, " %hhx", &c))) {
+ printf("%c", c);
}
if (!match) errx(EX_DATAERR, "invalid input");
}