summaryrefslogtreecommitdiff
path: root/src/error
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-10-19 05:35:06 -0500
committersanine-a <sanine.not@pm.me>2020-10-19 05:35:06 -0500
commit41fa908dc15b522e53946a716f4f6c00520bd46f (patch)
treebc8176462000b2c77c00d3227037c1acbb13e0ee /src/error
parent2d046ffd16d8ff3a06f92ca438ca6b2d6842ce6a (diff)
add honey libraries back and reorganize directories
Diffstat (limited to 'src/error')
-rw-r--r--src/error/error.c126
-rw-r--r--src/error/error.h7
2 files changed, 133 insertions, 0 deletions
diff --git a/src/error/error.c b/src/error/error.c
new file mode 100644
index 0000000..671d34e
--- /dev/null
+++ b/src/error/error.c
@@ -0,0 +1,126 @@
+#include "../common.h"
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+void honey_error_clear_strings() {
+ memset(honey_error_data.string1, 0, HONEY_ERROR_DATA_STRING_LENGTH);
+ memset(honey_error_data.string2, 0, HONEY_ERROR_DATA_STRING_LENGTH);
+}
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+void honey_error_set_string1(char* string) {
+ size_t n_bytes = strlen(string) + 1;
+ if (n_bytes > HONEY_ERROR_DATA_STRING_LENGTH)
+ n_bytes = HONEY_ERROR_DATA_STRING_LENGTH;
+ memcpy(honey_error_data.string1, string, n_bytes);
+ honey_error_data.string1[HONEY_ERROR_DATA_STRING_LENGTH-1] = 0;
+}
+
+void honey_error_set_string2(char* string) {
+ size_t n_bytes = strlen(string) + 1;
+ if (n_bytes > HONEY_ERROR_DATA_STRING_LENGTH)
+ n_bytes = HONEY_ERROR_DATA_STRING_LENGTH;
+ memcpy(honey_error_data.string2, string, n_bytes);
+ honey_error_data.string2[HONEY_ERROR_DATA_STRING_LENGTH-1] = 0;
+}
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+void honey_human_readable_error(char* error_string, honey_result error) {
+ size_t string_size = sizeof(char)*3*HONEY_ERROR_DATA_STRING_LENGTH;
+
+ switch(error) {
+ case HONEY_OK:
+ snprintf(error_string, string_size, "[honey] OK");
+ break;
+
+ case HONEY_MEMORY_ALLOCATION_ERROR:
+ snprintf(error_string, string_size, "[honey] ERROR: failed to allocate memory");
+ break;
+
+ case HONEY_FILE_READ_ERROR:
+ if (honey_error_data.string1 != NULL) {
+ snprintf(error_string,
+ string_size,
+ "[honey] ERROR: failed to read file '%s'",
+ honey_error_data.string1);
+ } else {
+ snprintf(error_string, string_size, "[honey] ERROR: failed to read file");
+ }
+ break;
+
+ case HONEY_VERTEX_SHADER_COMPILATION_ERROR:
+ if (honey_error_data.string1 != NULL) {
+ if (honey_error_data.string2 != NULL) {
+ snprintf(error_string,
+ string_size,
+ "[honey] ERROR: failed to compile vertex shader '%s'\n"
+ "[honey] GLSL compiler output:\n%s\n",
+ honey_error_data.string2,
+ honey_error_data.string1);
+ } else {
+ snprintf(error_string,
+ string_size,
+ "[honey] ERROR: failed to compile vertex shader\n"
+ "[honey] GLSL compiler output:\n%s\n",
+ honey_error_data.string1);
+ }
+ } else {
+ snprintf(error_string,
+ string_size,
+ "[honey] ERROR: failed to compile vertex shader.");
+ }
+ break;
+
+
+ case HONEY_FRAGMENT_SHADER_COMPILATION_ERROR:
+ if (honey_error_data.string1 != NULL) {
+ if (honey_error_data.string2 != NULL) {
+ snprintf(error_string,
+ string_size,
+ "[honey] ERROR: failed to compile fragment shader '%s'\n"
+ "[honey] GLSL compiler output:\n%s\n",
+ honey_error_data.string2,
+ honey_error_data.string1);
+ } else {
+ snprintf(error_string,
+ string_size,
+ "[honey] ERROR: failed to compile fragment shader\n"
+ "[honey] GLSL compiler output:\n%s\n",
+ honey_error_data.string1);
+ }
+ } else {
+ snprintf(error_string,
+ string_size,
+ "[honey] ERROR: failed to compile fragment shader.");
+ }
+ break;
+
+ case HONEY_SHADER_LINK_ERROR:
+ break;
+
+ case HONEY_MESH_BAD_VERTEX_DATA:
+ break;
+
+ case HONEY_MESH_BAD_INDEX_DATA:
+ break;
+
+ case HONEY_MODEL_LOAD_ERROR:
+ snprintf(error_string,
+ string_size,
+ "[honey] ERROR: model '%s' contains errors",
+ honey_error_data.string1);
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+
+
+
+
+
diff --git a/src/error/error.h b/src/error/error.h
new file mode 100644
index 0000000..e456c88
--- /dev/null
+++ b/src/error/error.h
@@ -0,0 +1,7 @@
+#ifndef HONEY_ERROR_H
+#define HONEY_ERROR_H
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+
+#endif