Bug 13507 - setkeycodes skips last arguments
Summary: setkeycodes skips last arguments
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: console-tools
Version: 6.2
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Bernhard Rosenkraenzer
QA Contact:
URL: http://mucus.com/console-tools/index....
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2000-07-05 18:57 UTC by Darrell Shively
Modified: 2008-05-01 15:37 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2000-07-05 18:57:58 UTC
Embargoed:


Attachments (Terms of Use)

Description Darrell Shively 2000-07-05 18:57:56 UTC
setkeycodes has a bug that causes it to skip the last scancode/keycode
pair specified on the command line.  One obvious example is that the
man page example:
 $ setkeycodes e06f 112

Will not won't work.  Perhaps more insidious, a longer sequence will
*seem* to work, except that the very last scancode will not get set.

Please find enclosed a patch to correct this, and to add a "-v" verbosity
option.  Patch can also be had from:

	http://mucus.com/console-tools/index.html

Feel free to email if you have any questions,
   - dash
   dash
	
---------------- patch follows ----------------------
--- console-tools-0.3.3/console-tools-0.3.3/kbdtools/setkeycodes.c	Wed Aug
25 14:18:42 1999
+++ console-tools-dash/console-tools-0.3.3/kbdtools/setkeycodes.c	Wed Jul 
5 11:30:38 2000
@@ -3,6 +3,11 @@
  *  (where scancode is either xx or e0xx, given in hexadecimal,
  *   and keycode is given in decimal)
  *
+ * dash, 05-July-2000 - Fixed main while loop to process all argument
+ * pairs (it used to skip the last one).  This also prevented working
+ * with a single pair of arguments (like in the man page example ;-).
+ * Also added verbosity option.
+ *
  * aeb, 941108
  */
 #include <lct/cline.h>
@@ -18,6 +23,7 @@
 #include <lct/console.h>
 
 char *progname;
+static int verbose = 0;
 
 static void usage() 
 {
@@ -27,10 +33,11 @@
   OPTIONS_ARE();
   OPT("-h --help         ", HELPDESC);
   OPT("-V --version      ", VERSIONDESC);
+  OPT("-v --verbose      ", "Be verbose");
 }
 
 
-void main(int argc, char **argv) 
+int main(int argc, char **argv) 
 {
   char *ep;
   int fd, sc;
@@ -38,6 +45,7 @@
   const struct option long_opts[] = {
     { "help"     , no_argument, NULL, 'h' },
     { "version"  , no_argument, NULL, 'V' },
+    { "verbose"  , no_argument, NULL, 'v' },
     { NULL, 0, NULL, 0 }
     };
   int c;
@@ -46,7 +54,7 @@
   
   progname = strip_path(argv[0]);
   
-  while ( (c = getopt_long (argc, argv, "Vh", long_opts, NULL)) != EOF) 
+  while ( (c = getopt_long (argc, argv, "Vvh", long_opts, NULL)) != EOF) 
       switch (c) {
       case 'h':
 	usage (progname);
@@ -54,6 +62,9 @@
       case 'V':
 	version (progname);
 	exit(0);
+      case 'v':
+        verbose = 1;
+        break;
       case '?':
 	exit(1);
       }
@@ -61,14 +72,23 @@
     
     if ( (argc - optind -1)  % 2 != 1)
       badusage(_("even number of arguments expected"));
-    if (-1 == (fd = get_console_fd(NULL)))
-      exit (1);
-
-  while ( (argc - optind)  > 2) 
+    if (-1 == (fd = get_console_fd(NULL))) {
+       fprintf( stderr, _("Couldn't open console" ));
+       exit (1);
+    } else if( verbose ) {
+       printf(_( "Console opened OK.\n" ));
+    }
+    
+    
+  while ( (argc - optind)  >= 2) 
     {
       a.scancode = sc = strtol(argv[optind++], &ep, 16);
       a.keycode = atoi(argv[optind++]);
 
+      if( verbose )
+         printf(_("  --> Scancode: %04x, Keycode: %02d\n"), 
+                 a.scancode, a.keycode );
+  
       if (*ep)
 	  badusage(_("error reading scancode"));
       if (a.scancode > 127) 
@@ -86,5 +106,9 @@
 	  exit(1);
 	}
     }
+
+  if( verbose )
+     printf(_( "Done.\n" ));
+  
   exit(0);
 }

Comment 1 Bernhard Rosenkraenzer 2000-07-05 19:37:31 UTC
Thanks, fixed.


Note You need to log in before you can comment on or make changes to this bug.