Added library for shared functions.
This commit is contained in:
parent
efd17b030e
commit
09a1f69010
6 changed files with 47 additions and 21 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -5,4 +5,6 @@ cmake_install.cmake
|
|||
compile_commands.json
|
||||
.dir-locals.el
|
||||
Makefile
|
||||
Urchin-*
|
||||
urchin-*
|
||||
lib*.a
|
||||
lib*.so
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
project(Urchin
|
||||
project(urchin
|
||||
VERSION 0
|
||||
DESCRIPTION "Simple Mud Experiment in C"
|
||||
HOMEPAGE_URL "https://git.warwick-new.co.uk/"
|
||||
|
|
@ -9,6 +9,15 @@ set(CMAKE_C_STANDARD 90)
|
|||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(CMAKE_C_CLANG_TIDY)
|
||||
|
||||
# Compile Shared Library
|
||||
file(GLOB_RECURSE LIBRARY_SOURCE_FILES
|
||||
${CMAKE_SOURCE_DIR}/src/shared_lib/*.c)
|
||||
|
||||
file(GLOB_RECURSE LIBRARY_HEADER_FILES
|
||||
${CMAKE_SOURCE_DIR}/src/shared_lib/*.h)
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED ${LIBRARY_HEADER_FILES} ${LIBRARY_SOURCE_FILES})
|
||||
|
||||
# Compile Server
|
||||
file(GLOB_RECURSE SERVER_SOURCE_FILES
|
||||
${CMAKE_SOURCE_DIR}/src/server/*.c)
|
||||
|
|
@ -17,6 +26,7 @@ file(GLOB_RECURSE SERVER_HEADER_FILES
|
|||
${CMAKE_SOURCE_DIR}/src/server/*.h)
|
||||
|
||||
add_executable(${PROJECT_NAME}-server ${SERVER_HEADER_FILES} ${SERVER_SOURCE_FILES})
|
||||
target_link_libraries(${PROJECT_NAME}-server ${PROJECT_NAME})
|
||||
|
||||
# Compile Client
|
||||
file(GLOB_RECURSE CLIENT_SOURCE_FILES
|
||||
|
|
@ -26,3 +36,4 @@ file(GLOB_RECURSE CLIENT_HEADER_FILES
|
|||
${CMAKE_SOURCE_DIR}/src/client/*.h)
|
||||
|
||||
add_executable(${PROJECT_NAME}-client ${CLIENT_HEADER_FILES} ${CLIENT_SOURCE_FILES})
|
||||
target_link_libraries(${PROJECT_NAME}-client ${PROJECT_NAME})
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Sorry in advance for all the comments. This project is also a way for me to
|
||||
// learn C.
|
||||
|
||||
#include "error.h"
|
||||
#include <netdb.h> // Contains host structure
|
||||
#include <netinet/in.h> //sockaddr_in
|
||||
#include <stdio.h>
|
||||
|
|
@ -10,15 +11,15 @@
|
|||
#include <sys/socket.h> // sockaddr
|
||||
#include <sys/types.h>
|
||||
|
||||
void error_crash(const char *msg) {
|
||||
fprintf(stderr, "error crash: %s\n", msg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void error_warn(const char *msg) { fprintf(stderr, "warning: %s\n", msg); }
|
||||
|
||||
// TODO: Save the logs somewhere
|
||||
void error_log(const char *msg) { fprintf(stderr, "log: %s\n", msg); }
|
||||
// void error_crash(const char *msg) {
|
||||
// fprintf(stderr, "error crash: %s\n", msg);
|
||||
// exit(EXIT_FAILURE);
|
||||
// }
|
||||
//
|
||||
// void error_warn(const char *msg) { fprintf(stderr, "warning: %s\n", msg); }
|
||||
//
|
||||
// // TODO: Save the logs somewhere
|
||||
// void error_log(const char *msg) { fprintf(stderr, "log: %s\n", msg); }
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// Set up containers for file descriptor id's
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Sorry in advance for all the comments. This project is also a way for me to
|
||||
// learn C.
|
||||
|
||||
#include "error.h"
|
||||
#include <netinet/in.h> //sockaddr_in
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> // Keeping for conversion functions
|
||||
|
|
@ -9,16 +10,6 @@
|
|||
#include <sys/socket.h> // sockaddr
|
||||
#include <sys/types.h>
|
||||
|
||||
void error_crash(const char *msg) {
|
||||
fprintf(stderr, "error crash: %s\n", msg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void error_warn(const char *msg) { fprintf(stderr, "warning: %s\n", msg); }
|
||||
|
||||
// TODO: Save the logs somewhere
|
||||
void error_log(const char *msg) { fprintf(stderr, "log: %s\n", msg); }
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// Set up containers for file descriptor id's
|
||||
int sockfd, clientsockfd, portno, errflag;
|
||||
|
|
|
|||
11
src/shared_lib/error.c
Normal file
11
src/shared_lib/error.c
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include "error.h"
|
||||
|
||||
void error_crash(const char *msg) {
|
||||
fprintf(stderr, "error crash: %s\n", msg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void error_warn(const char *msg) { fprintf(stderr, "warning: %s\n", msg); }
|
||||
|
||||
// TODO: Save the logs somewhere
|
||||
void error_log(const char *msg) { fprintf(stderr, "log: %s\n", msg); }
|
||||
10
src/shared_lib/error.h
Normal file
10
src/shared_lib/error.h
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void error_crash(const char *msg);
|
||||
|
||||
void error_warn(const char *msg);
|
||||
|
||||
void error_log(const char *msg);
|
||||
Loading…
Reference in a new issue