aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2015-10-07 09:15:32 +0200
committerBjörn Gustavsson <[email protected]>2016-05-04 13:04:28 +0200
commitd035b0cbaeb4f276b3d13613c1564ae7c90400e7 (patch)
tree99844f7e83cf554c95f84854eb8eec0baef4e071
parent4c8fdca47c9e727dfcc1ab2049ffea35cef76b39 (diff)
downloadotp-d035b0cbaeb4f276b3d13613c1564ae7c90400e7.tar.gz
otp-d035b0cbaeb4f276b3d13613c1564ae7c90400e7.tar.bz2
otp-d035b0cbaeb4f276b3d13613c1564ae7c90400e7.zip
epp: Refactor expansion of header path
scan_include_lib/4 uses a helper function find_lib_dir/1, which has a strange interface. It takes a string and returns a tuple. The caller must match the tuple and call fname_join/1 to obtain the desired result. I assume that the strange interface was not noticed because the function is only used in one place. Replace the find_lib_dir/1 with a new expand_lib_dir/1 function which does the entire job in one go. The new function is much easier to reuse in other places, which we might want to do in a future commit.
-rw-r--r--lib/stdlib/src/epp.erl23
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/stdlib/src/epp.erl b/lib/stdlib/src/epp.erl
index 55a818e87c..71c465dec3 100644
--- a/lib/stdlib/src/epp.erl
+++ b/lib/stdlib/src/epp.erl
@@ -933,9 +933,15 @@ scan_include(_Toks, Inc, From, St) ->
%% normal search path, if not we assume that the first directory name
%% is a library name, find its true directory and try with that.
-find_lib_dir(NewName) ->
- [Lib | Rest] = filename:split(NewName),
- {code:lib_dir(list_to_atom(Lib)), Rest}.
+expand_lib_dir(Name) ->
+ try
+ [App|Path] = filename:split(Name),
+ LibDir = code:lib_dir(list_to_atom(App)),
+ {ok,fname_join([LibDir|Path])}
+ catch
+ _:_ ->
+ error
+ end.
scan_include_lib([{'(',_Llp},{string,_Lf,_NewName0},{')',_Lrp},{dot,_Ld}],
Inc, From, St)
@@ -950,12 +956,11 @@ scan_include_lib([{'(',_Llp},{string,_Lf,NewName0},{')',_Lrp},{dot,_Ld}],
{ok,NewF,Pname} ->
wait_req_scan(enter_file2(NewF, Pname, From, St, Loc));
{error,_E1} ->
- case catch find_lib_dir(NewName) of
- {LibDir, Rest} when is_list(LibDir) ->
- LibName = fname_join([LibDir | Rest]),
- case file:open(LibName, [read]) of
+ case expand_lib_dir(NewName) of
+ {ok,Header} ->
+ case file:open(Header, [read]) of
{ok,NewF} ->
- wait_req_scan(enter_file2(NewF, LibName, From,
+ wait_req_scan(enter_file2(NewF, Header, From,
St, Loc));
{error,_E2} ->
epp_reply(From,
@@ -963,7 +968,7 @@ scan_include_lib([{'(',_Llp},{string,_Lf,NewName0},{')',_Lrp},{dot,_Ld}],
{include,lib,NewName}}}),
wait_req_scan(St)
end;
- _Error ->
+ error ->
epp_reply(From, {error,{loc(Inc),epp,
{include,lib,NewName}}}),
wait_req_scan(St)