Author: ablackmann
Date: Thu Nov 5 06:20:01 2009
New Revision: 43970
URL:
http://svn.reactos.org/svn/reactos?rev=43970&view=rev
Log:
The tool now generates 75% of a typical keyboard layout C file. Lots of stuff still
missing, but most of the annoying work is done now... it just has to start filling in the
dynamic data.
A full-fledged file will have ligature data, up to 8 shift states, dead keys, etc, but
that's not stuff we'll have to deal with at first for simple layouts.
By tomorrow we should be able to fully process and generate latin-alphabet-based language
keyboard layouts.
Modified:
trunk/reactos/tools/kbdtool/output.c
trunk/reactos/tools/kbdtool/parser.c
Modified: trunk/reactos/tools/kbdtool/output.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/kbdtool/output.c?rev…
==============================================================================
--- trunk/reactos/tools/kbdtool/output.c [iso-8859-1] (original)
+++ trunk/reactos/tools/kbdtool/output.c [iso-8859-1] Thu Nov 5 06:20:01 2009
@@ -141,7 +141,6 @@
/* We made it */
return TRUE;
-
}
BOOLEAN
@@ -387,8 +386,443 @@
IN PKEYNAME KeyNameExtData,
IN PKEYNAME KeyNameDeadData)
{
- /* FIXME: Stub */
- return FALSE;
+ CHAR OutputFile[13];
+ FILE *FileHandle;
+
+ /* Build the keyboard name and internal name */
+ strcpy(OutputFile, gKBDName);
+ strcat(OutputFile, ".C");
+
+ /* Open it */
+ FileHandle = fopen(OutputFile, "wt");
+ if (!FileHandle)
+ {
+ /* Fail */
+ printf(" %12s : can't open for write.\n", OutputFile);
+ return FALSE;
+ }
+
+ /* Print the header */
+ fprintf(FileHandle,
+
"/***************************************************************************\\\n"
+ "* Module Name: %s\n*\n* keyboard layout\n"
+ "*\n"
+ "* Copyright (c) 2009, ReactOS Foundation\n"
+ "*\n"
+ "* History:\n"
+ "* KBDTOOL v%d.%02d - Created %s"
+
"\\***************************************************************************/\n\n",
+ OutputFile,
+ gVersion,
+ gSubVersion,
+ asctime(Now));
+
+ /* What kind of driver is this? */
+ if (FallbackDriver)
+ {
+ /* Fallback only */
+ fprintf(FileHandle, "#include \"precomp.h\"\n");
+ }
+ else
+ {
+ /* Add the includes */
+ fprintf(FileHandle,
+ "#include <windows.h>\n"
+ "#include \"kbd.h\"\n"
+ "#include \"%s.h\"\n\n",
+ gKBDName);
+ }
+
+ /* What kind of driver is this? */
+ if (FallbackDriver)
+ {
+ /* Only one section */
+ fprintf(FileHandle,
+ "#pragma data_seg(\"%s\")\n#define
ALLOC_SECTION_LDATA\n\n",
+ ".kbdfallback");
+ }
+ else
+ {
+ /* Section and attributes depend on architecture */
+ fprintf(FileHandle,
+ "#if defined(_M_IA64)\n"
+ "#pragma section(\"%s\")\n"
+ "#define ALLOC_SECTION_LDATA
__declspec(allocate(\"%s\"))\n"
+ "#else\n"
+ "#pragma data_seg(\"%s\")\n"
+ "#define ALLOC_SECTION_LDATA\n"
+ "#endif\n\n",
+ ".data",
+ ".data",
+ ".data");
+ }
+
+ /* Scan code to virtual key conversion table header */
+ fprintf(FileHandle,
+
"/***************************************************************************\\\n"
+ "* ausVK[] - Virtual Scan Code to Virtual Key conversion table\n"
+
"\\***************************************************************************/\n\n");
+
+ /* Table begin */
+ fprintf(FileHandle,
+ "static ALLOC_SECTION_LDATA USHORT ausVK[] = {\n"
+ " T00, T01, T02, T03, T04, T05, T06, T07,\n"
+ " T08, T09, T0A, T0B, T0C, T0D, T0E, T0F,\n"
+ " T10, T11, T12, T13, T14, T15, T16, T17,\n"
+ " T18, T19, T1A, T1B, T1C, T1D, T1E, T1F,\n"
+ " T20, T21, T22, T23, T24, T25, T26, T27,\n"
+ " T28, T29, T2A, T2B, T2C, T2D, T2E, T2F,\n"
+ " T30, T31, T32, T33, T34, T35,\n\n");
+
+ /* Table continue */
+ fprintf(FileHandle,
+ " /*\n"
+ " * Right-hand Shift key must have KBDEXT bit set.\n"
+ " */\n"
+ " T36 | KBDEXT,\n\n"
+ " T37 | KBDMULTIVK, // numpad_* + Shift/Alt ->
SnapShot\n\n"
+ " T38, T39, T3A, T3B, T3C, T3D, T3E,\n"
+ " T3F, T40, T41, T42, T43, T44,\n\n");
+
+ /* Table continue */
+ fprintf(FileHandle,
+ " /*\n"
+ " * NumLock Key:\n"
+ " * KBDEXT - VK_NUMLOCK is an Extended key\n"
+ " * KBDMULTIVK - VK_NUMLOCK or VK_PAUSE (without or with
CTRL)\n"
+ " */\n"
+ " T45 | KBDEXT | KBDMULTIVK,\n\n"
+ " T46 | KBDMULTIVK,\n\n");
+
+ /* Numpad table */
+ fprintf(FileHandle,
+ " /*\n"
+ " * Number Pad keys:\n"
+ " * KBDNUMPAD - digits 0-9 and decimal point.\n"
+ " * KBDSPECIAL - require special processing by Windows\n"
+ " */\n"
+ " T47 | KBDNUMPAD | KBDSPECIAL, // Numpad 7 (Home)\n"
+ " T48 | KBDNUMPAD | KBDSPECIAL, // Numpad 8 (Up),\n"
+ " T49 | KBDNUMPAD | KBDSPECIAL, // Numpad 9 (PgUp),\n"
+ " T4A,\n"
+ " T4B | KBDNUMPAD | KBDSPECIAL, // Numpad 4 (Left),\n"
+ " T4C | KBDNUMPAD | KBDSPECIAL, // Numpad 5 (Clear),\n"
+ " T4D | KBDNUMPAD | KBDSPECIAL, // Numpad 6 (Right),\n"
+ " T4E,\n"
+ " T4F | KBDNUMPAD | KBDSPECIAL, // Numpad 1 (End),\n"
+ " T50 | KBDNUMPAD | KBDSPECIAL, // Numpad 2 (Down),\n"
+ " T51 | KBDNUMPAD | KBDSPECIAL, // Numpad 3 (PgDn),\n"
+ " T52 | KBDNUMPAD | KBDSPECIAL, // Numpad 0 (Ins),\n"
+ " T53 | KBDNUMPAD | KBDSPECIAL, // Numpad . (Del),\n\n");
+
+ /* Table finish */
+ fprintf(FileHandle,
+ " T54, T55, T56, T57, T58, T59, T5A, T5B,\n"
+ " T5C, T5D, T5E, T5F, T60, T61, T62, T63,\n"
+ " T64, T65, T66, T67, T68, T69, T6A, T6B,\n"
+ " T6C, T6D, T6E, T6F, T70, T71, T72, T73,\n"
+ " T74, T75, T76, T77, T78, T79, T7A, T7B,\n"
+ " T7C, T7D, T7E\n\n"
+ "};\n\n");
+
+ /* Key name table header */
+ fprintf(FileHandle, "static ALLOC_SECTION_LDATA VSC_VK aE0VscToVk[] =
{\n");
+
+ /* FIXME: Key names */
+
+ /* Key name table finish */
+ fprintf(FileHandle, " { 0, 0
}\n};\n\n");
+
+ /* Extended key name table header */
+ fprintf(FileHandle, "static ALLOC_SECTION_LDATA VSC_VK aE1VscToVk[] =
{\n");
+
+ /* FIXME: Extended scancodes */
+
+ /* Extended key name table finish */
+ fprintf(FileHandle,
+ " { 0x1D, Y1D }, // Pause\n"
+ " { 0 , 0 }\n};\n\n");
+
+ /* Modifier table description */
+ fprintf(FileHandle,
+
"/***************************************************************************\\\n"
+ "* aVkToBits[] - map Virtual Keys to Modifier Bits\n"
+ "*\n"
+ "* See kbd.h for a full description.\n"
+ "*\n"
+ "* The keyboard has only three shifter keys:\n"
+ "* SHIFT (L & R) affects alphabnumeric keys,\n"
+ "* CTRL (L & R) is used to generate control characters\n"
+ "* ALT (L & R) used for generating characters by number with
numpad\n"
+
"\\***************************************************************************/\n");
+
+ /* Modifier table header */
+ fprintf(FileHandle, "static ALLOC_SECTION_LDATA VK_TO_BIT aVkToBits[] =
{\n");
+
+ /* FIXME: Key modifiers */
+
+ /* Modifier table finish */
+ fprintf(FileHandle, " { 0, 0 }\n};\n\n");
+
+ /* Modifier conversion table description */
+ fprintf(FileHandle,
+
"/***************************************************************************\\\n"
+ "* aModification[] - map character modifier bits to modification
number\n"
+ "*\n"
+ "* See kbd.h for a full description.\n"
+ "*\n"
+
"\\***************************************************************************/\n\n");
+
+ /* Modifier conversion table header */
+ fprintf(FileHandle,
+ "static ALLOC_SECTION_LDATA MODIFIERS CharModifiers = {\n"
+ " &aVkToBits[0],\n"
+ " %d,\n"
+ " {\n"
+ " // Modification# // Keys Pressed\n"
+ " // ============= // =============\n",
+ 2); /* FIXME: STATE STUFF */
+
+ /* Modifier conversion table end */
+ fprintf(FileHandle," }\n" "};\n\n");
+
+ /* Shift state translation table description */
+ fprintf(FileHandle,
+
"/***************************************************************************\\\n"
+ "*\n"
+ "* aVkToWch2[] - Virtual Key to WCHAR translation for 2 shift
states\n"
+ "* aVkToWch3[] - Virtual Key to WCHAR translation for 3 shift
states\n"
+ "* aVkToWch4[] - Virtual Key to WCHAR translation for 4 shift
states\n");
+
+ /* FIXME: STATE STUFF */
+
+ /* Shift state translation table description continue */
+ fprintf(FileHandle,
+ "*\n"
+ "* Table attributes: Unordered Scan, null-terminated\n"
+ "*\n"
+ "* Search this table for an entry with a matching Virtual Key to find
the\n"
+ "* corresponding unshifted and shifted WCHAR characters.\n"
+ "*\n"
+ "* Special values for VirtualKey (column 1)\n"
+ "* 0xff - dead chars for the previous entry\n"
+ "* 0 - terminate the list\n"
+ "*\n"
+ "* Special values for Attributes (column 2)\n"
+ "* CAPLOK bit - CAPS-LOCK affect this key like SHIFT\n"
+ "*\n"
+ "* Special values for wch[*] (column 3 & 4)\n"
+ "* WCH_NONE - No character\n"
+ "* WCH_DEAD - Dead Key (diaresis) or invalid (US keyboard has
none)\n"
+ "* WCH_LGTR - Ligature (generates multiple characters)\n"
+ "*\n"
+
"\\***************************************************************************/\n\n");
+
+ /* FIXME: STATE STUFF */
+
+ /* Numpad translation table */
+ fprintf(FileHandle,
+ "// Put this last so that VkKeyScan interprets number
characters\n"
+ "// as coming from the main section of the kbd (aVkToWch2 and\n"
+ "// aVkToWch5) before considering the numpad (aVkToWch1).\n\n"
+ "static ALLOC_SECTION_LDATA VK_TO_WCHARS1 aVkToWch1[] = {\n"
+ " { VK_NUMPAD0 , 0 , '0' },\n"
+ " { VK_NUMPAD1 , 0 , '1' },\n"
+ " { VK_NUMPAD2 , 0 , '2' },\n"
+ " { VK_NUMPAD3 , 0 , '3' },\n"
+ " { VK_NUMPAD4 , 0 , '4' },\n"
+ " { VK_NUMPAD5 , 0 , '5' },\n"
+ " { VK_NUMPAD6 , 0 , '6' },\n"
+ " { VK_NUMPAD7 , 0 , '7' },\n"
+ " { VK_NUMPAD8 , 0 , '8' },\n"
+ " { VK_NUMPAD9 , 0 , '9' },\n"
+ " { 0 , 0 , '\\0' }\n"
+ "};\n\n");
+
+ /* Translation tables header */
+ fprintf(FileHandle,"static ALLOC_SECTION_LDATA VK_TO_WCHAR_TABLE
aVkToWcharTable[] = {\n");
+
+ /* FIXME: STATE STUFF */
+
+ /* Array of translation tables */
+ fprintf(FileHandle,
+ " { (PVK_TO_WCHARS1)aVkToWch2, 2, sizeof(aVkToWch2[0]) },\n"
+ " { (PVK_TO_WCHARS1)aVkToWch1, 1, sizeof(aVkToWch1[0]) },\n"
+ " { NULL, 0, 0 },\n"
+ "};\n\n");
+
+ /* Scan code to key name conversion table description */
+ fprintf(FileHandle,
+
"/***************************************************************************\\\n"
+ "* aKeyNames[], aKeyNamesExt[] - Virtual Scancode to Key Name
tables\n"
+ "*\n"
+ "* Table attributes: Ordered Scan (by scancode),
null-terminated\n"
+ "*\n"
+ "* Only the names of Extended, NumPad, Dead and Non-Printable keys are
here.\n"
+ "* (Keys producing printable characters are named by that
character)\n"
+
"\\***************************************************************************/\n\n");
+
+ /* Check for key name data */
+ if (KeyNameData)
+ {
+ /* Table header */
+ fprintf(FileHandle, "static ALLOC_SECTION_LDATA VSC_LPWSTR aKeyNames[] =
{\n");
+
+ /* FIXME: TODO: Print table */
+
+ /* Table end */
+ fprintf(FileHandle, "};\n\n");
+ }
+
+ /* Check for extended key name data */
+ if (KeyNameExtData)
+ {
+ /* Table header */
+ fprintf(FileHandle, "static ALLOC_SECTION_LDATA VSC_LPWSTR aKeyNamesExt[] =
{\n");
+
+ /* FIXME: TODO: Print table */
+
+ /* Table end */
+ fprintf(FileHandle, "};\n\n");
+ }
+
+ /* Check for dead key name data */
+ if (KeyNameDeadData)
+ {
+ /* Not yet supported */
+ printf("Dead key name data not supported!\n");
+ exit(1);
+ }
+
+ /* Check for dead key data */
+ if (DeadKeyData)
+ {
+ /* Not yet supported */
+ printf("Dead key data not supported!\n");
+ //exit(1);
+ }
+
+ /* Check for ligature data */
+ if (LigatureData)
+ {
+ /* Not yet supported */
+ printf("Ligature key data not supported!\n");
+ exit(1);
+ }
+
+ /* Main keyboard table descriptor type */
+ fprintf(FileHandle, "static ");
+
+ /* FIXME? */
+
+ /* Main keyboard table descriptor header */
+ fprintf(FileHandle,
+ "ALLOC_SECTION_LDATA KBDTABLES KbdTables%s = {\n"
+ " /*\n"
+ " * Modifier keys\n"
+ " */\n"
+ " &CharModifiers,\n\n"
+ " /*\n"
+ " * Characters tables\n"
+ " */\n"
+ " aVkToWcharTable,\n\n"
+ " /*\n"
+ " * Diacritics\n"
+ " */\n",
+ FallbackDriver ? "Fallback" : "" );
+
+ /* Descriptor dead key data section */
+ if (DeadKeyData)
+ {
+ fprintf(FileHandle," aDeadKey,\n\n");
+ }
+ else
+ {
+ fprintf(FileHandle," NULL,\n\n");
+ }
+
+ /* Descriptor key name comment */
+ fprintf(FileHandle,
+ " /*\n"
+ " * Names of Keys\n"
+ " */\n");
+
+ /* Descriptor key name section */
+ if (KeyNameData)
+ {
+ fprintf(FileHandle," aKeyNames,\n");
+ }
+ else
+ {
+ fprintf(FileHandle," NULL,\n");
+ }
+
+ /* Descriptor extended key name section */
+ if (KeyNameExtData)
+ {
+ fprintf(FileHandle," aKeyNamesExt,\n");
+ }
+ else
+ {
+ fprintf(FileHandle," NULL,\n");
+ }
+
+ /* Descriptor dead key name section */
+ if ((DeadKeyData) && (KeyNameDeadData))
+ {
+ fprintf(FileHandle," aKeyNamesDead,\n\n");
+ }
+ else
+ {
+ fprintf(FileHandle," NULL,\n\n");
+ }
+
+ /* Descriptor conversion table section */
+ fprintf(FileHandle,
+ " /*\n"
+ " * Scan codes to Virtual Keys\n"
+ " */\n"
+ " ausVK,\n"
+ " sizeof(ausVK) / sizeof(ausVK[0]),\n"
+ " aE0VscToVk,\n"
+ " aE1VscToVk,\n\n"
+ " /*\n"
+ " * Locale-specific special processing\n"
+ " */\n");
+
+ /* FIXME: AttributeData and KLLF_ALTGR stuff */
+
+ /* Descriptor locale-specific section */
+ fprintf(FileHandle, " MAKELONG(%s, KBD_VERSION),\n\n",
(PCHAR)AttributeData);
+
+ /* Descriptor ligature data comment */
+ fprintf(FileHandle, " /*\n * Ligatures\n */\n %d,\n", 0); /*
FIXME */
+
+ /* Descriptor ligature data section */
+ if (!LigatureData)
+ {
+ fprintf(FileHandle, " 0,\n");
+ fprintf(FileHandle, " NULL\n");
+ }
+ else
+ {
+ fprintf(FileHandle, " sizeof(aLigature[0]),\n");
+ fprintf(FileHandle, " (PLIGATURE1)aLigature\n");
+ }
+
+ /* Descriptor finish */
+ fprintf(FileHandle,"};\n\n");
+
+ /* Keyboard layout callback function */
+ if (!FallbackDriver) fprintf(FileHandle,
+ "PKBDTABLES KbdLayerDescriptor(VOID)\n"
+ "{\n"
+ " return &KbdTables;\n"
+ "}\n");
+
+ /* Clean up */
+ fclose(FileHandle);
+ return TRUE;
}
ULONG
Modified: trunk/reactos/tools/kbdtool/parser.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/kbdtool/parser.c?rev…
==============================================================================
--- trunk/reactos/tools/kbdtool/parser.c [iso-8859-1] (original)
+++ trunk/reactos/tools/kbdtool/parser.c [iso-8859-1] Thu Nov 5 06:20:01 2009
@@ -929,9 +929,9 @@
ULONG KeyWord;
ULONG StateCount;
ULONG ShiftStates[8];
- PKEYNAME DescriptionData, LanguageData;
- PKEYNAME KeyNameData, KeyNameExtData, KeyNameDeadData;
- PVOID AttributeData, LigatureData, DeadKeyData;
+ PKEYNAME DescriptionData = NULL, LanguageData = NULL;
+ PKEYNAME KeyNameData = NULL, KeyNameExtData = NULL, KeyNameDeadData = NULL;
+ PVOID AttributeData = NULL, LigatureData = NULL, DeadKeyData = NULL;
/* Parse keywords */
gLineCount = 0;