blob: aa841020c6d34174ecf1021f96353d75ea074980 [file] [log] [blame]
Jari Aalto726f6381996-08-26 18:22:31 +00001/* input.h -- Structures and unions used for reading input. */
2/* Copyright (C) 1993 Free Software Foundation, Inc.
3
4 This file is part of GNU Bash, the Bourne Again SHell.
5
6 Bash is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with Bash; see the file COPYING. If not, write to the Free Software
Jari Aaltobb706242000-03-17 21:46:59 +000018 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
Jari Aalto726f6381996-08-26 18:22:31 +000019
Jari Aaltoccc6cda1996-12-23 17:02:34 +000020#if !defined (_INPUT_H_)
21#define _INPUT_H_
Jari Aalto726f6381996-08-26 18:22:31 +000022
23#include "stdc.h"
24
25/* Function pointers can be declared as (Function *)foo. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +000026#if !defined (_FUNCTION_DEF)
27# define _FUNCTION_DEF
Jari Aalto726f6381996-08-26 18:22:31 +000028typedef int Function ();
29typedef void VFunction ();
Jari Aaltof73dda02001-11-13 17:56:06 +000030typedef char *CPFunction (); /* no longer used */
31typedef char **CPPFunction (); /* no longer used */
Jari Aalto726f6381996-08-26 18:22:31 +000032#endif /* _FUNCTION_DEF */
33
Jari Aaltof73dda02001-11-13 17:56:06 +000034typedef int sh_cget_func_t __P((void)); /* sh_ivoidfunc_t */
35typedef int sh_cunget_func_t __P((int)); /* sh_intfunc_t */
36
Jari Aaltoccc6cda1996-12-23 17:02:34 +000037enum stream_type {st_none, st_stdin, st_stream, st_string, st_bstream};
Jari Aalto726f6381996-08-26 18:22:31 +000038
39#if defined (BUFFERED_INPUT)
Jari Aalto726f6381996-08-26 18:22:31 +000040
41/* Possible values for b_flag. */
Jari Aaltocce855b1998-04-17 19:52:44 +000042#undef B_EOF
43#undef B_ERROR /* There are some systems with this define */
44#undef B_UNBUFF
45
Jari Aalto28ef6c32001-04-06 19:14:31 +000046#define B_EOF 0x01
47#define B_ERROR 0x02
48#define B_UNBUFF 0x04
49#define B_WASBASHINPUT 0x08
Jari Aalto726f6381996-08-26 18:22:31 +000050
51/* A buffered stream. Like a FILE *, but with our own buffering and
52 synchronization. Look in input.c for the implementation. */
53typedef struct BSTREAM
54{
Jari Aaltof73dda02001-11-13 17:56:06 +000055 int b_fd;
Jari Aalto726f6381996-08-26 18:22:31 +000056 char *b_buffer; /* The buffer that holds characters read. */
Jari Aaltocce855b1998-04-17 19:52:44 +000057 size_t b_size; /* How big the buffer is. */
Jari Aaltof73dda02001-11-13 17:56:06 +000058 size_t b_used; /* How much of the buffer we're using, */
59 int b_flag; /* Flag values. */
60 size_t b_inputp; /* The input pointer, index into b_buffer. */
Jari Aalto726f6381996-08-26 18:22:31 +000061} BUFFERED_STREAM;
62
Jari Aaltocce855b1998-04-17 19:52:44 +000063#if 0
Jari Aalto726f6381996-08-26 18:22:31 +000064extern BUFFERED_STREAM **buffers;
Jari Aaltocce855b1998-04-17 19:52:44 +000065#endif
Jari Aalto726f6381996-08-26 18:22:31 +000066
67extern int default_buffered_input;
68
69#endif /* BUFFERED_INPUT */
70
71typedef union {
72 FILE *file;
73 char *string;
74#if defined (BUFFERED_INPUT)
75 int buffered_fd;
76#endif
77} INPUT_STREAM;
78
79typedef struct {
Jari Aaltoccc6cda1996-12-23 17:02:34 +000080 enum stream_type type;
Jari Aalto726f6381996-08-26 18:22:31 +000081 char *name;
82 INPUT_STREAM location;
Jari Aaltof73dda02001-11-13 17:56:06 +000083 sh_cget_func_t *getter;
84 sh_cunget_func_t *ungetter;
Jari Aalto726f6381996-08-26 18:22:31 +000085} BASH_INPUT;
86
87extern BASH_INPUT bash_input;
88
Jari Aalto7117c2d2002-07-17 14:10:11 +000089/* Functions from parse.y whose use directly or indirectly depends on the
90 definitions in this file. */
Jari Aalto726f6381996-08-26 18:22:31 +000091extern void initialize_bash_input __P((void));
Jari Aaltof73dda02001-11-13 17:56:06 +000092extern 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 +000093extern char *yy_input_name __P((void));
Jari Aalto726f6381996-08-26 18:22:31 +000094extern void with_input_from_stdin __P((void));
Jari Aaltof73dda02001-11-13 17:56:06 +000095extern void with_input_from_string __P((char *, const char *));
96extern void with_input_from_stream __P((FILE *, const char *));
Jari Aaltoccc6cda1996-12-23 17:02:34 +000097extern void push_stream __P((int));
98extern void pop_stream __P((void));
99extern int stream_on_stack __P((enum stream_type));
Jari Aalto726f6381996-08-26 18:22:31 +0000100extern char *read_secondary_line __P((int));
101extern int find_reserved_word __P((char *));
Jari Aalto726f6381996-08-26 18:22:31 +0000102extern void gather_here_documents __P((void));
Jari Aalto06285672006-10-10 14:15:34 +0000103extern void execute_variable_command __P((char *, char *));
Jari Aalto726f6381996-08-26 18:22:31 +0000104
Jari Aaltobb706242000-03-17 21:46:59 +0000105extern int *save_token_state __P((void));
106extern void restore_token_state __P((int *));
107
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000108/* Functions from input.c */
Jari Aaltof73dda02001-11-13 17:56:06 +0000109extern int getc_with_restart __P((FILE *));
110extern int ungetc_with_restart __P((int, FILE *));
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000111
Jari Aalto726f6381996-08-26 18:22:31 +0000112#if defined (BUFFERED_INPUT)
113/* Functions from input.c. */
Jari Aalto28ef6c32001-04-06 19:14:31 +0000114extern int fd_is_bash_input __P((int));
115extern int set_bash_input_fd __P((int));
116extern int save_bash_input __P((int, int));
Jari Aalto726f6381996-08-26 18:22:31 +0000117extern int check_bash_input __P((int));
118extern int duplicate_buffered_stream __P((int, int));
119extern BUFFERED_STREAM *fd_to_buffered_stream __P((int));
Jari Aaltocce855b1998-04-17 19:52:44 +0000120extern BUFFERED_STREAM *set_buffered_stream __P((int, BUFFERED_STREAM *));
Jari Aalto726f6381996-08-26 18:22:31 +0000121extern BUFFERED_STREAM *open_buffered_stream __P((char *));
122extern void free_buffered_stream __P((BUFFERED_STREAM *));
123extern int close_buffered_stream __P((BUFFERED_STREAM *));
124extern int close_buffered_fd __P((int));
125extern int sync_buffered_stream __P((int));
126extern int buffered_getchar __P((void));
127extern int buffered_ungetchar __P((int));
128extern void with_input_from_buffered_stream __P((int, char *));
129#endif /* BUFFERED_INPUT */
130
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000131#endif /* _INPUT_H_ */