aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2020-04-22 02:06:37 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2020-04-22 02:06:37 +0200
commit8404096582103dccb8885b0c404f0a756685e913 (patch)
tree97d74ba2dd9591f55bd4284de6d40ba673eb8bec /src
parent67c856608a746b5205300d3f8141a6a29d3cc89e (diff)
downloadblogc-8404096582103dccb8885b0c404f0a756685e913.tar.gz
blogc-8404096582103dccb8885b0c404f0a756685e913.tar.bz2
blogc-8404096582103dccb8885b0c404f0a756685e913.zip
blogc: allow passing multiple -e options
Diffstat (limited to 'src')
-rw-r--r--src/blogc/main.c33
-rw-r--r--src/blogc/renderer.c10
-rw-r--r--src/blogc/renderer.h2
3 files changed, 29 insertions, 16 deletions
diff --git a/src/blogc/main.c b/src/blogc/main.c
index 550aec8..6a1839f 100644
--- a/src/blogc/main.c
+++ b/src/blogc/main.c
@@ -161,7 +161,6 @@ main(int argc, char **argv)
bool debug = false;
bool input_stdin = false;
bool listing = false;
- char *listing_entry = NULL;
char *template = NULL;
char *output = NULL;
char *print = NULL;
@@ -169,7 +168,8 @@ main(int argc, char **argv)
char **pieces = NULL;
bc_slist_t *sources = NULL;
- bc_trie_t *listing_entry_source = NULL;
+ bc_slist_t *listing_entries = NULL;
+ bc_slist_t *listing_entries_source = NULL;
bc_trie_t *config = bc_trie_new(free);
bc_trie_insert(config, "BLOGC_VERSION", bc_strdup(PACKAGE_VERSION));
@@ -194,9 +194,9 @@ main(int argc, char **argv)
break;
case 'e':
if (argv[i][2] != '\0')
- listing_entry = bc_strdup(argv[i] + 2);
+ listing_entries = bc_slist_append(listing_entries, bc_strdup(argv[i] + 2));
else if (i + 1 < argc)
- listing_entry = bc_strdup(argv[++i]);
+ listing_entries = bc_slist_append(listing_entries, bc_strdup(argv[++i]));
break;
case 't':
if (argv[i][2] != '\0')
@@ -316,12 +316,19 @@ main(int argc, char **argv)
goto cleanup2;
}
- if (listing && listing_entry != NULL) {
- listing_entry_source = blogc_source_parse_from_file(listing_entry, &err);
- if (err != NULL) {
- bc_error_print(err, "blogc");
- rv = 1;
- goto cleanup2;
+ if (listing) {
+ for (bc_slist_t *tmp = listing_entries; tmp != NULL; tmp = tmp->next) {
+ if (0 == strlen(tmp->data)) {
+ listing_entries_source = bc_slist_append(listing_entries_source, NULL);
+ continue;
+ }
+ bc_trie_t *e = blogc_source_parse_from_file(tmp->data, &err);
+ if (err != NULL) {
+ bc_error_print(err, "blogc");
+ rv = 1;
+ goto cleanup2;
+ }
+ listing_entries_source = bc_slist_append(listing_entries_source, e);
}
}
@@ -360,7 +367,7 @@ main(int argc, char **argv)
if (debug)
blogc_debug_template(l);
- char *out = blogc_render(l, s, listing_entry_source, config, listing);
+ char *out = blogc_render(l, s, listing_entries_source, config, listing);
bool write_to_stdout = (output == NULL || (0 == strcmp(output, "-")));
@@ -394,8 +401,8 @@ cleanup:
free(template);
free(output);
free(print);
- free(listing_entry);
- bc_trie_free(listing_entry_source);
+ bc_slist_free_full(listing_entries, free);
+ bc_slist_free_full(listing_entries_source, (bc_free_func_t) bc_trie_free);
bc_slist_free_full(sources, free);
return rv;
}
diff --git a/src/blogc/renderer.c b/src/blogc/renderer.c
index 87b3f5a..140a86e 100644
--- a/src/blogc/renderer.c
+++ b/src/blogc/renderer.c
@@ -166,7 +166,8 @@ blogc_split_list_variable(const char *name, bc_trie_t *global, bc_trie_t *local)
char*
-blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *listing_entry, bc_trie_t *config, bool listing)
+blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_slist_t *listing_entries,
+ bc_trie_t *config, bool listing)
{
if (tmpl == NULL)
return NULL;
@@ -194,6 +195,7 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *listing_entry, bc
int cmp = 0;
bc_slist_t *tmp = tmpl;
+ bc_slist_t *current_listing_entry = listing_entries;
while (tmp != NULL) {
blogc_template_node_t *node = tmp->data;
@@ -222,8 +224,12 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *listing_entry, bc
tmp_source = current_source != NULL ? current_source->data : NULL;
}
if (0 == strcmp("listing_entry", node->data[0])) {
+ bc_trie_t *listing_entry = NULL;
+ if (current_listing_entry != NULL) {
+ listing_entry = current_listing_entry->data;
+ current_listing_entry = current_listing_entry->next;
+ }
if (listing_entry == NULL || !listing) {
-
// we can just skip anything and walk until the next
// 'endblock'
while (node->type != BLOGC_TEMPLATE_NODE_ENDBLOCK) {
diff --git a/src/blogc/renderer.h b/src/blogc/renderer.h
index 8f2516a..b40da91 100644
--- a/src/blogc/renderer.h
+++ b/src/blogc/renderer.h
@@ -18,7 +18,7 @@ char* blogc_format_variable(const char *name, bc_trie_t *global, bc_trie_t *loca
bc_slist_t *foreach_var);
bc_slist_t* blogc_split_list_variable(const char *name, bc_trie_t *global,
bc_trie_t *local);
-char* blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *listing_entr,
+char* blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_slist_t *listing_entries,
bc_trie_t *config, bool listing);
#endif /* _RENDERER_H */