1999-03-17
Linux/SPARC modifications by Jeffrey Connell <ankh@canuck.gen.nz>:
It seems that the KDKBDREP ioctl is not available on this platform.
- However, Linux/SPARC has its own ioctl for this, with yet another
- different measurement system. Thus, try for KIOCSRATE, too.
+ However, Linux/SPARC has its own ioctl for this (since 2.1.30),
+ with yet another measurement system. Thus, try for KIOCSRATE, too.
*/
#include <errno.h>
#include <sys/file.h>
#include <sys/ioctl.h>
+#include <linux/kd.h>
#ifdef __sparc__
#include <asm/param.h>
#endif
-#ifndef KDKBDREP
-/* usually defined in <linux/kd.h> */
-#define KDKBDREP 0x4B52 /* set keyboard delay/repeat rate;
- * actually used values are returned */
-struct kbd_repeat {
+#ifdef COMPAT_HEADERS
+#include "compat/linux-kd.h"
+#endif
+
+/* Equal to kernel version, but field names vary. */
+struct my_kbd_repeat {
int delay; /* in msec; <= 0: don't change */
-#ifdef __sparc__
- int rate; /* in msec; <= 0: don't change */
-#else
int period; /* in msec; <= 0: don't change */
-#endif
+ /* earlier this field was misnamed "rate" */
};
-#endif /* KDKBDREP */
-
-#ifdef __sparc__
-#define KBD_PERIOD(var) var.rate
-#else
-#define KBD_PERIOD(var) var.period
-#endif
#include <signal.h>
static int
KDKBDREP_ioctl_ok(double rate, int delay, int silent) {
-#if defined(KDKBDREP) && !defined(__sparc__)
- /* This ioctl is defined in <linux/kd.h> but is not
- implemented anywhere - must be in some m68k patches.
- We cannot blindly try unimplemented ioctls on sparc64 -
- the 32<->64bit transition layer does not like it. */
- struct kbd_repeat kbdrep_s;
+ /*
+ * This ioctl is defined in <linux/kd.h> but is not
+ * implemented anywhere - must be in some m68k patches.
+ * Since 2.4.9 also on i386.
+ */
+ struct my_kbd_repeat kbdrep_s;
/* don't change, just test */
- KBD_PERIOD(kbdrep_s) = -1;
+ kbdrep_s.period = -1;
kbdrep_s.delay = -1;
if (ioctl( 0, KDKBDREP, &kbdrep_s )) {
if (errno == EINVAL || errno == ENOTTY)
#if 0
printf("old delay %d, period %d\n",
- kbdrep_s.delay, KBD_PERIOD(kbdrep_s));
+ kbdrep_s.delay, kbdrep_s.period);
#endif
/* do the change */
if (rate == 0) /* switch repeat off */
- KBD_PERIOD(kbdrep_s) = 0;
+ kbdrep_s.period = 0;
else
- KBD_PERIOD(kbdrep_s) = 1000.0 / rate; /* convert cps to msec */
- if (KBD_PERIOD(kbdrep_s) < 1)
- KBD_PERIOD(kbdrep_s) = 1;
+ kbdrep_s.period = 1000.0 / rate; /* convert cps to msec */
+ if (kbdrep_s.period < 1)
+ kbdrep_s.period = 1;
kbdrep_s.delay = delay;
if (kbdrep_s.delay < 1)
kbdrep_s.delay = 1;
}
/* report */
- if (KBD_PERIOD(kbdrep_s) == 0)
+ if (kbdrep_s.period == 0)
rate = 0;
else
- rate = 1000.0 / (double) KBD_PERIOD(kbdrep_s);
+ rate = 1000.0 / (double) kbdrep_s.period;
+
+ if (!silent)
+ printf( _("Typematic Rate set to %.1f cps (delay = %d ms)\n"),
+ rate, kbdrep_s.delay );
+
+ kbdrep_s.period = -1;
+ kbdrep_s.delay = -1;
+ if (ioctl( 0, KDKBDREP, &kbdrep_s )) {
+ if (errno == EINVAL)
+ return 0;
+ perror( "ioctl(KDKBDREP)" );
+ exit( 1 );
+ }
+ printf("old delay %d, period %d\n",
+ kbdrep_s.delay, kbdrep_s.period);
+ if (kbdrep_s.period == 0)
+ rate = 0;
+ else
+ rate = 1000.0 / (double) kbdrep_s.period;
if (!silent)
printf( _("Typematic Rate set to %.1f cps (delay = %d ms)\n"),
rate, kbdrep_s.delay );
return 1; /* success! */
-#else /* no KDKBDREP or __sparc__ */
- return 0;
-#endif /* KDKBDREP */
}
+#ifndef KIOCSRATE
+#define arg_state attr_unused
+#else
+#define arg_state
+#endif
+
static int
-KIOCSRATE_ioctl_ok(double rate, int delay, int silent) {
+KIOCSRATE_ioctl_ok(arg_state double rate, arg_state int delay, arg_state int silent) {
#ifdef KIOCSRATE
struct kbd_rate kbdrate_s;
int fd;
exit( 1 );
}
- KBD_PERIOD(kbdrate_s) = (int) (rate + 0.5); /* round up */
+ kbdrate_s.rate = (int) (rate + 0.5); /* round up */
kbdrate_s.delay = delay * HZ / 1000; /* convert ms to Hz */
- if (KBD_PERIOD(kbdrate_s) > 50)
- KBD_PERIOD(kbdrate_s) = 50;
+ if (kbdrate_s.rate > 50)
+ kbdrate_s.rate = 50;
if (ioctl( fd, KIOCSRATE, &kbdrate_s )) {
perror( "ioctl(KIOCSRATE)" );
if (!silent)
printf( "Typematic Rate set to %d cps (delay = %d ms)\n",
- KBD_PERIOD(kbdrate_s), kbdrate_s.delay * 1000 / HZ );
+ kbdrate_s.rate, kbdrate_s.delay * 1000 / HZ );
return 1;
#else /* no KIOCSRATE */
}
static void
-sigalrmhandler( int sig ) {
+sigalrmhandler( attr_unused int sig ) {
fprintf( stderr, "kbdrate: Failed waiting for kbd controller!\n" );
raise( SIGINT );
}
int
main( int argc, char **argv ) {
#ifdef __sparc__
- double rate = 20.0; /* Default rate */
+ double rate = 5.0; /* Default rate */
int delay = 200; /* Default delay */
#else
double rate = 10.9; /* Default rate */
int fd;
char data;
int c;
- int i;
+ unsigned int i;
extern char *optarg;
set_progname(argv[0]);
setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
+ bindtextdomain(PACKAGE_NAME, LOCALEDIR);
+ textdomain(PACKAGE_NAME);
if (argc == 2 &&
(!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")))
return 0;
- /* The ioport way - will crash on sparc */
+ /* The ioport way */
-#ifndef __sparc__
for (i = 0; i < RATE_COUNT; i++)
if (rate * 10 >= valid_rates[i]) {
value &= 0x60;
valid_rates[value & 0x1f] / 10.0,
valid_delays[ (value & 0x60) >> 5 ] );
-#endif
-
return 0;
}