home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / sun / kbd_mode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-09-10  |  3.2 KB  |  118 lines

  1. /************************************************************
  2. Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
  3.  
  4.                     All Rights Reserved
  5.  
  6. Permission  to  use,  copy,  modify,  and  distribute   this
  7. software  and  its documentation for any purpose and without
  8. fee is hereby granted, provided that the above copyright no-
  9. tice  appear  in all copies and that both that copyright no-
  10. tice and this permission notice appear in  supporting  docu-
  11. mentation,  and  that the names of Sun or MIT not be used in
  12. advertising or publicity pertaining to distribution  of  the
  13. software  without specific prior written permission. Sun and
  14. M.I.T. make no representations about the suitability of this
  15. software for any purpose. It is provided "as is" without any
  16. express or implied warranty.
  17.  
  18. SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
  19. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
  20. NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
  21. ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  22. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
  23. PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
  24. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
  25. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26.  
  27. ********************************************************/
  28.  
  29. #ifndef lint
  30. static  char sccsid[] = "@(#)kbd_mode.c 7.1 87/04/13";
  31. #endif
  32.  
  33. /*
  34.  * Copyright (c) 1986 by Sun Microsystems, Inc.
  35.  *
  36.  *      kbd_mode:       set keyboard encoding mode
  37.  */
  38.  
  39. #include <sys/types.h>
  40. #include <sys/file.h>
  41. #include <sys/ioctl.h>
  42. #include <sundev/kbio.h>
  43. #include <sundev/kbd.h>
  44. #include <stdio.h>
  45.  
  46. static void         die(), usage();
  47. static int          kbd_fd;
  48.  
  49. main(argc, argv)
  50.     int             argc;
  51.     char          **argv;
  52. {
  53.     int             code, translate;
  54.  
  55.     if ((kbd_fd = open("/dev/kbd", O_RDONLY, 0)) < 0) {
  56.     die("Couldn't open /dev/kbd");
  57.     }
  58.     argc--; argv++;
  59.     if (argc-- && **argv == '-') {
  60.     code = *(++*argv);
  61.     } else {
  62.     usage();
  63.     }
  64.     switch (code) {
  65.       case 'a':
  66.       case 'A':
  67.     translate = TR_ASCII;
  68.     break;
  69.       case 'e':
  70.       case 'E':
  71.     translate = TR_EVENT;
  72.     break;
  73.       case 'n':
  74.       case 'N':
  75.     translate = TR_NONE;
  76.     break;
  77.       case 'u':
  78.       case 'U':
  79.     translate = TR_UNTRANS_EVENT;
  80.     break;
  81.       default:
  82.     usage();
  83.     }
  84.     if (ioctl(kbd_fd, KIOCTRANS, (caddr_t) &translate)) {
  85.     die("Couldn't initialize translation to Event");
  86.     }
  87.     exit(0);
  88. }
  89.  
  90. static void
  91. die(msg)
  92.     char        *msg;
  93. {
  94.     fprintf(stderr, "%s\n", msg);
  95.     exit(1);
  96. }
  97.  
  98. static void
  99. usage()
  100. {
  101.     int             translate;
  102.  
  103.     if (ioctl(kbd_fd, KIOCGTRANS, (caddr_t) &translate)) {
  104.     die("Couldn't inquire current translation");
  105.      }
  106.     fprintf(stderr, "kbd_mode {-a | -e | -n | -u }\n");
  107.     fprintf(stderr, "\tfor ascii, encoded (normal) SunView events,\n");
  108.     fprintf(stderr, " \tnon-encoded, or unencoded SunView events, resp.\n");
  109.     fprintf(stderr, "Current mode is %s.\n",
  110.         (   translate == 0 ?    "n (non-translated bytes)"      :
  111.          (  translate == 1 ?    "a (ascii bytes)"               :
  112.           ( translate == 2 ?    "e (encoded events)"            :
  113.           /* translate == 3 */  "u (unencoded events)"))));
  114.     exit(1);
  115. }
  116.  
  117.  
  118.