File: input-buffer.h

package info (click to toggle)
mpsolve 3.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,100 kB
  • sloc: ansic: 25,748; sh: 4,925; cpp: 3,155; makefile: 914; python: 407; yacc: 158; lex: 85; xml: 41
file content (102 lines) | stat: -rw-r--r-- 2,709 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * This file is part of MPSolve 3.2.2
 *
 * Copyright (C) 2001-2020, Dipartimento di Matematica "L. Tonelli", Pisa.
 * License: http://www.gnu.org/licenses/gpl.html GPL version 3 or higher
 *
 * Authors:
 *   Leonardo Robol <leonardo.robol@unipi.it>
 */

#ifndef MPS_INPUT_BUFFER_H_
#define MPS_INPUT_BUFFER_H_

#include <mps/private/system/abstract-input-stream.h>

/**
 * @file
 * @brief Implementation of a buffer for parsing input file for MPSolve.
 */

MPS_BEGIN_DECLS

/**
 * @brief Default size of the buffer of old lines in the input
 * buffer instances.
 */
#define MPS_INPUT_BUFFER_HISTORY_DEFAULT_SIZE 2

/**
 * @brief Buffer used to parse input files in MPSolve. It can
 * read a stream line by line.
 */
struct mps_input_buffer {
  /**
   * @brief Stream associated with the
   * mps_input_buffer
   */
  mps_abstract_input_stream *stream;

  /**
   * @brief Pointer the last line read in the
   * buffer. Another line can be read with
   * <code>mps_input_buffer_readline()</code>
   */
  char *line;

  /**
   * @brief Number of the last read line, the one that
   * is stored in line field.
   */
  long int line_number;

  /**
   * @brief Lines that have been read before this.
   *
   * The number of lines that are remembered is set
   * by the variable MPS_INPUT_BUFFER_HISTORY_DEFAULT_SIZE,
   * but can be overriden by calling
   * <code>mps_input_buffer_set_history_size()</code>.
   */
  char **history;

  /**
   * @brief Size of the history that is been kept in memory.
   *
   * This value should never be modified directly, but can
   * be tweaked using <code>mps_input_buffer_set_history_size()</code>.
   */
  size_t history_size;

  /**
   * @brief Index of the last line inserted in history.
   *
   * This is used internally by the mps_input_buffer to implement
   * a circular buffer.
   */
  int last;

  /**
   * @brief This is a pointer to the last parsed char in the buffer->line
   * string.
   *
   * It is used by mps_input_buffer_next_token() to determine the last
   * thing read and if there is the need to read another line.
   *
   * As for <code>last</code>, this pointer should never be manually
   * modified, even if you think that you know what you're doing.
   */
  char * last_token;
};

/* Function prototypes */
mps_input_buffer *mps_input_buffer_new (mps_abstract_input_stream * stream);
int mps_input_buffer_readline (mps_input_buffer * buf);
void mps_input_buffer_free (mps_input_buffer * buf);
void mps_input_buffer_set_history_size (mps_input_buffer * buf, size_t size);
mps_boolean mps_input_buffer_eof (mps_input_buffer * buf);
char * mps_input_buffer_next_token (mps_input_buffer * buf);

MPS_END_DECLS

#endif /* ifndef MPS_INPUT_BUFFER_H */