[ros-diffs] [ablackmann] 43899: Add support for DESCRIPTIONS section (tested on test.klc). Add KEYNAME structure. Fixup some of the code in the SHIFTSTATES implementation.

ablackmann at svn.reactos.org ablackmann at svn.reactos.org
Sun Nov 1 18:43:51 CET 2009


Author: ablackmann
Date: Sun Nov  1 18:43:51 2009
New Revision: 43899

URL: http://svn.reactos.org/svn/reactos?rev=43899&view=rev
Log:
Add support for DESCRIPTIONS section (tested on test.klc). Add KEYNAME structure. Fixup some of the code in the SHIFTSTATES implementation.

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

Modified: trunk/reactos/tools/kbdtool/parser.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/kbdtool/parser.c?rev=43899&r1=43898&r2=43899&view=diff
==============================================================================
--- trunk/reactos/tools/kbdtool/parser.c [iso-8859-1] (original)
+++ trunk/reactos/tools/kbdtool/parser.c [iso-8859-1] Sun Nov  1 18:43:51 2009
@@ -13,6 +13,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <host/typedefs.h>
+
+typedef struct tagKEYNAME
+{
+    ULONG LanguageCode;
+    PCHAR Description;
+    struct tagKEYNAME* Next;
+} KEYNAME, *PKEYNAME;
 
 /* GLOBALS ********************************************************************/
 
@@ -232,9 +239,78 @@
 }
 
 ULONG
-DoDESCRIPTIONS(PVOID DescriptionData)
-{
-    return SkipLines();
+DoDESCRIPTIONS(IN PKEYNAME* DescriptionData)
+{
+    ULONG KeyWord = 0;
+    CHAR Token[32];
+    ULONG LanguageCode;
+    PCHAR p, pp;
+    PKEYNAME Description;
+    
+    /* Assume nothing */
+    *DescriptionData = 0;
+    
+    /* Start scanning */
+    while (NextLine(gBuf, 256, gfpInput))
+    {        
+        /* Search for token */
+        if (sscanf(gBuf, "%s", Token) != 1) continue;
+        
+        /* Make sure it's not just a comment */
+        if (*Token == ';') continue;
+        
+        /* Make sure it's not a keyword */
+        KeyWord = isKeyWord(Token);
+        if (KeyWord < KEYWORD_COUNT) break;
+        
+        /* Now scan for the language code */
+        if (sscanf(Token, " %4x", &LanguageCode) != 1)
+        {
+            /* Skip */
+            printf("An invalid LANGID was specified.\n");
+            continue;
+        }
+        
+        /* Now get the actual description */
+        if (sscanf(gBuf, " %*4x %s[^\n]", Token) != 1)
+        {
+            /* Skip */
+            printf("A language description is missing.\n");
+            continue;
+        }
+        
+        /* Get the description string and find the ending */
+        p = strstr(gBuf, Token);
+        pp = strchr(p, '\n');
+        if (!pp) pp = strchr(p, '\r');
+        
+        /* Terminate the description string here */
+        if (pp) *pp = 0;
+        
+        /* Now allocate the description */
+        Description = malloc(sizeof(KEYNAME));
+        if (!Description)
+        {
+            /* Fail */
+            printf("Unable to allocate the KEYNAME struct (out of memory?).\n");
+            exit(1);
+        }
+        
+        /* Fill out the structure */
+        Description->LanguageCode = LanguageCode;
+        Description->Description = strdup(p);
+        Description->Next = NULL;
+        
+        /* Debug only */
+        DPRINT1("LANGID: [%4x] Description: [%s]\n", Description->LanguageCode, Description->Description);
+        
+        /* Point to it and advance the pointer */
+        *DescriptionData = Description;
+        DescriptionData = &Description->Next;
+    }
+
+    /* We are done */
+    return KeyWord;
 }
 
 ULONG
@@ -293,15 +369,16 @@
         if (KeyWord < KEYWORD_COUNT) break;
         
         /* Now scan for the shift state */
-        if (sscanf(gBuf, " %1s[01234567]", Token) != 1)
+        if (sscanf(gBuf, " %1s[012367]", Token) != 1)
         {
             /* We failed -- should we warn? */
-            if (Verbose) printf("Invalid shift state\n");
+            if (Verbose) printf("An invalid shift state '%s' was found (use 0, 1, 2, 3, 6, or 7.)\n", Token);
             continue;
         }
         
         /* Now read the state */
         ShiftState = atoi(Token);
+
         /* Scan existing states */
         for (i = 0; i < *StateCount; i++)
         {
@@ -309,7 +386,7 @@
             if ((ShiftStates[i] == ShiftState) && (Verbose))
             {
                 /* Warn user */
-                printf("Duplicate shift state\n");
+                printf("The state '%d' was duplicated for this Virtual Key.\n", ShiftStates[i]);
                 break;
             }
         }
@@ -323,14 +400,14 @@
         else
         {
             /* Too many states -- should we warn? */
-            if (Verbose) printf("Too many shift states: %d\n", *StateCount);
+            if (Verbose) printf("There were too many states (you defined %d).\n", *StateCount);
         }
     }
 
     /* Debug only */
-    printf("Found %d Shift States: [", *StateCount);
-    for (i = 0; i < *StateCount; i++) printf("%d ", ShiftStates[i]);
-    printf("]\n");
+    DPRINT1("Found %d Shift States: [", *StateCount);
+    for (i = 0; i < *StateCount; i++) DPRINT1("%d ", ShiftStates[i]);
+    DPRINT1("]\n");
     
     /* We are done */
     return KeyWord;
@@ -352,7 +429,8 @@
     ULONG KeyWord;
     ULONG StateCount;
     ULONG ShiftStates[8];
-    PVOID AttributeData, LigatureData, DeadKeyData, DescriptionData;
+    PKEYNAME DescriptionData;
+    PVOID AttributeData, LigatureData, DeadKeyData;
     PVOID KeyNameData, KeyNameExtData, KeyNameDeadData, LanguageData;
     
     /* Parse keywords */




More information about the Ros-diffs mailing list