forked from bminor/bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.hh
94 lines (75 loc) · 2.29 KB
/
input.hh
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
/* input.h -- Structures and unions used for reading input. */
/* Copyright (C) 1993-2020 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Bash. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined(_INPUT_H_)
#define _INPUT_H_
#include "bashtypes.hh"
#include <string>
namespace bash
{
enum stream_type
{
st_none,
st_stdin,
st_stream,
st_string,
st_bstream
};
#if defined(BUFFERED_INPUT)
/* Possible values for b_flag. */
enum bstream_flags
{
BST_NOFLAGS = 0,
BST_EOF = 0x01,
BST_ERROR = 0x02,
BST_UNBUFF = 0x04,
BST_WASBASHINPUT = 0x08,
BST_TEXT = 0x10,
BST_SHAREDBUF = 0x20 /* shared input buffer */
};
static inline bstream_flags &
operator|= (bstream_flags &a, const bstream_flags &b)
{
a = static_cast<bstream_flags> (static_cast<uint32_t> (a)
| static_cast<uint32_t> (b));
return a;
}
static inline bstream_flags
operator| (const bstream_flags &a, const bstream_flags &b)
{
return static_cast<bstream_flags> (static_cast<uint32_t> (a)
| static_cast<uint32_t> (b));
}
/* A buffered stream. Like a FILE *, but with our own buffering and
synchronization. Look in input.cc for the implementation. */
struct BUFFERED_STREAM
{
char *b_buffer; /* The buffer that holds characters read. */
size_t b_size; /* How big the buffer is. */
size_t b_used; /* How much of the buffer we're using, */
size_t b_inputp; /* The input pointer, index into b_buffer. */
int b_fd;
bstream_flags b_flag; /* Flag values. */
};
#endif /* BUFFERED_INPUT */
union INPUT_STREAM
{
FILE *file;
char *string;
#if defined(BUFFERED_INPUT)
int buffered_fd;
#endif
};
} // namespace bash
#endif /* _INPUT_H_ */