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