Beispiel #1
0
keyok(int c, bool flag)
{
    int code = ERR;
    int count = 0;
    char *s;

    T((T_CALLED("keyok(%d,%d)"), c, flag));
    if (flag) {
        while ((s = _nc_expand_try(SP->_key_ok, c, &count, 0)) != 0
                && _nc_remove_key(&(SP->_key_ok), c)) {
            _nc_add_to_try(&(SP->_keytry), s, c);
            free(s);
            code = OK;
            count = 0;
        }
    } else {
        while ((s = _nc_expand_try(SP->_keytry, c, &count, 0)) != 0
                && _nc_remove_key(&(SP->_keytry), c)) {
            _nc_add_to_try(&(SP->_key_ok), s, c);
            free(s);
            code = OK;
            count = 0;
        }
    }
    returnCode(code);
}
Beispiel #2
0
keyok(int c, bool flag)
{
    int code = ERR;
    int count = 0;
    char *s;

    T((T_CALLED("keyok(%d,%d)"), c, flag));
    if (c >= 0) {
	unsigned ch = (unsigned) c;
	if (flag) {
	    while ((s = _nc_expand_try(SP->_key_ok, ch, &count, 0)) != 0
		   && _nc_remove_key(&(SP->_key_ok), ch)) {
		code = _nc_add_to_try(&(SP->_keytry), s, ch);
		free(s);
		count = 0;
		if (code != OK)
		    break;
	    }
	} else {
	    while ((s = _nc_expand_try(SP->_keytry, ch, &count, 0)) != 0
		   && _nc_remove_key(&(SP->_keytry), ch)) {
		code = _nc_add_to_try(&(SP->_key_ok), s, ch);
		free(s);
		count = 0;
		if (code != OK)
		    break;
	    }
	}
    }
    returnCode(code);
}
Beispiel #3
0
define_key(const char *str, int keycode)
{
    int code = ERR;

    T((T_CALLED("define_key(%s,%d)"), _nc_visbuf(str), keycode));
    if (SP == 0) {
	code = ERR;
    } else if (keycode > 0) {
	if (str != 0) {
	    define_key(str, 0);
	} else if (has_key(keycode)) {
	    while (_nc_remove_key(&(SP->_keytry), (unsigned) keycode))
		code = OK;
	}
	if (str != 0) {
	    if (key_defined(str) == 0) {
		(void) _nc_add_to_try(&(SP->_keytry), str, (unsigned) keycode);
		code = OK;
	    } else {
		code = ERR;
	    }
	}
    } else {
	while (_nc_remove_string(&(SP->_keytry), str))
	    code = OK;
    }
    returnCode(code);
}
Beispiel #4
0
NCURSES_SP_NAME(keyok) (NCURSES_SP_DCLx int c, bool flag)
{
    int code = ERR;

    if (HasTerminal(SP_PARM)) {
	T((T_CALLED("keyok(%p, %d,%d)"), (void *) SP_PARM, c, flag));
#ifdef USE_TERM_DRIVER
	code = CallDriver_2(sp, kyOk, c, flag);
#else
	T((T_CALLED("keyok(%d,%d)"), c, flag));
	if (c >= 0) {
	    int count = 0;
	    char *s;
	    unsigned ch = (unsigned) c;

	    if (flag) {
		while ((s = _nc_expand_try(SP_PARM->_key_ok,
					   ch, &count, (size_t) 0)) != 0) {
		    if (_nc_remove_key(&(SP_PARM->_key_ok), ch)) {
			code = _nc_add_to_try(&(SP_PARM->_keytry), s, ch);
			free(s);
			count = 0;
			if (code != OK)
			    break;
		    } else {
			free(s);
		    }
		}
	    } else {
		while ((s = _nc_expand_try(SP_PARM->_keytry,
					   ch, &count, (size_t) 0)) != 0) {
		    if (_nc_remove_key(&(SP_PARM->_keytry), ch)) {
			code = _nc_add_to_try(&(SP_PARM->_key_ok), s, ch);
			free(s);
			count = 0;
			if (code != OK)
			    break;
		    } else {
			free(s);
		    }
		}
	    }
	}
#endif
    }
    returnCode(code);
}
Beispiel #5
0
_nc_init_keytry(SCREEN *sp)
{
    unsigned n;

    /* The sp->_keytry value is initialized in newterm(), where the sp
     * structure is created, because we can not tell where keypad() or
     * mouse_activate() (which will call keyok()) are first called.
     */

    if (sp != 0) {
	for (n = 0; _nc_tinfo_fkeys[n].code; n++) {
	    if (_nc_tinfo_fkeys[n].offset < STRCOUNT) {
		(void) _nc_add_to_try(&(sp->_keytry),
				      CUR Strings[_nc_tinfo_fkeys[n].offset],
				      _nc_tinfo_fkeys[n].code);
	    }
	}
#if NCURSES_XNAMES
	/*
	 * Add any of the extended strings to the tries if their name begins
	 * with 'k', i.e., they follow the convention of other terminfo key
	 * names.
	 */
	{
	    TERMTYPE *tp = &(sp->_term->type);
	    for (n = STRCOUNT; n < NUM_STRINGS(tp); ++n) {
		const char *name = ExtStrname(tp, (int) n, strnames);
		char *value = tp->Strings[n];
		if (name != 0
		    && *name == 'k'
		    && value != 0
		    && NCURSES_SP_NAME(key_defined) (NCURSES_SP_ARGx
						     value) == 0) {
		    (void) _nc_add_to_try(&(sp->_keytry),
					  value,
					  n - STRCOUNT + KEY_MAX);
		}
	    }
	}
#endif
#ifdef TRACE
	_nc_trace_tries(sp->_keytry);
#endif
    }
}
void _nc_init_keytry(void)
{
	size_t n;

	/* The SP->_keytry value is initialized in newterm(), where the SP
	 * structure is created, because we can not tell where keypad() or
	 * mouse_activate() (which will call keyok()) are first called.
	 */

	for (n = 0; _nc_tinfo_fkeys[n].code; n++)
		if (_nc_tinfo_fkeys[n].offset < STRCOUNT)
		_nc_add_to_try(&(SP->_keytry),
			CUR Strings[_nc_tinfo_fkeys[n].offset],
			_nc_tinfo_fkeys[n].code);
#ifdef TRACE
	_nc_trace_tries(SP->_keytry);
#endif
}
Beispiel #7
0
int
define_key(char *str, int keycode)
{
	int code = ERR;

	T((T_CALLED("define_key(%s,%d)"), _nc_visbuf(str), keycode));
	if (keycode > 0) {
		if (has_key(keycode)) {
			if (_nc_remove_key(&(SP->_keytry), keycode))
				code = OK;
		}
		if (str != 0) {
			(void) _nc_add_to_try(&(SP->_keytry), str, keycode);
			code = OK;
		}
	}
	returnCode(code);
}
Beispiel #8
0
NCURSES_SP_NAME(define_key) (NCURSES_SP_DCLx const char *str, int keycode)
{
    int code = ERR;

    T((T_CALLED("define_key(%p, %s,%d)"), (void *) SP_PARM, _nc_visbuf(str), keycode));
    if (SP_PARM == 0 || !HasTInfoTerminal(SP_PARM)) {
	code = ERR;
    } else if (keycode > 0) {
	unsigned ukey = (unsigned) keycode;

#ifdef USE_TERM_DRIVER
#define CallHasKey(keycode) CallDriver_1(SP_PARM, td_kyExist, keycode)
#else
#define CallHasKey(keycode) NCURSES_SP_NAME(has_key)(NCURSES_SP_ARGx keycode)
#endif

	if (str != 0) {
	    NCURSES_SP_NAME(define_key) (NCURSES_SP_ARGx str, 0);
	} else if (CallHasKey(keycode)) {
	    while (_nc_remove_key(&(SP_PARM->_keytry), ukey))
		code = OK;
	}
	if (str != 0) {
	    if (NCURSES_SP_NAME(key_defined) (NCURSES_SP_ARGx str) == 0) {
		if (_nc_add_to_try(&(SP_PARM->_keytry), str, ukey) == OK) {
		    code = OK;
		} else {
		    code = ERR;
		}
	    } else {
		code = ERR;
	    }
	}
    } else {
	while (_nc_remove_string(&(SP_PARM->_keytry), str))
	    code = OK;
    }
    returnCode(code);
}
Beispiel #9
0
static void
initialize_mousetype(void)
{
    static const char *xterm_kmous = "\033[M";

    /* Try gpm first, because gpm may be configured to run in xterm */
#if USE_GPM_SUPPORT
    /* GPM: initialize connection to gpm server */
    gpm_connect.eventMask = GPM_DOWN | GPM_UP;
    gpm_connect.defaultMask = ~(gpm_connect.eventMask | GPM_HARD);
    gpm_connect.minMod = 0;
    gpm_connect.maxMod = ~((1 << KG_SHIFT) | (1 << KG_SHIFTL) | (1 << KG_SHIFTR));
    if (Gpm_Open(&gpm_connect, 0) >= 0) {	/* returns the file-descriptor */
	mousetype = M_GPM;
	SP->_mouse_fd = gpm_fd;
	return;
    }
#endif

    /* OS/2 VIO */
#ifdef USE_EMX_MOUSE
    if (!mouse_thread
	&& strstr(cur_term->type.term_names, "xterm") == 0
	&& key_mouse) {
	int handles[2];

	if (pipe(handles) < 0) {
	    perror("mouse pipe error");
	    return;
	} else {
	    int rc;

	    if (!mouse_buttons[0]) {
		char *s = getenv("MOUSE_BUTTONS_123");

		mouse_buttons[0] = 1;
		if (s && strlen(s) >= 3) {
		    mouse_buttons[1] = s[0] - '0';
		    mouse_buttons[2] = s[1] - '0';
		    mouse_buttons[3] = s[2] - '0';
		}
	    }
	    mouse_wfd = handles[1];
	    M_FD(SP) = handles[0];
	    /* Needed? */
	    setmode(handles[0], O_BINARY);
	    setmode(handles[1], O_BINARY);
	    /* Do not use CRT functions, we may single-threaded. */
	    rc = DosCreateThread((unsigned long *) &mouse_thread,
				 mouse_server, 0, 0, 8192);
	    if (rc) {
		printf("mouse thread error %d=%#x", rc, rc);
		return;
	    } else {
		mousetype = M_XTERM;
		return;
	    }
	}
    }
#endif

    /* we know how to recognize mouse events under "xterm" */
    if (key_mouse != 0) {
	if (!strcmp(key_mouse, xterm_kmous)) {
	    mousetype = M_XTERM;
	    return;
	}
    } else if (strstr(cur_term->type.term_names, "xterm") != 0) {
	(void) _nc_add_to_try(&(SP->_keytry), xterm_kmous, KEY_MOUSE);
	mousetype = M_XTERM;
	return;
    }
}
Beispiel #10
0
static void
initialize_mousetype(SCREEN *sp)
{
    T((T_CALLED("initialize_mousetype()")));

    /* Try gpm first, because gpm may be configured to run in xterm */
#if USE_GPM_SUPPORT
    if (allow_gpm_mouse()) {
	if (!sp->_mouse_gpm_loaded) {
#ifdef HAVE_LIBDL
	    load_gpm_library(sp);
#else /* !HAVE_LIBDL */
	    sp->_mouse_gpm_found = TRUE;
	    sp->_mouse_gpm_loaded = TRUE;
#endif
	}

	/*
	 * The gpm_fd file-descriptor may be negative (xterm).  So we have to
	 * maintain our notion of whether the mouse connection is active
	 * without testing the file-descriptor.
	 */
	if (sp->_mouse_gpm_found && enable_gpm_mouse(sp, TRUE)) {
	    sp->_mouse_type = M_GPM;
	    sp->_mouse_fd = *(my_gpm_fd);
	    T(("GPM mouse_fd %d", sp->_mouse_fd));
	    returnVoid;
	}
    }
#endif /* USE_GPM_SUPPORT */

    /* OS/2 VIO */
#if USE_EMX_MOUSE
    if (!sp->_emxmouse_thread
	&& strstr(TerminalOf(sp)->type.term_names, "xterm") == 0
	&& key_mouse) {
	int handles[2];

	if (pipe(handles) < 0) {
	    perror("mouse pipe error");
	    returnVoid;
	} else {
	    int rc;

	    if (!sp->_emxmouse_buttons[0]) {
		char *s = getenv("MOUSE_BUTTONS_123");

		sp->_emxmouse_buttons[0] = 1;
		if (s && strlen(s) >= 3) {
		    sp->_emxmouse_buttons[1] = s[0] - '0';
		    sp->_emxmouse_buttons[2] = s[1] - '0';
		    sp->_emxmouse_buttons[3] = s[2] - '0';
		} else {
		    sp->_emxmouse_buttons[1] = 1;
		    sp->_emxmouse_buttons[2] = 3;
		    sp->_emxmouse_buttons[3] = 2;
		}
	    }
	    sp->_emxmouse_wfd = handles[1];
	    M_FD(sp) = handles[0];
	    /* Needed? */
	    setmode(handles[0], O_BINARY);
	    setmode(handles[1], O_BINARY);
	    /* Do not use CRT functions, we may single-threaded. */
	    rc = DosCreateThread((unsigned long *) &sp->_emxmouse_thread,
				 mouse_server, (long) sp, 0, 8192);
	    if (rc) {
		printf("mouse thread error %d=%#x", rc, rc);
	    } else {
		sp->_mouse_type = M_XTERM;
	    }
	    returnVoid;
	}
    }
#endif /* USE_EMX_MOUSE */

#if USE_SYSMOUSE
    {
	struct mouse_info the_mouse;
	char *the_device = 0;

	if (isatty(sp->_ifd))
	    the_device = ttyname(sp->_ifd);
	if (the_device == 0)
	    the_device = "/dev/tty";

	sp->_mouse_fd = open(the_device, O_RDWR);

	if (sp->_mouse_fd >= 0) {
	    /*
	     * sysmouse does not have a usable user interface for obtaining
	     * mouse events.  The logical way to proceed (reading data on a
	     * stream) only works if one opens the device as root.  Even in
	     * that mode, careful examination shows we lose events
	     * occasionally.  The interface provided for user programs is to
	     * establish a signal handler.  really.
	     *
	     * Take over SIGUSR2 for this purpose since SIGUSR1 is more
	     * likely to be used by an application.  getch() will have to
	     * handle the misleading EINTR's.
	     */
	    signal(SIGUSR2, SIG_IGN);
	    the_mouse.operation = MOUSE_MODE;
	    the_mouse.u.mode.mode = 0;
	    the_mouse.u.mode.signal = SIGUSR2;
	    if (ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse) != -1) {
		signal(SIGUSR2, handle_sysmouse);
		the_mouse.operation = MOUSE_SHOW;
		ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse);

#if defined(FBIO_MODEINFO) || defined(CONS_MODEINFO)	/* FreeBSD > 2.x */
		{
#ifndef FBIO_GETMODE		/* FreeBSD 3.x */
#define FBIO_GETMODE    CONS_GET
#define FBIO_MODEINFO   CONS_MODEINFO
#endif /* FBIO_GETMODE */
		    video_info_t the_video;

		    if (ioctl(sp->_mouse_fd,
			      FBIO_GETMODE,
			      &the_video.vi_mode) != -1
			&& ioctl(sp->_mouse_fd,
				 FBIO_MODEINFO,
				 &the_video) != -1) {
			sp->_sysmouse_char_width = the_video.vi_cwidth;
			sp->_sysmouse_char_height = the_video.vi_cheight;
		    }
		}
#endif /* defined(FBIO_MODEINFO) || defined(CONS_MODEINFO) */

		if (sp->_sysmouse_char_width <= 0)
		    sp->_sysmouse_char_width = 8;
		if (sp->_sysmouse_char_height <= 0)
		    sp->_sysmouse_char_height = 16;
		sp->_mouse_type = M_SYSMOUSE;
		returnVoid;
	    }
	}
    }
#endif /* USE_SYSMOUSE */

#ifdef USE_TERM_DRIVER
    CallDriver(sp, initmouse);
#else
    /* 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) {
	    init_xterm_mouse(sp);
	}
    } else if (strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
	if (_nc_add_to_try(&(sp->_keytry), xterm_kmous, KEY_MOUSE) == OK)
	    init_xterm_mouse(sp);
    }
#endif

    returnVoid;
}