Guest User

Untitled

a guest
Feb 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. --- cmdline.ml.orig 2013-05-03 11:05:03.000000000 +0000
  2. +++ cmdline.ml 2013-09-03 11:07:07.142400000 +0000
  3. @@ -200,6 +200,152 @@
  4. ]
  5.  
  6.  
  7. +let unquote_win str =
  8. + let len = String.length str in
  9. + if len < 2 then
  10. + str
  11. + else if str.[0] <> '"' || ( str.[len - 1 ] <> '"' && str.[len-1] <> '\\' ) then
  12. + str
  13. + else if len = 2 then
  14. + ""
  15. + else
  16. + let b = Buffer.create (len - 2 ) in
  17. + let rec loop i =
  18. + if i <= len - 1 then (
  19. + match str.[i] with
  20. + | '\\'-> loop_bs 0 i
  21. + | '"' ->
  22. + if i <> len - 1 then (
  23. + if follow_only_bs (succ i) then
  24. + loop_bs 0 (succ i)
  25. + else (
  26. + Buffer.add_char b '"' ;
  27. + loop (succ i)
  28. + )
  29. + )
  30. + | c ->
  31. + Buffer.add_char b c ;
  32. + loop (succ i)
  33. + )
  34. + and follow_only_bs i =
  35. + if i >= len then
  36. + true
  37. + else
  38. + match str.[i] with
  39. + | '\\' -> follow_only_bs (succ i )
  40. + | _ -> false
  41. + and loop_bs n i =
  42. + if i = len - 1 then (
  43. + match str.[i] with
  44. + | '\\'-> add_bs (n+1)
  45. + | _ -> add_bs n
  46. + )
  47. + else (
  48. + match str.[i] with
  49. + | '"' ->
  50. + add_bs (n/2);
  51. + if follow_only_bs (succ i) = false ; then
  52. + Buffer.add_char b '"' ;
  53. + loop (succ i)
  54. + | '\\' ->
  55. + loop_bs (succ n) (succ i)
  56. + | c ->
  57. + add_bs n ;
  58. + loop i
  59. + )
  60. + and add_bs n =
  61. + for j = 1 to n do Buffer.add_char b '\\'; done
  62. + in
  63. + loop 1;
  64. + Buffer.contents b
  65. +
  66. +(*
  67. +let unquote_unix str =
  68. + let len = String.length str in
  69. + if len < 1 then
  70. + str
  71. + else if str.[0] <> '\'' || str.[len - 1] <> '\'' then
  72. + str
  73. + else
  74. + let b = Buffer.create len in
  75. + let rec iter i =
  76. + if i > len - 5 then
  77. + iter_end i
  78. + else
  79. + let c = str.[i] in
  80. + if c = '\'' &&
  81. + str.[i + 1] = '\\' &&
  82. + str.[i + 2] = '\'' &&
  83. + str.[i + 3] = '\''
  84. + then (
  85. + Buffer.add_char b '\'';
  86. + iter (i+4)
  87. + )
  88. + else (
  89. + Buffer.add_char b c;
  90. + iter (i+1)
  91. + )
  92. + and iter_end i =
  93. + if i > len - 2 then
  94. + ()
  95. + else (
  96. + Buffer.add_char b str.[i];
  97. + iter_end (succ i)
  98. + )
  99. + in
  100. + iter 1;
  101. + Buffer.contents b
  102. +
  103. +let unquote =
  104. + match Sys.os_type with
  105. + | "Win32" -> unquote_win
  106. + | _ -> unquote_unix
  107. +
  108. +
  109. +let () =
  110. + let testl =
  111. + [ "" ;
  112. + "\"";
  113. + "\"\"";
  114. + "\"\"\"";
  115. + "\"\"\"\"";
  116. + "\"\"\"\"\"";
  117. + "\"\"\"\"\"\"";
  118. + "\"\"\" \"\"\"";
  119. + " " ;
  120. + "a\\\\\\\\ \\ \\ \\ \\ \\" ;
  121. + "aaa fdasf" ;
  122. + "aaa\ fdasf" ;
  123. + "normal";
  124. + "'";
  125. + "' ";
  126. + "' ";
  127. + " '";
  128. + " '";
  129. + " '";
  130. + "''";
  131. + "'''";
  132. + "''''";
  133. + "'''''";
  134. + "''''''";
  135. + "'''''''";
  136. + "adf'";
  137. + "'asdfa'";
  138. + "'asdf''adsf'";
  139. + "'''asdfdsaf'''asdf''"
  140. + ]
  141. + in
  142. + let f a =
  143. + let a' = unquote (Filename.quote a) in
  144. + assert (a' = a)
  145. + in
  146. + List.iter f testl
  147. +*)
  148. +
  149. +(* currently, a responsefile is only used by the native version of ocaml,
  150. + * not the cygwin-based. *)
  151. +let unquote = unquote_win
  152. +
  153. let flexlinkflags =
  154. let s =
  155. try Sys.getenv "FLEXLINKFLAGS"
  156. @@ -245,36 +391,40 @@
  157. | x :: rest -> x :: tr rest
  158. | [] -> []
  159. in
  160. + let fresponse accu l =
  161. + let len = String.length l in
  162. + if len < 1 then
  163. + l::accu
  164. + else if l.[0] <> '@' then
  165. + l::accu
  166. + else
  167. + let fln = String.sub l 1 (pred len ) in
  168. + if Sys.file_exists fln = false then
  169. + l::accu
  170. + else
  171. + let ch = open_in fln in
  172. + let naccu =
  173. + let ac = ref accu in
  174. + try
  175. + while true do
  176. + ac := (unquote (input_line ch) ) :: !ac
  177. + done;
  178. + assert false
  179. + with
  180. + | End_of_file -> !ac
  181. + in
  182. + close_in ch;
  183. + naccu
  184. + in
  185. +
  186. let args =
  187. - match Array.to_list Sys.argv with
  188. + match List.rev ( Array.fold_left fresponse [] Sys.argv ) with
  189. | pgm :: args -> pgm :: tr (flexlinkflags @ args)
  190. | _ -> assert false
  191. in
  192.  
  193. - let add_file s =
  194. - if s.[0] = '@' then
  195. - let ic = open_in (String.sub s 1 (String.length s - 1)) in
  196. - begin
  197. - try
  198. - while true do
  199. - let fn = input_line ic in
  200. - if fn <> "" then
  201. - (* todo: better unquoting *)
  202. - let fn =
  203. - if fn.[0] = '\"' && fn.[String.length fn - 1] = '\"'
  204. - then String.sub fn 1 (String.length fn - 2)
  205. - else fn
  206. - in
  207. - files := fn :: !files
  208. - done
  209. - with End_of_file -> ()
  210. - end;
  211. - close_in ic
  212. - else
  213. - files := s :: !files
  214. - in
  215. Arg.parse_argv (Array.of_list args) (Arg.align specs)
  216. - add_file usage_msg;
  217. + (fun x -> files := x :: !files) usage_msg;
  218. if !output_file = "" && !mode <> `DUMP then begin
  219. Printf.eprintf
  220. "Please specify an output file (-help to get some usage information)\n";
Add Comment
Please, Sign In to add comment