diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2019-03-27 20:58:54 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2019-03-27 20:58:54 +0100 |
commit | ac8e82c3a11f79082e9ed5f5f9c654c8f32b2ebc (patch) | |
tree | bbcaf58ac980987495f072e96c40150c2d119f48 | |
parent | 2bc12dae0b1b0f17b80f79d7eef8e807c5e9341e (diff) | |
download | blogc-ac8e82c3a11f79082e9ed5f5f9c654c8f32b2ebc.tar.gz blogc-ac8e82c3a11f79082e9ed5f5f9c654c8f32b2ebc.tar.bz2 blogc-ac8e82c3a11f79082e9ed5f5f9c654c8f32b2ebc.zip |
blogc: dump source file variables as well as global variables
-rw-r--r-- | man/blogc.1.ronn | 12 | ||||
-rw-r--r-- | src/blogc/main.c | 15 |
2 files changed, 19 insertions, 8 deletions
diff --git a/man/blogc.1.ronn b/man/blogc.1.ronn index 96b7874..eb64420 100644 --- a/man/blogc.1.ronn +++ b/man/blogc.1.ronn @@ -58,9 +58,15 @@ designed to be used with make(1). See blogc-template(7) for details. * `-p` <KEY>: - Show the value of a global configuration parameter right after the source - parsing and exits. This is useful to get parameters for your `Makefile`, - like the last page when using pagination, see blogc-pagination(7) for details. + Show the value of a variable right after the source parsing and exits. This + is useful to get parameters for your `Makefile`, like the last page when + implementing pagination, see blogc-pagination(7) for details. This can be + also useful to dump variables defined in a source file without parsing it + manually, if called without `-l`. Please note that variables generated by + blogc during rendering process, like `BLOGC_RUSAGE_MEMORY` are not available + because blogc will exit without rendering any content when called with this + option, and will not even require a template, but variables generated during + parsing process, like `CONTENT` are available. * `-t` <TEMPLATE>: Template file. It is a required option, if `blogc` needs to render something. diff --git a/src/blogc/main.c b/src/blogc/main.c index 0e6bcc9..1ca0e82 100644 --- a/src/blogc/main.c +++ b/src/blogc/main.c @@ -60,9 +60,8 @@ blogc_print_help(void) " -d enable debug\n" " -i read list of source files from standard input\n" " -l build listing page, from multiple source files\n" - " -D KEY=VALUE set global configuration parameter\n" - " -p KEY show the value of a global configuration parameter\n" - " after source parsing and exit\n" + " -D KEY=VALUE set global variable\n" + " -p KEY show the value of a variable after source parsing and exit\n" " -t TEMPLATE template file\n" " -o OUTPUT output file\n" #ifdef MAKE_EMBEDDED @@ -292,9 +291,15 @@ main(int argc, char **argv) } if (print != NULL) { - const char *val = bc_trie_lookup(config, print); + const char *val = NULL; + if (!listing && s != NULL) { + val = bc_trie_lookup(s->data, print); + } + if (val == NULL) { + val = bc_trie_lookup(config, print); + } if (val == NULL) { - fprintf(stderr, "blogc: error: configuration variable not found: %s\n", + fprintf(stderr, "blogc: error: variable not found: %s\n", print); rv = 3; } |