added binary keymap loading. Now you can type 'keymap -b /etc/Keymap/French'

it also checks for binary version number in case you try to load anything else (who knows ...)


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11517 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2005-03-01 14:30:29 +00:00
parent c7cbf33821
commit e6d5cc8d84
2 changed files with 18 additions and 3 deletions
+4 -1
View File
@@ -265,6 +265,9 @@ Keymap::Load(entry_ref &ref)
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 (fKeys.version != 3)
return B_ERROR;
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;
@@ -276,7 +279,7 @@ Keymap::Load(entry_ref &ref)
fChars = new char[fCharsSize]; fChars = new char[fCharsSize];
if ((unsigned)file.Read(fChars, fCharsSize) != fCharsSize) if ((unsigned)file.Read(fChars, fCharsSize) != fCharsSize)
return B_BAD_VALUE; return B_BAD_VALUE;
return B_OK; return B_OK;
} }
+14 -2
View File
@@ -21,9 +21,10 @@ static const char *sProgramName = __progname;
static void static void
usage(void) usage(void)
{ {
printf("usage: %s {-o output_file} -[d|l|r|c]\n" printf("usage: %s {-o output_file} -[d|l|r|c|b input_file]\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"
" -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"
@@ -66,7 +67,7 @@ main(int argc, char **argv)
keymap.SaveAsCurrent(); keymap.SaveAsCurrent();
printf("Key map loaded.\n"); printf("Key map loaded.\n");
return 0; return 0;
} }
} else { } else {
if (operation == 'o') { if (operation == 'o') {
get_ref_for_path(argv[i], &outputRef); get_ref_for_path(argv[i], &outputRef);
@@ -91,6 +92,17 @@ main(int argc, char **argv)
keymap.Dump(); keymap.Dump();
keymap.SaveAsHeader(outputRef); keymap.SaveAsHeader(outputRef);
return 0; return 0;
} else if (operation == 'b') {
entry_ref ref;
get_ref_for_path(argv[i], &ref);
Keymap keymap;
if (keymap.Load(ref)!=B_OK) {
printf("error when loading the keymap\n");
return 1;
}
keymap.SaveAsCurrent();
printf("Key map loaded.\n");
return 0;
} else } else
break; break;
} }