mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-09 10:25:32 +00:00
feat(core): more kmx_plus_dump functions
- also update sample data
This commit is contained in:
parent
590ac8f8f6
commit
5926dfe5fe
3 changed files with 90 additions and 15 deletions
|
|
@ -15,14 +15,76 @@ dump_section_name(KMX_DWORD ident) {
|
|||
|
||||
static void
|
||||
dump_kmxplus_header(const COMP_KMXPLUS_HEADER* hdr) {
|
||||
if (hdr == NULL) {
|
||||
printf("! dump_kmxplus_header: NULL header\n");
|
||||
}
|
||||
dump_section_name(hdr->ident);
|
||||
printf(": (%X) size 0x%X\n", hdr->ident, hdr->size);
|
||||
}
|
||||
|
||||
static void
|
||||
dump_kmxplus_keys(const uint8_t* /*data*/, const COMP_KMXPLUS_KEYS* keys) {
|
||||
if(keys == NULL) {
|
||||
printf("! could not load 'keys' section\n");
|
||||
return;
|
||||
}
|
||||
dump_kmxplus_header((const COMP_KMXPLUS_HEADER*)keys);
|
||||
// TODO-LDML
|
||||
}
|
||||
|
||||
static void
|
||||
dump_kmxplus_loca(const uint8_t* /*data*/, const COMP_KMXPLUS_LOCA* loca) {
|
||||
if(loca == NULL) {
|
||||
printf("! could not load 'loca' section\n");
|
||||
return;
|
||||
}
|
||||
dump_kmxplus_header((const COMP_KMXPLUS_HEADER*)loca);
|
||||
// TODO-LDML
|
||||
}
|
||||
|
||||
static void
|
||||
dump_kmxplus_meta(const uint8_t* /*data*/, const COMP_KMXPLUS_META* meta) {
|
||||
if(meta == NULL) {
|
||||
printf("! could not load 'meta' section\n");
|
||||
return;
|
||||
}
|
||||
dump_kmxplus_header((const COMP_KMXPLUS_HEADER*)meta);
|
||||
// TODO-LDML
|
||||
}
|
||||
|
||||
static void
|
||||
dump_kmxplus_vkey(const uint8_t* /*data*/, const COMP_KMXPLUS_VKEY* vkey) {
|
||||
if(vkey == NULL) {
|
||||
printf("! could not load 'vkey' section\n");
|
||||
return;
|
||||
}
|
||||
dump_kmxplus_header((const COMP_KMXPLUS_HEADER*)vkey);
|
||||
// TODO-LDML
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
dump_kmxplus_strs(const uint8_t* /*data*/, const COMP_KMXPLUS_STRS* strs) {
|
||||
dump_kmxplus_header((const COMP_KMXPLUS_HEADER*)strs);
|
||||
printf("strs: count 0x%X\n", strs->count);
|
||||
for (KMX_DWORD i=0; i<strs->count; i++) {
|
||||
KMX_WCHAR buf[BUFSIZ];
|
||||
printf("#0x%X: ", i);
|
||||
PKMX_WCHAR str = strs->get(i, buf, BUFSIZ);
|
||||
if (!str) {
|
||||
printf("NULL/ERR\n");
|
||||
continue;
|
||||
}
|
||||
for(int j=0; str[j] && j<0x30; j++) {
|
||||
if (str[j] < 0x7F && str[j] != 0x0020 && str[j] > 0x20) {
|
||||
putchar(str[j]);
|
||||
} else {
|
||||
printf("U+%04X ", str[j]);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -35,20 +97,35 @@ dump_kmxplus_sect(const uint8_t* data, const COMP_KMXPLUS_SECT* sect) {
|
|||
const COMP_KMXPLUS_SECT_ENTRY& entry = sect->entries[i];
|
||||
dump_section_name(entry.sect);
|
||||
printf(" sect#%d: %X @ %X\n", i, entry.sect, entry.offset);
|
||||
|
||||
const uint8_t* entrydata = (data+entry.offset);
|
||||
switch(entry.sect) {
|
||||
case LDML_SECTION_KEYS:
|
||||
dump_kmxplus_keys(data, as_kmxplus_keys(entrydata));
|
||||
break;
|
||||
case LDML_SECTION_LOCA:
|
||||
dump_kmxplus_loca(data, as_kmxplus_loca(entrydata));
|
||||
break;
|
||||
case LDML_SECTION_META:
|
||||
dump_kmxplus_meta(data, as_kmxplus_meta(entrydata));
|
||||
break;
|
||||
case LDML_SECTION_SECT:
|
||||
printf("! Cowardly refusing to dump nested 'sect' section.\n");
|
||||
break;
|
||||
case LDML_SECTION_STRS:
|
||||
dump_kmxplus_strs(data, as_kmxplus_strs((void*)(data+entry.offset)));
|
||||
dump_kmxplus_strs(data, as_kmxplus_strs(entrydata));
|
||||
break;
|
||||
case LDML_SECTION_VKEY:
|
||||
dump_kmxplus_vkey(data, as_kmxplus_vkey(entrydata));
|
||||
break;
|
||||
default:
|
||||
;
|
||||
printf("Unknown section %X", entry.sect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
dump_kmxplus_data(const uint8_t* data) {
|
||||
const COMP_KMXPLUS_SECT* sect = as_kmxplus_sect((void*)data);
|
||||
const COMP_KMXPLUS_SECT* sect = as_kmxplus_sect(data);
|
||||
if (sect == NULL) {
|
||||
printf("Err: 'sect' null from %p\n", data);
|
||||
return;
|
||||
|
|
@ -71,7 +148,7 @@ dump_kmxplus_data(kmx::PCOMP_KEYBOARD keyboard) {
|
|||
}
|
||||
|
||||
PKMX_WCHAR
|
||||
COMP_KMXPLUS_STRS::get(KMX_DWORD entry, PKMX_WCHAR buf, KMX_DWORD bufsiz) {
|
||||
COMP_KMXPLUS_STRS::get(KMX_DWORD entry, PKMX_WCHAR buf, KMX_DWORD bufsiz) const {
|
||||
assert(entry < count);
|
||||
if (entry >= count) {
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ struct COMP_KMXPLUS_STRS {
|
|||
* @param bufsiz buffer size in bytes
|
||||
* @return NULL or a pointer to the output buffer
|
||||
*/
|
||||
PKMX_WCHAR get(KMX_DWORD entry, PKMX_WCHAR buf, KMX_DWORD bufsiz);
|
||||
PKMX_WCHAR get(KMX_DWORD entry, PKMX_WCHAR buf, KMX_DWORD bufsiz) const;
|
||||
};
|
||||
|
||||
static_assert(sizeof(struct COMP_KMXPLUS_STRS) == LDML_LENGTH_STRS, "mismatched size of section strs");
|
||||
|
|
@ -123,7 +123,7 @@ static_assert(sizeof(struct COMP_KMXPLUS_VKEY) == LDML_LENGTH_VKEY, "mismatched
|
|||
* @return COMP_KMXPLUS_ALLDATA* or null
|
||||
*/
|
||||
static inline const COMP_KMXPLUS_HEADER *
|
||||
validate_as_section(void *data, uint32_t ident) {
|
||||
validate_as_section(const uint8_t *data, uint32_t ident) {
|
||||
if (!data) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -142,7 +142,7 @@ validate_as_section(void *data, uint32_t ident) {
|
|||
* @return section data or null on error
|
||||
*/
|
||||
static inline const COMP_KMXPLUS_SECT *
|
||||
as_kmxplus_sect(void *data) {
|
||||
as_kmxplus_sect(const uint8_t *data) {
|
||||
const COMP_KMXPLUS_HEADER *all = validate_as_section(data, LDML_SECTION_SECT);
|
||||
return reinterpret_cast<const COMP_KMXPLUS_SECT *>(all);
|
||||
}
|
||||
|
|
@ -152,7 +152,7 @@ as_kmxplus_sect(void *data) {
|
|||
* @return section data or null on error
|
||||
*/
|
||||
static inline const COMP_KMXPLUS_STRS *
|
||||
as_kmxplus_strs(void *data) {
|
||||
as_kmxplus_strs(const uint8_t *data) {
|
||||
const COMP_KMXPLUS_HEADER *all = validate_as_section(data, LDML_SECTION_STRS);
|
||||
return reinterpret_cast<const COMP_KMXPLUS_STRS *>(all);
|
||||
}
|
||||
|
|
@ -162,7 +162,7 @@ as_kmxplus_strs(void *data) {
|
|||
* @return section data or null on error
|
||||
*/
|
||||
static inline const COMP_KMXPLUS_KEYS *
|
||||
as_kmxplus_keys(void *data) {
|
||||
as_kmxplus_keys(const uint8_t *data) {
|
||||
const COMP_KMXPLUS_HEADER *all = validate_as_section(data, LDML_SECTION_KEYS);
|
||||
return reinterpret_cast<const COMP_KMXPLUS_KEYS *>(all);
|
||||
}
|
||||
|
|
@ -171,7 +171,7 @@ as_kmxplus_keys(void *data) {
|
|||
* @return section data or null on error
|
||||
*/
|
||||
static inline const COMP_KMXPLUS_LOCA *
|
||||
as_kmxplus_loca(void *data) {
|
||||
as_kmxplus_loca(const uint8_t *data) {
|
||||
const COMP_KMXPLUS_HEADER *all = validate_as_section(data, LDML_SECTION_LOCA);
|
||||
return reinterpret_cast<const COMP_KMXPLUS_LOCA *>(all);
|
||||
}
|
||||
|
|
@ -180,7 +180,7 @@ as_kmxplus_loca(void *data) {
|
|||
* @return section data or null on error
|
||||
*/
|
||||
static inline const COMP_KMXPLUS_META *
|
||||
as_kmxplus_meta(void *data) {
|
||||
as_kmxplus_meta(const uint8_t *data) {
|
||||
const COMP_KMXPLUS_HEADER *all = validate_as_section(data, LDML_SECTION_META);
|
||||
return reinterpret_cast<const COMP_KMXPLUS_META *>(all);
|
||||
}
|
||||
|
|
@ -189,13 +189,11 @@ as_kmxplus_meta(void *data) {
|
|||
* @return section data or null on error
|
||||
*/
|
||||
static inline const COMP_KMXPLUS_VKEY *
|
||||
as_kmxplus_vkey(void *data) {
|
||||
as_kmxplus_vkey(const uint8_t *data) {
|
||||
const COMP_KMXPLUS_HEADER *all = validate_as_section(data, LDML_SECTION_VKEY);
|
||||
return reinterpret_cast<const COMP_KMXPLUS_VKEY *>(all);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Temporary function to dump raw data
|
||||
*
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Reference in a new issue