Compare commits

...

2 Commits

9 changed files with 94 additions and 53 deletions

View File

@@ -1,17 +1,37 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
CC=gcc # Makefile for Amber's BBS Interface
CFLAGS=-std=c99 -pedantic -Wall -Wextra -O2 -ggdb # Buildsys by Gale Faraday
LIBS=-lncursesw
EXECUTABLE=bbs
# .PHONY: all .PHONY: all clean run
# all: make .SUFFIXES:
make: bbs .DEFAULT_GOAL := all
bbs: bbs.c home.c home.h globals.h TARGET := $(shell basename $(CURDIR))
$(CC) $(CFLAGS) $(LIBS) bbs.c home.c -o $(EXECUTABLE) 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) ./$(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 $<

34
bbs.c
View File

@@ -5,17 +5,13 @@
#include <locale.h> #include <locale.h>
#include "globals.h" #include "globals.h"
#include "home.h" #include "screens.h"
const unsigned int GETCH_TIMEOUT = 10; /* in ms */ 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 */ 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]; 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) { static void draw_screen (struct Screen *screen, char *input) {
screen->draw_screen(screen, input); screen->draw_screen(screen, input);
box(screen->win, 0, 0); box(screen->win, 0, 0);
@@ -48,31 +44,9 @@ int main() {
enum ActiveScreen active_screen = HOME; enum ActiveScreen active_screen = HOME;
struct Screen screens[] = { /* could be it's own init func within the screen's file. */
{ screens[HOME].win = newwin(terminal_height, terminal_width, 0, 0);
"home", screens[ERROR].win = newwin(terminal_height, terminal_width, 0, 0);
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;
/* main event loop */ /* main event loop */
while (status != STATUS_QUIT) { while (status != STATUS_QUIT) {

8
error.c Normal file
View File

@@ -0,0 +1,8 @@
/* SPDX-License-Identifier: MIT */
#include <curses.h>
#include "screens.h"
void draw_error(struct Screen *screen, __attribute__((unused)) char *input) {
mvwprintw(screen->win, 1, 2, "%s", error_message);
}

10
error.h Normal file
View File

@@ -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

View File

@@ -1,11 +1,21 @@
/* SPDX-License-Identifier: MIT */ /* 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_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 */ #ifndef GLOBALS_H /* header guard */
#define GLOBALS_H #define GLOBALS_H
#include <curses.h>
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 { enum Status {
STATUS_QUIT, STATUS_QUIT,
STATUS_WAITING, STATUS_WAITING,
@@ -17,14 +27,4 @@ enum ActiveScreen {
ERROR 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 #endif

2
home.c
View File

@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: MIT */ /* SPDX-License-Identifier: MIT */
#include <curses.h> #include <curses.h>
#include "globals.h" #include "screens.h"
void draw_home(struct Screen *screen, char *input) { void draw_home(struct Screen *screen, char *input) {
static char* banner = "" static char* banner = ""

2
home.h
View File

@@ -3,7 +3,7 @@
#ifndef HOME_H /* header guard */ #ifndef HOME_H /* header guard */
#define HOME_H #define HOME_H
#include "globals.h" #include "screens.h"
void draw_home(struct Screen *screen, char *input); void draw_home(struct Screen *screen, char *input);

19
screens.c Normal file
View File

@@ -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
}
};

10
screens.h Normal file
View File

@@ -0,0 +1,10 @@
/* SPDX-License-Identifier: MIT */
#ifndef SCREENS_H /* header guard */
#define SCREENS_H
#include "globals.h"
extern struct Screen screens[];
#endif