(* Filled with any cpp-like defines seen on argv.
FIXME: Add something like `-D__ACTION_SCRIPT_2__' to it so we can
differentiate when we're compiling action script, and when c *)
(* Filled with the rest of command-line arguments *)
(* List of command-options we'd like to process *)
(* One option just for the test *)
let verbose = ref false
let begins_with_D str =
String.length str
>= 2 && str
.[0] = '-' && str
.[1] = 'D
';;
let split_argv str =
let files = ref [] in
let usage = "usage string\n Options :" in
let file = "some_file" in
let defines, args =
let args_spec = [
("-v",
Arg.Unit
(fun () -> verbose
:= true),
"turn on verbose mode"); ] @ !options in
Arg.parse_argv
!args args_spec
(fun file -> files := file :: !files) usage;
(* Debug defines *)
List.iter
(printf
"'%s' ") !defines
; printf "\n";
(* Debug args *)
printf "\n";
;;
b3BlbiBQcmludGYKCigqIEZpbGxlZCB3aXRoIGFueSBjcHAtbGlrZSBkZWZpbmVzIHNlZW4gb24gYXJndi4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgIEZJWE1FOiBBZGQgc29tZXRoaW5nIGxpa2UgYC1EX19BQ1RJT05fU0NSSVBUXzJfXycgdG8gaXQgc28gd2UgY2FuICAgICAgICAgICAgICAgICAgICAgICAgCiAgIGRpZmZlcmVudGlhdGUgd2hlbiB3ZSdyZSBjb21waWxpbmcgYWN0aW9uIHNjcmlwdCwgYW5kIHdoZW4gYyAqKQpsZXQgZGVmaW5lcyA9IHJlZiAoW10gOiBzdHJpbmcgbGlzdCkKCigqIEZpbGxlZCB3aXRoIHRoZSByZXN0IG9mIGNvbW1hbmQtbGluZSBhcmd1bWVudHMgKikKbGV0IGFyZ3MgPSByZWYgKFtdIDogc3RyaW5nIGxpc3QpCgooKiBMaXN0IG9mIGNvbW1hbmQtb3B0aW9ucyB3ZSdkIGxpa2UgdG8gcHJvY2VzcyAqKQpsZXQgb3B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