Merge branch 'keyboardprocessor-api' into linux-ibus-keyman

This commit is contained in:
glasseyes 2018-10-30 15:43:51 +07:00
commit c09fffa26c
12 changed files with 71 additions and 17 deletions

View file

@ -90,7 +90,7 @@ typedef uint32_t km_kbp_status; // Status return code.
typedef struct km_kbp_context km_kbp_context;
typedef struct km_kbp_keyboard km_kbp_keyboard;
typedef struct km_kbp_state km_kbp_state;
typedef struct km_kbp_options_set km_kbp_options_set;
typedef struct km_kbp_options_set km_kbp_options_set;
// Forward declarations
//
@ -148,7 +148,7 @@ enum km_kbp_context_type {
typedef struct {
uint8_t type;
uint8_t reserved[3];
uint8_t _reserved[3];
union {
km_kbp_usv character;
uint32_t marker;
@ -332,7 +332,7 @@ services framework to acheive the expected effect.
*/
typedef struct {
uint8_t type;
uint8_t __reserved[3];
uint8_t _reserved[3];
union {
uintptr_t marker; // MARKER type
km_kbp_option const * option; // OPT types

View file

@ -13,6 +13,10 @@ project('keyboardprocessor', 'cpp', 'c',
compiler = meson.get_compiler('cpp')
if compiler.get_id() == 'msvc'
add_global_arguments('/source-charset:utf-8', language: ['c', 'cpp'])
endif
py = import('python3')
python = py.find_python()

View file

@ -14,7 +14,7 @@
#include <keyboardprocessor.h>
namespace std {
using namespace std::experimental;
namespace filesystem = std::experimental::filesystem;
}
// Forward declartions
@ -28,7 +28,7 @@ namespace kbp
{
std::string const _keyboard_id;
std::string const _version_string;
std::filesystem::path const _folder_path;
std::string const _folder_path;
public:
keyboard(std::filesystem::path const &);
@ -36,13 +36,14 @@ namespace kbp
inline
keyboard::keyboard(std::filesystem::path const & path)
: _keyboard_id(path.stem()),
: _keyboard_id(path.stem().string()),
_version_string("3.145"),
_folder_path(path.parent_path())
_folder_path(path.parent_path().string())
{
version_string = _version_string.c_str();
id = _keyboard_id.c_str();
folder_path = _folder_path.c_str();
default_options = nullptr;
}
}

View file

@ -86,6 +86,7 @@ km_kbp_status km_kbp_process_event(km_kbp_state *state,
break;
default:
{
auto shift_state = modifier_state & KM_KBP_MODIFIER_SHIFT;
// Only process further one of the shift states has something to output.
if (table[0][vk][0] || table[1][vk][0])
@ -96,7 +97,7 @@ km_kbp_status km_kbp_process_event(km_kbp_state *state,
{
km_kbp_usv usv = *c;
state->context().emplace_back(km_kbp_context_item {KM_KBP_CT_CHAR,{0,},{usv}});
state->actions.emplace_back(km_kbp_action_item {KM_KBP_IT_CHAR, {0,}, {.character = usv}});
state->actions.emplace_back(km_kbp_action_item {KM_KBP_IT_CHAR, {0,}, {usv}});
}
state->actions.emplace_back(km_kbp_action_item {KM_KBP_IT_END, {0,}, {0}});
@ -107,6 +108,7 @@ km_kbp_status km_kbp_process_event(km_kbp_state *state,
state->actions.emplace_back(km_kbp_action_item {KM_KBP_IT_ALERT, {0,}, {0}});
state->actions.emplace_back(km_kbp_action_item {KM_KBP_IT_END, {0,}, {0}});
break;
}
}
}
catch (std::bad_alloc)

View file

@ -36,7 +36,7 @@ km_kbp_status km_kbp_keyboard_load(char const *kb_path,
// if (stat.type() != std::filesystem::file_type::regular)
// return KM_KBP_STATUS_INVALID_ARGUMENT;
*keyboard = static_cast<km_kbp_keyboard *>(new km::kbp::keyboard("/dev/null/unk_dummy.kmx"));
*keyboard = static_cast<km_kbp_keyboard *>(new km::kbp::keyboard(kb_path));
return KM_KBP_STATUS_OK;
}

View file

@ -12,6 +12,7 @@
#include <algorithm>
#include <iterator>
#include <list>
#include <sstream>
#include <utility>
#include <vector>

View file

@ -21,6 +21,7 @@ if compiler.get_id() == 'gcc' or compiler.get_id() == 'clang'
'-fvisibility=hidden',
'-fvisibility-inlines-hidden'
]
links = ['-lstdc++fs']
if compiler.get_id() == 'clang'
warns += [
@ -38,11 +39,12 @@ endif
if compiler.get_id() == 'msvc'
warns = []
flags = []
defns = [
defns += [
'-D_SCL_SECURE_NO_WARNINGS',
'-D_CRT_SECURE_NO_WARNINGS',
'-DUNICODE'
]
links = []
endif
pkg = import('pkgconfig')
@ -59,7 +61,7 @@ lib = library('kmnkbp0',
'km_kbp_state_api.cpp',
'json.cpp',
cpp_args: defns + warns + flags,
link_args: ['-lstdc++fs'],
link_args: links,
version: meson.project_version(),
include_directories: inc,
install: true)

View file

@ -5,7 +5,7 @@
#
e = executable('jsontest', 'jsontest.cpp',
include_directories: [inc, libsrc],
include_directories: [libsrc],
objects: lib.extract_objects('json.cpp'))
test('jsontest', e, args: 'jsontest.json')
test('jsontestOutput', python, is_parallel: false, args:

View file

@ -30,8 +30,8 @@ namespace
auto const bmp_ctxt_size = count_codepoints(initial_bmp_context),
smp_ctxt_size = count_codepoints(initial_smp_context);
km_kbp_context_item test_marker_ctxt[2] = {
{KM_KBP_CT_MARKER, {0,}, 0xDEADBEEF},
{KM_KBP_CT_END, {0,}, 0}
{KM_KBP_CT_MARKER, {0,}, {0xDEADBEEF}},
{KM_KBP_CT_END, {0,}, {0}}
};
@ -40,7 +40,7 @@ namespace
#define try_status(expr) \
{auto __s = (expr); if (__s != KM_KBP_STATUS_OK) return 100*__LINE__+__s;}
int main(int argc, char * argv[])
int main(int, char * [])
{
km_kbp_context_item *ctxt1, *ctxt2;
// Test UTF16 to context_item conversion.

View file

@ -0,0 +1,39 @@
/*
Copyright: © 2018 SIL International.
Description: Tests for the Keyboard API family of functions.
Create Date: 30 Oct 2018
Authors: Tim Eves (TSE)
*/
#include <string>
#include <keyboardprocessor.h>
#include <experimental/filesystem>
namespace std {
namespace filesystem = std::experimental::filesystem;
}
//#include "keyboard.hpp"
namespace
{
std::filesystem::path const test_kb_path = "/a/dummy/keyboard.mock";
}
#define try_status(expr) \
{auto __s = (expr); if (__s != KM_KBP_STATUS_OK) return 100*__LINE__+__s;}
int main(int, char *[])
{
km_kbp_keyboard * test_kb = nullptr;
try_status(km_kbp_keyboard_load(test_kb_path.string().c_str(), &test_kb));
auto kb_attrs = km_kbp_keyboard_get_attrs(test_kb);
if (kb_attrs->folder_path != test_kb_path.parent_path().string())
return __LINE__;
km_kbp_keyboard_dispose(test_kb);
return 0;
}

View file

@ -7,5 +7,10 @@
ctxt = executable('context-api', 'context_api.cpp',
include_directories: [inc, libsrc],
dependencies: [kmnkbp])
objects: lib.extract_objects('km_kbp_context_api.cpp', 'json.cpp'))
keyb = executable('keyboard-api', 'keyboard_api.cpp',
include_directories: [inc, libsrc],
link_args: links,
objects: lib.extract_objects('km_kbp_keyboard_api.cpp', 'json.cpp', 'km_kbp_options_api.cpp'))
test('context-api', ctxt)
test('keyboard-api', keyb)

View file

@ -4,5 +4,5 @@
# Authors: Tim Eves (TSE)
#
e = executable('utftest', 'utftest.cpp', include_directories: [inc, libsrc])
e = executable('utftest', 'utftest.cpp', include_directories: [libsrc])
test('utftest', e)