Merge from vendor branch BSDTAR:
[dragonfly.git] / contrib / texinfo / info / dribble.c
1 /* dribble.c -- dribble files for Info.
2
3    Copyright (C) 1993, 98 Free Software Foundation, Inc.
4
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 2, or (at your option)
8    any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 = (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 (name)
32      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. */
51 void
52 close_dribble_file ()
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. */
63 void
64 dribble (byte)
65      unsigned char byte;
66 {
67   if (info_dribble_file)
68     fwrite (&byte, sizeof (unsigned char), 1, info_dribble_file);
69 }