~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/asn1/src/asn1ct_tok.erl

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
%%
2
2
%% %CopyrightBegin%
3
 
%% 
4
 
%% Copyright Ericsson AB 1997-2009. All Rights Reserved.
5
 
%% 
 
3
%%
 
4
%% Copyright Ericsson AB 1997-2010. All Rights Reserved.
 
5
%%
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
11
 
%% 
 
11
%%
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
16
 
%% 
 
16
%%
17
17
%% %CopyrightEnd%
18
18
%%
19
19
%%
21
21
 
22
22
%% Tokenize ASN.1 code (input to parser generated with yecc)   
23
23
 
24
 
-export([get_name/2,tokenise/2, file/1]).
 
24
-export([get_name/2,tokenise/4, file/1]).
25
25
 
26
26
 
27
27
file(File) ->
29
29
        {error, Reason} ->
30
30
            {error,{File,file:format_error(Reason)}};
31
31
        {ok,Stream} ->
32
 
            process0(Stream)
 
32
            process(Stream,0,[])
33
33
    end.
34
34
 
35
 
process0(Stream) ->
36
 
    process(Stream,0,[]). 
37
 
 
38
35
process(Stream,Lno,R) ->
39
36
    process(io:get_line(Stream, ''), Stream,Lno+1,R).
40
37
 
45
42
 
46
43
process(L, Stream,Lno,R) when is_list(L) ->
47
44
    %%io:format('read:~s',[L]),
48
 
    case catch tokenise(L,Lno) of
 
45
    case catch tokenise(Stream,L,Lno,[]) of
49
46
        {'ERR',Reason} ->
50
47
            io:format("Tokeniser error on line: ~w ~w~n",[Lno,Reason]),
51
48
            exit(0);
52
 
        {multiline_comment,NestingLevel} ->
53
 
            {RestL,Lno2} = process_skip_multiline_comment(Stream,Lno,NestingLevel),
54
 
            process(RestL,Stream,Lno2,R);
55
 
        T ->
 
49
        {NewLno,T} ->
56
50
            %%io:format('toks:~w~n',[T]),
57
 
            process(Stream,Lno,[T|R])
 
51
            process(Stream,NewLno,[T|R])
58
52
    end. 
59
53
 
60
 
process_skip_multiline_comment(Stream,Lno,NestingLevel) ->
61
 
    process_skip_multiline_comment(io:get_line(Stream, ''),
62
 
                                   Stream, Lno + 1, NestingLevel).
63
 
process_skip_multiline_comment(eof,_Stream,Lno,_NestingLevel) ->
64
 
    io:format("Tokeniser error on line: ~w, premature end of multiline comment~n",[Lno]),
65
 
    exit(0);
66
 
process_skip_multiline_comment(Line,Stream,Lno,NestingLevel) ->
67
 
    case catch skip_multiline_comment(Line,NestingLevel) of
68
 
        {multiline_comment,NestingLevel2} ->
69
 
            process_skip_multiline_comment(Stream,Lno,NestingLevel2);
70
 
        T ->
71
 
            {T,Lno}
72
 
    end.
73
 
 
74
 
tokenise([H|T],Lno) when $a =< H , H =< $z ->
 
54
tokenise(Stream,[H|T],Lno,R) when $a =< H , H =< $z ->
75
55
    {X, T1} = get_name(T, [H]),
76
 
    [{identifier,Lno, list_to_atom(X)}|tokenise(T1,Lno)];
77
 
 
78
 
tokenise([$&,H|T],Lno) when $A =< H , H =< $Z ->
79
 
    {Y, T1} = get_name(T, [H]),
80
 
    X = list_to_atom(Y),
81
 
    [{typefieldreference, Lno, X} | tokenise(T1, Lno)];
82
 
 
83
 
tokenise([$&,H|T],Lno) when $a =< H , H =< $z ->
84
 
    {Y, T1} = get_name(T, [H]),
85
 
    X = list_to_atom(Y),
86
 
    [{valuefieldreference, Lno, X} | tokenise(T1, Lno)];
87
 
 
88
 
tokenise([H|T],Lno) when $A =< H , H =< $Z ->
 
56
    tokenise(Stream,T1,Lno,[{identifier,Lno, list_to_atom(X)}|R]);
 
57
 
 
58
tokenise(Stream,[$&,H|T],Lno,R) when $A =< H , H =< $Z ->
 
59
    {Y, T1} = get_name(T, [H]),
 
60
    X = list_to_atom(Y),
 
61
    tokenise(Stream,T1,Lno,[{typefieldreference, Lno, X} | R]);
 
62
 
 
63
tokenise(Stream,[$&,H|T],Lno,R) when $a =< H , H =< $z ->
 
64
    {Y, T1} = get_name(T, [H]),
 
65
    X = list_to_atom(Y),
 
66
    tokenise(Stream,T1,Lno,[{valuefieldreference, Lno, X} | R]);
 
67
 
 
68
tokenise(Stream,[H|T],Lno,R) when $A =< H , H =< $Z ->
89
69
    {Y, T1} = get_name(T, [H]),
90
70
    X = list_to_atom(Y),
91
71
    case reserved_word(X) of
92
72
        true ->
93
 
            [{X,Lno}|tokenise(T1,Lno)];
 
73
            tokenise(Stream,T1,Lno,[{X,Lno}|R]);
94
74
        false ->
95
 
            [{typereference,Lno,X}|tokenise(T1,Lno)];
 
75
            tokenise(Stream,T1,Lno,[{typereference,Lno,X}|R]);
96
76
        rstrtype ->
97
 
            [{restrictedcharacterstringtype,Lno,X}|tokenise(T1,Lno)]
 
77
            tokenise(Stream,T1,Lno,[{restrictedcharacterstringtype,Lno,X}|R])
98
78
    end;
99
79
 
100
 
tokenise([$-,H|T],Lno) when $0 =< H , H =< $9 ->
101
 
    {X, T1} = get_number(T, [H]),
102
 
    [{number,Lno,-1 * list_to_integer(X)}|tokenise(T1,Lno)];
103
 
 
104
 
tokenise([H|T],Lno) when $0 =< H , H =< $9 ->
105
 
    {X, T1} = get_number(T, [H]),
106
 
    [{number,Lno,list_to_integer(X)}|tokenise(T1,Lno)];
107
 
 
108
 
tokenise([$-,$-|T],Lno) ->
109
 
    tokenise(skip_comment(T),Lno);
110
 
 
111
 
tokenise([$/,$*|T],Lno) ->
112
 
    tokenise(skip_multiline_comment(T,0),Lno);
113
 
 
114
 
tokenise([$:,$:,$=|T],Lno) ->
115
 
    [{'::=',Lno}|tokenise(T,Lno)];
116
 
 
117
 
tokenise([$'|T],Lno) ->
 
80
tokenise(Stream,[$-,H|T],Lno,R) when $0 =< H , H =< $9 ->
 
81
    {X, T1} = get_number(T, [H]),
 
82
    tokenise(Stream,T1,Lno,[{number,Lno,-1 * list_to_integer(X)}|R]);
 
83
 
 
84
tokenise(Stream,[H|T],Lno,R) when $0 =< H , H =< $9 ->
 
85
    {X, T1} = get_number(T, [H]),
 
86
    tokenise(Stream,T1,Lno,[{number,Lno,list_to_integer(X)}|R]);
 
87
 
 
88
tokenise(Stream,[$-,$-|T],Lno,R) ->
 
89
    tokenise(Stream,skip_comment(T),Lno,R);
 
90
 
 
91
tokenise(Stream,[$/,$*|T],Lno,R) ->
 
92
    {NewLno,T1} = skip_multiline_comment(Stream,T,Lno,0),
 
93
    tokenise(Stream,T1,NewLno,R);
 
94
 
 
95
tokenise(Stream,[$:,$:,$=|T],Lno,R) ->
 
96
    tokenise(Stream,T,Lno,[{'::=',Lno}|R]);
 
97
 
 
98
tokenise(Stream,[$'|T],Lno,R) ->
118
99
    case catch collect_quoted(T,Lno,[]) of
119
100
         {'ERR',_} ->
120
101
             throw({'ERR','bad_quote'});
121
102
         {Thing, T1} ->
122
 
             [Thing|tokenise(T1,Lno)]
 
103
             tokenise(Stream,T1,Lno,[Thing|R])
123
104
    end;
124
105
 
125
 
tokenise([$"|T],Lno) ->
126
 
    collect_string(T,Lno);
127
 
 
128
 
tokenise([${|T],Lno) ->
129
 
    [{'{',Lno}|tokenise(T,Lno)];
130
 
 
131
 
tokenise([$}|T],Lno) ->
132
 
    [{'}',Lno}|tokenise(T,Lno)];
133
 
 
134
 
tokenise([$]|T],Lno) ->
135
 
    [{']',Lno}|tokenise(T,Lno)];
136
 
 
137
 
tokenise([$[|T],Lno) ->
138
 
    [{'[',Lno}|tokenise(T,Lno)];
139
 
 
140
 
tokenise([$,|T],Lno) ->
141
 
    [{',',Lno}|tokenise(T,Lno)];
142
 
 
143
 
tokenise([$(|T],Lno) ->
144
 
    [{'(',Lno}|tokenise(T,Lno)];
145
 
tokenise([$)|T],Lno) ->
146
 
    [{')',Lno}|tokenise(T,Lno)];
147
 
 
148
 
tokenise([$.,$.,$.|T],Lno) ->
149
 
    [{'...',Lno}|tokenise(T,Lno)];
150
 
 
151
 
tokenise([$.,$.|T],Lno) ->
152
 
    [{'..',Lno}|tokenise(T,Lno)];
153
 
 
154
 
tokenise([$.|T],Lno) ->
155
 
    [{'.',Lno}|tokenise(T,Lno)];
156
 
tokenise([$^|T],Lno) ->
157
 
    [{'^',Lno}|tokenise(T,Lno)];
158
 
tokenise([$!|T],Lno) ->
159
 
    [{'!',Lno}|tokenise(T,Lno)];
160
 
tokenise([$||T],Lno) ->
161
 
    [{'|',Lno}|tokenise(T,Lno)];
162
 
 
163
 
 
164
 
tokenise([H|T],Lno) ->
 
106
tokenise(Stream,[$"|T],Lno,R) ->
 
107
    {Str,T1} = collect_string(T,Lno),
 
108
    tokenise(Stream,T1,Lno,[Str|R]);
 
109
 
 
110
tokenise(Stream,[${|T],Lno,R) ->
 
111
    tokenise(Stream,T,Lno,[{'{',Lno}|R]);
 
112
 
 
113
tokenise(Stream,[$}|T],Lno,R) ->
 
114
    tokenise(Stream,T,Lno,[{'}',Lno}|R]);
 
115
 
 
116
%% tokenise(Stream,[$],$]|T],Lno,R) ->
 
117
%%     tokenise(Stream,T,Lno,[{']]',Lno}|R]);
 
118
 
 
119
%% Even though x.680 specify '[[' and ']]' as lexical items
 
120
%% it does not work to have them as such since the single [ and ] can
 
121
%% be used beside each other in the SYNTAX OF in x.681
 
122
%% the solution chosen here , i.e. to have them as separate lexical items
 
123
%% will not detect the cases where there is white space between them
 
124
%% which would be an error in the use in ExtensionAdditionGroups
 
125
 
 
126
%% tokenise(Stream,[$[,$[|T],Lno,R) ->
 
127
%%     tokenise(Stream,T,Lno,[{'[[',Lno}|R]);
 
128
 
 
129
tokenise(Stream,[$]|T],Lno,R) ->
 
130
    tokenise(Stream,T,Lno,[{']',Lno}|R]);
 
131
 
 
132
tokenise(Stream,[$[|T],Lno,R) ->
 
133
    tokenise(Stream,T,Lno,[{'[',Lno}|R]);
 
134
 
 
135
tokenise(Stream,[$,|T],Lno,R) ->
 
136
    tokenise(Stream,T,Lno,[{',',Lno}|R]);
 
137
 
 
138
tokenise(Stream,[$(|T],Lno,R) ->
 
139
    tokenise(Stream,T,Lno,[{'(',Lno}|R]);
 
140
tokenise(Stream,[$)|T],Lno,R) ->
 
141
    tokenise(Stream,T,Lno,[{')',Lno}|R]);
 
142
 
 
143
tokenise(Stream,[$.,$.,$.|T],Lno,R) ->
 
144
    tokenise(Stream,T,Lno,[{'...',Lno}|R]);
 
145
 
 
146
tokenise(Stream,[$.,$.|T],Lno,R) ->
 
147
    tokenise(Stream,T,Lno,[{'..',Lno}|R]);
 
148
 
 
149
tokenise(Stream,[$.|T],Lno,R) ->
 
150
    tokenise(Stream,T,Lno,[{'.',Lno}|R]);
 
151
tokenise(Stream,[$^|T],Lno,R) ->
 
152
    tokenise(Stream,T,Lno,[{'^',Lno}|R]);
 
153
tokenise(Stream,[$!|T],Lno,R) ->
 
154
    tokenise(Stream,T,Lno,[{'!',Lno}|R]);
 
155
tokenise(Stream,[$||T],Lno,R) ->
 
156
    tokenise(Stream,T,Lno,[{'|',Lno}|R]);
 
157
 
 
158
tokenise(Stream,[H|T],Lno,R) ->
165
159
    case white_space(H) of
166
160
        true ->
167
 
            tokenise(T,Lno);
 
161
            tokenise(Stream,T,Lno,R);
168
162
        false ->
169
 
            [{list_to_atom([H]),Lno}|tokenise(T,Lno)]
 
163
            tokenise(Stream,T,Lno,[{list_to_atom([H]),Lno}|R])
170
164
    end;
171
 
tokenise([],_) ->
172
 
    [].
 
165
tokenise(_Stream,[],Lno,R) ->
 
166
    {Lno,lists:reverse(R)}.
173
167
 
174
168
 
175
169
collect_string(L,Lno) ->
181
175
collect_string([H|T],Lno,Str) ->
182
176
    case H of
183
177
        $" ->
184
 
           [{cstring,1,lists:reverse(Str)}|tokenise(T,Lno)];
 
178
           {{cstring,1,lists:reverse(Str)},T};
185
179
        Ch ->
186
180
           collect_string(T,Lno,[Ch|Str])
187
181
    end.
252
246
    skip_comment(T).
253
247
 
254
248
 
255
 
skip_multiline_comment([],L) ->
256
 
    throw({multiline_comment,L});
257
 
skip_multiline_comment([$*,$/|T],0) ->
258
 
    T;
259
 
skip_multiline_comment([$*,$/|T],Level) ->
260
 
    skip_multiline_comment(T,Level - 1);
261
 
skip_multiline_comment([$/,$*|T],Level) ->
262
 
    skip_multiline_comment(T,Level + 1);
263
 
skip_multiline_comment([_|T],Level) ->
264
 
    skip_multiline_comment(T,Level).
265
 
 
 
249
skip_multiline_comment(Stream,[],Lno,Level) ->
 
250
    case io:get_line(Stream,'') of
 
251
        eof ->
 
252
            io:format("Tokeniser error on line: ~w~n"
 
253
                      "premature end of multiline comment~n",[Lno]),
 
254
            exit(0);
 
255
        Line ->
 
256
            skip_multiline_comment(Stream,Line,Lno+1,Level)
 
257
    end;
 
258
skip_multiline_comment(_Stream,[$*,$/|T],Lno,0) ->
 
259
    {Lno,T};
 
260
skip_multiline_comment(Stream,[$*,$/|T],Lno,Level) ->
 
261
    skip_multiline_comment(Stream,T,Lno,Level - 1);
 
262
skip_multiline_comment(Stream,[$/,$*|T],Lno,Level) ->
 
263
    skip_multiline_comment(Stream,T,Lno,Level + 1);
 
264
skip_multiline_comment(Stream,[_|T],Lno,Level) ->
 
265
    skip_multiline_comment(Stream,T,Lno,Level).
266
266
 
267
267
collect_quoted([$',$B|T],Lno, L) ->
268
268
    case check_bin(L) of
327
327
reserved_word('CONSTRAINED') -> true;
328
328
reserved_word('CONTAINING') -> true;
329
329
reserved_word('DEFAULT') -> true;
330
 
reserved_word('DEFINED') -> true;
 
330
reserved_word('DEFINED') -> true; % not present in X.680 07/2002
331
331
reserved_word('DEFINITIONS') -> true;
332
332
reserved_word('EMBEDDED') -> true;
333
333
reserved_word('ENCODED') -> true;
336
336
reserved_word('EXCEPT') -> true;
337
337
reserved_word('EXPLICIT') -> true;
338
338
reserved_word('EXPORTS') -> true;
 
339
reserved_word('EXTENSIBILITY') -> true;
339
340
reserved_word('EXTERNAL') -> true;
340
341
reserved_word('FALSE') -> true;
341
342
reserved_word('FROM') -> true;
343
344
reserved_word('GeneralString') -> rstrtype;
344
345
reserved_word('GraphicString') -> rstrtype;
345
346
reserved_word('IA5String') -> rstrtype;
346
 
% reserved_word('TYPE-IDENTIFIER') -> true; % impl as predef item
347
347
reserved_word('IDENTIFIER') -> true;
348
348
reserved_word('IMPLICIT') -> true;
 
349
reserved_word('IMPLIED') -> true;
349
350
reserved_word('IMPORTS') -> true;
350
351
reserved_word('INCLUDES') -> true;
351
352
reserved_word('INSTANCE') -> true;
379
380
reserved_word('TAGS') -> true;
380
381
reserved_word('TeletexString') -> rstrtype;
381
382
reserved_word('TRUE') -> true;
 
383
%% reserved_word('TYPE-IDENTIFIER') -> true; % impl as predef item
382
384
reserved_word('UNION') -> true;
383
385
reserved_word('UNIQUE') -> true;
384
386
reserved_word('UNIVERSAL') -> true;