Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 1 | /* input.h -- Structures and unions used for reading input. */ |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 2 | |
| 3 | /* Copyright (C) 1993-2009 Free Software Foundation, Inc. |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 4 | |
| 5 | This file is part of GNU Bash, the Bourne Again SHell. |
| 6 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 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. |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 11 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 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. |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 16 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 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 | */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 20 | |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 21 | #if !defined (_INPUT_H_) |
| 22 | #define _INPUT_H_ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 23 | |
| 24 | #include "stdc.h" |
| 25 | |
| 26 | /* Function pointers can be declared as (Function *)foo. */ |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 27 | #if !defined (_FUNCTION_DEF) |
| 28 | # define _FUNCTION_DEF |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 29 | typedef int Function (); |
| 30 | typedef void VFunction (); |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 31 | typedef char *CPFunction (); /* no longer used */ |
| 32 | typedef char **CPPFunction (); /* no longer used */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 33 | #endif /* _FUNCTION_DEF */ |
| 34 | |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 35 | typedef int sh_cget_func_t __P((void)); /* sh_ivoidfunc_t */ |
| 36 | typedef int sh_cunget_func_t __P((int)); /* sh_intfunc_t */ |
| 37 | |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 38 | enum stream_type {st_none, st_stdin, st_stream, st_string, st_bstream}; |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 39 | |
| 40 | #if defined (BUFFERED_INPUT) |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 41 | |
| 42 | /* Possible values for b_flag. */ |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 43 | #undef B_EOF |
| 44 | #undef B_ERROR /* There are some systems with this define */ |
| 45 | #undef B_UNBUFF |
| 46 | |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 47 | #define B_EOF 0x01 |
| 48 | #define B_ERROR 0x02 |
| 49 | #define B_UNBUFF 0x04 |
| 50 | #define B_WASBASHINPUT 0x08 |
Chet Ramey | 495aee4 | 2011-11-22 19:11:26 -0500 | [diff] [blame] | 51 | #define B_TEXT 0x10 |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 52 | |
| 53 | /* A buffered stream. Like a FILE *, but with our own buffering and |
| 54 | synchronization. Look in input.c for the implementation. */ |
| 55 | typedef struct BSTREAM |
| 56 | { |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 57 | int b_fd; |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 58 | char *b_buffer; /* The buffer that holds characters read. */ |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 59 | size_t b_size; /* How big the buffer is. */ |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 60 | size_t b_used; /* How much of the buffer we're using, */ |
| 61 | int b_flag; /* Flag values. */ |
| 62 | size_t b_inputp; /* The input pointer, index into b_buffer. */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 63 | } BUFFERED_STREAM; |
| 64 | |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 65 | #if 0 |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 66 | extern BUFFERED_STREAM **buffers; |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 67 | #endif |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 68 | |
| 69 | extern int default_buffered_input; |
| 70 | |
| 71 | #endif /* BUFFERED_INPUT */ |
| 72 | |
| 73 | typedef union { |
| 74 | FILE *file; |
| 75 | char *string; |
| 76 | #if defined (BUFFERED_INPUT) |
| 77 | int buffered_fd; |
| 78 | #endif |
| 79 | } INPUT_STREAM; |
| 80 | |
| 81 | typedef struct { |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 82 | enum stream_type type; |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 83 | char *name; |
| 84 | INPUT_STREAM location; |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 85 | sh_cget_func_t *getter; |
| 86 | sh_cunget_func_t *ungetter; |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 87 | } BASH_INPUT; |
| 88 | |
| 89 | extern BASH_INPUT bash_input; |
| 90 | |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 91 | /* Functions from parse.y whose use directly or indirectly depends on the |
| 92 | definitions in this file. */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 93 | extern void initialize_bash_input __P((void)); |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 94 | extern void init_yy_io __P((sh_cget_func_t *, sh_cunget_func_t *, enum stream_type, const char *, INPUT_STREAM)); |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 95 | extern char *yy_input_name __P((void)); |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 96 | extern void with_input_from_stdin __P((void)); |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 97 | extern void with_input_from_string __P((char *, const char *)); |
| 98 | extern void with_input_from_stream __P((FILE *, const char *)); |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 99 | extern void push_stream __P((int)); |
| 100 | extern void pop_stream __P((void)); |
| 101 | extern int stream_on_stack __P((enum stream_type)); |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 102 | extern char *read_secondary_line __P((int)); |
| 103 | extern int find_reserved_word __P((char *)); |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 104 | extern void gather_here_documents __P((void)); |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 105 | extern void execute_variable_command __P((char *, char *)); |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 106 | |
Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 107 | extern int *save_token_state __P((void)); |
| 108 | extern void restore_token_state __P((int *)); |
| 109 | |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 110 | /* Functions from input.c */ |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 111 | extern int getc_with_restart __P((FILE *)); |
| 112 | extern int ungetc_with_restart __P((int, FILE *)); |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 113 | |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 114 | #if defined (BUFFERED_INPUT) |
| 115 | /* Functions from input.c. */ |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 116 | extern int fd_is_bash_input __P((int)); |
| 117 | extern int set_bash_input_fd __P((int)); |
| 118 | extern int save_bash_input __P((int, int)); |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 119 | extern int check_bash_input __P((int)); |
| 120 | extern int duplicate_buffered_stream __P((int, int)); |
| 121 | extern BUFFERED_STREAM *fd_to_buffered_stream __P((int)); |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 122 | extern BUFFERED_STREAM *set_buffered_stream __P((int, BUFFERED_STREAM *)); |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 123 | extern BUFFERED_STREAM *open_buffered_stream __P((char *)); |
| 124 | extern void free_buffered_stream __P((BUFFERED_STREAM *)); |
| 125 | extern int close_buffered_stream __P((BUFFERED_STREAM *)); |
| 126 | extern int close_buffered_fd __P((int)); |
| 127 | extern int sync_buffered_stream __P((int)); |
| 128 | extern int buffered_getchar __P((void)); |
| 129 | extern int buffered_ungetchar __P((int)); |
| 130 | extern void with_input_from_buffered_stream __P((int, char *)); |
| 131 | #endif /* BUFFERED_INPUT */ |
| 132 | |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 133 | #endif /* _INPUT_H_ */ |