broken code, but added attempt at writing grammar

This commit is contained in:
Ellen Arvidsson 2025-04-14 17:40:22 +02:00
parent fb95e5d026
commit 20e3757f44
18 changed files with 1145 additions and 142 deletions

View file

@ -1,32 +1,40 @@
#ifndef _SPHO_ERR_H
#define _SPHO_ERR_H
#define SPHO_ERR_SYSTEM 0x000001
#include <errno.h>
#define SPHO_ERR_INTERNAL 0x010001
#ifdef SPHO_DEBUG
#include <stdio.h>
#endif
#define SPHO_ERR_IS_SYSERR(err) (SPHO_ERR_SYSTEM == err)
#define SPHO_ERR_SYS 0x000001
#define SPHO_ERR_INTERNAL 0x010001
#define SPHO_ERR_TOOBIG 0x010002
#define SPHO_ERR_ARGINVAL 0x010003
#define SPHO_ERR_NAMEINUSE 0x010004
#define SPHO_ERR_IS_SYSERR(err) (SPHO_ERR_SYS == err)
#ifdef SPHO_DEBUG
#define SPHO_ERR(ctx, err) \
#define SPHO_ERR(ctx, e) \
do { \
ctx->err = err; \
if (err == SPHO_ERR_SYSTEM) \
ctx->err_info = errno; \
snprintf(ctx->filebuf, sizeof(ctx->filebuf), "%s", \
(ctx)->err = (e); \
if ((e) == SPHO_ERR_SYS) \
(ctx)->err_info = errno; \
snprintf((ctx)->filebuf, sizeof((ctx)->filebuf), \
__FILE__); \
ctx->filebuf[sizeof(ctx->filebuf) - 1] = '\0'; \
ctx->errline = __LINE__; \
(ctx)->errline = __LINE__; \
} while (0)
#else /* SPHO_DEBUG */
#define SPHO_ERR(ctx, err) \
#define SPHO_ERR(ctx, e) \
do { \
ctx->err = err; \
if (err == SPHO_ERR_SYSTEM) \
ctx->err_info = errno; \
(ctx)->err = (e); \
if ((e) == SPHO_ERR_SYS) \
(ctx)->err_info = errno; \
} while (0)
#endif /* SPHO_DEBUG */
@ -34,30 +42,40 @@
/* debug stuff */
#ifdef SPHO_DEBUG
/* PRECOND/ASSERT/POSTCOND */
#define SPHO_PRECOND(cond) do { \
if (! (cond) ) { \
fprintf(stderr, "SPHO_PRECOND(" #cond ")@" __FILE__ ":" __LINE__ \
" failed. Aborting."); \
abort(); \
} \
} while (0)
#define SPHO_STRINGIFY(a) #a
#define SPHO_MACRO_STR(b) SPHO_STRINGIFY(b)
#define SPHO_ASSERT(cond) do { \
if (! (cond) ) { \
fprintf(stderr, "SPHO_ASSERT(" #cond ")@" __FILE__ ":" __LINE__ \
" failed. Aborting."); \
abort(); \
} \
} while (0)
#define __LINE__S SPHO_MACRO_STR(__LINE__)
#define SPHO_POSTCOND(cond) do { \
if (! (cond) ) { \
fprintf(stderr, "SPHO_POSTCOND(" #cond ")@" __FILE__ ":" __LINE__ \
" failed. Aborting."); \
abort(); \
} \
} while (0)
#define SPHO_PRECOND(cond) \
do { \
if (! (cond) ) { \
fprintf(stderr, "SPHO_PRECOND(" #cond ")@" \
__FILE__ ":" __LINE__S \
" failed. Aborting.\n"); \
abort(); \
} \
} while (0)
#define SPHO_ASSERT(cond) \
do { \
if (! (cond) ) { \
fprintf(stderr, "SPHO_ASSERT(" #cond ")@" \
__FILE__ ":" __LINE__S \
" failed. Aborting.\n"); \
abort(); \
} \
} while (0)
#define SPHO_POSTCOND(cond) \
do { \
if (! (cond) ) { \
fprintf(stderr, "SPHO_POSTCOND(" #cond ")@" \
__FILE__ ":" __LINE__S \
" failed. Aborting.\n"); \
abort(); \
} \
} while (0)
#else
#define SPHO_PRECOND(cond)