diff options
-rw-r--r-- | man/blogc.1.ronn | 19 | ||||
-rw-r--r-- | src/blogc/main.c | 29 |
2 files changed, 43 insertions, 5 deletions
diff --git a/man/blogc.1.ronn b/man/blogc.1.ronn index a97122b..fc865b8 100644 --- a/man/blogc.1.ronn +++ b/man/blogc.1.ronn @@ -3,9 +3,15 @@ blogc(1) -- a blog compiler ## SYNOPSIS -`blogc` `-d` [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] <SOURCE><br> -`blogc` `-d` `-l` [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] [<SOURCE> ...]<br> -`blogc` `-d` `-l` `-p` <KEY> [`-D` <KEY>=<VALUE> ...] [<SOURCE> ...]<br> +`blogc` [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] <SOURCE><br> +`blogc` `-l` [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] [<SOURCE> ...]<br> +`blogc` `-l` `-p` <KEY> [`-d`] [`-D` <KEY>=<VALUE> ...] [<SOURCE> ...]<br> +`blogc` `-i` [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] < <FILE_LIST><br> +`blogc` `-i` `-l` [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] < <FILE_LIST><br> +`blogc` `-i` `-l` `-p` <KEY> [`-d`] [`-D` <KEY>=<VALUE> ...] < <FILE_LIST><br> +`echo` `-e` "<SOURCE>\n..." | `blogc` `-i` [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>]<br> +`echo` `-e` "<SOURCE>\n..." | `blogc` `-i` `-l` [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>]<br> +`echo` `-e` "<SOURCE>\n..." | `blogc` `-i` `-l` `-p` <KEY> [`-d`] [`-D` <KEY>=<VALUE> ...]<br> `blogc` [`-h`|`-v`] ## DESCRIPTION @@ -33,6 +39,13 @@ designed to be used with make(1). * `-d`: Activates debug. + * `-i`: + Reads list of source files from standard input. Content of standard input is + parsed as a file where each line is a file path. Empty lines and lines + starting with `#` are ignored. If some source files are provided to command + line while using this option, they will be parsed **before** the files read + from standard input. + * `-l`: Activates listing mode, allowing user to provide multiple source files. See blogc-source(7) for details. diff --git a/src/blogc/main.c b/src/blogc/main.c index 35d9f69..35bcd88 100644 --- a/src/blogc/main.c +++ b/src/blogc/main.c @@ -27,6 +27,7 @@ #include "loader.h" #include "renderer.h" #include "../common/error.h" +#include "../common/file.h" #include "../common/utf8.h" #include "../common/utils.h" @@ -40,7 +41,7 @@ blogc_print_help(void) { printf( "usage:\n" - " blogc [-h] [-v] [-d] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE]\n" + " blogc [-h] [-v] [-d] [-i] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE]\n" " [-o OUTPUT] [SOURCE ...] - A blog compiler.\n" "\n" "positional arguments:\n" @@ -50,6 +51,7 @@ blogc_print_help(void) " -h show this help message and exit\n" " -v show version and exit\n" " -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" @@ -63,7 +65,7 @@ static void blogc_print_usage(void) { printf( - "usage: blogc [-h] [-v] [-d] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE]\n" + "usage: blogc [-h] [-v] [-d] [-i] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE]\n" " [-o OUTPUT] [SOURCE ...]\n"); } @@ -103,6 +105,22 @@ blogc_mkdir_recursive(const char *filename) } +static bc_slist_t* +blogc_read_stdin_to_list(bc_slist_t *l) +{ + char buffer[4096]; + while (NULL != fgets(buffer, 4096, stdin)) { + char *tmp = bc_str_strip(buffer); + if (tmp[0] == '\0') + continue; + if (tmp[0] == '#') + continue; + l = bc_slist_append(l, bc_strdup(tmp)); + } + return l; +} + + int main(int argc, char **argv) { @@ -111,6 +129,7 @@ main(int argc, char **argv) int rv = 0; bool debug = false; + bool input_stdin = false; bool listing = false; char *template = NULL; char *output = NULL; @@ -135,6 +154,9 @@ main(int argc, char **argv) case 'd': debug = true; break; + case 'i': + input_stdin = true; + break; case 'l': listing = true; break; @@ -204,6 +226,9 @@ main(int argc, char **argv) sources = bc_slist_append(sources, bc_strdup(argv[i])); } + if (input_stdin) + sources = blogc_read_stdin_to_list(sources); + if (!listing && bc_slist_length(sources) == 0) { blogc_print_usage(); fprintf(stderr, "blogc: error: one source file is required\n"); |