15796c8dcSSimon Schubert /* UI_FILE - a generic STDIO like output stream. 2*a45ae5f8SJohn Marino Copyright (C) 1999-2000, 2007-2012 Free Software Foundation, Inc. 35796c8dcSSimon Schubert 45796c8dcSSimon Schubert This file is part of GDB. 55796c8dcSSimon Schubert 65796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 75796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 85796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 95796c8dcSSimon Schubert (at your option) any later version. 105796c8dcSSimon Schubert 115796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 125796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 135796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 145796c8dcSSimon Schubert GNU General Public License for more details. 155796c8dcSSimon Schubert 165796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 175796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 185796c8dcSSimon Schubert 195796c8dcSSimon Schubert #ifndef UI_FILE_H 205796c8dcSSimon Schubert #define UI_FILE_H 215796c8dcSSimon Schubert 22cf7f2e2dSJohn Marino struct obstack; 235796c8dcSSimon Schubert struct ui_file; 245796c8dcSSimon Schubert 255796c8dcSSimon Schubert /* Create a generic ui_file object with null methods. */ 265796c8dcSSimon Schubert 275796c8dcSSimon Schubert extern struct ui_file *ui_file_new (void); 285796c8dcSSimon Schubert 295796c8dcSSimon Schubert /* Override methods used by specific implementations of a UI_FILE 305796c8dcSSimon Schubert object. */ 315796c8dcSSimon Schubert 325796c8dcSSimon Schubert typedef void (ui_file_flush_ftype) (struct ui_file *stream); 33c50c785cSJohn Marino extern void set_ui_file_flush (struct ui_file *stream, 34c50c785cSJohn Marino 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. */ 38c50c785cSJohn Marino typedef void (ui_file_write_ftype) (struct ui_file *stream, 39c50c785cSJohn Marino const char *buf, long length_buf); 40c50c785cSJohn Marino extern void set_ui_file_write (struct ui_file *stream, 41c50c785cSJohn Marino ui_file_write_ftype *fputs); 425796c8dcSSimon Schubert 435796c8dcSSimon Schubert typedef void (ui_file_fputs_ftype) (const char *, struct ui_file *stream); 44c50c785cSJohn Marino extern void set_ui_file_fputs (struct ui_file *stream, 45c50c785cSJohn Marino ui_file_fputs_ftype *fputs); 465796c8dcSSimon Schubert 47*a45ae5f8SJohn Marino /* This version of "write" is safe for use in signal handlers. 48*a45ae5f8SJohn Marino It's not guaranteed that all existing output will have been 49*a45ae5f8SJohn Marino flushed first. 50*a45ae5f8SJohn Marino Implementations are also free to ignore some or all of the request. 51*a45ae5f8SJohn Marino fputs_async is not provided as the async versions are rarely used, 52*a45ae5f8SJohn Marino no point in having both for a rarely used interface. */ 53*a45ae5f8SJohn Marino typedef void (ui_file_write_async_safe_ftype) 54*a45ae5f8SJohn Marino (struct ui_file *stream, const char *buf, long length_buf); 55*a45ae5f8SJohn Marino extern void set_ui_file_write_async_safe 56*a45ae5f8SJohn Marino (struct ui_file *stream, ui_file_write_async_safe_ftype *write_async_safe); 57*a45ae5f8SJohn Marino 58c50c785cSJohn Marino typedef long (ui_file_read_ftype) (struct ui_file *stream, 59c50c785cSJohn Marino char *buf, long length_buf); 60c50c785cSJohn Marino extern void set_ui_file_read (struct ui_file *stream, 61c50c785cSJohn Marino ui_file_read_ftype *fread); 625796c8dcSSimon Schubert 635796c8dcSSimon Schubert typedef int (ui_file_isatty_ftype) (struct ui_file *stream); 64c50c785cSJohn Marino extern void set_ui_file_isatty (struct ui_file *stream, 65c50c785cSJohn Marino ui_file_isatty_ftype *isatty); 665796c8dcSSimon Schubert 675796c8dcSSimon Schubert typedef void (ui_file_rewind_ftype) (struct ui_file *stream); 68c50c785cSJohn Marino extern void set_ui_file_rewind (struct ui_file *stream, 69c50c785cSJohn Marino ui_file_rewind_ftype *rewind); 705796c8dcSSimon Schubert 71c50c785cSJohn Marino typedef void (ui_file_put_method_ftype) (void *object, const char *buffer, 72c50c785cSJohn Marino long length_buffer); 73c50c785cSJohn Marino typedef void (ui_file_put_ftype) (struct ui_file *stream, 74c50c785cSJohn Marino ui_file_put_method_ftype *method, 75c50c785cSJohn Marino void *context); 765796c8dcSSimon Schubert extern void set_ui_file_put (struct ui_file *stream, ui_file_put_ftype *put); 775796c8dcSSimon Schubert 785796c8dcSSimon Schubert typedef void (ui_file_delete_ftype) (struct ui_file * stream); 79c50c785cSJohn Marino extern void set_ui_file_data (struct ui_file *stream, void *data, 80c50c785cSJohn Marino ui_file_delete_ftype *delete); 815796c8dcSSimon Schubert 825796c8dcSSimon Schubert extern void *ui_file_data (struct ui_file *file); 835796c8dcSSimon Schubert 845796c8dcSSimon Schubert 855796c8dcSSimon Schubert extern void gdb_flush (struct ui_file *); 865796c8dcSSimon Schubert 875796c8dcSSimon Schubert extern void ui_file_delete (struct ui_file *stream); 885796c8dcSSimon Schubert 895796c8dcSSimon Schubert extern void ui_file_rewind (struct ui_file *stream); 905796c8dcSSimon Schubert 915796c8dcSSimon Schubert extern int ui_file_isatty (struct ui_file *); 925796c8dcSSimon Schubert 93c50c785cSJohn Marino extern void ui_file_write (struct ui_file *file, const char *buf, 94c50c785cSJohn Marino long length_buf); 955796c8dcSSimon Schubert 96*a45ae5f8SJohn Marino extern void ui_file_write_async_safe (struct ui_file *file, const char *buf, 97*a45ae5f8SJohn Marino long length_buf); 98*a45ae5f8SJohn Marino 99c50c785cSJohn Marino /* NOTE: copies left to right. */ 100c50c785cSJohn Marino extern void ui_file_put (struct ui_file *src, 101c50c785cSJohn Marino ui_file_put_method_ftype *write, void *dest); 1025796c8dcSSimon Schubert 1035796c8dcSSimon Schubert /* Returns a freshly allocated buffer containing the entire contents 1045796c8dcSSimon Schubert of FILE (as determined by ui_file_put()) with a NUL character 1055796c8dcSSimon Schubert appended. LENGTH, if not NULL, is set to the size of the buffer 1065796c8dcSSimon Schubert minus that appended NUL. */ 1075796c8dcSSimon Schubert extern char *ui_file_xstrdup (struct ui_file *file, long *length); 1085796c8dcSSimon Schubert 109cf7f2e2dSJohn Marino /* Similar to ui_file_xstrdup, but return a new string allocated on 110cf7f2e2dSJohn Marino OBSTACK. */ 111cf7f2e2dSJohn Marino extern char *ui_file_obsavestring (struct ui_file *file, 112cf7f2e2dSJohn Marino struct obstack *obstack, long *length); 1135796c8dcSSimon Schubert 1145796c8dcSSimon Schubert extern long ui_file_read (struct ui_file *file, char *buf, long length_buf); 1155796c8dcSSimon Schubert 1165796c8dcSSimon Schubert /* Create/open a memory based file. Can be used as a scratch buffer 1175796c8dcSSimon Schubert for collecting output. */ 1185796c8dcSSimon Schubert extern struct ui_file *mem_fileopen (void); 1195796c8dcSSimon Schubert 1205796c8dcSSimon Schubert 1215796c8dcSSimon Schubert 122c50c785cSJohn Marino /* Open/create a STDIO based UI_FILE using the already open FILE. */ 1235796c8dcSSimon Schubert extern struct ui_file *stdio_fileopen (FILE *file); 1245796c8dcSSimon Schubert 1255796c8dcSSimon Schubert /* Open NAME returning an STDIO based UI_FILE. */ 1265796c8dcSSimon Schubert extern struct ui_file *gdb_fopen (char *name, char *mode); 1275796c8dcSSimon Schubert 1285796c8dcSSimon Schubert /* Create a file which writes to both ONE and TWO. CLOSE_ONE 1295796c8dcSSimon Schubert and CLOSE_TWO indicate whether the original files should be 1305796c8dcSSimon Schubert closed when the new file is closed. */ 1315796c8dcSSimon Schubert struct ui_file *tee_file_new (struct ui_file *one, 1325796c8dcSSimon Schubert int close_one, 1335796c8dcSSimon Schubert struct ui_file *two, 1345796c8dcSSimon Schubert int close_two); 1355796c8dcSSimon Schubert #endif 136