From 404d888fde5f3d421c26bcedd27cb75a4d9b78a8 Mon Sep 17 00:00:00 2001 From: Sabine Date: Thu, 20 Jun 2024 17:44:21 +0200 Subject: [PATCH] feat(linux): work on 2nd round of comments on PR 11816 --- .clang-format | 2 +- linux/mcompile/keymap/keymap.cpp | 15 +- linux/mcompile/keymap/mc_import_rules.cpp | 334 ++++++++++------------ linux/mcompile/keymap/mc_kmxfile.h | 2 +- linux/mcompile/keymap/mcompile.cpp | 3 +- linux/mcompile/keymap/meson.build | 9 +- 6 files changed, 175 insertions(+), 190 deletions(-) diff --git a/.clang-format b/.clang-format index dc3c220bbc..50df9fee12 100644 --- a/.clang-format +++ b/.clang-format @@ -9,7 +9,7 @@ AlignConsecutiveDeclarations: false AlignEscapedNewlines: Left AlignOperands: true AlignTrailingComments: true -AllowAllArgumentsOnNextLine: trues +AllowAllArgumentsOnNextLine: true AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: Never diff --git a/linux/mcompile/keymap/keymap.cpp b/linux/mcompile/keymap/keymap.cpp index 024f06a1d9..9eeef45f35 100755 --- a/linux/mcompile/keymap/keymap.cpp +++ b/linux/mcompile/keymap/keymap.cpp @@ -621,8 +621,11 @@ int KMX_get_KeyVal_From_KeyCode(GdkKeymap *keymap, guint keycode, ShiftState ss, if (!gdk_keymap_get_entries_for_keycode(keymap, keycode, &maps, &keyvals, &count)) return 0; - if (!(ensureValidInputForKeyboardTranslation( map_VKShiftState_to_LinModifier(ss), count, keycode))) + if (!(ensureValidInputForKeyboardTranslation( map_VKShiftState_to_LinModifier(ss), count, keycode))){ + g_free(keyvals); + g_free(maps); return 0; + } //BASE (shiftstate: 0) if (( ss == Base ) && ( caps == 0 )) { @@ -710,8 +713,11 @@ KMX_DWORD KMX_get_KeyValUnderlying_From_KeyCodeUnderlying(GdkKeymap *keymap, gui if (!gdk_keymap_get_entries_for_keycode(keymap, keycode, &maps, &keyvals, &count)) return 0; - if (!(ensureValidInputForKeyboardTranslation( shift_state_pos, count, keycode))) + if (!(ensureValidInputForKeyboardTranslation( shift_state_pos, count, keycode))){ + g_free(keyvals); + g_free(maps); return 0; + } kVal = (KMX_DWORD) KMX_get_KeyVal_From_KeyCode(keymap, keycode, (ShiftState) shift_state_pos, 0); @@ -732,8 +738,11 @@ KMX_DWORD KMX_get_KeyValUnderlying_From_KeyCodeUnderlying(GdkKeymap *keymap, UIN if (!gdk_keymap_get_entries_for_keycode(keymap, kc_underlying, &maps, &keyvals, &count)) return 0; - if (!(ensureValidInputForKeyboardTranslation( map_VKShiftState_to_LinModifier(vk_ShiftState), count, kc_underlying))) + if (!(ensureValidInputForKeyboardTranslation( map_VKShiftState_to_LinModifier(vk_ShiftState), count, kc_underlying))){ + g_free(keyvals); + g_free(maps); return 0; + } KMX_DWORD keyV = KMX_get_KeyVal_From_KeyCode(keymap, kc_underlying, ShiftState(map_VKShiftState_to_LinModifier(vk_ShiftState)), 0); diff --git a/linux/mcompile/keymap/mc_import_rules.cpp b/linux/mcompile/keymap/mc_import_rules.cpp index 32bb7cd245..2a966bfcca 100755 --- a/linux/mcompile/keymap/mc_import_rules.cpp +++ b/linux/mcompile/keymap/mc_import_rules.cpp @@ -26,17 +26,16 @@ #include "keymap.h" const int KMX_ShiftStateMap[] = { - ISVIRTUALKEY, - ISVIRTUALKEY | K_SHIFTFLAG, - ISVIRTUALKEY | K_CTRLFLAG, - ISVIRTUALKEY | K_SHIFTFLAG | K_CTRLFLAG, - 0, - 0, - ISVIRTUALKEY | RALTFLAG, - ISVIRTUALKEY | RALTFLAG | K_SHIFTFLAG, - 0, - 0 -}; + ISVIRTUALKEY, + ISVIRTUALKEY | K_SHIFTFLAG, + ISVIRTUALKEY | K_CTRLFLAG, + ISVIRTUALKEY | K_SHIFTFLAG | K_CTRLFLAG, + 0, + 0, + ISVIRTUALKEY | RALTFLAG, + ISVIRTUALKEY | RALTFLAG | K_SHIFTFLAG, + 0, + 0}; DeadKey::DeadKey(KMX_WCHAR deadCharacter) { this->m_deadchar = deadCharacter; @@ -53,51 +52,54 @@ void DeadKey::KMX_AddDeadKeyRow(KMX_WCHAR baseCharacter, KMX_WCHAR combinedChara bool DeadKey::KMX_ContainsBaseCharacter(KMX_WCHAR baseCharacter) { std::vector::iterator it; - for(it=this->m_rgbasechar.begin(); itm_rgbasechar.begin(); it < m_rgbasechar.end(); it++) { + if (*it == baseCharacter) { return true; } } return false; } -int KMX_ToUnicodeEx(guint keycode, PKMX_WCHAR pwszBuff, int shift_state_pos, int caps, GdkKeymap *keymap) { - GdkKeymapKey *maps; - guint *keyvals; +int KMX_ToUnicodeEx(guint keycode, PKMX_WCHAR pwszBuff, int shift_state_pos, int caps, GdkKeymap* keymap) { + GdkKeymapKey* maps; + guint* keyvals; gint count; + if (u16len(pwszBuff) < 1) + return 0; + if (!gdk_keymap_get_entries_for_keycode(keymap, keycode, &maps, &keyvals, &count)) return 0; - if (!(ensureValidInputForKeyboardTranslation( shift_state_pos, count, keycode))) + if (!(ensureValidInputForKeyboardTranslation(shift_state_pos, count, keycode))) return 0; - KMX_DWORD keyVal= (KMX_DWORD) KMX_get_KeyVal_From_KeyCode(keymap, keycode, ShiftState(shift_state_pos), caps); + KMX_DWORD keyVal = (KMX_DWORD)KMX_get_KeyVal_From_KeyCode(keymap, keycode, ShiftState(shift_state_pos), caps); std::u16string str = convert_DeadkeyValues_To_U16str(keyVal); - pwszBuff[0]= * (PKMX_WCHAR) str.c_str(); - + pwszBuff[0] = *(PKMX_WCHAR)str.c_str(); g_free(keyvals); g_free(maps); - if((keyVal >= deadkey_min) && (keyVal <= deadkey_max)) // deadkeys + + if ((keyVal >= deadkey_min) && (keyVal <= deadkey_max)) // deadkeys return -1; - else if(gdk_keyval_to_unicode(keyVal) == 0) // NO UNICODE + else if (gdk_keyval_to_unicode(keyVal) == 0) // NO UNICODE return 0; - else // usable char + else // usable char return 1; } -int KMX_DeadKeyMap(int index, std::vector *deadkeys, int deadkeyBase, std::vector *deadkeyMappings) { // I4327 // I4353 - for(size_t i = 0; i < deadkeyMappings->size(); i++) { - if((*deadkeyMappings)[i].deadkey == index) { +KMX_WCHAR KMX_DeadKeyMap( int index, std::vector* deadkeys, int deadkeyBase, std::vector* deadkeyMappings) { // I4327 // I4353 + for (size_t i = 0; i < deadkeyMappings->size(); i++) { + if ((*deadkeyMappings)[i].deadkey == index) { return (*deadkeyMappings)[i].dkid; } } - for(size_t i = 0; i < deadkeys->size(); i++) { - if((*deadkeys)[i]->KMX_DeadCharacter() == index) { - return deadkeyBase + i; + for (size_t i = 0; i < deadkeys->size(); i++) { + if ((*deadkeys)[i]->KMX_DeadCharacter() == index) { + return (KMX_WCHAR) (deadkeyBase + i); } } return 0xFFFF; @@ -111,11 +113,10 @@ private: std::u16string m_rgss[10][2]; public: - KMX_VirtualKey(UINT scanCode) { this->m_vk = KMX_get_VKUS_From_KeyCodeUnderlying(scanCode); this->m_sc = scanCode; - memset(this->m_rgfDeadKey,0,sizeof(this->m_rgfDeadKey)); + memset(this->m_rgfDeadKey, 0, sizeof(this->m_rgfDeadKey)); } UINT VK() { @@ -136,50 +137,34 @@ public: } bool KMX_IsSGCAPS() { - std::u16string stBase = this->KMX_GetShiftState(Base, false); - std::u16string stShift = this->KMX_GetShiftState(Shft, false); - std::u16string stCaps = this->KMX_GetShiftState(Base, true); - std::u16string stShiftCaps = this->KMX_GetShiftState(Shft, true); - return ( - ((stCaps.size() > 0) && - (stBase.compare(stCaps) != 0) && - (stShift.compare(stCaps) != 0)) || - ((stShiftCaps.size() > 0) && - (stBase.compare(stShiftCaps) != 0) && - (stShift.compare(stShiftCaps) != 0))); - } + std::u16string stBase = this->KMX_GetShiftState(Base, false); + std::u16string stShift = this->KMX_GetShiftState(Shft, false); + std::u16string stCaps = this->KMX_GetShiftState(Base, true); + std::u16string stShiftCaps = this->KMX_GetShiftState(Shft, true); + return ( + ((stCaps.size() > 0) && (stBase.compare(stCaps) != 0) && (stShift.compare(stCaps) != 0)) || + ((stShiftCaps.size() > 0) && (stBase.compare(stShiftCaps) != 0) && (stShift.compare(stShiftCaps) != 0))); + } bool KMX_IsCapsEqualToShift() { - std::u16string stBase = this->KMX_GetShiftState(Base, false); - std::u16string stShift = this->KMX_GetShiftState(Shft, false); - std::u16string stCaps = this->KMX_GetShiftState(Base, true); - return ( - (stBase.size() > 0) && - (stShift.size() > 0) && - (stBase.compare(stShift) != 0) && - (stShift.compare(stCaps) == 0)); - } + std::u16string stBase = this->KMX_GetShiftState(Base, false); + std::u16string stShift = this->KMX_GetShiftState(Shft, false); + std::u16string stCaps = this->KMX_GetShiftState(Base, true); + return ((stBase.size() > 0) && (stShift.size() > 0) && (stBase.compare(stShift) != 0) && (stShift.compare(stCaps) == 0)); + } bool KMX_IsAltGrCapsEqualToAltGrShift() { - std::u16string stBase = this->KMX_GetShiftState(MenuCtrl, false); - std::u16string stShift = this->KMX_GetShiftState(ShftMenuCtrl, false); - std::u16string stCaps = this->KMX_GetShiftState(MenuCtrl, true); - return ( - (stBase.size() > 0) && - (stShift.size() > 0) && - (stBase.compare(stShift) != 0) && - (stShift.compare(stCaps) == 0)); - } + std::u16string stBase = this->KMX_GetShiftState(MenuCtrl, false); + std::u16string stShift = this->KMX_GetShiftState(ShftMenuCtrl, false); + std::u16string stCaps = this->KMX_GetShiftState(MenuCtrl, true); + return ((stBase.size() > 0) && (stShift.size() > 0) && (stBase.compare(stShift) != 0) && (stShift.compare(stCaps) == 0)); + } bool KMX_IsXxxxGrCapsEqualToXxxxShift() { - std::u16string stBase = this->KMX_GetShiftState(Xxxx, false); - std::u16string stShift = this->KMX_GetShiftState(ShftXxxx, false); - std::u16string stCaps = this->KMX_GetShiftState(Xxxx, true); - return ( - (stBase.size() > 0) && - (stShift.size() > 0) && - (stBase.compare(stShift) != 0) && - (stShift.compare(stCaps) == 0)); + std::u16string stBase = this->KMX_GetShiftState(Xxxx, false); + std::u16string stShift = this->KMX_GetShiftState(ShftXxxx, false); + std::u16string stCaps = this->KMX_GetShiftState(Xxxx, true); + return ((stBase.size() > 0) && (stShift.size() > 0) && (stBase.compare(stShift) != 0) && (stShift.compare(stCaps) == 0)); } bool KMX_IsEmpty() { @@ -211,8 +196,7 @@ public: continue; } for (int caps = 0; caps <= 1; caps++) { - - std::u16string st = this->KMX_GetShiftState((ShiftState) ss, (caps == 1)); + std::u16string st = this->KMX_GetShiftState((ShiftState)ss, (caps == 1)); if (st.size() == 0) { // No character assigned here @@ -222,13 +206,14 @@ public: } else { bool isvalid = true; for (size_t ich = 0; ich < st.size(); ich++) { - if(st[ich] < 0x20 || st[ich] == 0x7F) { - isvalid=false; + if (st[ich] < 0x20 || st[ich] == 0x7F) { + isvalid = false; wprintf(L"invalid for: %i\n", st[ich]); - break; } + break; + } } - if(isvalid) { + if (isvalid) { nkeys++; } } @@ -237,13 +222,10 @@ public: return nkeys; } - bool KMX_LayoutRow(int MaxShiftState, LPKMX_KEY key, std::vector *deadkeys, int deadkeyBase, BOOL bDeadkeyConversion,vec_dword_3D& all_vector, GdkKeymap *keymap) { // I4552 + bool KMX_LayoutRow(int MaxShiftState, LPKMX_KEY key, std::vector* deadkeys, int deadkeyBase, BOOL bDeadkeyConversion, vec_dword_3D& all_vector, GdkKeymap* keymap) { // I4552 // Get the CAPSLOCK value - int capslock = - (this->KMX_IsCapsEqualToShift() ? 1 : 0) | - (this->KMX_IsSGCAPS() ? 2 : 0) | - (this->KMX_IsAltGrCapsEqualToAltGrShift() ? 4 : 0) | - (this->KMX_IsXxxxGrCapsEqualToXxxxShift() ? 8 : 0); + int capslock = (this->KMX_IsCapsEqualToShift() ? 1 : 0) | (this->KMX_IsSGCAPS() ? 2 : 0) | + (this->KMX_IsAltGrCapsEqualToAltGrShift() ? 4 : 0) | (this->KMX_IsXxxxGrCapsEqualToXxxxShift() ? 8 : 0); for (int ss = 0; ss <= MaxShiftState; ss++) { if (ss == Menu || ss == ShftMenu) { @@ -251,63 +233,60 @@ public: continue; } for (int caps = 0; caps <= 1; caps++) { - std::u16string st = this->KMX_GetShiftState((ShiftState) ss, (caps == 1)); + std::u16string st = this->KMX_GetShiftState((ShiftState)ss, (caps == 1)); PKMX_WCHAR p; if (st.size() == 0) { // No character assigned here - } - else if (this->m_rgfDeadKey[(int)ss][caps]) { + } else if (this->m_rgfDeadKey[(int)ss][caps]) { // It's a dead key, append an @ sign. key->dpContext = new KMX_WCHAR[1]; *key->dpContext = 0; - key->ShiftFlags = this->KMX_GetShiftStateValue(capslock, caps, (ShiftState) ss); + key->ShiftFlags = this->KMX_GetShiftStateValue(capslock, caps, (ShiftState)ss); // we already use VK_US so no need to convert it as we do on windows key->Key = this->VK(); key->Line = 0; - if(bDeadkeyConversion) { // I4552 + if (bDeadkeyConversion) { // I4552 p = key->dpOutput = new KMX_WCHAR[2]; *p++ = st[0]; *p = 0; } else { - p = key->dpOutput = new KMX_WCHAR[4]; *p++ = UC_SENTINEL; *p++ = CODE_DEADKEY; - // can convert since KMX_DeadKeyMap returns a small positive number - *p++ = (KMX_WCHAR) KMX_DeadKeyMap(st[0], deadkeys, deadkeyBase, &KMX_FDeadkeys); // I4353 + *p++ = KMX_DeadKeyMap(st[0], deadkeys, deadkeyBase, &KMX_FDeadkeys); // I4353 *p = 0; } key++; - } - else { + } else { bool isvalid = true; for (size_t ich = 0; ich < st.size(); ich++) { - if(st[ich] < 0x20 || st[ich] == 0x7F) { - isvalid=false; + if (st[ich] < 0x20 || st[ich] == 0x7F) { + isvalid = false; wprintf(L"invalid 16 for: %i\n", st[ich]); - break; } + break; + } } - if(isvalid) { + if (isvalid) { // this is different to mcompile windows !!!! // this->m_sc stores SC-US = SCUnderlying // this->m_vk stores VK-US ( not underlying !!) // key->Key stores VK-US ( not underlying !!) // key->dpOutput stores character Underlying - KMX_DWORD SC_Underlying = KMX_get_KeyCodeUnderlying_From_KeyCodeUS(keymap, all_vector, this->SC(), (ShiftState) ss, caps); - key->Key = KMX_get_VKUS_From_KeyCodeUnderlying( SC_Underlying); + KMX_DWORD SC_Underlying = KMX_get_KeyCodeUnderlying_From_KeyCodeUS(keymap, all_vector, this->SC(), (ShiftState)ss, caps); + key->Key = KMX_get_VKUS_From_KeyCodeUnderlying(SC_Underlying); key->Line = 0; - key->ShiftFlags = this->KMX_GetShiftStateValue(capslock, caps, (ShiftState) ss); + key->ShiftFlags = this->KMX_GetShiftStateValue(capslock, caps, (ShiftState)ss); key->dpContext = new KMX_WCHAR; *key->dpContext = 0; p = key->dpOutput = new KMX_WCHAR[st.size() + 1]; - for(size_t ich = 0; ich < st.size(); ich++) { + for (size_t ich = 0; ich < st.size(); ich++) { *p++ = st[ich]; } *p = 0; @@ -346,25 +325,24 @@ public: bool KMX_IsControlChar(char16_t ch) { return (ch < 0x0020) || (ch >= 0x007F && ch <= 0x009F); } - }; -int KMX_GetMaxDeadkeyIndex(KMX_WCHAR *p) { +int KMX_GetMaxDeadkeyIndex(KMX_WCHAR* p) { int n = 0; - while(p && *p) { - if(*p == UC_SENTINEL && *(p+1) == CODE_DEADKEY) - n = std::max(n, (int) *(p+2)); + while (p && *p) { + if (*p == UC_SENTINEL && *(p + 1) == CODE_DEADKEY) + n = std::max(n, (int)*(p + 2)); p = KMX_incxstr(p); } return n; } -bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **keymap, std::vector *FDeadkeys, KMX_BOOL bDeadkeyConversion) { // I4353 // I4552 +bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap** keymap, std::vector* FDeadkeys, KMX_BOOL bDeadkeyConversion) { // I4353 // I4552 KMX_Loader loader; std::vector rgKey; //= new VirtualKey[256]; std::vector alDead; - std::vector alDead_cpl = create_deadkeys_by_basechar(); + std::vector alDead_byBasechar = create_deadkeys_by_basechar(); rgKey.resize(256); @@ -372,19 +350,19 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke // values in it. Then, store the SC in each valid VK so it can act as both a // flag that the VK is valid, and it can store the SC value. - for(UINT sc = 0x01; sc <= 0x7f; sc++) { + for (UINT sc = 0x01; sc <= 0x7f; sc++) { // fills m_vk with the VK of the US keyboard // ( mcompile win uses MapVirtualKeyEx() to fill m_vk with the VK of the Underlying keyboard) // Linux can get a VK for the US Keyboard using USVirtualKeyToScanCode/ScanCodeToUSVirtualKey // Linux cannot get a VK for the underling Keyboard // this "connection" is possible only when using all_vector - KMX_VirtualKey *key = new KMX_VirtualKey(sc); + KMX_VirtualKey* key = new KMX_VirtualKey(sc); - if((key->VK() != 0) ) { - rgKey[key->VK()] = key; + if ((key->VK() != 0)) { + rgKey[key->VK()] = key; } else { - delete key; + delete key; } } @@ -393,40 +371,37 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke rgKey[VK_CANCEL] = new KMX_VirtualKey(hkl, VK_CANCEL); rgKey[VK_DECIMAL] = new KMX_VirtualKey(hkl, VK_DECIMAL);*/ - // in this part we skip shiftstates 4, 5, 8, 9 - for(UINT iKey = 0; iKey < rgKey.size(); iKey++) { + // in this part we skip shiftstates 4, 5, 8, 9 + for (UINT iKey = 0; iKey < rgKey.size(); iKey++) { + if (rgKey[iKey] != NULL) { + KMX_WCHAR sbBuffer[256]; // Scratchpad we use many places - if(rgKey[iKey] != NULL) { - KMX_WCHAR sbBuffer[256]; // Scratchpad we use many places + for (ShiftState ss = Base; ss <= loader.KMX_MaxShiftState(); ss = (ShiftState)((int)ss + 1)) { + if (ss == Menu || ss == ShftMenu) { + // Alt and Shift+Alt don't work, so skip them (ss 4+5) + continue; + } - for(ShiftState ss = Base; ss <= loader.KMX_MaxShiftState(); ss = (ShiftState)((int)ss + 1)) { - if(ss == Menu || ss == ShftMenu) { - // Alt and Shift+Alt don't work, so skip them (ss 4+5) - continue; - } + KMX_DWORD kc_us = (KMX_DWORD)KMX_get_KeyCodeUnderlying_From_VKUS(iKey); - KMX_DWORD kc_us = (KMX_DWORD) KMX_get_KeyCodeUnderlying_From_VKUS(iKey); + for (int caps = 0; caps <= 1; caps++) { + int rc = KMX_ToUnicodeEx(kc_us, sbBuffer, ss, caps, *keymap); - for(int caps = 0; caps <= 1; caps++) { - int rc = KMX_ToUnicodeEx(kc_us, sbBuffer, ss, caps, *keymap); - - if(rc > 0) { - if(*sbBuffer == 0) { - rgKey[iKey]->KMX_SetShiftState(ss, u"", false, (caps)); // different to windows since behavior on Linux is different - } - else { - if ((ss == Ctrl || ss == ShftCtrl) ) { + if (rc > 0) { + if (*sbBuffer == 0) { + rgKey[iKey]->KMX_SetShiftState(ss, u"", false, (caps)); // different to windows since behavior on Linux is different + } else { + if ((ss == Ctrl || ss == ShftCtrl)) { continue; } sbBuffer[rc] = 0; - rgKey[iKey]->KMX_SetShiftState(ss, sbBuffer, false, (caps)); // different to windows since behavior on Linux is different + rgKey[iKey]->KMX_SetShiftState(ss, sbBuffer, false, (caps)); // different to windows since behavior on Linux is different } - } - else if(rc < 0) { + } else if (rc < 0) { sbBuffer[2] = 0; - rgKey[iKey]->KMX_SetShiftState(ss, sbBuffer, true, (caps)); // different to windows since behavior on Linux is different + rgKey[iKey]->KMX_SetShiftState(ss, sbBuffer, true, (caps)); // different to windows since behavior on Linux is different - refine_alDead(sbBuffer[0], alDead, alDead_cpl); + refine_alDead(sbBuffer[0], alDead, alDead_byBasechar); } } } @@ -439,7 +414,7 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke //------------------------------------------------------------- int nDeadkey = 0; - LPKMX_GROUP gp = new KMX_GROUP[kp->cxGroupArray+4]; // leave space for old + LPKMX_GROUP gp = new KMX_GROUP[kp->cxGroupArray + 4]; // leave space for old memcpy(gp, kp->dpGroupArray, sizeof(KMX_GROUP) * kp->cxGroupArray); // @@ -447,44 +422,42 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke // kp->dpGroupArray = gp; - for(UINT i = 0; i < kp->cxGroupArray; i++, gp++) { - //if(gp->fUsingKeys && gp->dpNoMatch == NULL) { // I4550 - // WCHAR *p = gp->dpNoMatch = new WCHAR[4]; - // *p++ = UC_SENTINEL; - // *p++ = CODE_USE; - // *p++ = (WCHAR)(kp->cxGroupArray + 1); - // *p = 0; + for (UINT i = 0; i < kp->cxGroupArray; i++, gp++) { + // if(gp->fUsingKeys && gp->dpNoMatch == NULL) { // I4550 + // WCHAR *p = gp->dpNoMatch = new WCHAR[4]; + // *p++ = UC_SENTINEL; + // *p++ = CODE_USE; + // *p++ = (WCHAR)(kp->cxGroupArray + 1); + // *p = 0; //} LPKMX_KEY kkp = gp->dpKeyArray; - for(UINT j = 0; j < gp->cxKeyArray; j++, kkp++) { + for (UINT j = 0; j < gp->cxKeyArray; j++, kkp++) { nDeadkey = std::max(nDeadkey, KMX_GetMaxDeadkeyIndex(kkp->dpContext)); nDeadkey = std::max(nDeadkey, KMX_GetMaxDeadkeyIndex(kkp->dpOutput)); } } kp->cxGroupArray++; - gp = &kp->dpGroupArray[kp->cxGroupArray-1]; - + gp = &kp->dpGroupArray[kp->cxGroupArray - 1]; + // calculate the required size of `gp->dpKeyArray` - + UINT nkeys = 0; for (UINT iKey = 0; iKey < rgKey.size(); iKey++) { if ((rgKey[iKey] != NULL) && rgKey[iKey]->KMX_IsKeymanUsedKey() && (!rgKey[iKey]->KMX_IsEmpty())) { - nkeys+= rgKey[iKey]->KMX_GetKeyCount(loader.KMX_MaxShiftState()); + nkeys += rgKey[iKey]->KMX_GetKeyCount(loader.KMX_MaxShiftState()); } } gp->fUsingKeys = TRUE; - gp->dpMatch = NULL; - gp->dpName = NULL; - gp->dpNoMatch = NULL; + gp->dpMatch = NULL; + gp->dpName = NULL; + gp->dpNoMatch = NULL; gp->cxKeyArray = nkeys; gp->dpKeyArray = new KMX_KEY[gp->cxKeyArray]; - nDeadkey++; // ensure a 1-based index above the max deadkey value already in the keyboard - - + nDeadkey++; // ensure a 1-based index above the max deadkey value already in the keyboard // // Fill in the new rules @@ -492,8 +465,8 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke nkeys = 0; for (UINT iKey = 0; iKey < rgKey.size(); iKey++) { if ((rgKey[iKey] != NULL) && rgKey[iKey]->KMX_IsKeymanUsedKey() && (!rgKey[iKey]->KMX_IsEmpty())) { - if(rgKey[iKey]->KMX_LayoutRow(loader.KMX_MaxShiftState(), &gp->dpKeyArray[nkeys], &alDead, nDeadkey, bDeadkeyConversion, all_vector,*keymap)) { // I4552 - nkeys+=rgKey[iKey]->KMX_GetKeyCount(loader.KMX_MaxShiftState()); + if (rgKey[iKey]->KMX_LayoutRow(loader.KMX_MaxShiftState(), &gp->dpKeyArray[nkeys], &alDead, nDeadkey, bDeadkeyConversion, all_vector, *keymap)) { // I4552 + nkeys += rgKey[iKey]->KMX_GetKeyCount(loader.KMX_MaxShiftState()); } } } @@ -504,9 +477,9 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke // Add nomatch control to each terminating 'using keys' group // I4550 // LPKMX_GROUP gp2 = kp->dpGroupArray; - for(UINT i = 0; i < kp->cxGroupArray - 1; i++, gp2++) { - if(gp2->fUsingKeys && gp2->dpNoMatch == NULL) { - KMX_WCHAR *p = gp2->dpNoMatch = new KMX_WCHAR[4]; + for (UINT i = 0; i < kp->cxGroupArray - 1; i++, gp2++) { + if (gp2->fUsingKeys && gp2->dpNoMatch == NULL) { + KMX_WCHAR* p = gp2->dpNoMatch = new KMX_WCHAR[4]; *p++ = UC_SENTINEL; *p++ = CODE_USE; *p++ = (KMX_WCHAR)(kp->cxGroupArray); @@ -518,19 +491,19 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke // UINT j; LPKMX_KEY kkp; - for(j = 0, kkp = gp->dpKeyArray; j < gp->cxKeyArray; j++, kkp++) { - if((kkp->ShiftFlags & (K_CTRLFLAG|K_ALTFLAG|LCTRLFLAG|LALTFLAG|RCTRLFLAG|RALTFLAG)) != 0) { + for (j = 0, kkp = gp->dpKeyArray; j < gp->cxKeyArray; j++, kkp++) { + if ((kkp->ShiftFlags & (K_CTRLFLAG | K_ALTFLAG | LCTRLFLAG | LALTFLAG | RCTRLFLAG | RALTFLAG)) != 0) { gp2->cxKeyArray++; LPKMX_KEY kkp2 = new KMX_KEY[gp2->cxKeyArray]; - memcpy(kkp2, gp2->dpKeyArray, sizeof(KMX_KEY)*(gp2->cxKeyArray-1)); + memcpy(kkp2, gp2->dpKeyArray, sizeof(KMX_KEY) * (gp2->cxKeyArray - 1)); gp2->dpKeyArray = kkp2; - kkp2 = &kkp2[gp2->cxKeyArray-1]; - kkp2->dpContext = new KMX_WCHAR; + kkp2 = &kkp2[gp2->cxKeyArray - 1]; + kkp2->dpContext = new KMX_WCHAR; *kkp2->dpContext = 0; kkp2->Key = kkp->Key; kkp2->ShiftFlags = kkp->ShiftFlags; kkp2->Line = 0; - KMX_WCHAR *p = kkp2->dpOutput = new KMX_WCHAR[4]; + KMX_WCHAR* p = kkp2->dpOutput = new KMX_WCHAR[4]; *p++ = UC_SENTINEL; *p++ = CODE_USE; *p++ = (KMX_WCHAR)(kp->cxGroupArray); @@ -544,21 +517,21 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke // We only do this if not in deadkey conversion mode // - if (alDead.size() > 0 && !bDeadkeyConversion) { // I4552 + if (alDead.size() > 0 && !bDeadkeyConversion) { // I4552 kp->cxGroupArray++; - KMX_WCHAR *p = gp->dpMatch = new KMX_WCHAR[4]; + KMX_WCHAR* p = gp->dpMatch = new KMX_WCHAR[4]; *p++ = UC_SENTINEL; *p++ = CODE_USE; - *p++ = (KMX_WCHAR) kp->cxGroupArray; + *p++ = (KMX_WCHAR)kp->cxGroupArray; *p = 0; gp++; gp->fUsingKeys = FALSE; - gp->dpMatch = NULL; - gp->dpName = NULL; - gp->dpNoMatch = NULL; + gp->dpMatch = NULL; + gp->dpName = NULL; + gp->dpNoMatch = NULL; gp->cxKeyArray = alDead.size(); LPKMX_KEY kkp = gp->dpKeyArray = new KMX_KEY[alDead.size()]; @@ -571,13 +544,13 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke int nStoreBase = kp->cxStoreArray; kp->cxStoreArray += alDead.size() * 2; - for(UINT i = 0; i < alDead.size(); i++) { - DeadKey *dk = alDead[i]; + for (UINT i = 0; i < alDead.size(); i++) { + DeadKey* dk = alDead[i]; sp->dpName = NULL; sp->dwSystemID = 0; sp->dpString = new KMX_WCHAR[dk->KMX_Count() + 1]; - for(int j = 0; j < dk->KMX_Count(); j++) + for (int j = 0; j < dk->KMX_Count(); j++) sp->dpString[j] = dk->KMX_GetBaseCharacter(j); sp->dpString[dk->KMX_Count()] = 0; sp++; @@ -585,7 +558,7 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke sp->dpName = NULL; sp->dwSystemID = 0; sp->dpString = new KMX_WCHAR[dk->KMX_Count() + 1]; - for(int j = 0; j < dk->KMX_Count(); j++) + for (int j = 0; j < dk->KMX_Count(); j++) sp->dpString[j] = dk->KMX_GetCombinedCharacter(j); sp->dpString[dk->KMX_Count()] = 0; sp++; @@ -593,26 +566,25 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke kkp->Line = 0; kkp->ShiftFlags = 0; kkp->Key = 0; - KMX_WCHAR *p = kkp->dpContext = new KMX_WCHAR[8]; + KMX_WCHAR* p = kkp->dpContext = new KMX_WCHAR[8]; *p++ = UC_SENTINEL; *p++ = CODE_DEADKEY; - // can convert since KMX_DeadKeyMap returns a small positive number - *p++ = (KMX_WCHAR) KMX_DeadKeyMap(dk->KMX_DeadCharacter(), &alDead, nDeadkey, FDeadkeys); // I4353 + *p++ = KMX_DeadKeyMap(dk->KMX_DeadCharacter(), &alDead, nDeadkey, FDeadkeys); // I4353 // *p++ = nDeadkey+i; *p++ = UC_SENTINEL; *p++ = CODE_ANY; - *p++ = nStoreBase + i*2 + 1; + *p++ = nStoreBase + i * 2 + 1; *p = 0; p = kkp->dpOutput = new KMX_WCHAR[5]; *p++ = UC_SENTINEL; *p++ = CODE_INDEX; - *p++ = nStoreBase + i*2 + 2; + *p++ = nStoreBase + i * 2 + 2; *p++ = 2; *p = 0; kkp++; } } -return true; + return true; } diff --git a/linux/mcompile/keymap/mc_kmxfile.h b/linux/mcompile/keymap/mc_kmxfile.h index b68b5e4707..22c9255481 100755 --- a/linux/mcompile/keymap/mc_kmxfile.h +++ b/linux/mcompile/keymap/mc_kmxfile.h @@ -3,7 +3,7 @@ #define MC_KMXFILE_H #include "km_types.h" -#include <../../../../common/include/kmx_file.h> +#include #include "filesystem.h" #include "mcompile.h" diff --git a/linux/mcompile/keymap/mcompile.cpp b/linux/mcompile/keymap/mcompile.cpp index 6e5c83d672..64d00273b6 100755 --- a/linux/mcompile/keymap/mcompile.cpp +++ b/linux/mcompile/keymap/mcompile.cpp @@ -23,7 +23,7 @@ 08 Apr 2015 - mcdurdin - I4651 - V9.0 - Mnemonic layout recompiler maps AltGr+VK_BKSLASH rather than VK_OEM_102 */ // -// m-to-p.cpp : Defines the entry point for the console application. +// Defines the entry point for the console application. // // Note: this program deliberately leaks memory as it has a very short life cycle and managing the memory allocations // for the subcomponents of the compiled keyboard is an unnecessary optimisation. Just so you know. @@ -499,4 +499,3 @@ void KMX_LogError(const wchar_t* fmt, ...) { while(fmtbuf[j] != *end); putwchar(*nl); } - diff --git a/linux/mcompile/keymap/meson.build b/linux/mcompile/keymap/meson.build index d8f71ffaea..237ff81132 100755 --- a/linux/mcompile/keymap/meson.build +++ b/linux/mcompile/keymap/meson.build @@ -19,9 +19,14 @@ cpp_files = files( 'mc_import_rules.cpp', 'u16.cpp',) +comon_include_dir = [ + include_directories('../../../../common/include'), +] + + mcompile = executable( 'mcompile', sources: [cpp_files], - dependencies: deps + dependencies: deps, + include_directories : comon_include_dir ) -