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