home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / d / ddx-mips.zip / MIPSKBDN.C < prev    next >
C/C++ Source or Header  |  1992-07-31  |  3KB  |  124 lines

  1. /*
  2.  * $XConsortium$
  3.  *
  4.  * Copyright 1991 MIPS Computer Systems, Inc.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of MIPS not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  MIPS makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * MIPS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL MIPS
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  */
  23. #ident    "$Header: mipsKbdNET.c,v 1.5 91/07/10 15:43:40 dd Exp $"
  24.  
  25. /*
  26.  *    keysym mapping for the network keyboard.
  27.  */
  28.  
  29. #include <sys/types.h>
  30. #include <sys/errno.h>
  31. #include <fcntl.h>
  32. #ifdef SYSV
  33. #include <sys/termio.h>
  34. #include <bsd/sys/socket.h>
  35. #include <bsd/netinet/in.h>
  36. #include <bsd/netinet/tcp.h>
  37. #include <bsd/sys/un.h>
  38. #else /* SYSV */
  39. #include <sys/socket.h>
  40. #include <netinet/in.h>
  41. #include <netinet/tcp.h>
  42. #include <sys/un.h>
  43. #endif /* SYSV */
  44. #include "X.h"
  45. #include "Xmd.h"
  46. #include "input.h"
  47. #include "scrnintstr.h"
  48. #include "mips.h"
  49. #include "mipsIo.h"
  50. #include "mipsKbd.h"
  51.  
  52. #if NETWORK_KEYBD
  53. char    *netKeybdAddr = NULL;
  54.  
  55. int
  56. openNetKeybd()
  57. {
  58.     struct sockaddr_in  tcpsock;
  59.     struct sockaddr    *addr;
  60.     int            addrlen;
  61.     int                 connFd;
  62.     int            optval;
  63.  
  64.     if (netKeybdAddr) {
  65.     ErrorF("connecting to network keyboard at %s\n", netKeybdAddr);
  66.     bzero((char *)&tcpsock, sizeof(tcpsock));
  67.     tcpsock.sin_family = AF_INET;
  68.     tcpsock.sin_port = htons(6007);
  69.     tcpsock.sin_addr.s_addr = inet_addr(netKeybdAddr);
  70.     addr = (struct sockaddr *) &tcpsock;
  71.     addrlen = sizeof(tcpsock);
  72.     if ((connFd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
  73.         Error("creating TCP socket");
  74.     else if (connect(connFd, addr, addrlen) == -1)
  75.         ErrorF("unable to connect to network keyboard\n");
  76.     else {
  77. #ifdef SYSV
  78.         optval = 1;
  79.         ioctl(connFd, FIONBIO, &optval);
  80. #else /* SYSV */
  81.         fcntl(connFd, F_SETFL, FNDELAY);
  82. #endif /* SYSV */
  83.         ErrorF("connected to network keyboard\n");
  84.         keybdPriv.cap = DEV_READ;
  85.         netkeyboard();
  86.         return(connFd);
  87.     }
  88.     }
  89.     return(-1);
  90. }
  91.  
  92. netKeybd()
  93. {
  94.     void netKeybdEvent();
  95.  
  96. #ifdef XT_KEYBOARD
  97.     keybdType[XT_KEYBOARD].keybdEvent = netKeybdEvent;
  98. #endif /* XT_KEYBOARD */
  99. #ifdef AT_KEYBOARD
  100.     keybdType[AT_KEYBOARD].keybdEvent = netKeybdEvent;
  101. #endif /* AT_KEYBOARD */
  102. #ifdef UNIX1_KEYBOARD
  103.     keybdType[UNIX1_KEYBOARD].keybdEvent = netKeybdEvent;
  104. #endif /* UNIX1_KEYBOARD */
  105. }
  106.  
  107. void
  108. netKeybdEvent(pKeybd, code)
  109. DevicePtr    pKeybd;
  110. u_char        code;
  111. {
  112.     static int        release = 0;
  113.     u_char        kindex;
  114.  
  115.     if (code == 0xf0)
  116.     release = 1;
  117.     else {
  118.     kindex = code;
  119.     genKeybdEvent(pKeybd, release, kindex);
  120.     release = 0;
  121.     }
  122. }
  123. #endif /* NETWORK_KEYBD */
  124.