ignore the value types for now

main
Alan Francis 1 year ago
parent c31a6365aa
commit 229c2776ed
  1. 38
      configmodel.c
  2. 64
      sectionstore.c

@ -18,24 +18,11 @@ struct Section
ULONG insertPos; // we want to add new entries at end, but before any blanks ULONG insertPos; // we want to add new entries at end, but before any blanks
}; };
enum VariableType
{
TypeBool=0,
TypeInteger=1,
TypeString=2,
};
struct Variable struct Variable
{ {
enum VariableType type;
CONST_STRPTR key; CONST_STRPTR key;
CONST_STRPTR normalizedKey; CONST_STRPTR normalizedKey;
struct CONST_STRPTR stringValue;
{
CONST_STRPTR stringValue;
BOOL boolValue;
LONG longValue;
} value;
}; };
struct Line struct Line
@ -301,18 +288,12 @@ VOID SectionAddLine(SECTIONPTR abstractSection, LINEPTR abstractLine, BOOL addBe
if(!LineIsEmpty(abstractLine) ) if(!LineIsEmpty(abstractLine) )
{ {
section->insertPos = SizeOfArray(section->lines); section->insertPos = SizeOfArray(section->lines);
printf("xx (%s) insertpos = %lu\n", SectionCanonicalName(abstractSection), section->insertPos);
LineDump(abstractLine);
printf("xx\n");
} }
} }
else else
{ {
LineArrayInsert(section->lines, abstractLine, section->insertPos); LineArrayInsert(section->lines, abstractLine, section->insertPos);
section->insertPos += 1; section->insertPos += 1;
printf("yy (%s) insertpos = %lu\n", SectionCanonicalName(abstractSection), section->insertPos);
LineDump(abstractLine);
printf("yy\n");
} }
} }
} }
@ -501,12 +482,11 @@ VARIABLEPTR VariableCreate(CONST_STRPTR key, CONST_STRPTR rawValue)
CopyMem(key, (STRPTR)result->normalizedKey, length); CopyMem(key, (STRPTR)result->normalizedKey, length);
downcaseString((STRPTR)result->normalizedKey); downcaseString((STRPTR)result->normalizedKey);
} }
result->type = TypeString;
if( rawValue != NULL ) if( rawValue != NULL )
{ {
ULONG length = strlen(rawValue); ULONG length = strlen(rawValue);
result->value.stringValue = AllocVec(length+1, MEMF_CLEAR); result->stringValue = AllocVec(length+1, MEMF_CLEAR);
CopyMem(rawValue, (STRPTR)result->value.stringValue, length); CopyMem(rawValue, (STRPTR)result->stringValue, length);
} }
return result; return result;
} }
@ -516,7 +496,7 @@ CONST_STRPTR VariableGetRawValue(VARIABLEPTR abstractVariable)
struct Variable* variable = (struct Variable*)abstractVariable; struct Variable* variable = (struct Variable*)abstractVariable;
if( variable != NULL ) if( variable != NULL )
{ {
return variable->value.stringValue; return variable->stringValue;
} }
return NULL; return NULL;
} }
@ -547,9 +527,9 @@ VOID VariableFree(VARIABLEPTR abstractVariable)
{ {
FreeVec((STRPTR)variable->normalizedKey); FreeVec((STRPTR)variable->normalizedKey);
} }
if( variable->type == TypeString && variable->value.stringValue != NULL ) if( variable->stringValue != NULL )
{ {
FreeVec((STRPTR)variable->value.stringValue); FreeVec((STRPTR)variable->stringValue);
} }
FreeVec(variable); FreeVec(variable);
@ -560,11 +540,11 @@ CONST_STRPTR VariableSerialize(VARIABLEPTR abstractVariable)
{ {
STRPTR result = NULL; STRPTR result = NULL;
struct Variable* variable = (struct Variable*)abstractVariable; struct Variable* variable = (struct Variable*)abstractVariable;
if( variable != NULL && variable->normalizedKey != NULL && variable->value.stringValue != NULL ) if( variable != NULL && variable->normalizedKey != NULL && variable->stringValue != NULL )
{ {
ULONG size = 1 + strlen(variable->normalizedKey) + 3 + strlen(variable->value.stringValue) + 1 + 1; ULONG size = 1 + strlen(variable->normalizedKey) + 3 + strlen(variable->stringValue) + 1 + 1;
result = AllocVec(size, MEMF_CLEAR); result = AllocVec(size, MEMF_CLEAR);
sprintf(result, "\t%s = %s\n", variable->normalizedKey, variable->value.stringValue); sprintf(result, "\t%s = %s\n", variable->normalizedKey, variable->stringValue);
} }
return (CONST_STRPTR)result; return (CONST_STRPTR)result;
} }

@ -19,8 +19,8 @@
STATIC SECTIONPTR parseSection(LINEPTR line, PATTERNPTR sectionPatternProgram); STATIC SECTIONPTR parseSection(LINEPTR line, PATTERNPTR sectionPatternProgram);
STATIC VARIABLEPTR parseVariable(LINEPTR line, PATTERNPTR variablePatternProgram); STATIC VARIABLEPTR parseVariable(LINEPTR line, PATTERNPTR variablePatternProgram);
STATIC BOOL parseBlank(LINEPTR line, PATTERNPTR blankPatternProgram); STATIC BOOL parseBlank(LINEPTR line, PATTERNPTR blankPatternProgram);
STATIC BOOL parseBoolValue(CONST_STRPTR value, BOOL* outBool); //STATIC BOOL parseBoolValue(CONST_STRPTR value, BOOL* outBool);
STATIC BOOL parseIntegerValue(CONST_STRPTR value, LONG* outInt, PATTERNPTR integerProgram); //STATIC BOOL parseIntegerValue(CONST_STRPTR value, LONG* outInt, PATTERNPTR integerProgram);
struct SectionStore struct SectionStore
{ {
@ -275,34 +275,40 @@ STATIC SECTIONPTR parseSection(LINEPTR line, PATTERNPTR sectionPatternProgram)
return result; return result;
} }
STATIC BOOL parseBoolValue(CONST_STRPTR value, BOOL* outBool)
{
BOOL result = FALSE;
if( strcmp(value, "yes") == 0 || strcmp(value, "true") == 0 || strcmp(value, "on") == 0 ) {
*outBool = TRUE;
result = TRUE;
}
if( strcmp(value, "no") == 0 || strcmp(value, "false") == 0 || strcmp(value, "off") == 0 ) {
*outBool = FALSE;
result = TRUE;
}
return result;
}
// TODO I ended up not using these and just having all variable be strings.
STATIC BOOL parseIntegerValue(CONST_STRPTR value, LONG* outInt, PATTERNPTR integerProgram) // The calling code can decide how to parse the strings into ints or bools or whatever
{ // It just seemed like a step too far in complexity to have to decide for each
BOOL result = FALSE; // variable what type it was and then keep track of that when we set, or collect values
StringArray matches = NULL;
// STATIC BOOL parseBoolValue(CONST_STRPTR value, BOOL* outBool)
if( matches = PatternRun(value, integerProgram) ) // {
{ // BOOL result = FALSE;
StringArrayFree(matches, TRUE); // if( strcmp(value, "yes") == 0 || strcmp(value, "true") == 0 || strcmp(value, "on") == 0 ) {
*outInt = atol(value); // *outBool = TRUE;
result = TRUE; // result = TRUE;
} // }
return result; // if( strcmp(value, "no") == 0 || strcmp(value, "false") == 0 || strcmp(value, "off") == 0 ) {
} // *outBool = FALSE;
// result = TRUE;
// }
// return result;
// }
//
//
// STATIC BOOL parseIntegerValue(CONST_STRPTR value, LONG* outInt, PATTERNPTR integerProgram)
// {
// BOOL result = FALSE;
// StringArray matches = NULL;
//
// if( matches = PatternRun(value, integerProgram) )
// {
// StringArrayFree(matches, TRUE);
// *outInt = atol(value);
// result = TRUE;
// }
// return result;
// }
STATIC BOOL parseBlank(LINEPTR line, PATTERNPTR blankPatternProgram) STATIC BOOL parseBlank(LINEPTR line, PATTERNPTR blankPatternProgram)

Loading…
Cancel
Save