4
%% Copyright Ericsson AB 2009. 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
19
-module(reltool_utils).
22
-compile([export_all]).
24
-include_lib("wx/include/wx.hrl").
25
-include("reltool.hrl").
31
case os:getenv("ERL_LIBS") of
35
string:tokens(LibStr, ":;")
39
case erl_prim_loader:list_dir(Dir) of
42
filelib:is_dir(filename:join([Dir, F]),
48
%% "asn1-1.6.2" -> {"asn1", "1.6.2"}; "asn1" -> {"asn1", ""}
49
split_app_name(Name) ->
54
Elem >= $0, Elem =< $9 -> true;
58
case lists:splitwith(Pred, lists:reverse(Name)) of
60
{list_to_atom(lists:reverse(App)), lists:reverse(Vsn)};
62
{list_to_atom(Name), ""}
65
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67
prim_consult(Bin) when is_binary(Bin) ->
68
case erl_scan:string(binary_to_list(Bin)) of
69
{ok, Tokens, _EndLine} ->
70
prim_parse(Tokens, []);
71
{error, {_ErrorLine, Module, Reason}, _EndLine} ->
72
{error, Module:format_error(Reason)}
74
prim_consult(FullName) when is_list(FullName) ->
75
case erl_prim_loader:get_file(FullName) of
79
{error, file:format_error(enoent)}
82
prim_parse(Tokens, Acc) ->
83
case lists:splitwith(fun(T) -> element(1,T) =/= dot end, Tokens) of
85
{ok, lists:reverse(Acc)};
86
{Tokens2, [{dot,_} = Dot | Rest]} ->
87
case erl_parse:parse_term(Tokens2 ++ [Dot]) of
89
prim_parse(Rest, [Term | Acc]);
90
{error, {_ErrorLine, Module, Reason}} ->
91
{error, Module:format_error(Reason)}
94
case erl_parse:parse_term(Tokens2) of
96
{ok, lists:reverse([Term | Acc])};
97
{error, {_ErrorLine, Module, Reason}} ->
98
{error, Module:format_error(Reason)}
102
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105
Kernel = #rel_app{name = kernel, incl_apps = []},
106
Stdlib = #rel_app{name = stdlib, incl_apps = []},
107
Sasl = #rel_app{name = sasl, incl_apps = []},
109
#rel{name = ?DEFAULT_REL_NAME,
111
rel_apps = [Kernel, Stdlib]},
112
#rel{name = "start_sasl",
114
rel_apps = [Kernel, Sasl, Stdlib]}
117
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119
assign_image_list(ListCtrl) ->
120
Art = wxImageList:new(16,16),
121
[wxImageList:add(Art, wxArtProvider:getBitmap(Image, [{size, {16,16}}]))
122
|| Image <- ["wxART_ERROR",
128
wxListCtrl:assignImageList(ListCtrl, Art, ?wxIMAGE_LIST_SMALL).
130
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132
get_latest_resize(#wx{obj = ObjRef, event = #wxSize{}} = Wx) ->
134
#wx{obj = ObjRef, event = #wxSize{}} = Wx2 ->
135
get_latest_resize(Wx2)
140
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143
["all (ebin + app file)", "ebin + derived", "app file + derived", "derived", "none"].
145
list_to_mod_cond(List) ->
150
"derived" -> derived;
154
mod_cond_to_index(ModCond) ->
165
["include", "exclude", "derived"].
167
list_to_incl_cond(List) ->
169
"include" -> include;
170
"exclude" -> exclude;
174
incl_cond_to_index(ModCond) ->
181
elem_to_index(Elem, List) ->
182
elem_to_index(Elem, List, 1).
184
elem_to_index(Elem, [H | T], Index) ->
187
false -> elem_to_index(Elem, T, Index + 1)
189
elem_to_index(Elem, [], _) ->
190
erlang:error({not_found, Elem}).
192
app_dir_test(Dir1, Dir2) ->
193
{Name1, Vsn1, Parent1} = split_app_dir(Dir1),
194
{Name2, Vsn2, Parent2} = split_app_dir(Dir2),
196
Name1 < Name2 -> true;
197
Name1 > Name2 -> false;
198
Vsn1 < Vsn2 -> false;
200
Parent1 < Parent2 -> true;
204
split_app_dir(Dir) ->
205
ParentDir = filename:dirname(Dir),
206
Base = filename:basename(Dir),
207
{Name, Vsn} = split_app_name(Base),
210
[list_to_integer(N) || N <- string:tokens(Vsn, ".")]
215
{Name, Vsn2, ParentDir}.
217
get_item(ListCtrl) ->
218
case wxListCtrl:getItemCount(ListCtrl) of
222
case wxListCtrl:getNextItem(ListCtrl,
224
[{geometry, ?wxLIST_NEXT_ALL},
225
{state, ?wxLIST_STATE_SELECTED}]) of
227
ItemNo = wxListCtrl:getTopItem(ListCtrl),
228
case wxListCtrl:getItemText(ListCtrl, ItemNo) of
235
Text = wxListCtrl:getItemText(ListCtrl, ItemNo),
240
get_items(ListCtrl) ->
241
case wxListCtrl:getItemCount(ListCtrl) of
245
case get_selected_items(ListCtrl, -1, []) of
247
ItemNo = wxListCtrl:getTopItem(ListCtrl),
248
case wxListCtrl:getItemText(ListCtrl, ItemNo) of
251
Text when Text =/= ?MISSING_APP_TEXT ->
253
_MissingText when Count > 1 ->
254
case wxListCtrl:getItemText(ListCtrl, ItemNo + 1) of
268
get_selected_items(ListCtrl, PrevItem, Acc) ->
269
case wxListCtrl:getNextItem(ListCtrl,
271
[{geometry, ?wxLIST_NEXT_ALL},
272
{state, ?wxLIST_STATE_SELECTED}]) of
276
case wxListCtrl:getItemText(ListCtrl, ItemNo) of
277
Text when Text =/= ?MISSING_APP_TEXT ->
278
get_selected_items(ListCtrl, ItemNo, [{ItemNo, Text} | Acc]);
280
get_selected_items(ListCtrl, ItemNo, Acc)
284
select_items(_ListCtrl, _OldItems, []) ->
285
%% No new items. Nothing to select.
287
select_items(ListCtrl, [], Items) ->
288
%% No old selection. Select first.
289
select_item(ListCtrl, Items);
290
select_items(ListCtrl, _OldItems, [Item]) ->
291
%% Only one new item. Select it.
292
select_item(ListCtrl, [Item]);
293
select_items(ListCtrl, OldItems, NewItems) ->
294
%% Try to propagate old selection to new items.
296
fun({_OldItemNo, Text}) ->
297
case lists:keysearch(Text, 2, NewItems) of
298
{value, Item} -> {true, Item};
302
case lists:zf(Filter, OldItems) of
304
%% None of the old selections are valid. Select the first.
305
select_item(ListCtrl, NewItems);
307
%% Some old selections are still valid. Select them again.
308
lists:foreach(fun(Item) -> select_item(ListCtrl, [Item]) end, ValidItems)
311
select_item(ListCtrl, [{ItemNo, Text} | Items]) ->
312
case Text =:= ?MISSING_APP_TEXT of
314
select_item(ListCtrl, Items);
316
StateMask = ?wxLIST_STATE_SELECTED,
317
State = wxListCtrl:getItemState(ListCtrl, ItemNo, StateMask),
318
State2 = State bor ?wxLIST_STATE_SELECTED,
319
wxListCtrl:setItemState(ListCtrl, ItemNo, State2, StateMask),
320
wxListCtrl:refreshItem(ListCtrl, ItemNo)
322
select_item(_ListCtrl, []) ->
325
safe_keysearch(Key, Pos, List, Mod, Line) ->
326
case lists:keysearch(Key, Pos, List) of
328
io:format("~p(~p): lists:keysearch(~p, ~p, ~p) -> false\n",
329
[Mod, Line, Key, Pos, List]),
330
erlang:error({Mod, Line, lists, keysearch, [Key, Pos, List]});
335
print(X, X, Format, Args) ->
336
io:format(Format, Args);
340
%% -define(SAFE(M,F,A), safe(M, F, A, ?MODULE, ?LINE)).
342
%% safe(M, F, A, Mod, Line) ->
343
%% case catch apply(M, F, A) of
344
%% {'EXIT', Reason} ->
345
%% io:format("~p(~p): ~p:~p~p -> ~p\n", [Mod, Line, M, F, A, Reason]),
346
%% timer:sleep(infinity);
351
return_first_error(Status, NewError) when is_list(NewError) ->
359
add_warning(Status, Warning) ->
362
{ok, [Warning | Warnings]};