diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2020-04-23 15:55:03 +0200 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2020-04-23 15:59:48 +0200 |
| commit | 340d597440f27ac7c7ad7a9493cc7cad46ba48c5 (patch) | |
| tree | af746826786e26a96369381f6a427597e1270473 /src | |
| parent | 2288b901243d626b106fb45293d39d32006b04aa (diff) | |
| download | cc4group-340d597440f27ac7c7ad7a9493cc7cad46ba48c5.tar.gz cc4group-340d597440f27ac7c7ad7a9493cc7cad46ba48c5.zip | |
Add cc4group.setEntryNameMatchingCallback
Diffstat (limited to 'src')
| -rw-r--r-- | src/cc4group.c | 11 | ||||
| -rw-r--r-- | src/cc4group.h | 13 | ||||
| -rw-r--r-- | src/cppc4group.cpp | 5 | ||||
| -rw-r--r-- | src/cppc4group.hpp | 3 |
4 files changed, 31 insertions, 1 deletions
diff --git a/src/cc4group.c b/src/cc4group.c index cb37064..ad840f0 100644 --- a/src/cc4group.c +++ b/src/cc4group.c @@ -266,6 +266,9 @@ static void cc4group_copyErrorInformation(const CC4Group* const src, CC4Group* c static const CC4Group_WarningCallback cc4group_defaultWarningCallback = cc4group_printToStderrWarningCallback; static CC4Group_WarningCallback cc4group_warn = cc4group_defaultWarningCallback; +static const CC4Group_EntryNameMatchingCallback cc4group_defaultEntryNameMatchingCallback = strcmp; +static CC4Group_EntryNameMatchingCallback cc4group_namecmp = cc4group_defaultEntryNameMatchingCallback; + #define AddCleanUpJob(func, data) CleanUpJobListPrepend(this->cleanupJobs, (CC4Group_CleanupJob){(CC4Group_CleanupFunc)func, data}); static void memScrambleHeader(uint8_t* const data) @@ -1958,7 +1961,7 @@ static GroupEntryListEntry* cc4group_getChildListEntryByPath(CC4Group* const thi bool found = false; ForeachGroupEntry(children) { - if(strcmp(entry->value.core.FileName, part) == 0) + if(cc4group_namecmp(part, entry->value.core.FileName) == 0) { currentParent = &entry->value; listEntry = entry; @@ -2296,6 +2299,11 @@ static void cc4group_setWarningCallback(const CC4Group_WarningCallback warningCa cc4group_warn = (warningCallback == NULL) ? cc4group_defaultWarningCallback : warningCallback; } +static void cc4group_setEntryNameMatchingCallback(const CC4Group_EntryNameMatchingCallback matchingCallback) +{ + cc4group_namecmp = (matchingCallback == NULL) ? cc4group_defaultEntryNameMatchingCallback : matchingCallback; +} + static const char* cc4group_getErrorMessage(CC4Group* const this) { assert(this); @@ -3450,6 +3458,7 @@ CC4Group_API cc4group = { .setTmpMemoryStrategy = cc4group_setTmpMemoryStrategy, .setWarningCallback = cc4group_setWarningCallback, + .setEntryNameMatchingCallback = cc4group_setEntryNameMatchingCallback, .new = cc4group_new, diff --git a/src/cc4group.h b/src/cc4group.h index 4bcec34..25f3c53 100644 --- a/src/cc4group.h +++ b/src/cc4group.h @@ -180,6 +180,12 @@ typedef bool (*CC4Group_WriteCallback)(const void* const data, size_t const size typedef void (*CC4Group_WarningCallback)(const CC4Group* const group, const char* const format, ...); +// callback type for entry name matching +// must return 0 on match, non-zero otherwise +// query is the querying string passed in by the application, name is the candidate name +// query will be path-components of the actually queried path, determined by '/' +typedef int (*CC4Group_EntryNameMatchingCallback)(const char* query, const char* name); + // this is the main API struct of cc4group // it contains all available methods and constants typedef struct { @@ -225,6 +231,12 @@ typedef struct { // this will affect all groups in any state void (*setWarningCallback)(const CC4Group_WarningCallback callback); + // sets the global entry name comparison callback + // strcmp is the default callback; it can be restored by calling setEntryNameMatchingCallback with callback as NULL + // NOTE: this is a static method (i.e. it is used without any object) + // this will affect all groups in any state + void (*setEntryNameMatchingCallback)(const CC4Group_EntryNameMatchingCallback callback); + // allocates and initializes a new group object, like the operator new // NULL may be returned if the memory allocation (malloc) fails; in this case errno contains additional error information @@ -468,3 +480,4 @@ extern CC4Group_API cc4group; #undef new #undef delete #endif + diff --git a/src/cppc4group.cpp b/src/cppc4group.cpp index b30beb7..09a27e1 100644 --- a/src/cppc4group.cpp +++ b/src/cppc4group.cpp @@ -370,6 +370,11 @@ void CppC4Group::setWarningCallback(const CppC4Group::WarningCallback callback) } } +void CppC4Group::setEntryNameMatchingCallback(const CppC4Group::EntryNameMatchingCallback callback) +{ + cc4group.setEntryNameMatchingCallback(callback); +} + bool CppC4Group::setMaker(const std::string& maker, const std::string& path, const bool recursive) { return cc4group.setMaker(p->g, maker.c_str(), path.c_str(), recursive); diff --git a/src/cppc4group.hpp b/src/cppc4group.hpp index 346e8cb..42bef77 100644 --- a/src/cppc4group.hpp +++ b/src/cppc4group.hpp @@ -110,6 +110,7 @@ public: using ReadCallback = bool(*)(const void** const data, size_t* const size, void* const arg); using SetupCallback = bool(*)(void* const arg); using WriteCallback = bool(*)(const void* const data, size_t const size, void* const arg); + using EntryNameMatchingCallback = int(*)(const char* query, const char* name); // but a more practical variant here using WarningCallback = void(*)(const std::string& message); @@ -135,6 +136,8 @@ public: static void setWarningCallback(const WarningCallback callback); + static void setEntryNameMatchingCallback(const EntryNameMatchingCallback callback); + public: // the constructor will automatically construct an internal CC4Group, so no new-equivalent method is needed // may throw std::bad_alloc if the allocation and construction of the internal CC4Group object fails |
