about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-04-09 01:00:54 -0400
committerJune McEnroe <june@causal.agency>2018-04-09 01:00:54 -0400
commit99e3c574a02fdb779e97186119891fbe46390d72 (patch)
tree639e659dd91b6e9259f55f59ca91d6bf9ae46e12
parentLink against ncurses (diff)
downloadtorus-99e3c574a02fdb779e97186119891fbe46390d72.tar.gz
torus-99e3c574a02fdb779e97186119891fbe46390d72.zip
Replace #define with enum or const where possible
-rw-r--r--client.c6
-rw-r--r--help.c22
-rw-r--r--torus.h29
3 files changed, 33 insertions, 24 deletions
diff --git a/client.c b/client.c
index 6ad60d7..ef51ae0 100644
--- a/client.c
+++ b/client.c
@@ -29,8 +29,10 @@
 
 #include "torus.h"
 
-#define ESC (0x1B)
-#define DEL (0x7F)
+enum {
+    ESC = 0x1B,
+    DEL = 0x7F,
+};
 
 #define CH_COLOR(ch) (ch & A_BOLD ? COLOR_BRIGHT | ch >> 8 & 0xFF : ch >> 8 & 0xFF)
 
diff --git a/help.c b/help.c
index 4415065..d997bde 100644
--- a/help.c
+++ b/help.c
@@ -46,16 +46,18 @@ static void clientPut(uint8_t color, char cell) {
     clientMessage(msg);
 }
 
-#define DELAY (50000)
-
-#define R (COLOR_RED)
-#define G (COLOR_GREEN)
-#define Y (COLOR_YELLOW)
-#define B (COLOR_BLUE)
-#define M (COLOR_MAGENTA)
-#define C (COLOR_CYAN)
-#define W (COLOR_WHITE)
-#define I (COLOR_BRIGHT | COLOR_WHITE)
+static const useconds_t DELAY = 50000;
+
+enum {
+    R = COLOR_RED,
+    G = COLOR_GREEN,
+    Y = COLOR_YELLOW,
+    B = COLOR_BLUE,
+    M = COLOR_MAGENTA,
+    C = COLOR_CYAN,
+    W = COLOR_WHITE,
+    I = COLOR_BRIGHT | COLOR_WHITE,
+};
 
 static void h(void) { clientMove(-1,  0); usleep(DELAY); }
 static void j(void) { clientMove( 0,  1); usleep(DELAY); }
diff --git a/torus.h b/torus.h
index a1a085a..72895f2 100644
--- a/torus.h
+++ b/torus.h
@@ -18,6 +18,7 @@
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
+#include <stdlib.h>
 #include <time.h>
 
 #define PACKED __attribute__((packed))
@@ -44,12 +45,14 @@ enum {
     COLOR_BRIGHT,
 };
 
-#define CELL_ROWS (25)
-#define CELL_COLS (80)
-#define CELLS_SIZE (sizeof(char[CELL_ROWS][CELL_COLS]))
+enum {
+    CELL_ROWS = 25,
+    CELL_COLS = 80,
+};
+static const size_t CELLS_SIZE = sizeof(char[CELL_ROWS][CELL_COLS]);
 
-#define CELL_INIT_X (CELL_COLS / 2)
-#define CELL_INIT_Y (CELL_ROWS / 2)
+static const uint8_t CELL_INIT_X = CELL_COLS / 2;
+static const uint8_t CELL_INIT_Y = CELL_ROWS / 2;
 
 struct ALIGNED(4096) Tile {
     time_t createTime;
@@ -64,12 +67,14 @@ static_assert(4096 == sizeof(struct Tile), "struct File is page-sized");
 static_assert(16 == offsetof(struct Tile, cells), "stable cells offset");
 static_assert(2016 == offsetof(struct Tile, colors), "stable colors offset");
 
-#define TILE_ROWS (512)
-#define TILE_COLS (512)
-#define TILES_SIZE (sizeof(struct Tile[TILE_ROWS][TILE_COLS]))
+enum {
+    TILE_ROWS = 512,
+    TILE_COLS = 512,
+};
+static const size_t TILES_SIZE = sizeof(struct Tile[TILE_ROWS][TILE_COLS]);
 
-#define TILE_VOID_X UINT32_MAX
-#define TILE_VOID_Y UINT32_MAX
+static const uint32_t TILE_VOID_X = UINT32_MAX;
+static const uint32_t TILE_VOID_Y = UINT32_MAX;
 
 static const struct {
     uint32_t tileX;
@@ -81,7 +86,7 @@ static const struct {
     { TILE_COLS * 1 / 4, TILE_ROWS * 1 / 4 }, // SE
     { TILE_COLS * 3 / 4, TILE_ROWS * 1 / 4 }, // SW
 };
-#define SPAWNS_LEN (sizeof(SPAWNS) / sizeof(SPAWNS[0]))
+static const size_t SPAWNS_LEN = sizeof(SPAWNS) / sizeof(SPAWNS[0]);
 
 struct ServerMessage {
     enum PACKED {
@@ -110,7 +115,7 @@ struct ServerMessage {
     } data;
 };
 
-#define CURSOR_NONE UINT8_MAX
+static const uint8_t CURSOR_NONE = UINT8_MAX;
 
 struct ClientMessage {
     enum PACKED {
'3' class='logmsg'> 2018-08-07Hack clang into checking uiFmt format stringsJune McEnroe 2018-08-07Handle PART and QUIT without messagesJune McEnroe 2018-08-07Make safe filling the who bufferJune McEnroe 2018-08-07Add reverse and reset IRC formatting codesJune McEnroe 2018-08-06Rewrite line editing again, add formattingJune McEnroe 2018-08-06Fix allocation size in vaswprintfJune McEnroe This is so embarrassing. It only started crashing once it had strings that were long enough, and then it took me so long to notice this mistake. I was worried I was still doing va_list wrong somehow. 2018-08-06Implement word wrappingJune McEnroe 2018-08-06Use wchar_t strings for all of UIJune McEnroe vaswprintf is a nightmare. 2018-08-06Rename line editing functionsJune McEnroe 2018-08-05Initialize all possible color pairsJune McEnroe This is actually possible with use_default_colors! 2018-08-05Refactor color initializationJune McEnroe 2018-08-05Add ^L redrawJune McEnroe 2018-08-05Use 16 colors if availableJune McEnroe Fall back to using bold if there are only 8 colors. This also allowed bright background colors in 16-color terminals. I must port this system to torus. I'll be able to remove the awful termcap patch hack. 2018-08-05Limit parsed colors to number of mIRC colorsJune McEnroe Oh boy that's embarrassing. 2018-08-04Show source link on exitJune McEnroe 2018-08-04Implement line editing, scrollingJune McEnroe Don't really have a way to implement the M-* keys, and currently missing C-w. 2018-08-04Handle /topicJune McEnroe