Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- cmdline.ml.orig 2013-05-03 11:05:03.000000000 +0000
- +++ cmdline.ml 2013-09-03 11:07:07.142400000 +0000
- @@ -200,6 +200,152 @@
- ]
- +let unquote_win str =
- + let len = String.length str in
- + if len < 2 then
- + str
- + else if str.[0] <> '"' || ( str.[len - 1 ] <> '"' && str.[len-1] <> '\\' ) then
- + str
- + else if len = 2 then
- + ""
- + else
- + let b = Buffer.create (len - 2 ) in
- + let rec loop i =
- + if i <= len - 1 then (
- + match str.[i] with
- + | '\\'-> loop_bs 0 i
- + | '"' ->
- + if i <> len - 1 then (
- + if follow_only_bs (succ i) then
- + loop_bs 0 (succ i)
- + else (
- + Buffer.add_char b '"' ;
- + loop (succ i)
- + )
- + )
- + | c ->
- + Buffer.add_char b c ;
- + loop (succ i)
- + )
- + and follow_only_bs i =
- + if i >= len then
- + true
- + else
- + match str.[i] with
- + | '\\' -> follow_only_bs (succ i )
- + | _ -> false
- + and loop_bs n i =
- + if i = len - 1 then (
- + match str.[i] with
- + | '\\'-> add_bs (n+1)
- + | _ -> add_bs n
- + )
- + else (
- + match str.[i] with
- + | '"' ->
- + add_bs (n/2);
- + if follow_only_bs (succ i) = false ; then
- + Buffer.add_char b '"' ;
- + loop (succ i)
- + | '\\' ->
- + loop_bs (succ n) (succ i)
- + | c ->
- + add_bs n ;
- + loop i
- + )
- + and add_bs n =
- + for j = 1 to n do Buffer.add_char b '\\'; done
- + in
- + loop 1;
- + Buffer.contents b
- +
- +(*
- +let unquote_unix str =
- + let len = String.length str in
- + if len < 1 then
- + str
- + else if str.[0] <> '\'' || str.[len - 1] <> '\'' then
- + str
- + else
- + let b = Buffer.create len in
- + let rec iter i =
- + if i > len - 5 then
- + iter_end i
- + else
- + let c = str.[i] in
- + if c = '\'' &&
- + str.[i + 1] = '\\' &&
- + str.[i + 2] = '\'' &&
- + str.[i + 3] = '\''
- + then (
- + Buffer.add_char b '\'';
- + iter (i+4)
- + )
- + else (
- + Buffer.add_char b c;
- + iter (i+1)
- + )
- + and iter_end i =
- + if i > len - 2 then
- + ()
- + else (
- + Buffer.add_char b str.[i];
- + iter_end (succ i)
- + )
- + in
- + iter 1;
- + Buffer.contents b
- +
- +let unquote =
- + match Sys.os_type with
- + | "Win32" -> unquote_win
- + | _ -> unquote_unix
- +
- +
- +let () =
- + let testl =
- + [ "" ;
- + "\"";
- + "\"\"";
- + "\"\"\"";
- + "\"\"\"\"";
- + "\"\"\"\"\"";
- + "\"\"\"\"\"\"";
- + "\"\"\" \"\"\"";
- + " " ;
- + "a\\\\\\\\ \\ \\ \\ \\ \\" ;
- + "aaa fdasf" ;
- + "aaa\ fdasf" ;
- + "normal";
- + "'";
- + "' ";
- + "' ";
- + " '";
- + " '";
- + " '";
- + "''";
- + "'''";
- + "''''";
- + "'''''";
- + "''''''";
- + "'''''''";
- + "adf'";
- + "'asdfa'";
- + "'asdf''adsf'";
- + "'''asdfdsaf'''asdf''"
- + ]
- + in
- + let f a =
- + let a' = unquote (Filename.quote a) in
- + assert (a' = a)
- + in
- + List.iter f testl
- +*)
- +
- +(* currently, a responsefile is only used by the native version of ocaml,
- + * not the cygwin-based. *)
- +let unquote = unquote_win
- +
- let flexlinkflags =
- let s =
- try Sys.getenv "FLEXLINKFLAGS"
- @@ -245,36 +391,40 @@
- | x :: rest -> x :: tr rest
- | [] -> []
- in
- + let fresponse accu l =
- + let len = String.length l in
- + if len < 1 then
- + l::accu
- + else if l.[0] <> '@' then
- + l::accu
- + else
- + let fln = String.sub l 1 (pred len ) in
- + if Sys.file_exists fln = false then
- + l::accu
- + else
- + let ch = open_in fln in
- + let naccu =
- + let ac = ref accu in
- + try
- + while true do
- + ac := (unquote (input_line ch) ) :: !ac
- + done;
- + assert false
- + with
- + | End_of_file -> !ac
- + in
- + close_in ch;
- + naccu
- + in
- +
- let args =
- - match Array.to_list Sys.argv with
- + match List.rev ( Array.fold_left fresponse [] Sys.argv ) with
- | pgm :: args -> pgm :: tr (flexlinkflags @ args)
- | _ -> assert false
- in
- - let add_file s =
- - if s.[0] = '@' then
- - let ic = open_in (String.sub s 1 (String.length s - 1)) in
- - begin
- - try
- - while true do
- - let fn = input_line ic in
- - if fn <> "" then
- - (* todo: better unquoting *)
- - let fn =
- - if fn.[0] = '\"' && fn.[String.length fn - 1] = '\"'
- - then String.sub fn 1 (String.length fn - 2)
- - else fn
- - in
- - files := fn :: !files
- - done
- - with End_of_file -> ()
- - end;
- - close_in ic
- - else
- - files := s :: !files
- - in
- Arg.parse_argv (Array.of_list args) (Arg.align specs)
- - add_file usage_msg;
- + (fun x -> files := x :: !files) usage_msg;
- if !output_file = "" && !mode <> `DUMP then begin
- Printf.eprintf
- "Please specify an output file (-help to get some usage information)\n";
Add Comment
Please, Sign In to add comment