15796c8dcSSimon Schubert /* UI_FILE - a generic STDIO like output stream. 2*cf7f2e2dSJohn Marino Copyright (C) 1999, 2000, 2007, 2008, 2009, 2010 3*cf7f2e2dSJohn 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 23*cf7f2e2dSJohn 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); 345796c8dcSSimon Schubert extern void set_ui_file_flush (struct ui_file *stream, ui_file_flush_ftype * flush); 355796c8dcSSimon Schubert 365796c8dcSSimon Schubert /* NOTE: Both fputs and write methods are available. Default 375796c8dcSSimon Schubert implementations that mapping one onto the other are included. */ 385796c8dcSSimon Schubert typedef void (ui_file_write_ftype) (struct ui_file * stream, const char *buf, long length_buf); 395796c8dcSSimon Schubert extern void set_ui_file_write (struct ui_file *stream, ui_file_write_ftype *fputs); 405796c8dcSSimon Schubert 415796c8dcSSimon Schubert typedef void (ui_file_fputs_ftype) (const char *, struct ui_file * stream); 425796c8dcSSimon Schubert extern void set_ui_file_fputs (struct ui_file *stream, ui_file_fputs_ftype * fputs); 435796c8dcSSimon Schubert 445796c8dcSSimon Schubert typedef long (ui_file_read_ftype) (struct ui_file * stream, char *buf, long length_buf); 455796c8dcSSimon Schubert extern void set_ui_file_read (struct ui_file *stream, ui_file_read_ftype *fread); 465796c8dcSSimon Schubert 475796c8dcSSimon Schubert typedef int (ui_file_isatty_ftype) (struct ui_file * stream); 485796c8dcSSimon Schubert extern void set_ui_file_isatty (struct ui_file *stream, ui_file_isatty_ftype * isatty); 495796c8dcSSimon Schubert 505796c8dcSSimon Schubert typedef void (ui_file_rewind_ftype) (struct ui_file * stream); 515796c8dcSSimon Schubert extern void set_ui_file_rewind (struct ui_file *stream, ui_file_rewind_ftype * rewind); 525796c8dcSSimon Schubert 535796c8dcSSimon Schubert typedef void (ui_file_put_method_ftype) (void *object, const char *buffer, long length_buffer); 545796c8dcSSimon Schubert typedef void (ui_file_put_ftype) (struct ui_file *stream, ui_file_put_method_ftype * method, void *context); 555796c8dcSSimon Schubert extern void set_ui_file_put (struct ui_file *stream, ui_file_put_ftype * put); 565796c8dcSSimon Schubert 575796c8dcSSimon Schubert typedef void (ui_file_delete_ftype) (struct ui_file * stream); 585796c8dcSSimon Schubert extern void set_ui_file_data (struct ui_file *stream, void *data, ui_file_delete_ftype * delete); 595796c8dcSSimon Schubert 605796c8dcSSimon Schubert extern void *ui_file_data (struct ui_file *file); 615796c8dcSSimon Schubert 625796c8dcSSimon Schubert 635796c8dcSSimon Schubert extern void gdb_flush (struct ui_file *); 645796c8dcSSimon Schubert 655796c8dcSSimon Schubert extern void ui_file_delete (struct ui_file *stream); 665796c8dcSSimon Schubert 675796c8dcSSimon Schubert extern void ui_file_rewind (struct ui_file *stream); 685796c8dcSSimon Schubert 695796c8dcSSimon Schubert extern int ui_file_isatty (struct ui_file *); 705796c8dcSSimon Schubert 715796c8dcSSimon Schubert extern void ui_file_write (struct ui_file *file, const char *buf, long length_buf); 725796c8dcSSimon Schubert 735796c8dcSSimon Schubert /* NOTE: copies left to right */ 745796c8dcSSimon Schubert extern void ui_file_put (struct ui_file *src, ui_file_put_method_ftype *write, void *dest); 755796c8dcSSimon Schubert 765796c8dcSSimon Schubert /* Returns a freshly allocated buffer containing the entire contents 775796c8dcSSimon Schubert of FILE (as determined by ui_file_put()) with a NUL character 785796c8dcSSimon Schubert appended. LENGTH, if not NULL, is set to the size of the buffer 795796c8dcSSimon Schubert minus that appended NUL. */ 805796c8dcSSimon Schubert extern char *ui_file_xstrdup (struct ui_file *file, long *length); 815796c8dcSSimon Schubert 82*cf7f2e2dSJohn Marino /* Similar to ui_file_xstrdup, but return a new string allocated on 83*cf7f2e2dSJohn Marino OBSTACK. */ 84*cf7f2e2dSJohn Marino extern char *ui_file_obsavestring (struct ui_file *file, 85*cf7f2e2dSJohn Marino struct obstack *obstack, long *length); 865796c8dcSSimon Schubert 875796c8dcSSimon Schubert extern long ui_file_read (struct ui_file *file, char *buf, long length_buf); 885796c8dcSSimon Schubert 895796c8dcSSimon Schubert /* Create/open a memory based file. Can be used as a scratch buffer 905796c8dcSSimon Schubert for collecting output. */ 915796c8dcSSimon Schubert extern struct ui_file *mem_fileopen (void); 925796c8dcSSimon Schubert 935796c8dcSSimon Schubert 945796c8dcSSimon Schubert 955796c8dcSSimon Schubert /* Open/create a an STDIO based UI_FILE using the already open FILE. */ 965796c8dcSSimon Schubert extern struct ui_file *stdio_fileopen (FILE *file); 975796c8dcSSimon Schubert 985796c8dcSSimon Schubert /* Open NAME returning an STDIO based UI_FILE. */ 995796c8dcSSimon Schubert extern struct ui_file *gdb_fopen (char *name, char *mode); 1005796c8dcSSimon Schubert 1015796c8dcSSimon Schubert /* Create a file which writes to both ONE and TWO. CLOSE_ONE 1025796c8dcSSimon Schubert and CLOSE_TWO indicate whether the original files should be 1035796c8dcSSimon Schubert closed when the new file is closed. */ 1045796c8dcSSimon Schubert struct ui_file *tee_file_new (struct ui_file *one, 1055796c8dcSSimon Schubert int close_one, 1065796c8dcSSimon Schubert struct ui_file *two, 1075796c8dcSSimon Schubert int close_two); 1085796c8dcSSimon Schubert #endif 109