diff options
-rwxr-xr-x | a.out | bin | 12260 -> 12288 bytes | |||
-rw-r--r-- | assets/content/global.bvr | 32 | ||||
-rw-r--r-- | assets/layout/html/post.bvr | 30 | ||||
-rw-r--r-- | lib/strlcpy.c | 43 | ||||
-rw-r--r-- | src/tape.c | 82 | ||||
-rw-r--r-- | test/tape-test.bvr | 7 | ||||
-rw-r--r-- | tmp/output.htm | 3 |
7 files changed, 149 insertions, 48 deletions
Binary files differ diff --git a/assets/content/global.bvr b/assets/content/global.bvr index c6bbef6..0a4c194 100644 --- a/assets/content/global.bvr +++ b/assets/content/global.bvr @@ -1,25 +1,25 @@ # max 128 characters -?set site_name=Anton Luka Šijanec +<@?s site_name=Anton Luka Šijanec@> # max 2 characters -?set site_language=sl +<@?s site_language=sl@> # max 128 characters -?set site_description=Moj osebni blog. +<@?s site_description=Moj osebni blog.@> # max 32, max 64 characters per entry -?set featured_links=posts/about,posts/contact,posts/sample-post +<@?s featured_links=posts/about,posts/contact,posts/sample-post@> # max 64 characters or latest-posts -?set index_page=pages/about +<@?s index_page=pages/about@> # centered paragraph width. Can be 1, 2, 3, 4; 5 means text is left centered. -?set content_width=8 +<@?s content_width=8@> # hour offset to format dates with. NOTE: 11 is subtracted to this value. GMT is then 11, Ljubljana is then 13 -?set timezone=13 +<@?s timezone=13@> # what folders to copy from layout to dist (such as fonts) -?set copy_folders=fonts,media +<@?s copy_folders=fonts,media@> # post-specific variables --- you should set them now. unset variables may cause problems. -?set post_description=Unset description. -?set post_author=anonymous -?set post_header_image=transparent -?set post_header_color=black -?set post_heading=Unnamed post. -?set post_subheading=Unset subheading. -?set post_date=2020-04-29T15:05:10+00:00 -?set post_slug=posts/undefined +<@?s post_description Unset description.@> +<@?s post_author anonymous@> +<@?s post_header_image transparent@> +<@?s post_header_color black@> +<@?s post_heading Unnamed post.@> +<@?s post_subheading Unset subheading.@> +<@?s post_date 2020-04-29T15:05:10+00:00@> +<@?s post_slug posts/undefined@> diff --git a/assets/layout/html/post.bvr b/assets/layout/html/post.bvr index bfcf80c..39391b8 100644 --- a/assets/layout/html/post.bvr +++ b/assets/layout/html/post.bvr @@ -1,29 +1,29 @@ <!DOCTYPE html> -<html lang="<@?get site_language@>"> +<html lang="<@?g site_language@>"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> - <meta name="description" content="<!@get post_description@>"> - <meta name="author" content="<@?author name ?get post_author@>"> + <meta name="description" content="<!@g post_description@>"> + <meta name="author" content="<@?g post_author_name@>"> <title> - <@?get post_heading@> :: <@?get site_name@> - <@get site_description@> + <@?g post_heading@> :: <@?g site_name@> - <@g site_description@> </title> <link href="css/bundle.min.css" rel="stylesheet"> </head> <body> - <@?include navigation@> + <@?i navigation@> <!-- Page Header --> - <header class="masthead" style="background-image: url('<@?find_file ?get post_header_image@>'); background: <@?get post_header_color@>"> + <header class="masthead" style="background-image: url('<@?g post_header_image@>'); background: <@?g post_header_color@>"> <div class="overlay"></div> <div class="container"> <div class="row"> - <div class="col-lg-<@?get content_width@> mx-auto"> + <div class="col-lg-<@?g content_width@> mx-auto"> <div class="post-heading"> - <h1><@?get post_heading@></h1> - <h2 class="subheading"><@?get post_subheading@></h2> + <h1><@?g post_heading@></h1> + <h2 class="subheading"><@?g post_subheading@></h2> <span class="meta">Posted by - <a href="author/<@?get post_author@>"><@?author name ?get post_author@></a> - on <@?format_date ?get post_on_date?> + <a href="author/<@?g post_author@>"><@?g post_author_name@></a> + on <@?g post_date?> </span> </div> </div> @@ -34,13 +34,13 @@ <article> <div class="container"> <div class="row"> - <div class="col-lg-<@?get content_width@> mx-auto"> - <@?include_and_format_body ?post_slug@> + <div class="col-lg-<@?g content_width@> mx-auto"> + <@?i ?post_slug@> </div> </div> </div> </article> <hr> - <@?include footer@> + <@?i footer@> </body> -</html>
\ No newline at end of file +</html> diff --git a/lib/strlcpy.c b/lib/strlcpy.c new file mode 100644 index 0000000..1dc6147 --- /dev/null +++ b/lib/strlcpy.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2011 Apple, Inc. All rights reserved. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ + */ + +#include "string.h" + +#undef strlcpy +size_t +strlcpy(char * dst, const char * src, size_t maxlen) { + const size_t srclen = strlen(src); + if (srclen + 1 < maxlen) { + memcpy(dst, src, srclen + 1); + } else if (maxlen != 0) { + memcpy(dst, src, maxlen - 1); + dst[maxlen-1] = '\0'; + } + return srclen; +} + @@ -8,19 +8,25 @@ #include <fopenmkdir.c> #include <limits.h> #include <randstring.c> +#include <strlcpy.c> #define BVR_MAX_VARIABLE_SIZE 128 #define BVR_INITIAL_VARIABLES_COUNT 128 #define SUCCESS 0 #define FAILURE -1 -#define COPY_BUFFER_SIZE 2 +#define COPY_BUFFER_SIZE 128 #define OPENING_COMMAND_TAG_LENGTH 2 #define OPENING_COMMAND_TAG_CHAR_1 '<' #define OPENING_COMMAND_TAG_CHAR_2 '@' #define CLOSING_COMMAND_TAG_CHAR_1 '@' #define CLOSING_COMMAND_TAG_CHAR_2 '>' +#define LINE_COMMENT_CHAR '#' +#define LINE_COMMAND_CHAR '?' +#define WAITING_FOR_COMMAND 8922 +#define READING_COMMAND 2343 +#define PROCESSING_COMMAND 346 char bvr_variables[BVR_INITIAL_VARIABLES_COUNT][BVR_MAX_VARIABLE_SIZE]; // char* bvr_variables[128] = malloc(BVR_INITIAL_VARIABLES_COUNT * BVR_MAX_VARIABLE_SIZE); -int bvr_variables_multiplier = 1; +// int bvr_variables_multiplier = 1; // int bvr_increase_variables() { // this can be costly https://stackoverflow.com/a/3827922 // char* more_variables = realloc(bvr_variables, ++bvr_variables_multiplier * BVR_INITIAL_VARIABLES_COUNT * sizeof(BVR_MAX_VARIABLE_SIZE)); @@ -32,22 +38,52 @@ int bvr_variables_multiplier = 1; // return SUCCESS; // } - -int bvr_command_processor(FILE * page_source_file, FILE * temp_output_file, char copy_buffer[]) { +int bvr_inline_command_processor(FILE * page_source_file, FILE * temp_output_file, char copy_buffer[]) { + int what_to_return = SUCCESS; for(int i = 1; i <= OPENING_COMMAND_TAG_LENGTH; i++) { copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] = fgetc(page_source_file); // remove opening command tag characters } - while(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE] != CLOSING_COMMAND_TAG_CHAR_1 || copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] != CLOSING_COMMAND_TAG_CHAR_2) { + int command_processor_status = WAITING_FOR_COMMAND; + int argument_length = 0; + while(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE] != CLOSING_COMMAND_TAG_CHAR_1 || + copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] != CLOSING_COMMAND_TAG_CHAR_2 || + command_processor_status == PROCESSING_COMMAND) { copy_buffer[(ftell(page_source_file))% COPY_BUFFER_SIZE] = fgetc(page_source_file); // advance file pointer to the end of command without rewriting. - fputc('a', temp_output_file); + // printf("received command char %c\n", copy_buffer[(ftell(page_source_file)-2)% COPY_BUFFER_SIZE]); + if(copy_buffer[(ftell(page_source_file)-2)% COPY_BUFFER_SIZE] == '?' && command_processor_status == WAITING_FOR_COMMAND) { + command_processor_status = READING_COMMAND; + continue; + } + if(command_processor_status == READING_COMMAND) { + if(++argument_length > COPY_BUFFER_SIZE) { + fprintf(temp_output_file, "\nbVerbose %d bytes till buffer overflow. Decrease argument length (%d), increase COPY_BUFFER_SIZE (%d) or take cover.\n", + COPY_BUFFER_SIZE-argument_length, argument_length, COPY_BUFFER_SIZE); + fprintf(stderr, "[tape.c] bvr_inline_command_processor: %d bytes till buffer overflow. Decrease argument length (%d), increase COPY_BUFFER_SIZE (%d) or take cover.\n", + COPY_BUFFER_SIZE-argument_length, argument_length, COPY_BUFFER_SIZE); + what_to_return = FAILURE; + } + if(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE] == CLOSING_COMMAND_TAG_CHAR_1 && + copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] == CLOSING_COMMAND_TAG_CHAR_2) { // end of arguments! + // switch (copy_buffer[(ftell(page_source_file)-(1+argument_length))]) { // switch command + // + // } + char argument_string[argument_length+1]; + strncpy(argument_string, copy_buffer+(ftell(page_source_file)-(argument_length-1)), argument_length); + argument_string[argument_length-2] = '\0'; + printf("end of command, command was %c, argument was \"%s\"\n", copy_buffer[(ftell(page_source_file)-(1+argument_length))], argument_string); + fprintf(temp_output_file, "command was %c, argument was \"%s\"\n", copy_buffer[(ftell(page_source_file)-(1+argument_length))], argument_string); + return SUCCESS; + } + } + // fputc('a', temp_output_file); if(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE] == EOF) { fprintf(temp_output_file, "\nbVerbose syntax error: EOF reached before closing command tag --- stopped with this bvr file\n"); - fprintf(stderr, "[tape.c] bvr_command_processor: syntax error: EOF reached before @> --- stopped with this bvr file\n"); + fprintf(stderr, "[tape.c] bvr_inline_command_processor: syntax error: EOF reached before @> --- stopped with this bvr file\n"); return FAILURE; } } copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] = fgetc(page_source_file); // remove closing command tag character - return SUCCESS; + return what_to_return; } int bvr_compose_page(char page_source_file_path[], int this_is_a_top_level_page, char * temp_output_path) { @@ -70,22 +106,38 @@ int bvr_compose_page(char page_source_file_path[], int this_is_a_top_level_page, while (1) { copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] = fgetc(page_source_file); if(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE] == OPENING_COMMAND_TAG_CHAR_1 && copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] == OPENING_COMMAND_TAG_CHAR_2) { - if(bvr_command_processor(page_source_file, temp_output_file, copy_buffer)) { - fprintf(temp_output_file, "\nbvr_command_processor returned an error status whilst composing %s\n", page_source_file_path); + if(bvr_inline_command_processor(page_source_file, temp_output_file, copy_buffer) == FAILURE) { + fprintf(temp_output_file, "\nbvr_inline_command_processor returned an error status whilst composing %s\n", page_source_file_path); + fprintf(stderr, "[tape.c] bvr_inline_command_processor returned an error status whilst composing %s\n", page_source_file_path); } - } else { - if(copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] == EOF) { - break; + continue; + } + if(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE] == '\n' && copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] == LINE_COMMENT_CHAR) { + copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] = fgetc(page_source_file); // idk, OB1 is a bitch + while(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE] != '\n') { // idk, OB1 is a bitch + copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] = fgetc(page_source_file); // idk, OB1 is a bitch } - fputc(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE], temp_output_file); + continue; + } + // if(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE] == '\n' && copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] == LINE_COMMAND_CHAR) { + // if(bvr_command_processor(page_source_file, temp_output_file, copy_buffer) == FAILURE) { + // fprintf(temp_output_file, "\nbvr_command_processor returned an error status whilst composing %s\n", page_source_file_path); + // fprintf(stderr, "[tape.c] bvr_command_processor returned an error status whilst composing %s\n", page_source_file_path); + // } + // continue; + // } + if(copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] == EOF) { + fputc('\n', temp_output_file); + break; } + fputc(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE], temp_output_file); } done_reading_write_file: if(this_is_a_top_level_page) { char folder_of_file[PATH_MAX]; - strcpy(folder_of_file, page_source_file_path); + strlcpy(folder_of_file, page_source_file_path, PATH_MAX); char * p; p = strrchr(folder_of_file, '/'); if (!p) { diff --git a/test/tape-test.bvr b/test/tape-test.bvr index 8d934c5..bcbee24 100644 --- a/test/tape-test.bvr +++ b/test/tape-test.bvr @@ -1 +1,6 @@ -<h1><@this should be replaced with constant aaaaa@></h1> +<@?s post_author anton@> +# to je komentar in se ne rendera +<@?i h1@> +<@?s image_caption This is an example image.@> +<@?s image_src example.jpg@> +<@?i image@> diff --git a/tmp/output.htm b/tmp/output.htm index a52de17..b412afb 100644 --- a/tmp/output.htm +++ b/tmp/output.htm @@ -1 +1,2 @@ -<h1>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</h1>
\ No newline at end of file +<h1>command was s, argument was "should be" +></h1> |