gdb/ui-file.h - gdb

Data types defined

Macros defined

Source code

  1. /* UI_FILE - a generic STDIO like output stream.
  2.    Copyright (C) 1999-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #ifndef UI_FILE_H
  15. #define UI_FILE_H

  16. struct obstack;
  17. struct ui_file;

  18. /* Create a generic ui_file object with null methods.  */

  19. extern struct ui_file *ui_file_new (void);

  20. /* Override methods used by specific implementations of a UI_FILE
  21.    object.  */

  22. typedef void (ui_file_flush_ftype) (struct ui_file *stream);
  23. extern void set_ui_file_flush (struct ui_file *stream,
  24.                                ui_file_flush_ftype *flush);

  25. /* NOTE: Both fputs and write methods are available.  Default
  26.    implementations that mapping one onto the other are included.  */
  27. typedef void (ui_file_write_ftype) (struct ui_file *stream,
  28.                                     const char *buf, long length_buf);
  29. extern void set_ui_file_write (struct ui_file *stream,
  30.                                ui_file_write_ftype *fputs);

  31. typedef void (ui_file_fputs_ftype) (const char *, struct ui_file *stream);
  32. extern void set_ui_file_fputs (struct ui_file *stream,
  33.                                ui_file_fputs_ftype *fputs);

  34. /* This version of "write" is safe for use in signal handlers.
  35.    It's not guaranteed that all existing output will have been
  36.    flushed first.
  37.    Implementations are also free to ignore some or all of the request.
  38.    fputs_async is not provided as the async versions are rarely used,
  39.    no point in having both for a rarely used interface.  */
  40. typedef void (ui_file_write_async_safe_ftype)
  41.   (struct ui_file *stream, const char *buf, long length_buf);
  42. extern void set_ui_file_write_async_safe
  43.   (struct ui_file *stream, ui_file_write_async_safe_ftype *write_async_safe);

  44. typedef long (ui_file_read_ftype) (struct ui_file *stream,
  45.                                    char *buf, long length_buf);
  46. extern void set_ui_file_read (struct ui_file *stream,
  47.                               ui_file_read_ftype *fread);

  48. typedef int (ui_file_isatty_ftype) (struct ui_file *stream);
  49. extern void set_ui_file_isatty (struct ui_file *stream,
  50.                                 ui_file_isatty_ftype *isatty);

  51. typedef void (ui_file_rewind_ftype) (struct ui_file *stream);
  52. extern void set_ui_file_rewind (struct ui_file *stream,
  53.                                 ui_file_rewind_ftype *rewind);

  54. typedef void (ui_file_put_method_ftype) (void *object, const char *buffer,
  55.                                          long length_buffer);
  56. typedef void (ui_file_put_ftype) (struct ui_file *stream,
  57.                                   ui_file_put_method_ftype *method,
  58.                                   void *context);
  59. extern void set_ui_file_put (struct ui_file *stream, ui_file_put_ftype *put);

  60. typedef void (ui_file_delete_ftype) (struct ui_file * stream);
  61. extern void set_ui_file_data (struct ui_file *stream, void *data,
  62.                               ui_file_delete_ftype *delete);

  63. typedef int (ui_file_fseek_ftype) (struct ui_file *stream, long offset,
  64.                                    int whence);
  65. extern void set_ui_file_fseek (struct ui_file *stream,
  66.                                ui_file_fseek_ftype *fseek_ptr);

  67. extern void *ui_file_data (struct ui_file *file);


  68. extern void gdb_flush (struct ui_file *);

  69. extern void ui_file_delete (struct ui_file *stream);

  70. extern void ui_file_rewind (struct ui_file *stream);

  71. extern int ui_file_isatty (struct ui_file *);

  72. extern void ui_file_write (struct ui_file *file, const char *buf,
  73.                            long length_buf);

  74. /* A wrapper for ui_file_write that is suitable for use by
  75.    ui_file_put.  */

  76. extern void ui_file_write_for_put (void *data, const char *buffer,
  77.                                    long length_buffer);

  78. extern void ui_file_write_async_safe (struct ui_file *file, const char *buf,
  79.                                       long length_buf);

  80. /* NOTE: copies left to right.  */
  81. extern void ui_file_put (struct ui_file *src,
  82.                          ui_file_put_method_ftype *write, void *dest);

  83. /* Returns a freshly allocated buffer containing the entire contents
  84.    of FILE (as determined by ui_file_put()) with a NUL character
  85.    appended.  LENGTH, if not NULL, is set to the size of the buffer
  86.    minus that appended NUL.  */
  87. extern char *ui_file_xstrdup (struct ui_file *file, long *length);

  88. /* Similar to ui_file_xstrdup, but return a new string allocated on
  89.    OBSTACK.  */
  90. extern char *ui_file_obsavestring (struct ui_file *file,
  91.                                    struct obstack *obstack, long *length);

  92. extern long ui_file_read (struct ui_file *file, char *buf, long length_buf);

  93. extern int ui_file_fseek (struct ui_file *file, long offset, int whence);

  94. /* Create/open a memory based file.  Can be used as a scratch buffer
  95.    for collecting output.  */
  96. extern struct ui_file *mem_fileopen (void);



  97. /* Open/create a STDIO based UI_FILE using the already open FILE.  */
  98. extern struct ui_file *stdio_fileopen (FILE *file);

  99. /* Create a ui_file from stderr.  */
  100. extern struct ui_file *stderr_fileopen (void);


  101. /* Open NAME returning an STDIO based UI_FILE.  */
  102. extern struct ui_file *gdb_fopen (const char *name, const char *mode);

  103. /* Create a file which writes to both ONE and TWO.  CLOSE_ONE
  104.    and CLOSE_TWO indicate whether the original files should be
  105.    closed when the new file is closed.  */
  106. extern struct ui_file *tee_file_new (struct ui_file *one,
  107.                                      int close_one,
  108.                                      struct ui_file *two,
  109.                                      int close_two);
  110. #endif