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