* Reworked GetKey() after Marcus' suggestions. Thanks for the extra motivation
to work on this :-) * Also made it return "false" if there was no mapping, which will prevent empty dead keys to be written now (ie. the output now looks exactly like our sources). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31222 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+32
-32
@@ -1092,42 +1092,40 @@ Keymap::RestoreSystemDefault()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*static*/ void
|
/*static*/ bool
|
||||||
Keymap::GetKey(char* chars, int32 offset, char* string)
|
Keymap::GetKey(const char* chars, int32 offset, char* buffer, size_t bufferSize)
|
||||||
{
|
{
|
||||||
int size = chars[offset++];
|
uint8 size = (uint8)chars[offset++];
|
||||||
char str[32];
|
char string[1024];
|
||||||
memset(str, 0, 32);
|
|
||||||
memset(string, 0, 32);
|
|
||||||
|
|
||||||
switch (size) {
|
switch (size) {
|
||||||
case 0:
|
case 0:
|
||||||
// Not mapped
|
// Not mapped
|
||||||
sprintf(str, "''");
|
strlcpy(buffer, "''", bufferSize);
|
||||||
break;
|
return false;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// 1-byte UTF-8/ASCII character
|
// 1-byte UTF-8/ASCII character
|
||||||
if ((uint8)chars[offset] < 0x20
|
if ((uint8)chars[offset] < 0x20 || (uint8)chars[offset] > 0x7e)
|
||||||
|| (uint8)chars[offset] > 0x7e)
|
sprintf(string, "0x%02x", (uint8)chars[offset]);
|
||||||
sprintf(str, "0x%02x", (uint8)chars[offset]);
|
else {
|
||||||
else
|
sprintf(string, "'%s%c'",
|
||||||
sprintf(str, "'%s%c'",
|
|
||||||
(chars[offset] == '\\' || chars[offset] == '\'') ? "\\" : "",
|
(chars[offset] == '\\' || chars[offset] == '\'') ? "\\" : "",
|
||||||
chars[offset]);
|
chars[offset]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// n-byte UTF-8/ASCII character
|
// multi-byte UTF-8 character
|
||||||
sprintf(str, "0x");
|
sprintf(string, "0x");
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
sprintf(str + 2*(i+1), "%02x", (uint8)chars[offset+i]);
|
sprintf(string + 2 * (i + 1), "%02x", (uint8)chars[offset + i]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(string, str, strlen(str) < 12 ? strlen(str) : 12);
|
strlcpy(buffer, string, bufferSize);
|
||||||
// TODO: Huh?
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1295,7 +1293,7 @@ Keymap::_SaveSourceText(FILE* file)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (int idx = 0; idx < 128; idx++) {
|
for (int i = 0; i < 128; i++) {
|
||||||
char normalKey[32];
|
char normalKey[32];
|
||||||
char shiftKey[32];
|
char shiftKey[32];
|
||||||
char controlKey[32];
|
char controlKey[32];
|
||||||
@@ -1306,17 +1304,17 @@ Keymap::_SaveSourceText(FILE* file)
|
|||||||
char optionCapsKey[32];
|
char optionCapsKey[32];
|
||||||
char optionCapsShiftKey[32];
|
char optionCapsShiftKey[32];
|
||||||
|
|
||||||
GetKey(fChars, fKeys.normal_map[idx], normalKey);
|
GetKey(fChars, fKeys.normal_map[i], normalKey, 32);
|
||||||
GetKey(fChars, fKeys.shift_map[idx], shiftKey);
|
GetKey(fChars, fKeys.shift_map[i], shiftKey, 32);
|
||||||
GetKey(fChars, fKeys.control_map[idx], controlKey);
|
GetKey(fChars, fKeys.control_map[i], controlKey, 32);
|
||||||
GetKey(fChars, fKeys.option_map[idx], optionKey);
|
GetKey(fChars, fKeys.option_map[i], optionKey, 32);
|
||||||
GetKey(fChars, fKeys.option_shift_map[idx], optionShiftKey);
|
GetKey(fChars, fKeys.option_shift_map[i], optionShiftKey, 32);
|
||||||
GetKey(fChars, fKeys.caps_map[idx], capsKey);
|
GetKey(fChars, fKeys.caps_map[i], capsKey, 32);
|
||||||
GetKey(fChars, fKeys.caps_shift_map[idx], capsShiftKey);
|
GetKey(fChars, fKeys.caps_shift_map[i], capsShiftKey, 32);
|
||||||
GetKey(fChars, fKeys.option_caps_map[idx], optionCapsKey);
|
GetKey(fChars, fKeys.option_caps_map[i], optionCapsKey, 32);
|
||||||
GetKey(fChars, fKeys.option_caps_shift_map[idx], optionCapsShiftKey);
|
GetKey(fChars, fKeys.option_caps_shift_map[i], optionCapsShiftKey, 32);
|
||||||
|
|
||||||
fprintf(file, "Key 0x%02x = %-9s%-9s%-9s%-9s%-9s%-9s%-9s%-9s%-9s\n", idx,
|
fprintf(file, "Key 0x%02x = %-9s%-9s%-9s%-9s%-9s%-9s%-9s%-9s%-9s\n", i,
|
||||||
normalKey, shiftKey, controlKey, optionKey, optionShiftKey, capsKey,
|
normalKey, shiftKey, controlKey, optionKey, optionShiftKey, capsKey,
|
||||||
capsShiftKey, optionCapsKey, optionCapsShiftKey);
|
capsShiftKey, optionCapsKey, optionCapsShiftKey);
|
||||||
}
|
}
|
||||||
@@ -1346,11 +1344,13 @@ Keymap::_SaveSourceText(FILE* file)
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
for (int idx = 0; idx < 32; idx++) {
|
for (int deadIndex = 0; deadIndex < 32; deadIndex++) {
|
||||||
char deadKey[32];
|
char deadKey[32];
|
||||||
char secondKey[32];
|
char secondKey[32];
|
||||||
GetKey(fChars, deadOffsets[i][idx++], deadKey);
|
if (!GetKey(fChars, deadOffsets[i][deadIndex++], deadKey, 32))
|
||||||
GetKey(fChars, deadOffsets[i][idx], secondKey);
|
break;
|
||||||
|
|
||||||
|
GetKey(fChars, deadOffsets[i][deadIndex], secondKey, 32);
|
||||||
fprintf(file, "%s %-9s = %-9s\n", labels[i], deadKey, secondKey);
|
fprintf(file, "%s %-9s = %-9s\n", labels[i], deadKey, secondKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ public:
|
|||||||
uint8 activeDeadKey, char** chars,
|
uint8 activeDeadKey, char** chars,
|
||||||
int32* numBytes);
|
int32* numBytes);
|
||||||
void RestoreSystemDefault();
|
void RestoreSystemDefault();
|
||||||
static void GetKey(char* chars, int32 offset, char* string);
|
static bool GetKey(const char* chars, int32 offset,
|
||||||
|
char* buffer, size_t bufferSize);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if (defined(__BEOS__) || defined(__HAIKU__))
|
#if (defined(__BEOS__) || defined(__HAIKU__))
|
||||||
|
|||||||
Reference in New Issue
Block a user