Added ncurses lib

This commit is contained in:
Max 2024-01-21 17:46:25 +01:00
parent f8790d776b
commit 7a1808f8c6
5 changed files with 25 additions and 7 deletions

View File

@ -8,6 +8,9 @@ find_package(OpenSSL REQUIRED)
target_link_libraries(netex OpenSSL::SSL)
find_package(json-c REQUIRED)
target_link_libraries(netex json-c)
find_package(Curses REQUIRED)
target_link_libraries(netex ${CURSES_LIBRARIES})
target_link_directories(netex PUBLIC ${CURSES_INCLUDE_DIR})
target_include_directories(netex PRIVATE ${CMAKE_SOURCE_DIR}/src/net/include)

View File

@ -2,11 +2,13 @@
#define NETEX_H
#include <stdio.h>
#include <ncurses.h>
#define PRINT(msg, args...) fprintf(stdout, msg, ##args)
#define PRINT_LINE(msg, args...) fprintf(stdout, msg "\n", ##args)
#define WARN(msg, args...) fprintf(stdout, "[Warning]: " msg "\n", ##args)
#define ERROR(msg, args...) fprintf(stderr, "[ERROR]: " msg "\n", ##args)
#define PRINT(msg, args...) printw(msg, ##args); refresh()
#define PRINT_LINE(msg, args...) printw(msg "\n", ##args); refresh()
#define WARN(msg, args...) printw("[Warning]: " msg "\n", ##args); refresh()
#define ERROR(msg, args...) printw("[ERROR]: " msg "\n", ##args); refresh()
typedef enum socket_ipv
{

View File

@ -11,11 +11,20 @@
#define PORT_NUM_LENGHT 6
// https://invisible-island.net/ncurses/
void netex_init(void)
{
// Curses
initscr();
noecho(); // Stop printing key presses
if (has_colors() && can_change_color())
{
start_color();
PRINT_LINE("%i colors available, %i color pairs available.", COLORS, COLOR_PAIRS);
//TODO: Make color pairs
}
// OpenSSL
PRINT_LINE("Initializing OpenSSL...");
SSL_load_error_strings();
SSL_library_init();
OpenSSL_add_all_algorithms();
@ -26,6 +35,8 @@ void netex_shutdown(void)
// OpenSSL
ERR_free_strings();
EVP_cleanup();
// Curses
endwin();
}
int setup_socket(const int port, const char* hostname, const SOCKET_IPV_TYPE ipv_type)

View File

@ -11,11 +11,14 @@
int main(int argc, char *argv[])
{
netex_init();
const int init_result = initialize_server(argc, argv);
if (init_result)
{
WARN("Failed to initialize server. Exiting...");
return init_result;
}
return server_execute();
const int srv_exec_result = server_execute();
netex_shutdown();
return srv_exec_result;
}

View File

@ -40,7 +40,6 @@ int initialize_server(int argc, char* argv[])
WARN("Failed to save configuration to disk, default config is only available in memory!");
}
}
netex_init();
// Socket
const int64_t portnum = config_get_int(srv_configuration, "Connection.Port");