diff options
author | Anton L. Šijanec <sijanecantonluka@gmail.com> | 2020-05-15 15:21:23 +0200 |
---|---|---|
committer | Anton L. Šijanec <sijanecantonluka@gmail.com> | 2020-05-15 15:21:23 +0200 |
commit | a9fae18d69cd07ddd48df5fbda20432725129cfd (patch) | |
tree | e3bc9102d6f8fb5794874df6e884926729377850 /src | |
parent | testing (diff) | |
download | bverbose-a9fae18d69cd07ddd48df5fbda20432725129cfd.tar bverbose-a9fae18d69cd07ddd48df5fbda20432725129cfd.tar.gz bverbose-a9fae18d69cd07ddd48df5fbda20432725129cfd.tar.bz2 bverbose-a9fae18d69cd07ddd48df5fbda20432725129cfd.tar.lz bverbose-a9fae18d69cd07ddd48df5fbda20432725129cfd.tar.xz bverbose-a9fae18d69cd07ddd48df5fbda20432725129cfd.tar.zst bverbose-a9fae18d69cd07ddd48df5fbda20432725129cfd.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/bvrcommands.c | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/src/bvrcommands.c b/src/bvrcommands.c index 2a73abe..b040d46 100644 --- a/src/bvrcommands.c +++ b/src/bvrcommands.c @@ -2,17 +2,27 @@ #include <bvr.h> #include <tape.c> #include <bvrvar.c> -int bvr_commands_check_for_command(char * input_char, char * value, int *i, FILE * input) { +int bvr_commands_check_for_command(char * input_char, char ** value, int *i, FILE * input) { if((*input_char) == LINE_COMMAND_CHAR) { FILE * command_return; - command_return = fmemopen(value+((*i)++), sizeof(value)-(*i), "w"); // i bajtov smo že napisali. + size_t buf_size; + command_return = open_memstream(&(*value)+((*i)++), &buf_size); // i bajtov smo že napisali. if(bvr_command_processor(input, command_return) != SUCCESS) { fprintf(stderr, "[bvrcommands.c] bvr_commands_check_for_command: command, passed as argument, didn't return success. Going on.\n"); } - (*i) = (*i)+ftell(command_return); + fflush(command_return); + // fprintf(stderr, "debug: \"%s\"\n", (*value)+((*i)-1)); + // fprintf(stderr, "debug: \"%s\"\n", (*value)); + // fprintf(stderr, "debug: \"%d\"\n", (*i)); + // fprintf(stderr, "debug: \"%ld\"\n", (buf_size)); + (*i) = (*i)+buf_size; + // fprintf(stderr, "debug: \"%d\"\n", (*i)); (*input_char) = CLOSING_COMMAND_TAG_CHAR_1; // da zaključimo loop (drugače ostane notri ?) + //\\ zelo slabo. znak, ki ga najde izveden ukaz, se izgubi. rešitev bi bila dobiti zadnji input char, ki triggera break + // prejšnjega ukaza, kar pa je nemogoče. fflush(command_return); fclose(command_return); + // fprintf(stderr, "debug: \"%s\"\n", (*value)); return BVR_CONTINUE; } return BVR_KEEPGOING; @@ -27,12 +37,12 @@ char bvr_var_skip_separator_chars(FILE * input) { return input_char; } int bvr_handle_get(FILE * input, FILE * output) { - char item[BVR_MAX_VARIABLE_SIZE+1]; + char * item = (char*) malloc(BVR_MAX_VARIABLE_SIZE+1); char input_char = bvr_var_skip_separator_chars(input); 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) { - if(bvr_commands_check_for_command(&input_char, item, &i, input) == BVR_CONTINUE) { + if(bvr_commands_check_for_command(&input_char, &item, &i, input) == BVR_CONTINUE) { continue; } item[i++] = input_char; @@ -44,13 +54,13 @@ int bvr_handle_get(FILE * input, FILE * output) { return SUCCESS; } int bvr_handle_set(FILE * input, FILE * output) { - char item[BVR_MAX_VARIABLE_SIZE+1]; - char value[BVR_MAX_VARIABLE_SIZE+1]; + char * item = (char *) malloc(BVR_MAX_VARIABLE_SIZE+1); + char * value = (char *) malloc(BVR_MAX_VARIABLE_SIZE+1); char input_char = bvr_var_skip_separator_chars(input); 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) { - if(bvr_commands_check_for_command(&input_char, item, &i, input) == BVR_CONTINUE) { + if(bvr_commands_check_for_command(&input_char, &item, &i, input) == BVR_CONTINUE) { continue; } item[i++] = input_char; @@ -60,25 +70,28 @@ int bvr_handle_set(FILE * input, FILE * output) { i = 0; input_char = bvr_var_skip_separator_chars(input); while(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) { - if(bvr_commands_check_for_command(&input_char, value, &i, input) == BVR_CONTINUE) { + input_char != '\0' && i < BVR_MAX_VARIABLE_SIZE) { + if(bvr_commands_check_for_command(&input_char, &value, &i, input) == BVR_CONTINUE) { + // fprintf(stderr, "debug3: \"%s\"\n", value); continue; } value[i++] = input_char; input_char = fgetc(input); } value[i++] = '\0'; + // fprintf(stderr, "debug2: \"%s\"\n", value); + // fprintf(stderr, "debug2: \"%d\"\n", i); return bvr_var_set(item, value); fflush(output); return SUCCESS; } int bvr_handle_include(FILE * input, FILE * output) { - char item[BVR_MAX_VARIABLE_SIZE+1]; + char * item = (char *) malloc(BVR_MAX_VARIABLE_SIZE+1); char input_char = bvr_var_skip_separator_chars(input); 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) { - if(bvr_commands_check_for_command(&input_char, item, &i, input) == BVR_CONTINUE) { + if(bvr_commands_check_for_command(&input_char, &item, &i, input) == BVR_CONTINUE) { continue; } item[i++] = input_char; @@ -135,12 +148,15 @@ int bvr_handle_include(FILE * input, FILE * output) { fflush(output); } int bvr_handle_move(FILE * input, FILE * output) { - char item[BVR_MAX_VARIABLE_SIZE+1]; - char value[BVR_MAX_VARIABLE_SIZE+1]; + char * item = (char *) malloc(BVR_MAX_VARIABLE_SIZE+1); + char * value = (char *) malloc(BVR_MAX_VARIABLE_SIZE+1); char input_char = bvr_var_skip_separator_chars(input); 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) { + if(bvr_commands_check_for_command(&input_char, &item, &i, input) == BVR_CONTINUE) { + continue; + } item[i++] = input_char; input_char = fgetc(input); } @@ -149,7 +165,7 @@ int bvr_handle_move(FILE * input, FILE * output) { input_char = bvr_var_skip_separator_chars(input); 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) { - if(bvr_commands_check_for_command(&input_char, value, &i, input) == BVR_CONTINUE) { + if(bvr_commands_check_for_command(&input_char, &value, &i, input) == BVR_CONTINUE) { continue; } value[i++] = input_char; |