From 326cda3bba8dea2b912447cba46b997d084a8708 Mon Sep 17 00:00:00 2001 From: Cory Bloor Date: Mon, 24 Feb 2020 23:42:17 -0700 Subject: [PATCH] Rename buffer type to buffer_t --- main.c | 8 ++++---- misc/terminal.c | 18 +++++++++--------- misc/terminal.h | 22 +++++++++++----------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/main.c b/main.c index 954a703..e6affc0 100644 --- a/main.c +++ b/main.c @@ -1003,7 +1003,7 @@ float linear_to_sRGB(float x) { return powf(x, 1/2.2f); // approximation } -void buffer_append_color(buffer* buf, float r, float g, float b) { +void buffer_append_color(buffer_t* buf, float r, float g, float b) { char tmp[20]; int r_out = float_to_byte_color(linear_to_sRGB(r)); int g_out = float_to_byte_color(linear_to_sRGB(g)); @@ -1015,7 +1015,7 @@ void buffer_append_color(buffer* buf, float r, float g, float b) { buffer_append(buf, tmp, length); } -void draw_rows(buffer* buf) { +void draw_rows(buffer_t* buf) { const char* symbol[4] = {" ","o","O","0"}; const uint8_t max_symbol_idx = 3; const int y_cutoff = max_i((int)Y-1 - g_wy, 1); @@ -1055,7 +1055,7 @@ void draw_rows(buffer* buf) { } } -void draw(buffer* buf) { +void draw(buffer_t* buf) { buffer_clear(buf); reposition_cursor(buf); draw_rows(buf); @@ -1161,7 +1161,7 @@ int main(int argc, char** argv) { enable_raw_mode(); clear_screen_now(); - buffer buf = { 0, 0 }; + buffer_t buf = { 0, 0 }; draw(&buf); struct timespec interval_start; diff --git a/misc/terminal.c b/misc/terminal.c index fef46fd..f7fbaac 100644 --- a/misc/terminal.c +++ b/misc/terminal.c @@ -31,19 +31,19 @@ void clear_screen_now() { write_stdinz(T_CLEAR T_REPOSITION_CURSOR); } -void clear_screen(buffer* buf) { +void clear_screen(buffer_t* buf) { buffer_appendz(buf, T_CLEAR T_REPOSITION_CURSOR); } -void reposition_cursor(buffer* buf) { +void reposition_cursor(buffer_t* buf) { buffer_appendz(buf, T_REPOSITION_CURSOR); } -void hide_cursor(buffer* buf) { +void hide_cursor(buffer_t* buf) { buffer_appendz(buf, T_HIDE_CURSOR); } -void show_cursor(buffer* buf) { +void show_cursor(buffer_t* buf) { buffer_appendz(buf, T_SHOW_CURSOR); } @@ -85,7 +85,7 @@ void enable_raw_mode() { } } -void buffer_append(buffer* buf, const char* s, int len) { +void buffer_append(buffer_t* buf, const char* s, int len) { char* data = (char*)realloc(buf->data, buf->len + len); if (!data) { die("failed to reallocate buffer"); @@ -95,19 +95,19 @@ void buffer_append(buffer* buf, const char* s, int len) { buf->len += len; } -void buffer_appendz(buffer* buf, const char* s) { +void buffer_appendz(buffer_t* buf, const char* s) { buffer_append(buf, s, strlen(s)); } -void buffer_write(buffer* buf) { +void buffer_write(buffer_t* buf) { write_stdin(buf->data, buf->len); } -void buffer_clear(buffer* buf) { +void buffer_clear(buffer_t* buf) { buf->len = 0; } -void buffer_free(buffer* buf) { +void buffer_free(buffer_t* buf) { free(buf->data); } diff --git a/misc/terminal.h b/misc/terminal.h index 9897a14..bc82757 100644 --- a/misc/terminal.h +++ b/misc/terminal.h @@ -1,24 +1,24 @@ #pragma once -typedef struct buffer { +typedef struct buffer_t { char* data; int len; -} buffer; +} buffer_t; -void buffer_append(buffer* buf, const char* s, int len); -void buffer_appendz(buffer* buf, const char* s); -void buffer_free(buffer* buf); -void buffer_write(buffer* buf); -void buffer_clear(buffer* buf); +void buffer_append(buffer_t* buf, const char* s, int len); +void buffer_appendz(buffer_t* buf, const char* s); +void buffer_free(buffer_t* buf); +void buffer_write(buffer_t* buf); +void buffer_clear(buffer_t* buf); void die(const char* msg); void clear_screen_now(); -void clear_screen(buffer* buf); -void reposition_cursor(buffer* buf); -void hide_cursor(buffer* buf); -void show_cursor(buffer* buf); +void clear_screen(buffer_t* buf); +void reposition_cursor(buffer_t* buf); +void hide_cursor(buffer_t* buf); +void show_cursor(buffer_t* buf); void enable_raw_mode(); void disable_raw_mode();