dribble.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* dribble.c -- dribble files for Info.
  2. $Id$
  3. Copyright 1993, 1998, 2004, 2007, 2008, 2013
  4. Free Software Foundation, Inc.
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. Originally written by Brian Fox. */
  16. #include "info.h"
  17. #include "dribble.h"
  18. /* When non-zero, it is a stream to write all input characters to for the
  19. duration of this info session. */
  20. FILE *info_dribble_file = NULL;
  21. /* Open a dribble file named NAME, perhaps closing an already open one.
  22. This sets the global variable INFO_DRIBBLE_FILE to the open stream. */
  23. void
  24. open_dribble_file (char *name)
  25. {
  26. /* Perhaps close existing dribble file. */
  27. close_dribble_file ();
  28. /* Keystrokes can be non-printable characters, so we need binary I/O. */
  29. info_dribble_file = fopen (name, FOPEN_WBIN);
  30. #if defined (HAVE_SETVBUF)
  31. if (info_dribble_file)
  32. # if defined (SETVBUF_REVERSED)
  33. setvbuf (info_dribble_file, _IONBF, NULL, 1);
  34. # else
  35. setvbuf (info_dribble_file, NULL, _IONBF, 1);
  36. # endif /* !SETVBUF_REVERSED */
  37. #endif /* HAVE_SETVBUF */
  38. }
  39. /* If there is a dribble file already open, close it. */
  40. void
  41. close_dribble_file (void)
  42. {
  43. if (info_dribble_file)
  44. {
  45. fflush (info_dribble_file);
  46. fclose (info_dribble_file);
  47. info_dribble_file = NULL;
  48. }
  49. }
  50. /* Write some output to our existing dribble file. */
  51. void
  52. dribble (unsigned char byte)
  53. {
  54. if (info_dribble_file)
  55. fwrite (&byte, sizeof (unsigned char), 1, info_dribble_file);
  56. }