-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dependency_Tree.m
64 lines (47 loc) · 1.3 KB
/
Dependency_Tree.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function [fn, usage] = Dependency_Tree()
[fn, fc, im] = Build_File_List('.');
disp(fn);
disp(fc);
usage = zeros(numel(fc));
for i = 1:numel(fc)
usage(:,i) = File_Contains_Call(fn{i}, fc);
end
end
function out = File_Contains_Call(caller, targets)
fh = fopen(caller);
data = fscanf(fh, '%s');
fclose(fh);
out = cellfun(@(x)~isempty(strfind(data,x)), targets);
end
function [fnames, fcall, is_function] = Build_File_List(folder)
d = dir(folder);
c = {d.name}';
m = c(cellfun(@(x)~isempty(x), strfind(c,'.m')));
m = cellfun(@(x)fullfile(folder,x),m,'UniformOutput',false);
f = c(Find_Dirs(c));
f = cellfun(@(x)fullfile(folder,x),f,'UniformOutput',false);
nf = numel(f);
for i = 1:nf
m = [m; Build_File_List(f{i})];
end
if nargout >= 2
fcall = cellfun(@call_name, m, 'UniformOutput', false);
end
if nargout >= 3
is_function = cellfun(@(x)Is_Function(x), m);
end
fnames = m;
end
function out = Find_Dirs(fnames)
% Remove ./../.git
exclude = cellfun(@(x)isequal(x,'.'), fnames) | cellfun(@(x)isequal(x,'..'), fnames) | cellfun(@(x)isequal(x,'.git'), fnames);
out = ~exclude & cellfun(@isdir, fnames);
end
function out = Is_Function(fname)
fh = fopen(fname);
out = isequal(fscanf(fh, '%s', 1), 'function');
fclose(fh);
end
function out = call_name(fname)
[~,out,~] = fileparts(fname);
end