Imported from ../bash-2.0.tar.gz.
[platform/upstream/bash.git] / input.h
1 /* 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
18    Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #if !defined (_INPUT_H_)
21 #define _INPUT_H_
22
23 #include "stdc.h"
24
25 /* Function pointers can be declared as (Function *)foo. */
26 #if !defined (_FUNCTION_DEF)
27 #  define _FUNCTION_DEF
28 typedef int Function ();
29 typedef void VFunction ();
30 typedef char *CPFunction ();
31 typedef char **CPPFunction ();
32 #endif /* _FUNCTION_DEF */
33
34 enum stream_type {st_none, st_stdin, st_stream, st_string, st_bstream};
35
36 #if defined (BUFFERED_INPUT)
37
38 /* Possible values for b_flag. */
39 #define B_EOF           0x1
40 #define B_ERROR         0x2
41 #define B_UNBUFF        0x4
42
43 /* A buffered stream.  Like a FILE *, but with our own buffering and
44    synchronization.  Look in input.c for the implementation. */
45 typedef struct BSTREAM
46 {
47   int   b_fd;
48   char  *b_buffer;              /* The buffer that holds characters read. */
49   int   b_size;                 /* How big the buffer is. */
50   int   b_used;                 /* How much of the buffer we're using, */
51   int   b_flag;                 /* Flag values. */
52   int   b_inputp;               /* The input pointer, index into b_buffer. */
53 } BUFFERED_STREAM;
54
55 extern BUFFERED_STREAM **buffers;
56
57 extern BUFFERED_STREAM *fd_to_buffered_stream ();
58
59 extern int default_buffered_input;
60
61 #endif /* BUFFERED_INPUT */
62
63 typedef union {
64   FILE *file;
65   char *string;
66 #if defined (BUFFERED_INPUT)
67   int buffered_fd;
68 #endif
69 } INPUT_STREAM;
70
71 typedef struct {
72   enum stream_type type;
73   char *name;
74   INPUT_STREAM location;
75   Function *getter;
76   Function *ungetter;
77 } BASH_INPUT;
78
79 extern BASH_INPUT bash_input;
80
81 /* Functions from parse.y. */
82 extern void initialize_bash_input __P((void));
83 extern void init_yy_io __P((Function *, Function *, int, char *, INPUT_STREAM));
84 extern void with_input_from_stdin __P((void));
85 extern void with_input_from_string __P((char *, char *));
86 extern void with_input_from_stream __P((FILE *, char *));
87 extern void push_stream __P((int));
88 extern void pop_stream __P((void));
89 extern int stream_on_stack __P((enum stream_type));
90 extern char *read_secondary_line __P((int));
91 extern int find_reserved_word __P((char *));
92 extern char *decode_prompt_string __P((char *));
93 extern void gather_here_documents __P((void));
94 extern void execute_prompt_command __P((char *));
95
96 /* Functions from input.c */
97 extern int getc_with_restart ();
98 extern int ungetc_with_restart ();
99
100 #if defined (BUFFERED_INPUT)
101 /* Functions from input.c. */
102 extern int check_bash_input __P((int));
103 extern int duplicate_buffered_stream __P((int, int));
104 extern BUFFERED_STREAM *fd_to_buffered_stream __P((int));
105 extern BUFFERED_STREAM *open_buffered_stream __P((char *));
106 extern void free_buffered_stream __P((BUFFERED_STREAM *));
107 extern int close_buffered_stream __P((BUFFERED_STREAM *));
108 extern int close_buffered_fd __P((int));
109 extern int sync_buffered_stream __P((int));
110 extern int buffered_getchar __P((void));
111 extern int buffered_ungetchar __P((int));
112 extern void with_input_from_buffered_stream __P((int, char *));
113 #endif /* BUFFERED_INPUT */
114
115 #endif /* _INPUT_H_ */