(root)/
texinfo-7.1/
info/
dribble.c
       1  /* dribble.c -- dribble files for Info.
       2  
       3     Copyright 1993-2023 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 3 of the License, or
       8     (at your option) 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, see <http://www.gnu.org/licenses/>.
      17  
      18     Originally written by Brian Fox. */
      19  
      20  #include "info.h"
      21  #include "dribble.h"
      22  
      23  /* When non-zero, it is a stream to write all input characters to for the
      24     duration of this info session. */
      25  FILE *info_dribble_file = NULL;
      26  
      27  /* Open a dribble file named NAME, perhaps closing an already open one.
      28     This sets the global variable INFO_DRIBBLE_FILE to the open stream. */
      29  void
      30  open_dribble_file (char *name)
      31  {
      32    /* Perhaps close existing dribble file. */
      33    close_dribble_file ();
      34  
      35    /* Keystrokes can be non-printable characters, so we need binary I/O.  */
      36    info_dribble_file = fopen (name, FOPEN_WBIN);
      37  
      38    if (info_dribble_file)
      39      setvbuf (info_dribble_file, NULL, _IONBF, 1);
      40  }
      41  
      42  /* If there is a dribble file already open, close it. */
      43  void
      44  close_dribble_file (void)
      45  {
      46    if (info_dribble_file)
      47      {
      48        fflush (info_dribble_file);
      49        fclose (info_dribble_file);
      50        info_dribble_file = NULL;
      51      }
      52  }
      53  
      54  /* Write some output to our existing dribble file. */
      55  void
      56  dribble (unsigned char byte)
      57  {
      58    if (info_dribble_file)
      59      fwrite (&byte, sizeof (unsigned char), 1, info_dribble_file);
      60  }