|
|
|
@ -4,11 +4,16 @@ |
|
|
|
|
#include "cregex/cregex.h" |
|
|
|
|
#include "containers/stringarray.h" |
|
|
|
|
#include "containers/linearray.h" |
|
|
|
|
#include "containers/sectionarray.h" |
|
|
|
|
|
|
|
|
|
#include <proto/exec.h> |
|
|
|
|
#include <proto/dos.h> |
|
|
|
|
#include <string.h> |
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#include <ctype.h> |
|
|
|
|
|
|
|
|
|
STATIC VOID downcaseString(STRPTR string); |
|
|
|
|
|
|
|
|
|
#define ZERO ((BPTR)0) |
|
|
|
|
|
|
|
|
@ -37,6 +42,7 @@ struct Variable |
|
|
|
|
{ |
|
|
|
|
enum VariableType type; |
|
|
|
|
CONST_STRPTR key; |
|
|
|
|
CONST_STRPTR normalizedKey; |
|
|
|
|
union
|
|
|
|
|
{ |
|
|
|
|
CONST_STRPTR stringValue; |
|
|
|
@ -120,7 +126,26 @@ StringArray ConfigFileSplitKey(CONST_STRPTR key) |
|
|
|
|
StringArrayAppend(result, sectionPart); // its been alloced so dont copy
|
|
|
|
|
varPart = (STRPTR)ArrayBackValue(STRPTR, parts); |
|
|
|
|
StringArrayAppendAndRetain(result, varPart); // its a reference so copy
|
|
|
|
|
StringArrayFree(parts); |
|
|
|
|
StringArrayFree(parts, TRUE); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
StringArray ConfigFileGetAll(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey) |
|
|
|
|
{ |
|
|
|
|
StringArray result = StringArrayNew(); |
|
|
|
|
ULONG index = 0; |
|
|
|
|
struct ConfigFile* configFile = (struct ConfigFile*)abstractConfigFile; |
|
|
|
|
if( configFile != NULL ) |
|
|
|
|
{ |
|
|
|
|
StringArray split = ConfigFileSplitKey(compoundKey); |
|
|
|
|
VariableArray vars = SectionStoreGetAll(configFile->sectionStore, StringArrayValues(split)[0], StringArrayValues(split)[1]); |
|
|
|
|
for( index = 0; index < SizeOfArray(vars); index++ ) |
|
|
|
|
{ |
|
|
|
|
StringArrayAppendAndRetain(result, VariableGetRawValue(VariableArrayValues(vars)[index])); |
|
|
|
|
} |
|
|
|
|
VariableArrayFree(vars, FALSE); |
|
|
|
|
StringArrayFree(split, TRUE); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -302,6 +327,12 @@ VARIABLEPTR LineGetVariable(LINEPTR abstractLine) |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BOOL LineHasVariable(LINEPTR line, CONST_STRPTR varKey) |
|
|
|
|
{ |
|
|
|
|
VARIABLEPTR var = LineGetVariable(line); |
|
|
|
|
return (BOOL)(var != NULL && VariableHasKey(var, varKey)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VOID LineFree(LINEPTR abstractLine) |
|
|
|
|
{ |
|
|
|
|
struct Line* line = (struct Line*)abstractLine; |
|
|
|
@ -382,6 +413,33 @@ VOID SectionAddLine(SECTIONPTR abstractSection, LINEPTR abstractLine) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VOID SectionCollectLinesForVariable(SECTIONPTR abstractSection, CONST_STRPTR varKey, LineArray collecting) |
|
|
|
|
{ |
|
|
|
|
struct Section* section = (struct Section*)abstractSection; |
|
|
|
|
if( section != NULL ) |
|
|
|
|
{ |
|
|
|
|
ULONG lineCount = SizeOfArray(section->lines); |
|
|
|
|
ULONG index = 0; |
|
|
|
|
STRPTR normalizedKey = AllocVec(strlen(varKey)+1, MEMF_CLEAR); |
|
|
|
|
CopyMem(varKey, normalizedKey, strlen(varKey)); |
|
|
|
|
downcaseString(normalizedKey); |
|
|
|
|
|
|
|
|
|
for( index = 0; index < lineCount; index++ ) |
|
|
|
|
{ |
|
|
|
|
LINEPTR line = LineArrayValues(section->lines)[index]; |
|
|
|
|
if( LineHasVariable(line, normalizedKey) ) |
|
|
|
|
{ |
|
|
|
|
LineArrayAppend(collecting, line); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
FreeVec(normalizedKey);
|
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
Printf("null section\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VOID SectionDump(SECTIONPTR abstractSection) |
|
|
|
|
{ |
|
|
|
|
struct Section* section = (struct Section*)abstractSection; |
|
|
|
@ -449,6 +507,9 @@ VARIABLEPTR VariableCreate(CONST_STRPTR key, CONST_STRPTR rawValue) |
|
|
|
|
result = AllocVec(sizeof(struct Variable), MEMF_CLEAR); |
|
|
|
|
result->key = AllocVec(length+1, MEMF_CLEAR); |
|
|
|
|
CopyMem(key, (STRPTR)result->key, length); |
|
|
|
|
result->normalizedKey = AllocVec(length+1, MEMF_CLEAR); |
|
|
|
|
CopyMem(key, (STRPTR)result->normalizedKey, length); |
|
|
|
|
downcaseString((STRPTR)result->normalizedKey); |
|
|
|
|
} |
|
|
|
|
result->type = TypeString; |
|
|
|
|
if( rawValue != NULL ) |
|
|
|
@ -460,6 +521,29 @@ VARIABLEPTR VariableCreate(CONST_STRPTR key, CONST_STRPTR rawValue) |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CONST_STRPTR VariableGetRawValue(VARIABLEPTR abstractVariable) |
|
|
|
|
{ |
|
|
|
|
struct Variable* variable = (struct Variable*)abstractVariable; |
|
|
|
|
if( variable != NULL ) |
|
|
|
|
{ |
|
|
|
|
return variable->value.stringValue; |
|
|
|
|
} |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BOOL VariableHasKey(VARIABLEPTR abstractVariable, CONST_STRPTR varKey) |
|
|
|
|
{ |
|
|
|
|
struct Variable* variable = (struct Variable*)abstractVariable; |
|
|
|
|
if( variable != NULL ) |
|
|
|
|
{ |
|
|
|
|
if( strcmp(varKey, variable->normalizedKey) == 0 ) |
|
|
|
|
{ |
|
|
|
|
return TRUE; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return FALSE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VOID VariableFree(VARIABLEPTR abstractVariable) |
|
|
|
|
{ |
|
|
|
|
struct Variable* variable = (struct Variable*)abstractVariable; |
|
|
|
@ -469,6 +553,10 @@ VOID VariableFree(VARIABLEPTR abstractVariable) |
|
|
|
|
{ |
|
|
|
|
FreeVec((STRPTR)variable->key); |
|
|
|
|
} |
|
|
|
|
if( variable->normalizedKey != NULL ) |
|
|
|
|
{ |
|
|
|
|
FreeVec((STRPTR)variable->normalizedKey); |
|
|
|
|
} |
|
|
|
|
if( variable->type == TypeString && variable->value.stringValue != NULL ) |
|
|
|
|
{ |
|
|
|
|
FreeVec((STRPTR)variable->value.stringValue); |
|
|
|
@ -478,3 +566,12 @@ VOID VariableFree(VARIABLEPTR abstractVariable) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
STATIC VOID downcaseString(STRPTR string) |
|
|
|
|
{ |
|
|
|
|
BYTE* p = NULL; |
|
|
|
|
for(p=string; *p; p++)
|
|
|
|
|
{ |
|
|
|
|
*p=tolower(*p); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|