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