/****************************************************************************
- * Copyright (c) 1998-2015,2016 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2016,2017 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 *
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_mouse.c,v 1.169 2016/05/28 23:11:26 tom Exp $")
+MODULE_ID("$Id: lib_mouse.c,v 1.176 2017/11/18 22:12:06 Vassili.Courzakis Exp $")
#include <tic.h>
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;
{
sp->_mouse_gpm_found = FALSE;
if ((sp->_dlopen_gpm = dlopen(LIBGPM_SONAME, my_RTLD)) != 0) {
+#if (defined(__GNUC__) && (__GNUC__ >= 5)) || defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpedantic"
+#endif
if (GET_DLSYM(gpm_fd) == 0 ||
GET_DLSYM(Gpm_Open) == 0 ||
GET_DLSYM(Gpm_Close) == 0 ||
GET_DLSYM(Gpm_GetEvent) == 0) {
+#if (defined(__GNUC__) && (__GNUC__ >= 5)) || defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
T(("GPM initialization failed: %s", dlerror()));
unload_gpm_library(sp);
} else {
/* OS/2 VIO */
#if USE_EMX_MOUSE
if (!sp->_emxmouse_thread
- && strstr(TerminalOf(sp)->type.term_names, "xterm") == 0
+ && strstr(SP_TERMTYPE term_names, "xterm") == 0
&& key_mouse) {
int handles[2];
/* we know how to recognize mouse events under "xterm" */
if (key_mouse != 0) {
if (!strcmp(key_mouse, xterm_kmous)
- || strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
+ || strstr(SP_TERMTYPE term_names, "xterm") != 0) {
init_xterm_mouse(sp);
}
- } else if (strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
+ } else if (strstr(SP_TERMTYPE term_names, "xterm") != 0) {
if (_nc_add_to_try(&(sp->_keytry), xterm_kmous, KEY_MOUSE) == OK)
init_xterm_mouse(sp);
}
static bool
decode_xterm_X10(SCREEN *sp, MEVENT * eventp)
{
- unsigned char kbuf[4];
+#define MAX_KBUF 3
+ unsigned char kbuf[MAX_KBUF + 1];
size_t grabbed;
int res;
bool result;
# endif
_nc_globals.read_thread = pthread_self();
# endif
- for (grabbed = 0; grabbed < 3; grabbed += (size_t) res) {
+ for (grabbed = 0; grabbed < MAX_KBUF; grabbed += (size_t) res) {
/* For VIO mouse we add extra bit 64 to disambiguate button-up. */
res = (int) read(
#else
sp->_ifd,
#endif
- kbuf + grabbed, 3 - grabbed);
+ kbuf + grabbed, (size_t) (MAX_KBUF - (int) grabbed));
if (res == -1)
break;
}
#if USE_PTHREADS_EINTR
_nc_globals.read_thread = 0;
#endif
- kbuf[3] = '\0';
+ kbuf[MAX_KBUF] = '\0';
TR(TRACE_IEVENT,
("_nc_mouse_inline sees the following xterm data: '%s'", kbuf));
kbuf + grabbed, 1);
if (res == -1)
break;
- if ((grabbed + 3) >= (int) sizeof(kbuf)) {
+ if ((grabbed + MAX_KBUF) >= (int) sizeof(kbuf)) {
result->nerror++;
break;
}
NCURSES_SP_NAME(getmouse) (NCURSES_SP_DCLx MEVENT * aevent)
{
int result = ERR;
+ MEVENT *eventp;
T((T_CALLED("getmouse(%p,%p)"), (void *) SP_PARM, (void *) aevent));
- if ((aevent != 0) && (SP_PARM != 0) && (SP_PARM->_mouse_type != M_NONE)) {
- MEVENT *eventp = SP_PARM->_mouse_eventp;
+ if ((aevent != 0) &&
+ (SP_PARM != 0) &&
+ (SP_PARM->_mouse_type != M_NONE) &&
+ (eventp = SP_PARM->_mouse_eventp) != 0) {
/* compute the current-event pointer */
MEVENT *prev = PREV(eventp);
NCURSES_SP_NAME(ungetmouse) (NCURSES_SP_DCLx MEVENT * aevent)
{
int result = ERR;
+ MEVENT *eventp;
T((T_CALLED("ungetmouse(%p,%p)"), (void *) SP_PARM, (void *) aevent));
- if (aevent != 0 && SP_PARM != 0) {
- MEVENT *eventp = SP_PARM->_mouse_eventp;
+ if (aevent != 0 &&
+ SP_PARM != 0 &&
+ (eventp = SP_PARM->_mouse_eventp) != 0) {
/* stick the given event in the next-free slot */
*eventp = *aevent;