diff options
author | Siri Hansen <[email protected]> | 2013-01-25 18:07:04 +0100 |
---|---|---|
committer | Siri Hansen <[email protected]> | 2013-01-25 18:07:04 +0100 |
commit | 22bb6f45c1c6305d494dc73004d81066d64d2183 (patch) | |
tree | 7bcc885ae80f0db476cbaded8aa9a2b85b7b165e /lib/test_server/src/erl2html2.erl | |
parent | 3fb4def74a64a63fbb2b28aef6c5920d7db3ad6e (diff) | |
parent | 7a056d997ca002a99fec6d303b7077294c1d999b (diff) | |
download | otp-22bb6f45c1c6305d494dc73004d81066d64d2183.tar.gz otp-22bb6f45c1c6305d494dc73004d81066d64d2183.tar.bz2 otp-22bb6f45c1c6305d494dc73004d81066d64d2183.zip |
Merge branch 'siri/unicode'
* siri/unicode:
[test_server] Don't escape : and @ in test log links
[test_server] Don't create latin1 filenames if filename mode is utf8
[test_server] Ensure correct encoding in header for erl2html2:convert
[common_test] Update common test modules to handle unicode
[ts] Use unicode:characters_to_list/2 instead of binary_to_list/1
[test_server] Add tests for unicode support
[test_server] Write link target with correct encoding in erl2html2
[test_server] Update test_server to handle unicode
Update preloaded init.beam
Make arguments given with -s option to erl aware of file name encoding
OTP-10702
OTP-10783
Diffstat (limited to 'lib/test_server/src/erl2html2.erl')
-rw-r--r-- | lib/test_server/src/erl2html2.erl | 68 |
1 files changed, 44 insertions, 24 deletions
diff --git a/lib/test_server/src/erl2html2.erl b/lib/test_server/src/erl2html2.erl index 1729257809..9c0ca64173 100644 --- a/lib/test_server/src/erl2html2.erl +++ b/lib/test_server/src/erl2html2.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2012. All Rights Reserved. +%% Copyright Ericsson AB 1997-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -34,16 +34,17 @@ convert(File, Dest) -> %% %% FIXME: The colours should *really* be set with %% stylesheets... + %% + %% The html file is written with the same encoding as the input file. Encoding = encoding(File), Header = ["<!DOCTYPE HTML PUBLIC " "\"-//W3C//DTD HTML 3.2 Final//EN\">\n" - "<!-- autogenerated by '"++atom_to_list(?MODULE)++"'. -->\n" + "<!-- autogenerated by '",atom_to_list(?MODULE),"'. -->\n" "<html>\n" "<head>\n" "<meta http-equiv=\"Content-Type\" content=\"text/html;" - "charset=", - Encoding,"\"/>\n" - "<title>", File, "</title>\n" + "charset=",html_encoding(Encoding),"\"/>\n" + "<title>", to_raw_list(File,Encoding), "</title>\n" "</head>\n\n" "<body bgcolor=\"white\" text=\"black\"" " link=\"blue\" vlink=\"purple\" alink=\"red\">\n"], @@ -61,7 +62,7 @@ convert(File, Dest, Header) -> case file:open(Dest,[write,raw]) of {ok,DFd} -> file:write(DFd,[Header,"<pre>\n"]), - _Lines = build_html(SFd,DFd,Functions), + _Lines = build_html(SFd,DFd,encoding(File),Functions), file:write(DFd,["</pre>\n",footer(), "</body>\n</html>\n"]), %% {_, Time2} = statistics(runtime), @@ -121,21 +122,21 @@ parse_file(Epp,File,InCorrectFile) -> %%%----------------------------------------------------------------- %%% Add a link target for each line and one for each function definition. -build_html(SFd,DFd,Functions) -> - build_html(SFd,DFd,file:read_line(SFd),1,Functions,false). +build_html(SFd,DFd,Encoding,Functions) -> + build_html(SFd,DFd,Encoding,file:read_line(SFd),1,Functions,false). -build_html(SFd,DFd,{ok,Str},L,[{F,A,L}|Functions],_IsFuncDef) -> +build_html(SFd,DFd,Encoding,{ok,Str},L,[{F,A,L}|Functions],_IsFuncDef) -> FALink = http_uri:encode(F++"-"++integer_to_list(A)), - file:write(DFd,["<a name=\"",FALink,"\"/>"]), - build_html(SFd,DFd,{ok,Str},L,Functions,true); -build_html(SFd,DFd,{ok,Str},L,[{clause,L}|Functions],_IsFuncDef) -> - build_html(SFd,DFd,{ok,Str},L,Functions,true); -build_html(SFd,DFd,{ok,Str},L,Functions,IsFuncDef) -> + file:write(DFd,["<a name=\"",to_raw_list(FALink,Encoding),"\"/>"]), + build_html(SFd,DFd,Encoding,{ok,Str},L,Functions,true); +build_html(SFd,DFd,Encoding,{ok,Str},L,[{clause,L}|Functions],_IsFuncDef) -> + build_html(SFd,DFd,Encoding,{ok,Str},L,Functions,true); +build_html(SFd,DFd,Encoding,{ok,Str},L,Functions,IsFuncDef) -> LStr = line_number(L), Str1 = line(Str,IsFuncDef), file:write(DFd,[LStr,Str1]), - build_html(SFd,DFd,file:read_line(SFd),L+1,Functions,false); -build_html(_SFd,_DFd,eof,L,_Functions,_IsFuncDef) -> + build_html(SFd,DFd,Encoding,file:read_line(SFd),L+1,Functions,false); +build_html(_SFd,_DFd,_Encoding,eof,L,_Functions,_IsFuncDef) -> L. line_number(L) -> @@ -190,16 +191,35 @@ footer() -> %%%----------------------------------------------------------------- %%% Read encoding from source file encoding(File) -> - Encoding = - case epp:read_encoding(File) of - none -> - epp:default_encoding(); - E -> - E - end, - html_encoding(Encoding). + case epp:read_encoding(File) of + none -> + epp:default_encoding(); + E -> + E + end. +%%%----------------------------------------------------------------- +%%% Covert encoding atom to string for use in HTML header html_encoding(latin1) -> "iso-8859-1"; html_encoding(utf8) -> "utf-8". + +%%%----------------------------------------------------------------- +%%% Convert a string to a list of raw printable characters in the +%%% given encoding. This is necessary since the files (source and +%%% destination) are both opened in raw mode (default encoding). Byte +%%% by byte is read from source and written to the destination. This +%%% conversion is needed when printing data that is not first read +%%% from the source. +%%% +%%% Example: if the encoding of the file is utf8, and we have a string +%%% containing "�" = [229], then we need to convert this to [195,165] +%%% before writing. Note that this conversion is only necessary +%%% because the destination file is not (necessarily) opened with utf8 +%%% encoding - it is opened with default encoding in order to allow +%%% raw file mode and byte by byte copying from source. +to_raw_list(X,latin1) when is_list(X) -> + X; +to_raw_list(X,utf8) when is_list(X) -> + binary_to_list(unicode:characters_to_binary(X)). |