diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-11-15 23:14:13 -0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-11-15 23:14:13 -0200 |
commit | 38fe0a8d151e681e4818f9afceb5188470fc0636 (patch) | |
tree | 60f68287558baa2255c0701566c5f974f35afcdb /src/directives.c | |
parent | 74dfcce06d39060a4a97c1dd06db9eb55cdbf001 (diff) | |
download | blogc-38fe0a8d151e681e4818f9afceb5188470fc0636.tar.gz blogc-38fe0a8d151e681e4818f9afceb5188470fc0636.tar.bz2 blogc-38fe0a8d151e681e4818f9afceb5188470fc0636.zip |
directives: improved loader
Diffstat (limited to 'src/directives.c')
-rw-r--r-- | src/directives.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/directives.c b/src/directives.c index ed8b568..b538825 100644 --- a/src/directives.c +++ b/src/directives.c @@ -17,7 +17,7 @@ #include "error.h" -blogc_directive_t registry[] = { +const static blogc_directive_t registry[] = { {"youtube", blogc_directive_youtube}, {NULL, NULL}, }; @@ -28,14 +28,13 @@ blogc_directive_loader(blogc_directive_ctx_t *ctx, blogc_error_t **err) { if (ctx == NULL) return NULL; - for (unsigned int i = 0; registry[i].name != NULL; i++) { - if (0 == strcmp(ctx->name, registry[i].name)) { - if (err != NULL && *err != NULL) { - return NULL; - } + if (err == NULL || *err != NULL) + return NULL; + for (unsigned int i = 0; registry[i].name != NULL; i++) + if (0 == strcmp(ctx->name, registry[i].name)) return registry[i].callback(ctx, err); - } - } + *err = blogc_error_new_printf(BLOGC_WARNING_CONTENT_PARSER, + "Directive not found: %s", ctx->name); return NULL; } @@ -45,7 +44,7 @@ blogc_directive_youtube(blogc_directive_ctx_t *ctx, blogc_error_t **err) { if (ctx->argument == NULL) { *err = blogc_error_new_printf(BLOGC_WARNING_CONTENT_PARSER, - "youtube: Invalid video ID: %s", ctx->argument); + "youtube: video ID must be provided as argument"); return NULL; } |