Back to index

tetex-bin  3.0
dribble.c
Go to the documentation of this file.
00001 /* dribble.c -- dribble files for Info.
00002    $Id: dribble.c,v 1.3 2004/04/11 17:56:45 karl Exp $
00003 
00004    Copyright (C) 1993, 1998, 2004 Free Software Foundation, Inc.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2, or (at your option)
00009    any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019 
00020    Written by Brian Fox (bfox@ai.mit.edu). */
00021 
00022 #include "info.h"
00023 #include "dribble.h"
00024 
00025 /* When non-zero, it is a stream to write all input characters to for the
00026    duration of this info session. */
00027 FILE *info_dribble_file = (FILE *)NULL;
00028 
00029 /* Open a dribble file named NAME, perhaps closing an already open one.
00030    This sets the global variable INFO_DRIBBLE_FILE to the open stream. */
00031 void
00032 open_dribble_file (char *name)
00033 {
00034   /* Perhaps close existing dribble file. */
00035   close_dribble_file ();
00036 
00037   /* Keystrokes can be non-printable characters, so we need binary I/O.  */
00038   info_dribble_file = fopen (name, FOPEN_WBIN);
00039 
00040 #if defined (HAVE_SETVBUF)
00041   if (info_dribble_file)
00042 #  if defined (SETVBUF_REVERSED)
00043     setvbuf (info_dribble_file, _IONBF, (char *)NULL, 1);
00044 #  else
00045     setvbuf (info_dribble_file, (char *)NULL, _IONBF, 1);
00046 #  endif /* !SETVBUF_REVERSED */
00047 #endif /* HAVE_SETVBUF */
00048 }
00049 
00050 /* If there is a dribble file already open, close it. */
00051 void
00052 close_dribble_file (void)
00053 {
00054   if (info_dribble_file)
00055     {
00056       fflush (info_dribble_file);
00057       fclose (info_dribble_file);
00058       info_dribble_file = (FILE *)NULL;
00059     }
00060 }
00061 
00062 /* Write some output to our existing dribble file. */
00063 void
00064 dribble (unsigned char byte)
00065 {
00066   if (info_dribble_file)
00067     fwrite (&byte, sizeof (unsigned char), 1, info_dribble_file);
00068 }