Commits

UENISHI Kota  committed 43a4232

updated: binary now workshg st

  • Participants
  • Parent commits 672d395

Comments (0)

Files changed (2)

       (* see http://www.erlang.org/doc/apps/erts/erl_ext_dist.html for details*)
     begin match (String.get local_bin 0) with
       | 'a' ->  (* SMALL_INTEGER_EXT *)
-	  Printf.printf "%d\n" (int_of_char (String.get local_bin 1));
 	  Ok( Int(int_of_char (String.get local_bin 1)), Str.string_after local_bin 2)
       | 'b' ->  (* INTEGER_EXT *)
 	  Ok( Int( make_int32 (String.sub local_bin 1 5)), Str.string_after local_bin 5);
     end;;
 
 let print_binary bin = 
-  let rec p_bin i =
-    if i < (String.length bin) then begin
-      Printf.printf "%.2x," (int_of_char (String.get bin i));
-      p_bin (i+1)
-    end in
-    print_string "<<";
-    p_bin 0;
-    print_string ">>";;
+  let rec to_inverse_list bin_ list = 
+    if (String.length bin_)>0 then
+      to_inverse_list (Str.string_after bin_ 1) ((int_of_char (String.get bin_ 0))::list)
+    else list
+  in
+  let strs = List.fold_left (fun l c-> (Printf.sprintf "%.2x" c)::l ) [] (to_inverse_list bin []) in
+  let s = String.concat "," strs in
+    Printf.printf "<<%s>>" s;;
 
 let print_erlterm term = 
   let rec print_termlist rhs list =

File termreader.ml

 
 let print_termfile filename = 
+  let buflen = 1024 in
+  let buffer = String.create buflen in
   let load_file filename = 
     let rec load channel data = 
       try 
-	let line = Pervasives.input_line channel in
-	  load channel (String.concat "" [data; line])
+	begin match input channel buffer 0 buflen with
+	  | 0 -> 
+	      close_in channel;
+	      data;
+	  | bytes_read -> 
+	      load channel (String.concat "" [(String.sub buffer 0 bytes_read); data]);
+	end
       with
 	| End_of_file ->  
 	    close_in channel;