diff --git a/src/apps/bin/keymap/Keymap.cpp b/src/apps/bin/keymap/Keymap.cpp index 1c456ec392..a5230682b0 100644 --- a/src/apps/bin/keymap/Keymap.cpp +++ b/src/apps/bin/keymap/Keymap.cpp @@ -14,7 +14,6 @@ // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #include "Keymap.h" -#include #include #include #include @@ -24,6 +23,8 @@ #include #include +#define CHARS_TABLE_MAXSIZE 10000 + void Keymap::GetKey( char *chars, int32 offset, char* string) { @@ -266,6 +267,79 @@ Keymap::Load(entry_ref &ref) return B_OK; } + +void +Keymap::ComputeChars(const char *buffer, struct re_registers ®s, int i, int &offset) +{ + char *current = &fChars[offset+1]; + char hexChars[12]; + uint32 length = 0; + if (strncmp(buffer + regs.start[i], "''", regs.end[i] - regs.start[i]) == 0) + length = 0; + else if (sscanf(buffer + regs.start[i], "'%s'", current) > 0) { + if (current[0] == '\\') + current[0] = current[1]; + else if (current[0] == '\'') + current[0] = ' '; + length = 1; + } else if (sscanf(buffer + regs.start[i], "0x%s", hexChars) > 0) { + length = strlen(hexChars) / 2; + for (uint32 j=0; j 0) { - if (current[0] == '\\') - current[0] = current[1]; - else if (current[0] == '\'') - current[0] = ' '; - length = 1; - } else if (sscanf(buffer + regs.start[i], "0x%s", hexChars) > 0) { - length = strlen(hexChars) / 2; - for (uint32 j=0; j= 0) { sscanf(buffer + regs.start[1], "0x%lx", &fKeys.menu_key); } else if (re_search(&locksettingsBuf, buffer, strlen(buffer), 0, strlen(buffer), ®s) >= 0) { + fKeys.lock_settings = 0; for (int32 i=1; i<=3; i++) { + if (regs.end[i] - regs.start[i] <= 0) + break; if (strncmp(buffer + regs.start[i], "CapsLock", regs.end[i] - regs.start[i]) == 0) fKeys.lock_settings |= B_CAPS_LOCK; else if (strncmp(buffer + regs.start[i], "NumLock", regs.end[i] - regs.start[i]) == 0) @@ -521,14 +637,21 @@ Keymap::LoadSource(entry_ref &ref) fKeys.tilde_dead_key[tildeOffset++] = offset; ComputeChars(buffer, regs, i, offset); } + } else if (re_search(´tabBuf, buffer, strlen(buffer), 0, strlen(buffer), ®s) >= 0) { + ComputeTables(buffer, regs, fKeys.acute_tables); + } else if (re_search(&gravetabBuf, buffer, strlen(buffer), 0, strlen(buffer), ®s) >= 0) { + ComputeTables(buffer, regs, fKeys.grave_tables); + } else if (re_search(&circumflextabBuf, buffer, strlen(buffer), 0, strlen(buffer), ®s) >= 0) { + ComputeTables(buffer, regs, fKeys.circumflex_tables); + } else if (re_search(&diaeresistabBuf, buffer, strlen(buffer), 0, strlen(buffer), ®s) >= 0) { + ComputeTables(buffer, regs, fKeys.dieresis_tables); + } else if (re_search(&tildetabBuf, buffer, strlen(buffer), 0, strlen(buffer), ®s) >= 0) { + ComputeTables(buffer, regs, fKeys.tilde_tables); } } - /* - for (uint32 i=1; i < 3; i++) { - printf("%.*s\n", regs.end[i] - regs.start[i], buffer + regs.start[i]); - } - */ - + + fCharsSize = offset; + return B_OK; } @@ -823,3 +946,32 @@ Keymap::RestoreSystemDefault() _restore_key_map_(); } + + +void +Keymap::SaveAsCurrent() +{ + BPath path; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path)!=B_OK) + return; + + path.Append("Key_map"); + + entry_ref ref; + get_ref_for_path(path.Path(), &ref); + + status_t err; + if ((err = Save(ref)) != B_OK) { + printf("error when saving : %s", strerror(err)); + return; + } + Use(); +} + + +// we make our input server use the map in /boot/home/config/settings/Keymap +status_t +Keymap::Use() +{ + return _restore_key_map_(); +} diff --git a/src/apps/bin/keymap/Keymap.h b/src/apps/bin/keymap/Keymap.h index e838e931e6..094f4c30b7 100644 --- a/src/apps/bin/keymap/Keymap.h +++ b/src/apps/bin/keymap/Keymap.h @@ -18,6 +18,7 @@ #include #include +#include class Keymap { @@ -25,7 +26,10 @@ public: void LoadCurrent(); status_t Load(entry_ref &ref); status_t Save(entry_ref &ref); - status_t LoadSource(entry_ref &ref); + status_t LoadSource(FILE *f); + status_t LoadSourceFromRef(entry_ref &ref); + void SaveAsCurrent(); + status_t Use(); void Dump(); bool IsModifierKey(uint32 keyCode); uint8 IsDeadKey(uint32 keyCode, uint32 modifiers); @@ -35,7 +39,7 @@ public: static void GetKey( char *chars, int32 offset, char* string); private: void ComputeChars(const char *buffer, struct re_registers ®s, int i, int &offset); - + void ComputeTables(const char *buffer, struct re_registers ®s, uint32 &table); char *fChars; key_map fKeys; uint32 fCharsSize; diff --git a/src/apps/bin/keymap/key_map.cpp b/src/apps/bin/keymap/key_map.cpp index 619186fea5..683bc76790 100644 --- a/src/apps/bin/keymap/key_map.cpp +++ b/src/apps/bin/keymap/key_map.cpp @@ -21,15 +21,21 @@ static void usage(char *prog) { printf( -"usage: %s -d # dump key map to standard output\n" -" %s -l # load key map from standard input\n" -" %s -r # restore system default key map\n", prog, prog, prog); +"usage: %s {-o output_file} -[d|l|r|c] \n" +" -d # dump key map to standard output\n" +" -l # load key map from standard input\n" +" -r # restore system default key map\n" +" -c # compile source keymap to binary\n" +" -o # change output file to output_file (default:keymap.out)\n" + , prog); } int main(int argc, char **argv) { char operation = ' '; + entry_ref output_ref; + get_ref_for_path("keymap.out", &output_ref); int i; for (i = 1; i < argc; i++) { if (strncmp(argv[i], "-", 1) == 0) { @@ -42,22 +48,28 @@ int main(int argc, char **argv) keymap.LoadCurrent(); keymap.Dump(); return 0; - } - if (operation == 'r') { + } else if (operation == 'r') { Keymap keymap; keymap.RestoreSystemDefault(); return 0; + } else if (operation == 'l') { + Keymap keymap; + keymap.LoadSource(stdin); + + keymap.SaveAsCurrent(); + return 0; } } else { if (operation == 'o') { - return 0; - } if (operation == 'l') { + get_ref_for_path(argv[i], &output_ref); + } else if (operation == 'c') { entry_ref ref; get_ref_for_path(argv[i], &ref); Keymap keymap; - keymap.LoadSource(ref); - keymap.Dump(); + keymap.LoadSourceFromRef(ref); + + keymap.Save(output_ref); return 0; } else break;