blob: 834626ae1af99a0f2e93225bad788365c76cd88e [file] [log] [blame]
Jari Aalto726f6381996-08-26 18:22:31 +00001/* input.h -- Structures and unions used for reading input. */
Jari Aalto31859422009-01-12 13:36:28 +00002
3/* Copyright (C) 1993-2009 Free Software Foundation, Inc.
Jari Aalto726f6381996-08-26 18:22:31 +00004
5 This file is part of GNU Bash, the Bourne Again SHell.
6
Jari Aalto31859422009-01-12 13:36:28 +00007 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 Aalto726f6381996-08-26 18:22:31 +000011
Jari Aalto31859422009-01-12 13:36:28 +000012 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 Aalto726f6381996-08-26 18:22:31 +000016
Jari Aalto31859422009-01-12 13:36:28 +000017 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 Aalto726f6381996-08-26 18:22:31 +000020
Jari Aaltoccc6cda1996-12-23 17:02:34 +000021#if !defined (_INPUT_H_)
22#define _INPUT_H_
Jari Aalto726f6381996-08-26 18:22:31 +000023
24#include "stdc.h"
25
26/* Function pointers can be declared as (Function *)foo. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +000027#if !defined (_FUNCTION_DEF)
28# define _FUNCTION_DEF
Jari Aalto726f6381996-08-26 18:22:31 +000029typedef int Function ();
30typedef void VFunction ();
Jari Aaltof73dda02001-11-13 17:56:06 +000031typedef char *CPFunction (); /* no longer used */
32typedef char **CPPFunction (); /* no longer used */
Jari Aalto726f6381996-08-26 18:22:31 +000033#endif /* _FUNCTION_DEF */
34
Jari Aaltof73dda02001-11-13 17:56:06 +000035typedef int sh_cget_func_t __P((void)); /* sh_ivoidfunc_t */
36typedef int sh_cunget_func_t __P((int)); /* sh_intfunc_t */
37
Jari Aaltoccc6cda1996-12-23 17:02:34 +000038enum stream_type {st_none, st_stdin, st_stream, st_string, st_bstream};
Jari Aalto726f6381996-08-26 18:22:31 +000039
40#if defined (BUFFERED_INPUT)
Jari Aalto726f6381996-08-26 18:22:31 +000041
42/* Possible values for b_flag. */
Jari Aaltocce855b1998-04-17 19:52:44 +000043#undef B_EOF
44#undef B_ERROR /* There are some systems with this define */
45#undef B_UNBUFF
46
Jari Aalto28ef6c32001-04-06 19:14:31 +000047#define B_EOF 0x01
48#define B_ERROR 0x02
49#define B_UNBUFF 0x04
50#define B_WASBASHINPUT 0x08
Jari Aalto726f6381996-08-26 18:22:31 +000051
52/* A buffered stream. Like a FILE *, but with our own buffering and
53 synchronization. Look in input.c for the implementation. */
54typedef struct BSTREAM
55{
Jari Aaltof73dda02001-11-13 17:56:06 +000056 int b_fd;
Jari Aalto726f6381996-08-26 18:22:31 +000057 char *b_buffer; /* The buffer that holds characters read. */
Jari Aaltocce855b1998-04-17 19:52:44 +000058 size_t b_size; /* How big the buffer is. */
Jari Aaltof73dda02001-11-13 17:56:06 +000059 size_t b_used; /* How much of the buffer we're using, */
60 int b_flag; /* Flag values. */
61 size_t b_inputp; /* The input pointer, index into b_buffer. */
Jari Aalto726f6381996-08-26 18:22:31 +000062} BUFFERED_STREAM;
63
Jari Aaltocce855b1998-04-17 19:52:44 +000064#if 0
Jari Aalto726f6381996-08-26 18:22:31 +000065extern BUFFERED_STREAM **buffers;
Jari Aaltocce855b1998-04-17 19:52:44 +000066#endif
Jari Aalto726f6381996-08-26 18:22:31 +000067
68extern int default_buffered_input;
69
70#endif /* BUFFERED_INPUT */
71
72typedef union {
73 FILE *file;
74 char *string;
75#if defined (BUFFERED_INPUT)
76 int buffered_fd;
77#endif
78} INPUT_STREAM;
79
80typedef struct {
Jari Aaltoccc6cda1996-12-23 17:02:34 +000081 enum stream_type type;
Jari Aalto726f6381996-08-26 18:22:31 +000082 char *name;
83 INPUT_STREAM location;
Jari Aaltof73dda02001-11-13 17:56:06 +000084 sh_cget_func_t *getter;
85 sh_cunget_func_t *ungetter;
Jari Aalto726f6381996-08-26 18:22:31 +000086} BASH_INPUT;
87
88extern BASH_INPUT bash_input;
89
Jari Aalto7117c2d2002-07-17 14:10:11 +000090/* Functions from parse.y whose use directly or indirectly depends on the
91 definitions in this file. */
Jari Aalto726f6381996-08-26 18:22:31 +000092extern void initialize_bash_input __P((void));
Jari Aaltof73dda02001-11-13 17:56:06 +000093extern void init_yy_io __P((sh_cget_func_t *, sh_cunget_func_t *, enum stream_type, const char *, INPUT_STREAM));
Jari Aalto7117c2d2002-07-17 14:10:11 +000094extern char *yy_input_name __P((void));
Jari Aalto726f6381996-08-26 18:22:31 +000095extern void with_input_from_stdin __P((void));
Jari Aaltof73dda02001-11-13 17:56:06 +000096extern void with_input_from_string __P((char *, const char *));
97extern void with_input_from_stream __P((FILE *, const char *));
Jari Aaltoccc6cda1996-12-23 17:02:34 +000098extern void push_stream __P((int));
99extern void pop_stream __P((void));
100extern int stream_on_stack __P((enum stream_type));
Jari Aalto726f6381996-08-26 18:22:31 +0000101extern char *read_secondary_line __P((int));
102extern int find_reserved_word __P((char *));
Jari Aalto726f6381996-08-26 18:22:31 +0000103extern void gather_here_documents __P((void));
Jari Aalto06285672006-10-10 14:15:34 +0000104extern void execute_variable_command __P((char *, char *));
Jari Aalto726f6381996-08-26 18:22:31 +0000105
Jari Aaltobb706242000-03-17 21:46:59 +0000106extern int *save_token_state __P((void));
107extern void restore_token_state __P((int *));
108
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000109/* Functions from input.c */
Jari Aaltof73dda02001-11-13 17:56:06 +0000110extern int getc_with_restart __P((FILE *));
111extern int ungetc_with_restart __P((int, FILE *));
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000112
Jari Aalto726f6381996-08-26 18:22:31 +0000113#if defined (BUFFERED_INPUT)
114/* Functions from input.c. */
Jari Aalto28ef6c32001-04-06 19:14:31 +0000115extern int fd_is_bash_input __P((int));
116extern int set_bash_input_fd __P((int));
117extern int save_bash_input __P((int, int));
Jari Aalto726f6381996-08-26 18:22:31 +0000118extern int check_bash_input __P((int));
119extern int duplicate_buffered_stream __P((int, int));
120extern BUFFERED_STREAM *fd_to_buffered_stream __P((int));
Jari Aaltocce855b1998-04-17 19:52:44 +0000121extern BUFFERED_STREAM *set_buffered_stream __P((int, BUFFERED_STREAM *));
Jari Aalto726f6381996-08-26 18:22:31 +0000122extern BUFFERED_STREAM *open_buffered_stream __P((char *));
123extern void free_buffered_stream __P((BUFFERED_STREAM *));
124extern int close_buffered_stream __P((BUFFERED_STREAM *));
125extern int close_buffered_fd __P((int));
126extern int sync_buffered_stream __P((int));
127extern int buffered_getchar __P((void));
128extern int buffered_ungetchar __P((int));
129extern void with_input_from_buffered_stream __P((int, char *));
130#endif /* BUFFERED_INPUT */
131
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000132#endif /* _INPUT_H_ */