Exemplo n.º 1
0
static inline int
fifo_push(void)
{
    int n;
    unsigned int ch;

    if (tail == -1)
	return ERR;

#ifdef HIDE_EINTR
  again:
    errno = 0;
#endif

#if USE_GPM_SUPPORT || defined(USE_EMX_MOUSE)
    if ((SP->_mouse_fd >= 0)
	&& (_nc_timed_wait(3, -1, (int *) 0) & 2)) {
	SP->_mouse_event(SP);
	ch = KEY_MOUSE;
	n = 1;
    } else
#endif
    {
	unsigned char c2 = 0;
	n = read(SP->_ifd, &c2, 1);
	ch = c2 & 0xff;
    }

#ifdef HIDE_EINTR
    /*
     * Under System V curses with non-restarting signals, getch() returns
     * with value ERR when a handled signal keeps it from completing.
     * If signals restart system calls, OTOH, the signal is invisible
     * except to its handler.
     *
     * We don't want this difference to show.  This piece of code
     * tries to make it look like we always have restarting signals.
     */
    if (n <= 0 && errno == EINTR)
	goto again;
#endif

    if ((n == -1) || (n == 0)) {
	TR(TRACE_IEVENT, ("read(%d,&ch,1)=%d, errno=%d", SP->_ifd, n, errno));
	ch = ERR;
    }
    TR(TRACE_IEVENT, ("read %d characters", n));

    SP->_fifo[tail] = ch;
    SP->_fifohold = 0;
    if (head == -1)
	head = peek = tail;
    t_inc();
    TR(TRACE_IEVENT, ("pushed %#x at %d", ch, tail));
#ifdef TRACE
    if (_nc_tracing & TRACE_IEVENT)
	_nc_fifo_dump();
#endif
    return ch;
}
Exemplo n.º 2
0
safe_ungetch(SCREEN *sp, int ch)
{
    int rc = ERR;

    T((T_CALLED("ungetch(%p,%s)"), (void *) sp, _nc_tracechar(sp, ch)));

    if (tail != -1) {
	if (head == -1) {
	    head = 0;
	    t_inc();
	    peek = tail;	/* no raw keys */
	} else
	    h_dec();

	sp->_fifo[head] = ch;
	T(("ungetch %s ok", _nc_tracechar(sp, ch)));
#ifdef TRACE
	if (USE_TRACEF(TRACE_IEVENT)) {
	    _nc_fifo_dump(sp);
	    _nc_unlock_global(tracef);
	}
#endif
	rc = OK;
    }
    returnCode(rc);
}
Exemplo n.º 3
0
int ungetch(int ch)
{
	if (tail == -1)
		return ERR;
	if (head == -1) {
		head = 0;
		t_inc()
		peek = tail; /* no raw keys */
	} else
		h_dec();

	SP->_fifo[head] = ch;
	T(("ungetch %#x ok", ch));
#ifdef TRACE
	if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump();
#endif
	return OK;
}
Exemplo n.º 4
0
static inline int
fifo_pull(void)
{
    int ch;
    ch = SP->_fifo[head];
    TR(TRACE_IEVENT, ("pulling %d from %d", ch, head));

    if (peek == head) {
	h_inc();
	peek = head;
    } else
	h_inc();

#ifdef TRACE
    if (_nc_tracing & TRACE_IEVENT)
	_nc_fifo_dump();
#endif
    return ch;
}
Exemplo n.º 5
0
static NCURSES_INLINE int
fifo_pull(SCREEN *sp)
{
    int ch;
    ch = sp->_fifo[head];
    TR(TRACE_IEVENT, ("pulling %s from %d", _nc_tracechar(sp, ch), head));

    if (peek == head) {
	h_inc();
	peek = head;
    } else
	h_inc();

#ifdef TRACE
    if (USE_TRACEF(TRACE_IEVENT)) {
	_nc_fifo_dump(sp);
	_nc_unlock_global(tracef);
    }
#endif
    return ch;
}
Exemplo n.º 6
0
static inline int
fifo_push(EVENTLIST_0th(_nc_eventlist * evl))
{
    int n;
    int ch = 0;
    int mask = 0;

    (void) mask;
    if (tail == -1)
	return ERR;

#ifdef HIDE_EINTR
  again:
    errno = 0;
#endif

#ifdef NCURSES_WGETCH_EVENTS
    if (evl
#if USE_GPM_SUPPORT || USE_EMX_MOUSE || USE_SYSMOUSE
	|| (SP->_mouse_fd >= 0)
#endif
	) {
	mask = check_mouse_activity(-1 EVENTLIST_2nd(evl));
    } else
	mask = 0;

    if (mask & 4) {
	T(("fifo_push: ungetch KEY_EVENT"));
	ungetch(KEY_EVENT);
	return KEY_EVENT;
    }
#elif USE_GPM_SUPPORT || USE_EMX_MOUSE || USE_SYSMOUSE
    if (SP->_mouse_fd >= 0) {
	mask = check_mouse_activity(-1 EVENTLIST_2nd(evl));
    }
#endif

#if USE_GPM_SUPPORT || USE_EMX_MOUSE
    if ((SP->_mouse_fd >= 0) && (mask & 2)) {
	SP->_mouse_event(SP);
	ch = KEY_MOUSE;
	n = 1;
    } else
#endif
#if USE_SYSMOUSE
	if ((SP->_mouse_type == M_SYSMOUSE)
	    && (SP->_sysmouse_head < SP->_sysmouse_tail)) {
	SP->_mouse_event(SP);
	ch = KEY_MOUSE;
	n = 1;
    } else if ((SP->_mouse_type == M_SYSMOUSE)
	       && (mask <= 0) && errno == EINTR) {
	SP->_mouse_event(SP);
	ch = KEY_MOUSE;
	n = 1;
    } else
#endif
    {				/* Can block... */
	unsigned char c2 = 0;
	n = read(SP->_ifd, &c2, 1);
	ch = c2;
    }

#ifdef HIDE_EINTR
    /*
     * Under System V curses with non-restarting signals, getch() returns
     * with value ERR when a handled signal keeps it from completing.
     * If signals restart system calls, OTOH, the signal is invisible
     * except to its handler.
     *
     * We don't want this difference to show.  This piece of code
     * tries to make it look like we always have restarting signals.
     */
    if (n <= 0 && errno == EINTR)
	goto again;
#endif

    if ((n == -1) || (n == 0)) {
	TR(TRACE_IEVENT, ("read(%d,&ch,1)=%d, errno=%d", SP->_ifd, n, errno));
	ch = ERR;
    }
    TR(TRACE_IEVENT, ("read %d characters", n));

    SP->_fifo[tail] = ch;
    SP->_fifohold = 0;
    if (head == -1)
	head = peek = tail;
    t_inc();
    TR(TRACE_IEVENT, ("pushed %s at %d", _tracechar(ch), tail));
#ifdef TRACE
    if (_nc_tracing & TRACE_IEVENT)
	_nc_fifo_dump();
#endif
    return ch;
}