diff --git a/src/preferences/keymap/Keymap.cpp b/src/preferences/keymap/Keymap.cpp index 97743af8a4..c3cae2ffca 100644 --- a/src/preferences/keymap/Keymap.cpp +++ b/src/preferences/keymap/Keymap.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2004-2008 Haiku Inc. All rights reserved. + * Copyright 2004-2009 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -8,75 +8,78 @@ */ #include "Keymap.h" + #include #include + #include #include + #include -static void -print_key(char *chars, int32 offset) + +static void +print_key(char *chars, int32 offset) { int size = chars[offset++]; - + switch (size) { - case 0: - // Not mapped - printf("N/A"); - break; - - case 1: - // 1-byte UTF-8/ASCII character - printf("%c", chars[offset]); - break; - - default: - // 2-, 3-, or 4-byte UTF-8 character - { - char *str = new char[size + 1]; - strncpy(str, &(chars[offset]), size); - str[size] = 0; - printf("%s", str); - delete [] str; - } - break; - } - - printf("\t"); + case 0: + // Not mapped + printf("N/A"); + break; + + case 1: + // 1-byte UTF-8/ASCII character + printf("%c", chars[offset]); + break; + + default: + { + // 2-, 3-, or 4-byte UTF-8 character + char *str = new char[size + 1]; + strncpy(str, &chars[offset], size); + str[size] = 0; + printf("%s", str); + delete[] str; + break; + } + } + + printf("\t"); } void Keymap::DumpKeymap() { - // Print a chart of the normal, shift, option, and option+shift - // keys. - printf("Key #\tNormal\tShift\tCaps\tC+S\tOption\tO+S\tO+C\tO+C+S\tControl\n"); - for (int i = 0; i < 128; i++) { - printf(" 0x%x\t", i); - print_key(fChars, fKeys.normal_map[i]); - print_key(fChars, fKeys.shift_map[i]); - print_key(fChars, fKeys.caps_map[i]); - print_key(fChars, fKeys.caps_shift_map[i]); - print_key(fChars, fKeys.option_map[i]); - print_key(fChars, fKeys.option_shift_map[i]); - print_key(fChars, fKeys.option_caps_map[i]); - print_key(fChars, fKeys.option_caps_shift_map[i]); - print_key(fChars, fKeys.control_map[i]); - printf("\n"); - } - + // Print a chart of the normal, shift, option, and option+shift + // keys. + printf("Key #\tNormal\tShift\tCaps\tC+S\tOption\tO+S\tO+C\tO+C+S\tControl\n"); + for (int i = 0; i < 128; i++) { + printf(" 0x%x\t", i); + print_key(fChars, fKeys.normal_map[i]); + print_key(fChars, fKeys.shift_map[i]); + print_key(fChars, fKeys.caps_map[i]); + print_key(fChars, fKeys.caps_shift_map[i]); + print_key(fChars, fKeys.option_map[i]); + print_key(fChars, fKeys.option_shift_map[i]); + print_key(fChars, fKeys.option_caps_map[i]); + print_key(fChars, fKeys.option_caps_shift_map[i]); + print_key(fChars, fKeys.control_map[i]); + printf("\n"); + } } /* file format in big endian : - struct key_map + struct key_map uint32 size of following charset charset (offsets go into this with size of character followed by character) */ // we load a map from a file -status_t +status_t Keymap::Load(entry_ref &ref) { status_t err; @@ -85,26 +88,26 @@ Keymap::Load(entry_ref &ref) fprintf(stderr, "error loading keymap: %s\n", strerror(err)); return err; } - + BFile file(&entry, B_READ_ONLY); if ((err = file.InitCheck()) != B_OK) { fprintf(stderr, "error loading keymap: %s\n", strerror(err)); return err; } - + if ((err = file.Read(&fKeys, sizeof(fKeys))) < (ssize_t)sizeof(fKeys)) { fprintf(stderr, "error reading keymap keys: %s\n", strerror(err)); return B_BAD_VALUE; } - + for (uint32 i=0; i