From fa016a15156bf8122b2d3dccaecca53f471d6ecb Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 21 Apr 2015 15:42:16 -0300 Subject: refactored blocks - changed block names: - single_source -> entry - multiple_sources -> listing - multiple_sources_once -> listing_once - added -t cli option, to build listing pages, instead of guess it from the number of source files provided. --- src/main.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 552c322..f30a92e 100644 --- a/src/main.c +++ b/src/main.c @@ -36,13 +36,14 @@ blogc_print_help(void) { printf( "usage:\n" - " blogc [-h] -t TEMPLATE [-o OUTPUT] SOURCE [SOURCE ...] - A blog compiler.\n" + " blogc [-h] [-l] -t TEMPLATE [-o OUTPUT] SOURCE [SOURCE ...] - A blog compiler.\n" "\n" "positional arguments:\n" " SOURCE source file(s)\n" "\n" "optional arguments:\n" - " -h, --help show this help message and exit\n" + " -h show this help message and exit\n" + " -l build listing page, from multiple source files\n" " -t TEMPLATE template file\n" " -o OUTPUT output file\n"); } @@ -51,7 +52,7 @@ blogc_print_help(void) static void blogc_print_usage(void) { - printf("usage: blogc [-h] -t TEMPLATE [-o OUTPUT] SOURCE [SOURCE ...]\n"); + printf("usage: blogc [-h] [-l] -t TEMPLATE [-o OUTPUT] SOURCE [SOURCE ...]\n"); } @@ -95,6 +96,7 @@ main(int argc, char **argv) { int rv = 0; + bool listing = false; char *template = NULL; char *output = NULL; b_slist_t *sources = NULL; @@ -105,6 +107,9 @@ main(int argc, char **argv) case 'h': blogc_print_help(); goto cleanup; + case 'l': + listing = true; + break; case 't': if (i + 1 < argc) template = b_strdup(argv[++i]); @@ -128,7 +133,18 @@ main(int argc, char **argv) if (b_slist_length(sources) == 0) { blogc_print_usage(); - fprintf(stderr, "blogc: error: at least one source file is required\n"); + if (listing) + fprintf(stderr, "blogc: error: at least one source file is required\n"); + else + fprintf(stderr, "blogc: error: one source file is required\n"); + rv = 2; + goto cleanup; + } + + if (!listing && b_slist_length(sources) > 1) { + blogc_print_usage(); + fprintf(stderr, "blogc: error: only one source file should be provided, " + "if running without '-l'\n"); rv = 2; goto cleanup; } @@ -147,7 +163,7 @@ main(int argc, char **argv) goto cleanup3; } - char *out = blogc_render(l, s); + char *out = blogc_render(l, s, listing); bool write_to_stdout = (output == NULL || (0 == strcmp(output, "-"))); -- cgit v1.2.3-18-g5258