From 903090bd50afa4399066694f81302a164ecc5c28 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Wed, 19 Dec 2012 13:02:12 +0100 Subject: [tools] Add Unicode support for Cover Code written by Siri Hansen. --- lib/tools/src/cover.erl | 65 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/tools/src/cover.erl b/lib/tools/src/cover.erl index 10f14b0a49..5a908174d7 100644 --- a/lib/tools/src/cover.erl +++ b/lib/tools/src/cover.erl @@ -2087,30 +2087,40 @@ do_analyse_to_file(Module, OutFile, ErlFile, HTML) -> case file:open(OutFile, [write]) of {ok, OutFd} -> if HTML -> - io:format(OutFd, - "\n" - "~s" - "\n" - "
\n",
-				      [OutFile]);
+                           Encoding = encoding(ErlFile),
+                           Header =
+                               ["\n"
+                                "\n"
+                                "\n"
+                                "\n"
+                                "",OutFile,"\n"
+                                ""
+                                "\n"
+                                "
\n"],
+                           file:write(OutFd,Header);
 		       true -> ok
 		    end,
 		    
 		    %% Write some initial information to the output file
 		    {{Y,Mo,D},{H,Mi,S}} = calendar:local_time(),
-		    io:format(OutFd, "File generated from ~s by COVER "
-			             "~p-~s-~s at ~s:~s:~s~n",
-			      [ErlFile,
-			       Y,
-			       string:right(integer_to_list(Mo), 2, $0),
-			       string:right(integer_to_list(D),  2, $0),
-			       string:right(integer_to_list(H),  2, $0),
-			       string:right(integer_to_list(Mi), 2, $0),
-			       string:right(integer_to_list(S),  2, $0)]),
-		    io:format(OutFd, "~n"
-			             "**************************************"
-			             "**************************************"
-			             "~n~n", []),
+                   Timestamp =
+                       io_lib:format("~p-~s-~s at ~s:~s:~s",
+                                     [Y,
+                                      string:right(integer_to_list(Mo), 2, $0),
+                                      string:right(integer_to_list(D),  2, $0),
+                                      string:right(integer_to_list(H),  2, $0),
+                                      string:right(integer_to_list(Mi), 2, $0),
+                                      string:right(integer_to_list(S),  2, $0)]),
+                    file:write(OutFd,
+                               ["File generated from ",ErlFile," by COVER ",
+                                Timestamp,"\n\n"
+                                "**************************************"
+                                "**************************************"
+                                "\n\n"]),
 
 		    print_lines(Module, InFd, OutFd, 1, HTML),
 		    
@@ -2405,3 +2415,20 @@ pmap(Fun, [], [], Limit, Cnt, Acc) ->
 	{'DOWN', _Ref, process, X, _} when is_pid(X) ->
 	    pmap(Fun, [], [], Limit, Cnt - 1, Acc)
     end.
+
+%%%-----------------------------------------------------------------
+%%% Read encoding from source file
+encoding(File) ->
+    Encoding =
+       case epp:read_encoding(File) of
+           none ->
+               epp:default_encoding();
+           E ->
+               E
+       end,
+    html_encoding(Encoding).
+
+html_encoding(latin1) ->
+    "iso-8859-1";
+html_encoding(utf8) ->
+    "utf-8".
-- 
cgit v1.2.3