15796c8dcSSimon Schubert /* UI_FILE - a generic STDIO like output stream. 2*c50c785cSJohn Marino Copyright (C) 1999, 2000, 2007, 2008, 2009, 2010, 2011 3cf7f2e2dSJohn Marino Free Software Foundation, Inc. 45796c8dcSSimon Schubert 55796c8dcSSimon Schubert This file is part of GDB. 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 85796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 95796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 105796c8dcSSimon Schubert (at your option) any later version. 115796c8dcSSimon Schubert 125796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 135796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 145796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 155796c8dcSSimon Schubert GNU General Public License for more details. 165796c8dcSSimon Schubert 175796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 185796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 195796c8dcSSimon Schubert 205796c8dcSSimon Schubert #ifndef UI_FILE_H 215796c8dcSSimon Schubert #define UI_FILE_H 225796c8dcSSimon Schubert 23cf7f2e2dSJohn Marino struct obstack; 245796c8dcSSimon Schubert struct ui_file; 255796c8dcSSimon Schubert 265796c8dcSSimon Schubert /* Create a generic ui_file object with null methods. */ 275796c8dcSSimon Schubert 285796c8dcSSimon Schubert extern struct ui_file *ui_file_new (void); 295796c8dcSSimon Schubert 305796c8dcSSimon Schubert /* Override methods used by specific implementations of a UI_FILE 315796c8dcSSimon Schubert object. */ 325796c8dcSSimon Schubert 335796c8dcSSimon Schubert typedef void (ui_file_flush_ftype) (struct ui_file *stream); 34*c50c785cSJohn Marino extern void set_ui_file_flush (struct ui_file *stream, 35*c50c785cSJohn Marino ui_file_flush_ftype *flush); 365796c8dcSSimon Schubert 375796c8dcSSimon Schubert /* NOTE: Both fputs and write methods are available. Default 385796c8dcSSimon Schubert implementations that mapping one onto the other are included. */ 39*c50c785cSJohn Marino typedef void (ui_file_write_ftype) (struct ui_file *stream, 40*c50c785cSJohn Marino const char *buf, long length_buf); 41*c50c785cSJohn Marino extern void set_ui_file_write (struct ui_file *stream, 42*c50c785cSJohn Marino ui_file_write_ftype *fputs); 435796c8dcSSimon Schubert 445796c8dcSSimon Schubert typedef void (ui_file_fputs_ftype) (const char *, struct ui_file *stream); 45*c50c785cSJohn Marino extern void set_ui_file_fputs (struct ui_file *stream, 46*c50c785cSJohn Marino ui_file_fputs_ftype *fputs); 475796c8dcSSimon Schubert 48*c50c785cSJohn Marino typedef long (ui_file_read_ftype) (struct ui_file *stream, 49*c50c785cSJohn Marino char *buf, long length_buf); 50*c50c785cSJohn Marino extern void set_ui_file_read (struct ui_file *stream, 51*c50c785cSJohn Marino ui_file_read_ftype *fread); 525796c8dcSSimon Schubert 535796c8dcSSimon Schubert typedef int (ui_file_isatty_ftype) (struct ui_file *stream); 54*c50c785cSJohn Marino extern void set_ui_file_isatty (struct ui_file *stream, 55*c50c785cSJohn Marino ui_file_isatty_ftype *isatty); 565796c8dcSSimon Schubert 575796c8dcSSimon Schubert typedef void (ui_file_rewind_ftype) (struct ui_file *stream); 58*c50c785cSJohn Marino extern void set_ui_file_rewind (struct ui_file *stream, 59*c50c785cSJohn Marino ui_file_rewind_ftype *rewind); 605796c8dcSSimon Schubert 61*c50c785cSJohn Marino typedef void (ui_file_put_method_ftype) (void *object, const char *buffer, 62*c50c785cSJohn Marino long length_buffer); 63*c50c785cSJohn Marino typedef void (ui_file_put_ftype) (struct ui_file *stream, 64*c50c785cSJohn Marino ui_file_put_method_ftype *method, 65*c50c785cSJohn Marino void *context); 665796c8dcSSimon Schubert extern void set_ui_file_put (struct ui_file *stream, ui_file_put_ftype *put); 675796c8dcSSimon Schubert 685796c8dcSSimon Schubert typedef void (ui_file_delete_ftype) (struct ui_file * stream); 69*c50c785cSJohn Marino extern void set_ui_file_data (struct ui_file *stream, void *data, 70*c50c785cSJohn Marino ui_file_delete_ftype *delete); 715796c8dcSSimon Schubert 725796c8dcSSimon Schubert extern void *ui_file_data (struct ui_file *file); 735796c8dcSSimon Schubert 745796c8dcSSimon Schubert 755796c8dcSSimon Schubert extern void gdb_flush (struct ui_file *); 765796c8dcSSimon Schubert 775796c8dcSSimon Schubert extern void ui_file_delete (struct ui_file *stream); 785796c8dcSSimon Schubert 795796c8dcSSimon Schubert extern void ui_file_rewind (struct ui_file *stream); 805796c8dcSSimon Schubert 815796c8dcSSimon Schubert extern int ui_file_isatty (struct ui_file *); 825796c8dcSSimon Schubert 83*c50c785cSJohn Marino extern void ui_file_write (struct ui_file *file, const char *buf, 84*c50c785cSJohn Marino long length_buf); 855796c8dcSSimon Schubert 86*c50c785cSJohn Marino /* NOTE: copies left to right. */ 87*c50c785cSJohn Marino extern void ui_file_put (struct ui_file *src, 88*c50c785cSJohn Marino ui_file_put_method_ftype *write, void *dest); 895796c8dcSSimon Schubert 905796c8dcSSimon Schubert /* Returns a freshly allocated buffer containing the entire contents 915796c8dcSSimon Schubert of FILE (as determined by ui_file_put()) with a NUL character 925796c8dcSSimon Schubert appended. LENGTH, if not NULL, is set to the size of the buffer 935796c8dcSSimon Schubert minus that appended NUL. */ 945796c8dcSSimon Schubert extern char *ui_file_xstrdup (struct ui_file *file, long *length); 955796c8dcSSimon Schubert 96cf7f2e2dSJohn Marino /* Similar to ui_file_xstrdup, but return a new string allocated on 97cf7f2e2dSJohn Marino OBSTACK. */ 98cf7f2e2dSJohn Marino extern char *ui_file_obsavestring (struct ui_file *file, 99cf7f2e2dSJohn Marino struct obstack *obstack, long *length); 1005796c8dcSSimon Schubert 1015796c8dcSSimon Schubert extern long ui_file_read (struct ui_file *file, char *buf, long length_buf); 1025796c8dcSSimon Schubert 1035796c8dcSSimon Schubert /* Create/open a memory based file. Can be used as a scratch buffer 1045796c8dcSSimon Schubert for collecting output. */ 1055796c8dcSSimon Schubert extern struct ui_file *mem_fileopen (void); 1065796c8dcSSimon Schubert 1075796c8dcSSimon Schubert 1085796c8dcSSimon Schubert 109*c50c785cSJohn Marino /* Open/create a STDIO based UI_FILE using the already open FILE. */ 1105796c8dcSSimon Schubert extern struct ui_file *stdio_fileopen (FILE *file); 1115796c8dcSSimon Schubert 1125796c8dcSSimon Schubert /* Open NAME returning an STDIO based UI_FILE. */ 1135796c8dcSSimon Schubert extern struct ui_file *gdb_fopen (char *name, char *mode); 1145796c8dcSSimon Schubert 1155796c8dcSSimon Schubert /* Create a file which writes to both ONE and TWO. CLOSE_ONE 1165796c8dcSSimon Schubert and CLOSE_TWO indicate whether the original files should be 1175796c8dcSSimon Schubert closed when the new file is closed. */ 1185796c8dcSSimon Schubert struct ui_file *tee_file_new (struct ui_file *one, 1195796c8dcSSimon Schubert int close_one, 1205796c8dcSSimon Schubert struct ui_file *two, 1215796c8dcSSimon Schubert int close_two); 1225796c8dcSSimon Schubert #endif 123