Coccinelle release 1.0.0-rc13
[bpt/coccinelle.git] / ocaml / coccilib.ml
1 (* Function table management *)
2
3 type pos = { current_element : string;
4 file :string ;
5 line : int;
6 col : int;
7 line_end : int;
8 col_end : int; }
9
10 type param_type =
11 Pos of pos list
12 | Str of string
13 | Type of Ast_c.fullType
14 | Init of Ast_c.initialiser
15 | InitList of Ast_c.initialiser Ast_c.wrap2 list
16 | Int of int
17 | Param of Ast_c.parameterType
18 | ParamList of Ast_c.parameterType Ast_c.wrap2 list
19 | Expr of Ast_c.expression
20 | ExprList of Ast_c.argument Ast_c.wrap2 list
21 | Decl of Ast_c.declaration
22 | Field of Ast_c.field
23 | FieldList of Ast_c.field list
24 | Stmt of Ast_c.statement
25
26 let fcts : (string, param_type list -> string ref list -> unit) Hashtbl.t =
27 Hashtbl.create 11 (* Use prime number *)
28
29 (* ---------------------------------------------------------------------- *)
30 (* Match management *)
31
32 let inc_match = ref true
33 let include_match x = inc_match := x
34
35 let exited = ref false
36 let exit _ = exited := true
37
38 let dir () = !Flag.dir
39
40 (* ---------------------------------------------------------------------- *)
41 (* org mode *)
42
43 let build_link p msg color =
44 Printf.sprintf
45 "[[view:%s::face=%s::linb=%d::colb=%d::cole=%d][%s]]"
46 p.file color p.line p.col p.col_end msg
47
48 let print_todo ?color:(color="ovl-face1") ?msg:(msg="") p =
49 let msg =
50 if msg = ""
51 then Printf.sprintf "%s::%d" p.file p.line
52 else msg in
53 Printf.printf "* TODO %s\n" (build_link p msg color)
54
55 let print_link ?color:(color="ovl-face2") ?msg:(msg="") p =
56 let msg =
57 if msg = ""
58 then Printf.sprintf "%s::%d" p.file p.line
59 else msg in
60 Printf.printf "%s\n" (build_link p msg color)
61
62 let print_safe_todo ?color:(color="ovl-face1") ?msg:(msg="") p =
63 let msg = String.concat "@(" (Str.split_delim (Str.regexp_string "[") msg) in
64 let msg = String.concat ")" (Str.split_delim (Str.regexp_string "]") msg) in
65 print_todo ~color:color ~msg:msg p
66
67 let print_safe_link ?color:(color="ovl-face2") ?msg:(msg="") p =
68 let msg = String.concat "@(" (Str.split_delim (Str.regexp_string "[") msg) in
69 let msg = String.concat ")" (Str.split_delim (Str.regexp_string "]") msg) in
70 print_link ~color:color ~msg:msg p
71
72 (*
73 print_main, print_sec and print_secs
74 *)
75 let print_main ?color:(color="ovl-face1") msg ps =
76 let p = List.hd ps in
77 let oldmsgfmt =
78 if msg == ""
79 then Printf.sprintf "%s::%d" p.file p.line
80 else Printf.sprintf "%s %s::%d" msg p.file p.line in
81 print_todo ~color:color ~msg:oldmsgfmt p
82
83 let print_sec ?color:(color="ovl-face2") msg ps =
84 print_link ~color:color ~msg:msg (List.hd ps)
85
86 let print_secs ?color:(color="ovl-face2") msg ps =
87 List.iter (function i -> print_link ~color:color ~msg:msg i) ps