From f48ed22602e4208bc1a49770c094864d74b83628 Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 5 Aug 2025 12:42:21 -0400 Subject: [PATCH 1/7] enable compiler optimizations and gdb debug info --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index df3b7d6..67d90ed 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC=gcc -CFLAGS=-std=c99 -pedantic -Wall -Wextra +CFLAGS=-std=c99 -pedantic -Wall -Wextra -O2 -ggdb LIBS=-lncursesw EXECUTABLE=bbs -- 2.39.5 From 7d8f3d70b31de76fd7cf86ede9e7fa2c6dd66f97 Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 5 Aug 2025 12:42:58 -0400 Subject: [PATCH 2/7] refactoring bbs.c to prepare for screens to be seperate files --- bbs.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/bbs.c b/bbs.c index 57c642f..35a92a6 100644 --- a/bbs.c +++ b/bbs.c @@ -1,12 +1,16 @@ +/* SPDX-License-Identifier: MIT */ + #include #include #include +#define MAX_ERROR_MESSAGE_SIZE 60 /* size of error_message array */ +#define MAX_SCREENS 2 /* size of screens array */ + const unsigned int GETCH_TIMEOUT = 10; /* in ms */ -const unsigned int MAX_SCREENS = 2; /* size of screens array */ const char* LOCALE = "en_US.UTF-8"; /* enable unicode support, set to "ANSI_X3.4-1968" for ascii */ -char errorMessage[60]; +char error_message[MAX_ERROR_MESSAGE_SIZE]; enum Status { STATUS_QUIT, @@ -22,7 +26,7 @@ enum ActiveScreen { struct Screen { char name[20]; WINDOW *win; - void (*draw_screen)(struct Screen *, char *input); /* this is run about every 10ms */ + void (*draw_screen)(struct Screen *, char *input); /* GETCH_TIMEOUT determines how often this is run, in ms */ }; static void draw_home(struct Screen *screen, char *input) { @@ -42,15 +46,15 @@ static void draw_home(struct Screen *screen, char *input) { } static void draw_error(struct Screen *screen, __attribute__((unused)) char *input) { - mvwprintw(screen->win, 1, 2, "%s", errorMessage); + mvwprintw(screen->win, 1, 2, "%s", error_message); } static void draw_screen (struct Screen *screen, char *input) { screen->draw_screen(screen, input); box(screen->win, 0, 0); - // wattron(screen->win, A_STANDOUT); + /* wattron(screen->win, A_STANDOUT); */ mvwprintw(screen->win, 0, 1, " %s ", screen->name); - // wattroff(screen->win, A_STANDOUT); + /* wattroff(screen->win, A_STANDOUT); */ } int main() { @@ -73,7 +77,7 @@ int main() { enum Status status = STATUS_NEED_REFRESH; /* refresh screens[active_screen].window on first loop */ char input = ' '; - strcpy(errorMessage, ""); + strcpy(error_message, ""); getmaxyx(stdscr, terminal_height, terminal_width); @@ -116,7 +120,7 @@ int main() { if (terminal_width < 80 || terminal_height < 24) { if (active_screen != ERROR) { - strcpy(errorMessage, "This program expects at least 80 rows by 24 columns."); + strcpy(error_message, "This program expects at least 80 rows by 24 columns."); screen_before_error = active_screen; }; active_screen = ERROR; -- 2.39.5 From 1a90a816e5789abdf10c7be708a1743e23d48a17 Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 5 Aug 2025 14:17:27 -0400 Subject: [PATCH 3/7] nonfunctional, working on seperate screen files --- Makefile | 17 ++++++++--------- bbs.c | 41 +++++------------------------------------ globals.h | 27 +++++++++++++++++++++++++++ home.c | 20 ++++++++++++++++++++ home.h | 10 ++++++++++ 5 files changed, 70 insertions(+), 45 deletions(-) create mode 100644 globals.h create mode 100644 home.c create mode 100644 home.h diff --git a/Makefile b/Makefile index 67d90ed..9de78fb 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,17 @@ +# SPDX-License-Identifier: MIT + CC=gcc CFLAGS=-std=c99 -pedantic -Wall -Wextra -O2 -ggdb LIBS=-lncursesw EXECUTABLE=bbs -.PHONY: all -all: make +# .PHONY: all +# all: make +make: bbs -make: - $(CC) $(CFLAGS) $(LIBS) bbs.c -o $(EXECUTABLE) +bbs: bbs.c home.c home.h globals.h + $(CC) $(CFLAGS) $(LIBS) bbs.c home.c -o $(EXECUTABLE) -.PHONY: execute -execute: +run: bbs ./$(EXECUTABLE) - -.PHONY: run -run: make execute diff --git a/bbs.c b/bbs.c index 35a92a6..09f2728 100644 --- a/bbs.c +++ b/bbs.c @@ -4,47 +4,16 @@ #include #include +#include "globals.h" +#include "home.h" + #define MAX_ERROR_MESSAGE_SIZE 60 /* size of error_message array */ -#define MAX_SCREENS 2 /* size of screens 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 */ char error_message[MAX_ERROR_MESSAGE_SIZE]; -enum Status { - STATUS_QUIT, - STATUS_WAITING, - STATUS_NEED_REFRESH -}; - -enum ActiveScreen { - HOME, - ERROR -}; - -struct Screen { - char name[20]; - WINDOW *win; - void (*draw_screen)(struct Screen *, char *input); /* GETCH_TIMEOUT determines how often this is run, in ms */ -}; - -static void draw_home(struct Screen *screen, char *input) { - static char* banner = "" - " _ _ _ \n" - " | | | | | | \n" - " __ _ _ __ ___ | |__ ___ _ __ ___ _ __ | | __ _ ___ ___ _ __ ___| |_ \n" - " / _` | '_ ` _ \\| '_ \\ / _ \\ '__/ __| '_ \\| |/ _` |/ __/ _ \\ | '_ \\ / _ \\ __|\n" - " | (_| | | | | | | |_) | __/ | \\__ \\ |_) | | (_| | (_| __/_| | | | __/ |_ \n" - " \\__,_|_| |_| |_|_.__/ \\___|_| |___/ .__/|_|\\__,_|\\___\\___(_)_| |_|\\___|\\__|\n" - " | | \n" - " |_| \n"; - - mvwprintw(screen->win, 1, 2, "Thank you for visiting:"); - mvwprintw(screen->win, 2, 1, "%s", banner); - mvwprintw(screen->win, 10, 1, "Your current input is: %s", input); -} - static void draw_error(struct Screen *screen, __attribute__((unused)) char *input) { mvwprintw(screen->win, 1, 2, "%s", error_message); } @@ -72,7 +41,7 @@ int main() { unsigned int old_terminal_width = 0; unsigned int old_terminal_height = 0; - struct Screen screens[MAX_SCREENS]; + // struct Screen screens[MAX_SCREENS]; enum Status status = STATUS_NEED_REFRESH; /* refresh screens[active_screen].window on first loop */ char input = ' '; @@ -140,7 +109,7 @@ int main() { }; /* clean up */ - delwin(screens[active_screen].win); + delwin(screens[active_screen].win); /* TODO: delete all windows in screens[] */ nocbreak(); endwin(); /* ends curses mode */ curs_set(1); diff --git a/globals.h b/globals.h new file mode 100644 index 0000000..87a2c19 --- /dev/null +++ b/globals.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: MIT */ + +#define MAX_SCREENS 2 /* size of screens array */ + +#ifndef GLOBALS_H /* header guard */ +#define GLOBALS_H + +enum Status { + STATUS_QUIT, + STATUS_WAITING, + STATUS_NEED_REFRESH +}; + +enum ActiveScreen { + HOME, + ERROR +}; + +struct Screen { + char name[20]; + WINDOW *win; + void (*draw_screen)(struct Screen *, char *input); /* GETCH_TIMEOUT determines how often this is run, in ms */ +}; + +struct Screen screens[MAX_SCREENS]; + +#endif diff --git a/home.c b/home.c new file mode 100644 index 0000000..e31ad18 --- /dev/null +++ b/home.c @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: MIT */ + +#include +#include "globals.h" + +void draw_home(struct Screen *screen, char *input) { + static char* banner = "" + " _ _ _ \n" + " | | | | | | \n" + " __ _ _ __ ___ | |__ ___ _ __ ___ _ __ | | __ _ ___ ___ _ __ ___| |_ \n" + " / _` | '_ ` _ \\| '_ \\ / _ \\ '__/ __| '_ \\| |/ _` |/ __/ _ \\ | '_ \\ / _ \\ __|\n" + " | (_| | | | | | | |_) | __/ | \\__ \\ |_) | | (_| | (_| __/_| | | | __/ |_ \n" + " \\__,_|_| |_| |_|_.__/ \\___|_| |___/ .__/|_|\\__,_|\\___\\___(_)_| |_|\\___|\\__|\n" + " | | \n" + " |_| \n"; + + mvwprintw(screen->win, 1, 2, "Thank you for visiting:"); + mvwprintw(screen->win, 2, 1, "%s", banner); + mvwprintw(screen->win, 10, 1, "Your current input is: %s", input); +} diff --git a/home.h b/home.h new file mode 100644 index 0000000..74966a8 --- /dev/null +++ b/home.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: MIT */ + +#ifndef HOME_H /* header guard */ +#define HOME_H + +#include "globals.h" + +void draw_home(struct Screen *screen, char *input); + +#endif -- 2.39.5 From 18eba940f19a6708ef8ec7cce61711391b43f44b Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 5 Aug 2025 14:45:43 -0400 Subject: [PATCH 4/7] 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 -- 2.39.5 From db26be2a079db82fd0def297f91e04f4c2d1c277 Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 5 Aug 2025 17:25:21 -0400 Subject: [PATCH 5/7] Import makefile by Gale, thank you <3 --- Makefile | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 9de78fb..4519b7f 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,37 @@ # SPDX-License-Identifier: MIT -CC=gcc -CFLAGS=-std=c99 -pedantic -Wall -Wextra -O2 -ggdb -LIBS=-lncursesw -EXECUTABLE=bbs +# Makefile for Amber's BBS Interface +# Buildsys by Gale Faraday -# .PHONY: all -# all: make +.PHONY: all clean run +.SUFFIXES: -make: bbs +.DEFAULT_GOAL := all -bbs: bbs.c home.c home.h globals.h - $(CC) $(CFLAGS) $(LIBS) bbs.c home.c -o $(EXECUTABLE) +TARGET := $(shell basename $(CURDIR)) +SOURCES := src/ +BUILD := build/ +OBJS := $(patsubst $(SOURCES)%.c,$(BUILD)%.o,$(wildcard $(SOURCES)*.c)) +EXECUTABLE := $(TARGET) -run: bbs + +CC := gcc +LD := gcc +CFLAGS := -std=c99 -pedantic -Wall -Wextra -O2 -ggdb +LDFLAGS := $(CFLAGS) -lncursesw + +all: $(EXECUTABLE) + +run: $(EXECUTABLE) ./$(EXECUTABLE) + +.IGNORE: clean +clean: + @rm -rvf $(BUILD) $(EXECUTABLE) + +$(EXECUTABLE): $(OBJS) + $(LD) $(LDFLAGS) -o $@ $^ + +$(OBJS): $(BUILD)%.o : $(SOURCES)%.c + -@mkdir -p $(BUILD) + $(CC) $(CFLAGS) -o $@ -c $< -- 2.39.5 From 914ce0d7adf9229f1162e8ae2148e8158440df82 Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 5 Aug 2025 17:30:03 -0400 Subject: [PATCH 6/7] each screen now has it's own file, and there is a framework for adding more --- bbs.c | 34 ++++------------------------------ error.c | 8 ++++++++ error.h | 10 ++++++++++ globals.h | 22 +++++++++++----------- home.c | 2 +- home.h | 2 +- screens.c | 19 +++++++++++++++++++ screens.h | 10 ++++++++++ 8 files changed, 64 insertions(+), 43 deletions(-) create mode 100644 error.c create mode 100644 error.h create mode 100644 screens.c create mode 100644 screens.h diff --git a/bbs.c b/bbs.c index fc0d9ea..c59ef6c 100644 --- a/bbs.c +++ b/bbs.c @@ -5,17 +5,13 @@ #include #include "globals.h" -#include "home.h" +#include "screens.h" 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 */ char error_message[MAX_ERROR_MESSAGE_SIZE]; -static void draw_error(struct Screen *screen, __attribute__((unused)) char *input) { - mvwprintw(screen->win, 1, 2, "%s", error_message); -} - static void draw_screen (struct Screen *screen, char *input) { screen->draw_screen(screen, input); box(screen->win, 0, 0); @@ -48,31 +44,9 @@ int main() { enum ActiveScreen active_screen = HOME; - struct Screen screens[] = { - { - "home", - newwin(terminal_height, terminal_width, 0, 0), - draw_home - }, - { - "error", - newwin(terminal_height, terminal_width, 0, 0), - draw_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; + /* could be it's own init func within the screen's file. */ + screens[HOME].win = newwin(terminal_height, terminal_width, 0, 0); + screens[ERROR].win = newwin(terminal_height, terminal_width, 0, 0); /* main event loop */ while (status != STATUS_QUIT) { diff --git a/error.c b/error.c new file mode 100644 index 0000000..03d5adf --- /dev/null +++ b/error.c @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: MIT */ + +#include +#include "screens.h" + +void draw_error(struct Screen *screen, __attribute__((unused)) char *input) { + mvwprintw(screen->win, 1, 2, "%s", error_message); +} diff --git a/error.h b/error.h new file mode 100644 index 0000000..292a6a8 --- /dev/null +++ b/error.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: MIT */ + +#ifndef ERROR_H /* header guard */ +#define ERROR_H + +#include "screens.h" + +void draw_error(struct Screen *screen, char *input); + +#endif diff --git a/globals.h b/globals.h index abfe0ed..373266a 100644 --- a/globals.h +++ b/globals.h @@ -1,11 +1,21 @@ /* SPDX-License-Identifier: MIT */ -#define MAX_ERROR_MESSAGE_SIZE 60 /* size of error_message array */ #define MAX_SCREEN_NAME_SIZE 20 /* size of the screen name array */ +#define MAX_ERROR_MESSAGE_SIZE 60 /* size of error_message array */ #ifndef GLOBALS_H /* header guard */ #define GLOBALS_H +#include + +extern char error_message[]; + +struct Screen { + 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 */ +}; + enum Status { STATUS_QUIT, STATUS_WAITING, @@ -17,14 +27,4 @@ enum ActiveScreen { ERROR }; -struct Screen { - 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 */ -}; - -/* 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 diff --git a/home.c b/home.c index e31ad18..ad4d8d7 100644 --- a/home.c +++ b/home.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: MIT */ #include -#include "globals.h" +#include "screens.h" void draw_home(struct Screen *screen, char *input) { static char* banner = "" diff --git a/home.h b/home.h index 74966a8..d88904c 100644 --- a/home.h +++ b/home.h @@ -3,7 +3,7 @@ #ifndef HOME_H /* header guard */ #define HOME_H -#include "globals.h" +#include "screens.h" void draw_home(struct Screen *screen, char *input); diff --git a/screens.c b/screens.c new file mode 100644 index 0000000..a506b25 --- /dev/null +++ b/screens.c @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: MIT */ + +#include "globals.h" +#include "home.h" +#include "error.h" + +/* NOTE: this should be compile time */ +struct Screen screens[] = { + { + "home", + NULL, + draw_home + }, + { + "error", + NULL, + draw_error + } +}; diff --git a/screens.h b/screens.h new file mode 100644 index 0000000..e9126bc --- /dev/null +++ b/screens.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: MIT */ + +#ifndef SCREENS_H /* header guard */ +#define SCREENS_H + +#include "globals.h" + +extern struct Screen screens[]; + +#endif -- 2.39.5 From 96a18b8cdb64674d4be97e89050e8c7f0b74b147 Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 5 Aug 2025 17:34:42 -0400 Subject: [PATCH 7/7] move files to src/ directory and add build/ to .gitignore --- .gitignore | 1 + bbs.c => src/bbs.c | 0 error.c => src/error.c | 0 error.h => src/error.h | 0 globals.h => src/globals.h | 0 home.c => src/home.c | 0 home.h => src/home.h | 0 screens.c => src/screens.c | 0 screens.h => src/screens.h | 0 9 files changed, 1 insertion(+) rename bbs.c => src/bbs.c (100%) rename error.c => src/error.c (100%) rename error.h => src/error.h (100%) rename globals.h => src/globals.h (100%) rename home.c => src/home.c (100%) rename home.h => src/home.h (100%) rename screens.c => src/screens.c (100%) rename screens.h => src/screens.h (100%) diff --git a/.gitignore b/.gitignore index 2066820..602bc80 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ bbs +build/ diff --git a/bbs.c b/src/bbs.c similarity index 100% rename from bbs.c rename to src/bbs.c diff --git a/error.c b/src/error.c similarity index 100% rename from error.c rename to src/error.c diff --git a/error.h b/src/error.h similarity index 100% rename from error.h rename to src/error.h diff --git a/globals.h b/src/globals.h similarity index 100% rename from globals.h rename to src/globals.h diff --git a/home.c b/src/home.c similarity index 100% rename from home.c rename to src/home.c diff --git a/home.h b/src/home.h similarity index 100% rename from home.h rename to src/home.h diff --git a/screens.c b/src/screens.c similarity index 100% rename from screens.c rename to src/screens.c diff --git a/screens.h b/src/screens.h similarity index 100% rename from screens.h rename to src/screens.h -- 2.39.5