From 31c4bde4bfe120ebc995915cbf848c23c2e1ef06 Mon Sep 17 00:00:00 2001 From: Sven Balzer <4653051+Kyuusokuna@users.noreply.github.com> Date: Tue, 25 Mar 2025 21:19:54 +0100 Subject: [PATCH] cleanup: remove load_entire_file and m_string --- CMakeLists.txt | 1 - src/load_entire_file.cpp | 32 ------------------- src/load_entire_file.h | 4 --- src/m_string.h | 68 ---------------------------------------- src/main.cpp | 2 -- 5 files changed, 107 deletions(-) delete mode 100644 src/load_entire_file.cpp delete mode 100644 src/load_entire_file.h delete mode 100644 src/m_string.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d83acd..23656d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,7 +75,6 @@ add_shader(grid) add_executable(mikemon src/log.cpp - src/load_entire_file.cpp src/smol-atlas.cpp src/math_graphics.cpp src/main.cpp diff --git a/src/load_entire_file.cpp b/src/load_entire_file.cpp deleted file mode 100644 index a5e780a..0000000 --- a/src/load_entire_file.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include "load_entire_file.h" - -#include -#include - -String load_entire_file(const char* filename) { - auto file = fopen(filename, "rb"); - if (!file) - return {}; - - if (fseek(file, 0, SEEK_END)) - return {}; - - auto file_length = ftell(file); - if (file_length == -1) - return {}; - - if (fseek(file, 0, SEEK_SET)) - return {}; - - auto file_mem = malloc(file_length); - if (!file_mem) - return {}; - - if (fread(file_mem, file_length, 1, file) != 1) { - free(file_mem); - return {}; - } - - return { (size_t)file_length, (char*)file_mem }; -} \ No newline at end of file diff --git a/src/load_entire_file.h b/src/load_entire_file.h deleted file mode 100644 index 1b82158..0000000 --- a/src/load_entire_file.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "m_string.h" - -String load_entire_file(const char* filename); \ No newline at end of file diff --git a/src/m_string.h b/src/m_string.h deleted file mode 100644 index a0c2888..0000000 --- a/src/m_string.h +++ /dev/null @@ -1,68 +0,0 @@ -#pragma once -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#include - -struct String { - - size_t length; - char* data; - - constexpr String() : length(0), data(0) {}; - constexpr String(size_t length, char* data) : length(length), data(data) {}; - template constexpr String(const char(&data)[_len]) : length(_len - 1), data((char*)data) {}; - - char operator[](int index) { - if (index < 0) { - return 0; - } - if (index < length) { - return data[index]; - } - return 0; - } -}; - -inline String operator""_str(const char* str, size_t length) { - return { length, (char*)str }; -} - -inline bool operator==(String a, String b) { - if (a.length != b.length) - return false; - - if (a.data == b.data) - return true; - - for (int i = 0; i < a.length; i++) - if (a[i] != b[i]) - return false; - - return true; -} - -inline void advance(String& s, int num = 1) { - int to_advance = min(s.length, num); - s.data = s.data + to_advance; - s.length = s.length - to_advance; -} - -inline bool starts_with(String s, String start) { - if (s.length < start.length) { - return false; - } - for (int i = 0; i < start.length; i++) { - if (s[i] != start[i]) { - return false; - } - } - return true; -} - -template -inline T read(String& file) { - if (file.length < sizeof(T)) - return {}; - T value = *(T*)file.data; - advance(file, sizeof(T)); - return value; -} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 64fd513..3222d88 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,9 +10,7 @@ #include "defer.h" #include "log.h" -#include "m_string.h" #include "math_graphics.h" -#include "load_entire_file.h" #include "stb_image.h" #include "../assets/shader/basic.h"