Compare commits

...

5 Commits

  1. 12
      configfile.c
  2. 71
      configmodel.c
  3. 19
      containers/stringarray.c
  4. 3
      containers/stringarray.h
  5. 21
      smakefile

@ -68,10 +68,12 @@ CONFIGFILEPTR ConfigFileRead(BPTR configFile)
UBYTE buffer[256]; UBYTE buffer[256];
if(NameFromFH(configFile, buffer, 256))// if we opened with a filename this is a waste, if not its necessary if(NameFromFH(configFile, buffer, 256))// if we opened with a filename this is a waste, if not its necessary
{ {
int bufferlen = strlen(buffer);
result = AllocVec(sizeof(struct ConfigFile), MEMF_CLEAR); result = AllocVec(sizeof(struct ConfigFile), MEMF_CLEAR);
result->sectionStore = SectionStoreNew(); result->sectionStore = SectionStoreNew();
result->filename = AllocVec(strlen(buffer)+1, MEMF_CLEAR); result->filename = AllocVec(bufferlen+1, 0L);
CopyMem(buffer, result->filename, strlen(buffer)); CopyMem(buffer, result->filename, bufferlen);
result->filename[bufferlen] = '\0';
while( (line = configFileReadLine(configFile)) != NULL ) while( (line = configFileReadLine(configFile)) != NULL )
{ {
SectionStoreAddLineToCurrentSection(result->sectionStore, line); SectionStoreAddLineToCurrentSection(result->sectionStore, line);
@ -133,8 +135,10 @@ STRPTR ConfigFileGet(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey)
if( var != NULL ) if( var != NULL )
{ {
CONST_STRPTR value = VariableGetRawValue(var); CONST_STRPTR value = VariableGetRawValue(var);
result = AllocVec(strlen(value)+1, MEMF_CLEAR); int valuelen = strlen(value);
CopyMem(value, result, strlen(value)); result = AllocVec(valuelen+1, 0L);
CopyMem(value, result, valuelen);
result[valuelen] = '\0';
} }
StringArrayFree(split, TRUE); StringArrayFree(split, TRUE);
} }

@ -42,9 +42,11 @@ LINEPTR LineNew(CONST_STRPTR buffer)
struct Line* result = NULL; struct Line* result = NULL;
if( buffer != 0 ) if( buffer != 0 )
{ {
int bufferlen = strlen(buffer);
result = AllocVec(sizeof(struct Line), MEMF_CLEAR); result = AllocVec(sizeof(struct Line), MEMF_CLEAR);
result->rawText = AllocVec(strlen(buffer)+1, MEMF_CLEAR); result->rawText = AllocVec(bufferlen+1, 0L);
CopyMem(buffer, result->rawText, strlen(buffer)); CopyMem(buffer, result->rawText, bufferlen);
result->rawText[bufferlen] = '\0';
} }
return result; return result;
} }
@ -242,17 +244,19 @@ SECTIONPTR SectionCreateWithNameAndSubname(CONST_STRPTR primary, CONST_STRPTR se
if( primary != NULL ) if( primary != NULL )
{ {
ULONG length = strlen(primary); int primarylen = strlen(primary);
int secondarylen = secondary ? strlen(secondary) : 0;
result = AllocVec(sizeof(struct Section), MEMF_CLEAR); result = AllocVec(sizeof(struct Section), MEMF_CLEAR);
result->insertPos = 0; result->insertPos = 0;
result->primary = AllocVec(length+1, MEMF_CLEAR); result->primary = AllocVec(primarylen+1, 0L);
CopyMem(primary, (STRPTR)result->primary, length); CopyMem(primary, (STRPTR)result->primary, primarylen);
((STRPTR)result->primary)[primarylen] = '\0';
if( secondary != NULL && strlen(secondary) > 0 ) if( secondary != NULL && secondarylen > 0 )
{ {
ULONG length = strlen(secondary); result->secondary = AllocVec(secondarylen+1, 0L);
result->secondary = AllocVec(length+1, MEMF_CLEAR); CopyMem(secondary, (STRPTR)result->secondary, secondarylen);
CopyMem(secondary, (STRPTR)result->secondary, length); ((STRPTR)result->secondary)[secondarylen] = '\0';
} }
result->lines = LineArrayNew(); result->lines = LineArrayNew();
@ -327,8 +331,10 @@ VOID SectionCollectLinesForVariable(SECTIONPTR abstractSection, CONST_STRPTR var
{ {
ULONG lineCount = SizeOfArray(section->lines); ULONG lineCount = SizeOfArray(section->lines);
ULONG index = 0; ULONG index = 0;
STRPTR normalizedKey = AllocVec(strlen(varKey)+1, MEMF_CLEAR); int varKeylen = strlen(varKey);
CopyMem(varKey, normalizedKey, strlen(varKey)); STRPTR normalizedKey = AllocVec(varKeylen+1, 0L);
CopyMem(varKey, normalizedKey, varKeylen);
normalizedKey[varKeylen] = '\0';
downcaseString(normalizedKey); downcaseString(normalizedKey);
for( index = 0; index < lineCount; index++ ) for( index = 0; index < lineCount; index++ )
@ -356,8 +362,10 @@ VOID SectionRemoveLinesForVariable(SECTIONPTR abstractSection, CONST_STRPTR varK
ULONG index = 0; ULONG index = 0;
ULONG newInsertPos = 0; ULONG newInsertPos = 0;
LineArray newLineArray = LineArrayNew(); LineArray newLineArray = LineArrayNew();
STRPTR normalizedKey = AllocVec(strlen(varKey)+1, MEMF_CLEAR); int varKeylen = strlen(varKey);
CopyMem(varKey, normalizedKey, strlen(varKey)); STRPTR normalizedKey = AllocVec(varKeylen+1, 0L);
CopyMem(varKey, normalizedKey, varKeylen);
normalizedKey[varKeylen] = '\0';
downcaseString(normalizedKey); downcaseString(normalizedKey);
for( index = 0; index < lineCount; index++ ) for( index = 0; index < lineCount; index++ )
@ -423,7 +431,7 @@ CONST_STRPTR SectionSerialize(SECTIONPTR abstractSection)
} }
size += 2; // ]\n size += 2; // ]\n
result = AllocVec(size+1, MEMF_CLEAR); result = AllocVec(size+1, 0L);
if( section->secondary == NULL ) if( section->secondary == NULL )
{ {
sprintf(result, "[%s]\n", section->primary); sprintf(result, "[%s]\n", section->primary);
@ -482,7 +490,7 @@ CONST_STRPTR SectionCanonicalName(SECTIONPTR abstractSection)
totalLength += secondaryLength; totalLength += secondaryLength;
} }
result = AllocVec(totalLength+1, MEMF_CLEAR); result = AllocVec(totalLength+1, 0L);
CopyMem(section->primary, result, primaryLength); CopyMem(section->primary, result, primaryLength);
if( secondaryLength > 0 ) if( secondaryLength > 0 )
@ -504,19 +512,22 @@ VARIABLEPTR VariableCreate(CONST_STRPTR key, CONST_STRPTR rawValue)
struct Variable* result = NULL; struct Variable* result = NULL;
if( key != NULL ) if( key != NULL )
{ {
ULONG length = strlen(key); int keylen = strlen(key);
result = AllocVec(sizeof(struct Variable), MEMF_CLEAR); result = AllocVec(sizeof(struct Variable), MEMF_CLEAR);
result->key = AllocVec(length+1, MEMF_CLEAR); result->key = AllocVec(keylen+1, 0L);
CopyMem(key, (STRPTR)result->key, length); CopyMem(key, (STRPTR)result->key, keylen);
result->normalizedKey = AllocVec(length+1, MEMF_CLEAR); ((STRPTR)result->key)[keylen] = '\0';
CopyMem(key, (STRPTR)result->normalizedKey, length); result->normalizedKey = AllocVec(keylen+1, 0L);
CopyMem(key, (STRPTR)result->normalizedKey, keylen);
((STRPTR)result->normalizedKey)[keylen] = '\0';
downcaseString((STRPTR)result->normalizedKey); downcaseString((STRPTR)result->normalizedKey);
} }
if( rawValue != NULL ) if( rawValue != NULL )
{ {
ULONG length = strlen(rawValue); int rawValuelen = strlen(rawValue);
result->stringValue = AllocVec(length+1, MEMF_CLEAR); result->stringValue = AllocVec(rawValuelen+1, 0L);
CopyMem(rawValue, (STRPTR)result->stringValue, length); CopyMem(rawValue, (STRPTR)result->stringValue, rawValuelen);
((STRPTR)result->stringValue)[rawValuelen] = '\0';
} }
return result; return result;
} }
@ -573,7 +584,7 @@ CONST_STRPTR VariableSerialize(VARIABLEPTR abstractVariable)
if( variable != NULL && variable->normalizedKey != NULL && variable->stringValue != NULL ) if( variable != NULL && variable->normalizedKey != NULL && variable->stringValue != NULL )
{ {
ULONG size = 1 + strlen(variable->normalizedKey) + 3 + strlen(variable->stringValue) + 1 + 1; ULONG size = 1 + strlen(variable->normalizedKey) + 3 + strlen(variable->stringValue) + 1 + 1;
result = AllocVec(size, MEMF_CLEAR); result = AllocVec(size, 0L);
sprintf(result, "\t%s = %s\n", variable->normalizedKey, variable->stringValue); sprintf(result, "\t%s = %s\n", variable->normalizedKey, variable->stringValue);
} }
return (CONST_STRPTR)result; return (CONST_STRPTR)result;
@ -592,8 +603,10 @@ StringArray CompoundKeySplitKeyCompletely(CONST_STRPTR key)
STRPTR token = NULL; STRPTR token = NULL;
// we need to make a copy of the key because strtok modifies it. // we need to make a copy of the key because strtok modifies it.
STRPTR keyCopy = AllocVec(strlen(key)+1, MEMF_CLEAR); int keylen = strlen(key);
CopyMem(key, keyCopy, strlen(key)); STRPTR keyCopy = AllocVec(keylen+1, 0L);
CopyMem(key, keyCopy, keylen);
keyCopy[keylen] = '\0';
token = strtok(keyCopy, "."); token = strtok(keyCopy, ".");
while (token != NULL) while (token != NULL)
@ -650,8 +663,10 @@ StringArray CompoundKeySplitKeyForVar(CONST_STRPTR key)
STRPTR token = NULL; STRPTR token = NULL;
// we need to make a copy of the key because strtok modifies it. // we need to make a copy of the key because strtok modifies it.
STRPTR keyCopy = AllocVec(strlen(key)+1, MEMF_CLEAR); int keylen = strlen(key);
CopyMem(key, keyCopy, strlen(key)); STRPTR keyCopy = AllocVec(keylen+1, 0L);
CopyMem(key, keyCopy, keylen);
keyCopy[keylen] = '\0';
token = strtok(keyCopy, "."); token = strtok(keyCopy, ".");
while (token != NULL) while (token != NULL)

@ -19,8 +19,10 @@ VOID StringArrayAppend(StringArray array, CONST_STRPTR value)
VOID StringArrayAppendAndRetain(StringArray array, CONST_STRPTR value) VOID StringArrayAppendAndRetain(StringArray array, CONST_STRPTR value)
{ {
STRPTR localCopy = AllocVec(strlen(value)+1, MEMF_CLEAR); int valuelen = strlen(value);
CopyMem(value, localCopy, strlen(value)); STRPTR localCopy = AllocVec(valuelen+1, 0L);
CopyMem(value, localCopy, valuelen);
localCopy[valuelen] = '\0';
StringArrayAppend(array, localCopy); StringArrayAppend(array, localCopy);
} }
@ -30,7 +32,7 @@ VOID StringArrayFree(StringArray array, BOOL freeStrings)
{ {
if( freeStrings ) if( freeStrings )
{ {
StringArrayForEach(array, FreeVec(aString);); StringArrayForEach(array, FreeVec((STRPTR)aString););
} }
DeleteArray(array); DeleteArray(array);
} }
@ -59,18 +61,17 @@ STRPTR StringArrayJoinedParts(StringArray array, BYTE linkCharacter, ULONG start
} }
requiredSize += (maxParts == 0 ? 0 : maxParts - 1); // add the join characters requiredSize += (maxParts == 0 ? 0 : maxParts - 1); // add the join characters
requiredSize += 1; // trailing NULL result = AllocVec(requiredSize+1, MEMF_CLEAR);
result = AllocVec(requiredSize, MEMF_CLEAR);
for( index = startIndex; index < lastIndex; index++ ) for( index = startIndex; index < lastIndex; index++ )
{ {
CONST_STRPTR entry = StringArrayValues(array)[index]; CONST_STRPTR entry = StringArrayValues(array)[index];
CopyMem((STRPTR)entry, result+cursor, strlen(entry)); int entrylen = strlen(entry);
cursor += strlen(entry); CopyMem((STRPTR)entry, result+cursor, entrylen);
cursor += entrylen;
result[cursor] = linkCharacter; result[cursor] = linkCharacter;
cursor += 1; cursor += 1;
} }
result[requiredSize-1] = '\0'; result[requiredSize] = '\0';
return result; return result;
} }

@ -14,7 +14,6 @@ CONST_STRPTR* StringArrayValues(StringArray array);
STRPTR StringArrayJoined(StringArray array, BYTE linkCharacter); STRPTR StringArrayJoined(StringArray array, BYTE linkCharacter);
STRPTR StringArrayJoinedParts(StringArray array, BYTE linkCharacter, ULONG startIndex, ULONG maxParts); STRPTR StringArrayJoinedParts(StringArray array, BYTE linkCharacter, ULONG startIndex, ULONG maxParts);
#define StringArrayForEach(array, block) do {STRPTR *afe_123_p = (*(STRPTR **)array); STRPTR aString = *afe_123_p; int afe_123_c = (((ULONG *)array)[1]);\ #define StringArrayForEach(array, block) ArrayForEach(CONST_STRPTR, aString, array, block)
for (; afe_123_c--; aString = *(++afe_123_p)) block} while (0);
#endif #endif

@ -6,13 +6,12 @@
NAME = configreader NAME = configreader
CFLAGS = debug fullflush
LFLAGS = addsym smallcode smalldata noicons batch LFLAGS = addsym smallcode smalldata noicons batch
LIBS = lib:sc.lib lib:amiga.lib lib:debug.lib LIBS = lib:sc.lib lib:amiga.lib lib:debug.lib
############################################################################### ###############################################################################
$(NAME) : main.o configfile.lib configfile.h $(NAME) : main.o configfile.lib
slink lib:c.o main.o to $(NAME) noicons lib $(LIBS) configfile.lib $(LFLAGS) slink lib:c.o main.o to $(NAME) noicons lib $(LIBS) configfile.lib $(LFLAGS)
configfile.lib : configfile.o configmodel.o sectionstore.o cregex/pattern.o cregex/cregex_compile.o cregex/cregex_parse.o cregex/cregex_vm.o containers/stringarray.o containers/linearray.o containers/sectionarray.o containers/sectionmap.o configfile.lib : configfile.o configmodel.o sectionstore.o cregex/pattern.o cregex/cregex_compile.o cregex/cregex_parse.o cregex/cregex_vm.o containers/stringarray.o containers/linearray.o containers/sectionarray.o containers/sectionmap.o
@ -25,24 +24,24 @@ configfile.lib : configfile.o configmodel.o sectionstore.o cregex/pattern.o creg
# JOIN containers/stringarray.o containers/linearray.o containers/sectionarray.o containers/sectionmap.o AS containers/containers.lib # JOIN containers/stringarray.o containers/linearray.o containers/sectionarray.o containers/sectionmap.o AS containers/containers.lib
clean: clean:
delete \#?.o containers/\#?.o cregex/\#?.o $(NAME) ALL QUIET delete \#?.o $(NAME) ALL QUIET
cleanlibs: cleanlibs:
delete configfile.lib containers/\#?.o cregex/\#?.o ALL QUIET delete configfile.lib containers/\#?.o cregex/\#?.o ALL QUIET
############################################################################### ###############################################################################
main.o : main.c main.o : main.c configfile.h configmodel.h types.h containers/stringarray.h containers/linearray.h
configmodel.o : configmodel.c configmodel.h types.h configmodel.o : configmodel.c configmodel.h types.h containers/linearray.h containers/sectionarray.h containers/stringarray.h
configfile.o : configfile.c configfile.h types.h configfile.o : configfile.c configfile.h configmodel.h types.h sectionstore.h
sectionstore.o : sectionstore.c sectionstore.h types.h sectionstore.o : sectionstore.c configfile.h containers/sectionmap.h containers/sectionarray.h containers/stringarray.h containers/linearray.h cregex/pattern.h sectionstore.h
cregex/cregex_compile.o : cregex/cregex_compile.c cregex/cregex.h cregex/cregex_compile.o : cregex/cregex_compile.c cregex/cregex.h
cregex/cregex_parse.o : cregex/cregex_parse.c cregex/cregex.h cregex/cregex_parse.o : cregex/cregex_parse.c cregex/cregex.h
cregex/cregex_vm.o : cregex/cregex_vm.c cregex/cregex.h cregex/cregex_vm.o : cregex/cregex_vm.c cregex/cregex.h
cregex/pattern.o : cregex/pattern.c cregex/pattern.h cregex/cregex.h cregex/pattern.o : cregex/pattern.c cregex/pattern.h cregex/cregex.h containers/stringarray.h
containers/stringarray.o : containers/stringarray.c containers/stringarray.h types.h containers/stringarray.o : containers/stringarray.c containers/stringarray.h types.h
containers/linearray.o : containers/linearray.c containers/linearray.h types.h containers/linearray.o : containers/linearray.c containers/linearray.h configmodel.h types.h
containers/sectionarray.o : containers/sectionarray.c containers/sectionarray.h types.h containers/sectionarray.o : containers/sectionarray.c containers/sectionarray.h configmodel.h types.h
containers/sectionmap.o : containers/sectionmap.c containers/sectionmap.h types.h containers/sectionmap.o : containers/sectionmap.c containers/sectionmap.h configmodel.h types.h

Loading…
Cancel
Save