let switch t = if t then "ON" else "OFF"

let cmdopt arr = 
  let o = ref false 
  and q = ref false
  and d = ref "-"
  and args = Queue.create () in

  Arg.parse_argv ~current:(ref 0) arr
    [ "-o", Arg.Set o, "";
      "-q", Arg.Set q, "";
      "-d", Arg.Symbol (["0";"1";"2";], fun s -> d:=s),"";] 
    (fun anon -> Queue.push anon args) "";

  if not !o then raise Exit ;

  let len = Queue.length args in

  Printf.printf "\
    [オプション情報]\n\
    o(output)： %s\n\
    q(quote)： %s\n\
    d(debug)： %s\n\
    \n[パラメータ情報]\n指定数：%d \n"
    (switch !o) (switch !q) !d len;

  for i = 1 to len do 
    Printf.printf "%2d : %s \n" i (Queue.pop args);
  done;;

(* cmdopt [| "prog_name"; "-q"; "-o"; "aa"; "bb"|];; *)
