~ubuntu-branches/debian/sid/frama-c/sid

« back to all changes in this revision

Viewing changes to tests/slicing/libAnim.ml

  • Committer: Bazaar Package Importer
  • Author(s): Mehdi Dogguy
  • Date: 2009-06-03 08:19:25 UTC
  • Revision ID: james.westby@ubuntu.com-20090603081925-kihvxvt0wy3zc4ar
Tags: upstream-20081201.dfsg
ImportĀ upstreamĀ versionĀ 20081201.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(* Some useful function to use the graphical representation of a slicing
 
2
* project. (see tests/slicing/anim.ml for a test) *)
 
3
(*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
 
4
 
 
5
let use_dot =
 
6
  if (Unix.WEXITED 0) = Unix.system ("which dot > /dev/null 2>&1") then
 
7
    true
 
8
  else false
 
9
 
 
10
(* function to append [string_of_int n] on 3 char to basename. *)
 
11
let nth_name basename n = 
 
12
  assert (n < 1000);
 
13
  let str_n = string_of_int n in
 
14
  let str_n = if n < 100  then ("0"^str_n) else str_n in
 
15
  let str_n = if n < 10   then ("0"^str_n) else str_n in
 
16
  basename^"."^str_n
 
17
;;
 
18
 
 
19
(* generate the nth .jpg file (generate to .dot file and then remove it) *)
 
20
let print_proj basename title proj n =
 
21
  let name = nth_name basename n in
 
22
  let dot_name = (name^".dot") in
 
23
  let jpg_name = (name^".jpg") in
 
24
  !Db.Slicing.Project.print_dot ~filename:dot_name ~title:title proj;
 
25
  if use_dot then
 
26
    ignore (Sys.command ("dot -Tjpg -o "^jpg_name^" "^dot_name^" 2>/dev/null"));
 
27
  Sys.remove dot_name;
 
28
  n+1
 
29
;;
 
30
 
 
31
(* apply all requests of the project and generate a .jpg file for each step.
 
32
* (begin at number [n])
 
33
*)
 
34
let build_all_graphs basename title proj first_n =
 
35
  Format.printf "Processing %s : " basename;
 
36
  let rec next n =
 
37
    Format.printf ".@?";
 
38
    try
 
39
      !Db.Slicing.Request.apply_next_internal proj;
 
40
      let title = title^" ("^(string_of_int (n - first_n))^")" in
 
41
      let n = print_proj basename title proj n in
 
42
      next n
 
43
    with Not_found -> n
 
44
  in
 
45
  let next_num = next first_n in Format.printf "\n"; next_num
 
46
;;
 
47
 
 
48
let all_files basename = basename^".*.jpg ";;
 
49
let display_cmd basename = "display -resize 1000x500 "^(all_files basename);;
 
50
let clean_cmd basename = "rm -f "^(all_files basename);;
 
51
let build_anim_cmd basename=
 
52
  "convert -delay 10 -loop 1 "^(all_files basename)^" "^basename^".gif";;
 
53
 
 
54
let print_help basename =
 
55
  let display_cmd = display_cmd basename in
 
56
  let clean_cmd = clean_cmd basename in
 
57
  Format.printf "To display '%s' use :\n\t%s\n" basename display_cmd;
 
58
  Format.printf "\t- use : Space/Backspace to see next/previous step\n";
 
59
  Format.printf "\t- use : 'q' to quit\n@\n";
 
60
  Format.printf
 
61
    "After that, you can clear the generated files with:\n\t%s\n" clean_cmd
 
62
 
 
63
let remove_all_files basename = 
 
64
  Format.printf "removing generated .jpg files\n";
 
65
  ignore (Sys.command (clean_cmd basename))
 
66
 
 
67
(*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)