mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-05 00:15:32 +00:00
feat(mac): implement comments of PR9384
This commit is contained in:
parent
71a5226291
commit
f47a037a59
7 changed files with 76 additions and 293 deletions
7
mac/.gitignore
vendored
7
mac/.gitignore
vendored
|
|
@ -15,10 +15,3 @@ setup/textinputsource/textinputsource
|
|||
setup/textinputsource/textinputsource.arm64
|
||||
setup/textinputsource/textinputsource.x86_64
|
||||
setup/Install Keyman.app
|
||||
|
||||
//Sabine
|
||||
**/mcompile/executable/*.*
|
||||
**/mcompile/*.kmx
|
||||
**/mcompile/X*.cpp
|
||||
**/mcompile/X_bak
|
||||
**/mcompile/X*.*
|
||||
|
|
@ -119,8 +119,8 @@ int mac_write_US_ToVector( vector_dword_3D &vec_us) {
|
|||
std::vector<int> us_Base = {97,115,100,102,104,103,122,120,99,118,167,98,113,119,101,114,121,116,49,50,51,52,54,53,61,57,55,45,56,48, 93,111,117, 91,105,112,13,108,106,39,107,59, 92,44,47,110,109,46};
|
||||
std::vector<int> us_Shift = {65, 83, 68, 70, 72, 71, 90, 88,67, 86,177,66, 81, 87, 69, 82, 89, 84,33,64,35,36,94,37,43,40,38,95,42,41,125, 79, 85,123, 73, 80,13, 76, 74,34, 75,58,124,60,63, 78, 77,62};
|
||||
|
||||
vector_dword_1D values;
|
||||
vector_dword_2D key;
|
||||
vec_dword_1D values;
|
||||
vec_dword_2D key;
|
||||
|
||||
for ( int i=0; i< us_Base.size(); i++) {
|
||||
values.push_back(i);
|
||||
|
|
@ -147,10 +147,10 @@ int mac_write_US_ToVector( vector_dword_3D &vec_us) {
|
|||
* @return the 2D-Vector
|
||||
*/
|
||||
|
||||
vector_dword_2D mac_create_empty_2D_Vector( int dim_rows, int dim_cols) {
|
||||
vec_dword_2D mac_create_empty_2D_Vector( int dim_rows, int dim_cols) {
|
||||
|
||||
vector_dword_1D shift;
|
||||
vector_dword_2D vector_2D;
|
||||
vec_dword_1D shift;
|
||||
vec_dword_2D vector_2D;
|
||||
|
||||
for ( int j=0; j< dim_cols;j++) {
|
||||
shift.push_back(INVALID_NAME);
|
||||
|
|
@ -174,7 +174,7 @@ vector_dword_2D mac_create_empty_2D_Vector( int dim_rows, int dim_cols) {
|
|||
int mac_append_underlying_ToVector(vector_dword_3D &All_Vector, const UCKeyboardLayout * keyboard_layout) {
|
||||
int caps=0;
|
||||
// create a 2D vector all filled with " " and push to 3D-Vector
|
||||
vector_dword_2D underlying_Vector2D = mac_create_empty_2D_Vector(All_Vector[0].size(), All_Vector[0][0].size());
|
||||
vec_dword_2D underlying_Vector2D = mac_create_empty_2D_Vector(All_Vector[0].size(), All_Vector[0][0].size());
|
||||
|
||||
if (underlying_Vector2D.size() == 0) {
|
||||
wprintf(L"ERROR: can't create empty 2D-Vector\n");
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ const KMX_DWORD KMX_VKMap[] = {
|
|||
0
|
||||
};
|
||||
|
||||
typedef std::vector<std::string> vector_str_1D;
|
||||
typedef std::vector<KMX_DWORD> vector_dword_1D;
|
||||
typedef std::vector<std::vector<KMX_DWORD> > vector_dword_2D;
|
||||
typedef std::vector<std::string> vec_string_1D;
|
||||
typedef std::vector<KMX_DWORD> vec_dword_1D;
|
||||
typedef std::vector<std::vector<KMX_DWORD> > vec_dword_2D;
|
||||
typedef std::vector<std::vector<std::vector<KMX_DWORD> > > vector_dword_3D;
|
||||
static KMX_DWORD INVALID_NAME = 0;
|
||||
static KMX_DWORD max_shiftstate = 10;
|
||||
|
|
@ -76,7 +76,7 @@ int mac_createOneVectorFromBothKeyboards(vector_dword_3D &All_Vector, const UCKe
|
|||
|
||||
int mac_write_US_ToVector(vector_dword_3D &vec);
|
||||
|
||||
vector_dword_2D mac_create_empty_2D_Vector(int dim_rows, int dim_shifts);
|
||||
vec_dword_2D mac_create_empty_2D_Vector(int dim_rows, int dim_shifts);
|
||||
|
||||
int mac_append_underlying_ToVector(vector_dword_3D &All_Vector, const UCKeyboardLayout * keykeyboard_layout);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,37 +7,6 @@
|
|||
#define CERR_UnableToWriteFully 0x00008007
|
||||
#define CERR_SomewhereIGotItWrong 0x00008009
|
||||
|
||||
KMX_BOOL KMX_VerifyKeyboard(LPKMX_BYTE filebase, KMX_DWORD sz);
|
||||
|
||||
LPKMX_KEYBOARD KMX_FixupKeyboard(PKMX_BYTE bufp, PKMX_BYTE base, KMX_DWORD dwFileSize);
|
||||
|
||||
KMX_BOOL KMX_SaveKeyboard(LPKMX_KEYBOARD kbd, PKMX_WCHAR filename) {
|
||||
|
||||
FILE *fp;
|
||||
fp = Open_File(filename, u"wb");
|
||||
|
||||
if(fp == NULL)
|
||||
{
|
||||
mac_KMX_LogError(L"Failed to create output file (%d)", errno);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
KMX_DWORD err = KMX_WriteCompiledKeyboard(kbd, fp, FALSE);
|
||||
fclose(fp);
|
||||
|
||||
if(err != CERR_None) {
|
||||
mac_KMX_LogError(L"Failed to write compiled keyboard with error %d", err);
|
||||
|
||||
std::u16string u16_filname(filename);
|
||||
std::string s = string_from_u16string(u16_filname);
|
||||
|
||||
remove(s.c_str());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
KMX_DWORD KMX_WriteCompiledKeyboard(LPKMX_KEYBOARD fk, FILE* hOutfile, KMX_BOOL FSaveDebug) {
|
||||
|
||||
LPKMX_GROUP fgp;
|
||||
|
|
@ -217,6 +186,37 @@ KMX_DWORD KMX_WriteCompiledKeyboard(LPKMX_KEYBOARD fk, FILE* hOutfile, KMX_BOOL
|
|||
return CERR_None;
|
||||
}
|
||||
|
||||
|
||||
KMX_BOOL KMX_VerifyKeyboard(LPKMX_BYTE filebase, KMX_DWORD sz);
|
||||
|
||||
LPKMX_KEYBOARD KMX_FixupKeyboard(PKMX_BYTE bufp, PKMX_BYTE base, KMX_DWORD dwFileSize);
|
||||
|
||||
KMX_BOOL KMX_SaveKeyboard(LPKMX_KEYBOARD kbd, PKMX_WCHAR filename) {
|
||||
|
||||
FILE *fp;
|
||||
fp = Open_File(filename, u"wb");
|
||||
|
||||
if(fp == NULL)
|
||||
{
|
||||
mac_KMX_LogError(L"Failed to create output file (%d)", errno);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
KMX_DWORD err = KMX_WriteCompiledKeyboard(kbd, fp, FALSE);
|
||||
fclose(fp);
|
||||
|
||||
if(err != CERR_None) {
|
||||
mac_KMX_LogError(L"Failed to write compiled keyboard with error %d", err);
|
||||
|
||||
std::u16string u16_filname(filename);
|
||||
std::string s = string_from_u16string(u16_filname);
|
||||
|
||||
remove(s.c_str());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
PKMX_WCHAR KMX_StringOffset(PKMX_BYTE base, KMX_DWORD offset) {
|
||||
if(offset == 0) return NULL;
|
||||
return (PKMX_WCHAR)(base + offset);
|
||||
|
|
@ -516,3 +516,32 @@ PKMX_WCHAR KMX_incxstr(PKMX_WCHAR p) {
|
|||
//################################# Code beyond these lines needs to be included in mcompile #####################################################
|
||||
//################################################################################################################################################
|
||||
|
||||
|
||||
FILE* Open_File(const KMX_CHAR* Filename, const KMX_CHAR* mode) {
|
||||
#ifdef _MSC_VER
|
||||
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);
|
||||
std::string cpath, cmode;
|
||||
cpath = (const KMX_CHAR*) Filename;
|
||||
cmode = (const KMX_CHAR*) mode;
|
||||
return fopen(cpath.c_str(), cmode.c_str());
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
FILE* Open_File(const KMX_WCHAR* Filename, const KMX_WCHAR* mode) {
|
||||
#ifdef _MSC_VER
|
||||
std::wstring cpath = convert_pchar16T_To_wstr((KMX_WCHAR*) Filename);
|
||||
std::wstring cmode = convert_pchar16T_To_wstr((KMX_WCHAR*) mode);
|
||||
std::replace(cpath.begin(), cpath.end(), '/', '\\');
|
||||
return _wfsopen(cpath.c_str(), cmode.c_str(), _SH_DENYWR);
|
||||
#else
|
||||
std::string cpath, cmode;
|
||||
cpath = string_from_u16string(Filename);
|
||||
cmode = string_from_u16string(mode);
|
||||
return fopen(cpath.c_str(), cmode.c_str());
|
||||
#endif
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "km_types.h"
|
||||
#include "kmx_file.h"
|
||||
#include "util_filesystem.h" //_S2 TODO include from keyman; not from this folder
|
||||
//#include "util_filesystem.h" //_S2 TODO include from keyman; not from this folder
|
||||
#include "mcompile.h"
|
||||
|
||||
|
||||
|
|
@ -76,7 +76,11 @@ KMX_BOOL KMX_LoadKeyboard(char16_t* fileName, LPKMX_KEYBOARD *lpKeyboard);
|
|||
|
||||
KMX_BOOL KMX_SaveKeyboard(LPKMX_KEYBOARD kbd, PKMX_WCHAR filename);
|
||||
|
||||
KMX_DWORD KMX_WriteCompiledKeyboard(LPKMX_KEYBOARD fk, FILE* hOutfile, KMX_BOOL FSaveDebug);
|
||||
// _S2 Open files on windows and non-windows platforms. Datatypes for Filename and mode must be the same.
|
||||
// return FILE* if file could be opened; FILE must to be closed in calling function
|
||||
FILE* Open_File(const KMX_CHAR* Filename, const KMX_CHAR* mode);
|
||||
FILE* Open_File(const KMX_WCHAR* Filename, const KMX_WCHAR* mode);
|
||||
|
||||
|
||||
#endif // _KMXFILE_H
|
||||
|
||||
|
|
|
|||
|
|
@ -1,227 +0,0 @@
|
|||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#include <emscripten/bind.h>
|
||||
#endif
|
||||
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include "util_filesystem.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
//#define _DEBUG_FOPEN 1
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
|
||||
const std::string get_wasm_file_path(const std::string& filename) {
|
||||
// Verify that we are passing a fully-qualified path
|
||||
// TODO: we need to support relative paths based on CWD
|
||||
#if _DEBUG_FOPEN
|
||||
std::cout << "get_wasm_file_path ENTER (" << filename << ")" << std::endl;
|
||||
#endif
|
||||
|
||||
assert(
|
||||
(filename.length() > 0 && filename.at(0) == '/') ||
|
||||
(filename.length() > 1 && filename.at(1) == ':')
|
||||
);
|
||||
|
||||
#if _DEBUG_FOPEN
|
||||
std::cout << "get_wasm_file_path assert passed " << std::endl;
|
||||
#endif
|
||||
|
||||
EM_ASM_({
|
||||
//console.log('EM_ASM enter');
|
||||
let path = Module.UTF8ToString($0);
|
||||
const isWin32Path = path.match(/^[a-zA-Z]:/);
|
||||
|
||||
//console.log('EM_ASM path = '+path);
|
||||
let root = '/nodefs-mount';
|
||||
if(!FS.analyzePath(root).exists) {
|
||||
//console.log('EM_ASM mkdir '+root);
|
||||
FS.mkdir(root);
|
||||
if(!isWin32Path) {
|
||||
//console.log('EM_ASM mount '+root);
|
||||
FS.mount(NODEFS, {root : '/'}, root);
|
||||
}
|
||||
}
|
||||
|
||||
if(isWin32Path) {
|
||||
// Win32 path, one mount per drive
|
||||
root += "/" + path.charAt(0);
|
||||
if(!FS.analyzePath(root).exists) {
|
||||
//console.log('EM_ASM mkdir '+root);
|
||||
FS.mkdir(root);
|
||||
//console.log('EM_ASM mount '+root);
|
||||
FS.mount(NODEFS, {root : path.substr(0,3) }, root);
|
||||
}
|
||||
}
|
||||
}, filename.c_str());
|
||||
|
||||
#if _DEBUG_FOPEN
|
||||
std::cout << "get_wasm_file_path EM_ASM_ passed " << std::endl;
|
||||
#endif
|
||||
|
||||
std::string f = std::string("/nodefs-mount");
|
||||
|
||||
if(filename.length() > 2 && filename.at(1) == ':') {
|
||||
f += std::string("/") + filename.at(0) + filename.substr(2);
|
||||
} else {
|
||||
f += filename;
|
||||
}
|
||||
|
||||
#if _DEBUG_FOPEN
|
||||
std::cout << "get_wasm_file_path opening virtual path: " << f << std::endl;
|
||||
#endif
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
FILE* fopen_wasm(const std::string& filename, const std::string& mode) {
|
||||
std::string f = get_wasm_file_path(filename);
|
||||
FILE* fp = fopen(f.c_str(), mode.c_str());
|
||||
|
||||
#if _DEBUG_FOPEN
|
||||
std::cout << "get_wasm_file_path fopen called, returned " << fp << std::endl;
|
||||
#endif
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#define fopen_wrapper fopen_wasm
|
||||
#else
|
||||
#define fopen_wrapper fopen
|
||||
#endif
|
||||
#endif
|
||||
|
||||
FILE* Open_File(const KMX_CHAR* Filename, const KMX_CHAR* mode) {
|
||||
#ifdef _MSC_VER
|
||||
std::string cpath = Filename; //, cmode = mode;
|
||||
std::replace(cpath.begin(), cpath.end(), '/', '\\');
|
||||
return fopen(cpath.c_str(), (const KMX_CHAR*) mode);
|
||||
#else
|
||||
return fopen_wrapper(Filename, mode);
|
||||
std::string cpath, cmode;
|
||||
cpath = (const KMX_CHAR*) Filename;
|
||||
cmode = (const KMX_CHAR*) mode;
|
||||
return fopen_wrapper(cpath.c_str(), cmode.c_str());
|
||||
#endif
|
||||
};
|
||||
|
||||
FILE* Open_File(const KMX_WCHART* Filename, const KMX_WCHART* mode) {
|
||||
#ifdef _MSC_VER
|
||||
std::wstring cpath = Filename; //, cmode = mode;
|
||||
std::replace(cpath.begin(), cpath.end(), '/', '\\');
|
||||
return _wfsopen(cpath.c_str(), mode, _SH_DENYWR);
|
||||
#else
|
||||
std::string cpath, cmode;
|
||||
cpath = string_from_wstring(Filename);
|
||||
cmode = string_from_wstring(mode);
|
||||
return fopen_wrapper(cpath.c_str(), cmode.c_str());
|
||||
#endif
|
||||
};
|
||||
|
||||
FILE* Open_File(const KMX_WCHAR* Filename, const KMX_WCHAR* mode) {
|
||||
#ifdef _MSC_VER
|
||||
std::wstring cpath = convert_pchar16T_To_wstr((KMX_WCHAR*) Filename);
|
||||
std::wstring cmode = convert_pchar16T_To_wstr((KMX_WCHAR*) mode);
|
||||
std::replace(cpath.begin(), cpath.end(), '/', '\\');
|
||||
return _wfsopen(cpath.c_str(), cmode.c_str(), _SH_DENYWR);
|
||||
#else
|
||||
std::string cpath, cmode;
|
||||
cpath = string_from_u16string(Filename);
|
||||
cmode = string_from_u16string(mode);
|
||||
return fopen_wrapper(cpath.c_str(), cmode.c_str());
|
||||
#endif
|
||||
};
|
||||
|
||||
KMX_BOOL kmcmp_FileExists(const KMX_CHAR *filename) {
|
||||
|
||||
#ifdef _MSC_VER
|
||||
intptr_t n;
|
||||
_finddata_t fi;
|
||||
if((n = _findfirst(filename, &fi)) != -1) {
|
||||
_findclose(n);
|
||||
return TRUE;
|
||||
}
|
||||
#else //!_MSC_VER
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
std::string f = get_wasm_file_path(filename);
|
||||
#else //!__EMSCRIPTEN__
|
||||
std::string f = filename;
|
||||
#endif // !__EMSCRIPTEN__
|
||||
|
||||
if(access(f.c_str(), F_OK) != -1) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif // !_MSC_VER
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
KMX_BOOL kmcmp_FileExists(const KMX_WCHAR* filename) {
|
||||
#ifdef _MSC_VER
|
||||
intptr_t n;
|
||||
_wfinddata_t fi;
|
||||
if((n = _wfindfirst((wchar_t*) filename, &fi)) != -1) {
|
||||
_findclose(n);
|
||||
return TRUE;
|
||||
}
|
||||
#else
|
||||
std::string cpath;
|
||||
cpath = string_from_u16string(filename);
|
||||
return kmcmp_FileExists(cpath.c_str());
|
||||
#endif
|
||||
|
||||
return FALSE;
|
||||
};
|
||||
|
||||
|
||||
bool IsRelativePath(KMX_CHAR const * p) {
|
||||
// Relative path (returns TRUE):
|
||||
// ..\...\BITMAP.BMP
|
||||
// PATH\BITMAP.BMP
|
||||
// BITMAP.BMP
|
||||
|
||||
// Semi-absolute path (returns FALSE):
|
||||
// \...\BITMAP.BMP
|
||||
|
||||
// Absolute path (returns FALSE):
|
||||
// C:\...\BITMAP.BMP
|
||||
// \\SERVER\SHARE\...\BITMAP.BMP
|
||||
|
||||
if ((*p == '\\') || (*p == '/')) return FALSE;
|
||||
if (*p && *(p + 1) == ':') return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool IsRelativePath(KMX_WCHAR const * p) {
|
||||
// Relative path (returns TRUE):
|
||||
// ..\...\BITMAP.BMP
|
||||
// PATH\BITMAP.BMP
|
||||
// BITMAP.BMP
|
||||
|
||||
// Semi-absolute path (returns FALSE):
|
||||
// \...\BITMAP.BMP
|
||||
|
||||
// Absolute path (returns FALSE):
|
||||
// C:\...\BITMAP.BMP
|
||||
// \\SERVER\SHARE\...\BITMAP.BMP
|
||||
|
||||
if ((*p == u'\\') || (*p == u'/'))return FALSE;
|
||||
if (*p && *(p + 1) == u':') return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
//#include _S2 "../src/kmx_u16.h" we want to include this...
|
||||
#include "u16.h"
|
||||
|
||||
// Opens files on windows and non-windows platforms. Datatypes for Filename and mode must be the same.
|
||||
// returns FILE* if file could be opened; FILE needs to be closed in calling function
|
||||
FILE* Open_File(const KMX_CHAR* Filename, const KMX_CHAR* mode);
|
||||
FILE* Open_File(const KMX_WCHART* Filename, const KMX_WCHART* mode);
|
||||
FILE* Open_File(const KMX_WCHAR* Filename, const KMX_WCHAR* mode);
|
||||
KMX_BOOL kmcmp_FileExists(const KMX_CHAR *filename);
|
||||
KMX_BOOL kmcmp_FileExists(const KMX_WCHAR *filename);
|
||||
|
||||
bool IsRelativePath(KMX_CHAR const * p);
|
||||
bool IsRelativePath(KMX_WCHAR const * p);
|
||||
Loading…
Add table
Reference in a new issue