Files
haiku-beta6/src/apps/bin/keymap/key_map.cpp
T
Jérôme Duval 1cf63426c6 added messages outputs
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8754 a95241bf-73f2-0310-859d-f6bbb57e9c96
2004-08-31 22:17:23 +00:00

92 lines
2.1 KiB
C++

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2004, Haiku
//
// This software is part of the Haiku distribution and is covered
// by the Haiku license.
//
//
// File: key_map.cpp
// Author: Jérôme Duval
// Description: keymap bin
// Created : July 30, 2004
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
#include <stdio.h>
#include <string.h>
#include "Keymap.h"
static void usage(char *prog)
{
printf(
"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"
" -h # compile source keymap to header\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) {
if (strlen(argv[i]) > 1)
operation = argv[i][1];
else
break;
if (operation == 'd') {
Keymap keymap;
if (keymap.LoadCurrent() != B_OK)
return 1;
keymap.Dump();
return 0;
} else if (operation == 'r') {
Keymap keymap;
keymap.RestoreSystemDefault();
printf("System default key map restored.\n");
return 0;
} else if (operation == 'l') {
Keymap keymap;
keymap.LoadSource(stdin);
keymap.SaveAsCurrent();
printf("Key map loaded.\n");
return 0;
}
} else {
if (operation == 'o') {
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.LoadSourceFromRef(ref);
keymap.Save(output_ref);
return 0;
} else if (operation == 'h') {
entry_ref ref;
get_ref_for_path(argv[i], &ref);
Keymap keymap;
keymap.LoadSourceFromRef(ref);
keymap.SaveAsHeader(output_ref);
return 0;
} else
break;
}
}
usage("/bin/keymap");
return 1;
}