From 92c5d41501d3f7b84fb9922d21a0bf5adbbfe497 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Mon, 29 Jul 2024 04:13:15 +0700 Subject: [PATCH 1/4] refactor(developer): make `AddCompileError` void type `AddCompileError` would return FALSE only for 'user interruption' (not used since Developer 17) or for fatal errors. After analysis, it turns out that this error value was not used anywhere and removing it simplifies the error management logic, making code paths much easier to follow. The return value was used in v17.0 and earlier in the macro for `AddCompileWarning`, effectively only relevant for 'user interruption' (`CERR_Break`); this was an ugly code pattern as it meant that any `AddCompileWarning` could exit a function with failure -- though as noted above `CERR_Break` was never emitted in v17.0. --- developer/src/kmcmplib/src/CompilerErrors.cpp | 6 ++---- developer/src/kmcmplib/src/CompilerErrors.h | 2 +- developer/src/kmcmplib/tests/gtest-compiler-test.cpp | 1 - 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/developer/src/kmcmplib/src/CompilerErrors.cpp b/developer/src/kmcmplib/src/CompilerErrors.cpp index 6562db9204..faa336ce46 100644 --- a/developer/src/kmcmplib/src/CompilerErrors.cpp +++ b/developer/src/kmcmplib/src/CompilerErrors.cpp @@ -13,7 +13,7 @@ namespace kmcmp { kmcmp_CompilerMessageProc msgproc = nullptr; } -KMX_BOOL kmcmp::AddCompileWarning(PKMX_CHAR buf) +KMX_BOOL kmcmp::AddCompileWarning(PKMX_CHAR buf) // TODO: Used only for 'compiler version' message, so remove accordingly { KMCMP_COMPILER_RESULT_MESSAGE message; message.errorCode = KmnCompilerMessages::INFO_Info; @@ -23,7 +23,7 @@ KMX_BOOL kmcmp::AddCompileWarning(PKMX_CHAR buf) return FALSE; } -KMX_BOOL AddCompileError(KMX_DWORD msg) +void AddCompileError(KMX_DWORD msg) { KMX_CHAR szText[COMPILE_ERROR_MAX_LEN]; const KMX_CHAR* szTextp = NULL; @@ -38,7 +38,6 @@ KMX_BOOL AddCompileError(KMX_DWORD msg) message.message = szTextp; (*kmcmp::msgproc)(message, msgprocContext); kmcmp::nErrors++; - return TRUE; } if (severity == CompilerErrorSeverity::Error) { @@ -70,5 +69,4 @@ KMX_BOOL AddCompileError(KMX_DWORD msg) message.lineNumber = kmcmp::currentLine + 1; message.message = szText; (*kmcmp::msgproc)(message, msgprocContext); - return FALSE; } diff --git a/developer/src/kmcmplib/src/CompilerErrors.h b/developer/src/kmcmplib/src/CompilerErrors.h index 59bc2317f6..55faf9ba0b 100644 --- a/developer/src/kmcmplib/src/CompilerErrors.h +++ b/developer/src/kmcmplib/src/CompilerErrors.h @@ -12,7 +12,7 @@ namespace kmcmp { extern char ErrExtraLIB[ERR_EXTRA_LIB_LEN]; extern void* msgprocContext; -KMX_BOOL AddCompileError(KMX_DWORD msg); // TODO rename to AddCompileMessage +void AddCompileError(KMX_DWORD msg); // TODO rename to AddCompileMessage /// Use AddWarningBool for functions that return bool or KMX_BOOL; TODO merge with AddCompileMessage #define AddWarningBool(warn) AddCompileError(warn) diff --git a/developer/src/kmcmplib/tests/gtest-compiler-test.cpp b/developer/src/kmcmplib/tests/gtest-compiler-test.cpp index cc6a16afdb..e29b265426 100644 --- a/developer/src/kmcmplib/tests/gtest-compiler-test.cpp +++ b/developer/src/kmcmplib/tests/gtest-compiler-test.cpp @@ -11,7 +11,6 @@ PKMX_WCHAR strtowstr(PKMX_STR in); PKMX_STR wstrtostr(PKMX_WCHAR in); -KMX_BOOL AddCompileError(KMX_DWORD msg); KMX_DWORD ProcessBeginLine(PFILE_KEYBOARD fk, PKMX_WCHAR p); KMX_DWORD ValidateMatchNomatchOutput(PKMX_WCHAR p); KMX_BOOL IsValidKeyboardVersion(KMX_WCHAR *dpString); From 7371c87867bcac42c7d936844004811f4c91cb25 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Mon, 29 Jul 2024 04:18:28 +0700 Subject: [PATCH 2/4] refactor(developer): Move error reporting inside `CheckForDuplicateGroup` `CheckForDuplicateGroup` is one of a few places where parameterized errors are returned. Moving the error reporting inside the function makes it cleaner to refactor those parameterized errors later. (This requires a similar, simple change in `ProcessGroupLine`.) --- developer/src/kmcmplib/src/CheckForDuplicates.cpp | 7 ++++--- developer/src/kmcmplib/src/CheckForDuplicates.h | 2 +- developer/src/kmcmplib/src/CompileKeyboardBuffer.cpp | 3 +-- developer/src/kmcmplib/src/Compiler.cpp | 12 +++++++++--- developer/src/kmcmplib/src/kmcmplib.h | 2 +- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/developer/src/kmcmplib/src/CheckForDuplicates.cpp b/developer/src/kmcmplib/src/CheckForDuplicates.cpp index dc42718b33..e192096b9d 100644 --- a/developer/src/kmcmplib/src/CheckForDuplicates.cpp +++ b/developer/src/kmcmplib/src/CheckForDuplicates.cpp @@ -10,7 +10,7 @@ #include "CheckForDuplicates.h" -KMX_DWORD CheckForDuplicateGroup(PFILE_KEYBOARD fk, PFILE_GROUP gp) noexcept { +KMX_BOOL CheckForDuplicateGroup(PFILE_KEYBOARD fk, PFILE_GROUP gp) noexcept { KMX_DWORD i; PFILE_GROUP gp0 = fk->dpGroupArray; for (i = 0; i < fk->cxGroupArray; i++, gp0++) { @@ -19,10 +19,11 @@ KMX_DWORD CheckForDuplicateGroup(PFILE_KEYBOARD fk, PFILE_GROUP gp) noexcept { } if (u16icmp(gp0->szName, gp->szName) == 0) { snprintf(ErrExtraLIB, ERR_EXTRA_LIB_LEN, " Group '%s' declared on line %d", string_from_u16string(gp->szName).c_str(), gp0->Line); - return KmnCompilerMessages::ERROR_DuplicateGroup; + AddCompileError(KmnCompilerMessages::ERROR_DuplicateGroup); + return FALSE; } } - return STATUS_Success; + return TRUE; } KMX_DWORD CheckForDuplicateStore(PFILE_KEYBOARD fk, PFILE_STORE sp) noexcept { diff --git a/developer/src/kmcmplib/src/CheckForDuplicates.h b/developer/src/kmcmplib/src/CheckForDuplicates.h index 20789dd5e2..42b219397e 100644 --- a/developer/src/kmcmplib/src/CheckForDuplicates.h +++ b/developer/src/kmcmplib/src/CheckForDuplicates.h @@ -1,4 +1,4 @@ #pragma once -KMX_DWORD CheckForDuplicateGroup(PFILE_KEYBOARD fk, PFILE_GROUP gp) noexcept; +KMX_BOOL CheckForDuplicateGroup(PFILE_KEYBOARD fk, PFILE_GROUP gp) noexcept; KMX_DWORD CheckForDuplicateStore(PFILE_KEYBOARD fk, PFILE_STORE sp) noexcept; diff --git a/developer/src/kmcmplib/src/CompileKeyboardBuffer.cpp b/developer/src/kmcmplib/src/CompileKeyboardBuffer.cpp index ffa77eced6..636cd0a976 100644 --- a/developer/src/kmcmplib/src/CompileKeyboardBuffer.cpp +++ b/developer/src/kmcmplib/src/CompileKeyboardBuffer.cpp @@ -90,8 +90,7 @@ bool CompileKeyboardBuffer(KMX_BYTE* infile, int sz, PFILE_KEYBOARD fk) break; case T_GROUP: - if ((msg = ProcessGroupLine(fk, p)) != STATUS_Success) { - AddCompileError(msg); + if (!ProcessGroupLine(fk, p)) { return FALSE; } break; diff --git a/developer/src/kmcmplib/src/Compiler.cpp b/developer/src/kmcmplib/src/Compiler.cpp index b8ab8828b8..75c4e795c5 100644 --- a/developer/src/kmcmplib/src/Compiler.cpp +++ b/developer/src/kmcmplib/src/Compiler.cpp @@ -561,13 +561,16 @@ KMX_DWORD ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str) //********************************************************************************************************************** -KMX_DWORD ProcessGroupLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) +KMX_BOOL ProcessGroupLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) { PFILE_GROUP gp; PKMX_WCHAR q; gp = new FILE_GROUP[fk->cxGroupArray + 1]; - if (!gp) return KmnCompilerMessages::FATAL_CannotAllocateMemory; + if (!gp) { + AddCompileError(KmnCompilerMessages::FATAL_CannotAllocateMemory); + return FALSE; + } if (fk->dpGroupArray) { @@ -585,7 +588,10 @@ KMX_DWORD ProcessGroupLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) gp->cxKeyArray = 0; q = GetDelimitedString(&p, u"()", GDS_CUTLEAD | GDS_CUTFOLL); - if (!q) return KmnCompilerMessages::ERROR_InvalidGroupLine; + if (!q) { + AddCompileError(KmnCompilerMessages::ERROR_InvalidGroupLine); + return FALSE; + } gp->fUsingKeys = FALSE; gp->fReadOnly = IsSameToken(&p, u"readonly"); diff --git a/developer/src/kmcmplib/src/kmcmplib.h b/developer/src/kmcmplib/src/kmcmplib.h index 0fb795c25f..8c36a39054 100644 --- a/developer/src/kmcmplib/src/kmcmplib.h +++ b/developer/src/kmcmplib/src/kmcmplib.h @@ -33,7 +33,7 @@ KMX_DWORD WriteCompiledKeyboard(PFILE_KEYBOARD fk, KMX_BYTE**data, size_t& dataS KMX_DWORD AddStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, const KMX_WCHAR * str, KMX_DWORD *dwStoreID= NULL); KMX_DWORD ReadLine(KMX_BYTE* infile, int sz, int& offset, PKMX_WCHAR wstr, KMX_BOOL PreProcess); KMX_DWORD ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str); -KMX_DWORD ProcessGroupLine(PFILE_KEYBOARD fk, PKMX_WCHAR p); +KMX_BOOL ProcessGroupLine(PFILE_KEYBOARD fk, PKMX_WCHAR p); KMX_DWORD ProcessGroupFinish(PFILE_KEYBOARD fk); KMX_DWORD ProcessStoreLine(PFILE_KEYBOARD fk, PKMX_WCHAR p); int LineTokenType(PKMX_WCHAR *str); From 05fd680a9efec2d1c7bea7340c2e0d33277e0938 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Mon, 29 Jul 2024 04:27:06 +0700 Subject: [PATCH 3/4] refactor(developer): Move error reporting inside `CheckForDuplicateStore` This is the same change as for `CheckForDuplicateGroup`. `CheckForDuplicateStore` is one of a few places where parameterized errors are returned. Moving the error reporting inside the function makes it cleaner to refactor those parameterized errors later. (This requires a similar change in `ProcessStoreLine`, also formatted and rebraced per style guide.) --- .../src/kmcmplib/src/CheckForDuplicates.cpp | 9 ++-- .../src/kmcmplib/src/CheckForDuplicates.h | 2 +- .../kmcmplib/src/CompileKeyboardBuffer.cpp | 3 +- developer/src/kmcmplib/src/Compiler.cpp | 48 +++++++++++-------- developer/src/kmcmplib/src/kmcmplib.h | 2 +- .../kmcmplib/tests/gtest-compiler-test.cpp | 4 +- 6 files changed, 39 insertions(+), 29 deletions(-) diff --git a/developer/src/kmcmplib/src/CheckForDuplicates.cpp b/developer/src/kmcmplib/src/CheckForDuplicates.cpp index e192096b9d..12f4b656a5 100644 --- a/developer/src/kmcmplib/src/CheckForDuplicates.cpp +++ b/developer/src/kmcmplib/src/CheckForDuplicates.cpp @@ -26,11 +26,11 @@ KMX_BOOL CheckForDuplicateGroup(PFILE_KEYBOARD fk, PFILE_GROUP gp) noexcept { return TRUE; } -KMX_DWORD CheckForDuplicateStore(PFILE_KEYBOARD fk, PFILE_STORE sp) noexcept { +KMX_BOOL CheckForDuplicateStore(PFILE_KEYBOARD fk, PFILE_STORE sp) noexcept { if (!sp->szName[0]) { // Stores with zero length names are reserved system stores. // They cannot be defined in user code. This is not an issue. - return STATUS_Success; + return TRUE; } KMX_DWORD i; PFILE_STORE sp0 = fk->dpStoreArray; @@ -40,8 +40,9 @@ KMX_DWORD CheckForDuplicateStore(PFILE_KEYBOARD fk, PFILE_STORE sp) noexcept { } if (u16icmp(sp0->szName, sp->szName) == 0) { snprintf(ErrExtraLIB, ERR_EXTRA_LIB_LEN, " Store '%s' declared on line %d", string_from_u16string(sp0->szName).c_str(), sp0->line); - return KmnCompilerMessages::ERROR_DuplicateStore; + AddCompileError(KmnCompilerMessages::ERROR_DuplicateStore); + return FALSE; } } - return STATUS_Success; + return TRUE; } diff --git a/developer/src/kmcmplib/src/CheckForDuplicates.h b/developer/src/kmcmplib/src/CheckForDuplicates.h index 42b219397e..e338f290f5 100644 --- a/developer/src/kmcmplib/src/CheckForDuplicates.h +++ b/developer/src/kmcmplib/src/CheckForDuplicates.h @@ -1,4 +1,4 @@ #pragma once KMX_BOOL CheckForDuplicateGroup(PFILE_KEYBOARD fk, PFILE_GROUP gp) noexcept; -KMX_DWORD CheckForDuplicateStore(PFILE_KEYBOARD fk, PFILE_STORE sp) noexcept; +KMX_BOOL CheckForDuplicateStore(PFILE_KEYBOARD fk, PFILE_STORE sp) noexcept; diff --git a/developer/src/kmcmplib/src/CompileKeyboardBuffer.cpp b/developer/src/kmcmplib/src/CompileKeyboardBuffer.cpp index 636cd0a976..d195d58a2d 100644 --- a/developer/src/kmcmplib/src/CompileKeyboardBuffer.cpp +++ b/developer/src/kmcmplib/src/CompileKeyboardBuffer.cpp @@ -96,8 +96,7 @@ bool CompileKeyboardBuffer(KMX_BYTE* infile, int sz, PFILE_KEYBOARD fk) break; case T_STORE: - if ((msg = ProcessStoreLine(fk, p)) != STATUS_Success) { - AddCompileError(msg); + if (!ProcessStoreLine(fk, p)) { return FALSE; } break; diff --git a/developer/src/kmcmplib/src/Compiler.cpp b/developer/src/kmcmplib/src/Compiler.cpp index 75c4e795c5..66bc7ec697 100644 --- a/developer/src/kmcmplib/src/Compiler.cpp +++ b/developer/src/kmcmplib/src/Compiler.cpp @@ -675,28 +675,34 @@ KMX_DWORD ProcessGroupFinish(PFILE_KEYBOARD fk) * Store management */ -KMX_DWORD ProcessStoreLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) -{ +KMX_BOOL ProcessStoreLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) { PKMX_WCHAR q, pp; PFILE_STORE sp; - //WCHAR temp[GLOBAL_BUFSIZE]; KMX_DWORD msg; int i = 0; pp = p; - if ((q = GetDelimitedString(&p, u"()", GDS_CUTLEAD | GDS_CUTFOLL)) == NULL) return KmnCompilerMessages::ERROR_InvalidStoreLine; + if ((q = GetDelimitedString(&p, u"()", GDS_CUTLEAD | GDS_CUTFOLL)) == NULL) { + AddCompileError(KmnCompilerMessages::ERROR_InvalidStoreLine); + return FALSE; + } - if (*q == *SSN__PREFIX) - { - for (i = 0; StoreTokens[i]; i++) - if (!u16icmp(q, StoreTokens[i])) // I3481 + if (*q == *SSN__PREFIX) { + for (i = 0; StoreTokens[i]; i++) { + if (!u16icmp(q, StoreTokens[i])) { // I3481 break; - if (!StoreTokens[i]) return KmnCompilerMessages::ERROR_InvalidSystemStore; + } + } + if (!StoreTokens[i]) { + AddCompileError(KmnCompilerMessages::ERROR_InvalidSystemStore); + return FALSE; + } } if(!resizeStoreArray(fk)) { - return KmnCompilerMessages::FATAL_CannotAllocateMemory; + AddCompileError(KmnCompilerMessages::FATAL_CannotAllocateMemory); + return FALSE; } sp = &fk->dpStoreArray[fk->cxStoreArray]; @@ -711,10 +717,10 @@ KMX_DWORD ProcessStoreLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) { PKMX_WCHAR temp = new KMX_WCHAR[GLOBAL_BUFSIZE]; - if ((msg = GetXString(fk, p, u"c\n", temp, GLOBAL_BUFSIZE - 1, (int)(p - pp), &p, FALSE, TRUE)) != STATUS_Success) - { + if ((msg = GetXString(fk, p, u"c\n", temp, GLOBAL_BUFSIZE - 1, (int)(p - pp), &p, FALSE, TRUE)) != STATUS_Success) { delete[] temp; - return msg; + AddCompileError(msg); + return FALSE; } sp->dwSystemID = i; @@ -725,23 +731,27 @@ KMX_DWORD ProcessStoreLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) } if (xstrlen(sp->dpString) == 1 && *sp->dpString != UC_SENTINEL && - sp->dwSystemID == 0 && (fk->version >= VERSION_60 || fk->version == 0)) - { + sp->dwSystemID == 0 && (fk->version >= VERSION_60 || fk->version == 0)) { // In this case, we want to change behaviour for older versioned keyboards so that // we don't mix up named character codes which weren't supported in 5.x VERIFY_KEYBOARD_VERSION(fk, VERSION_60, KmnCompilerMessages::ERROR_60FeatureOnly_NamedCodes); // Add a single char store as a defined character constant - if (Uni_IsSurrogate1(*sp->dpString)) + if (Uni_IsSurrogate1(*sp->dpString)) { kmcmp::CodeConstants->AddCode(Uni_SurrogateToUTF32(sp->dpString[0], sp->dpString[1]), sp->szName, fk->cxStoreArray); - else + } else { kmcmp::CodeConstants->AddCode(sp->dpString[0], sp->szName, fk->cxStoreArray); + } kmcmp::CodeConstants->reindex(); // has to be done after every character add due to possible use in another store. // I4982 } fk->cxStoreArray++; // increment now, because GetXString refers to stores - if (i > 0) - if ((msg = ProcessSystemStore(fk, i, sp)) != STATUS_Success) return msg; + if (i > 0) { + if ((msg = ProcessSystemStore(fk, i, sp)) != STATUS_Success) { + AddCompileError(msg); + return FALSE; + } + } return CheckForDuplicateStore(fk, sp); } diff --git a/developer/src/kmcmplib/src/kmcmplib.h b/developer/src/kmcmplib/src/kmcmplib.h index 8c36a39054..f75246e50c 100644 --- a/developer/src/kmcmplib/src/kmcmplib.h +++ b/developer/src/kmcmplib/src/kmcmplib.h @@ -35,6 +35,6 @@ KMX_DWORD ReadLine(KMX_BYTE* infile, int sz, int& offset, PKMX_WCHAR wstr, KMX_B KMX_DWORD ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str); KMX_BOOL ProcessGroupLine(PFILE_KEYBOARD fk, PKMX_WCHAR p); KMX_DWORD ProcessGroupFinish(PFILE_KEYBOARD fk); -KMX_DWORD ProcessStoreLine(PFILE_KEYBOARD fk, PKMX_WCHAR p); +KMX_BOOL ProcessStoreLine(PFILE_KEYBOARD fk, PKMX_WCHAR p); int LineTokenType(PKMX_WCHAR *str); KMX_DWORD BuildVKDictionary(PFILE_KEYBOARD fk); // I3438 diff --git a/developer/src/kmcmplib/tests/gtest-compiler-test.cpp b/developer/src/kmcmplib/tests/gtest-compiler-test.cpp index e29b265426..56e751cfd6 100644 --- a/developer/src/kmcmplib/tests/gtest-compiler-test.cpp +++ b/developer/src/kmcmplib/tests/gtest-compiler-test.cpp @@ -250,10 +250,10 @@ TEST_F(CompilerTest, ValidateMatchNomatchOutput_test) { }; // KMX_DWORD ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str) -// KMX_DWORD ProcessGroupLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) +// KMX_BOOL ProcessGroupLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) // int kmcmp::cmpkeys(const void *key, const void *elem) // KMX_DWORD ProcessGroupFinish(PFILE_KEYBOARD fk) -// KMX_DWORD ProcessStoreLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) +// KMX_BOOL ProcessStoreLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) // bool resizeStoreArray(PFILE_KEYBOARD fk) // bool resizeKeyArray(PFILE_GROUP gp, int increment) // KMX_DWORD AddStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, const KMX_WCHAR * str, KMX_DWORD *dwStoreID) From bcec4461448f78498cac2b3711081546705b200a Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Mon, 29 Jul 2024 06:21:21 +0700 Subject: [PATCH 4/4] refactor(developer): return KMX_BOOL instead of KMX_DWORD for AddStore() and friends This is definitely a yak shave, but should have payoff in terms of cleaner and more descriptive error messages in the long run. In the existing design, many (but not all) functions return a KMX_DWORD error value, and that is passed on up the call stack to be reported as an error elsewhere. This separation of error reporting from error site makes it difficult to add parameters (and masks the actual error site in analysis). This commit starts to move the error reporting to the actual site of the error, in `AddStore()`, `ProcessSystemStore()`, `ParseLine()`, `AddCompilerVersionStore()`, `BuildVKDictionary()`, and `ProcessBeginLine()`. During analysis, identified a memory leak (missing `delete[] temp`) in `process_if()`. Fixed on line 2716. Many of the `process_*()` functions call `AddStore()`, which is now responsible for reporting its own errors; these functions have not yet been updated and so if `AddStore()` fails, the compiler will generate two error messages -- one from `AddStore()` and a second one in the value returned from the calling `process_*()` function. The `VERIFY_KEYBOARD_VERSION` macro hides a `return` statement which returned an error code on failure. This has been split into `VERIFY_KEYBOARD_VERSION_ret` which causes the caller to returns the error code, and the existing `VERIFY_KEYBOARD_VERSION` macro now causes the caller to return `FALSE` on failure. This should be refactored to move the `return` condition into the caller (removing the `return` side-effect) in the future. --- .../kmcmplib/src/CompileKeyboardBuffer.cpp | 25 +- developer/src/kmcmplib/src/Compiler.cpp | 397 ++++++++++++------ developer/src/kmcmplib/src/kmcmplib.h | 8 +- developer/src/kmcmplib/src/versioning.h | 8 + .../kmcmplib/tests/gtest-compiler-test.cpp | 50 ++- 5 files changed, 331 insertions(+), 157 deletions(-) diff --git a/developer/src/kmcmplib/src/CompileKeyboardBuffer.cpp b/developer/src/kmcmplib/src/CompileKeyboardBuffer.cpp index d195d58a2d..4ad51080ec 100644 --- a/developer/src/kmcmplib/src/CompileKeyboardBuffer.cpp +++ b/developer/src/kmcmplib/src/CompileKeyboardBuffer.cpp @@ -66,12 +66,18 @@ bool CompileKeyboardBuffer(KMX_BYTE* infile, int sz, PFILE_KEYBOARD fk) if(kmcmp::FShouldAddCompilerVersion) { u16sprintf(str,LINESIZE, L"Created with Keyman Developer version %d.%d.%d.%d", KEYMAN_VersionMajor, KEYMAN_VersionMinor, KEYMAN_VersionPatch, 0); - AddStore(fk, TSS_KEYMANCOPYRIGHT, str); + if(!AddStore(fk, TSS_KEYMANCOPYRIGHT, str)) { + return FALSE; + } } /* Add a system store for the Keyman edition number */ - AddStore(fk, TSS_CUSTOMKEYMANEDITION, u"0"); - AddStore(fk, TSS_CUSTOMKEYMANEDITIONNAME, u"Keyman"); + if(!AddStore(fk, TSS_CUSTOMKEYMANEDITION, u"0")) { + return FALSE; + } + if(!AddStore(fk, TSS_CUSTOMKEYMANEDITIONNAME, u"Keyman")) { + return FALSE; + } int offset = 0; @@ -83,8 +89,7 @@ bool CompileKeyboardBuffer(KMX_BYTE* infile, int sz, PFILE_KEYBOARD fk) { case T_VERSION: *(p + 4) = 0; - if ((msg = AddStore(fk, TSS_VERSION, p)) != STATUS_Success) { - AddCompileError(msg); + if (!AddStore(fk, TSS_VERSION, p)) { return FALSE; } break; @@ -121,9 +126,7 @@ bool CompileKeyboardBuffer(KMX_BYTE* infile, int sz, PFILE_KEYBOARD fk) /* ReadLine will automatically skip over $Keyman lines, and parse wrapped lines */ while ((msg = ReadLine(infile, sz, offset, str, FALSE)) == STATUS_Success) { - msg = ParseLine(fk, str); - if (msg != STATUS_Success) { - AddCompileError(msg); + if(!ParseLine(fk, str)) { return FALSE; } } @@ -138,13 +141,11 @@ bool CompileKeyboardBuffer(KMX_BYTE* infile, int sz, PFILE_KEYBOARD fk) if (kmcmp::FSaveDebug) kmcmp::RecordDeadkeyNames(fk); /* Add the compiler version as a system store */ - if ((msg = kmcmp::AddCompilerVersionStore(fk)) != STATUS_Success) { - AddCompileError(msg); + if (!kmcmp::AddCompilerVersionStore(fk)) { return FALSE; } - if ((msg = BuildVKDictionary(fk)) != STATUS_Success) { - AddCompileError(msg); + if (!BuildVKDictionary(fk)) { return FALSE; } diff --git a/developer/src/kmcmplib/src/Compiler.cpp b/developer/src/kmcmplib/src/Compiler.cpp index 66bc7ec697..ac8c96b559 100644 --- a/developer/src/kmcmplib/src/Compiler.cpp +++ b/developer/src/kmcmplib/src/Compiler.cpp @@ -152,7 +152,7 @@ KMX_DWORD ImportBitmapFile(PFILE_KEYBOARD fk, PKMX_WCHAR szName, PKMX_DWORD File KMX_DWORD ExpandKp(PFILE_KEYBOARD fk, PFILE_KEY kpp, KMX_DWORD storeIndex); int GetVKCode(PFILE_KEYBOARD fk, PKMX_WCHAR p); // I3438 // TODO: Consolidate GetDeadKey and GetVKCode? -KMX_DWORD ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE sp); +KMX_BOOL ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE sp); KMX_DWORD process_if(PFILE_KEYBOARD fk, PKMX_WCHAR q, PKMX_WCHAR tstr, int *mx); KMX_DWORD process_reset(PFILE_KEYBOARD fk, PKMX_WCHAR q, PKMX_WCHAR tstr, int *mx); @@ -265,8 +265,7 @@ PKMX_STR wstrtostr(PKMX_WCHAR in) } -KMX_DWORD ProcessBeginLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) -{ +KMX_BOOL ProcessBeginLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) { KMX_WCHAR tstr[128]; PKMX_WCHAR q, pp; int BeginMode; @@ -274,30 +273,42 @@ KMX_DWORD ProcessBeginLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) pp = p; - q = ( PKMX_WCHAR) u16chr(p, '>'); - if (!q) return KmnCompilerMessages::ERROR_NoTokensFound; + q = (PKMX_WCHAR) u16chr(p, '>'); + if (!q) { + AddCompileError(KmnCompilerMessages::ERROR_NoTokensFound); + return FALSE; + } while (iswspace(*p)) p++; if (u16nicmp(p, u"unicode", 7) == 0) BeginMode = BEGIN_UNICODE; else if (u16nicmp(p, u"ansi", 4) == 0) BeginMode = BEGIN_ANSI; else if (u16nicmp(p, u"newContext", 10) == 0) BeginMode = BEGIN_NEWCONTEXT; else if (u16nicmp(p, u"postKeystroke", 13) == 0) BeginMode = BEGIN_POSTKEYSTROKE; - else if (*p != '>') return KmnCompilerMessages::ERROR_InvalidToken; + else if (*p != '>') { + AddCompileError(KmnCompilerMessages::ERROR_InvalidToken); + return FALSE; + } else BeginMode = BEGIN_ANSI; if(kmcmp::BeginLine[BeginMode] != -1) { - return KmnCompilerMessages::ERROR_RepeatedBegin; + AddCompileError(KmnCompilerMessages::ERROR_RepeatedBegin); + return FALSE; } kmcmp::BeginLine[BeginMode] = kmcmp::currentLine; - if ((msg = GetRHS(fk, p, tstr, 80, (int)(p - pp), FALSE)) != STATUS_Success) return msg; + if ((msg = GetRHS(fk, p, tstr, 80, (int)(p - pp), FALSE)) != STATUS_Success) { + AddCompileError(msg); + return FALSE; + } if (tstr[0] != UC_SENTINEL || tstr[1] != CODE_USE) { - return KmnCompilerMessages::ERROR_InvalidBegin; + AddCompileError(KmnCompilerMessages::ERROR_InvalidBegin); + return FALSE; } if (tstr[3] != 0) { - return KmnCompilerMessages::ERROR_InvalidToken; + AddCompileError(KmnCompilerMessages::ERROR_InvalidToken); + return FALSE; } if (BeginMode == BEGIN_ANSI || BeginMode == BEGIN_UNICODE) { @@ -310,20 +321,18 @@ KMX_DWORD ProcessBeginLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) /* Record a system store for the line number of the begin statement */ AddDebugStore(fk, BeginMode == BEGIN_UNICODE ? DEBUGSTORE_BEGIN u"Unicode" : DEBUGSTORE_BEGIN u"ANSI"); } - } - else { - PFILE_GROUP gp = &fk->dpGroupArray[tstr[2] - 1]; - if (!gp->fReadOnly) { - return BeginMode == BEGIN_NEWCONTEXT ? - KmnCompilerMessages::ERROR_NewContextGroupMustBeReadonly : - KmnCompilerMessages::ERROR_PostKeystrokeGroupMustBeReadonly; - } - return AddStore(fk, BeginMode == BEGIN_NEWCONTEXT ? TSS_BEGIN_NEWCONTEXT : TSS_BEGIN_POSTKEYSTROKE, tstr, NULL); + } else { + PFILE_GROUP gp = &fk->dpGroupArray[tstr[2] - 1]; + if (!gp->fReadOnly) { + AddCompileError(BeginMode == BEGIN_NEWCONTEXT ? + KmnCompilerMessages::ERROR_NewContextGroupMustBeReadonly : + KmnCompilerMessages::ERROR_PostKeystrokeGroupMustBeReadonly); + return FALSE; } + return AddStore(fk, BeginMode == BEGIN_NEWCONTEXT ? TSS_BEGIN_NEWCONTEXT : TSS_BEGIN_POSTKEYSTROKE, tstr, NULL); + } - - - return STATUS_Success; + return TRUE; } KMX_DWORD ValidateMatchNomatchOutput(PKMX_WCHAR p) { @@ -341,8 +350,7 @@ KMX_DWORD ValidateMatchNomatchOutput(PKMX_WCHAR p) { return STATUS_Success; } -KMX_DWORD ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str) -{ +KMX_BOOL ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str) { PKMX_WCHAR p, q, pp; PFILE_GROUP gp; KMX_DWORD msg; @@ -364,49 +372,73 @@ KMX_DWORD ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str) case T_BEGIN: // after a begin can be "Unicode" or "ANSI" or nothing (=ANSI) - if ((msg = ProcessBeginLine(fk, p)) != STATUS_Success) return msg; + if (!ProcessBeginLine(fk, p)) { + return FALSE; + } break; case T_GROUP: - if (fk->currentGroup == 0xFFFFFFFF) fk->currentGroup = 0; - else - { - if ((msg = ProcessGroupFinish(fk)) != STATUS_Success) return msg; // finish off previous group first? + if (fk->currentGroup == 0xFFFFFFFF) { + fk->currentGroup = 0; + } else { + if ((msg = ProcessGroupFinish(fk)) != STATUS_Success) { + AddCompileError(msg); + return FALSE; // finish off previous group first? + } fk->currentGroup++; } - // if( (err = ProcessGroupLine( fk, p )) != STATUS_Success ) return err; break; case T_NAME: kmcmp::WarnDeprecatedHeader(); // I4866 q = GetDelimitedString(&p, u"\"\"", 0); - if (!q) return KmnCompilerMessages::ERROR_InvalidName; + if (!q) { + AddCompileError(KmnCompilerMessages::ERROR_InvalidName); + return FALSE; + } - if ((msg = AddStore(fk, TSS_NAME, q)) != STATUS_Success) return msg; + if (!AddStore(fk, TSS_NAME, q)) { + return FALSE; + } break; case T_COPYRIGHT: kmcmp::WarnDeprecatedHeader(); // I4866 q = GetDelimitedString(&p, u"\"\"", 0); - if (!q) return KmnCompilerMessages::ERROR_InvalidCopyright; + if (!q) { + AddCompileError(KmnCompilerMessages::ERROR_InvalidCopyright); + return FALSE; + } - if ((msg = AddStore(fk, TSS_COPYRIGHT, q)) != STATUS_Success) return msg; + if (!AddStore(fk, TSS_COPYRIGHT, q)) { + return FALSE; + } break; case T_MESSAGE: kmcmp::WarnDeprecatedHeader(); // I4866 q = GetDelimitedString(&p, u"\"\"", 0); - if (!q) return KmnCompilerMessages::ERROR_InvalidMessage; + if (!q) { + AddCompileError(KmnCompilerMessages::ERROR_InvalidMessage); + return FALSE; + } - if ((msg = AddStore(fk, TSS_MESSAGE, q)) != STATUS_Success) return msg; + if (!AddStore(fk, TSS_MESSAGE, q)) { + return FALSE; + } break; case T_LANGUAGENAME: kmcmp::WarnDeprecatedHeader(); // I4866 q = GetDelimitedString(&p, u"\"\"", 0); - if (!q) return KmnCompilerMessages::ERROR_InvalidLanguageName; + if (!q) { + AddCompileError(KmnCompilerMessages::ERROR_InvalidLanguageName); + return FALSE; + } - if ((msg = AddStore(fk, TSS_LANGUAGENAME, q)) != STATUS_Success) return msg; + if (!AddStore(fk, TSS_LANGUAGENAME, q)) { + return FALSE; + } break; case T_LANGUAGE: @@ -415,7 +447,9 @@ KMX_DWORD ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str) KMX_WCHAR *tokcontext = NULL; q = u16tok(p, p_sep, &tokcontext); // I3481 - if ((msg = AddStore(fk, TSS_LANGUAGE, q)) != STATUS_Success) return msg; + if (!AddStore(fk, TSS_LANGUAGE, q)) { + return FALSE; + } break; } case T_LAYOUT: @@ -423,46 +457,67 @@ KMX_DWORD ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str) kmcmp::WarnDeprecatedHeader(); // I4866 KMX_WCHAR *tokcontext = NULL; q = u16tok(p, p_sep, &tokcontext); // I3481 - if ((msg = AddStore(fk, TSS_LAYOUT, q)) != STATUS_Success) return msg; + if (!AddStore(fk, TSS_LAYOUT, q)) { + return FALSE; + } break; } case T_CAPSOFF: kmcmp::WarnDeprecatedHeader(); // I4866 - if ((msg = AddStore(fk, TSS_CAPSALWAYSOFF, u"1")) != STATUS_Success) return msg; + if (!AddStore(fk, TSS_CAPSALWAYSOFF, u"1")) { + return FALSE; + } break; case T_CAPSON: kmcmp::WarnDeprecatedHeader(); // I4866 - if ((msg = AddStore(fk, TSS_CAPSONONLY, u"1")) != STATUS_Success) return msg; + if (!AddStore(fk, TSS_CAPSONONLY, u"1")) { + return FALSE; + } break; case T_SHIFT: kmcmp::WarnDeprecatedHeader(); // I4866 - if ((msg = AddStore(fk, TSS_SHIFTFREESCAPS, u"1")) != STATUS_Success) return msg; + if (!AddStore(fk, TSS_SHIFTFREESCAPS, u"1")) { + return FALSE; + } break; case T_HOTKEY: { kmcmp::WarnDeprecatedHeader(); // I4866 KMX_WCHAR *tokcontext = NULL; - if ((q = u16tok(p, p_sep, &tokcontext)) == NULL) return KmnCompilerMessages::ERROR_CodeInvalidInThisSection; // I3481 - if ((msg = AddStore(fk, TSS_HOTKEY, q)) != STATUS_Success) return msg; + if ((q = u16tok(p, p_sep, &tokcontext)) == NULL) { + AddCompileError(KmnCompilerMessages::ERROR_CodeInvalidInThisSection); // I3481 + return FALSE; + } + if (!AddStore(fk, TSS_HOTKEY, q)) { + return FALSE; + } break; } case T_BITMAP: { kmcmp::WarnDeprecatedHeader(); // I4866 KMX_WCHAR *tokcontext = NULL; - if ((q = u16tok(p, p_sep, &tokcontext)) == NULL) return KmnCompilerMessages::ERROR_InvalidBitmapLine; // I3481 + if ((q = u16tok(p, p_sep, &tokcontext)) == NULL) { + AddCompileError(KmnCompilerMessages::ERROR_InvalidBitmapLine); // I3481 + return FALSE; + } while (iswspace(*q)) q++; if (*q == '"') { p = q; q = GetDelimitedString(&p, u"\"\"", 0); - if (!q) return KmnCompilerMessages::ERROR_InvalidBitmapLine; + if (!q) { + AddCompileError(KmnCompilerMessages::ERROR_InvalidBitmapLine); + return FALSE; + } } - if ((msg = AddStore(fk, TSS_BITMAP, q)) != STATUS_Success) return msg; + if (!AddStore(fk, TSS_BITMAP, q)) { + return FALSE; + } break; } case T_BITMAPS: @@ -471,31 +526,49 @@ KMX_DWORD ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str) KMX_WCHAR *tokcontext = NULL; AddWarning(KmnCompilerMessages::WARN_BitmapNotUsed); - if ((q = u16tok(p, p_sep, &tokcontext)) == NULL) return KmnCompilerMessages::ERROR_InvalidBitmapLine; // I3481 + if ((q = u16tok(p, p_sep, &tokcontext)) == NULL) { + AddCompileError(KmnCompilerMessages::ERROR_InvalidBitmapLine); // I3481 + return FALSE; + } - if ((PKMX_WCHAR) u16chr(q, ',')) *(PKMX_WCHAR) u16chr(q, ',') = 0; - if ((msg = AddStore(fk, TSS_BITMAP, q)) != STATUS_Success) return msg; + if ((PKMX_WCHAR) u16chr(q, ',')) { + *(PKMX_WCHAR) u16chr(q, ',') = 0; + } + if (!AddStore(fk, TSS_BITMAP, q)) { + return FALSE; + } break; } case T_KEYTOKEY: // A rule - if (fk->currentGroup == 0xFFFFFFFF) return KmnCompilerMessages::ERROR_CodeInvalidInThisSection; - if ((msg = ProcessKeyLine(fk, p, IsUnicode)) != STATUS_Success) return msg; + if (fk->currentGroup == 0xFFFFFFFF) { + AddCompileError(KmnCompilerMessages::ERROR_CodeInvalidInThisSection); + return FALSE; + } + if ((msg = ProcessKeyLine(fk, p, IsUnicode)) != STATUS_Success) { + AddCompileError(msg); + return FALSE; + } break; case T_MATCH: - if (fk->currentGroup == 0xFFFFFFFF) return KmnCompilerMessages::ERROR_CodeInvalidInThisSection; + if (fk->currentGroup == 0xFFFFFFFF) { + AddCompileError(KmnCompilerMessages::ERROR_CodeInvalidInThisSection); + return FALSE; + } { PKMX_WCHAR buf = new KMX_WCHAR[GLOBAL_BUFSIZE]; if ((msg = GetRHS(fk, p, buf, GLOBAL_BUFSIZE - 1, (int)(p - pp), IsUnicode)) != STATUS_Success) { delete[] buf; - return msg; + AddCompileError(msg); + return FALSE; } if ((msg = ValidateMatchNomatchOutput(buf)) != STATUS_Success) { delete[] buf; - return msg; + AddCompileError(msg); + return FALSE; } gp = &fk->dpGroupArray[fk->currentGroup]; @@ -520,18 +593,23 @@ KMX_DWORD ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str) break; case T_NOMATCH: - if (fk->currentGroup == 0xFFFFFFFF) return KmnCompilerMessages::ERROR_CodeInvalidInThisSection; + if (fk->currentGroup == 0xFFFFFFFF) { + AddCompileError(KmnCompilerMessages::ERROR_CodeInvalidInThisSection); + return FALSE; + } { PKMX_WCHAR buf = new KMX_WCHAR[GLOBAL_BUFSIZE]; if ((msg = GetRHS(fk, p, buf, GLOBAL_BUFSIZE, (int)(p - pp), IsUnicode)) != STATUS_Success) { delete[] buf; - return msg; + AddCompileError(msg); + return FALSE; } if ((msg = ValidateMatchNomatchOutput(buf)) != STATUS_Success) { delete[] buf; - return msg; + AddCompileError(msg); + return FALSE; } gp = &fk->dpGroupArray[fk->currentGroup]; @@ -553,10 +631,11 @@ KMX_DWORD ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str) break; default: - return KmnCompilerMessages::ERROR_InvalidToken; + AddCompileError(KmnCompilerMessages::ERROR_InvalidToken); + return FALSE; } - return STATUS_Success; + return TRUE; } //********************************************************************************************************************** @@ -747,8 +826,7 @@ KMX_BOOL ProcessStoreLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) { fk->cxStoreArray++; // increment now, because GetXString refers to stores if (i > 0) { - if ((msg = ProcessSystemStore(fk, i, sp)) != STATUS_Success) { - AddCompileError(msg); + if (!ProcessSystemStore(fk, i, sp)) { return FALSE; } } @@ -791,11 +869,11 @@ bool resizeKeyArray(PFILE_GROUP gp, int increment) { return true; } -KMX_DWORD AddStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, const KMX_WCHAR * str, KMX_DWORD *dwStoreID) -{ +KMX_BOOL AddStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, const KMX_WCHAR * str, KMX_DWORD *dwStoreID) { PFILE_STORE sp; if(!resizeStoreArray(fk)) { - return KmnCompilerMessages::FATAL_CannotAllocateMemory; + AddCompileError(KmnCompilerMessages::FATAL_CannotAllocateMemory); + return FALSE; } sp = &fk->dpStoreArray[fk->cxStoreArray]; @@ -818,7 +896,7 @@ KMX_DWORD AddStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, const KMX_WCHAR * str, fk->cxStoreArray++; - return ProcessSystemStore( fk, SystemID, sp); + return ProcessSystemStore(fk, SystemID, sp); } KMX_DWORD AddDebugStore(PFILE_KEYBOARD fk, KMX_WCHAR const * str) @@ -850,8 +928,7 @@ KMX_DWORD AddDebugStore(PFILE_KEYBOARD fk, KMX_WCHAR const * str) PKMX_WCHAR pssBuf = NULL; -KMX_DWORD ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE sp) -{ +KMX_BOOL ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE sp) { //WCHAR buf[GLOBAL_BUFSIZE]; int i, j; KMX_DWORD msg; @@ -862,9 +939,14 @@ KMX_DWORD ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE switch (SystemID) { + case TSS_BASELAYOUT: + break; + case TSS_BITMAP: - if ((msg = ImportBitmapFile(fk, sp->dpString, &fk->dwBitmapSize, &fk->lpBitmap)) != STATUS_Success) - return msg; + if ((msg = ImportBitmapFile(fk, sp->dpString, &fk->dwBitmapSize, &fk->lpBitmap)) != STATUS_Success) { + AddCompileError(msg); + return FALSE; + } break; case TSS_CALLDEFINITION: @@ -887,16 +969,28 @@ KMX_DWORD ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE case TSS_COPYRIGHT: break; + case TSS_CUSTOMKEYMANEDITION: + break; + + case TSS_CUSTOMKEYMANEDITIONNAME: + break; + case TSS_DEBUG_LINE: break; case TSS_ETHNOLOGUECODE: VERIFY_KEYBOARD_VERSION(fk, VERSION_60, KmnCompilerMessages::ERROR_60FeatureOnly_EthnologueCode); - if ((msg = ProcessEthnologueStore(sp->dpString)) != STATUS_Success) return msg; // I2646 + if ((msg = ProcessEthnologueStore(sp->dpString)) != STATUS_Success) { + AddCompileError(msg); + return FALSE; // I2646 + } break; case TSS_HOTKEY: - if ((msg = ProcessHotKey(sp->dpString, &fk->dwHotKey)) != STATUS_Success) return msg; + if ((msg = ProcessHotKey(sp->dpString, &fk->dwHotKey)) != STATUS_Success) { + AddCompileError(msg); + return FALSE; + } u16sprintf(buf, GLOBAL_BUFSIZE, L"%d", (int)fk->dwHotKey); // I3481 delete[] sp->dpString; sp->dpString = new KMX_WCHAR[u16len(buf) + 1]; @@ -906,18 +1000,25 @@ KMX_DWORD ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE case TSS_INCLUDECODES: VERIFY_KEYBOARD_VERSION(fk, VERSION_60, KmnCompilerMessages::ERROR_60FeatureOnly_NamedCodes); if (!kmcmp::CodeConstants->LoadFile(fk, sp->dpString)) { - return KmnCompilerMessages::ERROR_CannotLoadIncludeFile; + AddCompileError(KmnCompilerMessages::ERROR_CannotLoadIncludeFile); + return FALSE; } kmcmp::CodeConstants->reindex(); // I4982 break; + case TSS_KEYMANCOPYRIGHT: + break; + case TSS_LANGUAGE: { KMX_WCHAR *context = NULL; KMX_WCHAR sep_c[3] = u", "; PKMX_WCHAR p_sep_c = sep_c; q = u16tok(sp->dpString, p_sep_c, &context); // I3481 - if (!q) return KmnCompilerMessages::ERROR_InvalidLanguageLine; + if (!q) { + AddCompileError(KmnCompilerMessages::ERROR_InvalidLanguageLine); + return FALSE; + } i = xatoi(&q); KMX_WCHAR sep_n[4] = u" c\n"; @@ -932,7 +1033,10 @@ KMX_DWORD ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE else j = xatoi(&q); - if (i < 1 || j < 1 || i > 0x3FF || j > 0x3F) return KmnCompilerMessages::ERROR_InvalidLanguageLine; + if (i < 1 || j < 1 || i > 0x3FF || j > 0x3F) { + AddCompileError(KmnCompilerMessages::ERROR_InvalidLanguageLine); + return FALSE; + } if (i >= 0x200 || j >= 0x20) AddWarning(KmnCompilerMessages::WARN_CustomLanguagesNotSupported); fk->KeyboardID = (KMX_DWORD)MAKELANGID(i, j); @@ -947,8 +1051,14 @@ KMX_DWORD ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE case TSS_LANGUAGENAME: break; + case TSS_LAYER: + break; + case TSS_LAYOUT: - if (fk->KeyboardID == 0) return KmnCompilerMessages::ERROR_LayoutButNoLanguage; + if (fk->KeyboardID == 0) { + AddCompileError(KmnCompilerMessages::ERROR_LayoutButNoLanguage); + return FALSE; + } q = sp->dpString; @@ -964,7 +1074,8 @@ KMX_DWORD ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE if (kmcmp::FMnemonicLayout && FindSystemStore(fk, TSS_CASEDKEYS) != NULL) { // The &CasedKeys system store is not supported for // mnemonic layouts - return KmnCompilerMessages::ERROR_CasedKeysNotSupportedWithMnemonicLayout; + AddCompileError(KmnCompilerMessages::ERROR_CasedKeysNotSupportedWithMnemonicLayout); + return FALSE; } break; @@ -976,12 +1087,21 @@ KMX_DWORD ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE kmcmp::FOldCharPosMatching = atoiW(sp->dpString); break; + case TSS_PLATFORM: + case TSS_PLATFORM_MATCH: + case TSS_PLATFORM_NOMATCH: + // Never matched but included for completeness + break; + case TSS_SHIFTFREESCAPS: if (*sp->dpString == u'1') fk->dwFlags |= KF_SHIFTFREESCAPS; break; case TSS_VERSION: - if ((fk->dwFlags & KF_AUTOMATICVERSION) == 0) return KmnCompilerMessages::ERROR_VersionAlreadyIncluded; + if ((fk->dwFlags & KF_AUTOMATICVERSION) == 0) { + AddCompileError(KmnCompilerMessages::ERROR_VersionAlreadyIncluded); + return FALSE; + } p = sp->dpString; if (u16tof (p) < 5.0) { AddWarning(KmnCompilerMessages::WARN_OldVersion); @@ -1003,7 +1123,10 @@ KMX_DWORD ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE else if (u16ncmp(p, u"16.0", 4) == 0) fk->version = VERSION_160; // KMXPlus else if (u16ncmp(p, u"17.0", 4) == 0) fk->version = VERSION_170; // Flicks and gestures - else return KmnCompilerMessages::ERROR_InvalidVersion; + else { + AddCompileError(KmnCompilerMessages::ERROR_InvalidVersion); + return FALSE; + } if (fk->version < VERSION_60) kmcmp::FOldCharPosMatching = TRUE; @@ -1057,7 +1180,8 @@ KMX_DWORD ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE case TSS_TARGETS: // I4504 VERIFY_KEYBOARD_VERSION(fk, VERSION_90, KmnCompilerMessages::ERROR_90FeatureOnlyTargets); if((msg = GetCompileTargetsFromTargetsStore(sp->dpString, fk->extra->targets)) != STATUS_Success) { - return msg; + AddCompileError(msg); + return FALSE; } break; @@ -1080,7 +1204,8 @@ KMX_DWORD ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE if (i < 1 || j < 1 || i > 0x3FF || j > 0x3F) { delete[] q; - return KmnCompilerMessages::ERROR_InvalidLanguageLine; + AddCompileError(KmnCompilerMessages::ERROR_InvalidLanguageLine); + return FALSE; } u16sprintf(r, szQ - (size_t)(r - q), L"x%04.4x ", n); // I3481 @@ -1110,13 +1235,15 @@ KMX_DWORD ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE case TSS_KEYBOARDVERSION: // I4140 VERIFY_KEYBOARD_VERSION(fk, VERSION_90, KmnCompilerMessages::ERROR_90FeatureOnlyKeyboardVersion); if (!IsValidKeyboardVersion(sp->dpString)) { - return KmnCompilerMessages::ERROR_KeyboardVersionFormatInvalid; + AddCompileError(KmnCompilerMessages::ERROR_KeyboardVersionFormatInvalid); + return FALSE; } break; case TSS_CASEDKEYS: if ((msg = VerifyCasedKeys(sp)) != STATUS_Success) { - return msg; + AddCompileError(msg); + return FALSE; } break; @@ -1136,9 +1263,10 @@ KMX_DWORD ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE break; default: - return KmnCompilerMessages::ERROR_InvalidSystemStore; + AddCompileError(KmnCompilerMessages::ERROR_InvalidSystemStore); + return FALSE; } - return STATUS_Success; + return TRUE; } KMX_DWORD GetCompileTargetsFromTargetsStore(const KMX_WCHAR* store, int &targets) { @@ -1224,17 +1352,16 @@ KMX_BOOL IsValidKeyboardVersion(KMX_WCHAR *dpString) { // I4140 } -KMX_DWORD kmcmp::AddCompilerVersionStore(PFILE_KEYBOARD fk) -{ - KMX_DWORD msg; - +KMX_BOOL kmcmp::AddCompilerVersionStore(PFILE_KEYBOARD fk) { if(!kmcmp::FShouldAddCompilerVersion) { - return STATUS_Success; + return TRUE; } - if ((msg = AddStore(fk, TSS_COMPILEDVERSION, KEYMAN_VersionWin_W16)) != STATUS_Success) return msg; + if (!AddStore(fk, TSS_COMPILEDVERSION, KEYMAN_VersionWin_W16)) { + return FALSE; + } - return STATUS_Success; + return TRUE; } /**************************** @@ -1285,7 +1412,7 @@ KMX_DWORD CheckStatementOffsets(PFILE_KEYBOARD fk, PFILE_GROUP gp, PKMX_WCHAR co if (kmcmp::CompileTarget == CKF_KEYMANWEB) { for (q = context, i = 1; *q && i < contextOffset; q = incxstr(q), i++); if (*q == UC_SENTINEL && *(q + 1) == CODE_NOTANY) { - VERIFY_KEYBOARD_VERSION(fk, VERSION_140, KmnCompilerMessages::ERROR_140FeatureOnlyContextAndNotAnyWeb); + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_140, KmnCompilerMessages::ERROR_140FeatureOnlyContextAndNotAnyWeb); } } } @@ -1993,7 +2120,7 @@ KMX_DWORD GetXStringImpl(PKMX_WCHAR tstr, PFILE_KEYBOARD fk, PKMX_WCHAR str, KMX } else if (u16nicmp(p, u"baselayout", 10) == 0) // I3430 { - VERIFY_KEYBOARD_VERSION(fk, VERSION_90, KmnCompilerMessages::ERROR_90FeatureOnly_IfSystemStores); + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_90, KmnCompilerMessages::ERROR_90FeatureOnly_IfSystemStores); if (sFlag) return KmnCompilerMessages::ERROR_InvalidInVirtualKeySection; p += 10; q = GetDelimitedString(&p, u"()", GDS_CUTLEAD | GDS_CUTFOLL); @@ -2008,7 +2135,7 @@ KMX_DWORD GetXStringImpl(PKMX_WCHAR tstr, PFILE_KEYBOARD fk, PKMX_WCHAR str, KMX case 5: if (u16nicmp(p, u"if", 2) == 0) { - VERIFY_KEYBOARD_VERSION(fk, VERSION_80, KmnCompilerMessages::ERROR_80FeatureOnly); + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_80, KmnCompilerMessages::ERROR_80FeatureOnly); if (sFlag) return KmnCompilerMessages::ERROR_InvalidInVirtualKeySection; p += 2; q = GetDelimitedString(&p, u"()", GDS_CUTLEAD | GDS_CUTFOLL); @@ -2086,7 +2213,7 @@ KMX_DWORD GetXStringImpl(PKMX_WCHAR tstr, PFILE_KEYBOARD fk, PKMX_WCHAR str, KMX q = GetDelimitedString(&p, u"()", GDS_CUTLEAD | GDS_CUTFOLL); if (q && *q) { - VERIFY_KEYBOARD_VERSION(fk, VERSION_60, KmnCompilerMessages::ERROR_60FeatureOnly_Contextn); + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_60, KmnCompilerMessages::ERROR_60FeatureOnly_Contextn); int n1b; n1b = atoiW(q); if (n1b < 1 || n1b >= 0xF000) return KmnCompilerMessages::ERROR_InvalidToken; @@ -2111,7 +2238,7 @@ KMX_DWORD GetXStringImpl(PKMX_WCHAR tstr, PFILE_KEYBOARD fk, PKMX_WCHAR str, KMX } else if (u16nicmp(p, u"call", 4) == 0) { - VERIFY_KEYBOARD_VERSION(fk, VERSION_501, KmnCompilerMessages::ERROR_501FeatureOnly_Call); + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_501, KmnCompilerMessages::ERROR_501FeatureOnly_Call); if (sFlag) return KmnCompilerMessages::ERROR_CallInVirtualKeySection; p += 4; q = GetDelimitedString(&p, u"()", GDS_CUTLEAD | GDS_CUTFOLL); @@ -2139,8 +2266,8 @@ KMX_DWORD GetXStringImpl(PKMX_WCHAR tstr, PFILE_KEYBOARD fk, PKMX_WCHAR str, KMX case 8: if (u16nicmp(p, u"notany", 6) == 0) { - VERIFY_KEYBOARD_VERSION(fk, VERSION_70, KmnCompilerMessages::ERROR_70FeatureOnly) - if (sFlag) return KmnCompilerMessages::ERROR_AnyInVirtualKeySection; + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_70, KmnCompilerMessages::ERROR_70FeatureOnly); + if (sFlag) return KmnCompilerMessages::ERROR_AnyInVirtualKeySection; p += 6; q = GetDelimitedString(&p, u"()", GDS_CUTLEAD | GDS_CUTFOLL); if (!q || !*q) return KmnCompilerMessages::ERROR_InvalidAny; @@ -2193,7 +2320,7 @@ KMX_DWORD GetXStringImpl(PKMX_WCHAR tstr, PFILE_KEYBOARD fk, PKMX_WCHAR str, KMX case 10: if (u16nicmp(p, u"reset", 5) == 0) { - VERIFY_KEYBOARD_VERSION(fk, VERSION_80, KmnCompilerMessages::ERROR_80FeatureOnly); + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_80, KmnCompilerMessages::ERROR_80FeatureOnly); if (sFlag) return KmnCompilerMessages::ERROR_InvalidInVirtualKeySection; p += 5; q = GetDelimitedString(&p, u"()", GDS_CUTLEAD | GDS_CUTFOLL); @@ -2279,7 +2406,7 @@ KMX_DWORD GetXStringImpl(PKMX_WCHAR tstr, PFILE_KEYBOARD fk, PKMX_WCHAR str, KMX if (sFlag & (LCTRLFLAG | LALTFLAG | RCTRLFLAG | RALTFLAG | CAPITALFLAG | NOTCAPITALFLAG | NUMLOCKFLAG | NOTNUMLOCKFLAG | SCROLLFLAG | NOTSCROLLFLAG) && kmcmp::CompileTarget == CKF_KEYMANWEB && fk->dwFlags & KF_AUTOMATICVERSION) { - VERIFY_KEYBOARD_VERSION(fk, VERSION_100, 0); + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_100, 0); } //printf("sFlag: %x\n", sFlag); @@ -2300,7 +2427,7 @@ KMX_DWORD GetXStringImpl(PKMX_WCHAR tstr, PFILE_KEYBOARD fk, PKMX_WCHAR str, KMX { if (*q == '\'' || *q == '"') { - VERIFY_KEYBOARD_VERSION(fk, VERSION_60, KmnCompilerMessages::ERROR_60FeatureOnly_VirtualCharKey); + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_60, KmnCompilerMessages::ERROR_60FeatureOnly_VirtualCharKey); if (!kmcmp::FMnemonicLayout) AddWarning(KmnCompilerMessages::WARN_VirtualCharKeyWithPositionalLayout); KMX_WCHAR chQuote = *q; q++; if (*q == chQuote || *q == '\n' || *q == 0) return KmnCompilerMessages::ERROR_InvalidToken; @@ -2337,7 +2464,7 @@ KMX_DWORD GetXStringImpl(PKMX_WCHAR tstr, PFILE_KEYBOARD fk, PKMX_WCHAR str, KMX if (i == VK__MAX + 1) { - VERIFY_KEYBOARD_VERSION(fk, VERSION_90, KmnCompilerMessages::ERROR_InvalidToken); + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_90, KmnCompilerMessages::ERROR_InvalidToken); i = GetVKCode(fk, vkname); // I3438 if (i == 0) @@ -2364,7 +2491,7 @@ KMX_DWORD GetXStringImpl(PKMX_WCHAR tstr, PFILE_KEYBOARD fk, PKMX_WCHAR str, KMX case 14: if (u16nicmp(p, u"set", 3) == 0) { - VERIFY_KEYBOARD_VERSION(fk, VERSION_80, KmnCompilerMessages::ERROR_80FeatureOnly); + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_80, KmnCompilerMessages::ERROR_80FeatureOnly); p += 3; q = GetDelimitedString(&p, u"()", GDS_CUTLEAD | GDS_CUTFOLL); if (!q || !*q) return KmnCompilerMessages::ERROR_InvalidSet; @@ -2374,7 +2501,7 @@ KMX_DWORD GetXStringImpl(PKMX_WCHAR tstr, PFILE_KEYBOARD fk, PKMX_WCHAR str, KMX } else if (u16nicmp(p, u"save", 4) == 0) { - VERIFY_KEYBOARD_VERSION(fk, VERSION_80, KmnCompilerMessages::ERROR_80FeatureOnly); + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_80, KmnCompilerMessages::ERROR_80FeatureOnly); p += 4; q = GetDelimitedString(&p, u"()", GDS_CUTLEAD | GDS_CUTFOLL); if (!q || !*q) return KmnCompilerMessages::ERROR_InvalidSave; @@ -2406,7 +2533,7 @@ KMX_DWORD GetXStringImpl(PKMX_WCHAR tstr, PFILE_KEYBOARD fk, PKMX_WCHAR str, KMX return KmnCompilerMessages::ERROR_InvalidToken; continue; case 16: - VERIFY_KEYBOARD_VERSION(fk, VERSION_60, KmnCompilerMessages::ERROR_60FeatureOnly_NamedCodes); + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_60, KmnCompilerMessages::ERROR_60FeatureOnly_NamedCodes); q = p + 1; while (*q && !iswspace(*q)) q++; c = *q; *q = 0; @@ -2426,7 +2553,7 @@ KMX_DWORD GetXStringImpl(PKMX_WCHAR tstr, PFILE_KEYBOARD fk, PKMX_WCHAR str, KMX continue; case 17: if (u16nicmp(p, u"platform", 8) != 0) return KmnCompilerMessages::ERROR_InvalidToken; // I3430 - VERIFY_KEYBOARD_VERSION(fk, VERSION_90, KmnCompilerMessages::ERROR_90FeatureOnly_IfSystemStores); + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_90, KmnCompilerMessages::ERROR_90FeatureOnly_IfSystemStores); if (sFlag) return KmnCompilerMessages::ERROR_InvalidInVirtualKeySection; p += 8; q = GetDelimitedString(&p, u"()", GDS_CUTLEAD | GDS_CUTFOLL); @@ -2436,7 +2563,7 @@ KMX_DWORD GetXStringImpl(PKMX_WCHAR tstr, PFILE_KEYBOARD fk, PKMX_WCHAR str, KMX continue; case 18: // I3437 if (u16nicmp(p, u"layer", 5) != 0) return KmnCompilerMessages::ERROR_InvalidToken; - VERIFY_KEYBOARD_VERSION(fk, VERSION_90, KmnCompilerMessages::ERROR_90FeatureOnly_SetSystemStores); + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_90, KmnCompilerMessages::ERROR_90FeatureOnly_SetSystemStores); if (sFlag) return KmnCompilerMessages::ERROR_InvalidInVirtualKeySection; p += 5; q = GetDelimitedString(&p, u"()", GDS_CUTLEAD | GDS_CUTFOLL); @@ -2506,12 +2633,14 @@ KMX_DWORD process_if_synonym(KMX_DWORD dwSystemID, PFILE_KEYBOARD fk, PKMX_WCHAR KMX_DWORD dwStoreID; - if ((msg = AddStore(fk, TSS_COMPARISON, temp, &dwStoreID)) != STATUS_Success) - { + if (!AddStore(fk, TSS_COMPARISON, temp, &dwStoreID)) { delete[] temp; - return msg; + // TODO: redundant error + return KmnCompilerMessages::ERROR_InvalidIf; } + delete[] temp; + tstr[(*mx)++] = UC_SENTINEL; tstr[(*mx)++] = (KMX_WCHAR)CODE_IFSYSTEMSTORE; tstr[(*mx)++] = (KMX_WCHAR)(dwSystemID + 1); // I4785 @@ -2519,8 +2648,6 @@ KMX_DWORD process_if_synonym(KMX_DWORD dwSystemID, PFILE_KEYBOARD fk, PKMX_WCHAR tstr[(*mx)++] = (KMX_WCHAR)(dwStoreID + 1); tstr[(*mx)] = 0; - delete[] temp; - return STATUS_Success; } @@ -2547,7 +2674,7 @@ KMX_DWORD process_if(PFILE_KEYBOARD fk, PKMX_WCHAR q, PKMX_WCHAR tstr, int *mx) if (r[0] == '&') { - VERIFY_KEYBOARD_VERSION( fk, VERSION_90, KmnCompilerMessages::ERROR_90FeatureOnly_IfSystemStores); + VERIFY_KEYBOARD_VERSION_ret( fk, VERSION_90, KmnCompilerMessages::ERROR_90FeatureOnly_IfSystemStores); for (i = 0; StoreTokens[i]; i++) { if (u16icmp(r, StoreTokens[i]) == 0) break; @@ -2579,12 +2706,14 @@ KMX_DWORD process_if(PFILE_KEYBOARD fk, PKMX_WCHAR q, PKMX_WCHAR tstr, int *mx) KMX_DWORD dwStoreID; - if ((msg = AddStore(fk, TSS_COMPARISON, temp, &dwStoreID)) != STATUS_Success) - { + if (!AddStore(fk, TSS_COMPARISON, temp, &dwStoreID)) { delete[] temp; - return msg; + // TODO: redundant error + return KmnCompilerMessages::ERROR_InvalidIf; } + delete[] temp; + tstr[(*mx)++] = UC_SENTINEL; tstr[(*mx)++] = (KMX_WCHAR)code; tstr[(*mx)++] = (KMX_WCHAR)(i + 1); @@ -2732,9 +2861,13 @@ KMX_DWORD process_set_synonym(KMX_DWORD dwSystemID, PFILE_KEYBOARD fk, PKMX_WCHA KMX_DWORD dwStoreID; - msg = AddStore(fk, TSS_COMPARISON, temp, &dwStoreID); + if(!AddStore(fk, TSS_COMPARISON, temp, &dwStoreID)) { + delete[] temp; + // TODO: redundant error + return KmnCompilerMessages::ERROR_InvalidSet; + } + delete[] temp; - if (msg != STATUS_Success) return msg; tstr[(*mx)++] = UC_SENTINEL; tstr[(*mx)++] = (KMX_WCHAR)CODE_SETSYSTEMSTORE; @@ -2761,7 +2894,7 @@ KMX_DWORD process_set(PFILE_KEYBOARD fk, PKMX_WCHAR q, PKMX_WCHAR tstr, int *mx) if (r[0] == '&') { - VERIFY_KEYBOARD_VERSION((PFILE_KEYBOARD) fk, VERSION_90, KmnCompilerMessages::ERROR_90FeatureOnly_SetSystemStores); // I3437 + VERIFY_KEYBOARD_VERSION_ret((PFILE_KEYBOARD) fk, VERSION_90, KmnCompilerMessages::ERROR_90FeatureOnly_SetSystemStores); // I3437 for (i = 0; StoreTokens[i]; i++) { if (u16icmp(r, StoreTokens[i]) == 0) break; @@ -2798,9 +2931,13 @@ KMX_DWORD process_set(PFILE_KEYBOARD fk, PKMX_WCHAR q, PKMX_WCHAR tstr, int *mx) KMX_DWORD dwStoreID; - msg = AddStore(fk, TSS_COMPARISON, temp, &dwStoreID); + if(!AddStore(fk, TSS_COMPARISON, temp, &dwStoreID)) { + delete[] temp; + // TODO: redundant error + return KmnCompilerMessages::ERROR_InvalidSet; + } + delete[] temp; - if (msg != STATUS_Success) return msg; tstr[(*mx)++] = UC_SENTINEL; tstr[(*mx)++] = (KMX_WCHAR)code; @@ -3373,7 +3510,7 @@ KMX_DWORD ImportBitmapFile(PFILE_KEYBOARD fk, PKMX_WCHAR szName, PKMX_DWORD File /* Test for version 7.0 icon support */ if (*((PKMX_CHAR)*Buf) != 'B' && *(((PKMX_CHAR)*Buf) + 1) != 'M') { - VERIFY_KEYBOARD_VERSION(fk, VERSION_70, KmnCompilerMessages::ERROR_70FeatureOnly); + VERIFY_KEYBOARD_VERSION_ret(fk, VERSION_70, KmnCompilerMessages::ERROR_70FeatureOnly); } return STATUS_Success; @@ -3446,11 +3583,10 @@ KMX_DWORD kmcmp::UTF32ToUTF16(int n, int *n1, int *n2) return kmcmp::CheckUTF16(*n2); } -KMX_DWORD BuildVKDictionary(PFILE_KEYBOARD fk) -{ +KMX_BOOL BuildVKDictionary(PFILE_KEYBOARD fk) { KMX_DWORD i; size_t len = 0; - if (fk->cxVKDictionary == 0) return STATUS_Success; + if (fk->cxVKDictionary == 0) return TRUE; for (i = 0; i < fk->cxVKDictionary; i++) { len += u16len(fk->dpVKDictionary[i].szName) + 1; @@ -3468,9 +3604,12 @@ KMX_DWORD BuildVKDictionary(PFILE_KEYBOARD fk) *p = 0; KMX_DWORD dwStoreID; - KMX_DWORD msg = AddStore(fk, TSS_VKDICTIONARY, storeval, &dwStoreID); + if(!AddStore(fk, TSS_VKDICTIONARY, storeval, &dwStoreID)) { + delete[] storeval; + return FALSE; + } delete[] storeval; - return msg; + return TRUE; } int GetVKCode(PFILE_KEYBOARD fk, PKMX_WCHAR p) diff --git a/developer/src/kmcmplib/src/kmcmplib.h b/developer/src/kmcmplib/src/kmcmplib.h index f75246e50c..caf71a2b7b 100644 --- a/developer/src/kmcmplib/src/kmcmplib.h +++ b/developer/src/kmcmplib/src/kmcmplib.h @@ -19,7 +19,7 @@ namespace kmcmp { extern NamedCodeConstants *CodeConstants; void RecordDeadkeyNames(PFILE_KEYBOARD fk); - KMX_DWORD AddCompilerVersionStore(PFILE_KEYBOARD fk); + KMX_BOOL AddCompilerVersionStore(PFILE_KEYBOARD fk); } extern kmcmp_LoadFileProc loadfileproc; @@ -30,11 +30,11 @@ PKMX_WCHAR strtowstr(PKMX_STR in); PFILE_STORE FindSystemStore(PFILE_KEYBOARD fk, KMX_DWORD dwSystemID); bool UTF16TempFromUTF8(KMX_BYTE* infile, int sz, KMX_BYTE** tempfile, int *sz16); KMX_DWORD WriteCompiledKeyboard(PFILE_KEYBOARD fk, KMX_BYTE**data, size_t& dataSize); -KMX_DWORD AddStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, const KMX_WCHAR * str, KMX_DWORD *dwStoreID= NULL); +KMX_BOOL AddStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, const KMX_WCHAR * str, KMX_DWORD *dwStoreID= NULL); KMX_DWORD ReadLine(KMX_BYTE* infile, int sz, int& offset, PKMX_WCHAR wstr, KMX_BOOL PreProcess); -KMX_DWORD ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str); +KMX_BOOL ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str); KMX_BOOL ProcessGroupLine(PFILE_KEYBOARD fk, PKMX_WCHAR p); KMX_DWORD ProcessGroupFinish(PFILE_KEYBOARD fk); KMX_BOOL ProcessStoreLine(PFILE_KEYBOARD fk, PKMX_WCHAR p); int LineTokenType(PKMX_WCHAR *str); -KMX_DWORD BuildVKDictionary(PFILE_KEYBOARD fk); // I3438 +KMX_BOOL BuildVKDictionary(PFILE_KEYBOARD fk); // I3438 diff --git a/developer/src/kmcmplib/src/versioning.h b/developer/src/kmcmplib/src/versioning.h index a3a1c597bf..57adcc329b 100644 --- a/developer/src/kmcmplib/src/versioning.h +++ b/developer/src/kmcmplib/src/versioning.h @@ -4,6 +4,14 @@ #include "../../../../common/include/km_types.h" #define VERIFY_KEYBOARD_VERSION(fk, ver, err) { \ + if(!VerifyKeyboardVersion((fk), (ver))) { \ + AddCompileError((err)); \ + return FALSE; \ + } \ +} + +// TODO: DEPRECATED, use version above +#define VERIFY_KEYBOARD_VERSION_ret(fk, ver, err) { \ if(!VerifyKeyboardVersion((fk), (ver))) \ return (err); \ } diff --git a/developer/src/kmcmplib/tests/gtest-compiler-test.cpp b/developer/src/kmcmplib/tests/gtest-compiler-test.cpp index 56e751cfd6..3c14eb6a72 100644 --- a/developer/src/kmcmplib/tests/gtest-compiler-test.cpp +++ b/developer/src/kmcmplib/tests/gtest-compiler-test.cpp @@ -11,7 +11,7 @@ PKMX_WCHAR strtowstr(PKMX_STR in); PKMX_STR wstrtostr(PKMX_WCHAR in); -KMX_DWORD ProcessBeginLine(PFILE_KEYBOARD fk, PKMX_WCHAR p); +KMX_BOOL ProcessBeginLine(PFILE_KEYBOARD fk, PKMX_WCHAR p); KMX_DWORD ValidateMatchNomatchOutput(PKMX_WCHAR p); KMX_BOOL IsValidKeyboardVersion(KMX_WCHAR *dpString); PKMX_WCHAR GetDelimitedString(PKMX_WCHAR *p, KMX_WCHAR const * Delimiters, KMX_WORD Flags); @@ -48,7 +48,8 @@ class CompilerTest : public testing::Test { } void initGlobals() { - kmcmp::msgproc = NULL; + kmcmp::msgproc = msgproc_collect; + msgproc_errors.clear(); szText_stub[0] = '\0'; kmcmp::nErrors = 0; kmcmp::ErrChr = 0; @@ -111,6 +112,12 @@ class CompilerTest : public testing::Test { public: static KMX_CHAR szText_stub[]; + static std::vector msgproc_errors; + + static void msgproc_collect(const KMCMP_COMPILER_RESULT_MESSAGE &message, void* context) { + msgproc_errors.push_back(message); + } + static int msgproc_true_stub(int line, uint32_t dwMsgCode, const char* szText, void* context) { strcpy(szText_stub, szText); return 1; @@ -124,6 +131,7 @@ class CompilerTest : public testing::Test { #define COMPILE_ERROR_MAX_LEN (SZMAX_ERRORTEXT + 1 + 280) KMX_CHAR CompilerTest::szText_stub[COMPILE_ERROR_MAX_LEN]; +std::vector CompilerTest::msgproc_errors; TEST_F(CompilerTest, strtowstr_test) { EXPECT_EQ(0, u16cmp(u"hello", strtowstr((PKMX_STR)"hello"))); @@ -204,35 +212,53 @@ TEST_F(CompilerTest, ProcessBeginLine_test) { KMX_WCHAR str[LINESIZE]; // KmnCompilerMessages::ERROR_NoTokensFound + msgproc_errors.clear(); str[0] = '\0'; - EXPECT_EQ(KmnCompilerMessages::ERROR_NoTokensFound, ProcessBeginLine(&fileKeyboard, str)); + EXPECT_EQ(FALSE, ProcessBeginLine(&fileKeyboard, str)); + EXPECT_EQ(1, msgproc_errors.size()); + EXPECT_EQ(KmnCompilerMessages::ERROR_NoTokensFound, msgproc_errors[0].errorCode); // KmnCompilerMessages::ERROR_InvalidToken + msgproc_errors.clear(); u16cpy(str, u"abc >"); - EXPECT_EQ(KmnCompilerMessages::ERROR_InvalidToken, ProcessBeginLine(&fileKeyboard, str)); + EXPECT_EQ(FALSE, ProcessBeginLine(&fileKeyboard, str)); + EXPECT_EQ(1, msgproc_errors.size()); + EXPECT_EQ(KmnCompilerMessages::ERROR_InvalidToken, msgproc_errors[0].errorCode); // KmnCompilerMessages::ERROR_RepeatedBegin, BEGIN_UNICODE + msgproc_errors.clear(); kmcmp::BeginLine[BEGIN_UNICODE] = 0; // not -1 u16cpy(str, u" unicode>"); - EXPECT_EQ(KmnCompilerMessages::ERROR_RepeatedBegin, ProcessBeginLine(&fileKeyboard, str)); + EXPECT_EQ(FALSE, ProcessBeginLine(&fileKeyboard, str)); + EXPECT_EQ(1, msgproc_errors.size()); + EXPECT_EQ(KmnCompilerMessages::ERROR_RepeatedBegin, msgproc_errors[0].errorCode); kmcmp::BeginLine[BEGIN_UNICODE] = -1; // KmnCompilerMessages::ERROR_RepeatedBegin, BEGIN_ANSI + msgproc_errors.clear(); kmcmp::BeginLine[BEGIN_ANSI] = 0; // not -1 u16cpy(str, u" ansi>"); - EXPECT_EQ(KmnCompilerMessages::ERROR_RepeatedBegin, ProcessBeginLine(&fileKeyboard, str)); + EXPECT_EQ(FALSE, ProcessBeginLine(&fileKeyboard, str)); + EXPECT_EQ(1, msgproc_errors.size()); + EXPECT_EQ(KmnCompilerMessages::ERROR_RepeatedBegin, msgproc_errors[0].errorCode); kmcmp::BeginLine[BEGIN_ANSI] = -1; // KmnCompilerMessages::ERROR_RepeatedBegin, BEGIN_NEWCONTEXT + msgproc_errors.clear(); kmcmp::BeginLine[BEGIN_NEWCONTEXT] = 0; // not -1 u16cpy(str, u" newContext>"); - EXPECT_EQ(KmnCompilerMessages::ERROR_RepeatedBegin, ProcessBeginLine(&fileKeyboard, str)); + EXPECT_EQ(FALSE, ProcessBeginLine(&fileKeyboard, str)); + EXPECT_EQ(1, msgproc_errors.size()); + EXPECT_EQ(KmnCompilerMessages::ERROR_RepeatedBegin, msgproc_errors[0].errorCode); kmcmp::BeginLine[BEGIN_NEWCONTEXT] = -1; // KmnCompilerMessages::ERROR_RepeatedBegin, BEGIN_POSTKEYSTROKE + msgproc_errors.clear(); kmcmp::BeginLine[BEGIN_POSTKEYSTROKE] = 0; // not -1 u16cpy(str, u" postKeystroke>"); - EXPECT_EQ(KmnCompilerMessages::ERROR_RepeatedBegin, ProcessBeginLine(&fileKeyboard, str)); + EXPECT_EQ(FALSE, ProcessBeginLine(&fileKeyboard, str)); + EXPECT_EQ(1, msgproc_errors.size()); + EXPECT_EQ(KmnCompilerMessages::ERROR_RepeatedBegin, msgproc_errors[0].errorCode); kmcmp::BeginLine[BEGIN_POSTKEYSTROKE] = -1; }; @@ -249,16 +275,16 @@ TEST_F(CompilerTest, ValidateMatchNomatchOutput_test) { EXPECT_EQ(STATUS_Success, ValidateMatchNomatchOutput((PKMX_WCHAR)sentinel)); }; -// KMX_DWORD ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str) +// KMX_BOOL ParseLine(PFILE_KEYBOARD fk, PKMX_WCHAR str) // KMX_BOOL ProcessGroupLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) // int kmcmp::cmpkeys(const void *key, const void *elem) // KMX_DWORD ProcessGroupFinish(PFILE_KEYBOARD fk) // KMX_BOOL ProcessStoreLine(PFILE_KEYBOARD fk, PKMX_WCHAR p) // bool resizeStoreArray(PFILE_KEYBOARD fk) // bool resizeKeyArray(PFILE_GROUP gp, int increment) -// KMX_DWORD AddStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, const KMX_WCHAR * str, KMX_DWORD *dwStoreID) +// KMX_BOOL AddStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, const KMX_WCHAR * str, KMX_DWORD *dwStoreID) // KMX_DWORD AddDebugStore(PFILE_KEYBOARD fk, KMX_WCHAR const * str) -// KMX_DWORD ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE sp) +// KMX_BOOL ProcessSystemStore(PFILE_KEYBOARD fk, KMX_DWORD SystemID, PFILE_STORE sp) // int GetCompileTargetsFromTargetsStore(const KMX_WCHAR* store) TEST_F(CompilerTest, IsValidKeyboardVersion_test) { @@ -867,7 +893,7 @@ TEST_F(CompilerTest, isIntegerWstring_test) { } // KMX_DWORD kmcmp::UTF32ToUTF16(int n, int *n1, int *n2) -// KMX_DWORD BuildVKDictionary(PFILE_KEYBOARD fk) +// KMX_BOOL BuildVKDictionary(PFILE_KEYBOARD fk) // int GetVKCode(PFILE_KEYBOARD fk, PKMX_WCHAR p) // int GetDeadKey(PFILE_KEYBOARD fk, PKMX_WCHAR p) // void kmcmp::RecordDeadkeyNames(PFILE_KEYBOARD fk)