[SLP-Homepage]
[Source Modules]
[Manual]
[Run]
[Examples]
Interactive Input (From Keyboard)
This module defines a subclass in_kbd_c
of in_c,
which is responsibe for input from the standard input channel
(if SLP is not compiled in CGI-Mode).
Usually this means that the input is directly typed in by the user.
At the moment this module is very simple.
Later I will add the following:
- A test, whether the input really comes from a keyboard.
It might be that it comes from a file via input redirection.
- A small line editor and a history function
(maybe I will use the GNU readline library).
- Different prompts indicating whether SLP waits for a new command
or a continuation of a command in the previous line.
However,
these programming tasks don't have priority.
Initialisation and Closing:
- in_kbd_c:
-
in_kbd_c(void)
;
At the moment, the constructor does nothing
(except remembering that the input is currently open).
- close:
-
bool_t close(void)
;
This method does nothing for keyboard input streams,
except setting is_open
to false.
The method always returns BOOL_TRUE
.
Function for Getting Input:
- read:
-
int read(char *buf, int size)
;
This function prints a prompt
and reads a line of characters into the buffer buf
.
If the line is larger than the buffer size,
only size-1
characters are read.
It is assumed that this seldom happens.
The input buffer should be large enough.
The function returns the number of characters actually read.
As long as this is greater than zero,
everything is ok.
If it is zero,
the end of input was reached.
If an error occurs during input,
this function will print its own error message.
Diagnosis Functions:
- is_open:
-
bool_t is_open(void)
;
This method returns BOOL_TRUE
in all normal circumstances.
Only if close
was explicitly called,
it will return BOOL_FALSE
.
- filename:
-
str_t filename(void)
;
This method currently returns "<stdin>"
.
An alternative (still considered) is STR_NIL
.
Implementation:
Stefan Brass
(sbrass@sis.pitt.edu),
March 18, 2001.
[HTML 3.2 Checked]