fork download
  1. open Printf
  2.  
  3. (* Filled with any cpp-like defines seen on argv.
  4.  
  5.   FIXME: Add something like `-D__ACTION_SCRIPT_2__' to it so we can
  6.   differentiate when we're compiling action script, and when c *)
  7. let defines = ref ([] : string list)
  8.  
  9. (* Filled with the rest of command-line arguments *)
  10. let args = ref ([] : string list)
  11.  
  12. (* List of command-options we'd like to process *)
  13. let options = ref ([] : (string * Arg.spec * string) list)
  14.  
  15. (* One option just for the test *)
  16. let verbose = ref false
  17.  
  18. let begins_with_D str =
  19. String.length str >= 2 && str.[0] = '-' && str.[1] = 'D';;
  20.  
  21. let split_argv str =
  22. let files = ref [] in
  23. let usage = "usage string\n Options :" in
  24. let file = "some_file" in
  25.  
  26. let defines, args =
  27. List.partition begins_with_D (List.tl (Array.to_list Sys.argv)) in
  28.  
  29. let args_spec = [
  30. ("-v", Arg.Unit (fun () -> verbose := true), "turn on verbose mode");
  31. ] @ !options in
  32. Arg.parse_argv !args args_spec
  33. (fun file -> files := file :: !files) usage;
  34.  
  35. (* Debug defines *)
  36. List.iter (printf "'%s' ") !defines;
  37. printf "\n";
  38.  
  39. (* Debug args *)
  40. Array.iter (printf "'%s' ") (Array.of_list (List.rev !args));
  41. printf "\n";
  42. ;;
  43.  
  44. split_argv Sys.argv;;
  45.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty