home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / pty4 / part02 / trecord.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-18  |  1.1 KB  |  59 lines

  1. /* trecord.c: tape-record the input
  2. Daniel J. Bernstein, brnstnd@nyu.edu.
  3. Depends on timer.h.
  4. Requires read()/write(), i.e., UNIX.
  5. 7/27/91: Baseline. trecord 1.0, public domain.
  6. No known patent problems.
  7.  
  8. Documentation in trecord.1.
  9. */
  10.  
  11. #include "timer.h"
  12.  
  13. static char buf[8 + 256];
  14.  
  15. main()
  16. {
  17.  timer_clock latest;
  18.  timer_clock now;
  19.  timer_clock diff;
  20.  int r;
  21.  int n;
  22.  int w;
  23.  
  24.  if (timer_now(TIMER_REAL,&latest) == -1)
  25.    ; /*XXX*/
  26.  do
  27.   {
  28.    r = read(0,buf + 8,sizeof(buf) - 8);
  29.    if (r == -1)
  30.      ; /*XXX*/
  31.    if (timer_now(TIMER_REAL,&now) == -1)
  32.      ; /*XXX*/
  33.    if (timer_diff(&now,&latest,&diff) < 0)
  34.      ; /* time warp! */
  35.    latest = now;
  36.    buf[0] = diff.usec & 255;
  37.    buf[1] = (diff.usec / 256) & 255;
  38.    buf[2] = (diff.usec / 65536) & 255;
  39.    buf[3] = diff.sec & 255;
  40.    buf[4] = (diff.sec / 256) & 255;
  41.    buf[5] = (diff.sec / 65536) & 255;
  42.    buf[6] = (diff.sec / 16777216) & 255;
  43.    buf[7] = r - 1;
  44.    r += 8;
  45.    if (r == 8)
  46.      r = 7;
  47.    n = 0;
  48.    while (n < r)
  49.     {
  50.      w = write(1,buf + n,r - n);
  51.      if (w < 0)
  52.        ; /*XXX*/
  53.      n += w;
  54.     }
  55.   }
  56.  while (r != 7);
  57.  exit(0);
  58. }
  59.