void init_input(file_name, given_name)

- initializes the input module String file_name; String given_name;

String input_location()

- returns the current file name and line number

void debug_in(b)

- turns debug flag ON/OFF Bool b;

void print_stream(file, s)

- prints s on file, only for debugging FILE *file; Stream *s;

void print_input()

- prints current input streams, only for debugging

Bool is_end_of_stream(ch)

- checks whether ch is end of current stream

input_location() returns a string containing the current filename and line number. If the second argument of init_input() is not the empty string then instead of the current filename input_location() returns the second parameter of init_input() as idebtification. The string is in the format `` line :'', and is used in error-reports. The function debug_in() sets the debug flag for the input manager to b.
is_end_of_stream() checks whether ch is the end of the current stream. This is ch equals -1 for a file stream, ch equals 0 for each other stream.

Bool file_input(file_name)

- gets input from file file_name String file_name;

void string_input(string)

- gets input from string string String string;

void token_input(name, tokens, values)

- gets input from tokens, values String name; int *tokens; int *values;

These functions tell the input manager to take input from different streams. When that input stream reaches its end, input is taken from the previous stream. The input can be regarded as a stream of symbols. In the current situation, there are three types of streams; a file-stream, a token-stream, a string-stream. These streams are defined and implemented respectively in the modules file_in, token_in, str_in. In a file_stream and a string_stream the symbols are characters, in a token_stream they are tokens. A new stream implementation X must define the following functions:
.TS
l l.
int	X_next_ch()
int	X_current_ch()
void	X_pushback_ch(int l)
X	new_X_stream()
void	delete_X_stream(X x)
.TE

file_input() tells the input manager, that input is read from the file named file_name. It tries to open the file. If the file can not be opened, FALSE is returned and the call is ignored. If the file can be opened, it will become the current input stream and TRUE is returned.
string_input() makes str the current input stream.
token_input() makes {tokens, values} the current input stream. For an explanation of a token-stream, see the module token_in. The name parameter is the name of the token_input. It tells where the token input comes from.

void entity_input(name, tokens, values)

- next input is from entity String name; int *tokens; int *values;

This function tells the input manager that the input is taken from an entity from now on. The name is the name of the entity, tokens only contains the entity end delimiter (Ee), and values equals zero. After calling this function, one or more of the three functions above are called to put the contents of the entity in the input stream.

void pushback_ch(l)

- pushes back l characters(symbols) int l;

int next_ch()

- returns next character(symbol)

void done_ch()

- all characters(symbols) read until now are matched

int current_ch()

- returns current character(symbol)

int current_ch_value()

- returns value of current character(symbol)

This module is used by the lexical analyser to obtain characters from the current input stream. Whenever the lexical analyser has to deliver a new token, it tries to match the characters in the input stream with each of the delimiters allowed in the current recognition mode. To match a delimiter, the lexical analyser calls next_ch() one or more times to find out whether the characters in the input stream match the delimiter. If the delimiter does not match, pushback_ch() is called to put the characters, returned by next_ch(), back on the input stream. When a delimiter is found, the lexical analyser calls done_ch(), to tell the input manager that the read characters are matched and thus can be discarded.
next_ch() delivers the next character in the current input stream. If the end of the current input stream is reached, characters are taken from the previous input stream. If there is no previous input stream, then EOF is returned. No streams will be closed, because pushback_ch() may be needed for old streams.
pushback_ch() pushes l characters back on the input stream, so they will be delivered again by next_ch(). The maximum number of characters that can be pushed back equals the number of times next_ch() is called since the last call to done_ch().
When done_ch() is called, this means that the characters that are read, are matched with some delimiter or token in the lexical analyser. The characters read so far will not be pushed back any more. So all input streams that are ended will be closed and deleted.
The function current_ch() returns the current character, current_ch_value() the value of the current character. After a call to next_ch(), the current character is the one returned by next_ch().

void new_input(stream)

- makes stream the current input stream Stream *stream;

void switch_input(stream)

- makes stream the current input stream Stream *stream;

new_input() makes stream the current input stream. It sets stream in the group of currently opened input streams and calls switch_input(). switch_input() sets the static global variables real_next_ch, real_pushback_ch, real_current_ch, real_current_ch_value to the function corresponding with the type of stream. It also tells the module corresponding to the type of stream what the current stream is.

Stream* new_stream_file(file, name)

- creates a new input stream FILE *file; String name;

Stream* new_stream_entity(name, tokens, values)

- creates a new input stream String name; int *tokens; int *values;

Stream* new_stream_string(string)

- creates a new input stream String string;

Stream* new_stream_token(name, tokens, values)

- creates a new input stream String name; int *tokens; int *values;

void delete_stream(s)

- deletes s Stream *s;

These four functions respectively create input streams of type file, entity, string and token. They are called by file_input(), entity_input(), string_input() and token_input() respectively to allocate memory for the new stream and to initialize the new stream.
delete_stream() deallocates the memory that is used by s. After this, s can not be used any more.

in.c in.h