Initialize the terminal keyboard interface
int SLang_init_tty (int intr_ch, int no_flow_ctrl, int opost)
SLang_init_tty
initializes the terminal for single character
input. If the first parameter intr_ch
is in the range 0-255,
it will be used as the interrupt character, e.g., under Unix this
character will generate a SIGINT
signal. Otherwise, if it is
-1
, the interrupt character will be left unchanged.
If the second parameter no_flow_ctrl
is non-zero, flow control
(XON
/XOFF
) processing will be
enabled.
If the last parmeter opost
is non-zero, output processing by the
terminal will be enabled. If one intends to use this function in
conjunction with the S-Lang screen management routines
(SLsmg
), this paramete shold be set to zero.
SLang_init_tty
returns zero upon success, or -1
upon error.
Terminal I/O is a complex subject. The S-Lang interface presents a
simplification that the author has found useful in practice. For
example, the only special character processing that
SLang_init_tty
enables is that of the SIGINT
character,
and the generation of other signals via the keyboard is disabled.
However, generation of the job control signal SIGTSTP
is possible
via the SLtty_set_suspend_state
function.
Under Unix, the integer variable SLang_TT_Read_FD
is used to
specify the input descriptor for the terminal. If
SLang_TT_Read_FD
represents a terminal device as determined
via the isatty
system call, then it will be used as the
terminal file descriptor. Otherwise, the terminal device
/dev/tty
will used as the input device. The default value of
SLang_TT_Read_FD
is -1
which causes /dev/tty
to be
used. So, if you prefer to use stdin
for input, then set
SLang_TT_Read_FD
to fileno(stdin)
before calling
SLang_init_tty
.
If the variable SLang_TT_Baud_Rate
is zero when this function
is called, the function will attempt to determine the baud rate by
querying the terminal driver and set SLang_TT_Baud_Rate
to
that value.
SLang_reset_tty, SLang_getkey, SLtty_set_suspend_state
Reset the terminal
void SLang_reset_tty (void)
SLang_reset_tty
resets the terminal interface back to the
state it was in before SLang_init_tty
was called.
SLang_init_tty
Enable or disable keyboard suspension
void SLtty_set_suspend_state (int s)
The SLtty_set_suspend_state
function may be used to enable or
disable keyboard generation of the SIGTSTP
job control signal.
If s
is non-zero, generation of this signal via the terminal
interface will be enabled, otherwise it will be disabled.
This function should only be called after the terminal driver has be
initialized via SLang_init_tty
. The SLang_init_tty
always disables the generation of SIGTSTP
via the keyboard.
SLang_init_tty
Read a character from the keyboard
unsigned int SLang_getkey (void);
The SLang_getkey
reads a single character from the terminal
and returns it. The terminal must first be initialized via a call
to SLang_init_tty
before this function can be called. Upon
success, SLang_getkey
returns the character read from the
terminal, otherwise it returns SLANG_GETKEY_ERROR
.
SLang_init_tty, SLang_input_pending, SLang_ungetkey
Unget a key string
int SLang_ungetkey_string (unsigned char *buf, unsigned int n)
The SLang_ungetkey_string
function may be used to push the
n
characters pointed to by buf
onto the buffered input
stream that SLgetkey
uses. If there is not enough room for
the characters, -1
is returned and none are buffered. Otherwise,
it returns zero.
The difference between SLang_buffer_keystring
and
SLang_ungetkey_string
is that the SLang_buffer_keystring
appends the characters to the end of the getkey buffer, whereas
SLang_ungetkey_string
inserts the characters at the beginning
of the input buffer.
SLang_ungetkey, SLang_getkey
Append a keystring to the input buffer
int SLang_buffer_keystring (unsigned char *b, unsigned int len)
SLang_buffer_keystring
places the len
characters
specified by b
at the end of the buffer that
SLang_getkey
uses. Upon success it returns 0; otherwise, no
characters are buffered and it returns -1
.
The difference between SLang_buffer_keystring
and
SLang_ungetkey_string
is that the SLang_buffer_keystring
appends the characters to the end of the getkey buffer, whereas
SLang_ungetkey_string
inserts the characters at the beginning
of the input buffer.
SLang_getkey, SLang_ungetkey, SLang_ungetkey_string
Push a character back onto the input buffer
int SLang_ungetkey (unsigned char ch)
SLang_ungetkey
pushes the character ch
back onto the
SLgetkey
input stream. Upon success, it returns zero,
otherwise it returns 1
.
This function is implemented as:
int SLang_ungetkey (unsigned char ch)
{
return SLang_ungetkey_string(&ch, 1);
}
SLang_getkey, SLang_ungetkey_string
Discard all keyboard input waiting to be read
void SLang_flush_input (void)
SLang_flush_input
discards all input characters waiting to be
read by the SLang_getkey
function.
SLang_getkey
Check to see if input is pending
int SLang_input_pending (int tsecs)
SLang_input_pending
may be used to see if an input character
is available to be read without causing SLang_getkey
to block.
It will wait up to tsecs
tenths of a second if no characters
are immediately available for reading. If tsecs
is less than
zero, then SLang_input_pending
will wait -tsecs
milliseconds for input, otherwise tsecs
represents 1/10
of a second intervals.
Not all systems support millisecond resolution.
SLang_getkey
Set the signal to trap SIGINT
void SLang_set_abort_signal (void (*f)(int));
SLang_set_abort_signal
sets the function that gets
triggered when the user presses the interrupt key (SIGINT
) to
the function f
. If f
is NULL
the default handler
will get installed.
The default interrupt handler on a Unix system is:
static void default_sigint (int sig)
{
SLKeyBoard_Quit = 1;
if (SLang_Ignore_User_Abort == 0) SLang_Error = SL_USER_BREAK;
SLsignal_intr (SIGINT, default_sigint);
}
For Unix programmers, the name of this function may appear
misleading since it is associated with SIGINT
and not
SIGABRT
. The origin of the name stems from the original intent
of the function: to allow the user to abort the running of a S-Lang
interpreter function.
SLang_init_tty, SLsignal_intr