Debian Codegraph @

include/mps/private/input-buffer.h

raw
1 /*
2 * This file is part of MPSolve 3.2.2
3 *
4 * Copyright (C) 2001-2020, Dipartimento di Matematica "L. Tonelli", Pisa.
5 * License: http://www.gnu.org/licenses/gpl.html GPL version 3 or higher
6 *
7 * Authors:
8 * Leonardo Robol <[email protected]>
9 */
10
11 #ifndef MPS_INPUT_BUFFER_H_
12 #define MPS_INPUT_BUFFER_H_
13
14 #include <mps/private/system/abstract-input-stream.h>
15
16 /**
17 * @file
18 * @brief Implementation of a buffer for parsing input file for MPSolve.
19 */
20
21 MPS_BEGIN_DECLS
22
23 /**
24 * @brief Default size of the buffer of old lines in the input
25 * buffer instances.
26 */
27 #define MPS_INPUT_BUFFER_HISTORY_DEFAULT_SIZE 2
28
29 /**
30 * @brief Buffer used to parse input files in MPSolve. It can
31 * read a stream line by line.
32 */
33 struct mps_input_buffer {
34 /**
35 * @brief Stream associated with the
36 * mps_input_buffer
37 */
38 mps_abstract_input_stream *stream;
39
40 /**
41 * @brief Pointer the last line read in the
42 * buffer. Another line can be read with
43 * <code>mps_input_buffer_readline()</code>
44 */
45 char *line;
46
47 /**
48 * @brief Number of the last read line, the one that
49 * is stored in line field.
50 */
51 long int line_number;
52
53 /**
54 * @brief Lines that have been read before this.
55 *
56 * The number of lines that are remembered is set
57 * by the variable MPS_INPUT_BUFFER_HISTORY_DEFAULT_SIZE,
58 * but can be overriden by calling
59 * <code>mps_input_buffer_set_history_size()</code>.
60 */
61 char **history;
62
63 /**
64 * @brief Size of the history that is been kept in memory.
65 *
66 * This value should never be modified directly, but can
67 * be tweaked using <code>mps_input_buffer_set_history_size()</code>.
68 */
69 size_t history_size;
70
71 /**
72 * @brief Index of the last line inserted in history.
73 *
74 * This is used internally by the mps_input_buffer to implement
75 * a circular buffer.
76 */
77 int last;
78
79 /**
80 * @brief This is a pointer to the last parsed char in the buffer->line
81 * string.
82 *
83 * It is used by mps_input_buffer_next_token() to determine the last
84 * thing read and if there is the need to read another line.
85 *
86 * As for <code>last</code>, this pointer should never be manually
87 * modified, even if you think that you know what you're doing.
88 */
89 char * last_token;
90 };
91
92 /* Function prototypes */
93 mps_input_buffer *mps_input_buffer_new (mps_abstract_input_stream * stream);
94 int mps_input_buffer_readline (mps_input_buffer * buf);
95 void mps_input_buffer_free (mps_input_buffer * buf);
96 void mps_input_buffer_set_history_size (mps_input_buffer * buf, size_t size);
97 mps_boolean mps_input_buffer_eof (mps_input_buffer * buf);
98 char * mps_input_buffer_next_token (mps_input_buffer * buf);
99
100 MPS_END_DECLS
101
102 #endif /* ifndef MPS_INPUT_BUFFER_H */