Home | History | Annotate | Line # | Download | only in gdb
ui-file.h revision 1.1.1.3
      1      1.1  christos /* UI_FILE - a generic STDIO like output stream.
      2  1.1.1.2  christos    Copyright (C) 1999-2015 Free Software Foundation, Inc.
      3      1.1  christos 
      4      1.1  christos    This file is part of GDB.
      5      1.1  christos 
      6      1.1  christos    This program is free software; you can redistribute it and/or modify
      7      1.1  christos    it under the terms of the GNU General Public License as published by
      8      1.1  christos    the Free Software Foundation; either version 3 of the License, or
      9      1.1  christos    (at your option) any later version.
     10      1.1  christos 
     11      1.1  christos    This program is distributed in the hope that it will be useful,
     12      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14      1.1  christos    GNU General Public License for more details.
     15      1.1  christos 
     16      1.1  christos    You should have received a copy of the GNU General Public License
     17      1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     18      1.1  christos 
     19      1.1  christos #ifndef UI_FILE_H
     20      1.1  christos #define UI_FILE_H
     21      1.1  christos 
     22      1.1  christos struct obstack;
     23      1.1  christos struct ui_file;
     24      1.1  christos 
     25      1.1  christos /* Create a generic ui_file object with null methods.  */
     26      1.1  christos 
     27      1.1  christos extern struct ui_file *ui_file_new (void);
     28      1.1  christos 
     29      1.1  christos /* Override methods used by specific implementations of a UI_FILE
     30      1.1  christos    object.  */
     31      1.1  christos 
     32      1.1  christos typedef void (ui_file_flush_ftype) (struct ui_file *stream);
     33      1.1  christos extern void set_ui_file_flush (struct ui_file *stream,
     34      1.1  christos 			       ui_file_flush_ftype *flush);
     35      1.1  christos 
     36      1.1  christos /* NOTE: Both fputs and write methods are available.  Default
     37      1.1  christos    implementations that mapping one onto the other are included.  */
     38      1.1  christos typedef void (ui_file_write_ftype) (struct ui_file *stream,
     39      1.1  christos 				    const char *buf, long length_buf);
     40      1.1  christos extern void set_ui_file_write (struct ui_file *stream,
     41      1.1  christos 			       ui_file_write_ftype *fputs);
     42      1.1  christos 
     43      1.1  christos typedef void (ui_file_fputs_ftype) (const char *, struct ui_file *stream);
     44      1.1  christos extern void set_ui_file_fputs (struct ui_file *stream,
     45      1.1  christos 			       ui_file_fputs_ftype *fputs);
     46      1.1  christos 
     47      1.1  christos /* This version of "write" is safe for use in signal handlers.
     48      1.1  christos    It's not guaranteed that all existing output will have been
     49      1.1  christos    flushed first.
     50      1.1  christos    Implementations are also free to ignore some or all of the request.
     51      1.1  christos    fputs_async is not provided as the async versions are rarely used,
     52      1.1  christos    no point in having both for a rarely used interface.  */
     53      1.1  christos typedef void (ui_file_write_async_safe_ftype)
     54      1.1  christos   (struct ui_file *stream, const char *buf, long length_buf);
     55      1.1  christos extern void set_ui_file_write_async_safe
     56      1.1  christos   (struct ui_file *stream, ui_file_write_async_safe_ftype *write_async_safe);
     57      1.1  christos 
     58      1.1  christos typedef long (ui_file_read_ftype) (struct ui_file *stream,
     59      1.1  christos 				   char *buf, long length_buf);
     60      1.1  christos extern void set_ui_file_read (struct ui_file *stream,
     61      1.1  christos 			      ui_file_read_ftype *fread);
     62      1.1  christos 
     63      1.1  christos typedef int (ui_file_isatty_ftype) (struct ui_file *stream);
     64      1.1  christos extern void set_ui_file_isatty (struct ui_file *stream,
     65      1.1  christos 				ui_file_isatty_ftype *isatty);
     66      1.1  christos 
     67      1.1  christos typedef void (ui_file_rewind_ftype) (struct ui_file *stream);
     68      1.1  christos extern void set_ui_file_rewind (struct ui_file *stream,
     69      1.1  christos 				ui_file_rewind_ftype *rewind);
     70      1.1  christos 
     71      1.1  christos typedef void (ui_file_put_method_ftype) (void *object, const char *buffer,
     72      1.1  christos 					 long length_buffer);
     73      1.1  christos typedef void (ui_file_put_ftype) (struct ui_file *stream,
     74      1.1  christos 				  ui_file_put_method_ftype *method,
     75      1.1  christos 				  void *context);
     76      1.1  christos extern void set_ui_file_put (struct ui_file *stream, ui_file_put_ftype *put);
     77      1.1  christos 
     78      1.1  christos typedef void (ui_file_delete_ftype) (struct ui_file * stream);
     79      1.1  christos extern void set_ui_file_data (struct ui_file *stream, void *data,
     80  1.1.1.3  christos 			      ui_file_delete_ftype *to_delete);
     81      1.1  christos 
     82      1.1  christos typedef int (ui_file_fseek_ftype) (struct ui_file *stream, long offset,
     83      1.1  christos 				   int whence);
     84      1.1  christos extern void set_ui_file_fseek (struct ui_file *stream,
     85      1.1  christos 			       ui_file_fseek_ftype *fseek_ptr);
     86      1.1  christos 
     87      1.1  christos extern void *ui_file_data (struct ui_file *file);
     88      1.1  christos 
     89      1.1  christos 
     90      1.1  christos extern void gdb_flush (struct ui_file *);
     91      1.1  christos 
     92      1.1  christos extern void ui_file_delete (struct ui_file *stream);
     93      1.1  christos 
     94      1.1  christos extern void ui_file_rewind (struct ui_file *stream);
     95      1.1  christos 
     96      1.1  christos extern int ui_file_isatty (struct ui_file *);
     97      1.1  christos 
     98      1.1  christos extern void ui_file_write (struct ui_file *file, const char *buf,
     99      1.1  christos 			   long length_buf);
    100      1.1  christos 
    101  1.1.1.2  christos /* A wrapper for ui_file_write that is suitable for use by
    102  1.1.1.2  christos    ui_file_put.  */
    103  1.1.1.2  christos 
    104  1.1.1.2  christos extern void ui_file_write_for_put (void *data, const char *buffer,
    105  1.1.1.2  christos 				   long length_buffer);
    106  1.1.1.2  christos 
    107      1.1  christos extern void ui_file_write_async_safe (struct ui_file *file, const char *buf,
    108      1.1  christos 				      long length_buf);
    109      1.1  christos 
    110      1.1  christos /* NOTE: copies left to right.  */
    111      1.1  christos extern void ui_file_put (struct ui_file *src,
    112      1.1  christos 			 ui_file_put_method_ftype *write, void *dest);
    113      1.1  christos 
    114      1.1  christos /* Returns a freshly allocated buffer containing the entire contents
    115      1.1  christos    of FILE (as determined by ui_file_put()) with a NUL character
    116      1.1  christos    appended.  LENGTH, if not NULL, is set to the size of the buffer
    117      1.1  christos    minus that appended NUL.  */
    118      1.1  christos extern char *ui_file_xstrdup (struct ui_file *file, long *length);
    119      1.1  christos 
    120      1.1  christos /* Similar to ui_file_xstrdup, but return a new string allocated on
    121      1.1  christos    OBSTACK.  */
    122      1.1  christos extern char *ui_file_obsavestring (struct ui_file *file,
    123      1.1  christos 				   struct obstack *obstack, long *length);
    124      1.1  christos 
    125      1.1  christos extern long ui_file_read (struct ui_file *file, char *buf, long length_buf);
    126      1.1  christos 
    127      1.1  christos extern int ui_file_fseek (struct ui_file *file, long offset, int whence);
    128      1.1  christos 
    129      1.1  christos /* Create/open a memory based file.  Can be used as a scratch buffer
    130      1.1  christos    for collecting output.  */
    131      1.1  christos extern struct ui_file *mem_fileopen (void);
    132      1.1  christos 
    133      1.1  christos 
    134      1.1  christos 
    135      1.1  christos /* Open/create a STDIO based UI_FILE using the already open FILE.  */
    136      1.1  christos extern struct ui_file *stdio_fileopen (FILE *file);
    137      1.1  christos 
    138      1.1  christos /* Create a ui_file from stderr.  */
    139      1.1  christos extern struct ui_file *stderr_fileopen (void);
    140      1.1  christos 
    141      1.1  christos 
    142      1.1  christos /* Open NAME returning an STDIO based UI_FILE.  */
    143      1.1  christos extern struct ui_file *gdb_fopen (const char *name, const char *mode);
    144      1.1  christos 
    145      1.1  christos /* Create a file which writes to both ONE and TWO.  CLOSE_ONE
    146      1.1  christos    and CLOSE_TWO indicate whether the original files should be
    147      1.1  christos    closed when the new file is closed.  */
    148      1.1  christos extern struct ui_file *tee_file_new (struct ui_file *one,
    149      1.1  christos 				     int close_one,
    150      1.1  christos 				     struct ui_file *two,
    151      1.1  christos 				     int close_two);
    152      1.1  christos #endif
    153