[ros-diffs] [ablackmann] 43961: Holy shit Batman! KbdTool can now write out the keyboard layout header file! You should get a Layout01.h if you run it on test.klc (in your current working directory).

ablackmann at svn.reactos.org ablackmann at svn.reactos.org
Wed Nov 4 23:48:56 CET 2009


Author: ablackmann
Date: Wed Nov  4 23:48:55 2009
New Revision: 43961

URL: http://svn.reactos.org/svn/reactos?rev=43961&view=rev
Log:
Holy shit Batman! KbdTool can now write out the keyboard layout header file! You should get a Layout01.h if you run it on test.klc (in your current working directory).


Modified:
    trunk/reactos/tools/kbdtool/kbdtool.h
    trunk/reactos/tools/kbdtool/output.c
    trunk/reactos/tools/kbdtool/parser.c

Modified: trunk/reactos/tools/kbdtool/kbdtool.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/kbdtool/kbdtool.h?rev=43961&r1=43960&r2=43961&view=diff
==============================================================================
--- trunk/reactos/tools/kbdtool/kbdtool.h [iso-8859-1] (original)
+++ trunk/reactos/tools/kbdtool/kbdtool.h [iso-8859-1] Wed Nov  4 23:48:55 2009
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <getopt.h>
+#include <time.h>
 #include <host/typedefs.h>
 
 #define KEYWORD_COUNT 17
@@ -65,11 +66,22 @@
     LAYOUTENTRY Entry[110];
 } LAYOUT, *PLAYOUT;
 
+PCHAR
+getVKName(
+    IN ULONG VirtualKey,
+    IN BOOLEAN Prefix
+);
+
 extern BOOLEAN Verbose, UnicodeFile, SanityCheck, FallbackDriver;
 extern PCHAR gpszFileName;
 extern FILE* gfpInput;
 extern VKNAME VKName[];
 extern SCVK ScVk[];
 extern LAYOUT g_Layout;
+extern CHAR gVKeyName[32];
+extern CHAR gKBDName[10];
+extern CHAR gCopyright[256];
+extern CHAR gDescription[256];
+extern ULONG gVersion, gSubVersion;
 
 /* EOF */

Modified: trunk/reactos/tools/kbdtool/output.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/kbdtool/output.c?rev=43961&r1=43960&r2=43961&view=diff
==============================================================================
--- trunk/reactos/tools/kbdtool/output.c [iso-8859-1] (original)
+++ trunk/reactos/tools/kbdtool/output.c [iso-8859-1] Wed Nov  4 23:48:55 2009
@@ -12,13 +12,133 @@
 
 /* GLOBALS ********************************************************************/
 
+time_t Clock;
+struct tm *Now;
+
 /* FUNCTIONS ******************************************************************/
 
 BOOLEAN
 kbd_h(IN PLAYOUT Layout)
 {
-    /* FIXME: Stub */
-    return FALSE;
+    CHAR OutputFile[13];
+    FILE *FileHandle;
+    ULONG i;
+    CHAR UndefChar;
+    USHORT SubCode;
+  
+    /* Build the keyboard name */
+    strcpy(OutputFile, gKBDName);
+    strcat(OutputFile, ".H");
+    
+    /* Open it */
+    FileHandle = fopen(OutputFile, "wt");
+    if (!FileHandle)
+    {
+        /* Fail */
+        printf(" %12s : can't open for write.\n", OutputFile);
+        return FALSE;
+    }
+    
+    /* Print the module header */
+    fprintf(FileHandle,
+            "/****************************** Module Header ******************************\\\n"
+            "* Module Name: %s\n*\n* keyboard layout header\n"
+            "*\n"
+            "* Copyright (c) 2009, ReactOS Foundation\n"
+            "*\n"
+            "* Various defines for use by keyboard input code.\n*\n* History:\n"
+            "*\n"
+            "* created by KBDTOOL v%d.%02d %s*\n"
+            "\\***************************************************************************/\n\n",
+            OutputFile,
+            gVersion,
+            gSubVersion,
+            asctime(Now));
+    
+    /* Print out the includes and defines */
+    fprintf(FileHandle,
+            "/*\n"
+            " * kbd type should be controlled by cl command-line argument\n"
+            " *\\n"
+            "#define KBD_TYPE 4\n\n"
+            "/*\n"
+            "* Include the basis of all keyboard table values\n"
+            "*/\n"
+            "#include \"kbd.h\"\n");
+    
+    /* Now print out the virtual key conversion table */
+    fprintf(FileHandle,
+            "/***************************************************************************\\\n"
+            "* The table below defines the virtual keys for various keyboard types where\n"
+            "* the keyboard differ from the US keyboard.\n"
+            "*\n"
+            "* _EQ() : all keyboard types have the same virtual key for this scancode\n"
+            "* _NE() : different virtual keys for this scancode, depending on kbd type\n"
+            "*\n"
+            "*     +------+ +----------+----------+----------+----------+----------+----------+\n"
+            "*     | Scan | |    kbd   |    kbd   |    kbd   |    kbd   |    kbd   |    kbd   |\n"
+            "*     | code | |   type 1 |   type 2 |   type 3 |   type 4 |   type 5 |   type 6 |\n"
+            "\\****+-------+_+----------+----------+----------+----------+----------+----------+*/\n\n");
+    
+    /* Loop all keys */
+    for (i = 0; i < 110; i++)
+    {
+        /* Check if we processed this key */
+        if (Layout->Entry[i].Processed)
+        {
+            /* Check if it redefined a virtual key */
+            if (Layout->Entry[i].VirtualKey != Layout->Entry[i].OriginalVirtualKey)
+            {
+                /* Do we have a subcode? */
+                SubCode = Layout->Entry[i].ScanCode & 0xFF00;
+                if (SubCode)
+                {
+                    /* Which kind is it? */
+                    if (SubCode == 0xE000)
+                    {
+                        /* Extended 0 */
+                        UndefChar = 'X';
+                    }
+                    else
+                    {
+                        /* Illegal */
+                        if (SubCode != 0xE100)
+                        {
+                            /* Unrecognized */
+                            printf("Weird scancode value %04x: expected xx, E0xx, or E1xx\n", SubCode);
+                            exit(1);
+                        }
+                        
+                        /* Extended 1 */
+                        UndefChar = 'Y';
+                    }
+                }
+                else
+                {
+                    /* Normal key */
+                    UndefChar = 'T';
+                }
+                
+                /* Print out the virtual key redefinition */
+                fprintf(FileHandle,
+                        "#undef %c%02X\n#define %c%02X _EQ(%43s%23s\n",
+                        UndefChar,
+                        Layout->Entry[i].ScanCode,
+                        UndefChar,
+                        Layout->Entry[i].ScanCode,
+                        getVKName(Layout->Entry[i].VirtualKey, 0),
+                        ")");
+            }   
+        }
+    }
+    
+    /* Cleanup and close */
+    fprintf(FileHandle,"\n");
+    fclose(FileHandle);
+    
+    /* We made it */
+    return TRUE;
+    
 }
 
 BOOLEAN
@@ -64,7 +184,11 @@
          IN PKEYNAME KeyNameDeadData)
 {
     ULONG FailureCode = 0;
-    
+
+    /* Take the time */
+    time(&Clock);
+    Now = localtime(&Clock);
+
     /* Check if this just a fallback driver*/
     if (!FallbackDriver)
     {

Modified: trunk/reactos/tools/kbdtool/parser.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/kbdtool/parser.c?rev=43961&r1=43960&r2=43961&view=diff
==============================================================================
--- trunk/reactos/tools/kbdtool/parser.c [iso-8859-1] (original)
+++ trunk/reactos/tools/kbdtool/parser.c [iso-8859-1] Wed Nov  4 23:48:55 2009
@@ -19,6 +19,7 @@
 CHAR gDescription[256];
 CHAR gCompany[256];
 CHAR gLocaleName[256];
+CHAR gVKeyName[32];
 ULONG gID = 0;
 ULONG gKbdLayoutVersion;
 LAYOUT g_Layout;
@@ -58,6 +59,53 @@
     
     /* If we didn't find anything, i will be KEYWORD_COUNT, which is invalid */
     return i;
+}
+
+PCHAR
+getVKName(IN ULONG VirtualKey,
+          IN BOOLEAN Prefix)
+{
+    ULONG i;
+    
+    /* Loop for standard virtual key */
+    if (((VirtualKey >= 'A') && (VirtualKey <= 'Z')) ||
+        ((VirtualKey >= '0') && (VirtualKey <= '9')))
+    {
+        /* Fill out the name */
+        gVKeyName[0] = '\'';
+        gVKeyName[1] = VirtualKey;
+        gVKeyName[2] = '\'';
+        gVKeyName[3] = '\0';
+        return gVKeyName;
+    }
+    
+    /* Check if a prefix is required */
+    if (Prefix)
+    {
+        /* Add it */
+        strcpy(gVKeyName, "VK_");
+    }
+    else
+    {
+        /* Otherwise, don't add anything */
+        strcpy(gVKeyName, "");
+    }
+    
+    /* Loop all virtual keys */
+    for (i = 0; i < 36; i++)
+    {
+        /* Check if this key matches */
+        if (VKName[i].VirtualKey == VirtualKey)
+        {
+            /* Copy the key's name into the buffer */
+            strcat(gVKeyName, VKName[i].Name);
+            return gVKeyName;
+        }
+    }
+    
+    /* If we got here, then we failed, so print out an error name */
+    strcpy(gVKeyName, "#ERROR#");
+    return gVKeyName;
 }
 
 ULONG




More information about the Ros-diffs mailing list