summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/driver/amgc_unit_ctx.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/driver/amgc_unit_ctx.c b/src/driver/amgc_unit_ctx.c
index 54824e1..cfc2c0b 100644
--- a/src/driver/amgc_unit_ctx.c
+++ b/src/driver/amgc_unit_ctx.c
@@ -18,8 +18,9 @@
#include <apimagic/apimagic.h>
#include "apimagic_driver_impl.h"
+#include "apimagic_errinfo_impl.h"
-static int amgc_free_unit_ctx_impl(struct amgc_unit_ctx_impl * ctx, int status)
+static int amgc_free_unit_ctx_impl(struct amgc_unit_ctx_impl * ctx, int ret)
{
if (ctx) {
if (ctx->entities)
@@ -29,7 +30,7 @@ static int amgc_free_unit_ctx_impl(struct amgc_unit_ctx_impl * ctx, int status)
free(ctx);
}
- return status;
+ return ret;
}
static FILE * amgc_stdin_to_tmp(const struct amgc_driver_ctx * dctx)
@@ -120,20 +121,33 @@ int amgc_get_unit_ctx(
amgc_init_cparser_unit();
- if (!dctx || !(ctx = calloc(1,sizeof(*ctx))))
- return -1;
+ if (!dctx)
+ return AMGC_CUSTOM_ERROR(
+ dctx,AMGC_ERR_NULL_CONTEXT);
+
+ else if (!(ctx = calloc(1,sizeof(*ctx))))
+ return AMGC_SYSTEM_ERROR(dctx);
+
+ amgc_driver_set_ectx(
+ dctx,0,path);
if (strcmp(path,"-"))
fd = -1;
+
else if (!(ftmp = amgc_stdin_to_tmp(dctx)))
- return amgc_free_unit_ctx_impl(ctx,-1);
+ return amgc_free_unit_ctx_impl(
+ ctx,AMGC_SYSTEM_ERROR(dctx));
+
else if ((fd = dup(fileno(ftmp))) < 0)
- return amgc_free_unit_ctx_impl(ctx,-1);
+ return amgc_free_unit_ctx_impl(
+ ctx,AMGC_SYSTEM_ERROR(dctx));
+
else
ctx->ccunit.input = ftmp;
if (amgc_map_input(dctx,fd,path,PROT_READ,&ctx->map))
- return amgc_free_unit_ctx_impl(ctx,-1);
+ return amgc_free_unit_ctx_impl(
+ ctx,AMGC_NESTED_ERROR(dctx));
if (fd > 0)
close(fd);
@@ -148,7 +162,8 @@ int amgc_get_unit_ctx(
if ((process_unit(ctx->cctx.ccenv,&ctx->ccunit)) == false) {
if (ctx->ccunit.input)
fclose(ctx->ccunit.input);
- return amgc_free_unit_ctx_impl(ctx,-1);
+ return amgc_free_unit_ctx_impl(
+ ctx,AMGC_CUSTOM_ERROR(dctx,AMGC_ERR_FLOW_ERROR));
}
memcpy(&ctx->cctx,dctx->cctx,
@@ -162,7 +177,8 @@ int amgc_get_unit_ctx(
ctx->uctx.ccunit = &ctx->ccunit;
if (amgc_get_unit_entities(&ctx->uctx,&ctx->meta,&ctx->entities))
- return amgc_free_unit_ctx_impl(ctx,-1);
+ return amgc_free_unit_ctx_impl(
+ ctx,AMGC_CUSTOM_ERROR(dctx,AMGC_ERR_FLOW_ERROR));
ctx->uctx.entities = ctx->entities;
*pctx = &ctx->uctx;