/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
/*LINTLIBRARY*/
#include "curses_inc.h"
#include <signal.h>
#include <unistd.h>
#ifdef DEBUG
#include <ctype.h>
#endif /* DEBUG */
/*
* Read a key typed from the terminal
*
* interpret: = 0 for single-char key only
* = 1 for matching function key and macro patterns.
* = 2 same as 1 but no time-out for funckey matching.
*/
static int _fpk(void);
static int _pk(void);
{
#ifdef SYSV
/*
* Register the fact that getch is being used so
* that typeahead checking can be done.
* This code should GO AWAY when a poll() or FIONREAD can
* be done on the file descriptor as then the check
* will be non-destructive.
*/
#endif /* SYSV */
/* ask for input */
/* decode an ungetch()'d character */
} else {
if (*chars_onQ == 0) {
/* (*chars_onQ)++; MR */
#ifdef FIONREAD
#else /* FIONREAD */
/*
* interpret is set to 0 so that down below we don't
* drop into getkey since we already know there can't be
* a key that starts with -1. Also, we don't want to
* access funckeystarter[-1].
*/
}
#endif /* FIONREAD */
(*chars_onQ)++;
} else
#ifdef DEBUG
if (outf)
#endif /* DEBUG */
/* Check for arrow and function keys */
}
/* Collapse the input queue to remove the escape */
/* sequence from the stack. */
j = *chars_onQ;
while (collapse < j)
return (inp);
}
#ifdef FIONREAD
static int
{
int i;
unsigned char c;
int arg;
#ifdef DEBUG
if (outf)
#endif /* DEBUG */
if (arg < 1)
return (-1);
} else
char c;
int infd;
if (i < 0)
return (ERR);
} else
#ifdef DEBUG
if (outf)
#endif /* DEBUG */
if (i > 0)
return (c);
else
return (ERR);
}
#endif /* !FIONREAD */
#ifdef DEBUG
extern char *_asciify();
#endif /* DEBUG */
static int get_xterm_mouse(int, int *);
static void _map_button(chtype *);
/*
* This algorithm is a "learning" algorithm. The premise is
* that keys used once are like to be used again and again.
* Since the time for a linear search of the table is so
* expensive, we move keys that are found up to the top of
* the list, making the access to a repeated key very fast and
* keys that have been used before close to the top.
*/
static int
{
int i;
#ifdef DEBUG
if (outf)
"inp=%d\n", *inp);
#endif /* DEBUG */
key = 0;
else {
}
for (i = 1; i < INP_QSIZE; i++) {
/* found it? */
break;
/* partial match? peek ahead. */
if (*chars_onQ == i) {
(*chars_onQ)++;
switch ((int)inputQ[i]) {
case -2:
/*
* Since -2 signifies a timeout we don't really
* want to put it on the queue so we decrement
* our counter.
*/
(*chars_onQ)--;
#ifdef DEBUG
if (outf)
#endif /* DEBUG */
#ifdef DEBUG
if (outf)
"Found macro\n");
#endif /* DEBUG */
/*
* We have to decrement one because key will be
* incremented at the bottom of the out loop.
*/
cur_term->_first_macro) -
1;
goto outerloop;
}
/*FALLTHROUGH*/
case -1:
goto ret;
}
}
/* not this one? */
goto outerloop;
}
/* SS-mouse */
int rc;
/* read the mouse status information */
if (mouse_info)
else
goto ret;
/* or not mouse */
goto outerloop;
else if (rc == 0) /* report mouse pos */
/* mouse button event */
(((MOUSE_X_POS != old_mouse.x ||
(Mouse_status.button[0] !=
}
/* We found it! Read in any chars left in _sends */
(void) _fpk();
/* move key to top of ordered list */
short *lorder;
int j;
else
/*
* If we're below the last ordered key, swap next unordered
* key with this one and ripple from there.
*/
else
i = key;
/* ripple the ordered keys down */
for (j = i--; j > first; )
}
/*
* SS-mouse support: if mouse button event
* occured on top of the soft label, we may
* have to return the function key corresponding
* to that soft label
*/
(MOUSE_Y_POS == LINES) &&
(SP->_map_mbe_to_key != 0)) {
}
goto ret;
}
;
}
ret:
/* key not found */
#ifdef DEBUG
if (outf)
#endif /* DEBUG */
return (collapse);
}
/* SS-mouse */
/* this function tries to read in information that follows KEY_MOUSE: */
/* the first character identifies what button is involved (1,2,or 3) */
/* if the first character is 0, we are dealing with report_mouse_pos */
/*
* The routine returns the following:
* -3: not a mouse button event
* -2: read timed out
* -1: the read failed
* [0, 1, 2, 3] - the first character in the mouse event
*/
static int
{
/* LINTED */
/* the first character should be 0, 1, 2, or 4 */
/* read error or timeout */
if (char1 < 0)
return (char1);
(*chars_onQ)++;
return (-3);
/* if the character is 1, 2, or 3 it must be followed by */
/* P, R, C, D, or T */
if (char1 != '0') {
if (char2 < 0)
return (char2);
(*chars_onQ)++;
return (-3);
}
/* read X and Y coordinates of the mouse */
for (j = 0; j < 2; j++) {
if (c1 < 0)
return (c1);
(*chars_onQ)++;
if (j == 0)
else
if (c2 < 0)
return (c2);
(*chars_onQ)++;
if (j == 0)
else
} else
return (-3);
} else
return (-3);
}
/* read complete mouse event: update the Mouse_status structure */
MOUSE_X_POS = mx;
MOUSE_Y_POS = my;
j = char1 - '0';
if (j != 0) {
switch (char2) {
case 'P':
BUTTON_STATUS(j) = BUTTON_PRESSED;
break;
case 'R':
BUTTON_STATUS(j) = BUTTON_RELEASED;
break;
case 'C':
BUTTON_STATUS(j) = BUTTON_CLICKED;
break;
case 'D':
break;
case 'T':
break;
}
}
return (j);
}
/* SS-mouse-end */
/*
* Fast peek key. Like getchar but if the right flags are set, times out
* quickly if there is nothing waiting, returning -1.
* f is an output stdio descriptor, we read from the fileno.
* We wait for long enough for a terminal to send another character
* (at 15cps repeat rate, this is 67 ms, I'm using 100ms to allow
* a bit of a fudge factor) and time out more quickly.
* -2 is returned if we time out, -1 is returned if interrupted, and the
* character is returned otherwise.
*/
#ifndef FIONREAD
/*
* Traditional implementation. The best resolution we have is 1 second,
* so we set a 1 second alarm and try to read. If we fail for 1 second,
* we assume there is no key waiting. Problem here is that 1 second is
* too long; people can type faster than this.
*
* after each read does not work because the tty driver's timeout
* mechanism is too unreliable when the timeouts are changed too quickly.
*/
static char sig_caught;
static
#ifdef SIGPOLL /* Vr3 and beyond */
void
#endif /* SIGPOLL */
/* The following line causes a lint warning for "dummy" which is not used. */
{
sig_caught = 1;
}
static int
_fpk(void)
{
unsigned char c;
#ifdef SIGPOLL /* Vr3 and beyond */
void (*oldsig)(int);
#else /* SIGPOLL */
int (*oldsig)(int);
#endif /* SIGPOLL */
/* turn off any user alarms and set our own */
sig_caught = 0;
(void) alarm(1);
(void) alarm(0);
/*
* This code is to take care of the possibility of
* the process getting swapped out in the middle of
* read() call above. The interrupt will cause the
* read() call to retur, even if a character is really
* on the clist. So we do a non-blocking read() to make
* sure that there really isn't a character there.
*/
else {
#include <fcntl.h>
}
/* restore the user alarms */
oldalarm--;
return (c);
else
if (sig_caught) /* timed out */
return (-2);
else /* EOF or got interrupted */
return (-1);
}
#else /* FIONREAD */
/*
* If we have the select system call, we can do much better than the
* traditional method. Even if we don't have the real 4.2BSD select, we
* can emulate it with napms and FIONREAD. napms might be done with only
* 1 second resolution, but this is no worse than what we have in the
* traditional implementation.
*/
static
_fpk()
{
unsigned char c;
struct timeval t;
t.tv_sec = 0;
if (rc < 0)
return (-2);
}
#endif /* FIONREAD */
/*
* Plain peekchar function. Nothing fancy. This is just like _fpk
* but will wait forever rather than time out.
*/
static int
_pk(void)
{
unsigned char c;
}
/*
* SS-mouse: check if this mouse button event should map into
* function key
*/
static void
{
int i;
/* first determine if this mouse button event should be */
/* mapped into function key */
if (!(SP->_map_mbe_to_key &
return;
for (i = 0; i < num; i++) {
break;
continue;
break;
}
}