From 121d39883ebd41b001a3bcfdc114ede680e60db2 Mon Sep 17 00:00:00 2001 From: Sabine Date: Fri, 20 Jan 2023 15:44:33 +0100 Subject: [PATCH] chore(developer): typos, comments, add function u16rchr() --- common/test/keyboards/invalid/README.md | 8 ++++---- .../src/kmcmplib/src/CheckFilenameConsistency.cpp | 2 +- developer/src/kmcmplib/src/CompMsg.cpp | 2 +- developer/src/kmcmplib/src/Compiler.cpp | 4 ++-- developer/src/kmcmplib/src/kmcmpdll.h | 6 +++--- developer/src/kmcmplib/src/kmx_u16.cpp | 12 ++++++++++++ developer/src/kmcmplib/src/kmx_u16.h | 1 + 7 files changed, 24 insertions(+), 11 deletions(-) diff --git a/common/test/keyboards/invalid/README.md b/common/test/keyboards/invalid/README.md index 7cd5ffc5ab..e68cea4081 100644 --- a/common/test/keyboards/invalid/README.md +++ b/common/test/keyboards/invalid/README.md @@ -20,7 +20,7 @@ The naming convention of the files is as follows: * After the second underscore all combination of char can be used. -* The 4 characters following CERR_ correspond to the last 4 digits of the error-Code which is expected to be produced by this file. +* The 4 characters following CERR_ correspond to the last 4 digits of the error code which is expected to be produced by this file. ( e.g. CERR_404D_balochi_phonetic.kmn should produce error 0x0000404D). @@ -33,11 +33,11 @@ While running, kmcompxtest extracts those 4 characters from the Filename (e.g. 4 * If these 4 characters correspond to the actual error given, the test will be marked as OK. (Code 0)
-* If these 4 characters signifiy an error but **no error** does occur, the test will be marked as FAILED (Code 1) +* If these 4 characters signify an error but **no error** does occur, the test will be marked as FAILED (Code 1)
-* If these 4 characters signifiy an error but this **specific error** does not occur, the test will be marked as FAILED (Code 4) +* If these 4 characters signify an error but this **specific error** does not occur, the test will be marked as FAILED (Code 4)
-* If these 4 characters signifiy an error number that is **not correct**, the test will be marked as FAILED (Code 5) +* If these 4 characters signify an error number that is **not correct**, the test will be marked as FAILED (Code 5)
* If more than 1 error is produced, only the error coded in the Filename will be detected diff --git a/developer/src/kmcmplib/src/CheckFilenameConsistency.cpp b/developer/src/kmcmplib/src/CheckFilenameConsistency.cpp index 5d9176377c..7f3ddcacde 100644 --- a/developer/src/kmcmplib/src/CheckFilenameConsistency.cpp +++ b/developer/src/kmcmplib/src/CheckFilenameConsistency.cpp @@ -107,7 +107,7 @@ KMX_DWORD CheckFilenameConsistency(KMX_WCHAR const * Filename, bool ReportMissin } #if defined(_WIN32) || defined(_WIN64) - const KMX_WCHAR* cptr1 = u16chr(Name, '\\'); // _S2 const wchar_t* cptr1 = wcsrchr(Name, '\\'); + const KMX_WCHAR* cptr1 = u16rchr(Name, '\\'); // _S2 const wchar_t* cptr1 = wcsrchr(Name, '\\'); #else const KMX_WCHAR* cptr1 = u16rchr(Name, '/'); #endif diff --git a/developer/src/kmcmplib/src/CompMsg.cpp b/developer/src/kmcmplib/src/CompMsg.cpp index d37413f7ec..c245881a4b 100644 --- a/developer/src/kmcmplib/src/CompMsg.cpp +++ b/developer/src/kmcmplib/src/CompMsg.cpp @@ -110,7 +110,7 @@ const struct CompilerError CompilerErrors[] = { { CERR_DuplicateGroup , "A group with this name has already been defined."}, { CERR_DuplicateStore , "A store with this name has already been defined."}, { CERR_RepeatedBegin , "Begin has already been set"}, - { CHINT_FilenameHasDifferingCase , "HINT: Casing differences may fail on some platforms:"}, + { CHINT_FilenameHasDifferingCase , "HINT: Casing differences may fail on some platforms."}, { 0, nullptr } }; diff --git a/developer/src/kmcmplib/src/Compiler.cpp b/developer/src/kmcmplib/src/Compiler.cpp index c2eb67948f..36dd42eb98 100644 --- a/developer/src/kmcmplib/src/Compiler.cpp +++ b/developer/src/kmcmplib/src/Compiler.cpp @@ -3425,8 +3425,8 @@ KMX_DWORD ReadLine(FILE* fp_in , PKMX_WCHAR wstr, KMX_BOOL PreProcess) if (cur == fsize) - // Always a "\r\n" to the EOF, avoids funny bugs - //u16ncat(str, u"\r\n", _countof(str)); // I3481 // S: do we need changes at other places as well when we skip \r? + // S: Is replacing "\r\n" with "\n" here sufficient or do we need changes at other places as well when we skip "\r"? + // u16ncat(str, u"\r\n", _countof(str)); // I3481 // Always a "\r\n" to the EOF, avoids funny bugs u16ncat(str, u"\n", _countof(str)); // I3481 if (len == 0) return CERR_EndOfFile; diff --git a/developer/src/kmcmplib/src/kmcmpdll.h b/developer/src/kmcmplib/src/kmcmpdll.h index 13b163170f..78f05abfcb 100644 --- a/developer/src/kmcmplib/src/kmcmpdll.h +++ b/developer/src/kmcmplib/src/kmcmpdll.h @@ -8,12 +8,12 @@ namespace kmcmp { extern int currentLine; } -KMX_BOOL AddCompileError (KMX_DWORD msg); +KMX_BOOL AddCompileError(KMX_DWORD msg); // TODO: These macros can return FALSE in functions that expect a DWORD CERR_x // return value type. This is just plain wrong! -#define SetError(err) { if(AddCompileError (err) || (err & CERR_FATAL)) return FALSE; } -#define AddWarning(warn) { if(AddCompileError (warn)) return FALSE; } +#define SetError(err) { if(AddCompileError(err) || (err & CERR_FATAL)) return FALSE; } +#define AddWarning(warn) { if(AddCompileError(warn)) return FALSE; } PKMX_WCHAR strtowstr(PKMX_STR in); PFILE_STORE FindSystemStore(PFILE_KEYBOARD fk, KMX_DWORD dwSystemID); diff --git a/developer/src/kmcmplib/src/kmx_u16.cpp b/developer/src/kmcmplib/src/kmx_u16.cpp index e9172f6a64..6867f163bc 100644 --- a/developer/src/kmcmplib/src/kmx_u16.cpp +++ b/developer/src/kmcmplib/src/kmx_u16.cpp @@ -104,6 +104,18 @@ const KMX_WCHAR * u16ncat(KMX_WCHAR *dst, const KMX_WCHAR *src, size_t max) { return o; } +// u16rchr returns last occurence of ch in p; It returns p_end + 1 if ch = '\0' and NULL if ch is not found +const KMX_WCHAR* u16rchr(const KMX_WCHAR* p, KMX_WCHAR ch) { + const KMX_WCHAR* p_end = p + u16len(p) - 1; + + if (ch == '\0') return p_end + 1; + while (p_end >= p) { + if (*p_end == ch) return p_end; + p_end--; + } + return NULL; +} + const KMX_WCHAR * u16chr(const KMX_WCHAR *p, KMX_WCHAR ch) { while (*p) { if (*p == ch) return p; diff --git a/developer/src/kmcmplib/src/kmx_u16.h b/developer/src/kmcmplib/src/kmx_u16.h index 5d55d7a65d..bd207524a3 100644 --- a/developer/src/kmcmplib/src/kmx_u16.h +++ b/developer/src/kmcmplib/src/kmx_u16.h @@ -22,6 +22,7 @@ int u16ncmp(const KMX_WCHAR *p, const KMX_WCHAR *q, size_t count); int u16nicmp(const KMX_WCHAR *p, const KMX_WCHAR *q, size_t count) ; const KMX_WCHAR * u16ncpy(KMX_WCHAR *dst, const KMX_WCHAR *src, size_t max); const KMX_WCHAR * u16cpy(KMX_WCHAR *dst, const KMX_WCHAR *src); +const KMX_WCHAR * u16rchr(const KMX_WCHAR *p, KMX_WCHAR ch) ; const KMX_WCHAR * u16chr(const KMX_WCHAR *p, KMX_WCHAR ch) ; const KMX_WCHAR * u16ncat(KMX_WCHAR *dst, const KMX_WCHAR *src, size_t max); KMX_WCHAR * u16tok(KMX_WCHAR *p, KMX_WCHAR ch, KMX_WCHAR **ctx) ;