home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / PROCS.LZH / INBITS.ICN < prev    next >
Text File  |  1991-09-05  |  1KB  |  54 lines

  1. ############################################################################
  2. #
  3. #    Name:     inbits.icn
  4. #
  5. #    Title:     read in variable length characters from a file
  6. #
  7. #    Author:     Richard L. Goerwitz
  8. #
  9. #    Version: 1.2
  10. #
  11. #    Date:     June 1, 1991
  12. #
  13. ############################################################################
  14. #  
  15. #  This procedure, inbits(), re-imports data converted into writable
  16. #  form by outbits().  See the file outbits.icn for all the whys and
  17. #  hows.
  18. #
  19. ############################################################################
  20. #
  21. #  See also: outbits.icn
  22. #
  23. ############################################################################
  24.  
  25.  
  26. procedure inbits(f, len)
  27.  
  28.     local i, byte, old_byte_mask
  29.     static old_byte, old_len, byte_length
  30.     initial {
  31.     old_byte := old_len := 0
  32.     byte_length := 8
  33.     }
  34.  
  35.     old_byte_mask := (0 < 2^old_len - 1) | 0
  36.     old_byte := iand(old_byte, old_byte_mask)
  37.     i := ishift(old_byte, len-old_len)
  38.  
  39.     len -:= (len > old_len) | {
  40.     old_len -:= len
  41.     return i
  42.     }
  43.     
  44.     while byte := ord(reads(f)) do {
  45.     i := ior(i, ishift(byte, len-byte_length))
  46.     len -:= (len > byte_length) | {
  47.         old_len := byte_length-len
  48.         old_byte := byte
  49.         return i
  50.     }
  51.     }
  52.  
  53. end
  54.