]>
Commit | Line | Data |
---|---|---|
726f6388 | 1 | /* input.h -- Structures and unions used for reading input. */ |
3185942a | 2 | |
8868edaf | 3 | /* Copyright (C) 1993-2020 Free Software Foundation, Inc. |
726f6388 JA |
4 | |
5 | This file is part of GNU Bash, the Bourne Again SHell. | |
6 | ||
3185942a JA |
7 | Bash is free software: you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation, either version 3 of the License, or | |
10 | (at your option) any later version. | |
726f6388 | 11 | |
3185942a JA |
12 | Bash is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
726f6388 | 16 | |
3185942a JA |
17 | You should have received a copy of the GNU General Public License |
18 | along with Bash. If not, see <http://www.gnu.org/licenses/>. | |
19 | */ | |
726f6388 | 20 | |
ccc6cda3 JA |
21 | #if !defined (_INPUT_H_) |
22 | #define _INPUT_H_ | |
726f6388 JA |
23 | |
24 | #include "stdc.h" | |
25 | ||
26 | /* Function pointers can be declared as (Function *)foo. */ | |
ccc6cda3 JA |
27 | #if !defined (_FUNCTION_DEF) |
28 | # define _FUNCTION_DEF | |
726f6388 JA |
29 | typedef int Function (); |
30 | typedef void VFunction (); | |
f73dda09 JA |
31 | typedef char *CPFunction (); /* no longer used */ |
32 | typedef char **CPPFunction (); /* no longer used */ | |
726f6388 JA |
33 | #endif /* _FUNCTION_DEF */ |
34 | ||
8868edaf CR |
35 | typedef int sh_cget_func_t PARAMS((void)); /* sh_ivoidfunc_t */ |
36 | typedef int sh_cunget_func_t PARAMS((int)); /* sh_intfunc_t */ | |
f73dda09 | 37 | |
ccc6cda3 | 38 | enum stream_type {st_none, st_stdin, st_stream, st_string, st_bstream}; |
726f6388 JA |
39 | |
40 | #if defined (BUFFERED_INPUT) | |
726f6388 JA |
41 | |
42 | /* Possible values for b_flag. */ | |
cce855bc JA |
43 | #undef B_EOF |
44 | #undef B_ERROR /* There are some systems with this define */ | |
45 | #undef B_UNBUFF | |
46 | ||
28ef6c31 JA |
47 | #define B_EOF 0x01 |
48 | #define B_ERROR 0x02 | |
49 | #define B_UNBUFF 0x04 | |
50 | #define B_WASBASHINPUT 0x08 | |
495aee44 | 51 | #define B_TEXT 0x10 |
d233b485 | 52 | #define B_SHAREDBUF 0x20 /* shared input buffer */ |
726f6388 JA |
53 | |
54 | /* A buffered stream. Like a FILE *, but with our own buffering and | |
55 | synchronization. Look in input.c for the implementation. */ | |
56 | typedef struct BSTREAM | |
57 | { | |
f73dda09 | 58 | int b_fd; |
726f6388 | 59 | char *b_buffer; /* The buffer that holds characters read. */ |
cce855bc | 60 | size_t b_size; /* How big the buffer is. */ |
f73dda09 JA |
61 | size_t b_used; /* How much of the buffer we're using, */ |
62 | int b_flag; /* Flag values. */ | |
63 | size_t b_inputp; /* The input pointer, index into b_buffer. */ | |
726f6388 JA |
64 | } BUFFERED_STREAM; |
65 | ||
cce855bc | 66 | #if 0 |
726f6388 | 67 | extern BUFFERED_STREAM **buffers; |
cce855bc | 68 | #endif |
726f6388 JA |
69 | |
70 | extern int default_buffered_input; | |
d233b485 | 71 | extern int bash_input_fd_changed; |
726f6388 JA |
72 | |
73 | #endif /* BUFFERED_INPUT */ | |
74 | ||
75 | typedef union { | |
76 | FILE *file; | |
77 | char *string; | |
78 | #if defined (BUFFERED_INPUT) | |
79 | int buffered_fd; | |
80 | #endif | |
81 | } INPUT_STREAM; | |
82 | ||
83 | typedef struct { | |
ccc6cda3 | 84 | enum stream_type type; |
726f6388 JA |
85 | char *name; |
86 | INPUT_STREAM location; | |
f73dda09 JA |
87 | sh_cget_func_t *getter; |
88 | sh_cunget_func_t *ungetter; | |
726f6388 JA |
89 | } BASH_INPUT; |
90 | ||
91 | extern BASH_INPUT bash_input; | |
92 | ||
7117c2d2 JA |
93 | /* Functions from parse.y whose use directly or indirectly depends on the |
94 | definitions in this file. */ | |
8868edaf CR |
95 | extern void initialize_bash_input PARAMS((void)); |
96 | extern void init_yy_io PARAMS((sh_cget_func_t *, sh_cunget_func_t *, enum stream_type, const char *, INPUT_STREAM)); | |
97 | extern char *yy_input_name PARAMS((void)); | |
98 | extern void with_input_from_stdin PARAMS((void)); | |
99 | extern void with_input_from_string PARAMS((char *, const char *)); | |
100 | extern void with_input_from_stream PARAMS((FILE *, const char *)); | |
101 | extern void push_stream PARAMS((int)); | |
102 | extern void pop_stream PARAMS((void)); | |
103 | extern int stream_on_stack PARAMS((enum stream_type)); | |
104 | extern char *read_secondary_line PARAMS((int)); | |
105 | extern int find_reserved_word PARAMS((char *)); | |
106 | extern void gather_here_documents PARAMS((void)); | |
107 | extern void execute_variable_command PARAMS((char *, char *)); | |
108 | ||
109 | extern int *save_token_state PARAMS((void)); | |
110 | extern void restore_token_state PARAMS((int *)); | |
bb70624e | 111 | |
ccc6cda3 | 112 | /* Functions from input.c */ |
8868edaf CR |
113 | extern int getc_with_restart PARAMS((FILE *)); |
114 | extern int ungetc_with_restart PARAMS((int, FILE *)); | |
ccc6cda3 | 115 | |
726f6388 JA |
116 | #if defined (BUFFERED_INPUT) |
117 | /* Functions from input.c. */ | |
8868edaf CR |
118 | extern int fd_is_bash_input PARAMS((int)); |
119 | extern int set_bash_input_fd PARAMS((int)); | |
120 | extern int save_bash_input PARAMS((int, int)); | |
121 | extern int check_bash_input PARAMS((int)); | |
122 | extern int duplicate_buffered_stream PARAMS((int, int)); | |
123 | extern BUFFERED_STREAM *fd_to_buffered_stream PARAMS((int)); | |
124 | extern BUFFERED_STREAM *set_buffered_stream PARAMS((int, BUFFERED_STREAM *)); | |
125 | extern BUFFERED_STREAM *open_buffered_stream PARAMS((char *)); | |
126 | extern void free_buffered_stream PARAMS((BUFFERED_STREAM *)); | |
127 | extern int close_buffered_stream PARAMS((BUFFERED_STREAM *)); | |
128 | extern int close_buffered_fd PARAMS((int)); | |
129 | extern int sync_buffered_stream PARAMS((int)); | |
130 | extern int buffered_getchar PARAMS((void)); | |
131 | extern int buffered_ungetchar PARAMS((int)); | |
132 | extern void with_input_from_buffered_stream PARAMS((int, char *)); | |
726f6388 JA |
133 | #endif /* BUFFERED_INPUT */ |
134 | ||
ccc6cda3 | 135 | #endif /* _INPUT_H_ */ |