1 module StringSet
= Set.Make
(struct type t
= string let compare = compare end)
4 if line
.[String.length line
- 1] = '
\r'
6 String.sub line
0 (String.length line
- 1)
10 let safe_input_line ic
=
17 let iter_crlf_chan ic f
=
19 let opt_line = safe_input_line ic
in
29 let fold_crlf_chan ic f init
=
31 let opt_line = safe_input_line ic
in
34 let accu = f
(decrlf line
) accu in
41 let process_status = function
42 | Unix.WEXITED code
->
44 | Unix.WSIGNALED signum
->
45 prerr_string
"signalled ";
49 | Unix.WSTOPPED signum
->
50 prerr_string
"stopped ";
55 let close_process_in ic
=
56 let status = Unix.close_process_in ic
in
59 let close_process_full channels
=
60 let status = Unix.close_process_full channels
in
63 let make_arg_string f argv pos
=
65 if i
>= Array.length argv
70 let accu = s :: accu in
73 let arg_list = loop [] pos
in
74 String.concat
" " arg_list
76 let safe_group_extents group_nr
=
78 Str.group_beginning group_nr
, Str.group_end group_nr
80 failwith
"Internal error (cannot get group extents)"
82 let safe_group group_nr
s =
84 Str.matched_group group_nr
s
86 failwith
"Internal error (cannot find matched group)"
88 let safe_group_end group_nr
=
90 Str.group_end group_nr
92 failwith
"Internal error (cannot find group end)"
94 let some_action f d
= function
100 let array_find_from p a pos
=
102 if i
>= Array.length a
106 p a
.(i
) || loop (succ i
)
110 let question_pred s = s = "/?" || s = "-?"
111 let contains_question argv arg_start
=
112 array_find_from question_pred argv arg_start
116 Unix.getenv
("IMT_" ^
(String.uppercase
s))
120 let build_reject_list () =
123 Some
(Unix.getenv
"IMT_REJ")
132 let l = String.length
rejs in
133 let rec collect accu old_pos
=
140 String.index_from
rejs old_pos '
:'
144 let s = String.sub
rejs old_pos
(pos - old_pos
) in
147 if Sys.os_type
= "Win32"
149 Str.regexp_string_case_fold
s
155 collect accu (pos + 1)
159 let quotere = Str.regexp
"\""
162 if String.contains
s ' '
164 let ss = Str.global_substitute
quotere (fun _
-> "\\\"") s in
169 let output_quoted_path oc
s =
170 if String.contains
s ' '
172 let ss = Str.global_substitute
quotere (fun _
-> "\\\"") s in
179 let reject_path s = function
182 let rec find = function
185 if Str.string_partial_match rejre
s 0
193 let construct_args tool args extra
=
196 let via = Sys.getenv
"IMT_VIA" in
199 let s = Sys.getenv
"IMT_VIA_PASS_NAME" in
205 let s = Sys.getenv
"IMT_VIA_PASS_ARGS" in
206 args ^
" " ^
s ^
" " ^
quote extra
210 via ^
" " ^
s1 ^
" " ^ s2
212 tool ^
" " ^ args ^
" " ^ extra
216 (* let construct_args tool args extra = *)
217 (* let s = construct_args tool args extra in *)
218 (* prerr_endline tool; *)
219 (* prerr_endline args; *)
220 (* prerr_endline extra; *)
221 (* prerr_endline s; *)