15796c8dcSSimon Schubert /* UI_FILE - a generic STDIO like output stream. 2*ef5ccd6cSJohn Marino Copyright (C) 1999-2013 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 47a45ae5f8SJohn Marino /* This version of "write" is safe for use in signal handlers. 48a45ae5f8SJohn Marino It's not guaranteed that all existing output will have been 49a45ae5f8SJohn Marino flushed first. 50a45ae5f8SJohn Marino Implementations are also free to ignore some or all of the request. 51a45ae5f8SJohn Marino fputs_async is not provided as the async versions are rarely used, 52a45ae5f8SJohn Marino no point in having both for a rarely used interface. */ 53a45ae5f8SJohn Marino typedef void (ui_file_write_async_safe_ftype) 54a45ae5f8SJohn Marino (struct ui_file *stream, const char *buf, long length_buf); 55a45ae5f8SJohn Marino extern void set_ui_file_write_async_safe 56a45ae5f8SJohn Marino (struct ui_file *stream, ui_file_write_async_safe_ftype *write_async_safe); 57a45ae5f8SJohn 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 82*ef5ccd6cSJohn Marino typedef int (ui_file_fseek_ftype) (struct ui_file *stream, long offset, 83*ef5ccd6cSJohn Marino int whence); 84*ef5ccd6cSJohn Marino extern void set_ui_file_fseek (struct ui_file *stream, 85*ef5ccd6cSJohn Marino ui_file_fseek_ftype *fseek_ptr); 86*ef5ccd6cSJohn Marino 875796c8dcSSimon Schubert extern void *ui_file_data (struct ui_file *file); 885796c8dcSSimon Schubert 895796c8dcSSimon Schubert 905796c8dcSSimon Schubert extern void gdb_flush (struct ui_file *); 915796c8dcSSimon Schubert 925796c8dcSSimon Schubert extern void ui_file_delete (struct ui_file *stream); 935796c8dcSSimon Schubert 945796c8dcSSimon Schubert extern void ui_file_rewind (struct ui_file *stream); 955796c8dcSSimon Schubert 965796c8dcSSimon Schubert extern int ui_file_isatty (struct ui_file *); 975796c8dcSSimon Schubert 98c50c785cSJohn Marino extern void ui_file_write (struct ui_file *file, const char *buf, 99c50c785cSJohn Marino long length_buf); 1005796c8dcSSimon Schubert 101a45ae5f8SJohn Marino extern void ui_file_write_async_safe (struct ui_file *file, const char *buf, 102a45ae5f8SJohn Marino long length_buf); 103a45ae5f8SJohn Marino 104c50c785cSJohn Marino /* NOTE: copies left to right. */ 105c50c785cSJohn Marino extern void ui_file_put (struct ui_file *src, 106c50c785cSJohn Marino ui_file_put_method_ftype *write, void *dest); 1075796c8dcSSimon Schubert 1085796c8dcSSimon Schubert /* Returns a freshly allocated buffer containing the entire contents 1095796c8dcSSimon Schubert of FILE (as determined by ui_file_put()) with a NUL character 1105796c8dcSSimon Schubert appended. LENGTH, if not NULL, is set to the size of the buffer 1115796c8dcSSimon Schubert minus that appended NUL. */ 1125796c8dcSSimon Schubert extern char *ui_file_xstrdup (struct ui_file *file, long *length); 1135796c8dcSSimon Schubert 114cf7f2e2dSJohn Marino /* Similar to ui_file_xstrdup, but return a new string allocated on 115cf7f2e2dSJohn Marino OBSTACK. */ 116cf7f2e2dSJohn Marino extern char *ui_file_obsavestring (struct ui_file *file, 117cf7f2e2dSJohn Marino struct obstack *obstack, long *length); 1185796c8dcSSimon Schubert 1195796c8dcSSimon Schubert extern long ui_file_read (struct ui_file *file, char *buf, long length_buf); 1205796c8dcSSimon Schubert 121*ef5ccd6cSJohn Marino extern int ui_file_fseek (struct ui_file *file, long offset, int whence); 122*ef5ccd6cSJohn Marino 1235796c8dcSSimon Schubert /* Create/open a memory based file. Can be used as a scratch buffer 1245796c8dcSSimon Schubert for collecting output. */ 1255796c8dcSSimon Schubert extern struct ui_file *mem_fileopen (void); 1265796c8dcSSimon Schubert 1275796c8dcSSimon Schubert 1285796c8dcSSimon Schubert 129c50c785cSJohn Marino /* Open/create a STDIO based UI_FILE using the already open FILE. */ 1305796c8dcSSimon Schubert extern struct ui_file *stdio_fileopen (FILE *file); 1315796c8dcSSimon Schubert 1325796c8dcSSimon Schubert /* Open NAME returning an STDIO based UI_FILE. */ 1335796c8dcSSimon Schubert extern struct ui_file *gdb_fopen (char *name, char *mode); 1345796c8dcSSimon Schubert 1355796c8dcSSimon Schubert /* Create a file which writes to both ONE and TWO. CLOSE_ONE 1365796c8dcSSimon Schubert and CLOSE_TWO indicate whether the original files should be 1375796c8dcSSimon Schubert closed when the new file is closed. */ 138*ef5ccd6cSJohn Marino extern struct ui_file *tee_file_new (struct ui_file *one, 1395796c8dcSSimon Schubert int close_one, 1405796c8dcSSimon Schubert struct ui_file *two, 1415796c8dcSSimon Schubert int close_two); 1425796c8dcSSimon Schubert #endif 143