5
%% Copyright Ericsson AB 2010. All Rights Reserved.
7
%% The contents of this file are subject to the Erlang Public License,
8
%% Version 1.1, (the "License"); you may not use this file except in
9
%% compliance with the License. You should have received a copy of the
10
%% Erlang Public License along with this software. If not, it can be
11
%% retrieved online at http://www.erlang.org/.
13
%% Software distributed under the License is distributed on an "AS IS"
14
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
15
%% the License for the specific language governing rights and limitations
19
%%----------------------------------------------------------------------
20
%% File : xml_from_edoc.escript
22
%% Created : 12 Dec 2009 by Lars Thorsen
23
%%----------------------------------------------------------------------
26
%%======================================================================
28
%%======================================================================
29
-record(args, {suffix=".xml",
30
layout=docb_edoc_xml_cb,
34
sort_functions=true}).
37
%%======================================================================
39
%%======================================================================
40
%%----------------------------------------------------------------------
43
%%----------------------------------------------------------------------
45
case catch parse(RawOpts, erlref, #args{}) of
46
{ok, File, Type, Args} ->
51
users_guide(File, Args)
54
io:format("~p\n", [Msg]),
60
%%======================================================================
62
%%======================================================================
64
%%----------------------------------------------------------------------
67
%%----------------------------------------------------------------------
69
io:format("usage: xml_from_edoc.escript [<options>] <file> \n"),
73
%%----------------------------------------------------------------------
76
%%----------------------------------------------------------------------
78
case filelib:is_regular(File) of
80
Opts = [{def, Args#args.def},
81
{includes, Args#args.includes},
82
{preprocess, Args#args.preprocess},
83
{sort_functions, Args#args.sort_functions},
85
{app_default, "OTPROOT"},
86
{file_suffix, Args#args.suffix},
88
{layout, Args#args.layout}],
89
edoc:file(File, Opts);
91
io:format("~s: not a regular file\n", [File]),
96
%%----------------------------------------------------------------------
97
%% Function: users_guide/2
99
%%----------------------------------------------------------------------
100
users_guide(File, Args) ->
101
case filelib:is_regular(File) of
103
Opts = [{def, Args#args.def},
104
{app_default, "OTPROOT"},
105
{file_suffix, Args#args.suffix},
106
{layout, Args#args.layout}],
108
Env = edoc_lib:get_doc_env(Opts),
111
edoc_extract:file(File, overview, Env, Opts),
113
edoc_data:overview("Overview", Tags, Env, Opts),
114
F = fun(M) -> M:overview(Data, Opts) end,
115
Text = edoc_lib:run_layout(F, Opts),
117
OutFile = "chapter" ++ Args#args.suffix,
118
edoc_lib:write_file(Text, ".", OutFile);
120
io:format("~s: not a regular file\n", [File]),
126
parse(["-xml" |RawOpts], Type, Args) ->
127
parse(RawOpts, Type, Args); % default, no update of record necessary
128
parse(["-sgml" |RawOpts], Type, Args) ->
129
parse(RawOpts, Type, Args#args{suffix=".sgml", layout=docb_edoc_sgml_cb});
130
parse(["-chapter" |RawOpts], _Type, Args) ->
131
parse(RawOpts, chapter, Args);
132
parse(["-def", Key, Val |RawOpts], Type, Args) ->
133
Args2 = Args#args{def=Args#args.def++[{list_to_atom(Key), Val}]},
134
parse(RawOpts, Type, Args2);
136
parse(["-i", Dir |RawOpts], Type, Args) ->
137
Args2 = Args#args{includes=Args#args.includes++[Dir]},
138
parse(RawOpts, Type, Args2);
139
parse(["-preprocess", Bool |RawOpts], Type, Args) when Bool == "true";
141
parse(RawOpts, Type, Args#args{preprocess=list_to_atom(Bool)});
142
parse(["-sort_functions", Bool |RawOpts], Type, Args) when Bool == "true";
144
parse(RawOpts, Type, Args#args{sort_functions=list_to_atom(Bool)});
145
parse([File], Type, Args) ->
146
{ok, File, Type, Args};
147
parse([Opt | _RawOpts], _Type, _Args) ->
148
{error, io_lib:format("Bad option: ~p", [Opt])}.