Merge branch 'vendor/OPENSSL'
[dragonfly.git] / contrib / texinfo / info / dribble.c
1 /* dribble.c -- dribble files for Info.
2    $Id: dribble.c,v 1.7 2008/06/11 09:55:41 gray Exp $
3
4    Copyright (C) 1993, 1998, 2004, 2007, 2008 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 3 of the License, or
9    (at your option) 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, see <http://www.gnu.org/licenses/>.
18
19    Written by Brian Fox (bfox@ai.mit.edu). */
20
21 #include "info.h"
22 #include "dribble.h"
23
24 /* When non-zero, it is a stream to write all input characters to for the
25    duration of this info session. */
26 FILE *info_dribble_file = NULL;
27
28 /* Open a dribble file named NAME, perhaps closing an already open one.
29    This sets the global variable INFO_DRIBBLE_FILE to the open stream. */
30 void
31 open_dribble_file (char *name)
32 {
33   /* Perhaps close existing dribble file. */
34   close_dribble_file ();
35
36   /* Keystrokes can be non-printable characters, so we need binary I/O.  */
37   info_dribble_file = fopen (name, FOPEN_WBIN);
38
39 #if defined (HAVE_SETVBUF)
40   if (info_dribble_file)
41 #  if defined (SETVBUF_REVERSED)
42     setvbuf (info_dribble_file, _IONBF, NULL, 1);
43 #  else
44     setvbuf (info_dribble_file, NULL, _IONBF, 1);
45 #  endif /* !SETVBUF_REVERSED */
46 #endif /* HAVE_SETVBUF */
47 }
48
49 /* If there is a dribble file already open, close it. */
50 void
51 close_dribble_file (void)
52 {
53   if (info_dribble_file)
54     {
55       fflush (info_dribble_file);
56       fclose (info_dribble_file);
57       info_dribble_file = NULL;
58     }
59 }
60
61 /* Write some output to our existing dribble file. */
62 void
63 dribble (unsigned char byte)
64 {
65   if (info_dribble_file)
66     fwrite (&byte, sizeof (unsigned char), 1, info_dribble_file);
67 }