diff options
-rw-r--r-- | man/blogc.1.ronn | 9 | ||||
-rw-r--r-- | src/main.c | 48 |
2 files changed, 43 insertions, 14 deletions
diff --git a/man/blogc.1.ronn b/man/blogc.1.ronn index ddf33ca..d657529 100644 --- a/man/blogc.1.ronn +++ b/man/blogc.1.ronn @@ -5,6 +5,7 @@ blogc(1) -- a blog compiler `blogc` [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] <SOURCE><br> `blogc` `-l` [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] <SOURCE> [<SOURCE> ...]<br> +`blogc` `-l` `-p` <KEY> [`-D` <KEY>=<VALUE> ...] <SOURCE> [<SOURCE> ...]<br> `blogc` [`-h`|`-v`] ## DESCRIPTION @@ -40,8 +41,14 @@ designed to be used with make(1). but may be overridden by local configuration parameters set in source files. 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 support. + * `-t` <TEMPLATE>: - Template file. It is a required option. See blogc-template(7) for details. + Template file. It is a required option, if `blogc` needs to render something. + See blogc-template(7) for details. * `-o` <OUTPUT>: Output file. If provided this option, save the compiled output to the given @@ -36,7 +36,7 @@ blogc_print_help(void) { printf( "usage:\n" - " blogc [-h] [-v] [-l] [-D KEY=VALUE ...] -t TEMPLATE [-o OUTPUT] SOURCE [SOURCE ...] - A blog compiler.\n" + " blogc [-h] [-v] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE] [-o OUTPUT] SOURCE [SOURCE ...] - A blog compiler.\n" "\n" "positional arguments:\n" " SOURCE source file(s)\n" @@ -46,6 +46,7 @@ blogc_print_help(void) " -v show version and exit\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 after source parsing and exit\n" " -t TEMPLATE template file\n" " -o OUTPUT output file\n"); } @@ -54,7 +55,7 @@ blogc_print_help(void) static void blogc_print_usage(void) { - printf("usage: blogc [-h] [-v] [-l] [-D KEY=VALUE ...] -t TEMPLATE [-o OUTPUT] SOURCE [SOURCE ...]\n"); + printf("usage: blogc [-h] [-v] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE] [-o OUTPUT] SOURCE [SOURCE ...]\n"); } @@ -101,6 +102,7 @@ main(int argc, char **argv) bool listing = false; char *template = NULL; char *output = NULL; + char *print = NULL; char *tmp = NULL; char **pieces = NULL; @@ -132,6 +134,12 @@ main(int argc, char **argv) else if (i + 1 < argc) output = b_strdup(argv[++i]); break; + case 'p': + if (argv[i][2] != '\0') + print = b_strdup(argv[i] + 2); + else if (i + 1 < argc) + print = b_strdup(argv[++i]); + break; case 'D': if (argv[i][2] != '\0') tmp = argv[i] + 2; @@ -175,13 +183,6 @@ main(int argc, char **argv) sources = b_slist_append(sources, b_strdup(argv[i])); } - if (template == NULL) { - blogc_print_usage(); - fprintf(stderr, "blogc: error: argument -t is required\n"); - rv = 2; - goto cleanup; - } - if (b_slist_length(sources) == 0) { blogc_print_usage(); if (listing) @@ -202,18 +203,38 @@ main(int argc, char **argv) blogc_error_t *err = NULL; - b_slist_t* l = blogc_template_parse_from_file(template, &err); + b_slist_t *s = blogc_source_parse_from_files(config, sources, &err); if (err != NULL) { blogc_error_print(err); goto cleanup2; } - b_slist_t *s = blogc_source_parse_from_files(config, sources, &err); + b_slist_t* l = blogc_template_parse_from_file(template, &err); if (err != NULL) { blogc_error_print(err); goto cleanup3; } + if (print != NULL) { + const char *val = b_trie_lookup(config, print); + if (val == NULL) { + fprintf(stderr, "blogc: error: configuration variable not found: %s\n", + print); + rv = 2; + } + else { + printf("%s\n", val); + } + goto cleanup3; + } + + if (template == NULL) { + blogc_print_usage(); + fprintf(stderr, "blogc: error: argument -t is required when rendering content\n"); + rv = 2; + goto cleanup3; + } + char *out = blogc_render(l, s, config, listing); bool write_to_stdout = (output == NULL || (0 == strcmp(output, "-"))); @@ -239,14 +260,15 @@ main(int argc, char **argv) cleanup4: free(out); cleanup3: - b_slist_free_full(s, (b_free_func_t) b_trie_free); -cleanup2: blogc_template_free_stmts(l); +cleanup2: + b_slist_free_full(s, (b_free_func_t) b_trie_free); blogc_error_free(err); cleanup: b_trie_free(config); free(template); free(output); + free(print); b_slist_free_full(sources, free); return rv; } |