#include <stdlib.h>
#include "sgconf.h"
Include dependency graph for sgftoken.hpp:

This graph shows which files directly or indirectly include this file:

Classes | |
| class | t_str_chunk_reader |
| Class for reading string chunks. More... | |
| class | t_dchr_chunk_reader |
| Class for reading quoted strings and storing them in the dynamically allocated memory. More... | |
Defines | |
| #define | MAX_TOKEN 31 |
| #define | NEW_LINE_CHAR '\n' |
| #define | COMMENT_CHAR '#' |
Functions | |
| bool | open_input (char *file_name) |
| Opens the input file and sets the first entry of input_token_buf to '\0' and last_delim to '\0'. | |
| void | close_input () |
| Closes the input stream. | |
| void | read_token () |
| Reads the current token from the file. | |
| unsigned | read_string (char term, char *str, unsigned max_len) |
| Reads characters from 'sg_input_f' until 'term' is encountered. | |
| int | check_token (char *tok) |
| Compares a token given in the argument with the token in input_token_buf. | |
| int | check_long (long *num) |
| Converts the token in input_token_buf to an integer. | |
| int | check_double (double *num) |
| Converts the token in input_token_buf to a real number. | |
Variables | |
| char | input_token_buf [MAX_TOKEN+1] |
| The global buffer for a current token. This buffer is initialized by 'read_token' and used by 'check_token' or some external user. | |
| unsigned long | input_line_number |
The principle of processing the input file in this project is the following. First the input file must be opened using the function 'open_input' from this module. Then the function 'read_token' allows to read a current token from the file, function 'check_token' compares this token with a given one, function 'read_string' reads all characters until a given character is encountered. At the end the input file should be closed using 'close_input'. To read a string by chunks use 'read_by_chunks'. Remark: When reading quoted strings using 'read_string' or 'read_by_chunks' the character '\' is always skipped and the following character is never treated as the quotation. The combinations \ \ (two back slashes) are then translated to '\' (one back slash). Use 'fputs_quoted' to save strings in this format.
| #define COMMENT_CHAR '#' |
| #define MAX_TOKEN 31 |
| #define NEW_LINE_CHAR '\n' |
| int check_double | ( | double * | num | ) |
Converts the token in input_token_buf to a real number.
It returns nonzero if succeded to convert the whole contents of input_token_buf, and 0 otherwise.
| int check_long | ( | long * | num | ) |
Converts the token in input_token_buf to an integer.
It returns nonzero if succeded to convert the whole contents of input_token_buf, and 0 otherwise.
| int check_token | ( | char * | tok | ) |
Compares a token given in the argument with the token in input_token_buf.
It returns nonzero if the tokens are equal and zero otherwise.
| void close_input | ( | ) |
Closes the input stream.
It returns the return value of 'fclose'.
| bool open_input | ( | char * | file_name | ) |
Opens the input file and sets the first entry of input_token_buf to '\0' and last_delim to '\0'.
Read the first token using the function read_token, after that the same values of input_token_buf and last_delim mean EOF (in contrast to the situation before the first run of read_token). This function returns 0 if the operation succeded and nonzero if it failed.
| unsigned read_string | ( | char | term, | |
| char * | str, | |||
| unsigned | max_len | |||
| ) |
Reads characters from 'sg_input_f' until 'term' is encountered.
The first max. 'max_len' characters are written to 'str', other characters are skipped. Unless EOF encounered the terminating character 'term' is written to input_token_buf, else (if EOF encountered) the first entry of input_token_buf is set to zero. last_delim is always set to zero. The function returns the number of characters written to 'str'.
| void read_token | ( | ) |
Reads the current token from the file.
The token is placed in input_token_buf, the delimiter encountered at its end is written to last_delim. The previous values of these buffers are lost. The function follows the rules below:
Thus input_token_buf is empty after this function if and only if the EOF is encountered.
| unsigned long input_line_number |
This global variable stores the current line number, i. e. the number of new-line characters read and transfered to input_token_buf plus one. It is assumed that NL is always a white space character, so it newer appears in input_token_buf. Thus all the characters in input_token_buf belong to one line. The character writter currently to last_delim is not taken into account. The code of the new-line caracter is given by the macro NEW_LINE_CHAR.
| char input_token_buf[MAX_TOKEN+1] |
The global buffer for a current token. This buffer is initialized by 'read_token' and used by 'check_token' or some external user.
1.5.2