home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / dial / d_tscript.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-06-04  |  2.0 KB  |  107 lines

  1. # include  <stdio.h>
  2. # include  "d_returns.h"
  3.  
  4. /*  maintain a transcript of data i/o over the port.  * the transcript is
  5.  *  not buffered, so that it will reflect the * latest activity, for
  6.  *  debugging.  dhc.
  7.  */
  8.  
  9. static int  d_tsfd;           /*  file descriptor for transcript file  */
  10.  
  11. /*
  12.  *     D_TSOPEN
  13.  *
  14.  *     this routine creates the transcript file.
  15.  *
  16.  *     filename -- name of the transcript file to be created.  if this arg
  17.  *                 is zero, then the standard output is used.
  18.  */
  19.  
  20. d_tsopen(filename)
  21.   register char  *filename;
  22.     {
  23.     extern int  d_errno, errno;
  24.  
  25.     if (filename == 0)
  26.       {
  27. #ifdef D_LOG
  28.       d_log("d_tsopen", "transcript started on standard output");
  29. #endif D_LOG
  30.       d_tsfd = 1;
  31.       return(D_OK);
  32.       }
  33.  
  34.     if ((d_tsfd = creat(filename, 0662)) < 0)
  35.       {
  36. #ifdef D_LOG
  37.       d_log("d_tsopen", "can't create transcript file '%s'", filename);
  38. #endif D_LOG
  39.       d_errno = D_TSOPEN;
  40.       return(D_FATAL);
  41.       }
  42.  
  43.     chmod (filename, 0662);
  44. #ifdef D_LOG
  45.     d_log("d_tsopen", "transcript file '%s' created", filename);
  46. #endif D_LOG
  47.     return(D_OK);
  48.     }
  49.  
  50. /* */
  51. /*
  52.  *     D_TSCLOSE
  53.  *
  54.  *     this routine is called to stop transcribing
  55.  */
  56.  
  57. d_tsclose()
  58.     {
  59.  
  60. /*  do nothing if transcribing is not active  */
  61.  
  62.     if (d_tsfd <= 0)
  63.       return(D_OK);
  64.  
  65.     if (d_tsfd != 1)
  66.       (void) close(d_tsfd);
  67.  
  68. #ifdef D_LOG
  69.     d_log("d_tsclose", "transcript stopped");
  70. #endif D_LOG
  71.  
  72.     return(D_OK);
  73.     }
  74.  
  75.  
  76. /*
  77.  *     D_TSCRIBE
  78.  *
  79.  *     routine which writes on the transcript file
  80.  *
  81.  *     text -- pointer to byets to be written
  82.  *
  83.  *     length -- number of bytes to be written
  84.  */
  85.  
  86. d_tscribe(text, length)
  87.   register char  *text;
  88.   register int  length;
  89.     {
  90.     extern int  d_errno;
  91.  
  92. /*  if there's a transcript file and something to write, do it  */
  93.  
  94.     if ((d_tsfd > 0) && (length > 0))
  95.     {
  96.     if (write(d_tsfd, text, length) != length)
  97.       {
  98. #ifdef D_LOG
  99.       d_log("d_tscribe", "error writing on transcript file");
  100. #endif D_LOG
  101.       d_errno = D_TSWRITE;
  102.       return(D_NONFATAL);
  103.       }
  104.     }
  105.     return(D_OK);
  106.     }
  107.