diff options
author | Lars G Thorsen <[email protected]> | 2010-02-11 07:13:28 +0000 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2010-02-11 07:13:28 +0000 |
commit | 75bc5e521dcc9ab798acefb5400f5f15354f08fd (patch) | |
tree | 7d30692d4e91dba347f6fabec4e533df1a1cd998 /system/doc/top/src/otp_man_index.erl | |
parent | e1b759c0863e677527577af7cbf436d0574cbb00 (diff) | |
download | otp-75bc5e521dcc9ab798acefb5400f5f15354f08fd.tar.gz otp-75bc5e521dcc9ab798acefb5400f5f15354f08fd.tar.bz2 otp-75bc5e521dcc9ab798acefb5400f5f15354f08fd.zip |
OTP-8343 The documentation is now possible to build in an open source
environment after a number of bugs are fixed and some features
are added in the documentation build process.
- The arity calculation is updated.
- The module prefix used in the function names for bif's are
removed in the generated links so the links will look like
"http://www.erlang.org/doc/man/erlang.html#append_element-2"
instead of
"http://www.erlang.org/doc/man/erlang.html#erlang:append_element-
2".
- Enhanced the menu positioning in the html documentation when a
new page is loaded.
- A number of corrections in the generation of man pages (thanks
to Sergei Golovan)
- The legal notice is taken from the xml book file so OTP's build
process can be used for non OTP applications.
Diffstat (limited to 'system/doc/top/src/otp_man_index.erl')
-rw-r--r-- | system/doc/top/src/otp_man_index.erl | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/system/doc/top/src/otp_man_index.erl b/system/doc/top/src/otp_man_index.erl new file mode 100644 index 0000000000..78ecd8b954 --- /dev/null +++ b/system/doc/top/src/otp_man_index.erl @@ -0,0 +1,197 @@ +%%-------------------------------------------------------------------- +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2010. 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 +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% +%%----------------------------------------------------------------- +%% File: otp_man_index.erl +%% +%% Description: +%% This file generates the module overview in the documentation. +%% +%%----------------------------------------------------------------- + +-module(otp_man_index). + +-export([gen/1]). +-include_lib("kernel/include/file.hrl"). + + +gen([RootDir, OutFile]) when is_atom(RootDir), is_atom(OutFile)-> + Bases = [{"../lib/", filename:join(RootDir, "lib")}, + {"../", RootDir}], + Apps = find_application_paths(Bases), + RefPages = find_ref_files(Apps), + gen_html(RefPages, atom_to_list(OutFile)). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Find Reference files +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +find_ref_files(Apps) -> + find_ref_files(Apps, []). + +find_ref_files([], Acc) -> + Acc; +find_ref_files([{App, Vsn, AppPath, RelPath} |Apps], Acc) -> + case filelib:wildcard(filename:join(AppPath, "*.html")) of + [] -> + find_ref_files(Apps, Acc); + Result -> + + Refs1 = lists:filter(fun(Ref) -> + case file:read_file(Ref) of + {ok, Bin} -> + case re:run(Bin, ".*<!-- refpage -->.*",[]) of + {match, _} -> + true; + nomatch -> + false + end; + {error, Reason} -> + exit(io_lib:format("~p : ~s\n", [Reason, Ref])) + end + end, + Result), + + Refs2 = lists:map(fun(Ref) -> + Module = filename:basename(Ref, ".html"), + {string:to_lower(Module), + Module, + App ++ "-" ++ Vsn, + RelPath, + filename:join(RelPath, filename:basename(Ref))} + end, + Refs1), + find_ref_files(Apps, Refs2 ++ Acc) + end. + +find_application_paths([]) -> + []; +find_application_paths([{URL, Dir} | Paths]) -> + Sub1 = "doc/html", + + AppDirs = get_app_dirs(Dir), + + AppPaths = + lists:map( + fun({App, AppPath}) -> + VsnFile = filename:join(AppPath, "vsn.mk"), + VsnStr = + case file:read_file(VsnFile) of + {ok, Bin} -> + case re:run(Bin, ".*VSN\s*=\s*([0-9\.]+).*",[{capture,[1],list}]) of + {match, [V]} -> + V; + nomatch -> + exit(io_lib:format("No VSN variable found in ~s\n", + [VsnFile])) + end; + {error, Reason} -> + exit(io_lib:format("~p : ~s\n", [Reason, VsnFile])) + end, + AppURL = URL ++ App ++ "-" ++ VsnStr, + {App, VsnStr, AppPath ++ "/" ++ Sub1, AppURL ++ "/" ++ Sub1} + end, AppDirs), + AppPaths ++ find_application_paths(Paths). + + +get_app_dirs(Dir) -> + {ok, Files} = file:list_dir(Dir), + AFiles = + lists:map(fun(File) -> {File, filename:join([Dir, File])} end, Files), + lists:zf(fun is_app_with_doc/1, AFiles). + +is_app_with_doc({ADir, APath}) -> + case file:read_file_info(filename:join([APath, "info"])) of + {ok, _FileInfo} -> + {true, {ADir, APath}}; + _ -> + false + end. + + + + +gen_html(RefPages, OutFile)-> + case file:open(OutFile, [write]) of + {ok, Out} -> + io:fwrite(Out, "~s\n", [html_header()]), + + SortedPages = lists:sort(RefPages), + + lists:foreach(fun({_,Module, App, AppDocDir, RefPagePath}) -> + io:fwrite(Out, " <TR>\n",[]), + io:fwrite(Out, " <TD><A HREF=\"~s\">~s</A></TD>\n", + [RefPagePath, Module]), + io:fwrite(Out, " <TD><A HREF=\"~s\">~s</A></TD>\n", + [filename:join(AppDocDir, "index.html"), + App]), + io:fwrite(Out, " </TR>\n",[]) + end, + SortedPages), + + {Year, _, _} = date(), + io:fwrite(Out, "~s\n", [html_footer(integer_to_list(Year))]); + {error, Reason} -> + exit("~p: ~s\n",[Reason, OutFile]) + end. + + + +html_header() -> + "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" + "<!-- This file was generated by the otp_man_index -->\n" + "<HTML>\n" + "<HEAD>\n" + " <link rel=\"stylesheet\" href=\"otp_doc.css\" type=\"text/css\"/>\n" + " <TITLE>Erlang/OTP Manual Page Index</TITLE>\n" + "</HEAD>\n" + "<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\" LINK=\"#0000FF\" VLINK=\"#FF00FF\" ALINK=\"#FF0000\">\n" + "<CENTER>\n" + "<!-- A HREF=\"http://www.erlang.org/\">\n" + "<img alt=\"Erlang logo\" src=\"erlang-logo.png\"/>\n" + "</A><BR -->\n" + "<SMALL>\n" + "[<A HREF=\"index.html\">Up</A> | <A HREF=\"http://www.erlang.org/\">Erlang</A>]\n" + "</SMALL><BR>\n" + "<P/><FONT SIZE=\"+4\">OTP Reference Page Index</FONT><BR>\n" + "</CENTER>\n" + "<CENTER>\n" + "<P/>\n" + "<TABLE BORDER=1>\n" + "<TR>\n" + " <TH>Manual Page</TH><TH>Application</TH>\n" + "</TR>\n". + + + +html_footer(Year) -> + "</TABLE>\n" + "</CENTER>\n" + "<P/>\n" + "<CENTER>\n" + "<HR/>\n" + "<SMALL>\n" + "Copyright © 1991-" ++ Year ++ "\n" + "<a href=\"http://www.ericsson.com/technology/opensource/erlang/\">\n" + "Ericsson AB</a>\n" + "</SMALL>\n" + "</CENTER>\n" + "</BODY>\n" + "</HTML>\n". |