feat(mac): mcompile remove u16, kmx_file from mcompile-mac and use from common

This commit is contained in:
Sabine 2024-08-14 15:33:14 +02:00
parent b5ac6e4ce0
commit e79c534335
10 changed files with 66 additions and 895 deletions

Binary file not shown.

View file

@ -6,7 +6,8 @@
#include <Carbon/Carbon.h>
#include <string>
#include <vector>
#include "u16.h"
#include "../../common/include/km_u16.h"
enum ShiftState {
Base = 0, // 0

View file

@ -1,388 +0,0 @@
#pragma once
#ifndef KMX_FILE_H
#define KMX_FILE_H
/*
Copyright: Copyright (C) 2003-2018 SIL International.
Authors: mcdurdin
*/
#define UNREFERENCED_PARAMETER(P) (P)
#define TRUNCATE ((size_t) - 1)
#ifdef KMN_KBP
// TODO: move this to a common namespace keyman::common::kmx_file or similar in the future
namespace km {
namespace kbp {
namespace kmx {
#endif
#define KMX_MAX_ALLOWED_FILE_SIZE (128 * 1024 * 1024) // 128MB //
#define KEYMAN_LAYOUT_DEFAULT 0x000005FE
#define KEYMANID_NONKEYMAN 0xFFFFFFFF
#define KEYMANID_IGNORE 0xFFFFFFFE
#define KEYMANID_INVALID 0xFFFFFFFD
// Shift flags for hotkeys (version 1.0) //
#define SHIFTFLAG 0x2000
#define CTRLFLAG 0x4000
#define ALTFLAG 0x8000
// Miscellaneous flags and defines //
#define MAXGROUPS 128
// File version identifiers //
#define VERSION_30 0x00000300
#define VERSION_31 0x00000301
#define VERSION_32 0x00000302
#define VERSION_40 0x00000400
#define VERSION_50 0x00000500
#define VERSION_501 0x00000501
#define VERSION_60 0x00000600
#define VERSION_70 0x00000700
#define VERSION_80 0x00000800
#define VERSION_90 0x00000900
#define VERSION_100 0x00000A00
#define VERSION_140 0x00000E00
#define VERSION_150 0x00000F00
#define VERSION_160 0x00001000
#define VERSION_MIN VERSION_50
#define VERSION_MAX VERSION_160
//
// Backspace types
//
#define BK_DEFAULT 0
#define BK_DEADKEY 1
// Different begin types
#define BEGIN_ANSI 0
#define BEGIN_UNICODE 1
#define BEGIN_NEWCONTEXT 2
#define BEGIN_POSTKEYSTROKE 3
#define TSS_NONE 0
#define TSS_BITMAP 1
#define TSS_COPYRIGHT 2
#define TSS_HOTKEY 3
#define TSS_LANGUAGE 4
#define TSS_LAYOUT 5
#define TSS_MESSAGE 6
#define TSS_NAME 7
#define TSS_VERSION 8
#define TSS_CAPSONONLY 9
#define TSS_CAPSALWAYSOFF 10
#define TSS_SHIFTFREESCAPS 11
#define TSS_LANGUAGENAME 12
#define TSS_CALLDEFINITION 13
#define TSS_CALLDEFINITION_LOADFAILED 14
#define TSS_ETHNOLOGUECODE 15
#define TSS_DEBUG_LINE 16
#define TSS_MNEMONIC 17
#define TSS_INCLUDECODES 18
#define TSS_OLDCHARPOSMATCHING 19
#define TSS_COMPILEDVERSION 20
#define TSS_KEYMANCOPYRIGHT 21
#define TSS_CUSTOMKEYMANEDITION 22
#define TSS_CUSTOMKEYMANEDITIONNAME 23
// Keyman 7.0 system stores //
#define TSS__KEYMAN_60_MAX 23
#define TSS_VISUALKEYBOARD 24
#define TSS_KMW_RTL 25
#define TSS_KMW_HELPFILE 26
#define TSS_KMW_HELPTEXT 27
#define TSS_KMW_EMBEDJS 28
#define TSS_WINDOWSLANGUAGES 29
#define TSS__KEYMAN_70_MAX 29
// Keyman 8.0 system stores //
#define TSS_COMPARISON 30
#define TSS__KEYMAN_80_MAX 30
// Keyman 9.0 system stores //
#define TSS_PLATFORM 31
#define TSS_BASELAYOUT 32
#define TSS_LAYER 33
#define TSS_PLATFORM_NOMATCH 0x8001 // Reserved for internal use - after platform statement is run, set to either TSS_PLATFORM_NOMATCH or TSS_PLATFORM_MATCH
#define TSS_PLATFORM_MATCH 0x8002 // Reserved for internal use - as the result will never change for the lifetime of the process.
#define TSS_VKDICTIONARY 34 // Dictionary of virtual key names for v9 dynamic layouts
#define TSS_LAYOUTFILE 35 // Keyman 9 layer-based JSON OSK
#define TSS_KEYBOARDVERSION 36 // &keyboardversion system store // I4140
#define TSS_KMW_EMBEDCSS 37
#define TSS_TARGETS 38
#define TSS__KEYMAN_90_MAX 38
// Keyman 14.0 system stores //
#define TSS_CASEDKEYS 39
#define TSS__KEYMAN_140_MAX 39
// Keyman 15.0 system stores //
#define TSS_BEGIN_NEWCONTEXT 40
#define TSS_BEGIN_POSTKEYSTROKE 41
#define TSS_NEWLAYER 42
#define TSS_OLDLAYER 43
#define TSS__KEYMAN_150_MAX 43
#define TSS__MAX 43
// wm_keyman_control_internal message control codes //
#define KMCI_SELECTKEYBOARD 3 // I3933
#define KMCI_SELECTKEYBOARD_TSF 4 // I3933
#define KMCI_GETACTIVEKEYBOARD 5 // I3933
#define KMCI_SETFOREGROUND 6 // I3933
#define KMCI_SELECTKEYBOARD_BACKGROUND 7 // I4271
#define KMCI_SELECTKEYBOARD_BACKGROUND_TSF 8 // I4271
#define FILEID_COMPILED 0x5354584B
#define SZMAX_LANGUAGENAME 80
#define SZMAX_KEYBOARDNAME 80
#define SZMAX_COPYRIGHT 256
#define SZMAX_MESSAGE 1024
#define UC_SENTINEL 0xFFFF
#define UC_SENTINEL_EXTENDEDEND 0x10 // was ((CODE_LASTCODE)+1)... what was I thinking?
#define U_UC_SENTINEL u"\uFFFF"
/*
VK__MAX defines the highest virtual key code defined in the system = 0xFF. Custom VK codes start at 256
*/
#define VK__MAX 255
#define CODE_ANY 0x01
#define CODE_INDEX 0x02
#define CODE_CONTEXT 0x03
#define CODE_NUL 0x04
#define CODE_USE 0x05
#define CODE_RETURN 0x06
#define CODE_BEEP 0x07
#define CODE_DEADKEY 0x08
// 0x09 = bkspace.-- we don't need to keep this separate though with UC_SENTINEL
#define CODE_EXTENDED 0x0A
//#define CODE_EXTENDEDEND 0x0B deprecated
#define CODE_SWITCH 0x0C
#define CODE_KEY 0x0D
#define CODE_CLEARCONTEXT 0x0E
#define CODE_CALL 0x0F
// UC_SENTINEL_EXTENDEDEND 0x10
#define CODE_CONTEXTEX 0x11
#define CODE_NOTANY 0x12
#define CODE_KEYMAN70_LASTCODE 0x12
#define CODE_SETOPT 0x13
#define CODE_IFOPT 0x14
#define CODE_SAVEOPT 0x15
#define CODE_RESETOPT 0x16
#define CODE_KEYMAN80_LASTCODE 0x16
// Keyman 9.0 codes //
#define CODE_IFSYSTEMSTORE 0x17
#define CODE_SETSYSTEMSTORE 0x18
#define CODE_LASTCODE 0x18
#define U_CODE_ANY u"\u0001"
#define U_CODE_INDEX u"\u0002"
#define U_CODE_CONTEXT u"\u0003"
#define U_CODE_NUL u"\u0004"
#define U_CODE_USE u"\u0005"
#define U_CODE_RETURN u"\u0006"
#define U_CODE_BEEP u"\u0007"
#define U_CODE_DEADKEY u"\u0008"
#define U_CODE_EXTENDED u"\u000A"
#define U_CODE_SWITCH u"\u000C"
#define U_CODE_CLEARCONTEXT u"\u000E"
#define U_CODE_CALL u"\u000F"
#define U_CODE_EXTENDEDEND u"\u0010"
#define U_CODE_CONTEXTEX u"\u0011"
#define U_CODE_NOTANY u"\u0012"
#define U_CODE_SETOPT u"\u0013"
#define U_CODE_IFOPT u"\u0014"
#define U_CODE_SAVEOPT u"\u0015"
#define U_CODE_RESETOPT u"\u0016"
#define U_CODE_IFSYSTEMSTORE u"\u0017"
#define U_CODE_SETSYSTEMSTORE u"\u0018"
#define C_CODE_ANY(store) U_UC_SENTINEL U_CODE_ANY store
#define C_CODE_INDEX(val1, val2) U_UC_SENTINEL U_CODE_INDEX val1 val2
#define C_CODE_CONTEXT() U_UC_SENTINEL U_CODE_CONTEXT
#define C_CODE_NUL() U_UC_SENTINEL U_CODE_NUL
#define C_CODE_USE(val) U_UC_SENTINEL U_CODE_USE val
#define C_CODE_RETURN() U_UC_SENTINEL U_CODE_RETURN
#define C_CODE_BEEP() U_UC_SENTINEL U_CODE_BEEP
#define C_CODE_DEADKEY(deadkey) U_UC_SENTINEL U_CODE_DEADKEY deadkey
#define C_CODE_EXTENDED(varargs) U_UC_SENTINEL U_CODE_EXTENDED varargs
#define C_CODE_SWITCH(val) U_UC_SENTINEL U_CODE_SWITCH val
#define C_CODE_CLEARCONTEXT() U_UC_SENTINEL U_CODE_CLEARCONTEXT
#define C_CODE_CALL(val) U_UC_SENTINEL U_CODE_CALL val
#define C_CODE_CONTEXTEX(val) U_UC_SENTINEL U_CODE_CONTEXTEX val
#define C_CODE_NOTANY(val) U_UC_SENTINEL U_CODE_NOTANY val
#define C_CODE_SETOPT(val1, val2) U_UC_SENTINEL U_CODE_SETOPT val1 val2
#define C_CODE_IFOPT(opt, val1, val2) U_UC_SENTINEL U_CODE_IFOPT opt val1 val2
#define C_CODE_SAVEOPT(opt) U_UC_SENTINEL U_CODE_SAVEOPT opt
#define C_CODE_RESETOPT(opt) U_UC_SENTINEL U_CODE_RESETOPT opt
#define C_CODE_IFSYSTEMSTORE(store, val1, val2) U_UC_SENTINEL U_CODE_IFSYSTEMSTORE store val1 val2
#define C_CODE_SETSYSTEMSTORE(store, val) U_UC_SENTINEL U_CODE_SETSYSTEMSTORE store val
#define KF_SHIFTFREESCAPS 0x0001
#define KF_CAPSONONLY 0x0002
#define KF_CAPSALWAYSOFF 0x0004
#define KF_LOGICALLAYOUT 0x0008
#define KF_AUTOMATICVERSION 0x0010
// 16.0: Support for LDML Keyboards in KMXPlus file format
#define KF_KMXPLUS 0x0020
#define HK_ALT 0x00010000
#define HK_CTRL 0x00020000
#define HK_SHIFT 0x00040000
#define LCTRLFLAG 0x0001 // Left Control flag
#define RCTRLFLAG 0x0002 // Right Control flag
#define LALTFLAG 0x0004 // Left Alt flag
#define RALTFLAG 0x0008 // Right Alt flag
#define K_SHIFTFLAG 0x0010 // Either shift flag
#define K_CTRLFLAG 0x0020 // Either ctrl flag
#define K_ALTFLAG 0x0040 // Either alt flag
//#define K_METAFLAG 0x0080 // Either Meta-key flag (tentative). Not usable in keyboard rules;
// Used internally (currently, only by KMW) to ensure Meta-key
// shortcuts safely bypass rules
// Meta key = Command key on macOS, Windows key on Windows
#define CAPITALFLAG 0x0100 // Caps lock on
#define NOTCAPITALFLAG 0x0200 // Caps lock NOT on
#define NUMLOCKFLAG 0x0400 // Num lock on
#define NOTNUMLOCKFLAG 0x0800 // Num lock NOT on
#define SCROLLFLAG 0x1000 // Scroll lock on
#define NOTSCROLLFLAG 0x2000 // Scroll lock NOT on
#define ISVIRTUALKEY 0x4000 // It is a Virtual Key Sequence
#define VIRTUALCHARKEY 0x8000 // Keyman 6.0: Virtual Key Cap Sequence NOT YET
#define K_MODIFIERFLAG 0x007F
#define K_NOTMODIFIERFLAG 0xFF00 // I4548
struct KMX_COMP_STORE {
KMX_DWORD dwSystemID;
KMX_DWORD dpName;
KMX_DWORD dpString;
};
struct KMX_COMP_KEY {
KMX_WORD Key;
KMX_WORD _reserved;
KMX_DWORD Line;
KMX_DWORD ShiftFlags;
KMX_DWORD dpOutput;
KMX_DWORD dpContext;
};
struct KMX_COMP_GROUP {
KMX_DWORD dpName;
KMX_DWORD dpKeyArray; // [LPKEY] address of first item in key array
KMX_DWORD dpMatch;
KMX_DWORD dpNoMatch;
KMX_DWORD cxKeyArray; // in array entries
KMX_BOOL fUsingKeys; // group(xx) [using keys] <-- specified or not
};
struct KMX_COMP_KEYBOARD {
KMX_DWORD dwIdentifier; // 0000 Keyman compiled keyboard id
KMX_DWORD dwFileVersion; // 0004 Version of the file - Keyman 4.0 is 0x0400
KMX_DWORD dwCheckSum; // 0008 As stored in keyboard. DEPRECATED as of 16.0
KMX_DWORD KeyboardID; // 000C as stored in HKEY_LOCAL_MACHINE//system//currentcontrolset//control//keyboard layouts
KMX_DWORD IsRegistered; // 0010
KMX_DWORD version; // 0014 keyboard version
KMX_DWORD cxStoreArray; // 0018 in array entries
KMX_DWORD cxGroupArray; // 001C in array entries
KMX_DWORD dpStoreArray; // 0020 [LPSTORE] address of first item in store array
KMX_DWORD dpGroupArray; // 0024 [LPGROUP] address of first item in group array
KMX_DWORD StartGroup[2]; // 0028 index of starting groups [2 of them]
KMX_DWORD dwFlags; // 0030 Flags for the keyboard file
KMX_DWORD dwHotKey; // 0034 standard windows hotkey (hiword=shift/ctrl/alt stuff, loword=vkey)
KMX_DWORD dpBitmapOffset; // 0038 offset of the bitmaps in the file
KMX_DWORD dwBitmapSize; // 003C size in bytes of the bitmaps
};
struct KMX_COMP_KEYBOARD_KMXPLUSINFO {
KMX_DWORD dpKMXPlus; // 0040 offset of KMXPlus data, <sect> header is first
KMX_DWORD dwKMXPlusSize; // 0044 size in bytes of entire KMXPlus data
};
//
//* Only valid if comp_keyboard.dwFlags&KF_KMXPLUS
//
struct KMX_COMP_KEYBOARD_EX {
KMX_COMP_KEYBOARD header; // 0000 see COMP_KEYBOARD
KMX_COMP_KEYBOARD_KMXPLUSINFO kmxplus; // 0040 see COMP_KEYBOARD_EXTRA
};
typedef KMX_COMP_KEYBOARD *PKMX_COMP_KEYBOARD;
typedef KMX_COMP_STORE *PKMX_COMP_STORE;
typedef KMX_COMP_KEY *PKMX_COMP_KEY;
typedef KMX_COMP_GROUP *PKMX_COMP_GROUP;
extern const int CODE__SIZE[];
#define CODE__SIZE_MAX 5
#define KEYBOARDFILEHEADER_SIZE 64
#define KEYBOARDFILESTORE_SIZE 12
#define KEYBOARDFILEGROUP_SIZE 24
#define KEYBOARDFILEKEY_SIZE 20
static_assert(sizeof(KMX_COMP_STORE) == KEYBOARDFILESTORE_SIZE, "COMP_STORE must be KEYBOARDFILESTORE_SIZE bytes");
static_assert(sizeof(KMX_COMP_KEY) == KEYBOARDFILEKEY_SIZE, "COMP_KEY must be KEYBOARDFILEKEY_SIZE bytes");
static_assert(sizeof(KMX_COMP_GROUP) == KEYBOARDFILEGROUP_SIZE, "COMP_GROUP must be KEYBOARDFILEGROUP_SIZE bytes");
static_assert(sizeof(KMX_COMP_KEYBOARD) == KEYBOARDFILEHEADER_SIZE, "COMP_KEYBOARD must be KEYBOARDFILEHEADER_SIZE bytes");
#ifdef KMN_KBP
} // namespace kmx
} // namespace kbp
} // namespace km
#endif
#endif //KMX_FILE_H

View file

@ -58,18 +58,18 @@ KMX_DWORD KMX_WriteCompiledKeyboardToFile(LPKMX_KEYBOARD fk, FILE* hOutfile, KMX
LPKMX_STORE fsp;
LPKMX_KEY fkp;
PKMX_COMP_KEYBOARD ck;
PKMX_COMP_GROUP gp;
PKMX_COMP_STORE sp;
PKMX_COMP_KEY kp;
PCOMP_KEYBOARD ck;
PCOMP_GROUP gp;
PCOMP_STORE sp;
PCOMP_KEY kp;
PKMX_BYTE buf;
KMX_DWORD size, offset;
KMX_DWORD i, j;
// Calculate how much memory to allocate
size = sizeof(KMX_COMP_KEYBOARD) +
fk->cxGroupArray * sizeof(KMX_COMP_GROUP) +
fk->cxStoreArray * sizeof(KMX_COMP_STORE) +
size = sizeof(COMP_KEYBOARD) +
fk->cxGroupArray * sizeof(COMP_GROUP) +
fk->cxStoreArray * sizeof(COMP_STORE) +
//wcslen(fk->szName)*2 + 2 +
//wcslen(fk->szCopyright)*2 + 2 +
//wcslen(fk->szLanguageName)*2 + 2 +
@ -79,7 +79,7 @@ KMX_DWORD KMX_WriteCompiledKeyboardToFile(LPKMX_KEYBOARD fk, FILE* hOutfile, KMX
for (i = 0, fgp = fk->dpGroupArray; i < fk->cxGroupArray; i++, fgp++) {
if (fgp->dpName)
size += (u16len(fgp->dpName) + 1) * sizeof(KMX_WCHAR);
size += fgp->cxKeyArray * sizeof(KMX_COMP_KEY);
size += fgp->cxKeyArray * sizeof(COMP_KEY);
for (j = 0, fkp = fgp->dpKeyArray; j < fgp->cxKeyArray; j++, fkp++) {
size += (u16len(fkp->dpOutput) + 1) * sizeof(KMX_WCHAR);
size += (u16len(fkp->dpContext) + 1) * sizeof(KMX_WCHAR);
@ -100,7 +100,7 @@ KMX_DWORD KMX_WriteCompiledKeyboardToFile(LPKMX_KEYBOARD fk, FILE* hOutfile, KMX
return CERR_CannotAllocateMemory;
memset(buf, 0, size);
ck = (PKMX_COMP_KEYBOARD)buf;
ck = (PCOMP_KEYBOARD)buf;
ck->dwIdentifier = FILEID_COMPILED;
@ -116,12 +116,12 @@ KMX_DWORD KMX_WriteCompiledKeyboardToFile(LPKMX_KEYBOARD fk, FILE* hOutfile, KMX
ck->dwFlags = fk->dwFlags;
offset = sizeof(KMX_COMP_KEYBOARD);
offset = sizeof(COMP_KEYBOARD);
ck->dpStoreArray = offset;
sp = (PKMX_COMP_STORE)(buf + offset);
sp = (PCOMP_STORE)(buf + offset);
fsp = fk->dpStoreArray;
offset += sizeof(KMX_COMP_STORE) * ck->cxStoreArray;
offset += sizeof(COMP_STORE) * ck->cxStoreArray;
for (i = 0; i < ck->cxStoreArray; i++, sp++, fsp++) {
sp->dwSystemID = fsp->dwSystemID;
sp->dpString = offset;
@ -138,9 +138,9 @@ KMX_DWORD KMX_WriteCompiledKeyboardToFile(LPKMX_KEYBOARD fk, FILE* hOutfile, KMX
}
ck->dpGroupArray = offset;
gp = (PKMX_COMP_GROUP)(buf + offset);
gp = (PCOMP_GROUP)(buf + offset);
offset += sizeof(KMX_COMP_GROUP) * ck->cxGroupArray;
offset += sizeof(COMP_GROUP) * ck->cxGroupArray;
for (i = 0, fgp = fk->dpGroupArray; i < ck->cxGroupArray; i++, gp++, fgp++) {
gp->cxKeyArray = fgp->cxKeyArray;
@ -168,8 +168,8 @@ KMX_DWORD KMX_WriteCompiledKeyboardToFile(LPKMX_KEYBOARD fk, FILE* hOutfile, KMX
}
gp->dpKeyArray = offset;
kp = (PKMX_COMP_KEY)(buf + offset);
offset += gp->cxKeyArray * sizeof(KMX_COMP_KEY);
kp = (PCOMP_KEY)(buf + offset);
offset += gp->cxKeyArray * sizeof(COMP_KEY);
for (j = 0, fkp = fgp->dpKeyArray; j < gp->cxKeyArray; j++, kp++, fkp++) {
kp->Key = fkp->Key;
@ -265,7 +265,7 @@ PKMX_WCHAR KMX_StringOffset(PKMX_BYTE base, KMX_DWORD offset) {
* @return pointer to the keyboard
*/
LPKMX_KEYBOARD KMX_CopyKeyboard(PKMX_BYTE bufp, PKMX_BYTE base) {
PKMX_COMP_KEYBOARD ckbp = (PKMX_COMP_KEYBOARD)base;
PCOMP_KEYBOARD ckbp = (PCOMP_KEYBOARD)base;
// Copy keyboard structure //
@ -291,20 +291,20 @@ LPKMX_KEYBOARD KMX_CopyKeyboard(PKMX_BYTE bufp, PKMX_BYTE base) {
kbp->dpGroupArray = (LPKMX_GROUP)bufp;
bufp += sizeof(KMX_GROUP) * kbp->cxGroupArray;
PKMX_COMP_STORE csp;
PCOMP_STORE csp;
LPKMX_STORE sp;
KMX_DWORD i;
for (csp = (PKMX_COMP_STORE)(base + ckbp->dpStoreArray), sp = kbp->dpStoreArray, i = 0; i < kbp->cxStoreArray; i++, sp++, csp++) {
for (csp = (PCOMP_STORE)(base + ckbp->dpStoreArray), sp = kbp->dpStoreArray, i = 0; i < kbp->cxStoreArray; i++, sp++, csp++) {
sp->dwSystemID = csp->dwSystemID;
sp->dpName = KMX_StringOffset(base, csp->dpName);
sp->dpString = KMX_StringOffset(base, csp->dpString);
}
PKMX_COMP_GROUP cgp;
PCOMP_GROUP cgp;
LPKMX_GROUP gp;
for (cgp = (PKMX_COMP_GROUP)(base + ckbp->dpGroupArray), gp = kbp->dpGroupArray, i = 0; i < kbp->cxGroupArray; i++, gp++, cgp++) {
for (cgp = (PCOMP_GROUP)(base + ckbp->dpGroupArray), gp = kbp->dpGroupArray, i = 0; i < kbp->cxGroupArray; i++, gp++, cgp++) {
gp->dpName = KMX_StringOffset(base, cgp->dpName);
gp->dpKeyArray = cgp->cxKeyArray > 0 ? (LPKMX_KEY)bufp : NULL;
gp->cxKeyArray = cgp->cxKeyArray;
@ -313,11 +313,11 @@ LPKMX_KEYBOARD KMX_CopyKeyboard(PKMX_BYTE bufp, PKMX_BYTE base) {
gp->dpNoMatch = KMX_StringOffset(base, cgp->dpNoMatch);
gp->fUsingKeys = cgp->fUsingKeys;
PKMX_COMP_KEY ckp;
PCOMP_KEY ckp;
LPKMX_KEY kp;
KMX_DWORD j;
for (ckp = (PKMX_COMP_KEY)(base + cgp->dpKeyArray), kp = gp->dpKeyArray, j = 0; j < gp->cxKeyArray; j++, kp++, ckp++) {
for (ckp = (PCOMP_KEY)(base + cgp->dpKeyArray), kp = gp->dpKeyArray, j = 0; j < gp->cxKeyArray; j++, kp++, ckp++) {
kp->Key = ckp->Key;
kp->Line = ckp->Line;
kp->ShiftFlags = ckp->ShiftFlags;
@ -343,10 +343,10 @@ LPKMX_KEYBOARD KMX_FixupKeyboard(PKMX_BYTE bufp, PKMX_BYTE base, KMX_DWORD dwFil
UNREFERENCED_PARAMETER(dwFileSize);
KMX_DWORD i, j;
PKMX_COMP_KEYBOARD ckbp = (PKMX_COMP_KEYBOARD)base;
PKMX_COMP_GROUP cgp;
PKMX_COMP_STORE csp;
PKMX_COMP_KEY ckp;
PCOMP_KEYBOARD ckbp = (PCOMP_KEYBOARD)base;
PCOMP_GROUP cgp;
PCOMP_STORE csp;
PCOMP_KEY ckp;
LPKMX_KEYBOARD kbp = (LPKMX_KEYBOARD)bufp;
LPKMX_STORE sp;
LPKMX_GROUP gp;
@ -355,18 +355,18 @@ LPKMX_KEYBOARD KMX_FixupKeyboard(PKMX_BYTE bufp, PKMX_BYTE base, KMX_DWORD dwFil
kbp->dpStoreArray = (LPKMX_STORE)(base + ckbp->dpStoreArray);
kbp->dpGroupArray = (LPKMX_GROUP)(base + ckbp->dpGroupArray);
for (sp = kbp->dpStoreArray, csp = (PKMX_COMP_STORE)sp, i = 0; i < kbp->cxStoreArray; i++, sp++, csp++) {
for (sp = kbp->dpStoreArray, csp = (PCOMP_STORE)sp, i = 0; i < kbp->cxStoreArray; i++, sp++, csp++) {
sp->dpName = KMX_StringOffset(base, csp->dpName);
sp->dpString = KMX_StringOffset(base, csp->dpString);
}
for (gp = kbp->dpGroupArray, cgp = (PKMX_COMP_GROUP)gp, i = 0; i < kbp->cxGroupArray; i++, gp++, cgp++) {
for (gp = kbp->dpGroupArray, cgp = (PCOMP_GROUP)gp, i = 0; i < kbp->cxGroupArray; i++, gp++, cgp++) {
gp->dpName = KMX_StringOffset(base, cgp->dpName);
gp->dpKeyArray = (LPKMX_KEY)(base + cgp->dpKeyArray);
if (cgp->dpMatch != NULL)gp->dpMatch = (PKMX_WCHAR)(base + cgp->dpMatch);
if (cgp->dpNoMatch != NULL)gp->dpNoMatch = (PKMX_WCHAR)(base + cgp->dpNoMatch);
for (kp = gp->dpKeyArray, ckp = (PKMX_COMP_KEY)kp, j = 0; j < gp->cxKeyArray; j++, kp++, ckp++) {
for (kp = gp->dpKeyArray, ckp = (PCOMP_KEY)kp, j = 0; j < gp->cxKeyArray; j++, kp++, ckp++) {
kp->dpOutput = (PKMX_WCHAR)(base + ckp->dpOutput);
kp->dpContext = (PKMX_WCHAR)(base + ckp->dpContext);
}
@ -497,14 +497,14 @@ KMX_BOOL KMX_LoadKeyboard(KMX_CHAR* fileName, LPKMX_KEYBOARD* lpKeyboard) {
*/
KMX_BOOL KMX_VerifyKeyboard(PKMX_BYTE filebase, KMX_DWORD file_size) {
KMX_DWORD i;
PKMX_COMP_KEYBOARD ckbp = (PKMX_COMP_KEYBOARD)filebase;
PKMX_COMP_STORE csp;
PCOMP_KEYBOARD ckbp = (PCOMP_KEYBOARD)filebase;
PCOMP_STORE csp;
// Check file version //
if (ckbp->dwFileVersion < VERSION_MIN || ckbp->dwFileVersion > VERSION_MAX) {
// Old or new version -- identify the desired program version //
for (csp = (PKMX_COMP_STORE)(filebase + ckbp->dpStoreArray), i = 0; i < ckbp->cxStoreArray; i++, csp++) {
for (csp = (PCOMP_STORE)(filebase + ckbp->dpStoreArray), i = 0; i < ckbp->cxStoreArray; i++, csp++) {
if (csp->dwSystemID == TSS_COMPILEDVERSION) {
if (csp->dpString == 0) {
mac_KMX_LogError(L"errWrongFileVersion:NULL");

View file

@ -3,7 +3,7 @@
#define MC_KMXFILE_H
#include "../../common/include/km_types.h"
#include "kmx_file.h"
#include "../../common/include/kmx_file.h"
#include "mcompile.h"
#ifndef _KMXFILE_H

View file

@ -13,7 +13,7 @@
#include <stdarg.h>
#include <wchar.h>
#include "mcompile.h"
#include "u16.h"
#include "../../common/include/km_u16.h"
/** @brief convert mnemonic keyboard layout to positional keyboard layout and translate keyboard */
KMX_BOOL mac_KMX_DoConvert(LPKMX_KEYBOARD kbd, KMX_BOOL bDeadkeyConversion, int argc);

29
mac/mcompile/meson.build Normal file
View file

@ -0,0 +1,29 @@
project('mcompile', 'c', 'cpp',
license: 'MIT',
meson_version: '>=1.0')
carbon = dependency('Carbon')
deps = [carbon]
# subdir('resources')
cpp_files = files(
'keymap.cpp',
'mcompile.cpp',
'mc_kmxfile.cpp',
'mc_import_rules.cpp',
'../../common/cpp/km_u16.cpp',
)
comon_include_dir = [
include_directories('../../common/include')
]
mcompile = executable(
'mcompile',
cpp_args: ['-std=c++17'], # this should be defined from resources/standard.meson.build
sources: [cpp_files],
dependencies: deps,
include_directories : comon_include_dir
)

Binary file not shown.

View file

@ -1,388 +0,0 @@
/*
* Keyman is copyright (C) 2004 - 2024 SIL International. MIT License.
*
* Functions for u16string
*/
#include "u16.h"
#include <codecvt>
#include <locale>
#include <stdarg.h>
#include "../../core/src/utfcodec.hpp"
/** string <- wstring
* @brief Obtain a std::string from a std::wstring
* @param wstr the std::wstring to be converted
* @return a std::string
*/
std::string string_from_wstring(std::wstring const wstr) {
return convert<wchar_t, char>((const std::wstring)wstr);
}
/** wstring <- string
* @brief Obtain a std::wstring from a std::string
* @param str the std::string to be converted
* @return a std::wstring
*/
std::wstring wstring_from_string(std::string const str) {
return convert<char, wchar_t>((const std::string)str);
}
/** u16String <- string
* @brief Obtain a std::u16tring 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) {
return convert<char, char16_t>((const std::string)str);
}
/** string <- u16string
* @brief Obtain a std::string from a std::u16string
* @param str16 the std::u16string to be converted
* @return a std::string
*/
std::string string_from_u16string(std::u16string const str16) {
return convert<char16_t, char>((const std::u16string)str16);
}
/** wstring <- u16string
* @brief Obtain a std::wstring from a std::u16string
* @param str16 the std::u16string to be converted
* @return a std::wstring
*/
std::wstring wstring_from_u16string(std::u16string const str16) {
return convert<char16_t, wchar_t>((const std::u16string)str16);
}
/** u16string <- wstring
* @brief Obtain a std::u16string from a std::wstring
* @param wstr the std::wstring to be converted
* @return a std::u16string
*/
std::u16string u16string_from_wstring(std::wstring const wstr) {
return convert<wchar_t, char16_t>((const std::wstring)wstr);;
}
/** UTF16 (=const wchar_t*) -> std::string -> std::u16string -> UTF16 ( = char16_t*)
* @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 fmt source to convert and copy
* @return void
*/
void u16sprintf(KMX_WCHAR* dst, const size_t sz, const wchar_t* fmt, ...) {
wchar_t* wbuf = new wchar_t[sz];
va_list args;
va_start(args, fmt);
vswprintf(wbuf, sz, fmt, args);
va_end(args);
std::u16string u16str = u16string_from_wstring(wbuf);
u16ncpy(dst, u16str.c_str(), sz);
delete[] wbuf;
}
/**
* @brief Convert u16string to long integer
* @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 long
*/
long int u16tol(const KMX_WCHAR* str, KMX_WCHAR** endptr, int base) {
auto s = string_from_u16string(str);
char* t;
long int result = strtol(s.c_str(), &t, base);
if (endptr != nullptr)
*endptr = (KMX_WCHAR*)str + (t - s.c_str());
return result;
}
/**
* @brief Append n 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
*/
const KMX_WCHAR* u16ncat(KMX_WCHAR* dst, const KMX_WCHAR* src, size_t max) {
KMX_WCHAR* o = dst;
dst = (KMX_WCHAR*)u16chr(dst, 0);
// max -= (dst-o);
while (*src && max > 0) {
*dst++ = *src++;
max--;
}
if (max > 0)
*dst = 0;
return o;
}
/**
* @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* cp = NULL;
cp = u16rchr(name, '\\');
if (cp == NULL)
cp = u16rchr(name, '/');
return cp;
}
/**
* @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* cp = NULL;
cp = strrchr(name, '\\');
if (cp == NULL)
cp = strrchr(name, '/');
return cp;
}
/**
* @brief Locate last occurrence of character in u16string
* @param p Pointer to the source
* @param ch The character to be found
* @return A pointer to the last occurrence of character in u16str
*/
const KMX_WCHAR* u16rchr(const KMX_WCHAR* p, KMX_WCHAR ch) {
const KMX_WCHAR* p_end = p + u16len(p);
while (p_end > p) {
if (*p_end == ch)
return p_end;
p_end--;
}
return NULL;
}
/**
* @brief Locate first occurrence of character in u16string
* @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) {
while (*p) {
if (*p == ch)
return p;
p++;
}
return ch == 0 ? p : NULL;
}
/**
* @brief Copy 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
* @return Pointer to dst
*/
const KMX_WCHAR* u16cpy(KMX_WCHAR* dst, const KMX_WCHAR* src) {
KMX_WCHAR* o = dst;
while (*src) {
*dst++ = *src++;
}
*dst = 0;
return o;
}
/**
* @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 dst
*/
const KMX_WCHAR* u16ncpy(KMX_WCHAR* dst, const KMX_WCHAR* src, size_t max) {
KMX_WCHAR* o = dst;
while (*src && max > 0) {
*dst++ = *src++;
max--;
}
if (max > 0) {
*dst = 0;
}
return o;
}
/**
* @brief Return the length of the u16string str
* @param p Pointer to the source
* @return The length of u16string
*/
size_t u16len(const KMX_WCHAR* p) {
int i = 0;
while (*p) {
p++;
i++;
}
return i;
}
/**
* @brief Compare two u16strings
* @param p Pointer one u16string
* @param q Pointer another u16string
* @return 0 if strings are eqaual
* ! = 0 if unequal
*/
int u16cmp(const KMX_WCHAR* p, const KMX_WCHAR* q) {
while (*p && *q) {
if (*p != *q)
return *p - *q;
p++;
q++;
}
return *p - *q;
}
/**
* @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 equal
* ! = 0 if unequal
*/
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;
p++;
q++;
count--;
}
if (count)
return *p - *q;
return 0;
}
/**
* @brief Case insensitive comparison of two strings
* @param p Pointer one u16string
* @param q Pointer another u16string
* @return 0 if strings are equal
* ! = 0 if unequal
*/
int u16icmp(const KMX_WCHAR* p, const KMX_WCHAR* q) {
while (*p && *q) {
if (toupper(*p) != toupper(*q))
return *p - *q;
p++;
q++;
}
return *p - *q;
}
/**
* @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 equal
* ! = 0 if unequal
*/
int u16ncmp(const KMX_WCHAR* p, const KMX_WCHAR* q, size_t count) {
while (*p && *q && count) {
if (*p != *q)
return *p - *q;
p++;
q++;
count--;
}
if (count)
return *p - *q;
return 0;
}
/**
* @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 Pointer to the first token in p
*/
KMX_WCHAR* u16tok(KMX_WCHAR* p, const KMX_WCHAR ch, KMX_WCHAR** ctx) {
if (!p) {
p = *ctx;
if (!p)
return NULL;
}
KMX_WCHAR* q = p;
while (*q && *q != ch) {
q++;
}
if (*q) {
*q = 0;
q++;
while (*q == ch)
q++;
*ctx = q;
} else {
*ctx = NULL;
}
return *p ? p : NULL;
}
/**
* @brief Split u16string into tokens
* @param p Pointer to u16string to parse
* @param delimiters 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* delimiters, KMX_WCHAR** ctx) {
if (!p) {
p = *ctx;
if (!p)
return NULL;
}
KMX_WCHAR* q = p;
while (*q && !u16chr(delimiters, *q)) {
q++;
}
if (*q) {
*q = 0;
q++;
while (*q && u16chr(delimiters, *q))
q++;
*ctx = q;
} else {
*ctx = NULL;
}
return *p ? p : NULL;
}
/**
* @brief Convert a u16string to a double
* @param str Pointer to u16string
* @return double value equivalent to the string
*/
double u16tof(KMX_WCHAR* str) {
double val = 0;
int offsetdot = 0;
char digit;
PKMX_WCHAR q = (PKMX_WCHAR)u16chr(str, '.');
size_t pos_dot = (q - str < 0) ? u16len(str) : q - str;
for (size_t i = 0; i < u16len(str); i++) {
digit = static_cast<char>(towupper(*str));
if (i > pos_dot - 1)
offsetdot = 1;
if (digit != '.')
val = val + ((int(digit)) - 48) * pow(10, (pos_dot - 1 - i + offsetdot));
str++;
}
return val;
}

View file

@ -1,83 +0,0 @@
#ifndef U16_H
#define U16_H
#pragma once
#include "../../common/include/km_types.h"
#include <cmath>
#include <ctype.h>
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
/** @brief Obtain a std::string from a std::wstring */
std::string string_from_wstring(std::wstring const wstr);
/** @brief Obtain a std::wstring from a std::string */
std::wstring wstring_from_string(std::string const str);
/** @brief Obtain a std::u16tring from a std::string*/
std::u16string u16string_from_string(std::string const str);
/** @brief Obtain a std::string from a std::u16string */
std::string string_from_u16string(std::u16string const str16);
/** @brief Obtain a std::wstring from a std::u16string */
std::wstring wstring_from_u16string(std::u16string const str16);
/** @brief Obtain a std::u16string from a std::wstring */
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 */
void u16sprintf(KMX_WCHAR* dst, const size_t sz, const wchar_t* fmt, ...);
/** @brief Convert u16string to long integer */
long int u16tol(const KMX_WCHAR* str, KMX_WCHAR** endptr, int base);
/** @brief Append max characters from u16string */
const KMX_WCHAR* u16ncat(KMX_WCHAR* dst, const KMX_WCHAR* src, size_t max);
/** @brief find last '/' or '\\' in an array of char16_t */
const KMX_WCHAR* u16rchr_slash(KMX_WCHAR const* Name);
/** @brief find last '/' or '\\' in an array of char */
KMX_CHAR* strrchr_slash(KMX_CHAR* Name);
/** @brief Locate last occurrence of character in u16string */
const KMX_WCHAR* u16rchr(const KMX_WCHAR* p, KMX_WCHAR ch);
/** @brief Locate first occurrence of character in u16string */
const KMX_WCHAR* u16chr(const KMX_WCHAR* p, KMX_WCHAR ch);
/** @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);
/** @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);
/** @brief Return the length of the u16string str */
size_t u16len(const KMX_WCHAR* p);
/** @brief Compare two u16strings */
int u16cmp(const KMX_WCHAR* p, const KMX_WCHAR* q);
/** @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);
/** @brief Case insensitive comparison of two strings */
int u16icmp(const KMX_WCHAR* p, const KMX_WCHAR* q);
/** @brief Comparison of up to count characters in two strings */
int u16ncmp(const KMX_WCHAR* p, const KMX_WCHAR* q, size_t count);
/** @brief Split u16string into tokens */
KMX_WCHAR* u16tok(KMX_WCHAR* p, const KMX_WCHAR ch, KMX_WCHAR** ctx);
/** @brief Split u16string into tokens */
KMX_WCHAR* u16tok(KMX_WCHAR* p, const KMX_WCHAR* delimiters, KMX_WCHAR** ctx);
/** @brief Convert a u16string to a double */
double u16tof(KMX_WCHAR* str);
#endif /* U16_H */