123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101moduleVar=structmoduleT=structtypet=stringletcompare=ifSys.win32then(funab->String.compare(String.lowercasea)(String.lowercaseb))else(String.compare)endmoduleSet=Set.Make(T)includeTendmoduleMap=Map.Make(Var)typet={vars:stringMap.t;mutableunix:stringarrayoption}letmakevars={vars;unix=None}letempty=makeMap.emptyletvarst=Var.Set.of_list(Map.keyst.vars)letgettk=Map.findt.varskletto_unixt=matcht.unixwith|Somev->v|None->letres=Map.foldi~init:[]~f:(funkvacc->(Printf.sprintf"%s=%s"kv)::acc)t.vars|>Array.of_listint.unix<-Someres;resletof_unixarr=Array.to_listarr|>List.map~f:(funs->matchString.lsplit2s~on:'='with|None->Exn.code_error"Env.of_unix: entry without '=' found in the environ"["var",Sexp.Encoder.strings]|Some(k,v)->(k,v))|>Map.of_list_multi|>Map.map~f:(function|[]->assertfalse|x::_->x)letinitial=make(of_unix(Unix.environment()))letaddt~var~value=make(Map.addt.varsvarvalue)letremovet~var=make(Map.removet.varsvar)letextendt~vars=make(Map.uniont.varsvars~f:(fun__v->Somev))letextend_envxy=extendx~vars:y.varsletto_sexpt=letopenSexp.Encoderin(list(pairstringstring))(Map.to_listt.vars)letdiffxy=Map.mergex.varsy.vars~f:(fun_kvxvy->matchvywith|Some_->None|None->vx)|>makeletupdatet~var~f=make(Map.updatet.varsvar~f)letof_string_mapm=make(String.Map.foldi~init:Map.empty~f:(funkvacc->Map.addacckv)m)letitert=Map.iterit.varsletppfmtt=Sexp.ppfmt(to_sexpt)letcons_patht~dir=make(Map.updatet.vars"PATH"~f:(fun_PATH->Some(Bin.cons_pathdir~_PATH)))letpathenv=matchgetenv"PATH"with|None->[]|Somes->Bin.parse_paths