Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file misc.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160(**************************************************************************)(* *)(* Copyright (C) Johannes Kanig, Stephane Lescuyer *)(* Jean-Christophe Filliatre, Romain Bardou and Francois Bobot *)(* *)(* This software is free software; you can redistribute it and/or *)(* modify it under the terms of the GNU Library General Public *)(* License version 2.1, with the special exception on linking *)(* described in file LICENSE. *)(* *)(* This software is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *)(* *)(**************************************************************************)letidx=xletprint_optionstartprinterfmt=function|None->()|Someo->Format.fprintffmt"%s%a "startprinteroletdate_string()=lettm=Unix.gmtime(Unix.time())inPrintf.sprintf"%d/%d/%d, %d:%d:%d"(tm.Unix.tm_mon+1)tm.Unix.tm_mday(tm.Unix.tm_year+1900)tm.Unix.tm_hourtm.Unix.tm_mintm.Unix.tm_secletrecprint_listsepprffmt=function|[]->()|[x]->prffmtx|x::xs->prffmtx;sepfmt();print_listsepprffmtxsletprint_iter1itersepprintfmtl=letfirst=reftrueiniter(funx->if!firstthenfirst:=falseelsesepfmt();printfmtx)lletprint_iter2itersep1sep2print1print2fmtl=letfirst=reftrueiniter(funxy->if!firstthenfirst:=falseelsesep1fmt();print1fmtx;sep2fmt();print2fmty)lletspacefmt()=Format.fprintffmt"@ "letcommafmt()=Format.fprintffmt",@ "letsemicolonfmt()=Format.fprintffmt";@ "letnewlinefmt()=Format.fprintffmt"@\n "letnothing_fmt_=()letprint_int32fmti=Format.fprintffmt"%ld"iletrecfold_from_tofaccab=ifa<=bthenfold_from_tof(facca)(a+1)belseaccletsprintfs=letbuf=Buffer.create1024inletfmt=Format.formatter_of_bufferbufinFormat.kfprintf(fun_->Format.pp_print_flushfmt();Buffer.contentsbuf)fmts(*Filename.generic_quote*)letgeneric_quotewhatquotequotequotes=letl=String.lengthsinletb=Buffer.create(l+20)infori=0tol-1doifs.[i]=whatquotethenBuffer.add_stringbquotequoteelseBuffer.add_charbs.[i]done;Buffer.contentsbletgeneric_quote_listlwqqs=letl=String.lengthsinletb=Buffer.create(l+20)infori=0tol-1doifList.mem_assocs.[i]lwqqthenBuffer.add_stringb(List.assocs.[i]lwqq)elseBuffer.add_charbs.[i]done;Buffer.contentsbletcall_cmd?(inv=false)?(outv=false)?(verbose=false)cmd=(* inv = true -> print command line
* outv = true -> print command output
* verbose = true -> both
*)ifinv||verbosethenFormat.printf"+ %s@."cmd;let((outc,inc,errc)asproc)=Unix.open_process_fullcmd(Unix.environment())inclose_outinc;letout_descr=Unix.descr_of_in_channeloutcanderr_descr=Unix.descr_of_in_channelerrcin(* using Unix.select as in OCaml PLEAC *)letselector=ref[out_descr;err_descr]inletbuf=Bytes.create1024inwhile!selector<>[]doletcan_read,_,_=Unix.select!selector[][]1.0inList.iter(funfh->letret=Unix.readfhbuf01024inifret=0thenselector:=List.filter(funfh'->fh<>fh')!selector;ifoutv||verbosetheniffh=err_descrthenignore(Unix.writeUnix.stderrbuf0ret)elseignore(Unix.writeUnix.stdoutbuf0ret))can_readdone;letstatus=Unix.close_process_fullprocinflushstdout;flushstderr;matchstatuswith|Unix.WEXITEDn->ifn>124then(Printf.eprintf"command %s has aborted with exit code: %d@\n"cmdn;exitn);n|_->exit1(* persistent queues *)moduleQ=structtype'at='alist*'alistexceptionEmptyletempty=([],[])letpushx(i,o)=(x::i,o)letpop=function|[],[]->raiseEmpty|i,x::o->(x,(i,o))|i,[]->(matchList.reviwithx::o->(x,([],o))|[]->assertfalse)letof_listl=List.fold_left(funqc->pushcq)emptylendmoduleStringMap=Map.Make(String)moduleIntMap=Map.Make(structtypet=intletcompare=Stdlib.compareend)