From cdf445a7f00fcdc18751799fcb014b9501bb62af Mon Sep 17 00:00:00 2001 From: Greg Wells Date: Sat, 17 May 2025 13:46:23 -0400 Subject: [PATCH] delete the file API --- src/files/gryphn_file.c | 56 ----------------------------------------- src/files/gryphn_file.h | 29 --------------------- 2 files changed, 85 deletions(-) delete mode 100644 src/files/gryphn_file.c delete mode 100644 src/files/gryphn_file.h diff --git a/src/files/gryphn_file.c b/src/files/gryphn_file.c deleted file mode 100644 index 8ebeb58..0000000 --- a/src/files/gryphn_file.c +++ /dev/null @@ -1,56 +0,0 @@ -#include "gryphn_file.h" -#include -// #include "fstream" -// #include "iostream" - -gnFile gnLoadFile(const gnString path, gnFileType type) { - gnFile new_file = { - .path = path, - .type = type - }; - - if (type == GN_FILE_TEXT) { - new_file.data = malloc(sizeof(gnString)); - *((gnString*)new_file.data) = gnCreateEmptyString(); - } - - if (type == GN_FILE_TEXT) { - FILE *fptr; - fptr = fopen(path.value, "r"); - - int ch; - if (fptr != NULL) { - while ((ch = fgetc(fptr)) != EOF) { - putchar(ch); // or process the char - } - fclose(fptr); - } - } - else if (type == GN_FILE_BINARY) { - FILE *file = fopen(path.value, "rb"); - if (file) { - fseek(file, 0, SEEK_END); - long size = ftell(file); - rewind(file); - char *buffer = malloc(size); - if (buffer) { - fread(buffer, 1, size, file); - // use buffer here - free(buffer); - } - fclose(file); - } - } - return new_file; -} - -gnString gnGetFileData(const gnFile file) { return *(gnString*)file.data;} - // why I dont just return the file as a list of lines, cuz thats the easy way this way revealed so many errors in my string class, - // dont you love it when you dont actually copy a string and then the data gets lost and you dont know why because your an idiot - // thats never happened to me...... yea so im an idiot shouve actually copied the bytes over not just haphazardly asigned them to a string. - -gnString gnGetFilePath(const gnFile file) { - return file.path; -} - -gnChar* gnGetFileBytes(const gnFile file) { return (gnChar*)file.data; } diff --git a/src/files/gryphn_file.h b/src/files/gryphn_file.h deleted file mode 100644 index 78a057d..0000000 --- a/src/files/gryphn_file.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include "../strings/gryphn_string.h" -#include "../lists/gryphn_array_list.h" - -typedef enum gnFileType { - GN_FILE_TEXT, GN_FILE_BINARY -} gnFileType; - -typedef struct gnFile { - void* data; - // GN_FILE_TEXT = gnString - // GN_FILE_BINARY = gnChar* - gnString path; - gnFileType type; -} gnFile; - -#ifdef GN_UITLS_CPP -gnFile gnLoadFile(const gnString& path, gnFileType type = GN_FILE_TEXT); -#else -gnFile gnLoadFile(const gnString path, gnFileType type); -#endif -// gnFile gnCreateFile(const gnString path); -// gnFile gnWriteFile(const gnFile file); - -gnString gnGetFilePath(const gnFile file); -gnString gnGetFileData(const gnFile file); // i should rename this -gnChar* gnGetFileBytes(const gnFile file); // fuck object oriented code - // and fuck error detection the user can get the bytes of a text file if they want to cuz its slow to do error checking, its also smart but im slow - // so me and this project are one in the same