#spatch -j 44 --no-includes --include-headers --very-quiet @initialize:ocaml@ @@ let seen = Hashtbl.create 101 let bseen = Hashtbl.create 101 let ids = Hashtbl.create 101 exception NotOK let okw = ["needn";"aren";"isn";"wasn";"doesn";"didn";"weren";"shouldn";"couldn";"wouldn";"hasn";"haven";"linux";"hotplug";"cpu";"ifdef";"ifndef";"endif";"struct"] let add i = (if not (Hashtbl.mem ids i) then Hashtbl.add ids i ()); let pieces = Str.split (Str.regexp "_") i in List.iter (fun i -> if not (Hashtbl.mem ids i) then Hashtbl.add ids i ()) pieces; false let vowels = ['a';'e';'i';'o';'u';'y';'A';'E';'I';'O';'U';'Y'] let hasvowel s = try String.iter (fun c -> if List.mem c vowels then raise NotOK) s; false with NotOK -> true let hasconsonant s = try String.iter (fun c -> if not(List.mem c vowels) then raise NotOK) s; false with NotOK -> true let only_letters s = let islower c = 'a' <= c && c <= 'z' in let isupper c = 'A' <= c && c <= 'Z' in try String.iteri (fun i c -> let ok = if i = 0 then islower c || isupper c else islower c in if not ok then raise NotOK) s; true with NotOK -> false let hasthree s = let l = Common.list_of_string s in let rec loop = function a::b::c::d::_ when a = b && b = c && c = d -> false | a::b::c::_ when a = b && b = c -> true | x::xs -> loop xs | [] -> false in loop l let check bad loc p c = if not(Hashtbl.mem seen c) then begin Hashtbl.add seen c (); let pieces = Str.split (Str.regexp "\\b") c in List.iter (fun word -> if String.length word <= 3 || not(only_letters word) || Hashtbl.mem ids word || not(hasvowel word) || not(hasconsonant word) then () else let word = String.uncapitalize_ascii word in if List.mem word okw then () else let res = if hasthree word then [word] else [] in List.iter (fun wd -> Common.hashadd bseen word (loc,word,p)) res) pieces end @identifier@ identifier i : script:ocaml() { add i }; @@ i @r1@ comments c; statement S; position p; @@ S@c@p @script:ocaml@ c << r1.c; p << r1.p; @@ let bad = ref [] in List.iter (function c-> let (cb,ci,ca) = c in List.iter (check bad "before" p) cb; List.iter (check bad "within" p) ci; List.iter (check bad "after" p) ca) c @r2@ comments c; declaration d; position p; @@ d@c@p @script:ocaml@ c << r2.c; p << r2.p; @@ let bad = ref [] in List.iter (function c-> let (cb,ci,ca) = c in List.iter (check bad "before" p) cb; List.iter (check bad "within" p) ci; List.iter (check bad "after" p) ca) c @finalize:ocaml@ bseen << merge.bseen; @@ List.iter (fun bseen -> Hashtbl.iter (fun word l -> match !l with [(loc,word,p)] -> Coccilib.print_main (Printf.sprintf "problem with %s comment word: %s" loc word) p | _ -> ()) bseen) bseen