Loading...
Searching...
No Matches
config.c
Go to the documentation of this file.
#include "arc/audio/config.h"
#include "audio.h"
#include <stdlib.h>
#include "arc/std/config.h"
#include "arc/std/errno.h"
#include "arc/audio/audio.h"
// #define ARC_DEFAULT_CONFIG
#include "arc/std/defaults/config.h"
void ARC_AudioConfig_Init(ARC_Config *config){
ARC_Config_AddKeyCString(config, (char *)"ARC_Audio", 9, ARC_Audio_Read, ARC_Audio_Delete);
}
uint8_t ARC_Audio_Read(ARC_Config *config, ARC_String *string, void **value){
ARC_Config_Get(config, string, value);
if(*value){
return 1;
}
if(string->data[0] != '"' || string->data[string->length - 1] != '"'){
ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("in ARC_Point_Read(config, string, value); no matching quotes: %s", string->data);
arc_errno = ARC_ERRNO_DATA;
return 0;
}
ARC_Audio *audio = (ARC_Audio *)malloc(sizeof(ARC_Audio));
ARC_String *path;
ARC_String_CopySubstring(&path, string, 1, string->length - 2);
audio->chunk = Mix_LoadWAV(path->data);
//TODO: get error message if not loaded
*value = (void *)audio;
return 0;
}
void ARC_Audio_Delete(ARC_Config* config, ARC_String *string, void *value){
Mix_FreeChunk(((ARC_Audio *)value)->chunk);
free((ARC_Audio *)value);
}
config.h
errno.h
arc_errno
int32_t arc_errno
Definition errno.c:5
ARC_DEBUG_LOG_ERROR_WITH_VARIABLES
#define ARC_DEBUG_LOG_ERROR_WITH_VARIABLES(STR,...)
Definition errno.h:40
ARC_ERRNO_DATA
#define ARC_ERRNO_DATA
Definition errno.h:7
audio.h
audio.h
ARC_Audio_Read
uint8_t ARC_Audio_Read(ARC_Config *config, ARC_String *string, void **value)
Definition config.c:16
ARC_Audio_Delete
void ARC_Audio_Delete(ARC_Config *config, ARC_String *string, void *value)
Definition config.c:40
ARC_AudioConfig_Init
void ARC_AudioConfig_Init(ARC_Config *config)
Definition config.c:12
config.h
ARC_Config_AddKeyCString
void ARC_Config_AddKeyCString(ARC_Config *config, const char *type, uint64_t length, ARC_ConfigKeyRead keyRead, ARC_ConfigKeyDelete keyDelete)
adds a key from a cstring
Definition config.c:55
ARC_Config_Get
void ARC_Config_Get(ARC_Config *config, ARC_String *keyname, void **value)
get a value from a given keyname
Definition config.c:124
config.h
ARC_String_CopySubstring
void ARC_String_CopySubstring(ARC_String **substring, ARC_String *original, uint64_t start, uint64_t length)
copy a subtring from a givin ARC_String
Definition string.c:72
ARC_Audio
Definition audio.h:6
ARC_Audio::chunk
Mix_Chunk * chunk
Definition audio.h:7
ARC_Config
Definition config.c:13
ARC_String
substring position within a string
Definition string.h:14
ARC_String::length
uint64_t length
Definition string.h:16
ARC_String::data
char * data
Definition string.h:15