]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_mouse.c
ncurses 6.0 - patch 20161210
[ncurses.git] / ncurses / base / lib_mouse.c
index 72a99ce7922de9b071f471b77c383df5560411c0..43b0069a8a8b38ff90900ee69af6a69e5be91064 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2015,2016 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -84,7 +84,7 @@
 #define CUR SP_TERMTYPE
 #endif
 
-MODULE_ID("$Id: lib_mouse.c,v 1.167 2015/10/17 22:08:05 KO.Myung-Hun Exp $")
+MODULE_ID("$Id: lib_mouse.c,v 1.170 2016/09/10 18:36:08 tom Exp $")
 
 #include <tic.h>
 
@@ -225,7 +225,7 @@ write_event(SCREEN *sp, int down, int button, int x, int y)
     char buf[6];
     unsigned long ignore;
 
-    strcpy(buf, "\033[M");     /* should be the same as key_mouse */
+    _nc_STRCPY(buf, "\033[M", sizeof(buf));    /* should be the same as key_mouse */
     buf[3] = ' ' + (button - 1) + (down ? 0 : 0x40);
     buf[4] = ' ' + x - LEFT_COL + 1;
     buf[5] = ' ' + y - TOP_ROW + 1;
@@ -641,13 +641,14 @@ initialize_mousetype(SCREEN *sp)
 
 #if USE_SYSMOUSE
     {
+       static char dev_tty[] = "/dev/tty";
        struct mouse_info the_mouse;
        char *the_device = 0;
 
        if (NC_ISATTY(sp->_ifd))
            the_device = ttyname(sp->_ifd);
        if (the_device == 0)
-           the_device = "/dev/tty";
+           the_device = dev_tty;
 
        sp->_mouse_fd = open(the_device, O_RDWR);
 
@@ -727,10 +728,11 @@ _nc_mouse_init(SCREEN *sp)
 /* initialize the mouse */
 {
     bool result = FALSE;
-    int i;
 
     if (sp != 0) {
        if (!sp->_mouse_initialized) {
+           int i;
+
            sp->_mouse_initialized = TRUE;
 
            TR(MY_TRACE, ("_nc_mouse_init() called"));
@@ -896,7 +898,7 @@ _nc_mouse_event(SCREEN *sp)
 #else
 #define PRESS_POSITION(n) \
     do { \
-           eventp->bstate = (mmask_t) (sp->_mouse_bstate & MASK_PRESS(n) \
+           eventp->bstate = (mmask_t) ((sp->_mouse_bstate & MASK_PRESS(n)) \
                                    ? REPORT_MOUSE_POSITION \
                                    : MASK_PRESS(n)); \
            sp->_mouse_bstate |= MASK_PRESS(n); \
@@ -946,11 +948,11 @@ static bool
 decode_X10_bstate(SCREEN *sp, MEVENT * eventp, unsigned intro)
 {
     bool result;
-    int b;
 
     eventp->bstate = 0;
 
     if (!handle_wheel(sp, eventp, (int) intro, (intro & 96) == 96)) {
+
        /*
         * Release events aren't reported for individual buttons, just for
         * the button set as a whole.  However, because there are normally
@@ -959,6 +961,8 @@ decode_X10_bstate(SCREEN *sp, MEVENT * eventp, unsigned intro)
         * the previous event.
         */
        if (sp->_mouse_bstate & BUTTON_PRESSED) {
+           int b;
+
            eventp->bstate = BUTTON_RELEASED;
            for (b = 1; b <= MAX_BUTTONS; ++b) {
                if (!(sp->_mouse_bstate & MASK_PRESS(b)))
@@ -1074,7 +1078,6 @@ decode_xterm_1005(SCREEN *sp, MEVENT * eventp)
     size_t grabbed;
     size_t limit = (sizeof(kbuf) - 1);
     unsigned coords[2];
-    int res;
     bool result;
 
     coords[0] = 0;
@@ -1087,6 +1090,7 @@ decode_xterm_1005(SCREEN *sp, MEVENT * eventp)
        _nc_globals.read_thread = pthread_self();
 # endif
     for (grabbed = 0; grabbed < limit;) {
+       int res;
 
        res = (int) read(
 #if USE_EMX_MOUSE
@@ -1101,8 +1105,10 @@ decode_xterm_1005(SCREEN *sp, MEVENT * eventp)
        if (grabbed > 1) {
            size_t check = 1;
            int n;
-           int rc;
+
            for (n = 0; n < 2; ++n) {
+               int rc;
+
                if (check >= grabbed)
                    break;
                rc = _nc_conv_to_utf32(&coords[n], kbuf + check, (unsigned)
@@ -1156,7 +1162,6 @@ read_SGR(SCREEN *sp, SGR_DATA * result)
 {
     char kbuf[80];             /* bigger than any possible mouse response */
     int grabbed = 0;
-    int res;
     int ch = 0;
     int now = -1;
     int marker = 1;
@@ -1168,7 +1173,10 @@ read_SGR(SCREEN *sp, SGR_DATA * result)
 #  endif
        _nc_globals.read_thread = pthread_self();
 # endif
+
     do {
+       int res;
+
        res = (int) read(
 #if USE_EMX_MOUSE
                            (M_FD(sp) >= 0) ? M_FD(sp) : sp->_ifd,
@@ -1823,7 +1831,6 @@ NCURSES_SP_NAME(mousemask) (NCURSES_SP_DCLx mmask_t newmask, mmask_t * oldmask)
 /* set the mouse event mask */
 {
     mmask_t result = 0;
-    int b;
 
     T((T_CALLED("mousemask(%p,%#lx,%p)"),
        (void *) SP_PARM,
@@ -1836,7 +1843,10 @@ NCURSES_SP_NAME(mousemask) (NCURSES_SP_DCLx mmask_t newmask, mmask_t * oldmask)
 
        if (newmask || SP_PARM->_mouse_initialized) {
            _nc_mouse_init(SP_PARM);
+
            if (SP_PARM->_mouse_type != M_NONE) {
+               int b;
+
                result = newmask &
                    (REPORT_MOUSE_POSITION
                     | BUTTON_ALT