1/* UI_FILE - a generic STDIO like output stream.
2   Copyright (C) 1999, 2000, 2007 Free Software Foundation, Inc.
3
4   This file is part of GDB.
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 3 of the License, or
9   (at your option) any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19#ifndef UI_FILE_H
20#define UI_FILE_H
21
22struct ui_file;
23
24/* Create a generic ui_file object with null methods. */
25
26extern struct ui_file *ui_file_new (void);
27
28/* Override methods used by specific implementations of a UI_FILE
29   object. */
30
31typedef void (ui_file_flush_ftype) (struct ui_file * stream);
32extern void set_ui_file_flush (struct ui_file *stream, ui_file_flush_ftype * flush);
33
34/* NOTE: Both fputs and write methods are available. Default
35   implementations that mapping one onto the other are included. */
36typedef void (ui_file_write_ftype) (struct ui_file * stream, const char *buf, long length_buf);
37extern void set_ui_file_write (struct ui_file *stream, ui_file_write_ftype *fputs);
38
39typedef void (ui_file_fputs_ftype) (const char *, struct ui_file * stream);
40extern void set_ui_file_fputs (struct ui_file *stream, ui_file_fputs_ftype * fputs);
41
42typedef long (ui_file_read_ftype) (struct ui_file * stream, char *buf, long length_buf);
43extern void set_ui_file_read (struct ui_file *stream, ui_file_read_ftype *fread);
44
45typedef int (ui_file_isatty_ftype) (struct ui_file * stream);
46extern void set_ui_file_isatty (struct ui_file *stream, ui_file_isatty_ftype * isatty);
47
48typedef void (ui_file_rewind_ftype) (struct ui_file * stream);
49extern void set_ui_file_rewind (struct ui_file *stream, ui_file_rewind_ftype * rewind);
50
51typedef void (ui_file_put_method_ftype) (void *object, const char *buffer, long length_buffer);
52typedef void (ui_file_put_ftype) (struct ui_file *stream, ui_file_put_method_ftype * method, void *context);
53extern void set_ui_file_put (struct ui_file *stream, ui_file_put_ftype * put);
54
55typedef void (ui_file_delete_ftype) (struct ui_file * stream);
56extern void set_ui_file_data (struct ui_file *stream, void *data, ui_file_delete_ftype * delete);
57
58extern void *ui_file_data (struct ui_file *file);
59
60
61extern void gdb_flush (struct ui_file *);
62
63extern void ui_file_delete (struct ui_file *stream);
64
65extern void ui_file_rewind (struct ui_file *stream);
66
67extern int ui_file_isatty (struct ui_file *);
68
69extern void ui_file_write (struct ui_file *file, const char *buf, long length_buf);
70
71/* NOTE: copies left to right */
72extern void ui_file_put (struct ui_file *src, ui_file_put_method_ftype *write, void *dest);
73
74/* Returns a freshly allocated buffer containing the entire contents
75   of FILE (as determined by ui_file_put()) with a NUL character
76   appended.  LENGTH is set to the size of the buffer minus that
77   appended NUL. */
78extern char *ui_file_xstrdup (struct ui_file *file, long *length);
79
80
81
82extern long ui_file_read (struct ui_file *file, char *buf, long length_buf);
83
84/* Create/open a memory based file. Can be used as a scratch buffer
85   for collecting output. */
86extern struct ui_file *mem_fileopen (void);
87
88
89
90/* Open/create a an STDIO based UI_FILE using the already open FILE. */
91extern struct ui_file *stdio_fileopen (FILE *file);
92
93/* Open NAME returning an STDIO based UI_FILE. */
94extern struct ui_file *gdb_fopen (char *name, char *mode);
95
96/* Create a file which writes to both ONE and TWO.  CLOSE_ONE
97   and CLOSE_TWO indicate whether the original files should be
98   closed when the new file is closed.  */
99struct ui_file *tee_file_new (struct ui_file *one,
100			      int close_one,
101			      struct ui_file *two,
102			      int close_two);
103#endif
104