diff options
author | June McEnroe <june@causal.agency> | 2018-09-02 16:44:14 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2018-09-02 16:44:14 -0400 |
commit | cf3f3b186fc5306b090fbb3cd3da9139b22c936b (patch) | |
tree | 1d41937c2a6dea1cce5464cb3037fe88cb8d4460 /bin | |
parent | Remove colorcolumn at 100 (diff) | |
download | src-cf3f3b186fc5306b090fbb3cd3da9139b22c936b.tar.gz src-cf3f3b186fc5306b090fbb3cd3da9139b22c936b.zip |
Use PascalCase for constants
Get outta here, underscores.
Diffstat (limited to '')
-rw-r--r-- | bin/bri.c | 22 | ||||
-rw-r--r-- | bin/fbatt.c | 56 | ||||
-rw-r--r-- | bin/fbclock.c | 14 | ||||
-rw-r--r-- | bin/glitch.c | 86 | ||||
-rw-r--r-- | bin/klon.c | 94 | ||||
-rw-r--r-- | bin/modem.c | 4 | ||||
-rw-r--r-- | bin/pngo.c | 162 | ||||
-rw-r--r-- | bin/scheme.c | 88 | ||||
-rw-r--r-- | bin/wake.c | 4 |
9 files changed, 263 insertions, 267 deletions
diff --git a/bin/bri.c b/bin/bri.c index 52d4070c..3e5ebf5e 100644 --- a/bin/bri.c +++ b/bin/bri.c @@ -23,39 +23,39 @@ #include <sysexits.h> #include <unistd.h> -static const char *CLASS = "/sys/class/backlight"; +static const char *Class = "/sys/class/backlight"; int main(int argc, char *argv[]) { int error; const char *input = (argc > 1) ? argv[1] : NULL; - error = chdir(CLASS); - if (error) err(EX_OSFILE, "%s", CLASS); + error = chdir(Class); + if (error) err(EX_OSFILE, "%s", Class); DIR *dir = opendir("."); - if (!dir) err(EX_OSFILE, "%s", CLASS); + if (!dir) err(EX_OSFILE, "%s", Class); struct dirent *entry; while (NULL != (errno = 0, entry = readdir(dir))) { if (entry->d_name[0] == '.') continue; error = chdir(entry->d_name); - if (error) err(EX_OSFILE, "%s/%s", CLASS, entry->d_name); + if (error) err(EX_OSFILE, "%s/%s", Class, entry->d_name); break; } if (!entry) { - if (errno) err(EX_IOERR, "%s", CLASS); - errx(EX_CONFIG, "%s: empty", CLASS); + if (errno) err(EX_IOERR, "%s", Class); + errx(EX_CONFIG, "%s: empty", Class); } FILE *actual = fopen("actual_brightness", "r"); - if (!actual) err(EX_OSFILE, "%s/actual_brightness", CLASS); + if (!actual) err(EX_OSFILE, "actual_brightness"); unsigned value; int match = fscanf(actual, "%u", &value); - if (match == EOF) err(EX_IOERR, "%s/actual_brightness", CLASS); - if (match < 1) errx(EX_DATAERR, "%s/actual_brightness", CLASS); + if (match == EOF) err(EX_IOERR, "actual_brightness"); + if (match < 1) errx(EX_DATAERR, "actual_brightness"); if (!input) { printf("%u\n", value); @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) { } FILE *brightness = fopen("brightness", "w"); - if (!brightness) err(EX_OSFILE, "%s/brightness", CLASS); + if (!brightness) err(EX_OSFILE, "brightness"); int size = fprintf(brightness, "%u", value); if (size < 0) err(EX_IOERR, "brightness"); diff --git a/bin/fbatt.c b/bin/fbatt.c index 0f60e1da..c951cd21 100644 --- a/bin/fbatt.c +++ b/bin/fbatt.c @@ -29,23 +29,23 @@ #include "scheme.h" -static const char *CLASS = "/sys/class/power_supply"; +static const char *Class = "/sys/class/power_supply"; -static const uint32_t RIGHT = 5 * 8 + 1; // fbclock width. -static const uint32_t WIDTH = 8; -static const uint32_t HEIGHT = 16; +static const uint32_t Right = 5 * 8 + 1; // fbclock width. +static const uint32_t Width = 8; +static const uint32_t Height = 16; -static const uint32_t BG = SCHEME.darkBlack; -static const uint32_t BORDER = SCHEME.darkWhite; -static const uint32_t GRAY = SCHEME.lightBlack; -static const uint32_t YELLOW = SCHEME.darkYellow; -static const uint32_t RED = SCHEME.darkRed; +static const uint32_t BG = Scheme.darkBlack; +static const uint32_t Border = Scheme.darkWhite; +static const uint32_t Gray = Scheme.lightBlack; +static const uint32_t Yellow = Scheme.darkYellow; +static const uint32_t Red = Scheme.darkRed; int main() { int error; - DIR *dir = opendir(CLASS); - if (!dir) err(EX_OSFILE, "%s", CLASS); + DIR *dir = opendir(Class); + if (!dir) err(EX_OSFILE, "%s", Class); FILE *chargeFull = NULL; FILE *chargeNow = NULL; @@ -54,19 +54,19 @@ int main() { while (NULL != (errno = 0, entry = readdir(dir))) { if (entry->d_name[0] == '.') continue; - error = chdir(CLASS); - if (error) err(EX_OSFILE, "%s", CLASS); + error = chdir(Class); + if (error) err(EX_OSFILE, "%s", Class); error = chdir(entry->d_name); - if (error) err(EX_OSFILE, "%s/%s", CLASS, entry->d_name); + if (error) err(EX_OSFILE, "%s/%s", Class, entry->d_name); chargeFull = fopen("charge_full", "r"); chargeNow = fopen("charge_now", "r"); if (chargeFull && chargeNow) break; } if (!chargeFull || !chargeNow) { - if (errno) err(EX_OSFILE, "%s", CLASS); - errx(EX_CONFIG, "%s: empty", CLASS); + if (errno) err(EX_OSFILE, "%s", Class); + errx(EX_CONFIG, "%s: empty", Class); } closedir(dir); @@ -105,23 +105,23 @@ int main() { uint32_t height = 16 * now / full; for (int i = 0; i < 60; ++i, sleep(1)) { - uint32_t left = info.xres - RIGHT - WIDTH; + uint32_t left = info.xres - Right - Width; - for (uint32_t y = 0; y <= HEIGHT; ++y) { - buf[y * info.xres + left - 1] = BORDER; - buf[y * info.xres + left + WIDTH] = BORDER; + for (uint32_t y = 0; y <= Height; ++y) { + buf[y * info.xres + left - 1] = Border; + buf[y * info.xres + left + Width] = Border; } - for (uint32_t x = left; x < left + WIDTH; ++x) { - buf[HEIGHT * info.xres + x] = BORDER; + for (uint32_t x = left; x < left + Width; ++x) { + buf[Height * info.xres + x] = Border; } - for (uint32_t y = 0; y < HEIGHT; ++y) { - for (uint32_t x = left; x < left + WIDTH; ++x) { + for (uint32_t y = 0; y < Height; ++y) { + for (uint32_t x = left; x < left + Width; ++x) { buf[y * info.xres + x] = - (HEIGHT - 1 - y > height) ? BG - : (percent <= 10) ? RED - : (percent <= 30) ? YELLOW - : GRAY; + (Height - 1 - y > height) ? BG + : (percent <= 10) ? Red + : (percent <= 30) ? Yellow + : Gray; } } } diff --git a/bin/fbclock.c b/bin/fbclock.c index 20c7b6c6..942f2f43 100644 --- a/bin/fbclock.c +++ b/bin/fbclock.c @@ -30,8 +30,8 @@ #include "scheme.h" -static const uint32_t PSF2_MAGIC = 0x864AB572; -struct Psf2Header { +static const uint32_t PSF2Magic = 0x864AB572; +struct PSF2Header { uint32_t magic; uint32_t version; uint32_t headerSize; @@ -42,8 +42,8 @@ struct Psf2Header { uint32_t glyphWidth; }; -static const uint32_t BG = SCHEME.darkBlack; -static const uint32_t FG = SCHEME.darkWhite; +static const uint32_t BG = Scheme.darkBlack; +static const uint32_t FG = Scheme.darkWhite; int main() { size_t len; @@ -56,18 +56,18 @@ int main() { gzFile font = gzopen(fontPath, "r"); if (!font) err(EX_NOINPUT, "%s", fontPath); - struct Psf2Header header; + struct PSF2Header header; len = gzfread(&header, sizeof(header), 1, font); if (!len && gzeof(font)) errx(EX_DATAERR, "%s: missing header", fontPath); if (!len) errx(EX_IOERR, "%s", gzerror(font, NULL)); - if (header.magic != PSF2_MAGIC) { + if (header.magic != PSF2Magic) { errx( EX_DATAERR, "%s: invalid header magic %08X", fontPath, header.magic ); } - if (header.headerSize != sizeof(struct Psf2Header)) { + if (header.headerSize != sizeof(struct PSF2Header)) { errx( EX_DATAERR, "%s: weird header size %d", fontPath, header.headerSize diff --git a/bin/glitch.c b/bin/glitch.c index f62ee1fc..1faf25f6 100644 --- a/bin/glitch.c +++ b/bin/glitch.c @@ -47,20 +47,18 @@ static void writeExpect(const void *ptr, size_t size) { crc = crc32(crc, ptr, size); } -static const uint8_t SIGNATURE[8] = { - 0x89, 'P', 'N', 'G', '\r', '\n', 0x1A, '\n' -}; +static const uint8_t Signature[8] = "\x89PNG\r\n\x1A\n"; static void readSignature(void) { uint8_t signature[8]; readExpect(signature, 8, "signature"); - if (0 != memcmp(signature, SIGNATURE, 8)) { + if (0 != memcmp(signature, Signature, 8)) { errx(EX_DATAERR, "%s: invalid signature", path); } } static void writeSignature(void) { - writeExpect(SIGNATURE, sizeof(SIGNATURE)); + writeExpect(Signature, sizeof(Signature)); } struct PACKED Chunk { @@ -117,11 +115,11 @@ static struct PACKED { uint32_t height; uint8_t depth; enum PACKED { - GRAYSCALE = 0, - TRUECOLOR = 2, - INDEXED = 3, - GRAYSCALE_ALPHA = 4, - TRUECOLOR_ALPHA = 6, + Grayscale = 0, + Truecolor = 2, + Indexed = 3, + GrayscaleAlpha = 4, + TruecolorAlpha = 6, } color; uint8_t compression; uint8_t filter; @@ -131,11 +129,11 @@ static_assert(13 == sizeof(header), "header size"); static size_t lineSize(void) { switch (header.color) { - case GRAYSCALE: return (header.width * 1 * header.depth + 7) / 8; - case TRUECOLOR: return (header.width * 3 * header.depth + 7) / 8; - case INDEXED: return (header.width * 1 * header.depth + 7) / 8; - case GRAYSCALE_ALPHA: return (header.width * 2 * header.depth + 7) / 8; - case TRUECOLOR_ALPHA: return (header.width * 4 * header.depth + 7) / 8; + case Grayscale: return (header.width * 1 * header.depth + 7) / 8; + case Truecolor: return (header.width * 3 * header.depth + 7) / 8; + case Indexed: return (header.width * 1 * header.depth + 7) / 8; + case GrayscaleAlpha: return (header.width * 2 * header.depth + 7) / 8; + case TruecolorAlpha: return (header.width * 4 * header.depth + 7) / 8; default: abort(); } } @@ -260,12 +258,12 @@ static void writeEnd(void) { } enum PACKED Filter { - NONE, - SUB, - UP, - AVERAGE, - PAETH, - FILTER_COUNT, + None, + Sub, + Up, + Average, + Paeth, + FilterCount, }; static struct { @@ -302,22 +300,22 @@ static uint8_t paethPredictor(struct Bytes f) { static uint8_t recon(enum Filter type, struct Bytes f) { switch (type) { - case NONE: return f.x; - case SUB: return f.x + f.a; - case UP: return f.x + f.b; - case AVERAGE: return f.x + ((uint32_t)f.a + (uint32_t)f.b) / 2; - case PAETH: return f.x + paethPredictor(f); + case None: return f.x; + case Sub: return f.x + f.a; + case Up: return f.x + f.b; + case Average: return f.x + ((uint32_t)f.a + (uint32_t)f.b) / 2; + case Paeth: return f.x + paethPredictor(f); default: abort(); } } static uint8_t filt(enum Filter type, struct Bytes f) { switch (type) { - case NONE: return f.x; - case SUB: return f.x - f.a; - case UP: return f.x - f.b; - case AVERAGE: return f.x - ((uint32_t)f.a + (uint32_t)f.b) / 2; - case PAETH: return f.x - paethPredictor(f); + case None: return f.x; + case Sub: return f.x - f.a; + case Up: return f.x - f.b; + case Average: return f.x - ((uint32_t)f.a + (uint32_t)f.b) / 2; + case Paeth: return f.x - paethPredictor(f); default: abort(); } } @@ -334,7 +332,7 @@ static void scanlines(void) { size_t stride = 1 + lineSize(); for (uint32_t y = 0; y < header.height; ++y) { lines[y] = (struct Line *)&data[y * stride]; - if (lines[y]->type >= FILTER_COUNT) { + if (lines[y]->type >= FilterCount) { errx(EX_DATAERR, "%s: invalid filter type %hhu", path, lines[y]->type); } } @@ -361,16 +359,16 @@ static void reconData(void) { lines[y]->data[i] = recon(lines[y]->type, origBytes(y, i)); } } - lines[y]->type = NONE; + lines[y]->type = None; } } static void filterData(void) { for (uint32_t y = header.height - 1; y < header.height; --y) { - uint8_t filter[FILTER_COUNT][lineSize()]; - uint32_t heuristic[FILTER_COUNT] = {0}; - enum Filter minType = NONE; - for (enum Filter type = NONE; type < FILTER_COUNT; ++type) { + uint8_t filter[FilterCount][lineSize()]; + uint32_t heuristic[FilterCount] = {0}; + enum Filter minType = None; + for (enum Filter type = None; type < FilterCount; ++type) { for (size_t i = 0; i < lineSize(); ++i) { if (options.recon) { filter[type][i] = recon(type, origBytes(y, i)); @@ -419,7 +417,7 @@ static void glitch(const char *inPath, const char *outPath) { readSignature(); readHeader(); - if (header.color == INDEXED) readPalette(); + if (header.color == Indexed) readPalette(); readData(); fclose(file); @@ -440,7 +438,7 @@ static void glitch(const char *inPath, const char *outPath) { writeSignature(); writeHeader(); - if (header.color == INDEXED) writePalette(); + if (header.color == Indexed) writePalette(); writeData(); writeEnd(); free(data); @@ -451,11 +449,11 @@ static void glitch(const char *inPath, const char *outPath) { static enum Filter parseFilter(const char *s) { switch (s[0]) { - case 'N': case 'n': return NONE; - case 'S': case 's': return SUB; - case 'U': case 'u': return UP; - case 'A': case 'a': return AVERAGE; - case 'P': case 'p': return PAETH; + case 'N': case 'n': return None; + case 'S': case 's': return Sub; + case 'U': case 'u': return Up; + case 'A': case 'a': return Average; + case 'P': case 'p': return Paeth; default: errx(EX_USAGE, "invalid filter type %s", s); } } diff --git a/bin/klon.c b/bin/klon.c index 878f7f6d..548a505b 100644 --- a/bin/klon.c +++ b/bin/klon.c @@ -26,18 +26,18 @@ typedef uint8_t Card; enum { - MASK_RANK = 0x0F, - MASK_SUIT = 0x30, - MASK_COLOR = 0x10, - MASK_UP = 0x40, - MASK_SELECT = 0x80, + MaskRank = 0x0F, + MaskSuit = 0x30, + MaskColor = 0x10, + MaskUp = 0x40, + MaskSelect = 0x80, }; enum { - SUIT_CLUB = 0x00, - SUIT_DIAMOND = 0x10, - SUIT_SPADE = 0x20, - SUIT_HEART = 0x30, + SuitClub = 0x00, + SuitDiamond = 0x10, + SuitSpade = 0x20, + SuitHeart = 0x30, }; struct Stack { @@ -123,21 +123,21 @@ static void deal(void) { static void reveal(void) { for (int i = 0; i < 7; ++i) { if (get(&g.table[i], 0)) { - push(&g.table[i], pop(&g.table[i]) | MASK_UP); + push(&g.table[i], pop(&g.table[i]) | MaskUp); } } } static void draw(void) { - if (get(&g.stock, 0)) push(&g.waste, pop(&g.stock) | MASK_UP); - if (get(&g.stock, 0)) push(&g.waste, pop(&g.stock) | MASK_UP); - if (get(&g.stock, 0)) push(&g.waste, pop(&g.stock) | MASK_UP); + if (get(&g.stock, 0)) push(&g.waste, pop(&g.stock) | MaskUp); + if (get(&g.stock, 0)) push(&g.waste, pop(&g.stock) | MaskUp); + if (get(&g.stock, 0)) push(&g.waste, pop(&g.stock) | MaskUp); } static void wasted(void) { uint8_t n = len(&g.waste); for (int i = 0; i < n; ++i) { - push(&g.stock, pop(&g.waste) & ~MASK_UP); + push(&g.stock, pop(&g.waste) & ~MaskUp); } } @@ -152,22 +152,22 @@ static void transfer(struct Stack *dest, struct Stack *src, uint8_t n) { } static bool canFound(const struct Stack *found, Card card) { - if (!get(found, 0)) return (card & MASK_RANK) == 1; - if ((card & MASK_SUIT) != (get(found, 0) & MASK_SUIT)) return false; - return (card & MASK_RANK) == (get(found, 0) & MASK_RANK) + 1; + if (!get(found, 0)) return (card & MaskRank) == 1; + if ((card & MaskSuit) != (get(found, 0) & MaskSuit)) return false; + return (card & MaskRank) == (get(found, 0) & MaskRank) + 1; } static bool canTable(const struct Stack *table, Card card) { - if (!get(table, 0)) return (card & MASK_RANK) == 13; - if ((card & MASK_COLOR) == (get(table, 0) & MASK_COLOR)) return false; - return (card & MASK_RANK) == (get(table, 0) & MASK_RANK) - 1; + if (!get(table, 0)) return (card & MaskRank) == 13; + if ((card & MaskColor) == (get(table, 0) & MaskColor)) return false; + return (card & MaskRank) == (get(table, 0) & MaskRank) - 1; } enum { - PAIR_EMPTY = 1, - PAIR_BACK, - PAIR_BLACK, - PAIR_RED, + PairEmpty = 1, + PairBack, + PairBlack, + PairRed, }; static void curse(void) { @@ -182,44 +182,44 @@ static void curse(void) { start_color(); assume_default_colors(-1, -1); - init_pair(PAIR_EMPTY, COLOR_WHITE, COLOR_BLACK); - init_pair(PAIR_BACK, COLOR_WHITE, COLOR_BLUE); - init_pair(PAIR_BLACK, COLOR_BLACK, COLOR_WHITE); - init_pair(PAIR_RED, COLOR_RED, COLOR_WHITE); + init_pair(PairEmpty, COLOR_WHITE, COLOR_BLACK); + init_pair(PairBack, COLOR_WHITE, COLOR_BLUE); + init_pair(PairBlack, COLOR_BLACK, COLOR_WHITE); + init_pair(PairRed, COLOR_RED, COLOR_WHITE); } -static const char rank[] = "\0A23456789TJQK"; -static const char *suit[] = { - [SUIT_HEART] = "♥", - [SUIT_CLUB] = "♣", - [SUIT_DIAMOND] = "♦", - [SUIT_SPADE] = "♠", +static const char Rank[] = "\0A23456789TJQK"; +static const char *Suit[] = { + [SuitHeart] = "♥", + [SuitClub] = "♣", + [SuitDiamond] = "♦", + [SuitSpade] = "♠", }; static void renderCard(int y, int x, Card card) { - if (card & MASK_UP) { + if (card & MaskUp) { bkgdset( - COLOR_PAIR(card & MASK_COLOR ? PAIR_RED : PAIR_BLACK) - | (card & MASK_SELECT ? A_REVERSE : A_NORMAL) + COLOR_PAIR(card & MaskColor ? PairRed : PairBlack) + | (card & MaskSelect ? A_REVERSE : A_NORMAL) ); move(y, x); - addch(rank[card & MASK_RANK]); - addstr(suit[card & MASK_SUIT]); + addch(Rank[card & MaskRank]); + addstr(Suit[card & MaskSuit]); addch(' '); move(y + 1, x); - addstr(suit[card & MASK_SUIT]); + addstr(Suit[card & MaskSuit]); addch(' '); - addstr(suit[card & MASK_SUIT]); + addstr(Suit[card & MaskSuit]); move(y + 2, x); addch(' '); - addstr(suit[card & MASK_SUIT]); - addch(rank[card & MASK_RANK]); + addstr(Suit[card & MaskSuit]); + addch(Rank[card & MaskRank]); } else { - bkgdset(COLOR_PAIR(card ? PAIR_BACK : PAIR_EMPTY)); + bkgdset(COLOR_PAIR(card ? PairBack : PairEmpty)); mvaddstr(y, x, " "); mvaddstr(y + 1, x, " "); mvaddstr(y + 2, x, " "); @@ -266,8 +266,8 @@ static struct { static void deepen(void) { assert(input.stack); if (input.depth == len(input.stack)) return; - if (!(get(input.stack, input.depth) & MASK_UP)) return; - input.stack->data[input.stack->index + input.depth] |= MASK_SELECT; + if (!(get(input.stack, input.depth) & MaskUp)) return; + input.stack->data[input.stack->index + input.depth] |= MaskSelect; input.depth++; } @@ -281,7 +281,7 @@ static void select(struct Stack *stack) { static void commit(struct Stack *dest) { assert(input.stack); for (int i = 0; i < input.depth; ++i) { - input.stack->data[input.stack->index + i] &= ~MASK_SELECT; + input.stack->data[input.stack->index + i] &= ~MaskSelect; } if (dest) { checkpoint(); diff --git a/bin/modem.c b/bin/modem.c index 394ebb72..f41cab45 100644 --- a/bin/modem.c +++ b/bin/modem.c @@ -31,7 +31,7 @@ #include <util.h> #endif -static const int BAUD_RATE = 19200; +static const int BaudRate = 19200; static struct termios saveTerm; static void restoreTerm(void) { @@ -70,7 +70,7 @@ int main(int argc, char *argv[]) { { .events = POLLIN, .fd = STDIN_FILENO }, { .events = POLLIN, .fd = pty }, }; - while (usleep(8 * 1000000 / BAUD_RATE), 0 < poll(fds, 2, -1)) { + while (usleep(8 * 1000000 / BaudRate), 0 < poll(fds, 2, -1)) { if (fds[0].revents) { ssize_t size = read(STDIN_FILENO, &c, 1); if (size < 0) err(EX_IOERR, "read(%d)", STDIN_FILENO); diff --git a/bin/pngo.c b/bin/pngo.c index 76898b68..a6d036c3 100644 --- a/bin/pngo.c +++ b/bin/pngo.c @@ -49,20 +49,18 @@ static void writeExpect(const void *ptr, size_t size) { crc = crc32(crc, ptr, size); } -static const uint8_t SIGNATURE[8] = { - 0x89, 'P', 'N', 'G', '\r', '\n', 0x1A, '\n' -}; +static const uint8_t Signature[8] = "\x89PNG\r\n\x1A\n"; static void readSignature(void) { uint8_t signature[8]; readExpect(signature, 8, "signature"); - if (0 != memcmp(signature, SIGNATURE, 8)) { + if (0 != memcmp(signature, Signature, 8)) { errx(EX_DATAERR, "%s: invalid signature", path); } } static void writeSignature(void) { - writeExpect(SIGNATURE, sizeof(SIGNATURE)); + writeExpect(Signature, sizeof(Signature)); } struct PACKED Chunk { @@ -122,25 +120,25 @@ static struct PACKED { uint32_t height; uint8_t depth; enum PACKED { - GRAYSCALE = 0, - TRUECOLOR = 2, - INDEXED = 3, - GRAYSCALE_ALPHA = 4, - TRUECOLOR_ALPHA = 6, + Grayscale = 0, + Truecolor = 2, + Indexed = 3, + GrayscaleAlpha = 4, + TruecolorAlpha = 6, } color; - enum PACKED { DEFLATE } compression; - enum PACKED { ADAPTIVE } filter; - enum PACKED { PROGRESSIVE, ADAM7 } interlace; + enum PACKED { Deflate } compression; + enum PACKED { Adaptive } filter; + enum PACKED { Progressive, Adam7 } interlace; } header; static_assert(13 == sizeof(header), "header size"); static size_t lineSize(void) { switch (header.color) { - case GRAYSCALE: return (header.width * 1 * header.depth + 7) / 8; - case TRUECOLOR: return (header.width * 3 * header.depth + 7) / 8; - case INDEXED: return (header.width * 1 * header.depth + 7) / 8; - case GRAYSCALE_ALPHA: return (header.width * 2 * header.depth + 7) / 8; - case TRUECOLOR_ALPHA: return (header.width * 4 * header.depth + 7) / 8; + case Grayscale: return (header.width * 1 * header.depth + 7) / 8; + case Truecolor: return (header.width * 3 * header.depth + 7) / 8; + case Indexed: return (header.width * 1 * header.depth + 7) / 8; + case GrayscaleAlpha: return (header.width * 2 * header.depth + 7) / 8; + case TruecolorAlpha: return (header.width * 4 * header.depth + 7) / 8; default: abort(); } } @@ -149,12 +147,12 @@ static size_t dataSize(void) { return (1 + lineSize()) * header.height; } -static const char *COLOR_STR[] = { - [GRAYSCALE] = "grayscale", - [TRUECOLOR] = "truecolor", - [INDEXED] = "indexed", - [GRAYSCALE_ALPHA] = "grayscale alpha", - [TRUECOLOR_ALPHA] = "truecolor alpha", +static const char *ColorStr[] = { + [Grayscale] = "grayscale", + [Truecolor] = "truecolor", + [Indexed] = "indexed", + [GrayscaleAlpha] = "grayscale alpha", + [TruecolorAlpha] = "truecolor alpha", }; static void printHeader(void) { fprintf( @@ -162,7 +160,7 @@ static void printHeader(void) { "%s: %ux%u %hhu-bit %s\n", path, header.width, header.height, - header.depth, COLOR_STR[header.color] + header.depth, ColorStr[header.color] ); } @@ -186,21 +184,21 @@ static void readHeader(void) { if (!header.width) errx(EX_DATAERR, "%s: invalid width 0", path); if (!header.height) errx(EX_DATAERR, "%s: invalid height 0", path); switch (PAIR(header.color, header.depth)) { - case PAIR(GRAYSCALE, 1): - case PAIR(GRAYSCALE, 2): - case PAIR(GRAYSCALE, 4): - case PAIR(GRAYSCALE, 8): - case PAIR(GRAYSCALE, 16): - case PAIR(TRUECOLOR, 8): - case PAIR(TRUECOLOR, 16): - case PAIR(INDEXED, 1): - case PAIR(INDEXED, 2): - case PAIR(INDEXED, 4): - case PAIR(INDEXED, 8): - case PAIR(GRAYSCALE_ALPHA, 8): - case PAIR(GRAYSCALE_ALPHA, 16): - case PAIR(TRUECOLOR_ALPHA, 8): - case PAIR(TRUECOLOR_ALPHA, 16): + case PAIR(Grayscale, 1): + case PAIR(Grayscale, 2): + case PAIR(Grayscale, 4): + case PAIR(Grayscale, 8): + case PAIR(Grayscale, 16): + case PAIR(Truecolor, 8): + case PAIR(Truecolor, 16): + case PAIR(Indexed, 1): + case PAIR(Indexed, 2): + case PAIR(Indexed, 4): + case PAIR(Indexed, 8): + case PAIR(GrayscaleAlpha, 8): + case PAIR(GrayscaleAlpha, 16): + case PAIR(TruecolorAlpha, 8): + case PAIR(TruecolorAlpha, 16): break; default: errx( @@ -208,16 +206,16 @@ static void readHeader(void) { path, header.color, header.depth ); } - if (header.compression != DEFLATE) { + if (header.compression != Deflate) { errx( EX_DATAERR, "%s: invalid compression method %hhu", path, header.compression ); } - if (header.filter != ADAPTIVE) { + if (header.filter != Adaptive) { errx(EX_DATAERR, "%s: invalid filter method %hhu", path, header.filter); } - if (header.interlace > ADAM7) { + if (header.interlace > Adam7) { errx(EX_DATAERR, "%s: invalid interlace method %hhu", path, header.interlace); } @@ -357,12 +355,12 @@ static void writeEnd(void) { } enum PACKED Filter { - NONE, - SUB, - UP, - AVERAGE, - PAETH, - FILTER_COUNT, + None, + Sub, + Up, + Average, + Paeth, + FilterCount, }; struct Bytes { @@ -384,22 +382,22 @@ static uint8_t paethPredictor(struct Bytes f) { static uint8_t recon(enum Filter type, struct Bytes f) { switch (type) { - case NONE: return f.x; - case SUB: return f.x + f.a; - case UP: return f.x + f.b; - case AVERAGE: return f.x + ((uint32_t)f.a + (uint32_t)f.b) / 2; - case PAETH: return f.x + paethPredictor(f); + case None: return f.x; + case Sub: return f.x + f.a; + case Up: return f.x + f.b; + case Average: return f.x + ((uint32_t)f.a + (uint32_t)f.b) / 2; + case Paeth: return f.x + paethPredictor(f); default: abort(); } } static uint8_t filt(enum Filter type, struct Bytes f) { switch (type) { - case NONE: return f.x; - case SUB: return f.x - f.a; - case UP: return f.x - f.b; - case AVERAGE: return f.x - ((uint32_t)f.a + (uint32_t)f.b) / 2; - case PAETH: return f.x - paethPredictor(f); + case None: return f.x; + case Sub: return f.x - f.a; + case Up: return f.x - f.b; + case Average: return f.x - ((uint32_t)f.a + (uint32_t)f.b) / 2; + case Paeth: return f.x - paethPredictor(f); default: abort(); } } @@ -418,7 +416,7 @@ static void scanlines(void) { size_t stride = 1 + lineSize(); for (uint32_t y = 0; y < header.height; ++y) { lines[y] = (struct Line *)&data[y * stride]; - if (lines[y]->type >= FILTER_COUNT) { + if (lines[y]->type >= FilterCount) { errx(EX_DATAERR, "%s: invalid filter type %hhu", path, lines[y]->type); } } @@ -442,17 +440,17 @@ static void reconData(void) { lines[y]->data[i] = recon(lines[y]->type, origBytes(y, i)); } - lines[y]->type = NONE; + lines[y]->type = None; } } static void filterData(void) { - if (header.color == INDEXED || header.depth < 8) return; + if (header.color == Indexed || header.depth < 8) return; for (uint32_t y = header.height - 1; y < header.height; --y) { - uint8_t filter[FILTER_COUNT][lineSize()]; - uint32_t heuristic[FILTER_COUNT] = {0}; - enum Filter minType = NONE; - for (enum Filter type = NONE; type < FILTER_COUNT; ++type) { + uint8_t filter[FilterCount][lineSize()]; + uint32_t heuristic[FilterCount] = {0}; + enum Filter minType = None; + for (enum Filter type = None; type < FilterCount; ++type) { for (size_t i = 0; i < lineSize(); ++i) { filter[type][i] = filt(type, origBytes(y, i)); heuristic[type] += abs((int8_t)filter[type][i]); @@ -465,9 +463,9 @@ static void filterData(void) { } static void discardAlpha(void) { - if (header.color != GRAYSCALE_ALPHA && header.color != TRUECOLOR_ALPHA) return; + if (header.color != GrayscaleAlpha && header.color != TruecolorAlpha) return; size_t sampleSize = header.depth / 8; - size_t pixelSize = sampleSize * (header.color == GRAYSCALE_ALPHA ? 2 : 4); + size_t pixelSize = sampleSize * (header.color == GrayscaleAlpha ? 2 : 4); size_t colorSize = pixelSize - sampleSize; for (uint32_t y = 0; y < header.height; ++y) { for (uint32_t x = 0; x < header.width; ++x) { @@ -485,14 +483,14 @@ static void discardAlpha(void) { ptr += colorSize; } } - header.color = (header.color == GRAYSCALE_ALPHA) ? GRAYSCALE : TRUECOLOR; + header.color = (header.color == GrayscaleAlpha) ? Grayscale : Truecolor; scanlines(); } static void discardColor(void) { - if (header.color != TRUECOLOR && header.color != TRUECOLOR_ALPHA) return; + if (header.color != Truecolor && header.color != TruecolorAlpha) return; size_t sampleSize = header.depth / 8; - size_t pixelSize = sampleSize * (header.color == TRUECOLOR ? 3 : 4); + size_t pixelSize = sampleSize * (header.color == Truecolor ? 3 : 4); for (uint32_t y = 0; y < header.height; ++y) { for (uint32_t x = 0; x < header.width; ++x) { uint8_t *r = &lines[y]->data[x * pixelSize]; @@ -510,18 +508,18 @@ static void discardColor(void) { uint8_t *pixel = &lines[y]->data[x * pixelSize]; memmove(ptr, pixel, sampleSize); ptr += sampleSize; - if (header.color == TRUECOLOR_ALPHA) { + if (header.color == TruecolorAlpha) { memmove(ptr, pixel + 3 * sampleSize, sampleSize); ptr += sampleSize; } } } - header.color = (header.color == TRUECOLOR) ? GRAYSCALE : GRAYSCALE_ALPHA; + header.color = (header.color == Truecolor) ? Grayscale : GrayscaleAlpha; scanlines(); } static void indexColor(void) { - if (header.color != TRUECOLOR || header.depth != 8) return; + if (header.color != Truecolor || header.depth != 8) return; for (uint32_t y = 0; y < header.height; ++y) { for (uint32_t x = 0; x < header.width; ++x) { if (!paletteAdd(&lines[y]->data[x * 3])) return; @@ -535,14 +533,14 @@ static void indexColor(void) { *ptr++ = paletteIndex(&lines[y]->data[x * 3]); } } - header.color = INDEXED; + header.color = Indexed; scanlines(); } static void reduceDepth8(void) { - if (header.color != GRAYSCALE && header.color != INDEXED) return; + if (header.color != Grayscale && header.color != Indexed) return; if (header.depth != 8) return; - if (header.color == GRAYSCALE) { + if (header.color == Grayscale) { for (uint32_t y = 0; y < header.height; ++y) { for (size_t i = 0; i < lineSize(); ++i) { uint8_t a = lines[y]->data[i]; @@ -570,7 +568,7 @@ static void reduceDepth8(void) { static void reduceDepth4(void) { if (header.depth != 4) return; - if (header.color == GRAYSCALE) { + if (header.color == Grayscale) { for (uint32_t y = 0; y < header.height; ++y) { for (size_t i = 0; i < lineSize(); ++i) { uint8_t a = lines[y]->data[i] >> 4; @@ -600,7 +598,7 @@ static void reduceDepth4(void) { static void reduceDepth2(void) { if (header.depth != 2) return; - if (header.color == GRAYSCALE) { + if (header.color == Grayscale) { for (uint32_t y = 0; y < header.height; ++y) { for (size_t i = 0; i < lineSize(); ++i) { uint8_t a = lines[y]->data[i] >> 6; @@ -652,13 +650,13 @@ static void optimize(const char *inPath, const char *outPath) { readSignature(); readHeader(); - if (header.interlace != PROGRESSIVE) { + if (header.interlace != Progressive) { errx( EX_CONFIG, "%s: unsupported interlace method %hhu", path, header.interlace ); } - if (header.color == INDEXED) readPalette(); + if (header.color == Indexed) readPalette(); allocData(); readData(); fclose(file); @@ -685,7 +683,7 @@ static void optimize(const char *inPath, const char *outPath) { writeSignature(); writeHeader(); - if (header.color == INDEXED) writePalette(); + if (header.color == Indexed) writePalette(); writeData(); writeEnd(); free(data); diff --git a/bin/scheme.c b/bin/scheme.c index 00cb9581..8f8243bd 100644 --- a/bin/scheme.c +++ b/bin/scheme.c @@ -59,7 +59,7 @@ static struct Rgb { return (struct Rgb) { r * 255.0, g * 255.0, b * 255.0 }; } -enum { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE }; +enum { Black, Red, Green, Yellow, Blue, Magenta, Cyan, White }; static struct { struct Hsv dark[8]; struct Hsv light[8]; @@ -67,36 +67,36 @@ static struct { } scheme; static void generate(void) { - scheme.light[BLACK] = x(R, +45.0, 0.3, 0.3); - scheme.light[RED] = x(R, +10.0, 0.9, 0.8); - scheme.light[GREEN] = x(G, -55.0, 0.8, 0.6); - scheme.light[YELLOW] = x(Y, -20.0, 0.8, 0.8); - scheme.light[BLUE] = x(B, -55.0, 0.4, 0.5); - scheme.light[MAGENTA] = x(M, +45.0, 0.4, 0.6); - scheme.light[CYAN] = x(C, -60.0, 0.3, 0.6); - scheme.light[WHITE] = x(R, +45.0, 0.3, 0.8); + scheme.light[Black] = x(R, +45.0, 0.3, 0.3); + scheme.light[Red] = x(R, +10.0, 0.9, 0.8); + scheme.light[Green] = x(G, -55.0, 0.8, 0.6); + scheme.light[Yellow] = x(Y, -20.0, 0.8, 0.8); + scheme.light[Blue] = x(B, -55.0, 0.4, 0.5); + scheme.light[Magenta] = x(M, +45.0, 0.4, 0.6); + scheme.light[Cyan] = x(C, -60.0, 0.3, 0.6); + scheme.light[White] = x(R, +45.0, 0.3, 0.8); - 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) { + 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) { scheme.dark[i] = x(scheme.light[i], 0.0, 1.0, 0.8); } - scheme.background = x(scheme.dark[BLACK], 0.0, 1.0, 0.9); - scheme.text = x(scheme.light[WHITE], 0.0, 1.0, 0.9); - scheme.bold = x(scheme.light[WHITE], 0.0, 1.0, 1.0); - scheme.selection = x(scheme.light[RED], +10.0, 1.0, 0.8); - scheme.cursor = x(scheme.dark[WHITE], 0.0, 1.0, 0.8); + scheme.background = x(scheme.dark[Black], 0.0, 1.0, 0.9); + scheme.text = x(scheme.light[White], 0.0, 1.0, 0.9); + scheme.bold = x(scheme.light[White], 0.0, 1.0, 1.0); + scheme.selection = x(scheme.light[Red], +10.0, 1.0, 0.8); + scheme.cursor = x(scheme.dark[White], 0.0, 1.0, 0.8); } static void printHsv(struct Hsv hsv) { printf("%g,%g,%g\n", hsv.h, hsv.s, hsv.v); } static void hsv(bool ansi) { - for (int i = BLACK; i <= WHITE; ++i) { + for (int i = Black; i <= White; ++i) { printHsv(scheme.dark[i]); } - for (int i = BLACK; i <= WHITE; ++i) { + for (int i = Black; i <= White; ++i) { printHsv(scheme.light[i]); } if (ansi) return; @@ -112,10 +112,10 @@ static void printHex(struct Hsv hsv) { printf("%02X%02X%02X\n", rgb.r, rgb.g, rgb.b); } static void hex(bool ansi) { - for (int i = BLACK; i <= WHITE; ++i) { + for (int i = Black; i <= White; ++i) { printHex(scheme.dark[i]); } - for (int i = BLACK; i <= WHITE; ++i) { + for (int i = Black; i <= White; ++i) { printHex(scheme.light[i]); } if (ansi) return; @@ -140,12 +140,12 @@ static void header(void) { "\tuint32_t lightBlack, lightRed, lightGreen, lightYellow;\n" "\tuint32_t lightBlue, lightMagenta, lightCyan, lightWhite;\n" "\tuint32_t background, text, bold, selection, cursor;\n" - "} SCHEME = {\n" + "} Scheme = {\n" ); - for (int i = BLACK; i <= WHITE; ++i) { + for (int i = Black; i <= White; ++i) { printC(scheme.dark[i]); } - for (int i = BLACK; i <= WHITE; ++i) { + for (int i = Black; i <= White; ++i) { printC(scheme.light[i]); } printC(scheme.background); @@ -157,11 +157,11 @@ static void header(void) { } static void console(void) { - for (int i = BLACK; i <= WHITE; ++i) { + for (int i = Black; i <= White; ++i) { struct Rgb rgb = toRgb(scheme.dark[i]); printf("\x1B]P%X%02X%02X%02X", i, rgb.r, rgb.g, rgb.b); } - for (int i = BLACK; i <= WHITE; ++i) { + for (int i = Black; i <= White; ++i) { struct Rgb rgb = toRgb(scheme.dark[i]); printf("\x1B]P%X%02X%02X%02X", 8 + i, rgb.r, rgb.g, rgb.b); } @@ -172,23 +172,23 @@ static void printMintty(const char *key, struct Hsv hsv) { printf("%s=%d,%d,%d\n", key, rgb.r, rgb.g, rgb.b); } static void mintty(void) { - printMintty("Black", scheme.dark[BLACK]); - printMintty("Red", scheme.dark[RED]); - printMintty("Green", scheme.dark[GREEN]); - printMintty("Yellow", scheme.dark[YELLOW]); - printMintty("Blue", scheme.dark[BLUE]); - printMintty("Magenta", scheme.dark[MAGENTA]); - printMintty("Cyan", scheme.dark[CYAN]); - printMintty("White", scheme.dark[WHITE]); + printMintty("Black", scheme.dark[Black]); + printMintty("Red", scheme.dark[Red]); + printMintty("Green", scheme.dark[Green]); + printMintty("Yellow", scheme.dark[Yellow]); + printMintty("Blue", scheme.dark[Blue]); + printMintty("Magenta", scheme.dark[Magenta]); + printMintty("Cyan", scheme.dark[Cyan]); + printMintty("White", scheme.dark[White]); - printMintty("BoldBlack", scheme.light[BLACK]); - printMintty("BoldRed", scheme.light[RED]); - printMintty("BoldGreen", scheme.light[GREEN]); - printMintty("BoldYellow", scheme.light[YELLOW]); - printMintty("BoldBlue", scheme.light[BLUE]); - printMintty("BoldMagenta", scheme.light[MAGENTA]); - printMintty("BoldCyan", scheme.light[CYAN]); - printMintty("BoldWhite", scheme.light[WHITE]); + printMintty("BoldBlack", scheme.light[Black]); + printMintty("BoldRed", scheme.light[Red]); + printMintty("BoldGreen", scheme.light[Green]); + printMintty("BoldYellow", scheme.light[Yellow]); + printMintty("BoldBlue", scheme.light[Blue]); + printMintty("BoldMagenta", scheme.light[Magenta]); + printMintty("BoldCyan", scheme.light[Cyan]); + printMintty("BoldWhite", scheme.light[White]); printMintty("BackgroundColour", scheme.background); printMintty("ForegroundColour", scheme.text); @@ -238,8 +238,8 @@ static void png(const struct Hsv *hsv, size_t len) { uint8_t data[height][1 + width]; memset(data, 0, sizeof(data)); for (uint32_t y = 0; y < height; ++y) { - enum { NONE, SUB, UP, AVERAGE, PAETH }; - data[y][0] = (y % swatchHeight) ? UP : SUB; + enum { None, Sub, Up, Average, Paeth }; + data[y][0] = (y % swatchHeight) ? Up : Sub; } for (size_t i = 0; i < len; ++i) { uint32_t y = swatchHeight * (i / columns); diff --git a/bin/wake.c b/bin/wake.c index 7c4496da..cb5e5386 100644 --- a/bin/wake.c +++ b/bin/wake.c @@ -24,7 +24,7 @@ #include <sysexits.h> #define MAC 0x04, 0x7D, 0x7B, 0xD5, 0x6A, 0x53 -static const uint8_t payload[102] = { +static const uint8_t Payload[102] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, MAC, MAC, MAC, MAC, MAC, MAC, MAC, MAC, MAC, MAC, MAC, MAC, MAC, MAC, MAC, MAC, @@ -44,7 +44,7 @@ int main() { .sin_addr.s_addr = INADDR_BROADCAST, }; ssize_t size = sendto( - sock, payload, sizeof(payload), 0, + sock, Payload, sizeof(Payload), 0, (struct sockaddr *)&addr, sizeof(addr) ); if (size < 0) err(EX_IOERR, "sendto"); |