~clint-fewbar/ubuntu/precise/erlang/merge-15b

« back to all changes in this revision

Viewing changes to lib/diameter/src/compiler/diameter_make.erl

  • Committer: Package Import Robot
  • Author(s): Sergei Golovan
  • Date: 2011-12-15 19:20:10 UTC
  • mfrom: (1.1.18) (3.5.15 sid)
  • mto: (3.5.16 sid)
  • mto: This revision was merged to the branch mainline in revision 33.
  • Revision ID: package-import@ubuntu.com-20111215192010-jnxcfe3tbrpp0big
Tags: 1:15.b-dfsg-1
* New upstream release.
* Upload to experimental because this release breaks external drivers
  API along with ABI, so several applications are to be fixed.
* Removed SSL patch because the old SSL implementation is removed from
  the upstream distribution.
* Removed never used patch which added native code to erlang beam files.
* Removed the erlang-docbuilder binary package because the docbuilder
  application was dropped by upstream.
* Documented dropping ${erlang-docbuilder:Depends} substvar in
  erlang-depends(1) manpage.
* Made erlang-base and erlang-base-hipe provide virtual package
  erlang-abi-15.b (the number means the first erlang version, which
  provides current ABI).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%%
 
4
%% Copyright Ericsson AB 2010-2011. All Rights Reserved.
 
5
%%
 
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/.
 
11
%%
 
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
 
15
%% under the License.
 
16
%%
 
17
%% %CopyrightEnd%
 
18
%%
 
19
 
 
20
%%
 
21
%% Module alternative to diameterc for dictionary compilation.
 
22
%%
 
23
%% Eg. 1> diameter_make:codec("mydict.dia").
 
24
%%
 
25
%%     $ erl -noinput \
 
26
%%           -boot start_clean \
 
27
%%           -eval 'ok = diameter_make:codec("mydict.dia")' \
 
28
%%           -s init stop
 
29
%%
 
30
 
 
31
-module(diameter_make).
 
32
 
 
33
-export([codec/1,
 
34
         codec/2,
 
35
         dict/1,
 
36
         dict/2,
 
37
         format/1,
 
38
         reformat/1]).
 
39
 
 
40
-export_type([opt/0]).
 
41
 
 
42
-type opt() :: {include|outdir|name|prefix|inherits, string()}
 
43
             | verbose
 
44
             | debug.
 
45
 
 
46
%% ===========================================================================
 
47
 
 
48
%% codec/1-2
 
49
%%
 
50
%% Parse a dictionary file and generate a codec module.
 
51
 
 
52
-spec codec(Path, [opt()])
 
53
   -> ok
 
54
    | {error, Reason}
 
55
 when Path :: string(),
 
56
      Reason :: string().
 
57
 
 
58
codec(File, Opts) ->
 
59
    case dict(File, Opts) of
 
60
        {ok, Dict} ->
 
61
            make(File,
 
62
                 Opts,
 
63
                 Dict,
 
64
                 [spec || _ <- [1], lists:member(debug, Opts)] ++ [erl, hrl]);
 
65
        {error, _} = E ->
 
66
            E
 
67
    end.
 
68
 
 
69
codec(File) ->
 
70
    codec(File, []).
 
71
 
 
72
%% dict/2
 
73
%%
 
74
%% Parse a dictionary file and return the orddict that a codec module
 
75
%% returns from dict/0.
 
76
 
 
77
-spec dict(string(), [opt()])
 
78
   -> {ok, orddict:orddict()}
 
79
    | {error, string()}.
 
80
 
 
81
dict(Path, Opts) ->
 
82
    case diameter_dict_util:parse({path, Path}, Opts) of
 
83
        {ok, _} = Ok ->
 
84
            Ok;
 
85
        {error = E, Reason} ->
 
86
            {E, diameter_dict_util:format_error(Reason)}
 
87
    end.
 
88
 
 
89
dict(File) ->
 
90
    dict(File, []).
 
91
 
 
92
%% format/1
 
93
%%
 
94
%% Turn an orddict returned by dict/1-2 back into a dictionary file
 
95
%% in the form of an iolist().
 
96
 
 
97
-spec format(orddict:orddict())
 
98
   -> iolist().
 
99
 
 
100
format(Dict) ->
 
101
    diameter_dict_util:format(Dict).
 
102
 
 
103
%% reformat/1
 
104
%%
 
105
%% Parse a dictionary file and return its formatted equivalent.
 
106
 
 
107
-spec reformat(File)
 
108
   -> {ok, iolist()}
 
109
    | {error, Reason}
 
110
 when File :: string(),
 
111
      Reason :: string().
 
112
 
 
113
reformat(File) ->
 
114
    case dict(File) of
 
115
        {ok, Dict} ->
 
116
            {ok, format(Dict)};
 
117
        {error, _} = No ->
 
118
            No
 
119
    end.
 
120
 
 
121
%% ===========================================================================
 
122
 
 
123
make(_, _, _, []) ->
 
124
    ok;
 
125
make(File, Opts, Dict, [Mode | Rest]) ->
 
126
    try
 
127
        ok = diameter_codegen:from_dict(File, Dict, Opts, Mode),
 
128
        make(File, Opts, Dict, Rest)
 
129
    catch
 
130
        error: Reason ->
 
131
            erlang:error({Reason, Mode, erlang:get_stacktrace()})
 
132
    end.