Compare commits

..

No commits in common. '6002ea65bc49d3ad17e92297eeeb459ae114d6e5' and '9b5b255accd6557e6a7759d89e888c9fbe73e6e0' have entirely different histories.

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

@ -68,12 +68,10 @@ CONFIGFILEPTR ConfigFileRead(BPTR configFile)
UBYTE buffer[256];
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->sectionStore = SectionStoreNew();
result->filename = AllocVec(bufferlen+1, 0L);
CopyMem(buffer, result->filename, bufferlen);
result->filename[bufferlen] = '\0';
result->filename = AllocVec(strlen(buffer)+1, MEMF_CLEAR);
CopyMem(buffer, result->filename, strlen(buffer));
while( (line = configFileReadLine(configFile)) != NULL )
{
SectionStoreAddLineToCurrentSection(result->sectionStore, line);
@ -135,10 +133,8 @@ STRPTR ConfigFileGet(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundKey)
if( var != NULL )
{
CONST_STRPTR value = VariableGetRawValue(var);
int valuelen = strlen(value);
result = AllocVec(valuelen+1, 0L);
CopyMem(value, result, valuelen);
result[valuelen] = '\0';
result = AllocVec(strlen(value)+1, MEMF_CLEAR);
CopyMem(value, result, strlen(value));
}
StringArrayFree(split, TRUE);
}

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

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

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

@ -6,12 +6,13 @@
NAME = configreader
CFLAGS = debug fullflush
LFLAGS = addsym smallcode smalldata noicons batch
LIBS = lib:sc.lib lib:amiga.lib lib:debug.lib
###############################################################################
$(NAME) : main.o configfile.lib
$(NAME) : main.o configfile.lib configfile.h
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
@ -24,24 +25,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
clean:
delete \#?.o $(NAME) ALL QUIET
delete \#?.o containers/\#?.o cregex/\#?.o $(NAME) ALL QUIET
cleanlibs:
delete configfile.lib containers/\#?.o cregex/\#?.o ALL QUIET
###############################################################################
main.o : main.c configfile.h configmodel.h types.h containers/stringarray.h containers/linearray.h
configmodel.o : configmodel.c configmodel.h types.h containers/linearray.h containers/sectionarray.h containers/stringarray.h
configfile.o : configfile.c configfile.h configmodel.h types.h sectionstore.h
sectionstore.o : sectionstore.c configfile.h containers/sectionmap.h containers/sectionarray.h containers/stringarray.h containers/linearray.h cregex/pattern.h sectionstore.h
main.o : main.c
configmodel.o : configmodel.c configmodel.h types.h
configfile.o : configfile.c configfile.h types.h
sectionstore.o : sectionstore.c sectionstore.h types.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_vm.o : cregex/cregex_vm.c cregex/cregex.h
cregex/pattern.o : cregex/pattern.c cregex/pattern.h cregex/cregex.h containers/stringarray.h
cregex/pattern.o : cregex/pattern.c cregex/pattern.h cregex/cregex.h
containers/stringarray.o : containers/stringarray.c containers/stringarray.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 configmodel.h types.h
containers/sectionmap.o : containers/sectionmap.c containers/sectionmap.h configmodel.h types.h
containers/linearray.o : containers/linearray.c containers/linearray.h types.h
containers/sectionarray.o : containers/sectionarray.c containers/sectionarray.h types.h
containers/sectionmap.o : containers/sectionmap.c containers/sectionmap.h types.h

Loading…
Cancel
Save