summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsijanec <anton@sijanec.eu>2021-01-19 15:26:05 +0100
committersijanec <anton@sijanec.eu>2021-01-19 15:26:05 +0100
commit69c8904b2d9a325ab2a8f71c28cbaa34bb830887 (patch)
treea174c437024abb58c8af438281cf24891765c4f6 /src
parentdodal arraye (diff)
downloadbverbose-69c8904b2d9a325ab2a8f71c28cbaa34bb830887.tar
bverbose-69c8904b2d9a325ab2a8f71c28cbaa34bb830887.tar.gz
bverbose-69c8904b2d9a325ab2a8f71c28cbaa34bb830887.tar.bz2
bverbose-69c8904b2d9a325ab2a8f71c28cbaa34bb830887.tar.lz
bverbose-69c8904b2d9a325ab2a8f71c28cbaa34bb830887.tar.xz
bverbose-69c8904b2d9a325ab2a8f71c28cbaa34bb830887.tar.zst
bverbose-69c8904b2d9a325ab2a8f71c28cbaa34bb830887.zip
Diffstat (limited to 'src')
-rw-r--r--src/bvrcommands.c100
1 files changed, 63 insertions, 37 deletions
diff --git a/src/bvrcommands.c b/src/bvrcommands.c
index b7d14e3..a44954f 100644
--- a/src/bvrcommands.c
+++ b/src/bvrcommands.c
@@ -180,56 +180,82 @@ int bvr_handle_set(FILE * input, FILE * output) {
int bvr_handle_include(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));
- // 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);
- if(stream == NULL) {
- strcpy(notgoodatnamingvariables, item);
- 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);
- return FAILURE;
+ FILE * stream;
+ char * cp;
+ int return_status = SUCCESS;
+ // fprintf(stderr, "debug: %s\n", item);
+ if (strncmp(item, "bvr://", strlen("bvr://")) == 0) {
+ switch (item[6]) {
+ case 'v': /* ar */
+ cp = strchr(item+6, '/');
+ if (cp == NULL)
+ goto sike_this_actually_is_a_file;
+ cp = bvr_var_get(cp+1);
+ if (cp == NULL || 0 == strncmp(cp, "BVR_UNDEFINED", strlen("BVR_UNDEFINED")))
+ goto sike_this_actually_is_a_file;
+ stream = fmemopen(cp, strlen(cp), "r");
+ if (stream == NULL)
+ goto sike_this_actually_is_a_file;
+ break;
+ default:
+ goto sike_this_actually_is_a_file;
+ break; /* unreachable "code" */
}
- }
- char * singlepath;
- while(stream == NULL) {
- singlepath = strrchr(path, BVR_PATH_SEPARATOR);
- if(singlepath == NULL) {
- strcpy(notgoodatnamingvariables, path);
- strcat(notgoodatnamingvariables, item);
- stream = fopen(notgoodatnamingvariables, "r"); // ob1 fuckery
- if(stream == NULL) {
+ } else {
+ sike_this_actually_is_a_file:
+ stream = fopen(item, "r");
+ char notgoodatnamingvariables[PATH_MAX];
+ char * path = bvr_var_get(BVR_INCLUDE_PATH_VAR_NAME);
+ if(stream == NULL) {
+ strcpy(notgoodatnamingvariables, item);
+ 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);
+ return_status = FAILURE;
+ goto returncleanly;
+ }
+ }
+ char * singlepath;
+ while(stream == NULL) {
+ singlepath = strrchr(path, BVR_PATH_SEPARATOR);
+ if(singlepath == NULL) {
strcpy(notgoodatnamingvariables, path);
strcat(notgoodatnamingvariables, item);
- 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);
- return FAILURE;
+ strcpy(notgoodatnamingvariables, path);
+ strcat(notgoodatnamingvariables, item);
+ 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);
+ return_status = FAILURE;
+ goto returncleanly;
+ }
+ break;
}
break;
}
- break;
- }
- strcpy(notgoodatnamingvariables, singlepath);
- strcat(notgoodatnamingvariables, item);
- stream = fopen(notgoodatnamingvariables+1, "r"); // ob1 fuckery
- if(stream == NULL) {
- strcat(notgoodatnamingvariables, BVR_COMMAND_FILE_EXT);
+ strcpy(notgoodatnamingvariables, singlepath);
+ strcat(notgoodatnamingvariables, item);
stream = fopen(notgoodatnamingvariables+1, "r"); // ob1 fuckery
- if(stream != NULL) {
- break;
+ if(stream == NULL) {
+ strcat(notgoodatnamingvariables, BVR_COMMAND_FILE_EXT);
+ stream = fopen(notgoodatnamingvariables+1, "r"); // ob1 fuckery
+ if(stream != NULL) {
+ break;
+ }
}
+ *singlepath = '\0';
}
- *singlepath = '\0';
}
- int return_status = bvr_compose_stream(stream, output);
+ return_status = bvr_compose_stream(stream, output);
+ fclose(stream);
+ returncleanly:
fflush(output);
free(item);
item = NULL;