[BUG0000035: code folding has been implemented. bisect@x9c.fr**20090503160346 It allows to fold/unfold the part of the code that have little interest (that is lines with no point, or lines with only visited points). Code folding can be disabled by using the '-no-folding' command line switch. ] { hunk ./src/report.ml 33 +let no_folding = ref false + hunk ./src/report.ml 58 - " Disable the navigation bar (HTML only)") + " Disable the navigation bar (HTML only)") ; + ("-no-folding", + Arg.Set no_folding, + " Disable code folding (HTML only)") hunk ./src/report.ml 86 - ReportHTML.output verbose dir !tab_size !title !no_navbar data + ReportHTML.output verbose dir !tab_size !title !no_navbar !no_folding data hunk ./src/reportHTML.ml 248 -let output_html verbose tab_size title no_navbar in_file out_file visited = +let output_html verbose tab_size title no_navbar no_folding in_file out_file script_file script_file_basename visited = hunk ./src/reportHTML.ml 285 + (if no_folding then + [] + else + [ " " ]) @ hunk ./src/reportHTML.ml 300 - "title", title ] + "title", title ; + "script_file", script_file_basename ] hunk ./src/reportHTML.ml 317 + let fold_links = + if no_folding then + [] + else + [ "
" ]
+ ([ " " ;
+ " " ;
+ " " ;
+ "
" ;
+ "
" ;
+ "
" ;
+ " Source:" ;
+ "
" ] @
+ fold_links @
+ [ " " ])
hunk ./src/reportHTML.ml 340
+ let fold_starts = ref [] in
+ let fold_ends = ref [] in
hunk ./src/reportHTML.ml 360
- let cls, nav_color, nav_elements = match visited, unvisited with
- | false, false -> "lineNone", "gray", ""
- | true, false -> "lineAllVisited", "gray", ""
- | false, true -> "lineAllUnvisited", "red", jump
- | true, true -> "lineMixed", "yellow", jump in
+ let cls, nav_color, nav_elements, foldable = match visited, unvisited with
+ | false, false -> "lineNone", "gray", "", true
+ | true, false -> "lineAllVisited", "gray", "", true
+ | false, true -> "lineAllUnvisited", "red", jump, false
+ | true, true -> "lineMixed", "yellow", jump, false in
+ let starting_fold =
+ if foldable && (List.length !fold_starts) = (List.length !fold_ends) then begin
+ fold_starts := !line_no :: !fold_starts;
+ output_strings
+ [ " " ]
+ [ "line_no", (Printf.sprintf "%06d" !line_no) ]
+ out_channel;
+ true
+ end else
+ false in
+ if (not foldable) && (List.length !fold_starts) <> (List.length !fold_ends) then begin
+ fold_ends := (pred !line_no) :: !fold_ends;
+ output_strings
+ [ " " ]
+ [ ]
+ out_channel
+ end;
hunk ./src/reportHTML.ml 387
+ let icon =
+ if no_folding then
+ ""
+ else if starting_fold then
+ Printf.sprintf
+ "
"
+ !line_no
+ else if foldable then
+ "
"
+ else
+ "
" in
hunk ./src/reportHTML.ml 399
- [ " $(line_no)| $(line)" ]
+ [ " $(icon)$(line_no)| $(line)" ]
hunk ./src/reportHTML.ml 402
- "line", (if line' = "" then " " else line') ]
+ "line", (if line' = "" then " " else line') ;
+ "icon", icon ]
hunk ./src/reportHTML.ml 408
+ if (List.length !fold_starts) <> (List.length !fold_ends) then begin
+ fold_ends := (pred !line_no) :: !fold_ends;
+ output_strings
+ [ " " ]
+ [ ]
+ out_channel
+ end;
hunk ./src/reportHTML.ml 440
+ Common.try_out_channel
+ false
+ script_file
+ (fun channel ->
+ output_strings
+ [ "var texts = new Array();" ;
+ "var states = new Array();" ;
+ "" ]
+ []
+ channel;
+ List.iter2
+ (fun fstart fend ->
+ output_strings
+ [ "texts['$(id)'] = '$(icon) code folded from line $(start) to line $(end)';" ;
+ "states['$(id)'] = false;" ]
+ [ "id", (Printf.sprintf "fold%06d" fstart) ;
+ "icon",
+ (Printf.sprintf
+ "
"
+ fstart) ;
+ "start", string_of_int fstart ;
+ "end", string_of_int fend ]
+ channel)
+ (List.rev !fold_starts)
+ (List.rev !fold_ends);
+ output_strings
+ [ "" ;
+ "function fold(id) {" ;
+ " tmp = document.all[id].innerHTML;" ;
+ " document.all[id].innerHTML = texts[id];" ;
+ " texts[id] = tmp;" ;
+ " states[id] = !(states[id]);" ;
+ "}" ;
+ "" ;
+ "function unfoldAll() {" ;
+ " for (key in states) {" ;
+ " if (states[key]) {" ;
+ " fold(key);" ;
+ " }" ;
+ " }" ;
+ "}" ;
+ "" ;
+ "function foldAll() {" ;
+ " for (key in states) {" ;
+ " if (!(states[key])) {" ;
+ " fold(key);" ;
+ " }" ;
+ " }" ;
+ "}" ]
+ []
+ channel)
hunk ./src/reportHTML.ml 499
-let output verbose dir tab_size title no_navbar data =
+let blank_png = [|
+ 0x89; 0x50; 0x4e; 0x47; 0x0d; 0x0a; 0x1a; 0x0a;
+ 0x00; 0x00; 0x00; 0x0d; 0x49; 0x48; 0x44; 0x52;
+ 0x00; 0x00; 0x00; 0x0a; 0x00; 0x00; 0x00; 0x0a;
+ 0x08; 0x06; 0x00; 0x00; 0x00; 0x8d; 0x32; 0xcf;
+ 0xbd; 0x00; 0x00; 0x00; 0x01; 0x73; 0x52; 0x47;
+ 0x42; 0x00; 0xae; 0xce; 0x1c; 0xe9; 0x00; 0x00;
+ 0x00; 0x06; 0x62; 0x4b; 0x47; 0x44; 0x00; 0xff;
+ 0x00; 0xff; 0x00; 0xff; 0xa0; 0xbd; 0xa7; 0x93;
+ 0x00; 0x00; 0x00; 0x09; 0x70; 0x48; 0x59; 0x73;
+ 0x00; 0x00; 0x0b; 0x13; 0x00; 0x00; 0x0b; 0x13;
+ 0x01; 0x00; 0x9a; 0x9c; 0x18; 0x00; 0x00; 0x00;
+ 0x07; 0x74; 0x49; 0x4d; 0x45; 0x07; 0xd9; 0x05;
+ 0x03; 0x0e; 0x18; 0x19; 0xcf; 0x5e; 0xda; 0x4a;
+ 0x00; 0x00; 0x00; 0x0e; 0x49; 0x44; 0x41; 0x54;
+ 0x18; 0xd3; 0x63; 0x60; 0x18; 0x05; 0x83; 0x13;
+ 0x00; 0x00; 0x01; 0x9a; 0x00; 0x01; 0x0b; 0xa2;
+ 0x9d; 0x1f; 0x00; 0x00; 0x00; 0x00; 0x49; 0x45;
+ 0x4e; 0x44; 0xae; 0x42; 0x60; 0x82
+|]
+
+let dash_png = [|
+ 0x89; 0x50; 0x4e; 0x47; 0x0d; 0x0a; 0x1a; 0x0a;
+ 0x00; 0x00; 0x00; 0x0d; 0x49; 0x48; 0x44; 0x52;
+ 0x00; 0x00; 0x00; 0x0a; 0x00; 0x00; 0x00; 0x0a;
+ 0x08; 0x06; 0x00; 0x00; 0x00; 0x8d; 0x32; 0xcf;
+ 0xbd; 0x00; 0x00; 0x00; 0x01; 0x73; 0x52; 0x47;
+ 0x42; 0x00; 0xae; 0xce; 0x1c; 0xe9; 0x00; 0x00;
+ 0x00; 0x06; 0x62; 0x4b; 0x47; 0x44; 0x00; 0xff;
+ 0x00; 0xff; 0x00; 0xff; 0xa0; 0xbd; 0xa7; 0x93;
+ 0x00; 0x00; 0x00; 0x09; 0x70; 0x48; 0x59; 0x73;
+ 0x00; 0x00; 0x0b; 0x13; 0x00; 0x00; 0x0b; 0x13;
+ 0x01; 0x00; 0x9a; 0x9c; 0x18; 0x00; 0x00; 0x00;
+ 0x07; 0x74; 0x49; 0x4d; 0x45; 0x07; 0xd9; 0x05;
+ 0x03; 0x0e; 0x1b; 0x28; 0xb5; 0xad; 0x89; 0xb3;
+ 0x00; 0x00; 0x00; 0x1e; 0x49; 0x44; 0x41; 0x54;
+ 0x18; 0xd3; 0x63; 0x60; 0xa0; 0x39; 0x70; 0x71;
+ 0x71; 0xf9; 0xef; 0xe2; 0xe2; 0xf2; 0x1f; 0x5d;
+ 0x9c; 0x89; 0x58; 0x03; 0x86; 0x82; 0x42; 0xea;
+ 0x03; 0x00; 0x56; 0x54; 0x03; 0xa1; 0x79; 0x35;
+ 0xf3; 0x91; 0x00; 0x00; 0x00; 0x00; 0x49; 0x45;
+ 0x4e; 0x44; 0xae; 0x42; 0x60; 0x82
+|]
+
+let minus_png = [|
+ 0x89; 0x50; 0x4e; 0x47; 0x0d; 0x0a; 0x1a; 0x0a;
+ 0x00; 0x00; 0x00; 0x0d; 0x49; 0x48; 0x44; 0x52;
+ 0x00; 0x00; 0x00; 0x0a; 0x00; 0x00; 0x00; 0x0a;
+ 0x08; 0x02; 0x00; 0x00; 0x00; 0x02; 0x50; 0x58;
+ 0xea; 0x00; 0x00; 0x00; 0x01; 0x73; 0x52; 0x47;
+ 0x42; 0x00; 0xae; 0xce; 0x1c; 0xe9; 0x00; 0x00;
+ 0x00; 0x2e; 0x49; 0x44; 0x41; 0x54; 0x18; 0xd3;
+ 0x63; 0x60; 0xc0; 0x0b; 0x18; 0x19; 0x18; 0x18;
+ 0xfe; 0xff; 0xff; 0x8f; 0x5d; 0x8e; 0x91; 0x91;
+ 0x09; 0xbf; 0x6e; 0x02; 0xd2; 0x0c; 0xb8; 0x0c;
+ 0x87; 0x08; 0x12; 0xd0; 0xcd; 0x82; 0xc7; 0x00;
+ 0xc2; 0xba; 0x89; 0x70; 0x1a; 0x1e; 0x00; 0x00;
+ 0x96; 0x20; 0x0c; 0x07; 0xfb; 0x84; 0xbf; 0x6c;
+ 0x00; 0x00; 0x00; 0x00; 0x49; 0x45; 0x4e; 0x44;
+ 0xae; 0x42; 0x60; 0x82
+|]
+
+let plus_png = [|
+ 0x89; 0x50; 0x4e; 0x47; 0x0d; 0x0a; 0x1a; 0x0a;
+ 0x00; 0x00; 0x00; 0x0d; 0x49; 0x48; 0x44; 0x52;
+ 0x00; 0x00; 0x00; 0x0a; 0x00; 0x00; 0x00; 0x0a;
+ 0x08; 0x02; 0x00; 0x00; 0x00; 0x02; 0x50; 0x58;
+ 0xea; 0x00; 0x00; 0x00; 0x01; 0x73; 0x52; 0x47;
+ 0x42; 0x00; 0xae; 0xce; 0x1c; 0xe9; 0x00; 0x00;
+ 0x00; 0x37; 0x49; 0x44; 0x41; 0x54; 0x18; 0xd3;
+ 0x63; 0x60; 0xc0; 0x0b; 0x18; 0x19; 0x18; 0x18;
+ 0xfe; 0xff; 0xff; 0x8f; 0x5d; 0x8e; 0x91; 0x91;
+ 0x09; 0x8d; 0xcf; 0xc8; 0xc8; 0x88; 0x2c; 0xc2;
+ 0xc4; 0x40; 0x10; 0x60; 0x35; 0x1c; 0x22; 0x48;
+ 0x40; 0x37; 0x0b; 0xb2; 0x5a; 0x88; 0xc5; 0xc8;
+ 0x86; 0x11; 0xa7; 0x1b; 0x8f; 0x23; 0xf0; 0x01;
+ 0x00; 0x63; 0xaf; 0x12; 0x0c; 0x9b; 0x01; 0xf8;
+ 0x13; 0x00; 0x00; 0x00; 0x00; 0x49; 0x45; 0x4e;
+ 0x44; 0xae; 0x42; 0x60; 0x82
+|]
+
+let output_png_files dir =
+ List.iter
+ (fun (file, data) ->
+ output_bytes data (Filename.concat dir file))
+ [ "blank.png", blank_png ;
+ "dash.png", dash_png ;
+ "minus.png", minus_png ;
+ "plus.png", plus_png ]
+
+let output verbose dir tab_size title no_navbar no_folding data =
hunk ./src/reportHTML.ml 593
- let basename = Printf.sprintf "file%04d.html" l in
- let out_file = Filename.concat dir basename in
- let stats = output_html verbose tab_size title no_navbar in_file out_file visited in
- (in_file, basename, stats) :: acc)
+ let basename = Printf.sprintf "file%04d" l in
+ let out_file = (Filename.concat dir basename) ^ ".html" in
+ let script_file = (Filename.concat dir basename) ^ ".js" in
+ let script_file_basename = basename ^ ".js" in
+ let stats = output_html verbose tab_size title no_navbar no_folding in_file out_file script_file script_file_basename visited in
+ (in_file, (basename ^ ".html"), stats) :: acc)
hunk ./src/reportHTML.ml 601
+ output_png_files dir;
hunk ./src/reportHTML.mli 22
-val output : (string -> unit) -> string -> int -> string -> bool -> (string, int array) Hashtbl.t -> unit
-(** [output verbose dir tab_size title no_navbar data] writes all the HTML
- files for [data] in the directory [dir]. [verbose] is used for verbose
+val output : (string -> unit) -> string -> int -> string -> bool -> bool -> (string, int array) Hashtbl.t -> unit
+(** [output verbose dir tab_size title no_navbar no_folding data] writes all the
+ HTML files for [data] in the directory [dir]. [verbose] is used for verbose
hunk ./src/reportHTML.mli 27
- disabled, and [title] is the title for generated pages. *)
+ disabled, [no_folding] indicates whether code folding should be disabled,
+ and [title] is the title for generated pages. *)
hunk ./src/reportUtils.ml 91
+
+let output_bytes data filename =
+ let ch = open_out_bin filename in
+ try
+ Array.iter (output_byte ch) data;
+ close_out_noerr ch
+ with e ->
+ close_out_noerr ch;
+ raise e
hunk ./src/reportUtils.mli 60
+
+val output_bytes : int array -> string -> unit
+(** [output_bytes data filename] creates the file [filename] and writes
+ the bytes from [data] to it. *)
hunk ./tests/report/Makefile 18
- @$(REPORT) -html report *.out
+ @$(REPORT) -no-navbar -no-folding -html report *.out
hunk ./tests/report/reference 45
- 000001| let inf = (*[2]*)ref 0
- 000002| let sup = (*[2]*)ref 3
- 000003|
- 000004| let args = [
- 000005| (*[2]*)("-inf", (Arg.Set_int inf), "inferior bound") ;
- 000006| ("-sup", (Arg.Set_int sup), "superior bound")
- 000007| ]
- 000008|
- 000009| let kind = function
- 000010| | x when (*[9]*)x > 9 || (*[7]*)x < 0 -> (*[2]*)print_endline "not a digit"
- 000011| | _ -> (*[7]*)print_endline "digit"
- 000012|
- 000013| let print x =
- 000014| (*[9]*)print_int x;
- 000015| (*[9]*)print_newline ()
- 000016|
- 000017| let () =
- 000018| (*[2]*)Arg.parse args ignore "report test";
- 000019| (*[2]*)for i = !inf to !sup do
- 000020| (*[9]*)kind i;
- 000021| (*[9]*)print i
- 000022| done
+
+ 000001| let inf = (*[2]*)ref 0
+ 000002| let sup = (*[2]*)ref 3
+ 000003|
+ 000004| let args = [
+ 000005| (*[2]*)("-inf", (Arg.Set_int inf), "inferior bound") ;
+ 000006| ("-sup", (Arg.Set_int sup), "superior bound")
+ 000007| ]
+ 000008|
+ 000009| let kind = function
+ 000010| | x when (*[9]*)x > 9 || (*[7]*)x < 0 -> (*[2]*)print_endline "not a digit"
+ 000011| | _ -> (*[7]*)print_endline "digit"
+ 000012|
+ 000013| let print x =
+ 000014| (*[9]*)print_int x;
+ 000015| (*[9]*)print_newline ()
+ 000016|
+ 000017| let () =
+ 000018| (*[2]*)Arg.parse args ignore "report test";
+ 000019| (*[2]*)for i = !inf to !sup do
+ 000020| (*[9]*)kind i;
+ 000021| (*[9]*)print i
+ 000022| done
+
}