diff options
Diffstat (limited to '')
-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 |
4 files changed, 57 insertions, 29 deletions
@@ -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; } |