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