Do not install keyboard hooks if the standard input is not the
authorGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Sat, 17 Oct 1992 23:07:22 +0000 (23:07 +0000)
committerGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Sat, 17 Oct 1992 23:07:22 +0000 (23:07 +0000)
keyboard.

v7/src/microcode/doskbd.c

index fb9d598aecf87d13437cb8dc4b4d04c3353e5f27..953e2cb2ebc5e3f04483bf4be59872dbc2a35215 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: doskbd.c,v 1.10 1992/10/07 06:23:30 jinx Exp $
+$Id: doskbd.c,v 1.11 1992/10/17 23:07:22 jinx Exp $
 
 Copyright (c) 1992 Massachusetts Institute of Technology
 
@@ -39,6 +39,8 @@ MIT in each case. */
 #include <dos.h>
 #include <int.h>
 #include "msdos.h"
+#include "osio.h"
+#include "ostty.h"
 \f
 /* These flags determine how the code will behave. */
 
@@ -1494,21 +1496,31 @@ struct keyboard_method_s *
 #define N_KEYBOARD_METHODS                                             \
   ((sizeof (keyboard_methods)) / (sizeof (struct keyboard_method_s)))
 
+static int
+stdin_is_keyboard_p (void)
+{
+  Tchannel input = (OS_tty_input_channel ());
+  if ((OS_channel_type (input)) != channel_type_terminal)
+    return (0);
+  return (1);
+}
+
 int
 dos_install_kbd_hook (void)
 {
   int i, result;
 
-  for (i = 0; i < N_KEYBOARD_METHODS; i++)
-  {
-    if ((* (keyboard_methods[i].present)) ())
+  if (stdin_is_keyboard_p ())
+    for (i = 0; i < N_KEYBOARD_METHODS; i++)
     {
-      result = ((* (keyboard_methods[i].install)) ());
-      if (result == DOS_SUCCESS)
-       installed_keyboard_method = &keyboard_methods[i];
-      return (result);
+      if ((* (keyboard_methods[i].present)) ())
+      {
+       result = ((* (keyboard_methods[i].install)) ());
+       if (result == DOS_SUCCESS)
+         installed_keyboard_method = &keyboard_methods[i];
+       return (result);
+      }
     }
-  }
   return (DOS_FAILURE);
 }
 \f