Switching to tbs
[imt.git] / cl.ml
blob3f8692e80c6c3c724819ce47dbea565474d82b6e
1 let debug = false
2 let src_file_re = Str.regexp "^\\([ \t]*\\)\\(.*\\)([0-9]+) :"
3 let inc_file_re = Str.regexp "Cannot open include file: '\\(.*\\)'"
5 let process_include_err s =
6 let rec loop pos =
7 let opt_pos2 =
8 try
9 Some (Str.search_forward inc_file_re s pos)
10 with Not_found ->
11 None
13 match opt_pos2 with
14 | Some pos2 ->
15 let b, e = Utils.safe_group_extents 1 in
16 let win_path = String.sub s b (e - b) in
17 prerr_string (String.sub s pos b);
18 Path.prerr true win_path;
19 prerr_string (String.sub s e (String.length s - e));
20 loop e
21 | None ->
22 prerr_string (String.sub s pos (String.length s - pos))
24 loop 0
26 let process_cl_output_line s =
27 (* prerr_endline s; *)
28 if Str.string_match src_file_re s 0
29 then
30 let group1 = Utils.safe_group 1 s in
31 let win_path = Utils.safe_group 2 s in
32 prerr_string group1;
33 Path.prerr false win_path;
34 let gend = Utils.safe_group_end 2 in
35 process_include_err (String.sub s gend (String.length s - gend));
36 prerr_newline ()
37 else
38 begin
39 process_include_err s;
40 prerr_newline ()
41 end
43 let invoke argv arg_start =
44 let tool = Utils.tool_name "cl" in
45 let args = Utils.make_arg_string Path.check_and_modify_absolute argv arg_start in
46 if Utils.contains_question argv arg_start
47 then
48 let command = Utils.construct_args tool args "" in
49 let ic = Unix.open_process_in command in
50 Utils.iter_crlf_chan ic print_endline;
51 let code = Utils.close_process_in ic in
52 code
53 else
54 let command = Utils.construct_args tool args "-nologo" in
55 let ic = Unix.open_process_in command in
56 Utils.iter_crlf_chan ic process_cl_output_line;
57 let code = Utils.close_process_in ic in
58 code