123456789101112131415161718192021222324252627282930313233343536373839404142434445openStdLabelsletpatdiff_cmd~use_color=letargs=List.concat[["-keep-whitespace"];["-location-style omake"];(ifuse_colorthen[]else["-ascii"]);]inString.concat~sep:" "("patdiff"::args);;letprint?diff_command?(use_color=false)~file1~file2()=letexeccmd=letcmd=Printf.sprintf"%s %s %s 1>&2"cmd(Filename.quotefile1)(Filename.quotefile2)inmatchSys.commandcmdwith|0->`Same|1->`Different|n->`Error(n,cmd)inmatchdiff_commandwith|Somes->ignore(execs:[>`Same|`Different|`Errorofint*string])|None->beginmatchexec(patdiff_cmd~use_color)with|`Same->(* patdiff produced no output, fallback to diff -u *)Printf.eprintf"File \"%s\", line 1, characters 0-0:\n%!"file1;ignore(exec"diff -u":[>`Same|`Different|`Errorofint*string])|`Different->(* patdiff successfully found a difference *)()|`Error(err_code,cmd)->(* patdiff threw an error... perhaps it wasn't installed? fallback to diff -u *)Printf.eprintf"Error:\n\
> %S exited with code %d\n\
> Perhaps patdiff is not installed? Hint, try: opam install patdiff\n\
> Falling back to diff -u\n\
\n"cmderr_code;Printf.eprintf"File \"%s\", line 1, characters 0-0:\n%!"file1;ignore(exec"diff -u":[>`Same|`Different|`Errorofint*string])end;;