From 663dab64edd56a877a4d36fdfa374e161890e899 Mon Sep 17 00:00:00 2001 From: Alan Francis Date: Tue, 21 Nov 2023 21:12:41 +0000 Subject: [PATCH] Canonical name --- configmodel.c | 29 +++++++++++++++++++++++++++++ configmodel.h | 3 ++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/configmodel.c b/configmodel.c index e1200a5..2818dcb 100644 --- a/configmodel.c +++ b/configmodel.c @@ -192,12 +192,16 @@ VOID LineDump(LINEPTR abstractLine) else if( line->variable == NULL && line->section != NULL ) { struct Section* section = (struct Section*)LineGetSection(abstractLine); + CONST_STRPTR canonical = NULL; Printf("(new section %s", section->primary); if( section->secondary ) { Printf("[%s]", section->secondary); } Printf(")\n"); + canonical = SectionCanonicalName(section); + Printf("...((%s))...\n", canonical); + FreeVec((STRPTR)canonical); } else { @@ -350,6 +354,31 @@ VOID SectionFree(SECTIONPTR abstractSection) } } +CONST_STRPTR SectionCanonicalName(SECTIONPTR abstractSection) +{ + struct Section* section = (struct Section*)abstractSection; + STRPTR result = NULL; + if(section != NULL) + { + ULONG primaryLength = 0; + ULONG secondaryLength = 0; + if(section->primary != NULL) + { + primaryLength = strlen(section->primary); + } + if(section->secondary != NULL) + { + secondaryLength = strlen(section->secondary); + } + result = AllocVec(primaryLength+1+secondaryLength+1, MEMF_CLEAR); + CopyMem(section->primary, result, primaryLength); + result[primaryLength] = '.'; + CopyMem(section->secondary, result+primaryLength+1, secondaryLength); + } + return result; +} + + VARIABLEPTR VariableCreate(CONST_STRPTR key, CONST_STRPTR rawValue) { struct Variable* result = NULL; diff --git a/configmodel.h b/configmodel.h index 61512da..f43fb9b 100644 --- a/configmodel.h +++ b/configmodel.h @@ -22,7 +22,8 @@ CONST_STRPTR LineGetRawText(LINEPTR line); SECTIONPTR SectionCreateWithName(CONST_STRPTR primary); SECTIONPTR SectionCreateWithNameAndSubname(CONST_STRPTR primary, CONST_STRPTR secondary); -VOID SectionFree(SECTIONPTR abstractSection); +VOID SectionFree(SECTIONPTR section); +CONST_STRPTR SectionCanonicalName(SECTIONPTR section); VARIABLEPTR VariableCreate(CONST_STRPTR key, CONST_STRPTR rawValue); VOID VariableFree(VARIABLEPTR abstractVariable);