From 0e10e00f82fd7f727ee1bc227f20f35472f74b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20L=2E=20=C5=A0ijanec?= Date: Tue, 5 May 2020 19:32:35 +0200 Subject: =?UTF-8?q?including=20works-finnaly=20something=20to=20increase?= =?UTF-8?q?=20version=20number!=20=C4=87#=20Please=20enter=20the=20commit?= =?UTF-8?q?=20message=20for=20your=20changes.=20Lines=20starting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- a.out | Bin 17036 -> 21132 bytes assets/content/global.bvr | 4 +++- src/bvr.h | 5 +++++ src/bvrcommands.c | 32 ++++++++++++++++++++++++++++---- src/tape.c | 2 +- test/tape-test-to-include.bvr | 9 +++++++++ test/tape-test.bvr | 2 ++ tmp/output.htm | 12 ++++++++++++ 8 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 test/tape-test-to-include.bvr diff --git a/a.out b/a.out index e9a6c8e..813e70e 100755 Binary files a/a.out and b/a.out differ diff --git a/assets/content/global.bvr b/assets/content/global.bvr index 0a4c194..5fc4dbf 100644 --- a/assets/content/global.bvr +++ b/assets/content/global.bvr @@ -14,7 +14,9 @@ <@?s timezone=13@> # what folders to copy from layout to dist (such as fonts) <@?s copy_folders=fonts,media@> -# post-specific variables --- you should set them now. unset variables may cause problems. +# path, where bvr files will be searched for +<@?s bvr_include_path assets/content/;assets/content/posts/;assets/layout/;assets/content/html/@> +# post-specific variables --- you should set them now. unset variables may cause problems --- they return BVR_UNDEFINED <@?s post_description Unset description.@> <@?s post_author anonymous@> <@?s post_header_image transparent@> diff --git a/src/bvr.h b/src/bvr.h index c6431ae..0af9f54 100644 --- a/src/bvr.h +++ b/src/bvr.h @@ -25,3 +25,8 @@ int bvr_bvrvar_first_time_set = 1; #define BVR_VER_MAJOR 0 #define BVR_VER_MINOR 0 #define BVR_VER_PATCH 0 + +#define BVR_PATH_SEPARATOR ';' +#define BVR_INCLUDE_PATH_VAR_NAME "bvr_include_path" + +int bvr_compose_stream(FILE *, FILE *); diff --git a/src/bvrcommands.c b/src/bvrcommands.c index bc5eed3..747c757 100644 --- a/src/bvrcommands.c +++ b/src/bvrcommands.c @@ -1,5 +1,6 @@ #pragma once #include +#include #include char bvr_var_skip_separator_chars(FILE * input) { char input_char = fgetc(input); @@ -52,13 +53,36 @@ int bvr_handle_include(FILE * input, FILE * output) { int i = 0; while(input_char != ' ' && input_char != CLOSING_COMMAND_TAG_CHAR_1 && input_char != ',' && input_char != ';' && input_char != EOF && input_char != '\0' && input_char != '\n' && i < BVR_MAX_VARIABLE_SIZE) { - item[++i] = input_char; + item[i++] = input_char; input_char = fgetc(input); } - item[++i] = '\0'; - fprintf(output, "%s", bvr_var_get(item)); + item[i++] = '\0'; + FILE * stream = fopen(item, "r"); + char notgoodatnamingvariables[PATH_MAX]; + char * path = bvr_var_get(BVR_INCLUDE_PATH_VAR_NAME); + if(strcmp(path, BVR_UNDEFINED) == 0 && stream == NULL) { + fprintf(output, "\nbVerbose include error. File %s not found. Path is undefined.\n", item); + fprintf(stderr, "[bvrcommands.c] bvr_handle_include: File %s not found. Path is undefined.\n", item); + return FAILURE; + } + char * singlepath; + while(stream == NULL) { + singlepath = strrchr(path, BVR_PATH_SEPARATOR); + strcpy(notgoodatnamingvariables, singlepath); + strcat(notgoodatnamingvariables, item); + stream = fopen(notgoodatnamingvariables, "r"); + if(strrchr(path, BVR_PATH_SEPARATOR) == NULL) { + stream = fopen(notgoodatnamingvariables, "r"); + if(stream == NULL) { + fprintf(output, "\nbVerbose include error. File %s not found.\n", item); + fprintf(stderr, "[bvrcommands.c] bvr_handle_include: File %s not found.\n", item); + return FAILURE; + } + } + *singlepath = '\0'; + } + return bvr_compose_stream(stream, output); fflush(output); - return SUCCESS; } int bvr_handle_move(FILE * input, FILE * output) { char item[BVR_MAX_VARIABLE_SIZE+1]; diff --git a/src/tape.c b/src/tape.c index 5c574fb..1b1598d 100644 --- a/src/tape.c +++ b/src/tape.c @@ -10,7 +10,6 @@ #include #include #include - int bvr_inline_command_processor(FILE * page_source_file, FILE * output_file, char copy_buffer[]) { FILE * temp_output_file = output_file; int what_to_return = SUCCESS; @@ -92,6 +91,7 @@ int bvr_inline_command_processor(FILE * page_source_file, FILE * output_file, ch copy_buffer[(ftell(page_source_file)% COPY_BUFFER_SIZE)] = fgetc(page_source_file); // remove closing command tag character return what_to_return; } + int bvr_compose_stream(FILE * page_source_file, FILE * temp_output_file) { char copy_buffer[COPY_BUFFER_SIZE]; for(int i = 0; i < sizeof(copy_buffer); i++) { // da garbage vrednosti ne bodo slučajno ukazi! diff --git a/test/tape-test-to-include.bvr b/test/tape-test-to-include.bvr new file mode 100644 index 0000000..89d08fe --- /dev/null +++ b/test/tape-test-to-include.bvr @@ -0,0 +1,9 @@ +including worked! +included file: +| <@?s included_variable included variable set and read @> +| <@?g included_variable @> from included file +| +| +| +| +| diff --git a/test/tape-test.bvr b/test/tape-test.bvr index fbed8d3..3581604 100644 --- a/test/tape-test.bvr +++ b/test/tape-test.bvr @@ -1,3 +1,5 @@ +<@?i test/tape-test-to-include.bvr @> +<@?g included_variable @> <@?s abc 1232@> <@?g abc@> <@?m abc bbc@> diff --git a/tmp/output.htm b/tmp/output.htm index a2d7bed..b447744 100644 --- a/tmp/output.htm +++ b/tmp/output.htm @@ -1,5 +1,17 @@ +including worked! +included file: +| +| included variable set and read from included file +| +| +| +| +| + +included variable set and read + 1232 BVR_UNDEFINED -- cgit v1.2.3