From 6c076eb2a965fefc13f76e882748d3f3b06ee334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ki=C3=ABd=20Llaentenn?= Date: Thu, 17 Sep 2020 12:04:12 +0000 Subject: [PATCH] style changes --- draw.c | 6 +++--- draw.h | 15 +++++++-------- main.c | 36 ++++++++++++++++-------------------- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/draw.c b/draw.c index 33994a6..0a5dc76 100644 --- a/draw.c +++ b/draw.c @@ -19,7 +19,7 @@ extern struct Options *opts; // initialize the framebuffer void -init ( struct buffer *buf ) +init(struct buffer *buf) { // initialize width/height of terminal buf->width = tb_width(); @@ -45,7 +45,7 @@ init ( struct buffer *buf ) // update the framebuffer void -dofire ( struct buffer *buf ) +dofire(struct buffer *buf) { size_t src; size_t random; @@ -85,7 +85,7 @@ dofire ( struct buffer *buf ) // free framebuffer and shutdown termbox void -cleanup ( struct buffer *buf ) +cleanup(struct buffer *buf) { free(buf->buf); tb_shutdown(); diff --git a/draw.h b/draw.h index f8355fa..b556cb7 100644 --- a/draw.h +++ b/draw.h @@ -7,16 +7,15 @@ #include "stdint.h" #endif -typedef struct buffer -{ - size_t width; - size_t height; +struct buffer { + size_t width; + size_t height; uint8_t* buf; -} buffer; +}; -void init ( struct buffer *buf ); -void dofire ( struct buffer *buf ); -void cleanup ( struct buffer *buf ); +void init(struct buffer *buf); +void dofire(struct buffer *buf); +void cleanup(struct buffer *buf); #endif diff --git a/main.c b/main.c index 3d72db1..147785d 100644 --- a/main.c +++ b/main.c @@ -23,14 +23,13 @@ main ( int argc, char *argv[] ) { opts = (struct Options*) calloc(1, sizeof(struct Options*)); if (opts == NULL) { - EPRINT("fire: error: cannot "); - perror("calloc()"); + perror("fire: error: calloc()"); } // default args opts->refresh_rate = 5; - opts->truecolor = FALSE; size_t output_mode = TB_OUTPUT_NORMAL; + opts->truecolor = FALSE; // argument parsing argv0 = argv[0]; @@ -45,7 +44,7 @@ main ( int argc, char *argv[] ) break; case 'V': printf("%s %s\n", argv0, VERSION); - exit(EXIT_SUCCESS); + return 0; case 'h': default: printf("Usage: %s [-tVh] [-r rate]\n", argv0); @@ -58,7 +57,7 @@ main ( int argc, char *argv[] ) printf("(c) Kiƫd Llaentenn, nullgemm\n"); printf("https://github.com/lptstr/fire\n"); - exit(EXIT_SUCCESS); + return 0; } ARGEND // initialize termbox @@ -72,11 +71,7 @@ main ( int argc, char *argv[] ) init(&buf); // animate - while (TRUE) - { - // clear the screen - //tb_clear(); - + while (TRUE) { // update framebuffer dofire(&buf); @@ -86,11 +81,13 @@ main ( int argc, char *argv[] ) // event handling int err = (size_t) tb_peek_event(&e, opts->refresh_rate); - if (err < 0) + if (err < 0) { continue; + } - if (e.type == TB_EVENT_KEY) - { + // handle keypresses + // q, ctrl+c, ctrl+d => quit + if (e.type == TB_EVENT_KEY) { switch (e.ch) { case 'q': goto cleanup; @@ -98,13 +95,12 @@ main ( int argc, char *argv[] ) break; } - switch (e.key) - { - case TB_KEY_CTRL_C: - case TB_KEY_CTRL_D: - goto cleanup; - default: - break; + switch (e.key) { + case TB_KEY_CTRL_C: + case TB_KEY_CTRL_D: + goto cleanup; + default: + break; } } }