From d38f82f6462af4e5aad6a2c776f5c00ce5b13c87 Mon Sep 17 00:00:00 2001 From: Linnnus Date: Thu, 1 Feb 2024 22:59:38 +0100 Subject: feat: initial commit Here is a small overview of the state of the project at this first commit. I have basic Git Repo -> HTML working, and a plan for how setting up an actual server would work (mainly, NGINX + a git hook to rebuild). The main thing I'm working on right now is parsing WikiCreole, though I am starting to wonder if this is the right langauge. WikiCreole is pretty irregular and has a lot of edge cases (e.g. around emphasis). --- src/die.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/die.c (limited to 'src/die.c') diff --git a/src/die.c b/src/die.c new file mode 100644 index 0000000..529eb9b --- /dev/null +++ b/src/die.c @@ -0,0 +1,58 @@ +#include "die.h" + +#include // assert +#include // fprintf, vfprintf, fputc, stderr +#include // exit, EXIT_FAILURE +#include // va_* +#include // git_* +#include // strerror +#include // errno + +void die(const char *msg, ...) +{ + va_list ap; + va_start(ap, msg); + vfprintf(stderr, msg, ap); + va_end(ap); + + fputc('\n', stderr); + +#ifndef NDEBUG + git_libgit2_shutdown(); +#endif + exit(EXIT_FAILURE); +} + +// Die but include the last git error. +void noreturn die_git(const char *msg, ...) +{ + va_list ap; + va_start(ap, msg); + vfprintf(stderr, msg, ap); + va_end(ap); + + const git_error *e = git_error_last(); + assert(e != NULL && "die_git called without error"); + fprintf(stderr, ": %s\n", e->message); + +#ifndef NDEBUG + git_libgit2_shutdown(); +#endif + exit(EXIT_FAILURE); +} + +// Die but include errno information. +void noreturn die_errno(const char *msg, ...) +{ + va_list ap; + va_start(ap, msg); + vfprintf(stderr, msg, ap); + va_end(ap); + + fprintf(stderr, ": %s\n", strerror(errno)); + +#ifndef NDEBUG + git_libgit2_shutdown(); +#endif + exit(EXIT_FAILURE); +} -- cgit v1.2.3