aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-21 15:42:16 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-21 15:42:16 -0300
commitfa016a15156bf8122b2d3dccaecca53f471d6ecb (patch)
tree12e8ec4c971455b7a1578fdb9c4eaf0e37f018c3 /src/main.c
parent8d8f508b859647461d1e9f13eeab647ceae54597 (diff)
downloadblogc-fa016a15156bf8122b2d3dccaecca53f471d6ecb.tar.gz
blogc-fa016a15156bf8122b2d3dccaecca53f471d6ecb.tar.bz2
blogc-fa016a15156bf8122b2d3dccaecca53f471d6ecb.zip
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.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c26
1 files changed, 21 insertions, 5 deletions
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, "-")));