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

bug

parent b92fc45e
......@@ -6,13 +6,14 @@ 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 buff_int b i =
let ui = (i + (1 lsl 17)) mod (1 lsl 18) in
......@@ -36,8 +37,10 @@ let float_buff b pos =
let f = int_buff b pos in
(float_of_int f) /. 10.
let buff_string b str =
let n = String.length str in
buff_int b (((n+2)/3)*4);
let pos = ref 0 in
let pi i = add_char b (b64_of_ui i) in
while !pos < n do
......@@ -62,14 +65,82 @@ let buff_string b str =
add_char b '='
end;
pos := !pos+3
done;;
done
let string_buff b pin =
let n = int_buff b pin in
let pos = ref (pin+3) in
let pos2 = ref 0 in
let str = Bytes.create ((n/4)*3) in
while !pos < n+(pin+3) do
let v1 = ui_of_b64 b.[!pos] in
let v2 = ui_of_b64 b.[!pos+1] in
Bytes.set str !pos2 @@ char_of_int (v1*4 + v2/16);
if b.[!pos+2] <> '=' then
let v3 = ui_of_b64 b.[!pos+2] in
if b.[!pos+3] <> '=' then
let v4 = ui_of_b64 b.[!pos+3] in
Bytes.set str (!pos2+1) @@ char_of_int ((v2 mod 16)*16 + v3/4);
Bytes.set str (!pos2+2) @@ char_of_int ((v3 mod 4)*64 + v4);
pos2:= !pos2+3;
else begin
Bytes.set str (!pos2+1) @@ char_of_int ((v2 mod 16)*16 + v3/4);
pos2:= !pos2+2;
end;
else pos2:= !pos2+1;
pos:= !pos+4;
done;
!pos,Bytes.sub_string str 0 !pos2;;
(*
let t = Buffer.create 10 in
buff_string t "M";
Buffer.to_bytes t;;
buff_int t (-5156);
buff_string t "Mandsflsdh sdlhkfsd sd h % ^& # ";
string_buff (Bytes.to_string @@ Buffer.to_bytes t) 3 ;;*)
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
let p2,lq = list_buff b f p in
p2,le::lq
else pos,[]
(*let t = Buffer.create 10 in
buff_list t buff_int [54443;1;1;1;1;1;-2556;5];
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)
| 'P' -> let f1 = float_buff b (pos+1)
and f2 = float_buff b (pos+4) in (pos+7),`ControlPoint (f1,f2)
| 'S' -> let p,s = string_buff b (pos+1) in
p,(`String s)
| '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'
add_char b 'T';
buff_string b s;
buff_attribute b a
......@@ -202,9 +202,9 @@ module GraphEditor (G: GRAPH ) = struct
Buffer.add_char buff (b64_of_ui node_type);
let f1,f2 = DrawingGeom.center_shapes (G.shapes_of_node graph node) in
buff_float buff f1;
buff_float buff f2;
buff_float buff f2(* ;
let attr = snd @@ G.get_node_attribute graph node in
List.iter (write_attribute buff) attr
List.iter (write_attribute buff) attr*)
);
G.iter_arc graph (fun arc ->
let n1,n2 = G.nodes_of_arc graph arc in
......@@ -213,6 +213,7 @@ module GraphEditor (G: GRAPH ) = struct
buff_int buff (Hashtbl.find map n2);
);
Bytes.to_string @@ Buffer.to_bytes buff
let parse_exchange_string str =
let open GenericSerializer in
......@@ -238,7 +239,7 @@ module GraphEditor (G: GRAPH ) = struct
pos := !pos+7;
done;
graph
let save_load_html s =
let loadfile st =
......
Supports Markdown
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