home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2648 / mt.c < prev    next >
C/C++ Source or Header  |  1991-01-31  |  3KB  |  128 lines

  1. /*--------------------------*/
  2. #include "sys/param.h"
  3. #include "sys/types.h"
  4. #include "sys/sysmacros.h"
  5. #include "sys/dir.h"
  6. #include "sys/signal.h"
  7. #include "sys/user.h"
  8. #include "sys/errno.h"
  9. #include "sys/inline.h"
  10. /*--------------------------*/
  11. #include <stdio.h>
  12. #include    <fcntl.h>
  13. #include    <sys/mouse.h>
  14.  
  15. static int _fd = -1;
  16.  
  17. extern int errno;
  18.  
  19. /*---------------------------------------------------------------------------*/
  20. int ms_init()
  21. {
  22.    struct mouseinfo pkt;
  23.  
  24.    if ((_fd = open("/dev/lmouse", O_RDONLY)) == -1) {
  25.       printf("errno = %d\n", errno);
  26.       perror("ms_init: open");
  27.       return -1;
  28.    }
  29. /*
  30.  else if (ioctl(_fd, MOUSEIOCREAD, &pkt) == -1 ) {
  31.       perror("ms_init: ioctl");
  32.       close(_fd );
  33.       return -1;
  34.    }
  35. */
  36.    return 0;
  37. } /* ms_init */
  38.  
  39. /*---------------------------------------------------------------------------*/
  40. int ms_ioctl(cmd)
  41. int cmd;
  42. {
  43.    struct mouseinfo pkt;
  44.  
  45.    if (cmd == 25) {
  46.      if (ioctl(_fd, MOUSEIOCREAD, &pkt) == -1 ) {
  47.          perror("ms_init: ioctl");
  48. /*       close(_fd ); */
  49.          return -1;
  50.       }
  51.       printf("ms_ioctl: status = 0x%x, xmotion = %d, ymotion = %d\n",
  52.              pkt.status, pkt.xmotion, pkt.ymotion);
  53.    }
  54.    else if (ioctl(_fd, cmd, &pkt) == -1 ) {
  55.       perror("ms_ioctl: ioctl");
  56. /*    close(_fd ); */
  57.       return -1;
  58.    }
  59.  
  60.    return 0;
  61. } /* ms_ioctl */
  62.  
  63. /*---------------------------------------------------------------------------*/
  64. int ms_close()
  65. {
  66.    int rc = -1;
  67.  
  68.    if (_fd != -1) {
  69.       rc = close(_fd );
  70.       _fd = -1;
  71.    }
  72.    return rc;
  73. } /* ms_close */
  74.  
  75. #ifdef NOT_NOW
  76.  
  77. /*
  78.  * FUNCTION: BMSEMD_READ
  79.  *        a routine to call when mouse data is available
  80.  *
  81.  * INPUT PARAMETERS
  82.  *    none
  83.  * OUTPUT PARAMETERS
  84.  *    none
  85.  */
  86. void    bmsemd_read()
  87. {
  88.     MSEPKT    pkt;
  89.  
  90.     if    ( _fd == -1 || ioctl(_fd,VPC_MOUSE_READ,&pkt) == -1 )
  91.     {
  92. #ifdef    DEBUG
  93.         v86error(VERR_WARNING,"unable to get mouse data");
  94. #endif
  95.         return;
  96.     }
  97.  
  98.     if    ( pkt.status & MOVEMENT )    /* if the mouse moved */
  99.         xy_bmouse( pkt.xmotion, pkt.ymotion );
  100.  
  101.     if    ( pkt.status & BUT1CHNG )    /* if button 1 changed */
  102.         btn_bmouse( 0, (int)(pkt.status & BUT1STAT) );
  103.  
  104.     if    ( pkt.status & BUT2CHNG )    /* if button 2 changed */
  105.         btn_bmouse( 1, (int)(pkt.status & BUT2STAT) );
  106.  
  107.     if    ( pkt.status & BUT3CHNG )    /* if button 3 changed */
  108.         btn_bmouse( 2, (int)(pkt.status & BUT3STAT) );
  109. }
  110. #endif /* NOT_NOW */
  111.  
  112. main()
  113. {
  114.    char str[80];
  115.    int cmd;
  116.  
  117.    ms_init();
  118.    for (cmd = 0; 0 <= cmd && cmd <= 25;) {
  119.       printf("cmd? (0-25) > ");
  120.       (void) gets(str);
  121.       cmd = atoi(str);
  122.       printf("mt: cmd = %d\n", cmd);
  123.       if (0 <= cmd && cmd <= 25) ms_ioctl(cmd);
  124.       else                      printf("exiting\n");
  125.    }
  126.    ms_close();
  127. }
  128.