From 56c6be2aa29cb3be3bc8fb709cecdb6165f2ed30 Mon Sep 17 00:00:00 2001 From: Sabine Date: Thu, 1 Aug 2024 15:08:58 +0200 Subject: [PATCH] feat(linux): comments of PR 12065 # Conflicts: # linux/mcompile/keymap/keymap.h # linux/mcompile/keymap/mcompile.cpp --- linux/mcompile/keymap/deadkey.cpp | 2 +- linux/mcompile/keymap/deadkey.h | 63 ++++++----- linux/mcompile/keymap/keymap.cpp | 12 +-- linux/mcompile/keymap/keymap.h | 126 +++++++++++----------- linux/mcompile/keymap/mc_import_rules.cpp | 29 ++--- linux/mcompile/keymap/mc_import_rules.h | 20 ++-- linux/mcompile/keymap/mc_kmxfile.cpp | 50 ++++----- linux/mcompile/keymap/mc_kmxfile.h | 34 +++--- linux/mcompile/keymap/mcompile.cpp | 126 ++++++++++++---------- linux/mcompile/keymap/mcompile.h | 1 - linux/mcompile/keymap/u16.cpp | 76 ++++++------- linux/mcompile/keymap/u16.h | 113 ++++++++++--------- 12 files changed, 331 insertions(+), 321 deletions(-) diff --git a/linux/mcompile/keymap/deadkey.cpp b/linux/mcompile/keymap/deadkey.cpp index b7ebc1c665..1452d643ab 100644 --- a/linux/mcompile/keymap/deadkey.cpp +++ b/linux/mcompile/keymap/deadkey.cpp @@ -1,5 +1,5 @@ /* - * Keyman is copyright (C) 2004 SIL International. MIT License. + * Keyman is copyright (C) 2004 - 2024 SIL International. MIT License. * * Mnemonic layout support for Linux */ diff --git a/linux/mcompile/keymap/deadkey.h b/linux/mcompile/keymap/deadkey.h index 8f1c61f355..6e7bd7be58 100644 --- a/linux/mcompile/keymap/deadkey.h +++ b/linux/mcompile/keymap/deadkey.h @@ -7,66 +7,65 @@ #include /** - * @brief create a Vector of DeadKey containing all combinations of deadkey + character for ALL possible Linux keyboards + * @brief create a Vector of DeadKey containing all combinations of deadkey + character for ALL possible Linux keyboards * @return vector of Deadkey* that holds all combinations of deadkey + character */ std::vector create_deadkeys_by_basechar(); /** - * @brief filter entries for the currently used Linux Keyboard out of a vector of all existing deadKey combinations - * @param dk the deadkey for which all combinations will be found - * @param [in,out] dkVec combinations of deadkey + character for the currently used Linux Keyboard - * @param r_All_Vec all existing combinations of deadkey + character for ALL possible Linux keyboards - * @return void + * @brief filter entries for the currently used Linux Keyboard out of a vector of all existing deadKey combinations + * @param dk the deadkey for which all combinations will be found + * @param[in,out] dkVec combinations of deadkey + character for the currently used Linux Keyboard + * @param r_All_Vec all existing combinations of deadkey + character for ALL possible Linux keyboards */ void refine_alDead(KMX_WCHAR dk, std::vector& dkVec, std::vector& r_All_Vec); /** - * @brief check whether a deadkey already exists in the deadkey vector - * @param dk the deadkey to be found - * @param dkVec vector containing combinations of deadkey + character + * @brief check whether a deadkey already exists in the deadkey vector + * @param dk the deadkey to be found + * @param dkVec vector containing combinations of deadkey + character * @return true if deadkey alredy exists; * false if not */ bool found_dk_inVector(KMX_WCHAR dk, std::vector& dkVec); /** - * @brief find all deadkey combinations for a certain deadkey in a vector of all deadkey combinations - * @param r_dk_ComposeTable vector containing all possible deadkey combinations - * @param dk deadkey of interest - * @param [in,out] dk_SingleTable vector containing all dk-character combinations for a specific deadkey dk - * @return true if successful; false if not + * @brief find all deadkey combinations for a certain deadkey in a vector of all deadkey combinations + * @param r_dk_ComposeTable vector containing all possible deadkey combinations + * @param dk deadkey of interest + * @param[in,out] dk_SingleTable vector containing all dk-character combinations for a specific deadkey dk + * @return true if successful; + * false if not */ bool query_dk_combinations_for_specific_dk(vec_dword_2D& dk_ComposeTable, KMX_DWORD dk, vec_dword_2D& dk_SingleTable); /** - * @brief convert a character to the upper-case equivalent and find the corresponding shiftstate - * of the entered keyval: a(97) -> A(65) + Base A(65) -> A(65) + Shift - * @param kval keyval that might be changed - * @param [in,out] shift the shiftstate of the entered keyval - * @param keymap a pointer to the currently used (underlying) keyboard layout + * @brief convert a character to the upper-case equivalent and find the corresponding shiftstate + * of the entered keyval: a(97) -> A(65) + Base A(65) -> A(65) + Shift + * @param kval keyval that might be changed + * @param[in,out] shift the shiftstate of the entered keyval + * @param keymap a pointer to the currently used (underlying) keyboard layout * @return the upper case equivalent of the keyval */ KMX_DWORD KMX_change_keyname_to_capital(KMX_DWORD kVal, KMX_DWORD& shift, GdkKeymap* keymap); /** - * @brief append a 1D-vector containing name, base character and unicode_value to a 2D-Vector - * holding all possible combinations of deadkey + character for all Linux keyboards - * @param [in,out] dk_ComposeTable - * @param diacritic_name the name of a diacritic - * @param base_char Base character - * @param unicode_value Unicode-value of the combined character - * @return void + * @brief append a 1D-vector containing name, base character and unicode_value to a 2D-Vector + * holding all possible combinations of deadkey + character for all Linux keyboards + * @param[in,out] dk_ComposeTable 2D-Vector holding all possible combinations of deadkey + character + * @param diacritic_name the name of a diacritic + * @param base_char base character + * @param unicode_value Unicode-value of the combined character */ void add_deadkey_combination(vec_dword_2D& dk_ComposeTable, std::string diacritic_name, std::string base_char, KMX_DWORD unicode_value); /** - * @brief create a 2D-Vector containing all possible combinations of deadkey + character for all Linux keyboards - * the values are taken from from: https://help.ubuntu.com/community/GtkDeadKeyTable#Accents - * dk_ComposeTable[i][0] : diacritic_name (e.g. dead_circumflex) - * dk_ComposeTable[i][1] : base_char (e.g. a) - * dk_ComposeTable[i][2] : unicode_value-Value (e.g. 0x00E2) - * @param [in,out] dk_ComposeTable + * @brief create a 2D-Vector containing all possible combinations of deadkey + character for all Linux keyboards + * the values are taken from from: https://help.ubuntu.com/community/GtkDeadKeyTable#Accents + * dk_ComposeTable[i][0] : diacritic_name (e.g. dead_circumflex) + * dk_ComposeTable[i][1] : base_char (e.g. a) + * dk_ComposeTable[i][2] : unicode_value-Value (e.g. 0x00E2) + * @param[in,out] dk_ComposeTable */ void create_DKTable(vec_dword_2D& dk_ComposeTable); diff --git a/linux/mcompile/keymap/keymap.cpp b/linux/mcompile/keymap/keymap.cpp index 9f31256152..327c9fc24c 100644 --- a/linux/mcompile/keymap/keymap.cpp +++ b/linux/mcompile/keymap/keymap.cpp @@ -1,5 +1,5 @@ /* - * Keyman is copyright (C) 2004 SIL International. MIT License. + * Keyman is copyright (C) 2004 - 2024 SIL International. MIT License. * * Mnemonic layout support for Linux * @@ -388,7 +388,7 @@ bool createCompleteVector_US(vec_string_1D& complete_List) { if (!inputFile.is_open()) { printf("ERROR: could not open file!\n"); - return 1; + return TRUE; } else { @@ -410,7 +410,7 @@ bool createCompleteVector_US(vec_string_1D& complete_List) { complete_List.push_back(" key { [ space, space] };"); inputFile.close(); - return 0; + return FALSE; } /** @brief convert the key name obtained from symbol file to the matching keycode */ @@ -640,17 +640,17 @@ bool InitializeGDK(GdkKeymap** keymap, int argc, gchar* argv[]) { GdkDisplay* display = gdk_display_get_default(); if (!display) { printf("ERROR: can't get display\n"); - return 1; + return TRUE; } *keymap = gdk_keymap_get_for_display(display); if (!keymap) { printf("ERROR: Can't get keymap\n"); gdk_display_close(display); - return 2; + return TRUE; } // intentionally leaking `display` in order to still be able to access `keymap` - return 0; + return FALSE; } /** @brief check if keyval correponds to a character we use in mcompile */ diff --git a/linux/mcompile/keymap/keymap.h b/linux/mcompile/keymap/keymap.h index 91e9e16ea2..60655c80a8 100644 --- a/linux/mcompile/keymap/keymap.h +++ b/linux/mcompile/keymap/keymap.h @@ -65,8 +65,9 @@ static KMX_DWORD deadkey_min = 0xfe50; // X11's keysymdef.h defines deadkeys b static KMX_DWORD deadkey_max = 0xfe93; // https://fossies.org/linux/tk/xlib/X11/keysymdef.h /** - * @brief check if current machine uses little endian - * @return true if little endian is used; else false + * @brief check if current machine uses little endian + * @return true if little endian is used; + * else false */ inline bool isLittleEndianSystem() { char16_t test = 0x0102; @@ -103,52 +104,54 @@ bool ensureValidInputForKeyboardTranslation(int shiftstate, gint keycode); KMX_DWORD convertNamesTo_DWORD_Value(std::string tok_str); /** - * @brief create a 3D-Vector containing data of the US keyboard and the currently used (underlying) keyboard : - * all_vector [ US_Keyboard ] - * [KeyCode_US ] - * [Keyval unshifted ] - * [Keyval shifted ] + * @brief create a 3D-Vector containing data of the US keyboard and the currently used (underlying) keyboard : + * all_vector [ US_Keyboard ] + * [KeyCode_US ] + * [Keyval unshifted ] + * [Keyval shifted ] * [Underlying Kbd] - * [KeyCode_underlying] - * [Keyval unshifted ] - * [Keyval shifted ] + * [KeyCode_underlying] + * [Keyval unshifted ] + * [Keyval shifted ] * @param[in,out] all_vector Vector that holds the data of the US keyboard as well as the currently used (underlying) keyboard - * @param keymap pointer to currently used (underlying) keyboard layout - * @return 0 on success; - * 1 if data of US keyboard was not written; - * 2 if data of underlying keyboard was not written + * @param keymap pointer to currently used (underlying) keyboard layout + * @return 0 on success; + * 1 if data of US keyboard was not written; + * 2 if data of underlying keyboard was not written */ int createOneVectorFromBothKeyboards(vec_dword_3D& all_vector, GdkKeymap* keymap); /** - * @brief write data of the US keyboard into a 3D-Vector which later will contain - * data of the US keyboard and the currently used (underlying) keyboard + * @brief write data of the US keyboard into a 3D-Vector which later will contain + * data of the US keyboard and the currently used (underlying) keyboard * @param[in,out] vec_us Vector that holds the data of the US keyboard - * @return 0 on success; - * 1 if data of US keyboard was not written; + * @return 0 on success; + * 1 if data of US keyboard was not written; */ int write_US_ToVector(vec_dword_3D& vec_us); /** - * @brief create a 1D-Vector containing all relevant entries of the symbol file us basic - * @param [in,out] complete_List the 1D-Vector - * @return 0 on success; 1 if file could not be opened + * @brief create a 1D-Vector containing all relevant entries of the symbol file us basic + * @param[in,out] complete_List the 1D-Vector + * @return FALSE on success; + * TRUE if file could not be opened */ bool createCompleteVector_US(vec_string_1D& complete_List); /** - * @brief convert the key name obtained from symbol file to the matching keycode - * e.g. name of Key ) --> Keycode 15 - * @param key_name as stated in the symbol file + * @brief convert the key name obtained from symbol file to the matching keycode + * e.g. name of Key ) --> Keycode 15 + * @param key_name as stated in the symbol file * @return the equivalent keycode */ int get_keycode_from_keyname(std::string key_name); /** - * @brief process each element of a 1D-Vector, split and write to a 3D-Vector - * @param [in,out] all_US a 3D_Vector containing all keyvalues of the US keyboard - * @param completeList a 1D-Vector containing all relevant entries copied from the symbol file us basic - * @return 0 on success; 1 if entry can be split + * @brief process each element of a 1D-Vector, split and write to a 3D-Vector + * @param[in,out] all_US a 3D_Vector containing all keyvalues of the US keyboard + * @param completeList a 1D-Vector containing all relevant entries copied from the symbol file us basic + * @return 0 on success; + * if entry can be split */ int split_US_To_3D_Vector(vec_dword_3D& all_US, vec_string_1D completeList); @@ -161,21 +164,22 @@ int split_US_To_3D_Vector(vec_dword_3D& all_US, vec_string_1D completeList); vec_dword_2D create_empty_2D_Vector(int dim_rows, int dim_ss); /** - * @brief append a 2D-vector containing data of the currently used (underlying) keyboard to the 3D-vector + * @brief append a 2D-vector containing data of the currently used (underlying) keyboard to the 3D-vector * @param[in,out] all_vector 3D-vector that holds the data of the US keyboard and the currently used (underlying) keyboard - * @param keymap pointer to currently used (underlying) keybord layout - * @return 0 on success; - * 1 if the initialization of the underlying vector failes; - * 2 if data of less than 2 keyboards is contained in all_vector + * @param keymap pointer to currently used (underlying) keybord layout + * @return 0 on success; + * 1 if the initialization of the underlying vector failes; + * 2 if data of less than 2 keyboards is contained in all_vector */ int append_underlying_ToVector(vec_dword_3D& all_vector, GdkKeymap* keymap); /** * @brief create a pointer to pointer of the current keymap for later use - * @param keymap pointer to pointer to currently used (underlying) keyborad layout - * @param argc count of arguments - * @param argv array of arguments - * @return 0 on success; 1 if the display is not found; 2 if the keymap is not found + * @param keymap pointer to pointer to currently used (underlying) keyborad layout + * @param argc count of arguments + * @param argv array of arguments + * @return FALSE on success; + * TRUE if the display or keymap is not found */ bool InitializeGDK(GdkKeymap** keymap, int argc, gchar* argv[]); @@ -579,17 +583,19 @@ const UINT ScanCodeToUSVirtualKey[128] = { }; /** - * @brief check if keyval correponds to a character used in mcompile - * @param kv the keyval to be checked - * @return 1 if keyval is used in mcompile; 0 if not + * @brief check if keyval correponds to a character used in mcompile + * @param kv the keyval to be checked + * @return true if keyval is used in mcompile; + * false if not */ bool IsKeymanUsedChar(int kv); /** - * @brief convert a deadkey-value to a u16string if it is in the range of - * deadkeys used for mcompile e.g. 65106 -> '^' - * @param in value to be converted - * @return on success a u16string holding the converted value; else u"\0" + * @brief convert a deadkey-value to a u16string if it is in the range of + * deadkeys used for mcompile e.g. 65106 -> '^' + * @param in value to be converted + * @return on success a u16string holding the converted value; + * else u"\0" */ std::u16string convert_DeadkeyValues_To_U16str(KMX_DWORD in); @@ -597,10 +603,10 @@ std::u16string convert_DeadkeyValues_To_U16str(KMX_DWORD in); * @brief return the keyvalue for a given Keycode, shiftstate and caps of the * currently used (underlying) keyboard layout * "What character will be produced for a keypress of a key and modifier?" - * @param keymap pointer to the currently used (underlying) keyboard layout + * @param keymap pointer to the currently used (underlying) keyboard layout * @param keycode a key of the currently used keyboard layout - * @param ss a (windows-)shiftstate of the currently used keyboard layout - * @param caps state of the caps key of the currently used keyboard layout + * @param ss a (windows-)shiftstate of the currently used keyboard layout + * @param caps state of the caps key of the currently used keyboard layout * @return the keyval obtained from keycode, shiftstate and caps */ KMX_DWORD KMX_get_KeyVal_From_KeyCode(GdkKeymap* keymap, guint keycode, ShiftState ss, int caps); @@ -608,8 +614,8 @@ KMX_DWORD KMX_get_KeyVal_From_KeyCode(GdkKeymap* keymap, guint keycode, ShiftSta /** * @brief return the keyvalue for a given Keycode and shiftstate of the currently used (underlying) keyboard layout. * "What character will be produced for a keypress of a key and modifiers on the underlying keyboard?" - * @param keymap a pointer to the currently used (underlying) keyboard layout - * @param keycode a key of the currently used keyboard + * @param keymap a pointer to the currently used (underlying) keyboard layout + * @param keycode a key of the currently used keyboard * @param shift_state_pos a shiftstate of the currently used keyboard layout * @return the keyval obtained from Keycode and shiftstate; */ @@ -617,14 +623,14 @@ KMX_DWORD KMX_get_KeyValUnderlying_From_KeyCodeUnderlying(GdkKeymap* keymap, gui /** * @brief return the keyvalue for a given Keycode and shiftstate of the currently used (underlying) keyboard layout. - * "What character will be produced for a keypress of a key and modifiers on the underlying keyboard? + * "What character will be produced for a keypress of a key and modifiers on the underlying keyboard?" * If a deadkey was found return 0xFFFF and copy the deadkey into deadKey * This function is similar to KMX_DWORD KMX_get_KeyValUnderlying_From_KeyCodeUnderlying(GdkKeymap* keymap, guint keycode, int shiftState) * but processes deadkeys - * @param keymap a pointer to the currently used (underlying) keyboard layout - * @param keycode a key of the currently used keyboard + * @param keymap a pointer to the currently used (underlying) keyboard layout + * @param keycode a key of the currently used keyboard * @param shiftState a shiftstate of the currently used keyboard layout - * @param deadKey* pointer to keyvalue if a deadkey was found; if not NULL + * @param deadKey* pointer to keyvalue if a deadkey was found; if not NULL * @return 0xFFFF in case a deadkey was found, then the deadkey is stored in deadKey * 0xFFFE in case a deadkey is out of range * the keyval obtained from Keycode and shiftstate and caps; @@ -635,7 +641,7 @@ KMX_DWORD KMX_get_KeyValUnderlying_From_KeyCodeUnderlying(GdkKeymap* keymap, gui * @brief return the keyvalue of a key of the the currently used (underlying) keyboard for a given keyvalue of the US keyboard * "What character is on the same position/shiftstats/caps on the currently used (underlying) keyboard as on the US keyboard?" * @param all_vector 3D-vector that holds the data of the US keyboard and the currently used (underlying) keyboard - * @param kv_us a keyvalue on the US keyboard + * @param kv_us a keyvalue on the US keyboard * @return keyval of the underlying keyboard if available; * else the keyval of the US keyboard */ @@ -644,18 +650,18 @@ KMX_DWORD KMX_get_KeyValUnderlying_From_KeyValUS(vec_dword_3D& all_vector, KMX_D /** * @brief return the keycode of the currently used (underlying) keyboard for a given keycode of the US keyboard * "Where on an underlying keyboard do we find a character that is on a certain key on a US keyboard?" - * @param keymap the currently used (underlying) keyboard layout + * @param keymap the currently used (underlying) keyboard layout * @param all_vector 3D-vector that holds the data of the US keyboard and the currently used (underlying) keyboard - * @param kc_us a key of the US keyboard - * @param ss a windows-type shiftstate - * @param caps state of the caps key + * @param kc_us a key of the US keyboard + * @param ss a windows-type shiftstate + * @param caps state of the caps key * @return the keycode of the underlying keyboard if found; * else the keycode of the US keyboard */ KMX_DWORD KMX_get_KeyCodeUnderlying_From_KeyCodeUS(GdkKeymap* keymap, vec_dword_3D& all_vector, KMX_DWORD kc_us, ShiftState ss, int caps); /** - * @brief return the keycode of the currently used (underlying) keyboard for a given virtual key of the US keyboard + * return the keycode of the currently used (underlying) keyboard for a given virtual key of the US keyboard * "Where on an underlying keyboard do we find a character of a US keyboard?" * @param virtualKeyUS a virtual key of the US keyboard * @return the keycode of the currently used (underlying) keyboard @@ -663,7 +669,7 @@ KMX_DWORD KMX_get_KeyCodeUnderlying_From_KeyCodeUS(GdkKeymap* keymap, vec_dword_ KMX_DWORD KMX_get_KeyCodeUnderlying_From_VKUS(KMX_DWORD virtualKeyUS); /** - * @brief return a virtual key of the US keyboard for a given keycode of the currently used (underlying) keyboard + * return a virtual key of the US keyboard for a given keycode of the currently used (underlying) keyboard * "Which key of a underlying keyboard will be mapped to a virtual key of a US keyboard?" * @param keycode a keycode of the currently used (underlying) keyboard * @return the virtual key of the US keyboard or diff --git a/linux/mcompile/keymap/mc_import_rules.cpp b/linux/mcompile/keymap/mc_import_rules.cpp index 77bec96b89..69ad4ed398 100644 --- a/linux/mcompile/keymap/mc_import_rules.cpp +++ b/linux/mcompile/keymap/mc_import_rules.cpp @@ -1,9 +1,10 @@ /* - * Keyman is copyright (C) 2004 SIL International. MIT License. + * Keyman is copyright (C) 2004 - 2024 SIL International. MIT License. * * Mnemonic layout support for Linux */ + #include #include #include @@ -27,7 +28,7 @@ DeadKey::DeadKey(KMX_WCHAR deadCharacter) { this->m_deadchar = deadCharacter; } -/** @brief return dead character */ +/** @brief return dead character */ KMX_WCHAR DeadKey::KMX_DeadCharacter() { return this->m_deadchar; } @@ -56,11 +57,11 @@ bool DeadKey::KMX_ContainsBaseCharacter(KMX_WCHAR baseCharacter) { * This is because it is used in mcompile only which only deals with latin scripts. * In case this function should be used for surrogate pairs, they will be ignored and a message will be printed out - * @param keycode a key of the currently used keyboard Layout + * @param keycode a key of the currently used keyboard Layout * @param pwszBuff Buffer to store resulting character - * @param ss a shiftstate of the currently used keyboard Layout - * @param caps state of the caps key of the currently used keyboard Layout - * @param keymap the currently used (underlying)keyboard Layout + * @param ss a shiftstate of the currently used keyboard Layout + * @param caps state of the caps key of the currently used keyboard Layout + * @param keymap the currently used (underlying)keyboard Layout * @return -1 if a deadkey was found; * 0 if no translation is available; * +1 if character was found and written to pwszBuff @@ -119,7 +120,7 @@ KMX_WCHAR KMX_DeadKeyMap(int index, std::vector* deadkeys, int deadkey return 0xFFFF; } -/** @brief Base class for dealing with rgkey*/ +/** @brief Base class for dealing with rgkey*/ class KMX_VirtualKey { private: UINT m_vk; @@ -339,7 +340,7 @@ public: } }; -/** @brief Base class for KMX_loader*/ +/** @brief Base class for KMX_loader*/ class KMX_Loader { private: KMX_BYTE lpKeyStateNull[256]; @@ -369,8 +370,8 @@ public: }; /** - * @brief find the maximum index of a deadkey - * @param p pointer to deadkey + * @brief find the maximum index of a deadkey + * @param p pointer to deadkey * @return index of deadkey */ int KMX_GetMaxDeadkeyIndex(KMX_WCHAR* p) { @@ -390,10 +391,10 @@ int KMX_GetMaxDeadkeyIndex(KMX_WCHAR* p) { * On Linux the values of rgkey are sorted according to the VK of the the US keyboard * Since Linux Keyboards do not use a VK mcompile uses the VK of the the US keyboard because * these are available in mcompile through USVirtualKeyToScanCode/ScanCodeToUSVirtualKey and an offset of 8 - * @param kp pointer to keyboard - * @param all_vector vector that holds the data of the US keyboard and the currently used (underlying) keyboard - * @param keymap the currently used (underlying)keyboard Layout - * @param FDeadkeys vector of all deadkeys for the currently used (underlying)keyboard Layout + * @param kp pointer to keyboard + * @param all_vector vector that holds the data of the US keyboard and the currently used (underlying) keyboard + * @param keymap the currently used (underlying)keyboard Layout + * @param FDeadkeys vector of all deadkeys for the currently used (underlying)keyboard Layout * @param bDeadkeyConversion 1 to convert a deadkey to a character; 0 no conversion * @return true in case of success */ diff --git a/linux/mcompile/keymap/mc_import_rules.h b/linux/mcompile/keymap/mc_import_rules.h index a6c2cc014a..583890968f 100644 --- a/linux/mcompile/keymap/mc_import_rules.h +++ b/linux/mcompile/keymap/mc_import_rules.h @@ -3,7 +3,7 @@ #ifndef MC_IMPORT_RULES_H #define MC_IMPORT_RULES_H -/** @brief Base class for Deadkey*/ +/** @brief Base class for Deadkey*/ class DeadKey { private: KMX_WCHAR m_deadchar; @@ -12,8 +12,8 @@ private: public: /** - * @brief Constructor - * @param deadCharacter a deadkey + * @brief Constructor + * @param deadCharacter a deadkey */ DeadKey(KMX_WCHAR deadCharacter); @@ -24,10 +24,9 @@ public: KMX_WCHAR KMX_DeadCharacter(); /** - * @brief set Deadkey with values - * @param baseCharacter the base character - * @param combinedCharacter the combined character - * @return void + * @brief set Deadkey with values + * @param baseCharacter the base character + * @param combinedCharacter the combined character */ void KMX_AddDeadKeyRow(KMX_WCHAR baseCharacter, KMX_WCHAR combinedCharacter); @@ -48,9 +47,10 @@ public: } /** - * @brief check if character exists in DeadKey - * @param baseCharacter a character to be found - * @return true if found; false if not found + * @brief check if character exists in DeadKey + * @param baseCharacter a character to be found + * @return true if found; + * false if not found */ bool KMX_ContainsBaseCharacter(KMX_WCHAR baseCharacter); }; diff --git a/linux/mcompile/keymap/mc_kmxfile.cpp b/linux/mcompile/keymap/mc_kmxfile.cpp index e06e95f563..2988fe151b 100644 --- a/linux/mcompile/keymap/mc_kmxfile.cpp +++ b/linux/mcompile/keymap/mc_kmxfile.cpp @@ -1,5 +1,5 @@ /* - * Keyman is copyright (C) 2004 SIL International. MIT License. + * Keyman is copyright (C) 2004 - 2024 SIL International. MIT License. * * Mnemonic layout support for Linux */ @@ -43,28 +43,28 @@ const int CODE__SIZE[] = { /** * @brief check if the file has correct version - * @param filebase containing data of the input file - * @param file_size a size + * @param filebase containing data of the input file + * @param file_size a size * @return true if successful; * false if not */ KMX_BOOL KMX_VerifyKeyboard(LPKMX_BYTE filebase, KMX_DWORD file_size); /** - * @brief Fixup the keyboard by expanding pointers. On disk the pointers are stored relative to the - * beginning of the file, but we need real pointers. This method is used on 32-bit architectures. - * @param bufp pointer to buffer where data will be copied into - * @param base pointer to starting point - * @param dwFileSize size of the file + * @brief Fixup the keyboard by expanding pointers. On disk the pointers are stored relative to the + * beginning of the file, but we need real pointers. This method is used on 32-bit architectures. + * @param bufp pointer to buffer where data will be copied into + * @param base pointer to starting point + * @param dwFileSize size of the file * @return pointer to the keyboard */ LPKMX_KEYBOARD KMX_FixupKeyboard(PKMX_BYTE bufp, PKMX_BYTE base, KMX_DWORD dwFileSize); /** - * @brief Save a Keyboard to a file - * @param fk pointer to the keyboard - * @param hOutfile pointer to the output file - * @param FSaveDebug + * @brief Save a Keyboard to a file + * @param fk pointer to the keyboard + * @param hOutfile pointer to the output file + * @param FSaveDebug * @return an Error in case of failure */ KMX_DWORD KMX_WriteCompiledKeyboardToFile(LPKMX_KEYBOARD fk, FILE* hOutfile, KMX_BOOL FSaveDebug) { @@ -253,9 +253,9 @@ KMX_BOOL KMX_SaveKeyboard(LPKMX_KEYBOARD kbd, KMX_CHAR* filename) { } /** - * @brief add an offset - * @param base pointer to starting point - * @param offset a given offset + * @brief add an offset + * @param base pointer to starting point + * @param offset a given offset * @return pointer to base + offset */ PKMX_WCHAR KMX_StringOffset(PKMX_BYTE base, KMX_DWORD offset) { @@ -267,12 +267,12 @@ PKMX_WCHAR KMX_StringOffset(PKMX_BYTE base, KMX_DWORD offset) { #ifdef KMX_64BIT /** - * @brief CopyKeyboard will copy the data into bufp from x86-sized structures into - * x64-sized structures starting at `base`. After this function finishes, we still - * need to keep the original data because we don't copy the strings. The method is - * used on 64-bit architectures. - * @param bufp pointer to buffer where data is copied into - * @param base pointer to starting point + * @brief CopyKeyboard will copy the data into bufp from x86-sized structures into + * x64-sized structures starting at `base`. After this function finishes, we still + * need to keep the original data because we don't copy the strings. The method is + * used on 64-bit architectures. + * @param bufp pointer to buffer where data is copied into + * @param base pointer to starting point * @return pointer to the keyboard */ LPKMX_KEYBOARD CopyKeyboard(PKMX_BYTE bufp, PKMX_BYTE base) { @@ -550,15 +550,15 @@ PKMX_WCHAR KMX_incxstr(PKMX_WCHAR p) { } /** @brief open a file */ -FILE* Open_File(const KMX_CHAR* Filename, const KMX_CHAR* mode) { +FILE* Open_File(const KMX_CHAR* filename, const KMX_CHAR* mode) { #ifdef _MSC_VER - std::string cpath = Filename; //, cmode = mode; + std::string cpath = filename; //, cmode = mode; std::replace(cpath.begin(), cpath.end(), '/', '\\'); return fopen(cpath.c_str(), (const KMX_CHAR*)mode); #else - return fopen(Filename, mode); + return fopen(filename, mode); std::string cpath, cmode; - cpath = (const KMX_CHAR*)Filename; + cpath = (const KMX_CHAR*)filename; cmode = (const KMX_CHAR*)mode; return fopen(cpath.c_str(), cmode.c_str()); #endif diff --git a/linux/mcompile/keymap/mc_kmxfile.h b/linux/mcompile/keymap/mc_kmxfile.h index 78baf10810..1377820fb6 100644 --- a/linux/mcompile/keymap/mc_kmxfile.h +++ b/linux/mcompile/keymap/mc_kmxfile.h @@ -66,36 +66,38 @@ typedef struct KMX_tagKEYBOARD { } KMX_KEYBOARD, *LPKMX_KEYBOARD; /** - * @brief load a keyboard kmx-file - * @param fileName pointer to filename of kmx-file - * @param [in,out] lpKeyboard pointer to pointer to keyboard - * @return TRUE on success; else FALSE + * @brief load a keyboard kmx-file + * @param fileName pointer to filename of kmx-file + * @param[in,out] lpKeyboard pointer to pointer to keyboard + * @return TRUE on success; + * else FALSE */ KMX_BOOL KMX_LoadKeyboard(KMX_CHAR* fileName, LPKMX_KEYBOARD* lpKeyboard); /** - * @brief save keyboard to file - * @param kbd pointer to the keyboard - * @param filename pointer to filename of a kmx-file - * @return TRUE on success; else FALSE + * @brief save keyboard to file + * @param kbd pointer to the keyboard + * @param filename pointer to filename of a kmx-file + * @return TRUE on success; + * else FALSE */ KMX_BOOL KMX_SaveKeyboard(LPKMX_KEYBOARD kbd, KMX_CHAR* filename); /** - * @brief increment in a string - * @param p pointer to a character + * @brief increment in a string + * @param p pointer to a character * @return pointer to the incremented character */ PKMX_WCHAR KMX_incxstr(PKMX_WCHAR p); /** - * @brief open a file - * @param Filename name of the file - * @param mode same as mode in fopen - * @return pointer to file. On error, returns a null pointer + * @brief xx open a file + * @param filename name of the file + * @param mode same as mode in fopen + * @return pointer to file. + * On error returns a null pointer */ -FILE* Open_File(const KMX_CHAR* Filename, const KMX_CHAR* mode); -FILE* Open_File(const KMX_WCHAR* Filename, const KMX_WCHAR* mode); +FILE* Open_File(const KMX_CHAR* filename, const KMX_CHAR* mode); #endif // _KMXFILE_H diff --git a/linux/mcompile/keymap/mcompile.cpp b/linux/mcompile/keymap/mcompile.cpp index f74a3ea5df..3d96741dc7 100644 --- a/linux/mcompile/keymap/mcompile.cpp +++ b/linux/mcompile/keymap/mcompile.cpp @@ -1,5 +1,5 @@ /* - * Keyman is copyright (C) 2004 SIL International. MIT License. + * Keyman is copyright (C) 2004 - 2024 SIL International. MIT License. * * Mnemonic layout support for Linux * @@ -11,18 +11,37 @@ #include "mcompile.h" +/** + * @brief convert mnemonic keyboard layout to positional keyboard layout and translate keyboard + * @param kbd pointer to US keyboard + * @param bDeadkeyConversion option for converting a deadkey to a character: 1 = dk conversion; 0 = no dk conversion + * @param argc number of command line arguments + * @param argv pointer to command line arguments + * @return TRUE if conversion was successful; + * FALSE if not + */ KMX_BOOL KMX_DoConvert(LPKMX_KEYBOARD kbd, KMX_BOOL bDeadkeyConversion, gint argc, gchar* argv[]); -bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap** keymap, std::vector* KMX_FDeadkeys, KMX_BOOL bDeadkeyConversion); // I4353 // I4327 +/** @brief Collect the key data, translate it to kmx and append to the existing keyboard */ +bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap** keymap, std::vector* KMX_FDeadkeys, KMX_BOOL bDeadkeyConversion); // I4353 // I4327 +/** + * @brief start of mcompile; load, convert and save keyboard + * @param argc number of commandline arguments + * @param argv pointer to commandline arguments: executable, inputfile, outputfile + * @param argv_gdk pointer to (commandline arguments) + * @return 0 on success, + * 1 for wrong usage of calling parameters, + * 3 if unable to load keyboard + */ int run(int argc, char* argv[]); /** * @brief return an array of [usvk, ch_out] pairs: all existing combinations of a deadkey + character for the underlying keyboard - * @param dk_Table shiftstate of the deadkey - * @param deadkey deadkey character - * @param [out] outputPairs pointer to array of [usvk, ch_out] pairs - * @param keymap pointer to the currently used (underlying) keyboard Layout + * @param dk_Table shiftstate of the deadkey + * @param deadkey deadkey character + * @param[out] outputPairs pointer to array of [usvk, ch_out] pairs + * @param keymap pointer to the currently used (underlying) keyboard Layout * @return size of array of [usvk, ch_out] pairs */ int KMX_GetDeadkeys(vec_dword_2D& dk_Table, KMX_WORD deadkey, KMX_WORD* outputPairs, GdkKeymap* keymap); @@ -139,11 +158,10 @@ const UINT VKShiftState[] = {0, K_SHIFTFLAG, LCTRLFLAG | RALTFLAG, K_SHIFTFLAG | /** * @brief translate each key of a group: remap the content of a key (key->Key) of the US keyboard to a character (ch) - * @param key pointer to a key - * @param vk a keyvalue of the US keyboard + * @param key pointer to a key + * @param vk a keyvalue of the US keyboard * @param shift shiftstate - * @param ch character of the underlying keyboard to be remapped - * @return void + * @param ch character of the underlying keyboard to be remapped */ void KMX_TranslateKey(LPKMX_KEY key, KMX_WORD vk, UINT shift, KMX_WCHAR ch) { // The weird LCTRL+RALT is Windows' way of mapping the AltGr key. @@ -173,10 +191,9 @@ void KMX_TranslateKey(LPKMX_KEY key, KMX_WORD vk, UINT shift, KMX_WCHAR ch) { /** * @brief translate a group of a keyboard * @param group pointer to a keyboard group - * @param vk a keyvalue of the US keyboard + * @param vk a keyvalue of the US keyboard * @param shift shiftstate - * @param ch character of the underlying keyboard to be remapped - * @return void + * @param ch character of the underlying keyboard to be remapped */ void KMX_TranslateGroup(LPKMX_GROUP group, KMX_WORD vk, UINT shift, KMX_WCHAR ch) { for (unsigned int i = 0; i < group->cxKeyArray; i++) { @@ -186,11 +203,10 @@ void KMX_TranslateGroup(LPKMX_GROUP group, KMX_WORD vk, UINT shift, KMX_WCHAR ch /** * @brief translate a keyboard - * @param kbd pointer to the US keyboard - * @param vk a keyvalue of the US keyboard + * @param kbd pointer to the US keyboard + * @param vk a keyvalue of the US keyboard * @param shift shiftstate - * @param ch character of the underlying keyboard to be remapped - * @return void + * @param ch character of the underlying keyboard to be remapped */ void KMX_TranslateKeyboard(LPKMX_KEYBOARD kbd, KMX_WORD vk, UINT shift, KMX_WCHAR ch) { for (unsigned int i = 0; i < kbd->cxGroupArray; i++) { @@ -203,7 +219,6 @@ void KMX_TranslateKeyboard(LPKMX_KEYBOARD kbd, KMX_WORD vk, UINT shift, KMX_WCHA /** * @brief check key for unconverted key rules * @param key pointer to a key - * @return void */ void KMX_ReportUnconvertedKeyRule(LPKMX_KEY key) { if (key->ShiftFlags == 0) { @@ -216,7 +231,6 @@ void KMX_ReportUnconvertedKeyRule(LPKMX_KEY key) { /** * @brief check a group for unconverted rules * @param group pointer to a keyboard group - * @return void */ void KMX_ReportUnconvertedGroupRules(LPKMX_GROUP group) { for (unsigned int i = 0; i < group->cxKeyArray; i++) { @@ -227,7 +241,6 @@ void KMX_ReportUnconvertedGroupRules(LPKMX_GROUP group) { /** * @brief check a keyboard for unconverted rules * @param kbd pointer to the US keyboard - * @return void */ void KMX_ReportUnconvertedKeyboardRules(LPKMX_KEYBOARD kbd) { for (unsigned int i = 0; i < kbd->cxGroupArray; i++) { @@ -239,12 +252,11 @@ void KMX_ReportUnconvertedKeyboardRules(LPKMX_KEYBOARD kbd) { /** * @brief remap the content of a key (key->dpContext) of the US keyboard to a deadkey sequence - * @param key pointer to a key + * @param key pointer to a key * @param deadkey a deadkey to be remapped - * @param vk a keyvalue of the US keyboard - * @param shift shiftstate - * @param ch character of the underlying keyboard - * @return void + * @param vk a keyvalue of the US keyboard + * @param shift shiftstate + * @param ch character of the underlying keyboard */ void KMX_TranslateDeadkeyKey(LPKMX_KEY key, KMX_WCHAR deadkey, KMX_WORD vk, UINT shift, KMX_WORD ch) { @@ -278,12 +290,11 @@ void KMX_TranslateDeadkeyKey(LPKMX_KEY key, KMX_WCHAR deadkey, KMX_WORD vk, UINT /** * @brief translate a group - * @param group pointer to a keyboard group - * @param a deadkey to be remapped - * @param vk a keyvalue of the US keyboard - * @param shift shiftstate - * @param character of the underlying keyboard - * @return void + * @param group pointer to a keyboard group + * @param deadkey deadkey to be remapped + * @param vk a keyvalue of the US keyboard + * @param shift shiftstate + * @param ch character of the underlying keyboard */ void KMX_TranslateDeadkeyGroup(LPKMX_GROUP group, KMX_WCHAR deadkey, KMX_WORD vk, UINT shift, KMX_WORD ch) { for (unsigned int i = 0; i < group->cxKeyArray; i++) { @@ -293,12 +304,11 @@ void KMX_TranslateDeadkeyGroup(LPKMX_GROUP group, KMX_WCHAR deadkey, KMX_WORD vk /** * @brief translate a keyboard - * @param kbd pointer to the US keyboard - * @param a deadkey to be remapped - * @param vk a keyvalue of the US keyboard - * @param shift shiftstate - * @param character of the underlying keyboard - * @return void + * @param kbd pointer to the US keyboard + * @param deadkey a deadkey to be remapped + * @param vk a keyvalue of the US keyboard + * @param shift shiftstate + * @param ch character of the underlying keyboard */ void KMX_TranslateDeadkeyKeyboard(LPKMX_KEYBOARD kbd, KMX_WCHAR deadkey, KMX_WORD vk, UINT shift, KMX_WORD ch) { for (unsigned int i = 0; i < kbd->cxGroupArray; i++) { @@ -310,11 +320,10 @@ void KMX_TranslateDeadkeyKeyboard(LPKMX_KEYBOARD kbd, KMX_WCHAR deadkey, KMX_WOR /** * @brief add a deadkey rule - * @param kbd pointer to the US keyboard + * @param kbd pointer to the US keyboard * @param deadkey a deadkey to be added - * @param vk a keyvalue of the US keyboard - * @param shift shiftstate - * @return void + * @param vk a keyvalue of the US keyboard + * @param shift shiftstate */ void KMX_AddDeadkeyRule(LPKMX_KEYBOARD kbd, KMX_WCHAR deadkey, KMX_WORD vk, UINT shift) { // The weird LCTRL+RALT is Windows' way of mapping the AltGr key. @@ -369,9 +378,10 @@ struct KMX_dkidmap { /** * @brief find the deadkey id for a given deadkey - * @param kbd pointer to the keyboard + * @param kbd pointer to the keyboard * @param deadkey for which an id is to be found - * @return 0 if failed; otherwise a deadkey-id + * @return 0 if failed; + * otherwise a deadkey-id */ KMX_WCHAR KMX_GetUniqueDeadkeyID(LPKMX_KEYBOARD kbd, KMX_WCHAR deadkey) { LPKMX_GROUP gp; @@ -425,14 +435,13 @@ KMX_WCHAR KMX_GetUniqueDeadkeyID(LPKMX_KEYBOARD kbd, KMX_WCHAR deadkey) { /** * @brief Lookup the deadkey table for the deadkey in the physical keyboard. Then for each character, go through and map it through - * @param kbd pointer to the keyboard - * @param vk_US virtual key of the us keyboard - * @param shift shiftstate - * @param deadkey character produced by a deadkey + * @param kbd pointer to the keyboard + * @param vk_US virtual key of the us keyboard + * @param shift shiftstate + * @param deadkey character produced by a deadkey * @param all_vector vector that holds the data of the US keyboard and the currently used (underlying) keyboard - * @param keymap pointer to the currently used (underlying) keyboard Layout - * @param dk_Table a vector of all possible deadkey combinations for all Linux keyboards - * @return void + * @param keymap pointer to the currently used (underlying) keyboard Layout + * @param dk_Table a vector of all possible deadkey combinations for all Linux keyboards */ void KMX_ConvertDeadkey(LPKMX_KEYBOARD kbd, KMX_WORD vk_US, UINT shift, KMX_WCHAR deadkey, vec_dword_3D& all_vector, GdkKeymap* keymap, vec_dword_2D dk_Table) { KMX_WORD deadkeys[512], *pdk; @@ -461,7 +470,8 @@ void KMX_ConvertDeadkey(LPKMX_KEYBOARD kbd, KMX_WORD vk_US, UINT shift, KMX_WCHA * @brief convert a mnemonic keyboard to a positional keyboard * (i.e. setting *sp->dpString = '0' / TSS_MNEMONIC=0) * @param kbd pointer to keyboard - * @return TRUE if conversion was successful; FALSE otherwise + * @return TRUE if conversion was successful; + * FALSE otherwise */ KMX_BOOL KMX_SetKeyboardToPositional(LPKMX_KEYBOARD kbd) { LPKMX_STORE sp; @@ -484,7 +494,7 @@ KMX_BOOL KMX_SetKeyboardToPositional(LPKMX_KEYBOARD kbd) { return FALSE; } -/** @brief convert mnemonic keyboard layout to positional keyboard layout and translate keyboard */ +/** @brief convert mnemonic keyboard layout to positional keyboard layout and translate keyboard */ KMX_BOOL KMX_DoConvert(LPKMX_KEYBOARD kbd, KMX_BOOL bDeadkeyConversion, gint argc, gchar* argv[]) { KMX_WCHAR DeadKey = 0; @@ -548,11 +558,11 @@ KMX_BOOL KMX_DoConvert(LPKMX_KEYBOARD kbd, KMX_BOOL bDeadkeyConversion, gint arg /** * @brief return an array of [usvk, ch_out] pairs: all existing combinations of a deadkey + character for the underlying keyboard - * @param deadkey deadkey character - * @param [out] OutputPairs pointer to array of [usvk, ch_out] pairs - * @param keymap pointer to the currently used (underlying) keyboard Layout - * @param dk_Table shiftstate of the deadkey - * @return size of array of [usvk, ch_out] pairs + * @param dk_Table shiftstate of the deadkey + * @param deadkey deadkey character + * @param[out] outputPairs pointer to array of [usvk, ch_out] pairs + * @param keymap pointer to the currently used (underlying) keyboard Layout + * @return size of array of [usvk, ch_out] pairs */ int KMX_GetDeadkeys(vec_dword_2D& dk_Table, KMX_WORD deadkey, KMX_WORD* outputPairs, GdkKeymap* keymap) { KMX_WORD* p = outputPairs; @@ -574,7 +584,7 @@ int KMX_GetDeadkeys(vec_dword_2D& dk_Table, KMX_WORD deadkey, KMX_WORD* outputPa return (p - outputPairs); } -/** @brief print (error) messages */ +/** @brief print (error) messages */ void KMX_LogError(const wchar_t* fmt, ...) { WCHAR fmtbuf[256]; const wchar_t* end = L"\0"; diff --git a/linux/mcompile/keymap/mcompile.h b/linux/mcompile/keymap/mcompile.h index 03a03c46be..5436735ba7 100644 --- a/linux/mcompile/keymap/mcompile.h +++ b/linux/mcompile/keymap/mcompile.h @@ -35,7 +35,6 @@ extern std::vector KMX_FDeadkeys; // I4353 /** * @brief print (error) messages * @param fmt text to print - * @return void */ void KMX_LogError(const wchar_t* fmt, ...); diff --git a/linux/mcompile/keymap/u16.cpp b/linux/mcompile/keymap/u16.cpp index cc77596956..0170b5dfc5 100644 --- a/linux/mcompile/keymap/u16.cpp +++ b/linux/mcompile/keymap/u16.cpp @@ -1,5 +1,5 @@ /* - * Keyman is copyright 2024 (C) SIL International. MIT License. + * Keyman is copyright 2004 - 2024 (C) SIL International. MIT License. * * Functions for u16string */ @@ -12,8 +12,8 @@ // string <- wstring /** @brief Obtain a std::string from a std::wstring */ -std::string string_from_wstring(std::wstring const str) { - return convert((const std::wstring)str); +std::string string_from_wstring(std::wstring const wstr) { + return convert((const std::wstring)wstr); } // wstring <- string @@ -23,35 +23,31 @@ std::wstring wstring_from_string(std::string const str) { } // u16string <- string -/** @brief Obtain a std::string from a std::wstring */ +/** @brief Obtain a std::16string from a std::string */ std::u16string u16string_from_string(std::string const str) { return convert((const std::string)str); } // string <- u16string -/** @brief Obtain a std::string from a std::u16string */ -std::string string_from_u16string(std::u16string const str) { - return convert((const std::u16string)str); +/** @brief Obtain a std::string from a std::u16string */ +std::string string_from_u16string(std::u16string const str16) { + return convert((const std::u16string)str16); } // wstring <- u16string -/** @brief Obtain a std::wstring from a std::u16string */ -std::wstring wstring_from_u16string(std::u16string const str) { - std::string s = convert((const std::u16string)str); - std::wstring ws = convert((const std::string)s); - return ws; +/** @brief Obtain a std::wstring from a std::u16string */ +std::wstring wstring_from_u16string(std::u16string const str16) { + return convert((const std::u16string)str16); } // u16string <- wstring -/** @brief Obtain a std::u16string from a std::wstring */ -std::u16string u16string_from_wstring(std::wstring const str) { - std::string s = convert((const std::wstring)str); - std::u16string utf16 = convert((const std::string)s); - return utf16; +/** @brief Obtain a std::u16string from a std::wstring */ +std::u16string u16string_from_wstring(std::wstring const wstr) { + return convert((const std::wstring)wstr);; } - // UTF16 (=const wchar_t*) -> -> std::string -> std::u16string -> UTF16 ( = char16_t*) -/** @brief @brief Convert pointer to wchar_t to u16string and copy sz elements into dst */ +// UTF16 (=const wchar_t*) -> -> std::string -> std::u16string -> UTF16 ( = char16_t*) +/** @brief Convert pointer to wchar_t to u16string and copy sz elements into dst */ void u16sprintf(KMX_WCHAR* dst, const size_t sz, const wchar_t* fmt, ...) { wchar_t* wbuf = new wchar_t[sz]; va_list args; @@ -64,7 +60,7 @@ void u16sprintf(KMX_WCHAR* dst, const size_t sz, const wchar_t* fmt, ...) { delete[] wbuf; } -/** @brief @brief Convert u16string to long integer */ +/** @brief Convert u16string to long integer */ long int u16tol(const KMX_WCHAR* str, KMX_WCHAR** endptr, int base) { auto s = string_from_u16string(str); char* t; @@ -73,7 +69,7 @@ long int u16tol(const KMX_WCHAR* str, KMX_WCHAR** endptr, int base) { return result; } -/** @brief Append n characters from u16string */ +/** @brief Append max characters from u16string */ const KMX_WCHAR* u16ncat(KMX_WCHAR* dst, const KMX_WCHAR* src, size_t max) { KMX_WCHAR* o = dst; dst = (KMX_WCHAR*)u16chr(dst, 0); @@ -87,33 +83,31 @@ const KMX_WCHAR* u16ncat(KMX_WCHAR* dst, const KMX_WCHAR* src, size_t max) { return o; } -/** @brief Append a '/' or '\\' to an array of char16_t */ -const KMX_WCHAR* u16rchr_slash(KMX_WCHAR const* Name) +/** @brief find last '/' or '\\' in an array of char16_t */ +const KMX_WCHAR* u16rchr_slash(KMX_WCHAR const* name) { const KMX_WCHAR* cp = NULL; - cp = u16rchr(Name, '\\'); + cp = u16rchr(name, '\\'); if (cp == NULL) - cp = u16rchr(Name, '/'); + cp = u16rchr(name, '/'); return cp; } -/** @brief Append a '/' or '\\' to an array of char */ -KMX_CHAR* strrchr_slash(KMX_CHAR* Name) +/** @brief find last '/' or '\\' in an array of char */ +KMX_CHAR* strrchr_slash(KMX_CHAR* name) { KMX_CHAR* cp = NULL; - cp = strrchr(Name, '\\'); + cp = strrchr(name, '\\'); if (cp == NULL) - cp = strrchr(Name, '/'); + cp = strrchr(name, '/'); return cp; } -/** @brief Locate last occurrence of character in u16string */ +/** @brief Locate last occurrence of character in u16string */ const KMX_WCHAR* u16rchr(const KMX_WCHAR* p, KMX_WCHAR ch) { - const KMX_WCHAR* p_end = p + u16len(p) - 1; + const KMX_WCHAR* p_end = p + u16len(p); - if (ch == '\0') - return p_end + 1; - while (p_end >= p) { + while (p_end > p) { if (*p_end == ch) return p_end; p_end--; @@ -121,7 +115,7 @@ const KMX_WCHAR* u16rchr(const KMX_WCHAR* p, KMX_WCHAR ch) { return NULL; } -/** @brief @brief Locate first occurrence of character in u16string */ +/** @brief Locate first occurrence of character in u16string */ const KMX_WCHAR* u16chr(const KMX_WCHAR* p, KMX_WCHAR ch) { while (*p) { if (*p == ch) return p; @@ -130,7 +124,7 @@ const KMX_WCHAR* u16chr(const KMX_WCHAR* p, KMX_WCHAR ch) { return ch == 0 ? p : NULL; } -/** @brief @brief Copy the u16string pointed to by source into the array pointed to by destination */ +/** @brief Copy the u16string pointed to by src into the array pointed to by dst */ const KMX_WCHAR* u16cpy(KMX_WCHAR* dst, const KMX_WCHAR* src) { KMX_WCHAR* o = dst; while (*src) { @@ -140,7 +134,7 @@ const KMX_WCHAR* u16cpy(KMX_WCHAR* dst, const KMX_WCHAR* src) { return o; } -/** @brief Copy n characters of the u16string pointed to by source into the array pointed to by destination */ +/** @brief Copy max characters of the u16string pointed to by src into the array pointed to by dst */ const KMX_WCHAR* u16ncpy(KMX_WCHAR* dst, const KMX_WCHAR* src, size_t max) { KMX_WCHAR* o = dst; while (*src && max > 0) { @@ -153,7 +147,7 @@ const KMX_WCHAR* u16ncpy(KMX_WCHAR* dst, const KMX_WCHAR* src, size_t max) { return o; } -/** @brief @brief Return the length of the u16string str */ +/** @brief Return the length of the u16string str */ size_t u16len(const KMX_WCHAR* p) { int i = 0; while (*p) { @@ -163,7 +157,7 @@ size_t u16len(const KMX_WCHAR* p) { return i; } -/** @brief @brief Compare two u16strings */ +/** @brief Compare two u16strings */ int u16cmp(const KMX_WCHAR* p, const KMX_WCHAR* q) { while (*p && *q) { if (*p != *q) return *p - *q; @@ -173,7 +167,7 @@ int u16cmp(const KMX_WCHAR* p, const KMX_WCHAR* q) { return *p - *q; } -/** @brief @brief Case sensitive comparison of up to count characters in two strings */ +/** @brief Case insensitive comparison of up to count characters in two strings */ int u16nicmp(const KMX_WCHAR* p, const KMX_WCHAR* q, size_t count) { while (*p && *q && count) { if (toupper(*p) != toupper(*q)) return *p - *q; @@ -186,7 +180,7 @@ int u16nicmp(const KMX_WCHAR* p, const KMX_WCHAR* q, size_t count) { return 0; } -/** @brief @brief Case sensitive comparison of two strings */ +/** @brief Case insensitive comparison of two strings */ int u16icmp(const KMX_WCHAR* p, const KMX_WCHAR* q) { while (*p && *q) { if (toupper(*p) != toupper(*q)) return *p - *q; diff --git a/linux/mcompile/keymap/u16.h b/linux/mcompile/keymap/u16.h index 8a4f615e5d..5cf642515b 100644 --- a/linux/mcompile/keymap/u16.h +++ b/linux/mcompile/keymap/u16.h @@ -13,10 +13,10 @@ /** * @brief Obtain a std::string from a std::wstring - * @param str the std::wstring to be converted + * @param wstr the std::wstring to be converted * @return a std::string */ -std::string string_from_wstring(std::wstring const str); +std::string string_from_wstring(std::wstring const wstr); /** * @brief Obtain a std::wstring from a std::string @@ -26,78 +26,77 @@ std::string string_from_wstring(std::wstring const str); std::wstring wstring_from_string(std::string const str); /** - * @brief Obtain a std::string from a std::wstring - * @param str the std::wstring to be converted - * @return a std::string + * @brief Obtain a std::u16string from a std::string + * @param str the std::string to be converted + * @return a std::u16string */ std::u16string u16string_from_string(std::string const str); /** * @brief Obtain a std::string from a std::u16string - * @param str the std::string to be converted - * @return a std::u16string + * @param str16 the std::u16string to be converted + * @return a std::string */ -std::string string_from_u16string(std::u16string const str); +std::string string_from_u16string(std::u16string const str16); /** * @brief Obtain a std::wstring from a std::u16string - * @param str the std::u16string to be converted + * @param str16 the std::u16string to be converted * @return a std::wstring */ -std::wstring wstring_from_u16string(std::u16string const str); +std::wstring wstring_from_u16string(std::u16string const str16); /** * @brief Obtain a std::u16string from a std::wstring - * @param str the std::wstring to be converted + * @param wstr the std::wstring to be converted * @return a std::u16string */ -std::u16string u16string_from_wstring(std::wstring const str); +std::u16string u16string_from_wstring(std::wstring const wstr); /** * @brief Convert pointer to wchar_t to pointer to char16_t and copy sz elements into dst * @param dst destination - * @param sz nr of characters to be copied + * @param sz nr of characters to be copied * @param fmt source to convert and copy - * @return void */ void u16sprintf(KMX_WCHAR* dst, const size_t sz, const wchar_t* fmt, ...); /** * @brief Convert u16string to long integer - * @param str u16string beginning with the representation of an integral number. + * @param str u16string beginning with the representation of an integral number. * @param endptr Reference to the next character in str - * @param base Numerical base (radix) that determines the valid characters and their interpretation - * @return a std::string + * @param base Numerical base (radix) that determines the valid characters and their interpretation + * @return a long */ long int u16tol(const KMX_WCHAR* str, KMX_WCHAR** endptr, int base); /** - * @brief Append n characters from u16string + * @brief Append max characters from u16string * @param dst Pointer to the destination array * @param src u16string to be appended * @param max Maximum number of characters to be appended. - * @return Pointer to the destination array + * @return Pointer to dst */ const KMX_WCHAR* u16ncat(KMX_WCHAR* dst, const KMX_WCHAR* src, size_t max); /** - * @brief Append a '/' or '\\' to an array of char16_t - * @param Name Pointer to the source - * @return Pointer to the source with slash/backslash added + * @brief Find last '/' or '\\' in an array of char16_t + * @param name Pointer to the source + * @return Pointer to the last slash/backslash */ -const KMX_WCHAR* u16rchr_slash(KMX_WCHAR const* Name); +const KMX_WCHAR* u16rchr_slash(KMX_WCHAR const* name); /** - * @brief Append a '/' or '\\' to an array of char - * @param Name Pointer to the source - * @return Pointer to the source with slash/backslash added + * @brief Find last '/' or '\\' in an array of char + * @param name Pointer to the source + * @return Pointer to the last slash/backslash */ -KMX_CHAR* strrchr_slash(KMX_CHAR* Name); +KMX_CHAR* strrchr_slash(KMX_CHAR* name); /** * @brief Locate last occurrence of character in u16string - * @param p Pointer to the source + * @param p Pointer to the source * @param ch The character to be found * @return A pointer to the last occurrence of character in u16str */ @@ -105,26 +104,26 @@ const KMX_WCHAR* u16rchr(const KMX_WCHAR* p, KMX_WCHAR ch); /** * @brief Locate first occurrence of character in u16string - * @param p Pointer to the source + * @param p Pointer to the source * @param ch The character to be found * @return A pointer to the first occurrence of character in u16str */ const KMX_WCHAR* u16chr(const KMX_WCHAR* p, KMX_WCHAR ch); /** - * @brief Copy the u16string pointed by source into the array pointed by destination + * @brief Copy the u16string pointed by scr into the array pointed by dst * @param dst Pointer to the destination * @param src Pointer to the source to be copied - * @return Pointer to the destination + * @return Pointer to dst */ - const KMX_WCHAR* u16cpy(KMX_WCHAR* dst, const KMX_WCHAR* src); + /** - * @brief Copy n characters of the u16string pointed by source into the array pointed by destination + * @brief Copy max characters of the u16string pointed by src into the array pointed by dst * @param dst Pointer to the destination * @param src Pointer to the source to be copied * @param max Maximum number of characters to be copied - * @return Pointer to the destination + * @return Pointer to dst */ const KMX_WCHAR* u16ncpy(KMX_WCHAR* dst, const KMX_WCHAR* src, size_t max); @@ -139,61 +138,61 @@ size_t u16len(const KMX_WCHAR* p); * @brief Compare two u16strings * @param p Pointer one u16string * @param q Pointer another u16string - * @return 0 if strings are eqaual + * @return 0 if strings are equal * ! = 0 if unequal */ int u16cmp(const KMX_WCHAR* p, const KMX_WCHAR* q); /** - * @brief Case sensitive comparison of up to count characters in two strings - * @param p Pointer one u16string - * @param q Pointer another u16string + * @brief Case insensitive comparison of up to count characters in two strings + * @param p Pointer one u16string + * @param q Pointer another u16string * @param count Maximum number of characters to compare - * @return 0 if strings are eqaual + * @return 0 if strings are equal * ! = 0 if unequal */ int u16nicmp(const KMX_WCHAR* p, const KMX_WCHAR* q, size_t count); /** - * @brief Case sensitive comparison of two strings + * @brief Case insensitive comparison of two strings * @param p Pointer one u16string * @param q Pointer another u16string - * @return 0 if strings are eqaual + * @return 0 if strings are equal * ! = 0 if unequal */ int u16icmp(const KMX_WCHAR* p, const KMX_WCHAR* q); /** - * @brief Comparison of up to count characters in two strings - * @param p Pointer one u16string - * @param q Pointer another u16string + * @brief Comparison of up to count characters in two strings + * @param p Pointer one u16string + * @param q Pointer another u16string * @param count Maximum number of characters to compare - * @return 0 if strings are eqaual + * @return 0 if strings are equal * ! = 0 if unequal */ int u16ncmp(const KMX_WCHAR* p, const KMX_WCHAR* q, size_t count); /** - * @brief Split u16string into tokens - * @param p Pointer to u16string to truncate. - * @param ch the delimiter character - * @param ctx the string until and without the delimiter - * @return Pointer to the destination or NULL + * @brief Split u16string into tokens + * @param p Pointer to u16string to parse. + * @param ch the delimiter character + * @param ctx the remaining string after the first delimiter + * @return PPointer to the first token in p */ KMX_WCHAR* u16tok(KMX_WCHAR* p, const KMX_WCHAR ch, KMX_WCHAR** ctx); /** - * @brief Split u16string into tokens - * @param p Pointer to u16string to truncate. - * @param delim the delimiter character - * @param ctx the string until and without the delimiter - * @return Pointer to the destination or NULL + * @brief Split u16string into tokens + * @param p Pointer to u16string to parse. + * @param delim an array of delimiter characters + * @param ctx the remaining string after the first delimiter + * @return Pointer to the first token in p */ KMX_WCHAR* u16tok(KMX_WCHAR* p, const KMX_WCHAR* delim, KMX_WCHAR** ctx); /** - * @brief Convert a u16string to a double - * @param str Pointer to u16string + * @brief Convert a u16string to a double + * @param tr Pointer to u16string * @return double value equivalent to the string */ double u16tof(KMX_WCHAR* str);