]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/ui-file.h
Make out and error streams be per UI
[thirdparty/binutils-gdb.git] / gdb / ui-file.h
CommitLineData
d9fcf2fb 1/* UI_FILE - a generic STDIO like output stream.
618f726f 2 Copyright (C) 1999-2016 Free Software Foundation, Inc.
d9fcf2fb
JM
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
a9762ec7 8 the Free Software Foundation; either version 3 of the License, or
d9fcf2fb
JM
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
a9762ec7 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
d9fcf2fb
JM
18
19#ifndef UI_FILE_H
20#define UI_FILE_H
21
94af9270 22struct obstack;
d9fcf2fb
JM
23struct ui_file;
24
581e13c1 25/* Create a generic ui_file object with null methods. */
d9fcf2fb
JM
26
27extern struct ui_file *ui_file_new (void);
28
29/* Override methods used by specific implementations of a UI_FILE
581e13c1 30 object. */
d9fcf2fb 31
3e43a32a
MS
32typedef void (ui_file_flush_ftype) (struct ui_file *stream);
33extern void set_ui_file_flush (struct ui_file *stream,
34 ui_file_flush_ftype *flush);
d9fcf2fb 35
581e13c1
MS
36/* NOTE: Both fputs and write methods are available. Default
37 implementations that mapping one onto the other are included. */
3e43a32a
MS
38typedef void (ui_file_write_ftype) (struct ui_file *stream,
39 const char *buf, long length_buf);
40extern void set_ui_file_write (struct ui_file *stream,
41 ui_file_write_ftype *fputs);
42
43typedef void (ui_file_fputs_ftype) (const char *, struct ui_file *stream);
44extern void set_ui_file_fputs (struct ui_file *stream,
45 ui_file_fputs_ftype *fputs);
46
01124a23
DE
47/* This version of "write" is safe for use in signal handlers.
48 It's not guaranteed that all existing output will have been
49 flushed first.
50 Implementations are also free to ignore some or all of the request.
51 fputs_async is not provided as the async versions are rarely used,
52 no point in having both for a rarely used interface. */
53typedef void (ui_file_write_async_safe_ftype)
54 (struct ui_file *stream, const char *buf, long length_buf);
55extern void set_ui_file_write_async_safe
56 (struct ui_file *stream, ui_file_write_async_safe_ftype *write_async_safe);
57
3e43a32a
MS
58typedef long (ui_file_read_ftype) (struct ui_file *stream,
59 char *buf, long length_buf);
60extern void set_ui_file_read (struct ui_file *stream,
61 ui_file_read_ftype *fread);
62
63typedef int (ui_file_isatty_ftype) (struct ui_file *stream);
64extern void set_ui_file_isatty (struct ui_file *stream,
65 ui_file_isatty_ftype *isatty);
66
67typedef void (ui_file_rewind_ftype) (struct ui_file *stream);
68extern void set_ui_file_rewind (struct ui_file *stream,
69 ui_file_rewind_ftype *rewind);
70
71typedef void (ui_file_put_method_ftype) (void *object, const char *buffer,
72 long length_buffer);
73typedef void (ui_file_put_ftype) (struct ui_file *stream,
74 ui_file_put_method_ftype *method,
75 void *context);
76extern void set_ui_file_put (struct ui_file *stream, ui_file_put_ftype *put);
d9fcf2fb
JM
77
78typedef void (ui_file_delete_ftype) (struct ui_file * stream);
3e43a32a 79extern void set_ui_file_data (struct ui_file *stream, void *data,
fe978cb0 80 ui_file_delete_ftype *to_delete);
d9fcf2fb 81
2a9d5ccf
HZ
82typedef int (ui_file_fseek_ftype) (struct ui_file *stream, long offset,
83 int whence);
84extern void set_ui_file_fseek (struct ui_file *stream,
85 ui_file_fseek_ftype *fseek_ptr);
86
d9fcf2fb
JM
87extern void *ui_file_data (struct ui_file *file);
88
89
90extern void gdb_flush (struct ui_file *);
91
92extern void ui_file_delete (struct ui_file *stream);
93
94extern void ui_file_rewind (struct ui_file *stream);
95
96extern int ui_file_isatty (struct ui_file *);
97
3e43a32a
MS
98extern void ui_file_write (struct ui_file *file, const char *buf,
99 long length_buf);
d9fcf2fb 100
de571fc5
TT
101/* A wrapper for ui_file_write that is suitable for use by
102 ui_file_put. */
103
104extern void ui_file_write_for_put (void *data, const char *buffer,
105 long length_buffer);
106
01124a23
DE
107extern void ui_file_write_async_safe (struct ui_file *file, const char *buf,
108 long length_buf);
109
581e13c1 110/* NOTE: copies left to right. */
3e43a32a
MS
111extern void ui_file_put (struct ui_file *src,
112 ui_file_put_method_ftype *write, void *dest);
d9fcf2fb
JM
113
114/* Returns a freshly allocated buffer containing the entire contents
115 of FILE (as determined by ui_file_put()) with a NUL character
759ef836 116 appended. LENGTH, if not NULL, is set to the size of the buffer
581e13c1 117 minus that appended NUL. */
d9fcf2fb
JM
118extern char *ui_file_xstrdup (struct ui_file *file, long *length);
119
94af9270
KS
120/* Similar to ui_file_xstrdup, but return a new string allocated on
121 OBSTACK. */
122extern char *ui_file_obsavestring (struct ui_file *file,
123 struct obstack *obstack, long *length);
d9fcf2fb 124
449092f6
CV
125extern long ui_file_read (struct ui_file *file, char *buf, long length_buf);
126
2a9d5ccf
HZ
127extern int ui_file_fseek (struct ui_file *file, long offset, int whence);
128
581e13c1
MS
129/* Create/open a memory based file. Can be used as a scratch buffer
130 for collecting output. */
d9fcf2fb
JM
131extern struct ui_file *mem_fileopen (void);
132
133
134
766062f6 135/* Open/create a STDIO based UI_FILE using the already open FILE. */
d9fcf2fb
JM
136extern struct ui_file *stdio_fileopen (FILE *file);
137
694ec099
PA
138/* Likewise, for stderr-like streams. */
139extern struct ui_file *stderr_fileopen (FILE *file);
ffa4ac95
YQ
140
141
581e13c1 142/* Open NAME returning an STDIO based UI_FILE. */
23b3a2c3 143extern struct ui_file *gdb_fopen (const char *name, const char *mode);
d9fcf2fb 144
e4c242d9
DJ
145/* Create a file which writes to both ONE and TWO. CLOSE_ONE
146 and CLOSE_TWO indicate whether the original files should be
147 closed when the new file is closed. */
2da6da3b
PM
148extern struct ui_file *tee_file_new (struct ui_file *one,
149 int close_one,
150 struct ui_file *two,
151 int close_two);
d9fcf2fb 152#endif