4
%% Copyright Ericsson AB 2010-2011. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
21
%% Module alternative to diameterc for dictionary compilation.
23
%% Eg. 1> diameter_make:codec("mydict.dia").
26
%% -boot start_clean \
27
%% -eval 'ok = diameter_make:codec("mydict.dia")' \
31
-module(diameter_make).
40
-export_type([opt/0]).
42
-type opt() :: {include|outdir|name|prefix|inherits, string()}
46
%% ===========================================================================
50
%% Parse a dictionary file and generate a codec module.
52
-spec codec(Path, [opt()])
55
when Path :: string(),
59
case dict(File, Opts) of
64
[spec || _ <- [1], lists:member(debug, Opts)] ++ [erl, hrl]);
74
%% Parse a dictionary file and return the orddict that a codec module
75
%% returns from dict/0.
77
-spec dict(string(), [opt()])
78
-> {ok, orddict:orddict()}
82
case diameter_dict_util:parse({path, Path}, Opts) of
85
{error = E, Reason} ->
86
{E, diameter_dict_util:format_error(Reason)}
94
%% Turn an orddict returned by dict/1-2 back into a dictionary file
95
%% in the form of an iolist().
97
-spec format(orddict:orddict())
101
diameter_dict_util:format(Dict).
105
%% Parse a dictionary file and return its formatted equivalent.
110
when File :: string(),
121
%% ===========================================================================
125
make(File, Opts, Dict, [Mode | Rest]) ->
127
ok = diameter_codegen:from_dict(File, Dict, Opts, Mode),
128
make(File, Opts, Dict, Rest)
131
erlang:error({Reason, Mode, erlang:get_stacktrace()})