diff options
author | sijanec <anton@sijanec.eu> | 2021-01-21 08:19:19 +0100 |
---|---|---|
committer | sijanec <anton@sijanec.eu> | 2021-01-21 08:19:19 +0100 |
commit | 8f877a7a8a2bb81caeed24256baea4b54032b750 (patch) | |
tree | b8c08e77ff3d5cd14d9438a5b408c8e9c943aca8 | |
parent | tweaks (diff) | |
download | bverbose-8f877a7a8a2bb81caeed24256baea4b54032b750.tar bverbose-8f877a7a8a2bb81caeed24256baea4b54032b750.tar.gz bverbose-8f877a7a8a2bb81caeed24256baea4b54032b750.tar.bz2 bverbose-8f877a7a8a2bb81caeed24256baea4b54032b750.tar.lz bverbose-8f877a7a8a2bb81caeed24256baea4b54032b750.tar.xz bverbose-8f877a7a8a2bb81caeed24256baea4b54032b750.tar.zst bverbose-8f877a7a8a2bb81caeed24256baea4b54032b750.zip |
-rw-r--r-- | Makefile | 12 | ||||
-rwxr-xr-x | bin/bvr-compose-html | bin | 36712 -> 36656 bytes | |||
-rwxr-xr-x | bin/bvr-compose-single | bin | 36568 -> 36480 bytes | |||
-rwxr-xr-x | bin/bvr-jsbundle | bin | 17576 -> 17576 bytes | |||
-rwxr-xr-x | bin/bvr-jsmin | bin | 17904 -> 17904 bytes | |||
-rw-r--r-- | src/bvr.h | 2 | ||||
-rw-r--r-- | src/bvrcommands.c | 38 | ||||
-rw-r--r-- | src/bvrvar.c | 43 | ||||
-rw-r--r-- | src/tape.c | 3 | ||||
-rw-r--r-- | test/tape-test.bvr | 12 |
10 files changed, 72 insertions, 38 deletions
@@ -3,17 +3,13 @@ default: @echo "welcome to bverbose Makefile." @echo "*** ONLY DEBIAN IS SUPPORTED (woah) ***" @echo "targets are" - @echo " make prepare installs dependencies - requires root" @echo " make install compiles some useful binaries." @echo "no target specified, exiting." -prepare: - sudo apt install libuuid1 uuid-dev -y - install: mkdir -p bin - gcc -I lib -I src test/tape-test.c -o bin/bvr-compose-single -luuid - gcc test/compose-all-in-dir.c -I lib -I src -o bin/bvr-compose-html -luuid - gcc test/jsbundle-test.c -I lib -I src -luuid -o bin/bvr-jsbundle - gcc test/jsmin-test.c -I lib -I src -luuid -o bin/bvr-jsmin + gcc -I lib -I src test/tape-test.c -o bin/bvr-compose-single + gcc test/compose-all-in-dir.c -I lib -I src -o bin/bvr-compose-html + gcc test/jsbundle-test.c -I lib -I src -o bin/bvr-jsbundle + gcc test/jsmin-test.c -I lib -I src -o bin/bvr-jsmin @echo "install target done, now you should add the bin directory to your PATH" diff --git a/bin/bvr-compose-html b/bin/bvr-compose-html Binary files differindex e311aeb..005f4cc 100755 --- a/bin/bvr-compose-html +++ b/bin/bvr-compose-html diff --git a/bin/bvr-compose-single b/bin/bvr-compose-single Binary files differindex 1ef4359..406b4b7 100755 --- a/bin/bvr-compose-single +++ b/bin/bvr-compose-single diff --git a/bin/bvr-jsbundle b/bin/bvr-jsbundle Binary files differindex a617bbf..c1bce8c 100755 --- a/bin/bvr-jsbundle +++ b/bin/bvr-jsbundle diff --git a/bin/bvr-jsmin b/bin/bvr-jsmin Binary files differindex 88924b6..fe78f98 100755 --- a/bin/bvr-jsmin +++ b/bin/bvr-jsmin @@ -23,7 +23,7 @@ #define PROCESSING_COMMAND 346 // not needed #define THE_VOID "/dev/null" -#define BVR_INITIAL_VARIABLES_COUNT 1024 +#define BVR_INITIAL_VARIABLES_COUNT 128 #define BVR_UNDEFINED "BVR_UNDEFINED" #define BVR_ARRAY_INDEX_CHAR '[' #define BVR_ARRAY_AFTER_INDEX "]" diff --git a/src/bvrcommands.c b/src/bvrcommands.c index f160731..cbff95f 100644 --- a/src/bvrcommands.c +++ b/src/bvrcommands.c @@ -7,7 +7,6 @@ #include <tape.c> #include <bvrvar.c> #include <inarray.c> -#include <uuid/uuid.h> int bvr_commands_check_for_command(char * input_char, char ** value, int *i, FILE * input, int * value_size) { if((*input_char) == LINE_COMMAND_CHAR) { @@ -279,14 +278,15 @@ int bvr_handle_move(FILE * input, FILE * output) { } int bvr_handle_string(FILE * input, FILE * output) { char * item = bvr_commands_get_string(input); - uuid_t binuuid; - uuid_generate_random(binuuid); - char uuid[37]; - uuid_unparse(binuuid, uuid); + char * uuid = randstring(37); + strcpy(uuid, "BVR_STRING"); + uuid[10] = '_'; int return_value = bvr_var_set(uuid, item); free(item); item = NULL; fprintf(output, "%s", uuid); + free(uuid); + uuid = NULL; fflush(output); return return_value; } @@ -298,19 +298,13 @@ int bvr_handle_equals(FILE * input, FILE * output) { int return_value = 0; char * string1 = bvr_var_get(item); char * string2 = bvr_var_get(value); - uuid_t binuuid; - uuid_generate_random(binuuid); - char uuid[37]; - char outputst[2]; - outputst[1] = '\0'; - uuid_unparse(binuuid, uuid); + char out; if(strcmp(string1, string2) == 0) { - outputst[0] = '1'; + out = '1'; } else { - outputst[0] = '0'; + out = '0'; } - return_value = bvr_var_set(uuid, outputst); - fprintf(output, "%s", uuid); + fprintf(output, "?\"%c\"", out); free(item); free(value); item = NULL; @@ -538,6 +532,18 @@ int bvr_handle_explode(FILE * input, FILE * output) { } int bvr_handle_info(FILE * input, FILE * output) { // fprintf(stderr, "[bvrcommands.c] bvr_handle_info: bvr bVerbose HTPCMS %d.%d.%d\n", BVR_VER_MAJOR, BVR_VER_MINOR, BVR_VER_PATCH); - fprintf(output, "\nbvr bVerbose HTPCMS %d.%d.%d\n", BVR_VER_MAJOR, BVR_VER_MINOR, BVR_VER_PATCH); + char chars_to_break_value[69] = " "; + strlcat(chars_to_break_value, BVR_CHARS_TO_BREAK_VALUE, sizeof(chars_to_break_value)); + char * item = bvr_commands_get_value(input, chars_to_break_value); + switch(item[0]) { + case 'c': + fprintf(output, "%lu", bvr_variables_count); + break; + default: + fprintf(output, "\nbvr bVerbose HTPCMS %d.%d.%d\n", BVR_VER_MAJOR, BVR_VER_MINOR, BVR_VER_PATCH); + break; + } + free(item); + item = NULL; return SUCCESS; } diff --git a/src/bvrvar.c b/src/bvrvar.c index 584611f..9ba2021 100644 --- a/src/bvrvar.c +++ b/src/bvrvar.c @@ -2,19 +2,34 @@ #include <bvr.h> #include <string.h> #include <stdlib.h> +#define BVR_VAR_MALLOC_VAR(i) \ + bvr_variables[i].v = malloc(sizeof(char)*128); \ + strcpy(bvr_variables[i].v, BVR_UNDEFINED); \ + bvr_variables[i].sv = 128; \ + bvr_variables[i].k = malloc(sizeof(char)*128); \ + strcpy(bvr_variables[i].k, BVR_UNDEFINED); \ + bvr_variables[i].sk = 128; #define BVR_VAR_FIRST_TIME() \ if(bvr_bvrvar_first_time_set == 1) { \ bvr_variables = malloc(sizeof(struct bvr_variable)*bvr_variables_count); \ for(int i = 0; i < bvr_variables_count; i++) { \ - bvr_variables[i].v = malloc(sizeof(char)*128); \ - strcpy(bvr_variables[i].v, BVR_UNDEFINED); \ - bvr_variables[i].sv = 128; \ - bvr_variables[i].k = malloc(sizeof(char)*128); \ - strcpy(bvr_variables[i].k, BVR_UNDEFINED); \ - bvr_variables[i].sk = 128; \ + BVR_VAR_MALLOC_VAR(i) \ } \ bvr_bvrvar_first_time_set = 0; \ } +char * bvr_var_remove_orphans() { + BVR_VAR_FIRST_TIME(); + for (int i = 0; i < bvr_variables_count; i++) { + if (strncmp("BVR_STRING_", bvr_variables[i].k, strlen("BVR_STRING_")) == 0) { + for (int j = 0; j < bvr_variables_count; j++) { + if (strcmp(bvr_variables[i].k, bvr_variables[j].v) == 0 && strcmp(bvr_variables[j].k, BVR_UNDEFINED) != 0) + break; + } + strcpy(bvr_variables[i].k, BVR_UNDEFINED); + } + } + return SUCCESS; +} char * bvr_var_get(char * item) { BVR_VAR_FIRST_TIME(); for(int i = 0; i < bvr_variables_count; i++) { @@ -32,23 +47,27 @@ int bvr_var_set(char * item, char * value) { int freevar = -69420; for(int i = 0; i < bvr_variables_count; i++) { // printf("loop here4\n"); - if (freevar != -69420 && strcmp(bvr_variables[i].v, BVR_UNDEFINED) == 0) { + if (freevar == -69420 && strcmp(bvr_variables[i].k, BVR_UNDEFINED) == 0) { freevar = i; } if(strcmp(bvr_variables[i].k, item) == 0 || i+1 == bvr_variables_count) { if (i+1 == bvr_variables_count && strcmp(bvr_variables[i].k, item) != 0) { i = freevar; - if (i == -69420) { - fprintf(stderr, "[bvrvar.c] bvr_set: no more space on the variable stack for %s. Increase BVR_INITIAL_VARIABLES_COUNT (%d).\n", item, BVR_INITIAL_VARIABLES_COUNT); - return FAILURE; + if (freevar == -69420) { + freevar = i = bvr_variables_count; + bvr_variables_count += BVR_INITIAL_VARIABLES_COUNT; + bvr_variables = realloc(bvr_variables, sizeof(struct bvr_variable)*bvr_variables_count); + for (int j = freevar; j < bvr_variables_count; j++) { + BVR_VAR_MALLOC_VAR(j); + } } } - if (bvr_variables[i].sk > strlen(item)) { + if (bvr_variables[i].sk < strlen(item)+64) { bvr_variables[i].sk = strlen(item)+128; free(bvr_variables[i].k); bvr_variables[i].k = malloc(sizeof(char)*bvr_variables[i].sk); } - if (bvr_variables[i].sv > strlen(item)) { + if (bvr_variables[i].sv < strlen(value)+64) { bvr_variables[i].sv = strlen(value)+128; free(bvr_variables[i].v); bvr_variables[i].v = malloc(sizeof(char)*bvr_variables[i].sv); @@ -101,6 +101,9 @@ int bvr_inline_command_processor(FILE * page_source_file, FILE * output_file, ch return FAILURE; } } + /* start collect garbage on success */ + bvr_var_remove_orphans(); + /* end collect garbage on success */ // copy_buffer[(ftell(page_source_file)% COPY_BUFFER_SIZE)] = fgetc(page_source_file); // remove closing command tag character return what_to_return; } diff --git a/test/tape-test.bvr b/test/tape-test.bvr index 52b8664..6c04328 100644 --- a/test/tape-test.bvr +++ b/test/tape-test.bvr @@ -1,5 +1,5 @@ yeet -<@?i assets/content/global.bvr @> +# <@?i assets/content/global.bvr @> <@?s testing krneki@> # <@?u -2 -1 ?g testing @> <@?s branch_name .git/refs/heads/master@> @@ -18,3 +18,13 @@ yeet <@?m ?"a very long string should surpass 128 characters. this should trigger the automatic or, in other words, dynamic memory allocation that should extend the variable space to support such a long string. yup, that's enough of text." longstring@> <@?g longstring@> <@?g longstring@> + +<@?s stevilka 256@> +začetek testa pobiranja smeti. nastaviti bi se moralo 256 nizov, ki pa bi se morali takoj izbrisati. +<@?b c@> +<@?w stevilka <@ + <@?r- stevilka ?"1"@> + <@?s xxx ?"this is a test variable."@> +@>@> +<@?b c@> +konec! |