home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_12 / 8n12046a < prev    next >
Text File  |  1990-10-15  |  1KB  |  46 lines

  1. /*
  2.  *  RING.C
  3.  *
  4.  *  ring buffer routines
  5.  *
  6.  */
  7.  
  8. #include    "char.h"
  9.  
  10. /*
  11.  *  r_write()
  12.  *
  13.  *  r_write() puts a byte in the buffer.  when is the buffer full?
  14.  *  when writing 1 more byte would set the read and write indices
  15.  *  equal to each other (which means the buffer is empty!!).  does
  16.  *  nothing but return if it can't write the byte without
  17.  *  overflowing the buffer... if this was a real multi-tasking
  18.  *  system, we could sleep until somebody reads a byte, which
  19.  *  would allow us to do our write, but it isn't, so...
  20.  */
  21.  
  22. void    r_write(c)
  23. char    c;
  24.     {
  25.     if (((w_index + 1) & RLIMIT) == r_index)
  26.         return;
  27.     r_buf[ w_index++ ] = c;
  28.     w_index &= RLIMIT;      /* wrap the index around */
  29.     }
  30.  
  31.  
  32. /*
  33.  *  r_puti()
  34.  *
  35.  *  r_puti() converts a small (0 - 99) decimal number into two
  36.  *  ASCII digits and put them in the ring buffer
  37.  */
  38.  
  39. void    r_puti(c)
  40. char    c;
  41.     {
  42.     r_write((c / 10) + '0');
  43.     r_write((c % 10) + '0');
  44.     }
  45.  
  46.