-
-
Notifications
You must be signed in to change notification settings - Fork 141
test(linux): Add unit tests for mcompile #15892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 15 commits
99baacb
77acb6f
c040314
0ed8eb1
f309d90
8bd47e4
d5accca
6e38fc0
c05bba9
bb87e1d
0646808
e3dd7f1
8ba6a13
9cf4e78
471c6c4
61f1a2b
8803089
c9c45a0
0ccc9af
8cf0c41
cc9e0be
7b367e9
28b0c96
fcea563
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
ermshiperete marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * Keyman is copyright (C) SIL Global. MIT License. | ||
| * | ||
| * Created by Markus-SWAG on 2026-05-05 | ||
| * | ||
| * Mnemonic layout support for Linux | ||
| */ | ||
|
|
||
| #include "mcompile.h" | ||
|
ermshiperete marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From devin.ai:
|
||
|
|
||
| /** | ||
| * @brief main function for mcompile for Linux | ||
| * @param argc number of commandline arguments | ||
| * @param argv pointer to commandline arguments: executable, inputfile, outputfile | ||
| * @return 0 on success | ||
| */ | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
|
|
||
|
|
||
| int bDeadkeyConversion = 0; | ||
|
|
||
| if (argc > 1) | ||
| bDeadkeyConversion = (strcmp(argv[1], "-d") == 0); | ||
|
|
||
| int n = (bDeadkeyConversion ? 2 : 1); | ||
|
|
||
| if (argc < 3 || argc > 4 || (argc - n) != 2) { | ||
| printf( | ||
| "Usage: \tmcompile [-d] infile.kmx outfile.kmx\n" | ||
| " \tmcompile converts a Keyman mnemonic layout to\n" | ||
| " \ta positional one based on the currently used \n" | ||
| " \tLinux keyboard layout\n" | ||
| " \t(-d convert deadkeys to plain keys) \n \n"); | ||
|
|
||
| return 1; | ||
| } | ||
|
|
||
| // -u option is not available for Linux and macOS | ||
|
|
||
| KMX_CHAR* infile = argv[n]; | ||
| KMX_CHAR* outfile = argv[n + 1]; | ||
|
|
||
| printf("mcompile%s \"%s\" \"%s\"\n", bDeadkeyConversion ? " -d" : "", infile, outfile); | ||
|
|
||
| // 1. Load the keyman keyboard file | ||
|
|
||
| // 2. For each key on the system layout, determine its output character and perform a | ||
| // 1-1 replacement on the keyman keyboard of that character with the base VK + shift | ||
| // state. This fixup will transform the char to a vk, which will avoid any issues | ||
| // with the key. | ||
| // | ||
| // | ||
| // For each deadkey, we need to determine its possible outputs. Then we generate a VK | ||
| // rule for that deadkey, e.g. [K_LBRKT] > dk(c101) | ||
| // | ||
| // Next, update each rule that references the output from that deadkey to add an extra | ||
| // context deadkey at the end of the context match, e.g. 'a' dk(c101) + [K_SPACE] > 'b'. | ||
| // This will require a memory layout change for the .kmx file, plus fixups on the | ||
| // context+output index offsets | ||
| // | ||
| // --> virtual character keys | ||
| // | ||
| // [CTRL ' '] : we look at the character, and replace it in the same way, but merely | ||
| // switch the shift state from the VIRTUALCHARKEY to VIRTUALKEY, without changing any | ||
| // other properties of the key. | ||
| // | ||
| // 3. Write the new keyman keyboard file | ||
|
|
||
| LPKMX_KEYBOARD kmxfile = nullptr; | ||
|
|
||
| if (!KMX_LoadKeyboard(infile, &kmxfile)) { | ||
| KMX_LogError(L"Failed to load keyboard (%d)\n", errno); | ||
|
ermshiperete marked this conversation as resolved.
|
||
| delete kmxfile; | ||
| return 3; | ||
| } | ||
|
|
||
| if (KMX_DoConvert(kmxfile, bDeadkeyConversion, argc, (gchar**)argv)) { | ||
| if(!KMX_SaveKeyboard(kmxfile, outfile)) { | ||
| KMX_LogError(L"Failed to save keyboard (%d)\n", errno); | ||
|
ermshiperete marked this conversation as resolved.
|
||
| delete kmxfile; | ||
| return 3; | ||
| } | ||
| } | ||
|
|
||
| delete kmxfile; | ||
|
Markus-SWAG marked this conversation as resolved.
Outdated
|
||
|
|
||
| return 0; | ||
|
Comment on lines
+78
to
+88
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From devin.ai: Program returns success (0) when In |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.