summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xa.outbin22552 -> 27096 bytes
-rw-r--r--files_and_folders56
-rw-r--r--lib/inarray.c9
-rw-r--r--lib/joinarrays.c18
-rw-r--r--lib/randstring.c5
-rw-r--r--lib/strlcat.c39
-rw-r--r--src/bvr.h6
-rw-r--r--src/bvrcommands.c195
-rw-r--r--src/tape.c17
-rw-r--r--test/inarray-test.c16
-rw-r--r--test/joinarray.c13
-rw-r--r--test/tape-test.bvr5
-rw-r--r--tmp/output.htm7
13 files changed, 283 insertions, 103 deletions
diff --git a/a.out b/a.out
index 80970bc..44004e8 100755
--- a/a.out
+++ b/a.out
Binary files differ
diff --git a/files_and_folders b/files_and_folders
new file mode 100644
index 0000000..eafa9e6
--- /dev/null
+++ b/files_and_folders
@@ -0,0 +1,56 @@
+/sys/devices/pci0000:00/0000:00:19.0/net/enp0s25/queues/tx-0/byte_queue_limits/hold_time
+/sys/devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1.4/2-1.4:1.0/net/wlx0013eff60304/queues/tx-2/byte_queue_limits/hold_time
+/sys/devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1.4/2-1.4:1.0/net/wlx0013eff60304/queues/tx-0/byte_queue_limits/hold_time
+/sys/devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1.4/2-1.4:1.0/net/wlx0013eff60304/queues/tx-3/byte_queue_limits/hold_time
+/sys/devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1.4/2-1.4:1.0/net/wlx0013eff60304/queues/tx-1/byte_queue_limits/hold_time
+/sys/devices/virtual/net/lo/queues/tx-0/byte_queue_limits/hold_time
+/opt/Publii/resources/app.asar.unpacked/node_modules/sharp/vendor/include/orc-0.4/orc/orclimits.h
+/home/a/snap/arduino/17/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/include/sys/syslimits.h
+/home/a/snap/arduino/17/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/include/limits.h
+/home/a/snap/arduino/17/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/lib/gcc/xtensa-lx106-elf/4.8.2/include-fixed/syslimits.h
+/home/a/snap/arduino/17/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/lib/gcc/xtensa-lx106-elf/4.8.2/include-fixed/limits.h
+/home/a/snap/arduino/17/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/lib/gcc/xtensa-lx106-elf/4.8.2/install-tools/gsyslimits.h
+/home/a/snap/arduino/17/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/lib/gcc/xtensa-lx106-elf/4.8.2/install-tools/include/limits.h
+/home/a/snap/arduino/17/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/xtensa-lx106-elf/include/sys/syslimits.h
+/home/a/snap/arduino/17/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/xtensa-lx106-elf/include/c++/4.8.2/tr1/limits.h
+/home/a/snap/arduino/17/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/xtensa-lx106-elf/include/limits.h
+/home/a/snap/arduino/23/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/include/sys/syslimits.h
+/home/a/snap/arduino/23/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/include/limits.h
+/home/a/snap/arduino/23/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/lib/gcc/xtensa-lx106-elf/4.8.2/include-fixed/syslimits.h
+/home/a/snap/arduino/23/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/lib/gcc/xtensa-lx106-elf/4.8.2/include-fixed/limits.h
+/home/a/snap/arduino/23/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/lib/gcc/xtensa-lx106-elf/4.8.2/install-tools/gsyslimits.h
+/home/a/snap/arduino/23/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/lib/gcc/xtensa-lx106-elf/4.8.2/install-tools/include/limits.h
+/home/a/snap/arduino/23/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/xtensa-lx106-elf/include/sys/syslimits.h
+/home/a/snap/arduino/23/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/xtensa-lx106-elf/include/c++/4.8.2/tr1/limits.h
+/home/a/snap/arduino/23/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/xtensa-lx106-elf/include/limits.h
+/usr/include/linux/limits.h
+/usr/include/c++/7/tr1/limits.h
+/usr/include/limits.h
+/usr/src/linux-headers-5.3.0-46/include/uapi/linux/limits.h
+/usr/src/linux-headers-5.3.0-46/include/linux/drbd_limits.h
+/usr/src/linux-headers-5.3.0-46/include/linux/dynamic_queue_limits.h
+/usr/src/linux-headers-5.3.0-46/include/linux/limits.h
+/usr/src/linux-headers-5.3.0-45/include/uapi/linux/limits.h
+/usr/src/linux-headers-5.3.0-45/include/linux/drbd_limits.h
+/usr/src/linux-headers-5.3.0-45/include/linux/dynamic_queue_limits.h
+/usr/src/linux-headers-5.3.0-45/include/linux/limits.h
+/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/syslimits.h
+/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h
+/usr/lib/llvm-6.0/lib/clang/6.0.0/include/limits.h
+/snap/arduino/17/hardware/tools/avr/lib/gcc/avr/7.3.0/include-fixed/limits.h
+/snap/arduino/17/hardware/tools/avr/lib/gcc/avr/7.3.0/include-fixed/syslimits.h
+/snap/arduino/17/hardware/tools/avr/lib/gcc/avr/7.3.0/install-tools/gsyslimits.h
+/snap/arduino/17/hardware/tools/avr/lib/gcc/avr/7.3.0/install-tools/include/limits.h
+/snap/arduino/17/hardware/tools/avr/lib/gcc/avr/7.3.0/plugin/include/glimits.h
+/snap/arduino/17/hardware/tools/avr/lib/gcc/avr/7.3.0/plugin/include/gsyslimits.h
+/snap/arduino/23/hardware/tools/avr/lib/gcc/avr/7.3.0/include-fixed/limits.h
+/snap/arduino/23/hardware/tools/avr/lib/gcc/avr/7.3.0/include-fixed/syslimits.h
+/snap/arduino/23/hardware/tools/avr/lib/gcc/avr/7.3.0/install-tools/gsyslimits.h
+/snap/arduino/23/hardware/tools/avr/lib/gcc/avr/7.3.0/install-tools/include/limits.h
+/snap/arduino/23/hardware/tools/avr/lib/gcc/avr/7.3.0/plugin/include/glimits.h
+/snap/arduino/23/hardware/tools/avr/lib/gcc/avr/7.3.0/plugin/include/gsyslimits.h
+/snap/gnome-3-34-1804/33/usr/include/c++/6/tr1/limits.h
+/snap/gnome-3-34-1804/33/usr/include/limits.h
+/snap/gnome-3-34-1804/33/usr/include/linux/limits.h
+/snap/gnome-3-34-1804/33/usr/lib/gcc/x86_64-linux-gnu/6/include-fixed/limits.h
+/snap/gnome-3-34-1804/33/usr/lib/gcc/x86_64-linux-gnu/6/include-fixed/syslimits.h
diff --git a/lib/inarray.c b/lib/inarray.c
new file mode 100644
index 0000000..e45137a
--- /dev/null
+++ b/lib/inarray.c
@@ -0,0 +1,9 @@
+int char_in_array(char val, char * arr) {
+ int i;
+ for(i = 0; i < sizeof(arr) / sizeof(arr[0]); i++) {
+ if(arr[i] == val) {
+ return 1;
+ }
+ }
+ return 0;
+}
diff --git a/lib/joinarrays.c b/lib/joinarrays.c
new file mode 100644
index 0000000..22070b0
--- /dev/null
+++ b/lib/joinarrays.c
@@ -0,0 +1,18 @@
+#pragma once
+#include <bvr.h>
+// do not use this, this is idiotic, use strlcpy
+char * join_null_terminated_arrays(char * a1, char * a2) { // returns null terminated array
+ char sizeof0 = BVR_VALUE_CHUNK_SIZE;
+ char * a0 = malloc(sizeof(char) * sizeof0);
+ char i = 0;
+ char position = 0;
+ while(a1[i] != 0) {
+ a0[position++] = a1[i++];
+ }
+ i = 0;
+ while(a2[i] != 0) {
+ a0[position++] = a2[i++];
+ }
+ a0[position++] = 0;
+ return a0;
+}
diff --git a/lib/randstring.c b/lib/randstring.c
index 2eeed8f..dd5ca8f 100644
--- a/lib/randstring.c
+++ b/lib/randstring.c
@@ -1,12 +1,13 @@
#pragma once
+#include <time.h>
char *randstring(size_t length) {
static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
char *randomString = NULL;
-
+ time_t t;
if (length) {
randomString = malloc(sizeof(char) * (length +1));
-
+ srand((unsigned) time(&t));
if (randomString) {
for (int n = 0;n < length;n++) {
int key = rand() % (int)(sizeof(charset) -1);
diff --git a/lib/strlcat.c b/lib/strlcat.c
new file mode 100644
index 0000000..5d4e99e
--- /dev/null
+++ b/lib/strlcat.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2011 Apple, Inc. All rights reserved.
+ *
+ * @APPLE_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. 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_LICENSE_HEADER_END@
+ */
+
+#include <strings.h>
+
+size_t
+strlcat(char * restrict dst, const char * restrict src, size_t maxlen) {
+ const size_t srclen = strlen(src);
+ const size_t dstlen = strnlen(dst, maxlen);
+ if (dstlen == maxlen) return maxlen+srclen;
+ if (srclen < maxlen-dstlen) {
+ memcpy(dst+dstlen, src, srclen+1);
+ } else {
+ memcpy(dst+dstlen, src, maxlen-1);
+ dst[dstlen+maxlen-1] = '\0';
+ }
+ return dstlen + srclen;
+}
+
diff --git a/src/bvr.h b/src/bvr.h
index 0008bef..588f31f 100644
--- a/src/bvr.h
+++ b/src/bvr.h
@@ -25,8 +25,8 @@ char bvr_variables[BVR_INITIAL_VARIABLES_COUNT*2][BVR_MAX_VARIABLE_SIZE];
int bvr_bvrvar_first_time_set = 1;
#define BVR_VER_MAJOR 0
-#define BVR_VER_MINOR 1
-#define BVR_VER_PATCH 1
+#define BVR_VER_MINOR 2
+#define BVR_VER_PATCH 0
#define BVR_PATH_SEPARATOR ' '
#define BVR_INCLUDE_PATH_VAR_NAME "bvr_include_path"
@@ -34,6 +34,8 @@ int bvr_bvrvar_first_time_set = 1;
#define BVR_CONTINUE 1328
#define BVR_KEEPGOING 132
+char BVR_CHARS_TO_BREAK_VALUE[3] = {CLOSING_COMMAND_TAG_CHAR_1, EOF, '\0'}; // 0x00 mora biti na koncu (null terminated array)
+#define BVR_VALUE_CHUNK_SIZE 256
int bvr_compose_stream(FILE *, FILE *);
int bvr_command_processor(FILE *, FILE *);
diff --git a/src/bvrcommands.c b/src/bvrcommands.c
index b040d46..3d54cd0 100644
--- a/src/bvrcommands.c
+++ b/src/bvrcommands.c
@@ -1,7 +1,12 @@
#pragma once
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <strlcat.c>
#include <bvr.h>
#include <tape.c>
#include <bvrvar.c>
+#include <inarray.c>
int bvr_commands_check_for_command(char * input_char, char ** value, int *i, FILE * input) {
if((*input_char) == LINE_COMMAND_CHAR) {
FILE * command_return;
@@ -11,12 +16,7 @@ int bvr_commands_check_for_command(char * input_char, char ** value, int *i, FIL
fprintf(stderr, "[bvrcommands.c] bvr_commands_check_for_command: command, passed as argument, didn't return success. Going on.\n");
}
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.
@@ -27,7 +27,6 @@ int bvr_commands_check_for_command(char * input_char, char ** value, int *i, FIL
}
return BVR_KEEPGOING;
}
-
char bvr_var_skip_separator_chars(FILE * input) {
char input_char = fgetc(input);
while(input_char == ' ' || input_char == CLOSING_COMMAND_TAG_CHAR_1 || input_char == ',' || input_char == ';' || input_char == EOF ||
@@ -36,68 +35,105 @@ char bvr_var_skip_separator_chars(FILE * input) {
}
return input_char;
}
-int bvr_handle_get(FILE * input, FILE * output) {
- char * item = (char*) malloc(BVR_MAX_VARIABLE_SIZE+1);
+char * bvr_commands_get_value(FILE * input, char * yeetus_chars) {
+ int value_size = BVR_VALUE_CHUNK_SIZE;
+ char * value = (char*) malloc(value_size);
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) {
+ while(1) {
+ // i == napisali smo že toliko znakov
+ if(i >= value_size) { // <-- todo: uncomment after done debugging
+ value = realloc(value, (value_size) * BVR_VALUE_CHUNK_SIZE);
+ value_size = value_size + BVR_VALUE_CHUNK_SIZE;
+ }
+ if(char_in_array(input_char, yeetus_chars)) {
+ value[i++] = '\0';
+ return value; // or yeet!
+ }
+ if(bvr_commands_check_for_command(&(input_char), &(value), &(i), input) == BVR_CONTINUE) {
continue;
}
- item[i++] = input_char;
+ (value)[(i)++] = input_char;
input_char = fgetc(input);
}
- item[i++] = '\0';
+ // we should not get here!
+}
+int bvr_handle_substring(FILE * input, FILE * output) { // acts like https://www.php.net/manual/en/function.substr.php
+ char chars_to_break_value[69] = ",; ";
+ strlcat(chars_to_break_value, BVR_CHARS_TO_BREAK_VALUE, sizeof(chars_to_break_value));
+ char * offset = bvr_commands_get_value(input, chars_to_break_value);
+ char * length = bvr_commands_get_value(input, chars_to_break_value);
+ char * string = bvr_commands_get_value(input, BVR_CHARS_TO_BREAK_VALUE);
+
+ int return_status = SUCCESS;
+ int real_offset = atoi(offset);
+
+ if(real_offset < 0) {
+ real_offset = strlen(string)-abs(real_offset);
+ }
+
+ if(strlen(string) < real_offset) { // catch errors
+ fprintf(stderr, "[bvrcommands.c] bvr_handle_substring: string lenght (%ld) is less than offset (%d). fuck you.\n",
+ strlen(string), real_offset);
+ fprintf(output, "\nbVerbose substring: string length of %ld is less than offset of %d.\n", strlen(string), real_offset);
+ return_status = FAILURE;
+ goto cleanup_and_return;
+ }
+ if(real_offset < 0) { // catch errors
+ fprintf(stderr, "[bvrcommands.c] bvr_handle_substring: supplied negative offset after calculation (%d) is negative. failing...\n",
+ real_offset);
+ fprintf(output, "\nbVerbose substring: supplied negative offset after calculation (%d) is negative.\n", real_offset);
+ return_status = FAILURE;
+ goto cleanup_and_return;
+ }
+
+ if(atoi(length) < 0) {
+ string[strlen(string)-abs(atoi(length))] = '\0';
+ fprintf(output, "%s", string+real_offset);
+ } else {
+ fprintf(output, "%.*s", atoi(length), string+real_offset);
+ }
+
+ cleanup_and_return:
+ fflush(output);
+ free(offset);
+ free(length);
+ free(string);
+ offset = NULL;
+ length = NULL;
+ string = NULL;
+ return return_status;
+}
+int bvr_handle_get(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);
+
fprintf(output, "%s", bvr_var_get(item));
fflush(output);
+ free(item);
+ item = NULL;
return SUCCESS;
}
int bvr_handle_set(FILE * input, FILE * output) {
- 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);
- }
- item[i++] = '\0';
- 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' && 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);
+ 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, BVR_CHARS_TO_BREAK_VALUE);
+ int return_value = bvr_var_set(item, value);
fflush(output);
- return SUCCESS;
+ free(item);
+ free(value);
+ item = NULL;
+ value = NULL;
+ return return_value;
}
int bvr_handle_include(FILE * input, FILE * output) {
- 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) {
- continue;
- }
- item[i++] = input_char;
- input_char = fgetc(input);
- }
- item[i++] = '\0';
+ char chars_to_break_value[69] = " ";
+ strlcat(chars_to_break_value, BVR_CHARS_TO_BREAK_VALUE, sizeof(chars_to_break_value));
+ // fprintf(stderr, "debug: \"%s\"\n", chars_to_break_value);
+ char * item = bvr_commands_get_value(input, chars_to_break_value);
+
FILE * stream = fopen(item, "r");
char notgoodatnamingvariables[PATH_MAX];
char * path = bvr_var_get(BVR_INCLUDE_PATH_VAR_NAME);
@@ -106,8 +142,8 @@ int bvr_handle_include(FILE * input, FILE * output) {
strcat(notgoodatnamingvariables, BVR_COMMAND_FILE_EXT);
stream = fopen(notgoodatnamingvariables, "r");
if(strcmp(path, BVR_UNDEFINED) == 0 && stream == NULL) {
- fprintf(output, "\nbVerbose include error. File %s not found. Path is undefined.\n", item);
- fprintf(stderr, "[bvrcommands.c] bvr_handle_include: File %s not found. Path is undefined.\n", item);
+ fprintf(output, "\nbVerbose include error. File \"%s\" not found. Path is undefined.\n", item);
+ fprintf(stderr, "[bvrcommands.c] bvr_handle_include: File \"%s\" not found. Path is undefined.\n", item);
return FAILURE;
}
}
@@ -124,8 +160,8 @@ int bvr_handle_include(FILE * input, FILE * output) {
strcat(notgoodatnamingvariables, BVR_COMMAND_FILE_EXT);
stream = fopen(notgoodatnamingvariables, "r"); // ob1 fuckery
if(stream == NULL) {
- fprintf(output, "\nbVerbose include error. File %s not found.\n", item);
- fprintf(stderr, "[bvrcommands.c] bvr_handle_include: File %s not found.\n", item);
+ fprintf(output, "\nbVerbose include error. File \"%s\" not found.\n", item);
+ fprintf(stderr, "[bvrcommands.c] bvr_handle_include: File \"%s\" not found.\n", item);
return FAILURE;
}
break;
@@ -144,37 +180,26 @@ int bvr_handle_include(FILE * input, FILE * output) {
}
*singlepath = '\0';
}
- return bvr_compose_stream(stream, output);
+ int return_status = bvr_compose_stream(stream, output);
fflush(output);
+ free(item);
+ item = NULL;
+ return return_status;
+ fflush(output); // kja?
}
int bvr_handle_move(FILE * input, FILE * output) {
- 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);
- }
- item[i++] = '\0';
- i = 0;
- 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) {
- continue;
- }
- value[i++] = input_char;
- input_char = fgetc(input);
- }
- value[i++] = '\0';
- return bvr_var_mv(item, value);
+ 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 = bvr_var_mv(item, value);
+ free(item);
+ free(value);
+ value = NULL;
+ item = NULL;
fflush(output);
- return SUCCESS;
+ return return_value;
}
int bvr_handle_info(FILE * input, FILE * output) {
diff --git a/src/tape.c b/src/tape.c
index 185097b..e405001 100644
--- a/src/tape.c
+++ b/src/tape.c
@@ -29,8 +29,11 @@ int bvr_command_processor(FILE * page_source_file, FILE * temp_output_file) {
case 'm':
command_handler_output = bvr_handle_move(page_source_file, temp_output_file);
break;
+ case 'u':
+ command_handler_output = bvr_handle_substring(page_source_file, temp_output_file);
+ break;
case 'b':
- fprintf(stderr, "bunden %c\n", command_entered);
+ // fprintf(stderr, "bunden %c\n", command_entered);
command_handler_output = bvr_handle_info(page_source_file, temp_output_file);
break;
default:
@@ -83,9 +86,11 @@ int bvr_inline_command_processor(FILE * page_source_file, FILE * output_file, ch
int bvr_compose_stream(FILE * page_source_file, FILE * temp_output_file) {
char copy_buffer[COPY_BUFFER_SIZE];
+ int cycles = 0;
for(int i = 0; i < sizeof(copy_buffer); i++) { // da garbage vrednosti ne bodo slučajno ukazi!
- copy_buffer[i] = '\n';
- }
+ copy_buffer[i] = '\n'; // čeprav OS verjetno nastavi ram na \0\0\0\0\0\0 preden ga da procesu
+ } // ampak kaj pa, ko funkcijo zaženemo drugič, pointer bo kazal na isto mesto! // nočemo \0
+
// copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] = fgetc(page_source_file);
// if(copy_buffer[ftell(page_source_file)% COPY_BUFFER_SIZE] == EOF) {
// goto done_reading_write_file;
@@ -116,10 +121,12 @@ 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);
+ fputc('\n', temp_output_file); // NO POMEGRANTES! NO! NO! NO! NO POMEGRANTES!
break;
}
- fputc(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE], temp_output_file);
+ if (cycles++ != 0) { // da ne napišemo prvega znaka bufferja, preden je sploh kaj v bufferju.
+ fputc(copy_buffer[(ftell(page_source_file)-1)% COPY_BUFFER_SIZE], temp_output_file);
+ }
}
return SUCCESS;
}
diff --git a/test/inarray-test.c b/test/inarray-test.c
new file mode 100644
index 0000000..21cb1d1
--- /dev/null
+++ b/test/inarray-test.c
@@ -0,0 +1,16 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <limits.h>
+#include <inarray.c>
+extern int main(int argc, char* argv[]) {
+ if(argc != 3) {
+ printf("%s c string\n", argv[0]);
+ return 1;
+ }
+ if(char_in_array(argv[1][0], argv[2])) {
+ printf("%c is in %s\n", argv[1][0], argv[2]);
+ } else {
+ printf("%c is NOT in %s\n", argv[1][0], argv[2]);
+ }
+ return 0;
+}
diff --git a/test/joinarray.c b/test/joinarray.c
new file mode 100644
index 0000000..5c81a65
--- /dev/null
+++ b/test/joinarray.c
@@ -0,0 +1,13 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <limits.h>
+#include <joinarrays.c>
+// do not use this, it is idiotic, you have strlcpy!
+extern int main(int argc, char* argv[]) {
+ char a1[3] = {1, 2, 3};
+ char a2[5] = {4, 5, 6, 7, 8};
+ int * joined = join_null_terminated_arrays(a1, a2);
+ joined[8] = '\n';
+ fprintf(stdout, "%ld\n", joined);
+ return 0;
+}
diff --git a/test/tape-test.bvr b/test/tape-test.bvr
index 0ae5679..85e9f58 100644
--- a/test/tape-test.bvr
+++ b/test/tape-test.bvr
@@ -1,4 +1,3 @@
<@?i assets/content/global.bvr @>
-<@?s testing krnkeni@>
-<@?s abcdefghijklmnopr ?i krnkeni@>
-<@?g abcdefghijklmnopr@>
+<@?s testing krneki@>
+<@?u -2 -1 ?g testing @>
diff --git a/tmp/output.htm b/tmp/output.htm
index 5948d6a..57a8f14 100644
--- a/tmp/output.htm
+++ b/tmp/output.htm
@@ -1,6 +1,4 @@
-
-
@@ -19,7 +17,4 @@
-
-
-69krnkeni file inclusion complete
-
+k