From 18eba940f19a6708ef8ec7cce61711391b43f44b Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 5 Aug 2025 14:45:43 -0400 Subject: [PATCH] prepare for compile time init of screens[] --- bbs.c | 42 +++++++++++++++++++++++++----------------- globals.h | 9 ++++++--- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/bbs.c b/bbs.c index 09f2728..fc0d9ea 100644 --- a/bbs.c +++ b/bbs.c @@ -7,8 +7,6 @@ #include "globals.h" #include "home.h" -#define MAX_ERROR_MESSAGE_SIZE 60 /* size of error_message array */ - const unsigned int GETCH_TIMEOUT = 10; /* in ms */ const char* LOCALE = "en_US.UTF-8"; /* enable unicode support, set to "ANSI_X3.4-1968" for ascii */ @@ -34,15 +32,11 @@ int main() { timeout(GETCH_TIMEOUT); /* set timeout for getch() */ setlocale(LC_CTYPE, LOCALE); /* set locale, UTF8 support is enabled here */ - unsigned int start_y = 0; - unsigned int start_x = 0; unsigned int terminal_width; unsigned int terminal_height; unsigned int old_terminal_width = 0; unsigned int old_terminal_height = 0; - // struct Screen screens[MAX_SCREENS]; - enum Status status = STATUS_NEED_REFRESH; /* refresh screens[active_screen].window on first loop */ char input = ' '; @@ -53,18 +47,32 @@ int main() { unsigned int screen_before_error = HOME; enum ActiveScreen active_screen = HOME; - struct Screen home = { - "home", - newwin(terminal_height, terminal_width, start_y, start_x), - draw_home + + struct Screen screens[] = { + { + "home", + newwin(terminal_height, terminal_width, 0, 0), + draw_home + }, + { + "error", + newwin(terminal_height, terminal_width, 0, 0), + draw_error + } }; - screens[HOME] = home; - struct Screen error = { - "error", - newwin(terminal_height, terminal_width, start_y, start_x), - draw_error - }; - screens[ERROR] = error; + + // struct Screen home = { + // "home", + // newwin(terminal_height, terminal_width, start_y, start_x), + // draw_home + // }; + // screens[HOME] = home; + // struct Screen error = { + // "error", + // newwin(terminal_height, terminal_width, start_y, start_x), + // draw_error + // }; + // screens[ERROR] = error; /* main event loop */ while (status != STATUS_QUIT) { diff --git a/globals.h b/globals.h index 87a2c19..abfe0ed 100644 --- a/globals.h +++ b/globals.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: MIT */ -#define MAX_SCREENS 2 /* size of screens array */ +#define MAX_ERROR_MESSAGE_SIZE 60 /* size of error_message array */ +#define MAX_SCREEN_NAME_SIZE 20 /* size of the screen name array */ #ifndef GLOBALS_H /* header guard */ #define GLOBALS_H @@ -17,11 +18,13 @@ enum ActiveScreen { }; struct Screen { - char name[20]; + char name[MAX_SCREEN_NAME_SIZE]; WINDOW *win; void (*draw_screen)(struct Screen *, char *input); /* GETCH_TIMEOUT determines how often this is run, in ms */ }; -struct Screen screens[MAX_SCREENS]; +/* TODO: put this in a screens.c file and include all screens there, that way the array can be initialized at compile + * time */ +extern struct Screen screens[]; #endif