1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
#pragma once
#include <bvr.h>
#include <tape.c>
#include <bvrvar.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;
command_return = fmemopen(value+((*i)++), sizeof(value)-(*i), "w"); // 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);
(*input_char) = CLOSING_COMMAND_TAG_CHAR_1; // da zaključimo loop (drugače ostane notri ?)
fflush(command_return);
fclose(command_return);
return BVR_CONTINUE;
}
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 ||
input_char == '\0' || input_char == '\n') {
input_char = fgetc(input);
}
return input_char;
}
int bvr_handle_get(FILE * input, FILE * output) {
char item[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';
fprintf(output, "%s", bvr_var_get(item));
fflush(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 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' && 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_set(item, value);
fflush(output);
return SUCCESS;
}
int bvr_handle_include(FILE * input, FILE * output) {
char item[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';
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;
}
}
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) {
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;
}
break;
}
break;
}
strcpy(notgoodatnamingvariables, singlepath);
strcat(notgoodatnamingvariables, item);
stream = fopen(notgoodatnamingvariables+1, "r"); // ob1 fuckery
if(stream == NULL) {
strcat(notgoodatnamingvariables, BVR_COMMAND_FILE_EXT);
stream = fopen(notgoodatnamingvariables+1, "r"); // ob1 fuckery
if(stream != NULL) {
break;
}
}
*singlepath = '\0';
}
return bvr_compose_stream(stream, 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 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) {
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);
fflush(output);
return SUCCESS;
}
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);
return SUCCESS;
}
|