198944Sobrien/* UI_FILE - a generic STDIO like output stream.
298944Sobrien   Copyright 1999, 2000 Free Software Foundation, Inc.
398944Sobrien
498944Sobrien   This file is part of GDB.
598944Sobrien
698944Sobrien   This program is free software; you can redistribute it and/or modify
798944Sobrien   it under the terms of the GNU General Public License as published by
898944Sobrien   the Free Software Foundation; either version 2 of the License, or
998944Sobrien   (at your option) any later version.
1098944Sobrien
1198944Sobrien   This program is distributed in the hope that it will be useful,
1298944Sobrien   but WITHOUT ANY WARRANTY; without even the implied warranty of
1398944Sobrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1498944Sobrien   GNU General Public License for more details.
1598944Sobrien
1698944Sobrien   You should have received a copy of the GNU General Public License
1798944Sobrien   along with this program; if not, write to the Free Software
1898944Sobrien   Foundation, Inc., 59 Temple Place - Suite 330,
1998944Sobrien   Boston, MA 02111-1307, USA.  */
2098944Sobrien
2198944Sobrien#ifndef UI_FILE_H
2298944Sobrien#define UI_FILE_H
2398944Sobrien
2498944Sobrienstruct ui_file;
2598944Sobrien
2698944Sobrien/* Create a generic ui_file object with null methods. */
2798944Sobrien
2898944Sobrienextern struct ui_file *ui_file_new (void);
2998944Sobrien
3098944Sobrien/* Override methods used by specific implementations of a UI_FILE
3198944Sobrien   object. */
3298944Sobrien
3398944Sobrientypedef void (ui_file_flush_ftype) (struct ui_file * stream);
3498944Sobrienextern void set_ui_file_flush (struct ui_file *stream, ui_file_flush_ftype * flush);
3598944Sobrien
3698944Sobrien/* NOTE: Both fputs and write methods are available. Default
3798944Sobrien   implementations that mapping one onto the other are included. */
3898944Sobrientypedef void (ui_file_write_ftype) (struct ui_file * stream, const char *buf, long length_buf);
3998944Sobrienextern void set_ui_file_write (struct ui_file *stream, ui_file_write_ftype *fputs);
4098944Sobrien
4198944Sobrientypedef void (ui_file_fputs_ftype) (const char *, struct ui_file * stream);
4298944Sobrienextern void set_ui_file_fputs (struct ui_file *stream, ui_file_fputs_ftype * fputs);
4398944Sobrien
44130803Smarceltypedef long (ui_file_read_ftype) (struct ui_file * stream, char *buf, long length_buf);
45130803Smarcelextern void set_ui_file_read (struct ui_file *stream, ui_file_read_ftype *fread);
46130803Smarcel
4798944Sobrientypedef int (ui_file_isatty_ftype) (struct ui_file * stream);
4898944Sobrienextern void set_ui_file_isatty (struct ui_file *stream, ui_file_isatty_ftype * isatty);
4998944Sobrien
5098944Sobrientypedef void (ui_file_rewind_ftype) (struct ui_file * stream);
5198944Sobrienextern void set_ui_file_rewind (struct ui_file *stream, ui_file_rewind_ftype * rewind);
5298944Sobrien
5398944Sobrientypedef void (ui_file_put_method_ftype) (void *object, const char *buffer, long length_buffer);
5498944Sobrientypedef void (ui_file_put_ftype) (struct ui_file *stream, ui_file_put_method_ftype * method, void *context);
5598944Sobrienextern void set_ui_file_put (struct ui_file *stream, ui_file_put_ftype * put);
5698944Sobrien
5798944Sobrientypedef void (ui_file_delete_ftype) (struct ui_file * stream);
5898944Sobrienextern void set_ui_file_data (struct ui_file *stream, void *data, ui_file_delete_ftype * delete);
5998944Sobrien
6098944Sobrienextern void *ui_file_data (struct ui_file *file);
6198944Sobrien
6298944Sobrien
6398944Sobrienextern void gdb_flush (struct ui_file *);
6498944Sobrien
6598944Sobrienextern void ui_file_delete (struct ui_file *stream);
6698944Sobrien
6798944Sobrienextern void ui_file_rewind (struct ui_file *stream);
6898944Sobrien
6998944Sobrienextern int ui_file_isatty (struct ui_file *);
7098944Sobrien
7198944Sobrienextern void ui_file_write (struct ui_file *file, const char *buf, long length_buf);
7298944Sobrien
7398944Sobrien/* NOTE: copies left to right */
7498944Sobrienextern void ui_file_put (struct ui_file *src, ui_file_put_method_ftype *write, void *dest);
7598944Sobrien
7698944Sobrien/* Returns a freshly allocated buffer containing the entire contents
7798944Sobrien   of FILE (as determined by ui_file_put()) with a NUL character
7898944Sobrien   appended.  LENGTH is set to the size of the buffer minus that
7998944Sobrien   appended NUL. */
8098944Sobrienextern char *ui_file_xstrdup (struct ui_file *file, long *length);
8198944Sobrien
8298944Sobrien
8398944Sobrien
84130803Smarcelextern long ui_file_read (struct ui_file *file, char *buf, long length_buf);
85130803Smarcel
8698944Sobrien/* Create/open a memory based file. Can be used as a scratch buffer
8798944Sobrien   for collecting output. */
8898944Sobrienextern struct ui_file *mem_fileopen (void);
8998944Sobrien
9098944Sobrien
9198944Sobrien
9298944Sobrien/* Open/create a an STDIO based UI_FILE using the already open FILE. */
9398944Sobrienextern struct ui_file *stdio_fileopen (FILE *file);
9498944Sobrien
9598944Sobrien/* Open NAME returning an STDIO based UI_FILE. */
9698944Sobrienextern struct ui_file *gdb_fopen (char *name, char *mode);
9798944Sobrien
98130803Smarcel/* Create a file which writes to both ONE and TWO.  CLOSE_ONE
99130803Smarcel   and CLOSE_TWO indicate whether the original files should be
100130803Smarcel   closed when the new file is closed.  */
101130803Smarcelstruct ui_file *tee_file_new (struct ui_file *one,
102130803Smarcel			      int close_one,
103130803Smarcel			      struct ui_file *two,
104130803Smarcel			      int close_two);
10598944Sobrien#endif
106