Source

ocaml-bert / termreader.ml

UENISHI Kota 19d1fed 
UENISHI Kota 3aec550 
UENISHI Kota 43a4232 

UENISHI Kota 19d1fed 


UENISHI Kota 43a4232 






UENISHI Kota 19d1fed 




UENISHI Kota b8bd721 
UENISHI Kota 19d1fed 

UENISHI Kota c3bcbad 











UENISHI Kota b8bd721 
UENISHI Kota 3aec550 
UENISHI Kota 7fed6ae 
UENISHI Kota c3bcbad 
UENISHI Kota 3aec550 


UENISHI Kota 0c35e71 
UENISHI Kota 3aec550 
UENISHI Kota 0c35e71 




UENISHI Kota 89e6797 


UENISHI Kota 9433b13 

UENISHI Kota 89e6797 
UENISHI Kota 9433b13 

UENISHI Kota 89e6797 

UENISHI Kota 9433b13 
let print_termfile filename = 
  let buflen = 1024 in
  let buffer = String.create buflen in
  let load_file filename = 
    let rec load channel data = 
      try 
	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;
	    data
    in
    let fch = open_in_bin filename in (* opening file channel *)
      load fch ""
  in
  let rec decode_all bin = 
    begin match Bert.decode_binary bin with
      | Bert.Ok(term, remain)->
	  Bert.print_erlterm term;
	  print_endline "";
	  if String.length remain > 0 then 
	    decode_all remain
	  else
	    print_endline "==all read.";
      | _->
	  print_endline "==failed in decoding.";
    end in
  let bin = load_file filename in
    Printf.printf "reading %s: \n" filename;
(*    Bert.print_binary_string bin; *)
    decode_all bin;;

let _ = 
  let argv = Array.to_list Sys.argv in
    print_string "==";
    match List.tl argv with
      | [] -> 
	  print_string "no files specified - ";
	  [print_termfile "termwriter.bert"];
      | list -> 
	  List.map print_termfile list;;

let _ = 
  let str = String.create 64 in
  let _ = Bert.init_buf str in
  let i = Bert.encode_int 774567 str 1 in
  let j = Bert.encode_float 234.354 str i in
  let k = Bert.encode_atom "HAHAHAHA" str j in
  let l = Bert.encode_string "HAHAHAHA" str k in
    Bert.print_binary_string str;
(*    print_endline str; *)
    l;;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.