summaryrefslogtreecommitdiff
path: root/src/driver
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-01-02 11:57:37 -0500
committermidipix <writeonce@midipix.org>2016-01-02 11:57:37 -0500
commit6adb90fd75f544895ba8ffc960f08ff00dc58949 (patch)
treec73ada7c1e59ddd865b9f277ca062fddbf7a8d71 /src/driver
parentca20d63c3c17dfdb0b4d34a99b0d630043d1b74f (diff)
downloadapimagic-6adb90fd75f544895ba8ffc960f08ff00dc58949.tar.bz2
apimagic-6adb90fd75f544895ba8ffc960f08ff00dc58949.tar.xz
action vector and action iteration: initial implementation.
Diffstat (limited to 'src/driver')
-rw-r--r--src/driver/amgc_driver_ctx.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/driver/amgc_driver_ctx.c b/src/driver/amgc_driver_ctx.c
index 66e4f2f..c25be55 100644
--- a/src/driver/amgc_driver_ctx.c
+++ b/src/driver/amgc_driver_ctx.c
@@ -28,6 +28,7 @@ extern const struct argv_option amgc_default_options[];
struct amgc_driver_ctx_alloc {
struct argv_meta * meta;
+ struct amgc_action * actions;
struct amgc_driver_ctx_impl ctx;
uint64_t guard;
const char * units[];
@@ -70,9 +71,11 @@ static int amgc_driver_usage(
static struct amgc_driver_ctx_impl * amgc_driver_ctx_alloc(
struct argv_meta * meta,
const struct amgc_common_ctx * cctx,
- size_t nunits)
+ size_t nunits,
+ size_t nactions)
{
struct amgc_driver_ctx_alloc * ictx;
+ struct amgc_action * actions;
size_t size;
struct argv_entry * entry;
const char ** units;
@@ -83,6 +86,11 @@ static struct amgc_driver_ctx_impl * amgc_driver_ctx_alloc(
if (!(ictx = calloc(1,size)))
return 0;
+ if (!(actions = calloc(nactions+1,sizeof(*ictx->actions)))) {
+ free(ictx);
+ return 0;
+ }
+
if (cctx)
memcpy(&ictx->ctx.cctx,cctx,sizeof(*cctx));
@@ -92,6 +100,8 @@ static struct amgc_driver_ctx_impl * amgc_driver_ctx_alloc(
ictx->meta = meta;
ictx->ctx.fdtmpin = -1;
+ ictx->actions = actions;
+ ictx->ctx.actions = actions;
ictx->ctx.ctx.units = ictx->units;
return &ictx->ctx;
}
@@ -130,6 +140,7 @@ int amgc_get_driver_ctx(
struct argv_meta * meta;
struct argv_entry * entry;
size_t nunits;
+ size_t nactions;
const char * program;
options = amgc_default_options;
@@ -138,6 +149,7 @@ int amgc_get_driver_ctx(
return -1;
nunits = 0;
+ nactions= 0;
program = argv_program_name(argv[0]);
memset(&cctx,0,sizeof(cctx));
@@ -162,6 +174,10 @@ int amgc_get_driver_ctx(
case TAG_LANG_STD:
cctx.std = amgc_lang_std_from_string(entry->arg);
break;
+
+ default:
+ nactions++;
+ break;
}
} else
nunits++;
@@ -170,11 +186,22 @@ int amgc_get_driver_ctx(
if (amgc_init_cparser())
return amgc_get_driver_ctx_fail(meta);
- if (!(ctx = amgc_driver_ctx_alloc(meta,&cctx,nunits)))
+ if (!(ctx = amgc_driver_ctx_alloc(meta,&cctx,nunits,nactions)))
return amgc_get_driver_ctx_fail(meta);
+ /* create action vector */
+ for (entry=meta->entries,nactions=0; entry->fopt || entry->arg; entry++)
+ if (entry->fopt)
+ switch (entry->tag) {
+ case TAG_PRINT_ENUMS:
+ ctx->actions[nactions].type = AMGC_ACTION_OUTPUT;
+ ctx->actions[nactions++].action = AMGC_OUTPUT_ENUM;
+ break;
+ }
+
ctx->ctx.program = program;
ctx->ctx.cctx = &ctx->cctx;
+ ctx->cctx.actions = ctx->actions;
ctx->cctx.ccenv = &ctx->ccenv;
*pctx = &ctx->ctx;
@@ -192,7 +219,7 @@ int amgc_create_driver_ctx(
if (!(meta = argv_get(argv,amgc_default_options,0)))
return -1;
- if (!(ctx = amgc_driver_ctx_alloc(meta,cctx,0)))
+ if (!(ctx = amgc_driver_ctx_alloc(meta,cctx,0,0)))
return amgc_get_driver_ctx_fail(0);
ctx->ctx.cctx = &ctx->cctx;
@@ -216,6 +243,7 @@ static void amgc_exit_cparser(void)
static void amgc_free_driver_ctx_impl(struct amgc_driver_ctx_alloc * ictx)
{
argv_free(ictx->meta);
+ free(ictx->actions);
free(ictx);
amgc_exit_cparser();
}