This commit is contained in:
herbglitch 2022-10-27 15:16:54 -06:00
commit db1adbb838
35 changed files with 4408 additions and 0 deletions

View file

@ -0,0 +1,5 @@
#ifndef ARC_GRAPHICS_DATA_H_
#define ARC_GRAPHICS_DATA_H_
#endif //ARC_GRAPHICS_DATA_H_

141
include/arc/std/config.h Normal file
View file

@ -0,0 +1,141 @@
#ifndef ARC_STD_CONFIG_H_
#define ARC_STD_CONFIG_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "arc/std/hashtable.h"
#include "arc/std/string.h"
#include <stdint.h>
#ifndef ARC_HOME_PATH
#define ARC_HOME_PATH "./res/"
#endif //ARC_HOME_PATH
#define ARC_KEY_BUCKET_SIZE 0x20
#define ARC_GROUP_BUCKET_SIZE 0x20
#define ARC_GROUP_DATA_BUCKET_SIZE 0x20
/**
* @brief a type that keeps permanice of data for when loading and unloading config files
*/
typedef struct ARC_Config ARC_Config;
/**
* @brief a function to read a key from string to a ARC_ConfigTypeTemplate
*
* @param config ARC_Config to store data to
* @param data string of what is to be read in
* @param subdata location of stubstring in data for what is to be read in
* @param value value of read in variable
*/
typedef int32_t (* ARC_ConfigKeyRead)(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
/**
* @brief a function to delete a value from a key in ARC_Config
*
* @param config ARC_Config that can be used to check for references in data
* @param data string of what is going to be deleted (used to check if value is a reference)
* @param subdata location of substring in data for what is going to be deleted (used to check if value is a reference)
* @param value pointer of data to be deleted
*/
typedef int32_t (* ARC_ConfigKeyDelete)(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
/**
* @brief adds a usable key to ARC_Config
*
* @param config ARC_Config we are adding keys to
* @param type string of key type
* @param keyRead function for reading/creating key from string
* @param keyDelete function for deleting stored key
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_ConfigKey_Add(ARC_Config *config, char *type, ARC_ConfigKeyRead keyRead, ARC_ConfigKeyDelete keyDelete);
/**
* @brief external callback to add keys to config
*/
typedef int32_t (* ARC_ConfigKey_AddFunc)(ARC_Config *config);
/**
* @brief creates ARC_Config type
*
* @param config ARC_Config we are initializing
* @param keysAdd callback to add ConfigKeys to config->keys, can be NULL
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_Config_Create(ARC_Config **config, ARC_ConfigKey_AddFunc keysAdd);
/**
* @brief destroys ARC_Config type
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_Config_Destroy(ARC_Config *config);
/**
* @brief commands that can be used in ARC_Config_FileIO
*/
#define ARC_CONFIG_FILE_IO_LOAD 0x00
#define ARC_CONFIG_FILE_IO_UNLOAD 0x01
/**
* @brief handles file io for ARC_Config Type
*
* @param config ARC_Config where io operations will take place
* @param path file path for io
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_Config_FileIO(ARC_Config *config, const char *path, uint8_t command);
/**
* @brief sets current group in config
*
* @note ARC_Config_Get will use this set group
*
* @param config ARC_Config we are setting current group in
* @param groupname name of group that will be set
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_Config_SetGroup(ARC_Config *config, char *groupname);
/**
* @brief get a value from a given keyname
*
* @note name may be prefaced with <group>:: to specify group
*
* @param config ARC_Config to get value from
* @param keyname name of key to get from config
* @param value data retrieved from config
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_Config_Get(ARC_Config *config, char *keyname, void **value);
/**
* @brief get a reference value from a given substring
*
* @note this function is meant to help with creation and deletion functions for types
*
* @param config ARC_Config to get value from
* @param data string that holds the substring that will be used
* @param subdata location of stubstring in data for what is to be read in
*
* @return a valid pointer on sucess, NULL on fail
*/
void *ARC_Config_GetReference(ARC_Config *config, char *data, ARC_StringSubstr *subdata);
#ifdef __cplusplus
}
#endif
#endif //ARC_STD_CONFIG_H_
#ifdef ARC_DEFAULT_CONFIG
#include "defaults/config.h"
#endif //ARC_DEFAULT_CONFIG

View file

@ -0,0 +1,48 @@
#ifdef ARC_DEFAULT_CONFIG
#ifndef ARC_DEFAULTS_CONFIG_H_
#define ARC_DEFAULTS_CONFIG_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "arc/std/string.h"
typedef struct ARC_Config ARC_Config;
int32_t ARC_Defaults_ConfigKey_Create(ARC_Config *config);
int32_t ARC_ConfigKey_Read_Uint8_t (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_ConfigKey_Read_Int8_t (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
//int32_t ARC_ConfigKey_Read_Char (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_ConfigKey_Read_Uint16_t(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_ConfigKey_Read_Int16_t (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_ConfigKey_Read_Uint32_t(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_ConfigKey_Read_Int32_t (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_ConfigKey_Read_Int (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_ConfigKey_Read_Uint64_t(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_ConfigKey_Read_Int64_t (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_ConfigKey_Read_Long (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_ConfigKey_Read_String (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
int32_t ARC_ConfigKey_Delete_Uint8_t (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_ConfigKey_Delete_Int8_t (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_ConfigKey_Delete_Char (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_ConfigKey_Delete_Uint16_t(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_ConfigKey_Delete_Int16_t (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_ConfigKey_Delete_Uint32_t(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_ConfigKey_Delete_Int32_t (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_ConfigKey_Delete_Int (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_ConfigKey_Delete_Uint64_t(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_ConfigKey_Delete_Int64_t (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_ConfigKey_Delete_Long (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
int32_t ARC_ConfigKey_Delete_String (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
#ifdef __cplusplus
}
#endif
#endif //ARC_DEFAULTS_CONFIG_H_
#endif //ARC_DEFAULT_CONFIG

36
include/arc/std/errno.h Normal file
View file

@ -0,0 +1,36 @@
#ifndef ARC_STD_ERRNO_H_
#define ARC_STD_ERRNO_H_
#include <stdint.h>
#define ARC_ERRNO_NULL -0x01
#define ARC_ERRNO_DATA -0x02
#define ARC_ERRNO_COPY -0x03
#define ARC_ERRNO_EXISTS -0x04
#define ARC_ERRNO_OVERFLOW -0x05
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
static int32_t arc_errno = 0;
// #pragma GCC diagnostic pop
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#ifdef ARC_DEBUG
# include <stdio.h>
# define ARC_DEBUG_LOG(ERR, STR, ...) printf("[ERROR %d] " STR "\n", ERR, __VA_ARGS__)
#else
# define ARC_DEBUG_LOG(ERR, STR, ...)
#endif
#define ARC_ERR_CHECK(FUNC) FUNC; if(arc_errno){ ARC_DEBUG_LOG(arc_errno, "%s", #FUNC); return; }
#endif //ARC_STD_ERRNO_H_

110
include/arc/std/handler.h Normal file
View file

@ -0,0 +1,110 @@
#ifndef ARC_STD_HANDLER_H_
#define ARC_STD_HANDLER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/**
* @brief a handler type
*/
typedef struct ARC_Handler ARC_Handler;
/**
* @brief a function that will take iterated data
*
* @param data iterated data from ARC_Handler_Iterate
*/
typedef void (* ARC_Handler_DataFn)(void *data);
/**
* @brief a function that will be used during destruction of trash vector
*
* @param data data that is being destroyed from trash
*/
typedef void (* ARC_Handler_CleanDataFn)(void *data);
/**
* @brief creates ARC_Handler type
*
* @param config ARC_Handler to initialize
*/
void ARC_Handler_Create(ARC_Handler **handler);
/**
* @brief destroyes ARC_Handler type
*/
void ARC_Handler_Destroy(ARC_Handler *handler, ARC_Handler_CleanDataFn cleanfn);
/**
* @brief adds data to handler
*
* @param handler ARC_Handler to add to
* @param data data that is being added
*/
void ARC_Handler_Add(ARC_Handler *handler, void *data);
/**
* @brief remove from handler
*
* @note the data that is removed is stored in a trash vector
* the ARC_Handler_Clean function must be called clean the trash vector
* the trash vector is to make sure a state is not deleted while being run
*
* @param handler ARC_Handler to remove from
* @param data data that is being removed
*/
void ARC_Handler_Remove(ARC_Handler *handler, void *data);
/**
* @brief remove from handler
*
* @note the data that is removed is stored in a trash vector
* the ARC_Handler_Clean function must be called clean the trash vector
* the trash vector is to make sure a state is not deleted while being run
*
* @param handler ARC_Handler to remove from
* @param index index of data that is being removed
*/
void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t *index);
/**
* @brief calls provided function on each element in handler
*
* @param handler ARC_Handler to iterate through
* @param datafn function that will be called on each element of data
*/
void ARC_Handler_Iterate(ARC_Handler *handler, ARC_Handler_DataFn datafn);
/**
* @brief clears all data from handler and puts it in trash vector
*
* @param handler ARC_Handler to clear data from
*/
void ARC_Handler_Clear(ARC_Handler *handler);
/**
* @brief clears trash from handler
*
* @note cleanfn's main purpose is to help manage memory
*
* @param handler ARC_Handler to remove trash from
* @param cleanfn user provided function to run on trash before clearing from trash vector
* can be null
*/
void ARC_Handler_Clean(ARC_Handler *handler, ARC_Handler_CleanDataFn cleanfn);
/**
* @brief gets size of vector
*
* @param handler ARC_handler to get size from
*/
uint32_t *ARC_Handler_Size(ARC_Handler *handler);
#ifdef __cplusplus
}
#endif
#endif //ARC_STD_HANDLER_H_

121
include/arc/std/hashtable.h Normal file
View file

@ -0,0 +1,121 @@
#ifndef ARC_STD_HASHTABLE_H_
#define ARC_STD_HASHTABLE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stddef.h>
/**
* @brief the arc hashtable data type
*/
typedef struct ARC_Hashtable ARC_Hashtable;
/**
* @brief a node that contains a key-value reference along with a linked list like node
*/
typedef struct ARC_HashtableNode ARC_HashtableNode;
struct ARC_HashtableNode {
void *key;
size_t keysize;
void *data;
ARC_HashtableNode *node;
};
/**
* @brief a hashing function ptr
*
* @param key value to hash
* @param keysize should be sizeof(key) before key is a void ptr
* @param hashval value of hash, does not need to be within range of buckets
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
typedef int32_t (* ARC_Hashtable_Hash)(void *key, size_t *keysize, uint32_t *hashval);
/**
* @brief key comparison function ptr
*
* @param key1 first key
* @param key2 second key
*
* @return 0 on sucess
*/
typedef int32_t (* ARC_Hashtable_KeyCompare)(void *key1, size_t *key1size, void *key2, size_t *key2size);
/**
* @brief callback to allow memory freeing of nodes
*
* @param node node to be destroyed
* @param userdata any data the user wants to access in the callback
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
typedef int32_t (* ARC_HashtableNode_DestroyExternal)(ARC_HashtableNode *node, void *userdata);
/**
* @brief cteates ARC_Hashtable type
*
* @param htable where to store data
* @param bucketsize num of nodes to create in inital table
* @param hash hashing function to be used, if set to NULL, CRC32 will be used
* @param compare comparison functon for checking keys, if set to NULL, addresses will be compared
*/
void ARC_Hashtable_Create(ARC_Hashtable **htable, uint32_t bucketsize, ARC_Hashtable_Hash hash, ARC_Hashtable_KeyCompare compare);
/**
* @brief destroys ARC_Hashtable type
*
* @param htable htable that will be destroyed
* @param external function to allow external freeing of nodes, can be NULL
* @param userdata any data the user wants access to in the callback
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_Hashtable_Destroy(ARC_Hashtable *htable, ARC_HashtableNode_DestroyExternal external, void *userdata);
/**
* @brief adds value to hastable
*
* @param htable ARC_Hashtable to add to
* @param key key for node that is being added
* @param keysize sizeof key before it is passed into a void *
* @param data data for node that is being added
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_Hashtable_Add(ARC_Hashtable *htable, void *key, size_t keysize, void *data);
/**
* @brief gets value from hashtable by key
*
* @param htable table to get value from
* @param key key to get value from table
* @param keysize sizeof key before it is passed into a void *
* @param data data retrieved from table
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_Hashtable_Get(ARC_Hashtable *htable, void *key, size_t keysize, void **data);
/**
* @brief removes value from hashtable
*
* @param htable ARC_Hashtable to remove from
* @param key key of data to remove from hash table
* @param keysize sizeof key before it is passed into a void *
* @param external function to allow external freeing of data, can be NULL
* @param userdata any data the user wants access to in the callback
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_Hashtable_Remove(ARC_Hashtable *htable, void *key, size_t keysize, ARC_HashtableNode_DestroyExternal external, void *userdata);
#ifdef __cplusplus
}
#endif
#endif //ARC_STD_HASHTABLE_H_

26
include/arc/std/io.h Normal file
View file

@ -0,0 +1,26 @@
#ifndef ARC_STD_IO_H_
#define ARC_STD_IO_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/**
* @brief get string and size from file
*
* @param path a string to path of target file
* @param data pointer to where string will be created
* this will need to be freed once done using it
* @param size size of string
*
* @return int 0 on success, ARC_ERRNO_ on fail
*/
int32_t ARC_IO_FileToStr(const char *path, char **data, uint64_t *size);
#ifdef __cplusplus
}
#endif
#endif //ARC_STD_IO_H_

104
include/arc/std/string.h Normal file
View file

@ -0,0 +1,104 @@
#ifndef ARC_STD_STRING_H_
#define ARC_STD_STRING_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/**
* @brief substring position within a string
*/
typedef struct ARC_StringSubstr {
uint64_t index;
uint64_t length;
} ARC_StringSubstr;
/**
* @brief substring position within a string, stored as 4 bytes
*/
typedef struct ARC_StringSubstr32_t {
uint32_t index;
uint32_t length;
} ARC_StringSubstr32_t;
/**
* @brief substring position within a string, stored as 1 byte
*/
typedef struct ARC_StringSubstr8_t {
uint8_t index;
uint8_t length;
} ARC_StringSubstr8_t;
/**
* @brief checks if string is alphabetic
*
* @param val string to check
* @param length length of string to check
*
* @return 1 if alphabetic, 0 if not alphabetic
*/
uint8_t ARC_String_Alpha(char *val, uint64_t length);
/**
* @brief converst substring from string to uint64_t
*
* @param data string to get substring from
* @param substr substring to convert to long
*
* @return uint64_t converted number
*/
uint64_t ARC_String_ToUint64_t(const char *data, ARC_StringSubstr *substr);
/**
* @brief takes a given string, and assigns index and length for position of first matching substring
*
* @param data the string to find substring in
* @param substr the string to find
* @param index the index of substring within the string will be ~uint64_t if not found
*
* @return int ARC_ERRNO_ error code
*/
int32_t ARC_String_Find(char *data, char *substr, uint64_t *index);
/**
* @brief takes a given string, and assigns index and length for position of last matching substring
*
* @param data the string to find substring in
* @param substr the string to find
* @param index the index of substring within the string will be ~uint64_t if not found
*
* @return int ARC_ERRNO_ error code
*/
int32_t ARC_String_FindBack(char *data, char *substr, uint64_t *index);
/**
* @brief strips the ends based on a given substing
*
* @param data the string to find the substring in
* @param substr the substring to strip ends by, defaults to " " if NULL
* @param subdata the substring of data, will use given substring data, or strlen if length == 0
* also will hold the return values
*
* @return int ARC_ERRNO_ error code
*/
int32_t ARC_StringSubstr_StripEnds(char *data, char *substr, ARC_StringSubstr *subdata);
/**
* @brief strips the ends based on a given substing
*
* @param data the string to find the substring in
* @param substr the substring to strip ends by, defaults to " " if NULL
* @param subdata the substring of data, will use given substring data, or strlen if length == 0
* also will hold the return values
*
* @return int ARC_ERRNO_ error code
*/
int32_t ARC_StringSubstr_StripWhitespaceEnds(char *data, ARC_StringSubstr *subdata);
#ifdef __cplusplus
}
#endif
#endif //ARC_STD_STRING_H_

82
include/arc/std/vector.h Normal file
View file

@ -0,0 +1,82 @@
#ifndef ARC_STD_VECTOR_H_
#define ARC_STD_VECTOR_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/**
* @brief a dynamic array type
*/
typedef struct ARC_Vector ARC_Vector;
/**
* @brief data comparison function ptr
*
* @param a first data struct
* @param b second data struct
*
* @return 0 when a == b
*/
typedef int8_t (* ARC_Vector_CompareDataFn)(void *a, void *b);
/**
* @brief creates ARC_Vector type
*
* @param config ARC_Vector to initialize
*/
void ARC_Vector_Create(ARC_Vector **vector, uint32_t dataSize);
/**
* @brief destroyes ARC_Vector type
*/
void ARC_Vector_Destroy(ARC_Vector *vector);
/**
* @brief adds value to vector
*
* @param vector ARC_Vector to add to
* @param data data that is being added
*/
void ARC_Vector_Add(ARC_Vector *vector, void *data);
/**
* @brief remove from ARC_Vector
*
* @param vector ARC_Vector to remove from
* @param data data that is being removed
*/
void ARC_Vector_Remove(ARC_Vector *vector, void *data, ARC_Vector_CompareDataFn compare);
/**
* @brief remove from ARC_Vector
*
* @param vector ARC_Vector to remove from
* @param index index of data that is being removed
*/
void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t *index);
/**
* @brief gets size of vector
*
* @param vector ARC_Vector to get size from
*/
uint32_t *ARC_Vector_Size(ARC_Vector *vector);
/**
* @brief gets data from ARC_Vector at position index
*
* @param vector ARC_Vector to get data from
* @param index position of data in ARC_Vector
*
* @return pointer to data on success, NULL on fail
*/
void *ARC_Vector_Get(ARC_Vector *vector, uint32_t *index);
#ifdef __cplusplus
}
#endif
#endif //ARC_STD_VECTOR_H_