* Further improved error handling in class Keymap.
* Improved header output, it now looks a lot nicer. * Fixed style issues of that header, too: replaced "s" prefix with the correct "k" prefix. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17690 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
f4e8263700
commit
c8467d6ba1
@ -24,6 +24,41 @@
|
|||||||
#define CHARS_TABLE_MAXSIZE 10000
|
#define CHARS_TABLE_MAXSIZE 10000
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
dump_map(FILE* file, const char* name, int32* map)
|
||||||
|
{
|
||||||
|
fprintf(file, "\t%s:{\n", name);
|
||||||
|
|
||||||
|
for (uint32 i = 0; i < 16; i++) {
|
||||||
|
fprintf(file, "\t\t");
|
||||||
|
for (uint32 j = 0; j < 8; j++) {
|
||||||
|
fprintf(file, "0x%04lx,%s", map[i * 8 + j], j < 7 ? " " : "");
|
||||||
|
}
|
||||||
|
fprintf(file, "\n");
|
||||||
|
}
|
||||||
|
fprintf(file, "\t},\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
dump_keys(FILE* file, const char* name, int32* keys)
|
||||||
|
{
|
||||||
|
fprintf(file, "\t%s:{\n", name);
|
||||||
|
|
||||||
|
for (uint32 i = 0; i < 4; i++) {
|
||||||
|
fprintf(file, "\t\t");
|
||||||
|
for (uint32 j = 0; j < 8; j++) {
|
||||||
|
fprintf(file, "0x%04lx,%s", keys[i * 8 + j], j < 7 ? " " : "");
|
||||||
|
}
|
||||||
|
fprintf(file, "\n");
|
||||||
|
}
|
||||||
|
fprintf(file, "\t},\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
Keymap::Keymap()
|
Keymap::Keymap()
|
||||||
:
|
:
|
||||||
fChars(NULL),
|
fChars(NULL),
|
||||||
@ -65,11 +100,14 @@ Keymap::GetKey(char *chars, int32 offset, char* string)
|
|||||||
default:
|
default:
|
||||||
// n-byte UTF-8/ASCII character
|
// n-byte UTF-8/ASCII character
|
||||||
sprintf(str, "0x");
|
sprintf(str, "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(str + 2*(i+1), "%02x", (uint8)chars[offset+i]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
strncpy(string, str, (strlen(str) < 12) ? strlen(str) : 12);
|
|
||||||
|
strncpy(string, str, strlen(str) < 12 ? strlen(str) : 12);
|
||||||
|
// TODO: Huh?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -235,10 +273,9 @@ Keymap::LoadCurrent()
|
|||||||
#ifdef __BEOS__
|
#ifdef __BEOS__
|
||||||
key_map *keys = NULL;
|
key_map *keys = NULL;
|
||||||
get_key_map(&keys, &fChars);
|
get_key_map(&keys, &fChars);
|
||||||
if (!keys) {
|
if (!keys)
|
||||||
fprintf(stderr, "error while getting current keymap!\n");
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
|
||||||
memcpy(&fKeys, keys, sizeof(fKeys));
|
memcpy(&fKeys, keys, sizeof(fKeys));
|
||||||
free(keys);
|
free(keys);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@ -264,10 +301,8 @@ Keymap::Load(entry_ref &ref)
|
|||||||
status_t err;
|
status_t err;
|
||||||
|
|
||||||
BFile file(&ref, B_READ_ONLY);
|
BFile file(&ref, B_READ_ONLY);
|
||||||
if ((err = file.InitCheck()) != B_OK) {
|
if ((err = file.InitCheck()) != B_OK)
|
||||||
printf("error %s\n", strerror(err));
|
|
||||||
return err;
|
return err;
|
||||||
}
|
|
||||||
|
|
||||||
if (file.Read(&fKeys, sizeof(fKeys)) < (ssize_t)sizeof(fKeys))
|
if (file.Read(&fKeys, sizeof(fKeys)) < (ssize_t)sizeof(fKeys))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
@ -351,15 +386,18 @@ Keymap::LoadSourceFromRef(entry_ref &ref)
|
|||||||
status_t err;
|
status_t err;
|
||||||
|
|
||||||
BFile file(&ref, B_READ_ONLY);
|
BFile file(&ref, B_READ_ONLY);
|
||||||
if ((err = file.InitCheck()) != B_OK) {
|
if ((err = file.InitCheck()) != B_OK)
|
||||||
printf("error %s\n", strerror(err));
|
|
||||||
return err;
|
return err;
|
||||||
}
|
|
||||||
|
|
||||||
int fd = file.Dup();
|
int fd = file.Dup();
|
||||||
FILE * f = fdopen(fd, "r");
|
FILE* f = fdopen(fd, "r");
|
||||||
|
if (f != NULL) {
|
||||||
return LoadSource(f);
|
err = LoadSource(f);
|
||||||
|
fclose(f);
|
||||||
|
} else
|
||||||
|
err = B_FILE_ERROR;
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -684,174 +722,126 @@ Keymap::LoadSource(FILE * f)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// we save a map to a file
|
//! we save a map to a file
|
||||||
status_t
|
status_t
|
||||||
Keymap::Save(entry_ref &ref)
|
Keymap::Save(entry_ref &ref)
|
||||||
{
|
{
|
||||||
status_t err;
|
status_t err;
|
||||||
|
|
||||||
BFile file(&ref, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
|
BFile file(&ref, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
|
||||||
if ((err = file.InitCheck()) != B_OK) {
|
if ((err = file.InitCheck()) != B_OK)
|
||||||
printf("error %s\n", strerror(err));
|
|
||||||
return err;
|
return err;
|
||||||
}
|
|
||||||
|
// convert to big endian
|
||||||
for (uint32 i=0; i<sizeof(fKeys)/4; i++)
|
for (uint32 i = 0; i < sizeof(fKeys) / sizeof(uint32); i++) {
|
||||||
((uint32*)&fKeys)[i] = B_HOST_TO_BENDIAN_INT32(((uint32*)&fKeys)[i]);
|
((uint32*)&fKeys)[i] = B_HOST_TO_BENDIAN_INT32(((uint32*)&fKeys)[i]);
|
||||||
|
|
||||||
if ((err = file.Write(&fKeys, sizeof(fKeys))) < (ssize_t)sizeof(fKeys)) {
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32 i=0; i<sizeof(fKeys)/4; i++)
|
ssize_t bytesWritten = file.Write(&fKeys, sizeof(fKeys));
|
||||||
|
|
||||||
|
// convert endian back
|
||||||
|
for (uint32 i = 0; i < sizeof(fKeys) / sizeof(uint32); i++) {
|
||||||
((uint32*)&fKeys)[i] = B_BENDIAN_TO_HOST_INT32(((uint32*)&fKeys)[i]);
|
((uint32*)&fKeys)[i] = B_BENDIAN_TO_HOST_INT32(((uint32*)&fKeys)[i]);
|
||||||
|
|
||||||
fCharsSize = B_HOST_TO_BENDIAN_INT32(fCharsSize);
|
|
||||||
|
|
||||||
if ((err = file.Write(&fCharsSize, sizeof(uint32))) < (ssize_t)sizeof(uint32)) {
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fCharsSize = B_BENDIAN_TO_HOST_INT32(fCharsSize);
|
if (bytesWritten < (ssize_t)sizeof(fKeys))
|
||||||
|
return B_ERROR;
|
||||||
if ((err = file.Write(fChars, fCharsSize)) < (ssize_t)fCharsSize)
|
if (bytesWritten < B_OK)
|
||||||
return err;
|
return bytesWritten;
|
||||||
|
|
||||||
|
uint32 charSize = B_HOST_TO_BENDIAN_INT32(fCharsSize);
|
||||||
|
|
||||||
|
bytesWritten = file.Write(&charSize, sizeof(uint32));
|
||||||
|
if (bytesWritten < (ssize_t)sizeof(uint32))
|
||||||
|
return B_ERROR;
|
||||||
|
if (bytesWritten < B_OK)
|
||||||
|
return bytesWritten;
|
||||||
|
|
||||||
|
bytesWritten = file.Write(fChars, fCharsSize);
|
||||||
|
if (bytesWritten < (ssize_t)fCharsSize)
|
||||||
|
return B_ERROR;
|
||||||
|
if (bytesWritten < B_OK)
|
||||||
|
return bytesWritten;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char header_header[] =
|
/*!
|
||||||
"/*\tHaiku \t*/\n"
|
Save a keymap as C source file - this is used to get the default keymap
|
||||||
"/*\n"
|
into the input_server, for example.
|
||||||
" This file is generated automatically. Don't edit ! \n"
|
*/
|
||||||
"*/\n\n";
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Keymap::SaveAsHeader(entry_ref &ref)
|
Keymap::SaveAsHeader(entry_ref &ref)
|
||||||
{
|
{
|
||||||
status_t err;
|
BPath path;
|
||||||
|
status_t err = path.SetTo(&ref);
|
||||||
|
if (err < B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
BFile file(&ref, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
FILE* file = fopen(path.Path(), "w");
|
||||||
if ((err = file.InitCheck()) != B_OK) {
|
|
||||||
printf("error %s\n", strerror(err));
|
fprintf(file, "/*\n"
|
||||||
return;
|
" * Haiku Keymap\n"
|
||||||
|
" * This file is generated automatically. Don't edit!\n"
|
||||||
|
" */\n\n");
|
||||||
|
fprintf(file, "#include <InterfaceDefs.h>\n\n");
|
||||||
|
fprintf(file, "const key_map kSystemKeymap = {\n");
|
||||||
|
fprintf(file, "\tversion:%ld,\n", fKeys.version);
|
||||||
|
fprintf(file, "\tcaps_key:0x%lx,\n", fKeys.caps_key);
|
||||||
|
fprintf(file, "\tscroll_key:0x%lx,\n", fKeys.scroll_key);
|
||||||
|
fprintf(file, "\tnum_key:0x%lx,\n", fKeys.num_key);
|
||||||
|
fprintf(file, "\tleft_shift_key:0x%lx,\n", fKeys.left_shift_key);
|
||||||
|
fprintf(file, "\tright_shift_key:0x%lx,\n", fKeys.right_shift_key);
|
||||||
|
fprintf(file, "\tleft_command_key:0x%lx,\n", fKeys.left_command_key);
|
||||||
|
fprintf(file, "\tright_command_key:0x%lx,\n", fKeys.right_command_key);
|
||||||
|
fprintf(file, "\tleft_control_key:0x%lx,\n", fKeys.left_control_key);
|
||||||
|
fprintf(file, "\tright_control_key:0x%lx,\n", fKeys.right_control_key);
|
||||||
|
fprintf(file, "\tleft_option_key:0x%lx,\n", fKeys.left_option_key);
|
||||||
|
fprintf(file, "\tright_option_key:0x%lx,\n", fKeys.right_option_key);
|
||||||
|
fprintf(file, "\tmenu_key:0x%lx,\n", fKeys.menu_key);
|
||||||
|
fprintf(file, "\tlock_settings:0x%lx,\n", fKeys.lock_settings);
|
||||||
|
|
||||||
|
dump_map(file, "control_map", fKeys.control_map);
|
||||||
|
dump_map(file, "option_caps_shift_map", fKeys.option_caps_shift_map);
|
||||||
|
dump_map(file, "option_caps_map", fKeys.option_caps_map);
|
||||||
|
dump_map(file, "option_shift_map", fKeys.option_shift_map);
|
||||||
|
dump_map(file, "option_map", fKeys.option_map);
|
||||||
|
dump_map(file, "caps_shift_map", fKeys.caps_shift_map);
|
||||||
|
dump_map(file, "caps_map", fKeys.caps_map);
|
||||||
|
dump_map(file, "shift_map", fKeys.shift_map);
|
||||||
|
dump_map(file, "normal_map", fKeys.normal_map);
|
||||||
|
|
||||||
|
dump_keys(file, "acute_dead_key", fKeys.acute_dead_key);
|
||||||
|
dump_keys(file, "grave_dead_key", fKeys.grave_dead_key);
|
||||||
|
|
||||||
|
dump_keys(file, "circumflex_dead_key", fKeys.circumflex_dead_key);
|
||||||
|
dump_keys(file, "dieresis_dead_key", fKeys.dieresis_dead_key);
|
||||||
|
dump_keys(file, "tilde_dead_key", fKeys.tilde_dead_key);
|
||||||
|
|
||||||
|
fprintf(file, "\tacute_tables:0x%lx,\n", fKeys.acute_tables);
|
||||||
|
fprintf(file, "\tgrave_tables:0x%lx,\n", fKeys.grave_tables);
|
||||||
|
fprintf(file, "\tcircumflex_tables:0x%lx,\n", fKeys.circumflex_tables);
|
||||||
|
fprintf(file, "\tdieresis_tables:0x%lx,\n", fKeys.dieresis_tables);
|
||||||
|
fprintf(file, "\ttilde_tables:0x%lx,\n", fKeys.tilde_tables);
|
||||||
|
|
||||||
|
fprintf(file, "};\n\n");
|
||||||
|
|
||||||
|
fprintf(file, "const char kSystemKeyChars[] = {\n");
|
||||||
|
for (uint32 i = 0; i < fCharsSize; i++) {
|
||||||
|
if (i % 10 == 0) {
|
||||||
|
if (i > 0)
|
||||||
|
fprintf(file, "\n");
|
||||||
|
fprintf(file, "\t");
|
||||||
|
} else
|
||||||
|
fprintf(file, " ");
|
||||||
|
|
||||||
|
fprintf(file, "0x%02x,", (uint8)fChars[i]);
|
||||||
}
|
}
|
||||||
|
fprintf(file, "\n};\n\n");
|
||||||
|
|
||||||
int fd = file.Dup();
|
fprintf(file, "const uint32 kSystemKeyCharsSize = %ld;\n", fCharsSize);
|
||||||
FILE * f = fdopen(fd, "w");
|
fclose(file);
|
||||||
|
|
||||||
fprintf(f, "%s", header_header);
|
|
||||||
fprintf(f, "#include <InterfaceDefs.h>\n\n");
|
|
||||||
fprintf(f, "const key_map sSystemKeymap = {\n");
|
|
||||||
fprintf(f, "\tversion:%ld,\n", fKeys.version);
|
|
||||||
fprintf(f, "\tcaps_key:0x%lx,\n", fKeys.caps_key);
|
|
||||||
fprintf(f, "\tscroll_key:0x%lx,\n", fKeys.scroll_key);
|
|
||||||
fprintf(f, "\tnum_key:0x%lx,\n", fKeys.num_key);
|
|
||||||
fprintf(f, "\tleft_shift_key:0x%lx,\n", fKeys.left_shift_key);
|
|
||||||
fprintf(f, "\tright_shift_key:0x%lx,\n", fKeys.right_shift_key);
|
|
||||||
fprintf(f, "\tleft_command_key:0x%lx,\n", fKeys.left_command_key);
|
|
||||||
fprintf(f, "\tright_command_key:0x%lx,\n", fKeys.right_command_key);
|
|
||||||
fprintf(f, "\tleft_control_key:0x%lx,\n", fKeys.left_control_key);
|
|
||||||
fprintf(f, "\tright_control_key:0x%lx,\n", fKeys.right_control_key);
|
|
||||||
fprintf(f, "\tleft_option_key:0x%lx,\n", fKeys.left_option_key);
|
|
||||||
fprintf(f, "\tright_option_key:0x%lx,\n", fKeys.right_option_key);
|
|
||||||
fprintf(f, "\tmenu_key:0x%lx,\n", fKeys.menu_key);
|
|
||||||
fprintf(f, "\tlock_settings:0x%lx,\n", fKeys.lock_settings);
|
|
||||||
|
|
||||||
fprintf(f, "\tcontrol_map:{\n");
|
|
||||||
for (uint32 i = 0; i < 128; i++) {
|
|
||||||
fprintf(f, "\t\t%ld,\n", fKeys.control_map[i]);
|
|
||||||
}
|
|
||||||
fprintf(f, "\t},\n");
|
|
||||||
|
|
||||||
fprintf(f, "\toption_caps_shift_map:{\n");
|
|
||||||
for (uint32 i = 0; i < 128; i++) {
|
|
||||||
fprintf(f, "\t\t%ld,\n", fKeys.option_caps_shift_map[i]);
|
|
||||||
}
|
|
||||||
fprintf(f, "\t},\n");
|
|
||||||
|
|
||||||
fprintf(f, "\toption_caps_map:{\n");
|
|
||||||
for (uint32 i = 0; i < 128; i++) {
|
|
||||||
fprintf(f, "\t\t%ld,\n", fKeys.option_caps_map[i]);
|
|
||||||
}
|
|
||||||
fprintf(f, "\t},\n");
|
|
||||||
|
|
||||||
fprintf(f, "\toption_shift_map:{\n");
|
|
||||||
for (uint32 i = 0; i < 128; i++) {
|
|
||||||
fprintf(f, "\t\t%ld,\n", fKeys.option_shift_map[i]);
|
|
||||||
}
|
|
||||||
fprintf(f, "\t},\n");
|
|
||||||
|
|
||||||
fprintf(f, "\toption_map:{\n");
|
|
||||||
for (uint32 i=0; i<128; i++)
|
|
||||||
fprintf(f, "\t\t%ld,\n", fKeys.option_map[i]);
|
|
||||||
fprintf(f, "\t},\n");
|
|
||||||
|
|
||||||
fprintf(f, "\tcaps_shift_map:{\n");
|
|
||||||
for (uint32 i=0; i<128; i++)
|
|
||||||
fprintf(f, "\t\t%ld,\n", fKeys.caps_shift_map[i]);
|
|
||||||
fprintf(f, "\t},\n");
|
|
||||||
|
|
||||||
fprintf(f, "\tcaps_map:{\n");
|
|
||||||
for (uint32 i=0; i<128; i++)
|
|
||||||
fprintf(f, "\t\t%ld,\n", fKeys.caps_map[i]);
|
|
||||||
fprintf(f, "\t},\n");
|
|
||||||
|
|
||||||
fprintf(f, "\tshift_map:{\n");
|
|
||||||
for (uint32 i=0; i<128; i++)
|
|
||||||
fprintf(f, "\t\t%ld,\n", fKeys.shift_map[i]);
|
|
||||||
fprintf(f, "\t},\n");
|
|
||||||
|
|
||||||
fprintf(f, "\tnormal_map:{\n");
|
|
||||||
for (uint32 i=0; i<128; i++)
|
|
||||||
fprintf(f, "\t\t%ld,\n", fKeys.normal_map[i]);
|
|
||||||
fprintf(f, "\t},\n");
|
|
||||||
|
|
||||||
fprintf(f, "\tacute_dead_key:{\n");
|
|
||||||
for (uint32 i=0; i<32; i++)
|
|
||||||
fprintf(f, "\t\t%ld,\n", fKeys.acute_dead_key[i]);
|
|
||||||
fprintf(f, "\t},\n");
|
|
||||||
|
|
||||||
fprintf(f, "\tgrave_dead_key:{\n");
|
|
||||||
for (uint32 i = 0; i < 32; i++) {
|
|
||||||
fprintf(f, "\t\t%ld,\n", fKeys.grave_dead_key[i]);
|
|
||||||
}
|
|
||||||
fprintf(f, "\t},\n");
|
|
||||||
|
|
||||||
fprintf(f, "\tcircumflex_dead_key:{\n");
|
|
||||||
for (uint32 i = 0; i < 32; i++) {
|
|
||||||
fprintf(f, "\t\t%ld,\n", fKeys.circumflex_dead_key[i]);
|
|
||||||
}
|
|
||||||
fprintf(f, "\t},\n");
|
|
||||||
|
|
||||||
fprintf(f, "\tdieresis_dead_key:{\n");
|
|
||||||
for (uint32 i = 0; i < 32; i++) {
|
|
||||||
fprintf(f, "\t\t%ld,\n", fKeys.dieresis_dead_key[i]);
|
|
||||||
}
|
|
||||||
fprintf(f, "\t},\n");
|
|
||||||
|
|
||||||
fprintf(f, "\ttilde_dead_key:{\n");
|
|
||||||
for (uint32 i = 0; i < 32; i++) {
|
|
||||||
fprintf(f, "\t\t%ld,\n", fKeys.tilde_dead_key[i]);
|
|
||||||
}
|
|
||||||
fprintf(f, "\t},\n");
|
|
||||||
|
|
||||||
fprintf(f, "\tacute_tables:0x%lx,\n", fKeys.acute_tables);
|
|
||||||
fprintf(f, "\tgrave_tables:0x%lx,\n", fKeys.grave_tables);
|
|
||||||
fprintf(f, "\tcircumflex_tables:0x%lx,\n", fKeys.circumflex_tables);
|
|
||||||
fprintf(f, "\tdieresis_tables:0x%lx,\n", fKeys.dieresis_tables);
|
|
||||||
fprintf(f, "\ttilde_tables:0x%lx,\n", fKeys.tilde_tables);
|
|
||||||
|
|
||||||
fprintf(f, "};\n\n");
|
|
||||||
|
|
||||||
fprintf(f, "const char sSystemKeyChars[] = {\n");
|
|
||||||
for (uint32 i = 0; i<fCharsSize; i++) {
|
|
||||||
fprintf(f, "\t%hhd,\n", fChars[i]);
|
|
||||||
}
|
|
||||||
fprintf(f, "};\n\n");
|
|
||||||
|
|
||||||
fprintf(f, "const uint32 sSystemKeyCharsSize = %ld;\n", fCharsSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,14 +21,14 @@ static const char *sProgramName = __progname;
|
|||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
printf("usage: %s {-o output_file} -[d|l|r|c|b input_file]\n"
|
printf("usage: %s {-o output_file} -[d|l|r|c|b|h input_file]\n"
|
||||||
|
" -o change output file to output_file (default:keymap.out)\n"
|
||||||
" -d dump key map to standard output\n"
|
" -d dump key map to standard output\n"
|
||||||
" -l load key map from standard input\n"
|
" -l load key map from standard input\n"
|
||||||
" -b load binary key map from file\n"
|
" -b load binary key map from file\n"
|
||||||
" -r restore system default key map\n"
|
" -r restore system default key map\n"
|
||||||
" -c compile source keymap to binary\n"
|
" -c compile source keymap to binary\n"
|
||||||
" -h compile source keymap to header\n"
|
" -h compile source keymap to header\n",
|
||||||
" -o change output file to output_file (default:keymap.out)\n",
|
|
||||||
sProgramName);
|
sProgramName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,8 +51,8 @@ load_keymap_source(Keymap& keymap, const char* name)
|
|||||||
|
|
||||||
status_t status = keymap.LoadSourceFromRef(ref);
|
status_t status = keymap.LoadSourceFromRef(ref);
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
fprintf(stderr, "error when loading the keymap: %s\n",
|
fprintf(stderr, "%s: error when loading the keymap: %s\n",
|
||||||
keymap_error(status));
|
sProgramName, keymap_error(status));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,8 +74,10 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
if (operation == 'd') {
|
if (operation == 'd') {
|
||||||
Keymap keymap;
|
Keymap keymap;
|
||||||
if (keymap.LoadCurrent() != B_OK)
|
if (keymap.LoadCurrent() != B_OK) {
|
||||||
|
fprintf(stderr, "%s: error while getting current keymap!\n", sProgramName);
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
keymap.Dump();
|
keymap.Dump();
|
||||||
return 0;
|
return 0;
|
||||||
} else if (operation == 'r') {
|
} else if (operation == 'r') {
|
||||||
@ -87,8 +89,8 @@ main(int argc, char **argv)
|
|||||||
Keymap keymap;
|
Keymap keymap;
|
||||||
status_t status = keymap.LoadSource(stdin);
|
status_t status = keymap.LoadSource(stdin);
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
fprintf(stderr, "error when loading the keymap: %s\n",
|
fprintf(stderr, "%s: error when loading the keymap: %s\n",
|
||||||
keymap_error(status));
|
sProgramName, keymap_error(status));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
keymap.SaveAsCurrent();
|
keymap.SaveAsCurrent();
|
||||||
@ -103,7 +105,13 @@ main(int argc, char **argv)
|
|||||||
} else if (operation == 'c') {
|
} else if (operation == 'c') {
|
||||||
Keymap keymap;
|
Keymap keymap;
|
||||||
load_keymap_source(keymap, argv[i]);
|
load_keymap_source(keymap, argv[i]);
|
||||||
keymap.Save(outputRef);
|
|
||||||
|
status_t status = keymap.Save(outputRef);
|
||||||
|
if (status < B_OK) {
|
||||||
|
fprintf(stderr, "%s: error saving \"%s\": %s\n", sProgramName,
|
||||||
|
argv[i], strerror(status));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} else if (operation == 'h') {
|
} else if (operation == 'h') {
|
||||||
Keymap keymap;
|
Keymap keymap;
|
||||||
@ -116,8 +124,8 @@ main(int argc, char **argv)
|
|||||||
Keymap keymap;
|
Keymap keymap;
|
||||||
status_t status = keymap.Load(ref);
|
status_t status = keymap.Load(ref);
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
fprintf(stderr, "error when loading the keymap: %s\n",
|
fprintf(stderr, "%s: error when loading the keymap: %s\n",
|
||||||
keymap_error(status));
|
sProgramName, keymap_error(status));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
keymap.SaveAsCurrent();
|
keymap.SaveAsCurrent();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2005, Haiku, Inc. All Rights Reserved.
|
* Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -275,26 +275,23 @@ status_t
|
|||||||
InputServer::_LoadKeymap()
|
InputServer::_LoadKeymap()
|
||||||
{
|
{
|
||||||
BPath path;
|
BPath path;
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path)!=B_OK)
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
path.Append("Key_map");
|
path.Append("Key_map");
|
||||||
|
|
||||||
entry_ref ref;
|
|
||||||
get_ref_for_path(path.Path(), &ref);
|
|
||||||
|
|
||||||
status_t err;
|
status_t err;
|
||||||
|
|
||||||
BFile file(&ref, B_READ_ONLY);
|
BFile file(path.Path(), B_READ_ONLY);
|
||||||
if ((err = file.InitCheck()) != B_OK)
|
if ((err = file.InitCheck()) != B_OK)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (file.Read(&fKeys, sizeof(fKeys)) < (ssize_t)sizeof(fKeys))
|
if (file.Read(&fKeys, sizeof(fKeys)) < (ssize_t)sizeof(fKeys))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
for (uint32 i = 0; i < sizeof(fKeys)/4; i++)
|
for (uint32 i = 0; i < sizeof(fKeys)/4; i++)
|
||||||
((uint32*)&fKeys)[i] = B_BENDIAN_TO_HOST_INT32(((uint32*)&fKeys)[i]);
|
((uint32*)&fKeys)[i] = B_BENDIAN_TO_HOST_INT32(((uint32*)&fKeys)[i]);
|
||||||
|
|
||||||
if (file.Read(&fCharsSize, sizeof(uint32)) < (ssize_t)sizeof(uint32))
|
if (file.Read(&fCharsSize, sizeof(uint32)) < (ssize_t)sizeof(uint32))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
@ -316,14 +313,15 @@ status_t
|
|||||||
InputServer::_LoadSystemKeymap()
|
InputServer::_LoadSystemKeymap()
|
||||||
{
|
{
|
||||||
delete[] fChars;
|
delete[] fChars;
|
||||||
fKeys = sSystemKeymap;
|
fKeys = kSystemKeymap;
|
||||||
fCharsSize = sSystemKeyCharsSize;
|
fCharsSize = kSystemKeyCharsSize;
|
||||||
fChars = new (nothrow) char[fCharsSize];
|
fChars = new (nothrow) char[fCharsSize];
|
||||||
if (fChars == NULL)
|
if (fChars == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
memcpy(fChars, sSystemKeyChars, fCharsSize);
|
memcpy(fChars, kSystemKeyChars, fCharsSize);
|
||||||
|
|
||||||
|
// TODO: why are we doing this?
|
||||||
// we save this keymap to file
|
// we save this keymap to file
|
||||||
BPath path;
|
BPath path;
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||||
@ -331,34 +329,29 @@ InputServer::_LoadSystemKeymap()
|
|||||||
|
|
||||||
path.Append("Key_map");
|
path.Append("Key_map");
|
||||||
|
|
||||||
entry_ref ref;
|
|
||||||
get_ref_for_path(path.Path(), &ref);
|
|
||||||
|
|
||||||
BFile file;
|
BFile file;
|
||||||
status_t err = file.SetTo(&ref, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
status_t err = file.SetTo(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
||||||
if (err != B_OK) {
|
if (err != B_OK) {
|
||||||
PRINTERR(("error %s\n", strerror(err)));
|
PRINTERR(("error %s\n", strerror(err)));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32 i = 0; i < sizeof(fKeys) / 4; i++) {
|
for (uint32 i = 0; i < sizeof(fKeys) / sizeof(uint32); i++) {
|
||||||
((uint32*)&fKeys)[i] = B_HOST_TO_BENDIAN_INT32(((uint32*)&fKeys)[i]);
|
((uint32*)&fKeys)[i] = B_HOST_TO_BENDIAN_INT32(((uint32*)&fKeys)[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = file.Write(&fKeys, sizeof(fKeys))) < (ssize_t)sizeof(fKeys))
|
if ((err = file.Write(&fKeys, sizeof(fKeys))) < (ssize_t)sizeof(fKeys))
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
for (uint32 i = 0; i < sizeof(fKeys) / 4; i++) {
|
for (uint32 i = 0; i < sizeof(fKeys) / sizeof(uint32); i++) {
|
||||||
((uint32*)&fKeys)[i] = B_BENDIAN_TO_HOST_INT32(((uint32*)&fKeys)[i]);
|
((uint32*)&fKeys)[i] = B_BENDIAN_TO_HOST_INT32(((uint32*)&fKeys)[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fCharsSize = B_HOST_TO_BENDIAN_INT32(fCharsSize);
|
uint32 size = B_HOST_TO_BENDIAN_INT32(fCharsSize);
|
||||||
|
|
||||||
if ((err = file.Write(&fCharsSize, sizeof(uint32))) < (ssize_t)sizeof(uint32))
|
if ((err = file.Write(&size, sizeof(uint32))) < (ssize_t)sizeof(uint32))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
fCharsSize = B_BENDIAN_TO_HOST_INT32(fCharsSize);
|
|
||||||
|
|
||||||
if ((err = file.Write(fChars, fCharsSize)) < (ssize_t)fCharsSize)
|
if ((err = file.Write(fChars, fCharsSize)) < (ssize_t)fCharsSize)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user