aboutsummaryrefslogtreecommitdiffstats
path: root/android/charmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'android/charmap.c')
-rw-r--r--android/charmap.c147
1 files changed, 26 insertions, 121 deletions
diff --git a/android/charmap.c b/android/charmap.c
index 81c866a..95dacee 100644
--- a/android/charmap.c
+++ b/android/charmap.c
@@ -133,73 +133,9 @@ static const AKeycodeMapEntry keycode_map[] = {
/* the following is automatically generated by the 'gen-charmap.py' script
* do not touch. the generation command was:
- * gen-charmap.py qwerty.kcm qwerty2.kcm
+ * gen-charmap.py qwerty2.kcm
*/
-static const AKeyEntry _qwerty_keys[] =
-{
- /* keycode base caps fn caps+fn number */
-
- { kKeyCodeA , 'a', 'A', '#', 0x00, '#' },
- { kKeyCodeB , 'b', 'B', '<', 0x00, '<' },
- { kKeyCodeC , 'c', 'C', '9', 0x00E7, '9' },
- { kKeyCodeD , 'd', 'D', '5', 0x00, '5' },
- { kKeyCodeE , 'e', 'E', '2', 0x0301, '2' },
- { kKeyCodeF , 'f', 'F', '6', 0x00A5, '6' },
- { kKeyCodeG , 'g', 'G', '-', '_', '-' },
- { kKeyCodeH , 'h', 'H', '[', '{', '[' },
- { kKeyCodeI , 'i', 'I', '$', 0x0302, '$' },
- { kKeyCodeJ , 'j', 'J', ']', '}', ']' },
- { kKeyCodeK , 'k', 'K', '"', '~', '"' },
- { kKeyCodeL , 'l', 'L', '\'', '`', '\'' },
- { kKeyCodeM , 'm', 'M', '!', 0x00, '!' },
- { kKeyCodeN , 'n', 'N', '>', 0x0303, '>' },
- { kKeyCodeO , 'o', 'O', '(', 0x00, '(' },
- { kKeyCodeP , 'p', 'P', ')', 0x00, ')' },
- { kKeyCodeQ , 'q', 'Q', '*', 0x0300, '*' },
- { kKeyCodeR , 'r', 'R', '3', 0x20AC, '3' },
- { kKeyCodeS , 's', 'S', '4', 0x00DF, '4' },
- { kKeyCodeT , 't', 'T', '+', 0x00A3, '+' },
- { kKeyCodeU , 'u', 'U', '&', 0x0308, '&' },
- { kKeyCodeV , 'v', 'V', '=', '^', '=' },
- { kKeyCodeW , 'w', 'W', '1', 0x00, '1' },
- { kKeyCodeX , 'x', 'X', '8', 0x00, '8' },
- { kKeyCodeY , 'y', 'Y', '%', 0x00A1, '%' },
- { kKeyCodeZ , 'z', 'Z', '7', 0x00, '7' },
- { kKeyCodeComma , ',', ';', ';', '|', ',' },
- { kKeyCodePeriod , '.', ':', ':', 0x2026, '.' },
- { kKeyCodeAt , '@', '0', '0', 0x2022, '0' },
- { kKeyCodeSlash , '/', '?', '?', '\\', '/' },
- { kKeyCodeSpace , 0x20, 0x20, 0x9, 0x9, 0x20 },
- { kKeyCodeNewline , 0xa, 0xa, 0xa, 0xa, 0xa },
- { kKeyCodeTab , 0x9, 0x9, 0x9, 0x9, 0x9 },
- { kKeyCode0 , '0', ')', '0', ')', '0' },
- { kKeyCode1 , '1', '!', '1', '!', '1' },
- { kKeyCode2 , '2', '@', '2', '@', '2' },
- { kKeyCode3 , '3', '#', '3', '#', '3' },
- { kKeyCode4 , '4', '$', '4', '$', '4' },
- { kKeyCode5 , '5', '%', '5', '%', '5' },
- { kKeyCode6 , '6', '^', '6', '^', '6' },
- { kKeyCode7 , '7', '&', '7', '&', '7' },
- { kKeyCode8 , '8', '*', '8', '*', '8' },
- { kKeyCode9 , '9', '(', '9', '(', '9' },
- { kKeyCodeGrave , '`', '~', '`', '~', '`' },
- { kKeyCodeMinus , '-', '_', '-', '_', '-' },
- { kKeyCodeEquals , '=', '+', '=', '+', '=' },
- { kKeyCodeLeftBracket , '[', '{', '[', '{', '[' },
- { kKeyCodeRightBracket , ']', '}', ']', '}', ']' },
- { kKeyCodeBackslash , '\\', '|', '\\', '|', '\\' },
- { kKeyCodeSemicolon , ';', ':', ';', ':', ';' },
- { kKeyCodeApostrophe , '\'', '"', '\'', '"', '\'' },
-};
-
-static const AKeyCharmap _qwerty_charmap =
-{
- _qwerty_keys,
- 51,
- "qwerty"
-};
-
static const AKeyEntry _qwerty2_keys[] =
{
/* keycode base caps fn caps+fn number */
@@ -257,7 +193,7 @@ static const AKeyEntry _qwerty2_keys[] =
{ kKeyCodeApostrophe , '\'', '"', '\'', '"', '\'' },
};
-static const AKeyCharmap _qwerty2_charmap =
+static const AKeyCharmap _default_charmap =
{
_qwerty2_keys,
51,
@@ -267,8 +203,7 @@ static const AKeyCharmap _qwerty2_charmap =
/* Custom character map created with -charmap option. */
static AKeyCharmap android_custom_charmap = { 0 };
-static const AKeyCharmap** android_charmaps = 0;
-static int android_charmap_count = 0;
+static const AKeyCharmap* android_charmap = &_default_charmap;
/* Checks if a character represents an end of the line.
* Returns a non-zero value if ch is an EOL character. Returns
@@ -692,31 +627,17 @@ parse_kcm_file(const char* kcm_file_path, AKeyCharmap* char_map) {
int
android_charmap_setup(const char* kcm_file_path) {
- // android_charmap_count being non-zero is used here as a flag,
- // indicating that charmap has been initialized for the running
- // executable.
- if (android_charmap_count != 0) {
+
+ /* Return if we already loaded a charmap */
+ if (android_charmap != &_default_charmap || kcm_file_path == NULL)
return 0;
- }
- if (NULL != kcm_file_path) {
- if (!parse_kcm_file(kcm_file_path, &android_custom_charmap)) {
- // Here we have two default charmaps and the custom one.
- android_charmap_count = 3;
- AARRAY_NEW(android_charmaps, android_charmap_count);
- android_charmaps[0] = &android_custom_charmap;
- android_charmaps[1] = &_qwerty_charmap;
- android_charmaps[2] = &_qwerty2_charmap;
- } else {
- derror("Unable to parse kcm file.");
- return -1;
- }
+ if (!parse_kcm_file(kcm_file_path, &android_custom_charmap)) {
+ // Here we have the default charmap and the custom one.
+ android_charmap = &android_custom_charmap;
} else {
- // Here we have only two default charmaps.
- android_charmap_count = 2;
- AARRAY_NEW(android_charmaps, android_charmap_count);
- android_charmaps[0] = &_qwerty_charmap;
- android_charmaps[1] = &_qwerty2_charmap;
+ derror("Unable to parse kcm file.");
+ return -1;
}
return 0;
@@ -724,40 +645,21 @@ android_charmap_setup(const char* kcm_file_path) {
void
android_charmap_done(void) {
- if (NULL != android_charmaps) {
- int n;
- for (n = 0; n < android_charmap_count; n++) {
- // Entries for qwerty and qwerty2 character maps are
- // static entries defined in charmap.c
- if ((_qwerty_charmap.entries != android_charmaps[n]->entries) &&
- (_qwerty2_charmap.entries != android_charmaps[n]->entries)) {
- AFREE((void*)android_charmaps[n]->entries);
- }
- }
- AFREE(android_charmaps);
- }
+ if (android_charmap != &_default_charmap)
+ AFREE((void*)android_charmap->entries);
}
const AKeyCharmap*
android_get_charmap_by_name(const char* name) {
- int nn;
-
if (name != NULL) {
- // Find charmap by its name in the array of available charmaps.
- for (nn = 0; nn < android_charmap_count; nn++) {
- if (!strcmp(android_charmaps[nn]->name, name)) {
- return android_charmaps[nn];
- }
- }
+ if (!strcmp(android_charmap->name, name))
+ return android_charmap;
+ if (!strcmp(_default_charmap.name, name))
+ return &_default_charmap;
}
return NULL;
}
-const AKeyCharmap*
-android_get_charmap_by_index(unsigned int index) {
- return index < android_charmap_count ? android_charmaps[index] : NULL;
-}
-
int
android_charmap_reverse_map_unicode(const AKeyCharmap* cmap,
unsigned int unicode,
@@ -825,14 +727,17 @@ android_charmap_reverse_map_unicode(const AKeyCharmap* cmap,
return 0;
}
-const AKeyCharmap*
-android_get_default_charmap(void)
+const AKeyCharmap* android_get_default_charmap(void)
+{
+ return &_default_charmap;
+}
+
+const AKeyCharmap* android_get_charmap(void)
{
- return android_get_charmap_by_index(0);
+ return android_charmap;
}
-const char*
-android_get_default_charmap_name(void)
+const char* android_get_charmap_name(void)
{
- return android_get_default_charmap()->name;
+ return android_get_charmap()->name;
}