~ubuntu-branches/ubuntu/hardy/ocaml-doc/hardy

« back to all changes in this revision

Viewing changes to examples/compress/esbit.ml

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2007-09-08 01:49:22 UTC
  • mfrom: (0.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070908014922-lvihyehz0ndq7suu
Tags: 3.10-1
* New upstream release.
* Removed camlp4 documentation since it is not up-to-date.
* Updated to standards version 3.7.2, no changes needed.
* Updated my email address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
(***********************************************************************)
2
 
(*                                                                     *)
3
 
(*                           Objective Caml                            *)
4
 
(*                                                                     *)
5
 
(*               Pierre Weis, projet Cristal, INRIA Rocquencourt       *)
6
 
(*                                                                     *)
7
 
(*  Copyright 2001 Institut National de Recherche en Informatique et   *)
8
 
(*  en Automatique.  All rights reserved.  This file is distributed    *)
9
 
(*  only by permission.                                                *)
10
 
(*                                                                     *)
11
 
(***********************************************************************)
12
 
type tampon = { mutable value : int; mutable nbits : int };;
13
 
 
14
 
let tampon = { value = 0; nbits = 0 };;
15
 
 
16
 
let initialise () = tampon.value <- 0; tampon.nbits <- 0;;
17
 
 
18
 
let �crire_bit sortie bit =
19
 
  tampon.value <- tampon.value lor (bit lsl tampon.nbits);
20
 
  tampon.nbits <- tampon.nbits + 1;
21
 
  if tampon.nbits >= 8 then begin
22
 
    output_char sortie (char_of_int tampon.value);
23
 
    tampon.value <- 0;
24
 
    tampon.nbits <- 0
25
 
  end;;
26
 
 
27
 
let finir sortie =
28
 
  if tampon.nbits > 0 then
29
 
    output_char sortie (char_of_int tampon.value);;
30
 
 
31
 
let lire_bit entr�e =
32
 
  if tampon.nbits <= 0 then begin
33
 
    tampon.value <- int_of_char(input_char entr�e);
34
 
    tampon.nbits <- 8
35
 
  end;
36
 
  let res = tampon.value land 1 in
37
 
  tampon.value <- tampon.value lsr 1;
38
 
  tampon.nbits <- tampon.nbits - 1;
39
 
  res;;