cleanup: remove load_entire_file and m_string

This commit is contained in:
Sven Balzer 2025-03-25 21:19:54 +01:00
parent 1db5440767
commit 31c4bde4bf
5 changed files with 0 additions and 107 deletions

View File

@ -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

View File

@ -1,32 +0,0 @@
#define _CRT_SECURE_NO_WARNINGS
#include "load_entire_file.h"
#include <stdio.h>
#include <stdlib.h>
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 };
}

View File

@ -1,4 +0,0 @@
#pragma once
#include "m_string.h"
String load_entire_file(const char* filename);

View File

@ -1,68 +0,0 @@
#pragma once
#define min(a,b) (((a) < (b)) ? (a) : (b))
#include <stddef.h>
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<size_t _len> 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 <typename T>
inline T read(String& file) {
if (file.length < sizeof(T))
return {};
T value = *(T*)file.data;
advance(file, sizeof(T));
return value;
}

View File

@ -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"