Skip to content

Commit 154b973

Browse files
committed
chore(display): fmt
1 parent 7a5b097 commit 154b973

File tree

3 files changed

+56
-29
lines changed

3 files changed

+56
-29
lines changed

display/main.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ int main(int argc, char *argv[])
5959
setvbuf(stdout, NULL, _IOLBF, 32);
6060
setvbuf(stderr, NULL, _IOLBF, 32);
6161

62-
assert(backend_count == (sizeof(backend_strings) / sizeof(*backend_strings)));
62+
assert(backend_count ==
63+
(sizeof(backend_strings) / sizeof(*backend_strings)));
6364

6465
// Parse command-line arguments. This only returns if they're valid.
6566
const struct args args = parse_args(argc, argv);
@@ -114,8 +115,10 @@ static void print_usage(const char *self)
114115
}
115116

116117
fprintf(stderr, " --test <DIR>\n");
117-
fprintf(stderr, " \tRun the test cases and dump their pixel buffers into <DIR>.\n");
118-
fprintf(stderr, " \tThese can be manually diffed to verify the rendering code.\n");
118+
fprintf(stderr,
119+
" \tRun the test cases and dump their pixel buffers into <DIR>.\n");
120+
fprintf(stderr,
121+
" \tThese can be manually diffed to verify the rendering code.\n");
119122

120123
fprintf(stderr, " -h, --help\n");
121124
fprintf(stderr, " \tPrint help.\n");

display/rendering/canvas.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,17 @@ void rendering_fill(struct canvas *c, struct color color)
6565
draw_point(c, x, y, color);
6666
}
6767

68-
DEFN_RENDER(rect) {
68+
DEFN_RENDER(rect)
69+
{
6970
uint16_t right_edge = rect->x + rect->w;
7071
uint16_t bottom_edge = rect->y + rect->h;
7172
for (uint16_t y = rect->y; y < bottom_edge && y < c->height; y++)
7273
for (uint16_t x = rect->x; x < right_edge && x < c->width; x++)
7374
draw_point(c, x, y, rect->c);
7475
}
7576

76-
DEFN_RENDER(circle) {
77+
DEFN_RENDER(circle)
78+
{
7779
uint16_t x = circle->r;
7880
uint16_t y = 0;
7981
int32_t t1 = circle->r / 16;
@@ -123,7 +125,8 @@ DEFN_RENDER(circle) {
123125
}
124126
}
125127

126-
DEFN_RENDER(line) {
128+
DEFN_RENDER(line)
129+
{
127130
const struct color color = line->c;
128131

129132
// I think this is essentially Bresenham's line algorithm, as in, that
@@ -210,7 +213,8 @@ DEFN_RENDER(line) {
210213
}
211214
}
212215

213-
DEFN_RENDER(rect_copy) {
216+
DEFN_RENDER(rect_copy)
217+
{
214218
const struct rect_copy rc = *rect_copy;
215219

216220
// The regions may overlap, so we care whether we are incrementing or
@@ -272,7 +276,8 @@ static float bezier2_arclen_approx(struct bezier2 b, size_t n)
272276
return dist;
273277
}
274278

275-
DEFN_RENDER(bezier2) {
279+
DEFN_RENDER(bezier2)
280+
{
276281
const struct bezier2 b = *bezier2;
277282

278283
// TODO: not pixel perfect (this approach is heuristic)

display/threads/commands.c

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ static char *run(struct ui_ctx *, const struct command *);
5555
static char *eat_whitespace(char *);
5656
static char **collect_args(char **, size_t *, char **);
5757

58-
static char *act_create(struct ui_ctx *, char *target, size_t argc, char **argv);
59-
static char *act_remove(struct ui_ctx *, char *target, size_t argc, char **argv);
58+
static char *act_create(
59+
struct ui_ctx *, char *target, size_t argc, char **argv);
60+
static char *act_remove(
61+
struct ui_ctx *, char *target, size_t argc, char **argv);
6062
static char *act_rect(struct ui_ctx *, char *target, size_t argc, char **argv);
61-
static char *act_circle(struct ui_ctx *, char *target, size_t argc, char **argv);
63+
static char *act_circle(
64+
struct ui_ctx *, char *target, size_t argc, char **argv);
6265
static char *act_line(struct ui_ctx *, char *target, size_t argc, char **argv);
6366
static char *act_copy_rect(
6467
struct ui_ctx *, char *target, size_t argc, char **argv);
@@ -259,19 +262,21 @@ static char *call_action(struct ui_ctx *ctx, const struct command *c,
259262
char *ret = malloc(512);
260263
snprintf(ret, 512, "no such action found: %s", c->action);
261264
return ret;
262-
} else return NULL;
265+
} else
266+
return NULL;
263267
}
264268

265269
static char *run(struct ui_ctx *ctx, const struct command *c)
266270
{
267271
char *ret = NULL;
268272
if (strcmp(c->target_name, "root") == 0) {
269273
if ((ret = call_action(ctx, c, root_actions,
270-
sizeof(root_actions) / sizeof(*root_actions), false)))
274+
sizeof(root_actions) / sizeof(*root_actions), false)))
271275
return ret;
272276
}
273277

274-
ret = call_action(ctx, c, actions, sizeof(actions) / sizeof(*actions), true);
278+
ret = call_action(
279+
ctx, c, actions, sizeof(actions) / sizeof(*actions), true);
275280
return ret;
276281
}
277282

@@ -330,7 +335,8 @@ static char *act_create(
330335
enum ui_failure r = ui_pane_create(ctx, target, fill);
331336
if (r != UI_OK) {
332337
err_buf = malloc(1024);
333-
snprintf(err_buf, 1024, "act_create: failed: %s", ui_failure_str(r));
338+
snprintf(
339+
err_buf, 1024, "act_create: failed: %s", ui_failure_str(r));
334340
}
335341

336342
return err_buf;
@@ -346,20 +352,23 @@ static char *act_remove(
346352
enum ui_failure r = ui_pane_remove(ctx, target);
347353
if (r != UI_OK) {
348354
err_buf = malloc(1024);
349-
snprintf(err_buf, 1024, "act_remove: failed: %s", ui_failure_str(r));
355+
snprintf(
356+
err_buf, 1024, "act_remove: failed: %s", ui_failure_str(r));
350357
}
351358

352359
return err_buf;
353360
}
354361

355-
static char *act_rect(struct ui_ctx *ctx, char *target, size_t argc, char **argv)
362+
static char *act_rect(
363+
struct ui_ctx *ctx, char *target, size_t argc, char **argv)
356364
{
357365
char *err_buf = NULL;
358366
struct rect rect;
359367

360368
long x, y, w, h;
361369

362-
if ((err_buf = parse_args("ciiii", argc, argv, &rect.c, &x, &y, &w, &h)))
370+
if ((err_buf =
371+
parse_args("ciiii", argc, argv, &rect.c, &x, &y, &w, &h)))
363372
return err_buf;
364373

365374
rect.x = x;
@@ -372,7 +381,8 @@ static char *act_rect(struct ui_ctx *ctx, char *target, size_t argc, char **argv
372381

373382
if (r != UI_OK) {
374383
err_buf = malloc(1024);
375-
snprintf(err_buf, 1024, "act_rect: failed: %s", ui_failure_str(r));
384+
snprintf(
385+
err_buf, 1024, "act_rect: failed: %s", ui_failure_str(r));
376386
}
377387

378388
return err_buf;
@@ -398,20 +408,23 @@ static char *act_circle(
398408

399409
if (r != UI_OK) {
400410
err_buf = malloc(1024);
401-
snprintf(err_buf, 1024, "act_circle: failed: %s", ui_failure_str(r));
411+
snprintf(
412+
err_buf, 1024, "act_circle: failed: %s", ui_failure_str(r));
402413
}
403414

404415
return err_buf;
405416
}
406417

407-
static char *act_line(struct ui_ctx *ctx, char *target, size_t argc, char **argv)
418+
static char *act_line(
419+
struct ui_ctx *ctx, char *target, size_t argc, char **argv)
408420
{
409421
char *err_buf = NULL;
410422
struct line line;
411423

412424
long x0, y0, x1, y1;
413425

414-
if ((err_buf = parse_args("ciiii", argc, argv, &line.c, &x0, &y0, &x1, &y1)))
426+
if ((err_buf = parse_args(
427+
"ciiii", argc, argv, &line.c, &x0, &y0, &x1, &y1)))
415428
return err_buf;
416429

417430
line.x0 = x0;
@@ -424,7 +437,8 @@ static char *act_line(struct ui_ctx *ctx, char *target, size_t argc, char **argv
424437

425438
if (r != UI_OK) {
426439
err_buf = malloc(1024);
427-
snprintf(err_buf, 1024, "act_line: failed: %s", ui_failure_str(r));
440+
snprintf(
441+
err_buf, 1024, "act_line: failed: %s", ui_failure_str(r));
428442
}
429443

430444
return err_buf;
@@ -439,7 +453,7 @@ static char *act_copy_rect(
439453
long dst_x, dst_y, src_x, src_y, w, h;
440454

441455
if ((err_buf = parse_args(
442-
"iiiiii", argc, argv, &dst_x, &dst_y, &src_x, &src_y, &w, &h)))
456+
"iiiiii", argc, argv, &dst_x, &dst_y, &src_x, &src_y, &w, &h)))
443457
return err_buf;
444458

445459
rc.dst_x = dst_x;
@@ -454,7 +468,8 @@ static char *act_copy_rect(
454468

455469
if (r != UI_OK) {
456470
err_buf = malloc(1024);
457-
snprintf(err_buf, 1024, "act_copy_rect: failed: %s", ui_failure_str(r));
471+
snprintf(err_buf, 1024, "act_copy_rect: failed: %s",
472+
ui_failure_str(r));
458473
}
459474

460475
return err_buf;
@@ -526,10 +541,12 @@ static char *parse_args(const char *fmt, size_t argc, char **argv, ...)
526541
va_list args;
527542
va_start(args, argv);
528543
char *err_buf = malloc(1024);
529-
if (!err_buf) FATAL_ERR("parse_args: OOM");
544+
if (!err_buf)
545+
FATAL_ERR("parse_args: OOM");
530546

531547
if (argc != strlen(fmt)) {
532-
snprintf(err_buf, 1024, "failure: got %zu arguments, expected %lu.", argc,
548+
snprintf(err_buf, 1024,
549+
"failure: got %zu arguments, expected %lu.", argc,
533550
strlen(fmt));
534551
return err_buf;
535552
}
@@ -542,7 +559,8 @@ static char *parse_args(const char *fmt, size_t argc, char **argv, ...)
542559
case 'c':
543560
struct color *cout = va_arg(args, struct color *);
544561
if (!parse_color(in, cout)) {
545-
snprintf(err_buf, 1024, "failure: expected color, got: %s", in);
562+
snprintf(err_buf, 1024,
563+
"failure: expected color, got: %s", in);
546564
return err_buf;
547565
}
548566

@@ -553,7 +571,8 @@ static char *parse_args(const char *fmt, size_t argc, char **argv, ...)
553571
long iout = strtol(in, &end, 0);
554572
*out = iout;
555573
if (*end != '\0') {
556-
snprintf(err_buf, 1024, "failure: expected number, got: %s", in);
574+
snprintf(err_buf, 1024,
575+
"failure: expected number, got: %s", in);
557576
return err_buf;
558577
}
559578
break;

0 commit comments

Comments
 (0)