started working on chemical (arc config), also removed files/config as that is now handled by parser/csv
This commit is contained in:
parent
8496ea4a40
commit
4b59d5c062
4 changed files with 15 additions and 162 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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_
|
||||
|
|
@ -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 <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
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);
|
||||
}
|
||||
55
temp.txt
55
temp.txt
|
|
@ -1,48 +1,19 @@
|
|||
<configLanguage> -> <configLanguageBody> EOF
|
||||
<language> -> <group> <language> | <variableLine> <language> | <whitespace> <language>
|
||||
|
||||
<configLanguageBody> -> <configPreDefines> <configComment> <configGroup> <configFunction> <configFunctionCall> <configVariableLine> <configLanguageBody> | LAMBDA
|
||||
<configPreDefines> -> <preDefines> | LAMBDA
|
||||
<configComment> -> <comment> | LAMBDA
|
||||
<configGroup> -> <group> | LAMBDA
|
||||
<configFunction> -> <function> | LAMBDA
|
||||
<configFunctionCall> -> <functionCall> | LAMBDA
|
||||
<configVariableLine> -> <variableLine> | LAMBDA
|
||||
<group> -> <groupName> <whitespace> <variable> <whitespace> LEFT_CURLY_BRACE <whitespace> <variableLine> <whitespace> RIGHT_CURLY_BRACE
|
||||
|
||||
<preDefines> -> HASH <preDefineRule>
|
||||
<preDefineRule> -> <preDefineInclude> | <preDefineExclude>
|
||||
<variableLine> -> <type> <whitespace> <variable> <whitespace> EQUALS <whitespace> value <whitespace> SEMICOLON <whitespace>
|
||||
|
||||
<comment> -> <commentSingleLine> | <commentMultiLine>
|
||||
<commentSingleLine> -> SLASH SLASH <commentContents> | NEWLINE
|
||||
<commentMultiLine> -> SLASH ASTERISK <commentContents> ASTERISK SLASH
|
||||
<commentContents> -> STRING <commentContents> | LAMBDA
|
||||
<groupName> -> <variable>
|
||||
<type> -> <variable>
|
||||
<value> -> <variable> | <number> | <nestedValue>
|
||||
<nestedValue> -> OPEN_CURLY_BRACE <whitespace> <valueArgs> <whitespace> CLOSE_CURLY_BRACE
|
||||
<valueArgs> -> <value> | <value> COMMA <valueArgs>
|
||||
|
||||
<group> -> <groupName> LEFT_CURLY_BRACE <configLanguage> RIGHT_CURLY_BRACE
|
||||
<groupRef> -> <parameter> COLON COLON <parameter>
|
||||
<variable> -> ALPHA_UPPER_CHAR <variableName> | ALPHA_LOWER_CHAR <variableName> | UNDERSCORE <variableName>
|
||||
<variableName> -> <charOrNum> <variableName> | LAMBDA
|
||||
<charOrNum> -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE | NUM
|
||||
|
||||
<function> -> <parameter> LEFT_PAREN <parameterList> RIGHT_PAREN LEFT_CURLY_BRACE <configLanguage> RIGHT_CURLY_BRACE
|
||||
<parameterList> -> <type> <parameter> <parameterListItem> | LAMBDA
|
||||
<parameterListItem> -> COMMA <type> <parameter> <parameterListItem> | LAMBDA
|
||||
<number> -> NUMBER <number> | NUMBER LAMBDA
|
||||
|
||||
<variableLine> -> <variableCreate> <variable> EQUALS <variableData> SEMICOLON
|
||||
<variableCreate> -> <type> | LAMBDA
|
||||
<variableData> -> <equation> | <variableOption>
|
||||
<equation> -> <equationFormula> | <encapsulation>
|
||||
<equationFormula> -> <equationData> SYMBOL <equationData>
|
||||
<equationData> -> LEFT_PAREN <equation> RIGHT_PAREN | <data>
|
||||
<variableOption> -> <data> | <dataList>
|
||||
<data> -> <variable> | <value>
|
||||
<dataList> -> LEFT_CURLY_BRACE <variableData> <dataListItem> RIGHT_CURLY_BRACE SEMICOLON
|
||||
<dataListItem> -> COMMA <variableData> <dataListItem> | LAMBDA
|
||||
|
||||
<functionCall> -> <functionName> LEFT_PAREN <valueList> <RIGHT_PAREN> SEMICOLON
|
||||
<valueList> -> <value> <valueListItem>
|
||||
<valueListItem> -> COMMA <value> <valueListItem>
|
||||
|
||||
<groupName> -> <variable>
|
||||
<functionName> -> <variable>
|
||||
<type> -> <variable>
|
||||
|
||||
<value> -> <variable> | NUM
|
||||
<variable> -> CHAR <variableName>
|
||||
<variableName> -> <charOrNum> <variableName> | LAMBDA
|
||||
<charOrNum> -> CHAR | NUM
|
||||
<whitespace> -> SPACE <whitespace> | TAB <whitespace> | NEWLINE <whitespace> | LAMBDA
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue