From 4b59d5c062066c8ae5a6951aa069527a3226ec7e Mon Sep 17 00:00:00 2001 From: herbglitch Date: Sun, 22 Dec 2024 23:31:31 -0700 Subject: [PATCH] started working on chemical (arc config), also removed files/config as that is now handled by parser/csv --- CMakeLists.txt | 5 +- include/arc/files/config.h | 17 ------- src/files/config.c | 100 ------------------------------------- temp.txt | 55 +++++--------------- 4 files changed, 15 insertions(+), 162 deletions(-) delete mode 100644 include/arc/files/config.h delete mode 100644 src/files/config.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c78e13..167d0bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,7 @@ set(ARCHEUS_STD_LINK_LIBRARIES # ~ ARCHEUS_SOURCES ~ # set(ARCHEUS_STD_SOURCES - src/std/config.c + src/std/chemical.c src/std/errno.c src/std/handler.c src/std/hashtable.c @@ -81,8 +81,6 @@ set(ARCHEUS_STD_SOURCES src/math/rectangle.c src/math/vector2.c - src/files/config.c - src/engine/engine.c src/engine/state.c ) @@ -130,6 +128,7 @@ if(ARCHEUS_STD_TESTS) add_executable(tests tests/test.c + tests/std/chemical.c #tests/std/vector.c #tests/std/lexer.c #tests/std/parser.c diff --git a/include/arc/files/config.h b/include/arc/files/config.h deleted file mode 100644 index f1f4d2d..0000000 --- a/include/arc/files/config.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef ARC_FILES_CONFIG_H_ -#define ARC_FILES_CONFIG_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "arc/std/config.h" -#include "arc/graphics/renderer.h" - -void ARC_FilesConfig_Init(ARC_Config *config); - -#ifdef __cplusplus -} -#endif - -#endif // !ARC_FILES_CONFIG_H_ \ No newline at end of file diff --git a/src/files/config.c b/src/files/config.c deleted file mode 100644 index e97594f..0000000 --- a/src/files/config.c +++ /dev/null @@ -1,100 +0,0 @@ -#include "arc/files/config.h" -#include "arc/std/io.h" -#include "arc/std/errno.h" -#include "arc/std/string.h" -#include "arc/std/array.h" -#include -#include - -uint8_t ARC_CSV_Read(ARC_Config *config, ARC_String *string, void **value); - -void ARC_CSV_Delete(ARC_Config *config, ARC_String *string, void *value); - -void ARC_FilesConfig_Init(ARC_Config *config){ - ARC_Config_AddKeyCString(config, (char *)"CSV", 3, ARC_CSV_Read, ARC_CSV_Delete); -} - -uint8_t ARC_CSV_Read(ARC_Config *config, ARC_String *string, void **value){ - ARC_Config_Get(config, string, value); - if(*value){ - return 1; - } - - ARC_String *fileData; - ARC_IO_FileToStr(string, &fileData); - if(arc_errno){ - ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_CSV_Read(config, string, value) could not read in csv file: \"%s\"", string->data); - ARC_String_Destroy(fileData); - return 0; - } - - uint32_t height = 0; - for(uint32_t i = 0; i < fileData->length; i++){ - if(fileData->data[i] == '\n'){ - height++; - } - } - - *value = malloc(sizeof(ARC_Array)); - ((ARC_Array *)*value)->data = malloc(sizeof(ARC_Array *) * height); - ((ARC_Array *)*value)->size = height; - - uint32_t index = 0; - for(uint32_t y = 0; y < height; y++){ - uint32_t width = 0; - uint32_t x = 0; - - for(uint32_t i = index; i < fileData->length; i++){ - if(fileData->data[i] == ','){ - width++; - } - - if(fileData->data[i] == '\n'){ - width++; - break; - } - } - - if(!width){ - arc_errno = ARC_ERRNO_DATA; - ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_CSV_Read(config, string, value) no width of line %d", y); - ARC_String_Destroy(fileData); - return 0; - } - - ((ARC_Array **)((ARC_Array *)*value)->data)[y] = (ARC_Array *) malloc(sizeof(ARC_Array)); - ((ARC_Array **)((ARC_Array *)*value)->data)[y]->data = malloc(sizeof(int32_t ) * width); - ((ARC_Array **)((ARC_Array *)*value)->data)[y]->size = width; - - for(uint32_t i = index; i < fileData->length; i++){ - if(fileData->data[i] != ',' && fileData->data[i] != '\n'){ - continue; - } - ARC_String *indexValueString; - ARC_String_CopySubstring(&indexValueString, fileData, index, i - index); - index = i + 1; - - ((int32_t *)((ARC_Array **)((ARC_Array *)*value)->data)[y]->data)[x] = (int32_t)ARC_String_ToInt64_t(indexValueString); - ARC_String_Destroy(indexValueString); - x++; - - if(fileData->data[i] == '\n'){ - index = i + 1; - break; - } - } - } - - return 0; -} - -void ARC_CSV_Delete(ARC_Config *config, ARC_String *string, void *value){ - ARC_Array *valueArray = value; - for(uint32_t i = 0; i < valueArray->size; i++){ - free((int32_t *)((ARC_Array **)valueArray->data)[i]->data); - free((ARC_Array *)((ARC_Array **)valueArray->data)[i]); - } - - free((ARC_Array **)valueArray->data); - free(valueArray); -} \ No newline at end of file diff --git a/temp.txt b/temp.txt index 153c754..00671ca 100644 --- a/temp.txt +++ b/temp.txt @@ -1,48 +1,19 @@ - -> EOF + -> | | - -> | LAMBDA - -> | LAMBDA - -> | LAMBDA - -> | LAMBDA - -> | LAMBDA - -> | LAMBDA - -> | LAMBDA + -> LEFT_CURLY_BRACE RIGHT_CURLY_BRACE - -> HASH - -> | + -> EQUALS value SEMICOLON - -> | - -> SLASH SLASH | NEWLINE - -> SLASH ASTERISK ASTERISK SLASH - -> STRING | LAMBDA + -> + -> + -> | | + -> OPEN_CURLY_BRACE CLOSE_CURLY_BRACE + -> | COMMA - -> LEFT_CURLY_BRACE RIGHT_CURLY_BRACE - -> COLON COLON + -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE + -> | LAMBDA + -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE | NUM - -> LEFT_PAREN RIGHT_PAREN LEFT_CURLY_BRACE RIGHT_CURLY_BRACE - -> | LAMBDA - -> COMMA | LAMBDA + -> NUMBER | NUMBER LAMBDA - -> EQUALS SEMICOLON - -> | LAMBDA - -> | - -> | - -> SYMBOL - -> LEFT_PAREN RIGHT_PAREN | - -> | - -> | - -> LEFT_CURLY_BRACE RIGHT_CURLY_BRACE SEMICOLON - -> COMMA | LAMBDA - - -> LEFT_PAREN SEMICOLON - -> - -> COMMA - - -> - -> - -> - - -> | NUM - -> CHAR - -> | LAMBDA - -> CHAR | NUM + -> SPACE | TAB | NEWLINE | LAMBDA