156160Sru/* dribble.c -- dribble files for Info.
2146515Sru   $Id: dribble.c,v 1.3 2004/04/11 17:56:45 karl Exp $
321495Sjmacd
4146515Sru   Copyright (C) 1993, 1998, 2004 Free Software Foundation, Inc.
521495Sjmacd
621495Sjmacd   This program is free software; you can redistribute it and/or modify
721495Sjmacd   it under the terms of the GNU General Public License as published by
821495Sjmacd   the Free Software Foundation; either version 2, or (at your option)
921495Sjmacd   any later version.
1021495Sjmacd
1121495Sjmacd   This program is distributed in the hope that it will be useful,
1221495Sjmacd   but WITHOUT ANY WARRANTY; without even the implied warranty of
1321495Sjmacd   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1421495Sjmacd   GNU General Public License for more details.
1521495Sjmacd
1621495Sjmacd   You should have received a copy of the GNU General Public License
1721495Sjmacd   along with this program; if not, write to the Free Software
1821495Sjmacd   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1921495Sjmacd
2021495Sjmacd   Written by Brian Fox (bfox@ai.mit.edu). */
2121495Sjmacd
2242660Smarkm#include "info.h"
2321495Sjmacd#include "dribble.h"
2421495Sjmacd
2521495Sjmacd/* When non-zero, it is a stream to write all input characters to for the
2621495Sjmacd   duration of this info session. */
2721495SjmacdFILE *info_dribble_file = (FILE *)NULL;
2821495Sjmacd
2921495Sjmacd/* Open a dribble file named NAME, perhaps closing an already open one.
3021495Sjmacd   This sets the global variable INFO_DRIBBLE_FILE to the open stream. */
3121495Sjmacdvoid
32146515Sruopen_dribble_file (char *name)
3321495Sjmacd{
3421495Sjmacd  /* Perhaps close existing dribble file. */
3521495Sjmacd  close_dribble_file ();
3621495Sjmacd
3756160Sru  /* Keystrokes can be non-printable characters, so we need binary I/O.  */
3856160Sru  info_dribble_file = fopen (name, FOPEN_WBIN);
3921495Sjmacd
4021495Sjmacd#if defined (HAVE_SETVBUF)
4121495Sjmacd  if (info_dribble_file)
4221495Sjmacd#  if defined (SETVBUF_REVERSED)
4321495Sjmacd    setvbuf (info_dribble_file, _IONBF, (char *)NULL, 1);
4421495Sjmacd#  else
4521495Sjmacd    setvbuf (info_dribble_file, (char *)NULL, _IONBF, 1);
4621495Sjmacd#  endif /* !SETVBUF_REVERSED */
4721495Sjmacd#endif /* HAVE_SETVBUF */
4821495Sjmacd}
4921495Sjmacd
5021495Sjmacd/* If there is a dribble file already open, close it. */
5121495Sjmacdvoid
52146515Sruclose_dribble_file (void)
5321495Sjmacd{
5421495Sjmacd  if (info_dribble_file)
5521495Sjmacd    {
5621495Sjmacd      fflush (info_dribble_file);
5721495Sjmacd      fclose (info_dribble_file);
5821495Sjmacd      info_dribble_file = (FILE *)NULL;
5921495Sjmacd    }
6021495Sjmacd}
6121495Sjmacd
6221495Sjmacd/* Write some output to our existing dribble file. */
6321495Sjmacdvoid
64146515Srudribble (unsigned char byte)
6521495Sjmacd{
6621495Sjmacd  if (info_dribble_file)
6721495Sjmacd    fwrite (&byte, sizeof (unsigned char), 1, info_dribble_file);
6821495Sjmacd}
69