Commit b8bdd28e authored by Benoit Barbot's avatar Benoit Barbot
Browse files

gen

parent 77b89518
Pipeline #976 failed with stage
in 10 seconds
......@@ -6,16 +6,46 @@ let b64_of_ui i =
else if i < 62 then char_of_int (i-52+48)
else if i=62 then '+'
else '/'
let ui_of_b64 c =
let i = int_of_char c in
if i>=65 && i<91 then i -65
else if i>= 97 && i<123 then i-97+26
else if i>= 48 && i<58 then i-48+52
else if i=43 then 62
else 63
else 63
let print_buff s =
String.iter (fun c -> let i = ui_of_b64 c in
Printf.printf "[%i]" i
) s
let buff_int b i =
if i>=0 && i< 32 then add_char b (b64_of_ui i)
else if i>=0 && i< (1 lsl 10) then (
let i1 = i/32 + 32
and i2 = i mod 32 in
add_char b (b64_of_ui i1);
add_char b (b64_of_ui i2);
) else
let r = int_of_float ((log @@ float @@ abs @@ i) /. log 2.0) / 5 in
add_char b (b64_of_ui (32 + (if i<0 then 16 else 0) + ((abs i) lsr (r*5))));
let j = ref ((abs i) mod (1 lsl (5*r))) in
let r2 = ref (r*5) in
while !r2 > 0 do
print_endline (string_of_int !r2);
add_char b (b64_of_ui ((if r>5 then 32 else 0) + (!j mod (1 lsl (!r2*5)))));
j:= !j / 32;
r2:= !r2-5;
done
let int_buff s pos =
let i1 = ui_of_b64 s.[pos] in
if i1 < (1 lsl 5) then pos+1,i1
else let i2 = ui_of_b64 s.[pos+1] in
pos+2, (i1 mod (1 lsl 5))*(1 lsl 5) + i2
(*let buff_int b i =
let ui = (i + (1 lsl 17)) mod (1 lsl 18) in
let i1 = ui / (1 lsl 12)
and i2 = (ui / (1 lsl 6)) mod (1 lsl 6)
......@@ -28,8 +58,8 @@ let int_buff s pos =
and i2 = ui_of_b64 s.[pos+1]
and i3 = ui_of_b64 s.[pos+2] in
let ui = i1*(1 lsl 12) + i2*(1 lsl 6) +i3 in
ui - (1 lsl 17)
ui - (1 lsl 17)*)
let buff_float b f =
let i = int_of_float (f *. 10.0) in
buff_int b i
......@@ -37,6 +67,20 @@ let float_buff b pos =
let f = int_buff b pos in
(float_of_int f) /. 10.
let _ =
let t = Buffer.create 100 in
for i = -1025 to -1020 do
buff_int t i;
done;
let str = (Bytes.to_string @@ Buffer.to_bytes t) in
print_buff str;
print_newline ();
let pos = ref 0 in
while !pos < String.length str do
let p1,i1= int_buff str !pos in
pos := p1;
print_endline (string_of_int i1);
done
let buff_string b str =
let n = String.length str in
......@@ -49,7 +93,7 @@ let buff_string b str =
begin if !pos+1 < n then
let v2 = 256*(v1 mod 4) + int_of_char str.[!pos+1] in
pi (v2/16);
if !pos+2 < n then
let v3 = 256*(v2 mod 16) + int_of_char str.[!pos+2] in
pi (v3/64);
......@@ -67,7 +111,7 @@ let buff_string b str =
pos := !pos+3
done
let string_buff b pin =
let n = int_buff b pin in
let pos = ref (pin+3) in
......@@ -93,7 +137,7 @@ let string_buff b pin =
done;
!pos,Bytes.sub_string str 0 !pos2;;
(*
let t = Buffer.create 10 in
buff_int t (-5156);
......@@ -104,7 +148,7 @@ let t = Buffer.create 10 in
let buff_list b f l =
List.iter (fun x -> Buffer.add_char b 'l'; f b x) l
let rec list_buff b f pos =
if pos < String.length b && b.[pos] = 'l' then
let p,le = f b (pos+1) in
......@@ -118,15 +162,15 @@ let rec list_buff b f pos =
let s = Bytes.to_string @@ Buffer.to_bytes t in
print_endline s;
list_buff s (fun b p -> p+3,int_buff b p) 0 ;;*)
let buff_attribute b = function
`Color c -> Buffer.add_char b 'c'; buff_string b c
| `ControlPoint (f1,f2)-> Buffer.add_char b 'P'; buff_float b f1; buff_float b f2
| `String s -> Buffer.add_char b 'S'; buff_string b s
| `Choice sl -> buff_list b buff_string sl
let attribute_buff b pos = match b.[pos] with
'c' -> let p,s = string_buff b (pos+1) in
p,(`Color s)
......@@ -137,8 +181,8 @@ let attribute_buff b pos = match b.[pos] with
| 'd' -> let p,s = list_buff b string_buff (pos+1) in
p,(`Choice s)
| _ -> failwith "bad serialization"
let write_attribute b (_,s,a) =
add_char b 'T';
buff_string b s;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment