Re: [AD] xkeymap fix

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Fri, 2003-10-10 at 08:49, Eric Botcazou wrote:
> > I'm about to commit the attached patch to stop xkeymap from crashing,
> > since KEY_MAX was increased and someone coded xkeymap so it tries to
> > display a NULL pointer in that case (/me looks away).
> 
> I'd suggest to additionally put an ASSERT that checks whether the index is 
> out-of-bounds.
> 
> > Btw., is there a reason KEY_MAX is 120, but the highest key is 118?
> 
> A different counting scheme from Italy? :-)
> 
> > And what is the purpose of KEY_MODIFIERS ? If some part of the Allegro code 
> > assumes only modifier keys are defined after it, something might go wrong
> > with the added OSX keys..
> 
> Angelo was probably not aware of that. Do you think this can affect non-OSX 
> ports?

No idea, I just noticed that xkeymap somehow treats the keys >=
KEY_MODIFIERS differently.

Seems keyconf has the same problem. I attached another patch which tries
to also fix keyconf.

-- 
Elias Pschernig <elias@xxxxxxxxxx>
Index: keyconf.c
===================================================================
RCS file: /cvsroot/alleg/allegro/setup/keyconf.c,v
retrieving revision 1.20
diff -u -r1.20 keyconf.c
--- keyconf.c	31 May 2003 19:38:24 -0000	1.20
+++ keyconf.c	10 Oct 2003 14:36:02 -0000
@@ -56,7 +56,7 @@
    "KEY_LSHIFT",     "KEY_RSHIFT",     "KEY_LCONTROL",   "KEY_RCONTROL",
    "KEY_ALT",        "KEY_ALTGR",      "KEY_LWIN",       "KEY_RWIN",
    "KEY_MENU",       "KEY_SCRLOCK",    "KEY_NUMLOCK",    "KEY_CAPSLOCK",
-   "KEY_MAX"
+   "KEY_EQUALS_PAD", "KEY_BACKQUOTE",  "KEY_SEMICOLON",  "KEY_COMMAND"
 };
 
 
@@ -563,10 +563,16 @@
 
    val = editor_table[index];
 
-   if (val >= ' ')
-      usprintf(buf, "%-16s ->  U+%04X - '%c'", scancode_name[index], val, val);
-   else
-      usprintf(buf, "%-16s ->  U+%04X - %s", scancode_name[index], val, ascii_name[val]);
+   if (scancode_name[index])
+   {
+     if (val >= ' ')
+        usprintf(buf, "%-16s ->  U+%04X - '%c'", scancode_name[index], val, val);
+     else
+        usprintf(buf, "%-16s ->  U+%04X - %s", scancode_name[index], val, ascii_name[val]);
+   }
+   else {
+      sprintf(buf, "<undef>");
+   }
 
    return buf;
 }
@@ -631,7 +637,10 @@
       return NULL;
    }
 
-   return scancode_name[index];
+   if (scancode_name[index])
+     return scancode_name[index];
+   else
+     return "<undef>";
 }
 
 
@@ -772,7 +781,8 @@
    clear_to_color(screen, palette_color[8]);
 
    for (i=0; i<=KEY_MAX; i++)
-      textout_ex(screen, font, scancode_name[i], 32+(i%4)*160, 88+(i/4)*14, palette_color[255], palette_color[8]);
+      textout_ex(screen, font, scancode_name[i] ? scancode_name[i] :
+         "<undef>", 32+(i%4)*160, 60+(i/4)*14, palette_color[255], palette_color[8]);
 
    release_screen();
 
@@ -788,7 +798,7 @@
       acquire_screen();
 
       for (i=0; i<KEY_MAX; i++)
-	 textout_ex(screen, font, key[i] ? "*" : " ", 16+(i%4)*160, 88+(i/4)*14, palette_color[255], palette_color[8]);
+	 textout_ex(screen, font, key[i] ? "*" : " ", 16+(i%4)*160, 60 +(i/4)*14, palette_color[255], palette_color[8]);
 
       buf[0] = 0;
 
@@ -848,7 +858,7 @@
 	 a = ureadkey(&i);
 	 if (!a)
 	    a = ' ';
-	 textprintf_ex(screen, font, 32, 48, palette_color[255], palette_color[8], "ureadkey() returns scancode 0x%02X, U+0x%04X, '%c'", i, a, a);
+	 textprintf_ex(screen, font, 32, 34, palette_color[255], palette_color[8], "ureadkey() returns scancode 0x%02X, U+0x%04X, '%c'", i, a, a);
       }
 
    } while ((!key[KEY_ESC]) && (!mouse_b));


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/