123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293openPrintf(*
let split s = Str.split (Str.regexp ",") s
*)letsplits=letacc=ref[]inletstop=ref(String.lengths)infori=!stop-1downto0doifs.[i]=','then(letstart=i+1inacc:=String.subsstart(!stop-start)::!acc;stop:=i)done;String.subs0!stop::!accletload_linesaccus=letic=open_insinletl=refaccuin(trywhiletruedol:=input_lineic::List.rev!ldonewithEnd_of_file->close_inic);!lletloadic=letbuf=Buffer.create1000intrywhiletruedoBuffer.add_charbuf(input_charic);done;assertfalsewithEnd_of_file->Buffer.contentsbuflet(//)=Filename.concatletdefault_dict_path()=trymatchSys.os_typewith"Unix"->Some(Sys.getenv"HOME"//".bdump-dict")|"Win32"->Some(Sys.getenv"HOMEPATH"//"_bdump-dict")|"Cygwin"->Some(Sys.getenv"HOME"//".bdump-dict")|_->NonewithNot_found->Noneletload_dictionarydic_fileaccu=matchdic_filewithNone->accu|Somefn->ifSys.file_existsfnthentryload_linesaccufnwithe->failwith(sprintf"Cannot load dictionary from %S: %s\n%!"fn(Printexc.to_stringe))elseacculetwrite_uniqoca=ifArray.lengtha>0then(fprintfoc"%s\n"a.(0);ignore(Array.fold_left(funlastx->iflast<>xthenfprintfoc"%s\n"x;x)a.(0)a))letsave_dictionarydic_filel=matchdic_filewithNone->()|Somefn->leta=Array.of_listlinArray.sortString.comparea;letoc=open_outfninletfinally()=close_out_noerrocintrywrite_uniqoca;finally()withe->finally();raisee