From c1263dfa8510e475be2a3b3fac3edb8605f3c6ef Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 21 Feb 2026 16:44:57 +0100 Subject: [PATCH 1/1] Initial commit --- .gitattributes | 1 + .gitignore | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ BUGS.md | 3 +++ LICENSE | 18 +++++++++++++ README.md | 32 ++++++++++++++++++++++++ STYLE.md | 20 +++++++++++++++ TODO.md | 2 ++ makefile | 48 +++++++++++++++++++++++++++++++++++ man/lmud.1 | 40 +++++++++++++++++++++++++++++ man/lmud.5 | 14 +++++++++++ src/lmud.c | 57 ++++++++++++++++++++++++++++++++++++++++++ src/lmud.h | 49 ++++++++++++++++++++++++++++++++++++ src/main.c | 11 ++++++++ src/test.c | 17 +++++++++++++ src/u_mem.c | 1 + src/u_mem.h | 6 +++++ src/u_stdio.c | 14 +++++++++++ src/u_stdio.h | 14 +++++++++++ 18 files changed, 415 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 BUGS.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 STYLE.md create mode 100644 TODO.md create mode 100644 makefile create mode 100644 man/lmud.1 create mode 100644 man/lmud.5 create mode 100644 src/lmud.c create mode 100644 src/lmud.h create mode 100644 src/main.c create mode 100644 src/test.c create mode 100644 src/u_mem.c create mode 100644 src/u_mem.h create mode 100644 src/u_stdio.c create mode 100644 src/u_stdio.h diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..51a31e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,68 @@ +# Build directory +bin/ +obj/ +tags + + Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb +vgcore.* + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +compile_commands.json +.cache/ +.clang_complete +# .clangd +.session + +lmud +testlmud +*.patch diff --git a/BUGS.md b/BUGS.md new file mode 100644 index 0000000..616168d --- /dev/null +++ b/BUGS.md @@ -0,0 +1,3 @@ +# Known Bugs + + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5e5b158 --- /dev/null +++ b/LICENSE @@ -0,0 +1,18 @@ +Copyright 2025-2026 Lukas Krickl (lukas@krickl.dev) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, +including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, +and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", +WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..306b681 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# lmud + +lukas' multi user dungeon. + +## Table of content + +- [Installation](#Installation) +- [Usage](#Usage) +- [License](#License) +- [Contributing](#Contributing) +- [TODO](#TODO) + +## Installation + +To build this program you will require a recent C compiler, and make. + +```sh +make # to compile all targets +``` + +## Usage + +Usage instructions can be found in the manual. + +- man/lmud.1: Command reference + +## License + +This program is distributed under the terms of the MIT License. + +## Contributing + diff --git a/STYLE.md b/STYLE.md new file mode 100644 index 0000000..28d350d --- /dev/null +++ b/STYLE.md @@ -0,0 +1,20 @@ +# Coding Style + +## Modules + +The code base is split into modules. +Files and all functions therein are prefixed with one of the following: + +- `lmud_`: public api +- `t_`: thinker related +- `r_`: rendering +- `n_`: network +- `m_`: macro command language +- `c_`: client-side code +- `s_`: server side code +- `u_`: system utility code + +## Library functions + +Third party functions (even the C stdlib) should be wrapped at all times. +Platform specific code (including the stdlib) should be clearly marked. diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..b6dbda7 --- /dev/null +++ b/TODO.md @@ -0,0 +1,2 @@ +# TODO + diff --git a/makefile b/makefile new file mode 100644 index 0000000..f2cfe5b --- /dev/null +++ b/makefile @@ -0,0 +1,48 @@ +NAME=lmud +TEST_NAME=test$(NAME) +DBGCFLAGS=-g -fsanitize=address +DBGLDFLAGS=-fsanitize=address +CFLAGS=-Wall -pedantic $(DBGCFLAGS) -std=c89 +LIBS= +LDFLAGS=$(DBGLDFLAGS) $(LIBS) + +INSTALL_DIR=/usr/local +OBJS:= + +CCOBJ=$(CC) -c -o $@ $< $(CFLAGS) $(LDFLAGS) + +all: bin test + +release: + make DBGCFLAGS="" DBGLDFLAGS="" + +.PHONY: FORCE +FORCE: + +main.o: src/main.c FORCE + $(CCOBJ) +test.o: src/test.c FORCE + $(CCOBJ) + + +bin: main.o $(OBJS) + $(CC) -o $(NAME) main.o $(OBJS) $(CFLAGS) $(LDFLAGS) + +test: test.o $(OBJS) + $(CC) -o $(TEST_NAME) test.o $(OBJS) $(CFLAGS) $(LDFLAGS) + +.PHONY: clean +clean: + rm -f ./*.o + rm -f ./$(NAME) + rm -f ./$(TEST_NAME) + +.PHONY: install +install: + mkdir -p $(INSTALL_DIR)/bin + mkdir -p $(INSTALL_DIR)/man/man1 + mkdir -p $(INSTALL_DIR)/man/man5 + cp ./$(NAME) $(INSTALL_DIR)/bin + cp ./man/$(NAME).1 $(INSTALL_DIR)/man/man1 + cp ./man/$(NAME).5 $(INSTALL_DIR)/man/man5 + diff --git a/man/lmud.1 b/man/lmud.1 new file mode 100644 index 0000000..ff3e815 --- /dev/null +++ b/man/lmud.1 @@ -0,0 +1,40 @@ +.\" Manpage for lmud. +.\" Contact lukas@krickl.dev to correct errors or typos. + +.TH man 1 "21 Febuary 2026" "0.0.1" "lmud manual" + +.SH NAME + lmud +.SH SYNOPSIS + lmud [-hvV] [-c=command] +.SH DESCRIPTION + lmud + + -h + display this help and exit + + -V + display version info and exit + + -v + verbose output + + -c + execute a command and exit + +.SH EXAMPLES + +.SH SEE ALSO + lmud(5) for a command syntax reference + + The documentation for make(1) for compilation instructions. + + A compiler documentation such as cc(1) gcc(1) or clang(1). + +.SH BUGS + +.SH AUTHOR + Lukas Krickl (lukas@krickl.dev) + +.SH COPYRIGHT + Copyright 2026 Lukas Krickl (lukas@krickl.dev) diff --git a/man/lmud.5 b/man/lmud.5 new file mode 100644 index 0000000..230a5d7 --- /dev/null +++ b/man/lmud.5 @@ -0,0 +1,14 @@ +.\" Manpage for lmud. +.\" Contact lukas@krickl.dev to correct errors or typos. + +.TH man 5 "21 Febuary 2026" "0.0.1" "lmud command language reference" + +.SH SEE ALSO + + lmud(1) for a reference on how to use lmud. + +.SH AUTHOR + Lukas Krickl (lukas@krickl.dev) + +.SH COPYRIGHT + Copyright 2026 Lukas Krickl (lukas@krickl.dev) diff --git a/src/lmud.c b/src/lmud.c new file mode 100644 index 0000000..1286643 --- /dev/null +++ b/src/lmud.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include "lmud.h" + +struct lmud_config lmud_global_cfg; + +struct lmud_config* lmud_cfg() { + return &lmud_global_cfg; +} + +void lmud_help(int argc, char **argv) { + u_printf(u_stderr, "%s\n", argv[0]); + u_printf(u_stderr, "Usage: %s [-%s] [-c=command]\n\n", + argv[0], LMUD_OPTS); + LMUD_HELP("h", "display this help and exit"); + LMUD_HELP("V", "display version info and exit"); + LMUD_HELP("v", "verbose output"); +} + +void lmud_version(void) { + u_printf(u_stderr, "%s\n", LMUD_VER); +} + +void lmud_getopt(int argc, char **argv, struct lmud_config *cfg) { + int c = 0; + while ((c = getopt(argc, argv, LMUD_OPTS LMUD_OPTS_ARG)) != -1) { + switch (c) { + case 'h': + lmud_help(argc, argv); + exit(0); + break; + case 'V': + lmud_version(); + exit(0); + break; + case 'v': + cfg->verbose = 1; + break; + case '?': + break; + default: + u_printf(u_stderr, "%s: invalid option '%c'\nTry '%s -h' for more information.\n", + argv[0], c, argv[0]); + exit(-1); + break; + } + } + + cfg->argc = argc - optind; + cfg->argv = argv + optind; +} + +int lmud_main(int argc, char **argv) { + lmud_getopt(argc, argv, lmud_cfg()); + return 0; +} diff --git a/src/lmud.h b/src/lmud.h new file mode 100644 index 0000000..481e6b2 --- /dev/null +++ b/src/lmud.h @@ -0,0 +1,49 @@ +#ifndef LMUD_H__ +#define LMUD_H__ + +/** + * System includes + */ +#include "u_stdio.h" +#include "u_mem.h" + +#define LMUD_VER "0.0.1" + +/* args without value */ +#define LMUD_OPTS "hvV" + +/* args with value */ +#define LMUD_OPTS_ARG "c:" +#define LMUD_HELP(a, desc) printf("\t-%s\t%s\n", (a), desc); + +typedef unsigned char lmud_bool; +#define LMUD_TRUE 1 +#define LMUD_FALSE 0 + +struct lmud_config { + lmud_bool verbose; + + char **argv; + int argc; +}; + +struct lmud_config* lmud_cfg(); +void lmud_help(int argc, char **argv); +void lmud_version(void); +void lmud_getopt(int argc, char **argv, struct lmud_config *cfg); +int lmud_main(int argc, char **argv); + + +/** + * If this is an implementation + * we include all c files for a mono-build + */ +#ifdef LMUD_IMPL + +#include "lmud.c" +#include "u_stdio.c" +#include "u_mem.c" + +#endif + +#endif diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..e96a978 --- /dev/null +++ b/src/main.c @@ -0,0 +1,11 @@ +#define LMUD_IMPL + +#include +#include +#include +#include +#include "lmud.h" + +int main(int argc, char **argv) { + return lmud_main(argc, argv); +} diff --git a/src/test.c b/src/test.c new file mode 100644 index 0000000..8f5411f --- /dev/null +++ b/src/test.c @@ -0,0 +1,17 @@ +#define LMUD_IMPL + +#include +#include +#include "lmud.h" + +#define TESTBEGIN(name) { u_printf(u_stderr, "%s\n", name); } + +#define TESTEND(name) { u_printf(u_stderr, "%s\n", name); } + +int main(int argc, char **argv) { + TESTBEGIN("lmud test"); + lmud_getopt(argc, argv, lmud_cfg()); + + TESTEND("lmud test"); + return 0; +} diff --git a/src/u_mem.c b/src/u_mem.c new file mode 100644 index 0000000..ec55198 --- /dev/null +++ b/src/u_mem.c @@ -0,0 +1 @@ +#include "u_mem.h" diff --git a/src/u_mem.h b/src/u_mem.h new file mode 100644 index 0000000..6984914 --- /dev/null +++ b/src/u_mem.h @@ -0,0 +1,6 @@ +#ifndef U_MEM_H__ +#define U_MEM_H__ + + + +#endif diff --git a/src/u_stdio.c b/src/u_stdio.c new file mode 100644 index 0000000..73968c1 --- /dev/null +++ b/src/u_stdio.c @@ -0,0 +1,14 @@ +#include +#include "u_stdio.h" + +int u_printf(U_FILE* stream, const char *fmt, ...) { + int res = 0; + va_list args; + + va_start(args, fmt); + res = vfprintf(stream, fmt, args); + va_end(args); + + return res; +} + diff --git a/src/u_stdio.h b/src/u_stdio.h new file mode 100644 index 0000000..db8ad36 --- /dev/null +++ b/src/u_stdio.h @@ -0,0 +1,14 @@ +#ifndef U_STDIO_H__ +#define U_STDIO_H__ + + +typedef FILE U_FILE; + +#define u_stdin stdin +#define u_stdout stdout +#define u_stderr stderr + +int u_printf(U_FILE* stream, const char *fmt, ...); + + +#endif -- 2.30.2