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