#!OCAMLRUN OCAML
#load "unix.cma";;
let (//) = Filename.concat
let dirname = Filename.dirname Sys.argv.(0)
let dirname = if Filename.is_relative dirname && dirname <> Filename.current_dir_name then Sys.getcwd () // dirname else dirname
let env =
  Array.map (fun var ->
   let value = try Sys.getenv var with _ -> dirname in
   let value = if value = "." then Sys.getcwd () else value in
   Printf.sprintf "%s=%s" var value)
   [|"PAPARAZZI_SRC"; "PAPARAZZI_HOME"|]
let com =
  if Array.length (Sys.argv) > 1 then begin
    Printf.printf "%d\n" (Array.length (Sys.argv));
    if Sys.argv.(1) = "-python" then
      dirname // "paparazzi-python.sh"
    else
      dirname // "sw/supervision/paparazzicenter"
    end
  else
    dirname // "sw/supervision/paparazzicenter";;
Sys.argv.(0) <- com;;
let env = Array.append env (Unix.environment ());;
Unix.execve com Sys.argv env
