summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsijanec <anton@sijanec.eu>2021-01-19 13:43:26 +0100
committersijanec <anton@sijanec.eu>2021-01-19 13:43:26 +0100
commit1aaf0c83b9cdd5855a3a2cbff7538ad36f55cc24 (patch)
tree92de130c3e8e1d0a36853312004d4045c8ffc09c /src
parentwhy return 1 if it did not fail=!= (diff)
downloadbverbose-1aaf0c83b9cdd5855a3a2cbff7538ad36f55cc24.tar
bverbose-1aaf0c83b9cdd5855a3a2cbff7538ad36f55cc24.tar.gz
bverbose-1aaf0c83b9cdd5855a3a2cbff7538ad36f55cc24.tar.bz2
bverbose-1aaf0c83b9cdd5855a3a2cbff7538ad36f55cc24.tar.lz
bverbose-1aaf0c83b9cdd5855a3a2cbff7538ad36f55cc24.tar.xz
bverbose-1aaf0c83b9cdd5855a3a2cbff7538ad36f55cc24.tar.zst
bverbose-1aaf0c83b9cdd5855a3a2cbff7538ad36f55cc24.zip
Diffstat (limited to '')
-rw-r--r--src/bvr.h2
-rw-r--r--src/bvrcommands.c148
-rw-r--r--src/bvrvar.c4
-rw-r--r--src/tape.c29
4 files changed, 169 insertions, 14 deletions
diff --git a/src/bvr.h b/src/bvr.h
index 27ae526..abcd0cf 100644
--- a/src/bvr.h
+++ b/src/bvr.h
@@ -26,6 +26,8 @@
#define BVR_INITIAL_VARIABLES_COUNT 128
#define BVR_MAX_VARIABLE_SIZE 128
#define BVR_UNDEFINED "BVR_UNDEFINED"
+#define BVR_ARRAY_INDEX_CHAR '['
+#define BVR_ARRAY_AFTER_INDEX "]"
char bvr_variables[BVR_INITIAL_VARIABLES_COUNT*2][BVR_MAX_VARIABLE_SIZE];
int bvr_bvrvar_first_time_set = 1;
diff --git a/src/bvrcommands.c b/src/bvrcommands.c
index 9484e49..a3c5dba 100644
--- a/src/bvrcommands.c
+++ b/src/bvrcommands.c
@@ -272,11 +272,19 @@ 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);
if(strcmp(string1, string2) == 0) {
- fprintf(output, "1");
+ outputst[0] = '1';
} else {
- fprintf(output, "0");
+ outputst[0] = '0';
}
+ return_value = bvr_var_set(uuid, outputst);
+ fprintf(output, "%s", uuid);
free(item);
free(value);
item = NULL;
@@ -338,6 +346,142 @@ int bvr_handle_if(FILE * input, FILE * output) { // ?f 1 <@this is all executed@
}
return return_value;
}
+int bvr_handle_while(FILE * input, FILE * output) {
+ 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);
+ int return_value = 0;
+ char input_char = fgetc(input);
+ char previous_char = 'a';
+ char * string1 = bvr_var_get(item);
+ FILE * codestream;
+ int depth = -1; // to increase to 0 after first <@
+ int we_re_in_a_comment = 0;
+ char * code = malloc(sizeof(char)*2);
+ size_t code_index = 0;
+ size_t read_index = 0;
+ int in_string = 0;
+ while(1) {
+ if((input_char == BVR_CLOSING_COMMAND_TAG_CHAR_2 && previous_char == BVR_CLOSING_COMMAND_TAG_CHAR_1 && depth == 0 &&
+ we_re_in_a_comment == 0 && in_string == 0)) {
+ break;
+ }
+ if(previous_char == BVR_OPENING_COMMAND_TAG_CHAR_1 && input_char == BVR_OPENING_COMMAND_TAG_CHAR_2) {
+ depth++;
+ } // this šubidubi doesn't account for <@ and @> in strings.
+ if(previous_char == BVR_CLOSING_COMMAND_TAG_CHAR_1 && input_char== BVR_CLOSING_COMMAND_TAG_CHAR_2) {
+ depth--;
+ }
+ if(previous_char == LINE_COMMAND_CHAR && input_char == BVR_BREAK_STRING_CHAR) {
+ in_string = 1;
+ }
+ if (previous_char != BVR_ESCAPE_CHAR && input_char == BVR_BREAK_STRING_CHAR && in_string == 1) {
+ in_string = 0;
+ }
+ if(previous_char == BVR_NEWLINE_CHAR && input_char == LINE_COMMENT_CHAR) {
+ we_re_in_a_comment = 1;
+ }
+ if(we_re_in_a_comment && input_char == BVR_NEWLINE_CHAR) {
+ we_re_in_a_comment = 0;
+ }
+ previous_char = input_char;
+ input_char = fgetc(input);
+ read_index++;
+ if (read_index >= 2) {
+ code[code_index++] = input_char;
+ code[code_index] = '\0';
+ }
+ code = realloc(code, sizeof(char)*(2+code_index));
+ if (code == NULL) {
+ fprintf(stderr, "segmentation fault caught (?) in bvr_handle_while, expect killing of the process soon. there was also a memory leak of around %lu bytes.\n", code_index+2);
+ return_value = FAILURE;
+ goto criticalfuckery;
+ }
+ }
+ code[strlen(code)-2] = '\0';
+ code_index -= 2;
+ codestream = fmemopen(code, code_index, "r");
+ while (atoi(string1) > 0) { /* basically the whole logic */
+ rewind(codestream);
+ // fprintf(stderr, "debug: %s\n", code);
+ return_value = return_value != SUCCESS ? return_value : bvr_compose_stream(codestream, output);
+ string1 = bvr_var_get(item);
+ }
+ fclose(codestream);
+ criticalfuckery:
+ free(item);
+ item = NULL;
+ fflush(output);
+ return return_value;
+}
+int bvr_handle_math(FILE * input, FILE * output) {
+ char operation = fgetc(input);
+ int return_value = SUCCESS;
+ 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);
+ char * value = bvr_commands_get_value(input, chars_to_break_value);
+ long long int stvar1 = strtoll(bvr_var_get(item), NULL, 10);
+ long long int stvar2 = strtoll(bvr_var_get(value), NULL, 10);
+ char numberplaceholder[69];
+ switch (operation) {
+ case '+':
+ stvar1 += stvar2;
+ break;
+ case '-':
+ stvar1 -= stvar2;
+ break;
+ case '*':
+ stvar1 *= stvar2;
+ break;
+ case '/':
+ if (stvar2 == 0) {
+ return_value = FAILURE;
+ fprintf(stderr, "division with zero is illegal, prevented, but raised an error. setting to highest value possible.\n");
+ stvar1 = LLONG_MAX;
+ } else {
+ stvar1 /= stvar2;
+ }
+ break;
+ default:
+ return_value = FAILURE;
+ break;
+ }
+ snprintf(numberplaceholder, 69-1, "%lld", stvar1);
+ return_value = bvr_var_set(item, numberplaceholder);
+ free(item);
+ free(value);
+ item = NULL;
+ value = NULL;
+ return return_value;
+}
+int bvr_handle_explode(FILE * input, FILE * output) {
+ 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);
+ char * value = bvr_commands_get_value(input, chars_to_break_value);
+ int return_value = SUCCESS;
+ char * string1 = bvr_var_get(item);
+ char * string2 = bvr_var_get(value);
+ char * token;
+ char * rest = string1;
+ char * charpointer;
+ int index = strlen(item);
+ item[index++] = '[';
+ item[index] = '\0';
+ index = 0;
+ while ((token = strtok_r(rest, string2, &rest))) {
+ charpointer = strrchr(item, BVR_ARRAY_INDEX_CHAR);
+ snprintf(charpointer+1, (BVR_MAX_VARIABLE_SIZE-(charpointer-string1))-4, "%d" BVR_ARRAY_AFTER_INDEX, index++);
+ return_value = return_value != SUCCESS ? return_value : bvr_var_set(charpointer, token); // če je bila prej napaka pač ne poskušamo več!
+ }
+ free(item);
+ free(value);
+ item = NULL;
+ value = NULL;
+ fflush(output);
+ return return_value;
+}
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);
diff --git a/src/bvrvar.c b/src/bvrvar.c
index 97b54b7..9e405ec 100644
--- a/src/bvrvar.c
+++ b/src/bvrvar.c
@@ -40,7 +40,7 @@ int bvr_var_set(char * item, char * value) {
return SUCCESS;
}
}
- fprintf(stderr, "[bvrvar.c] bvr_set: no more space on the variable stack for %s. Increase BVR_INITIAL_VARIABLES_COUNT (%d).", item, BVR_INITIAL_VARIABLES_COUNT);
+ 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;
}
@@ -51,6 +51,6 @@ int bvr_var_mv(char * item, char * newname) {
return SUCCESS;
}
}
- fprintf(stderr, "[bvrvar.c] bvr_mv: variable %s not found!", item);
+ fprintf(stderr, "[bvrvar.c] bvr_mv: variable %s not found!\n", item);
return FAILURE;
}
diff --git a/src/tape.c b/src/tape.c
index 0492313..88d1950 100644
--- a/src/tape.c
+++ b/src/tape.c
@@ -17,31 +17,40 @@ int bvr_command_processor(FILE * page_source_file, FILE * temp_output_file) {
int command_handler_output = SUCCESS;;
// argument_feed = fmemopen (argument_string, strlen (argument_string), "r");
switch (command_entered) { // switch command
- case 'g':
+ case 'g': /* et */
command_handler_output = bvr_handle_get(page_source_file, temp_output_file);
break;
- case 's':
+ case 's': /* et */
command_handler_output = bvr_handle_set(page_source_file, temp_output_file);
break;
- case 'i':
+ case 'i': /* nclude */
command_handler_output = bvr_handle_include(page_source_file, temp_output_file);
break;
- case 'm':
+ case 'm': /* ove */
command_handler_output = bvr_handle_move(page_source_file, temp_output_file);
break;
- case 'f':
+ case 'f': /* i_ */
command_handler_output = bvr_handle_if(page_source_file, temp_output_file);
break;
- case '=':
+ case '=': /* */
command_handler_output = bvr_handle_equals(page_source_file, temp_output_file);
break;
- case '"':
+ case '"': /* */
command_handler_output = bvr_handle_string(page_source_file, temp_output_file);
break;
- case 'u':
+ case 'u': /* s_bstring*/
command_handler_output = bvr_handle_substring(page_source_file, temp_output_file);
break;
- case 'b':
+ case 'w': /* hile */
+ command_handler_output = bvr_handle_while(page_source_file, temp_output_file);
+ break;
+ case 'e': /* xplode */
+ command_handler_output = bvr_handle_explode(page_source_file, temp_output_file);
+ break;
+ case 'r': /* ačunanje */
+ command_handler_output = bvr_handle_math(page_source_file, temp_output_file);
+ break;
+ case 'b': /* unden */
// fprintf(stderr, "bunden %c\n", command_entered);
command_handler_output = bvr_handle_info(page_source_file, temp_output_file);
break;
@@ -133,7 +142,7 @@ int bvr_compose_stream(FILE * page_source_file, FILE * temp_output_file) {
// continue;
// }
if(copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] == EOF) {
- fputc('\n', temp_output_file); // NO POMEGRANTES! NO! NO! NO! NO POMEGRANTES!
+ fputc(' ', temp_output_file); // NO POMEGRANTES! NO! NO! NO! NO POMEGRANTES!
break;
}
if (cycles++ != 0) { // da ne napišemo prvega znaka bufferja, preden je sploh kaj v bufferju.