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

@ -4,7 +4,6 @@
#include <stdlib.h>
#include <string.h>
#include "spho/err.h"
#include "spho/ctx.h"
static const char *spho_ctx_sys_strerror(struct spho_ctx *);
@ -16,8 +15,11 @@ struct spho_err {
};
struct spho_err spho_errmsgs[] = {
{ SPHO_ERR_SYSTEM, "spho system error" },
{ SPHO_ERR_INTERNAL, "spho internal error" },
{ SPHO_ERR_SYS, "spho system error" },
{ SPHO_ERR_INTERNAL, "spho internal error" },
{ SPHO_ERR_TOOBIG, "parameter size too big" },
{ SPHO_ERR_ARGINVAL, "invalid argument" },
{ SPHO_ERR_NAMEINUSE, "name in use" },
{ -1, NULL }
};
@ -26,14 +28,20 @@ spho_ctx_create(void)
{
struct spho_ctx *c;
c = NULL;
if ((c = malloc(sizeof(struct spho_ctx))) == NULL)
return (NULL);
c->err = 0;
c->err_info = 0;
SLIST_INIT(&c->noms);
SLIST_INIT(&c->cnsts);
if (spho_scope_init(&c->glob, c, NULL) == -1) {
free(c);
return (NULL);
}
SPHO_POSTCOND(c != NULL);
return (c);
}
@ -41,22 +49,11 @@ spho_ctx_create(void)
void
spho_ctx_destroy(struct spho_ctx *ctx)
{
struct spho_nom_le *nom;
struct spho_cnst_le *cnst;
SPHO_PRECOND(ctx != NULL);
while (! SLIST_EMPTY(&ctx->noms)) {
nom = SLIST_FIRST(&ctx->noms);
SLIST_REMOVE_HEAD(&ctx->noms, next);
free(nom);
}
spho_scope_term(&ctx->glob);
while (! SLIST_EMPTY(&ctx->cnsts)) {
cnst = SLIST_FIRST(&ctx->cnsts);
SLIST_REMOVE_HEAD(&ctx->cnsts, next);
free(cnst);
}
free(ctx);
}