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