diff options
author | Hans Bolinder <[email protected]> | 2012-12-19 13:02:12 +0100 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2013-01-02 10:15:18 +0100 |
commit | 903090bd50afa4399066694f81302a164ecc5c28 (patch) | |
tree | 38c309b6e216623e07b6db510a61b49fd2f59872 /lib | |
parent | 567115dab453dd05b74b28c5130582c14fe67bc5 (diff) | |
download | otp-903090bd50afa4399066694f81302a164ecc5c28.tar.gz otp-903090bd50afa4399066694f81302a164ecc5c28.tar.bz2 otp-903090bd50afa4399066694f81302a164ecc5c28.zip |
[tools] Add Unicode support for Cover
Code written by Siri Hansen.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tools/src/cover.erl | 65 |
1 files changed, 46 insertions, 19 deletions
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, - "<html>\n" - "<head><title>~s</title></head>" - "<body bgcolor=white text=black>\n" - "<pre>\n", - [OutFile]); + Encoding = encoding(ErlFile), + Header = + ["<!DOCTYPE HTML PUBLIC " + "\"-//W3C//DTD HTML 3.2 Final//EN\">\n" + "<html>\n" + "<head>\n" + "<meta http-equiv=\"Content-Type\"" + " content=\"text/html; charset=", + Encoding,"\"/>\n" + "<title>",OutFile,"</title>\n" + "</head>" + "<body style='background-color: white;" + " color: black'>\n" + "<pre>\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". |