]>
Commit | Line | Data |
---|---|---|
1 | /* UI_FILE - a generic STDIO like output stream. | |
2 | Copyright (C) 1999-2000, 2007-2012 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 | ||
22 | struct obstack; | |
23 | struct ui_file; | |
24 | ||
25 | /* Create a generic ui_file object with null methods. */ | |
26 | ||
27 | extern struct ui_file *ui_file_new (void); | |
28 | ||
29 | /* Override methods used by specific implementations of a UI_FILE | |
30 | object. */ | |
31 | ||
32 | typedef void (ui_file_flush_ftype) (struct ui_file *stream); | |
33 | extern void set_ui_file_flush (struct ui_file *stream, | |
34 | ui_file_flush_ftype *flush); | |
35 | ||
36 | /* NOTE: Both fputs and write methods are available. Default | |
37 | implementations that mapping one onto the other are included. */ | |
38 | typedef void (ui_file_write_ftype) (struct ui_file *stream, | |
39 | const char *buf, long length_buf); | |
40 | extern void set_ui_file_write (struct ui_file *stream, | |
41 | ui_file_write_ftype *fputs); | |
42 | ||
43 | typedef void (ui_file_fputs_ftype) (const char *, struct ui_file *stream); | |
44 | extern void set_ui_file_fputs (struct ui_file *stream, | |
45 | ui_file_fputs_ftype *fputs); | |
46 | ||
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. */ | |
53 | typedef void (ui_file_write_async_safe_ftype) | |
54 | (struct ui_file *stream, const char *buf, long length_buf); | |
55 | extern void set_ui_file_write_async_safe | |
56 | (struct ui_file *stream, ui_file_write_async_safe_ftype *write_async_safe); | |
57 | ||
58 | typedef long (ui_file_read_ftype) (struct ui_file *stream, | |
59 | char *buf, long length_buf); | |
60 | extern void set_ui_file_read (struct ui_file *stream, | |
61 | ui_file_read_ftype *fread); | |
62 | ||
63 | typedef int (ui_file_isatty_ftype) (struct ui_file *stream); | |
64 | extern void set_ui_file_isatty (struct ui_file *stream, | |
65 | ui_file_isatty_ftype *isatty); | |
66 | ||
67 | typedef void (ui_file_rewind_ftype) (struct ui_file *stream); | |
68 | extern void set_ui_file_rewind (struct ui_file *stream, | |
69 | ui_file_rewind_ftype *rewind); | |
70 | ||
71 | typedef void (ui_file_put_method_ftype) (void *object, const char *buffer, | |
72 | long length_buffer); | |
73 | typedef void (ui_file_put_ftype) (struct ui_file *stream, | |
74 | ui_file_put_method_ftype *method, | |
75 | void *context); | |
76 | extern void set_ui_file_put (struct ui_file *stream, ui_file_put_ftype *put); | |
77 | ||
78 | typedef void (ui_file_delete_ftype) (struct ui_file * stream); | |
79 | extern void set_ui_file_data (struct ui_file *stream, void *data, | |
80 | ui_file_delete_ftype *delete); | |
81 | ||
82 | extern void *ui_file_data (struct ui_file *file); | |
83 | ||
84 | ||
85 | extern void gdb_flush (struct ui_file *); | |
86 | ||
87 | extern void ui_file_delete (struct ui_file *stream); | |
88 | ||
89 | extern void ui_file_rewind (struct ui_file *stream); | |
90 | ||
91 | extern int ui_file_isatty (struct ui_file *); | |
92 | ||
93 | extern void ui_file_write (struct ui_file *file, const char *buf, | |
94 | long length_buf); | |
95 | ||
96 | extern void ui_file_write_async_safe (struct ui_file *file, const char *buf, | |
97 | long length_buf); | |
98 | ||
99 | /* NOTE: copies left to right. */ | |
100 | extern void ui_file_put (struct ui_file *src, | |
101 | ui_file_put_method_ftype *write, void *dest); | |
102 | ||
103 | /* Returns a freshly allocated buffer containing the entire contents | |
104 | of FILE (as determined by ui_file_put()) with a NUL character | |
105 | appended. LENGTH, if not NULL, is set to the size of the buffer | |
106 | minus that appended NUL. */ | |
107 | extern char *ui_file_xstrdup (struct ui_file *file, long *length); | |
108 | ||
109 | /* Similar to ui_file_xstrdup, but return a new string allocated on | |
110 | OBSTACK. */ | |
111 | extern char *ui_file_obsavestring (struct ui_file *file, | |
112 | struct obstack *obstack, long *length); | |
113 | ||
114 | extern long ui_file_read (struct ui_file *file, char *buf, long length_buf); | |
115 | ||
116 | /* Create/open a memory based file. Can be used as a scratch buffer | |
117 | for collecting output. */ | |
118 | extern struct ui_file *mem_fileopen (void); | |
119 | ||
120 | ||
121 | ||
122 | /* Open/create a STDIO based UI_FILE using the already open FILE. */ | |
123 | extern struct ui_file *stdio_fileopen (FILE *file); | |
124 | ||
125 | /* Open NAME returning an STDIO based UI_FILE. */ | |
126 | extern struct ui_file *gdb_fopen (char *name, char *mode); | |
127 | ||
128 | /* Create a file which writes to both ONE and TWO. CLOSE_ONE | |
129 | and CLOSE_TWO indicate whether the original files should be | |
130 | closed when the new file is closed. */ | |
131 | struct ui_file *tee_file_new (struct ui_file *one, | |
132 | int close_one, | |
133 | struct ui_file *two, | |
134 | int close_two); | |
135 | #endif |