forked from korbinian90/ASPIRE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetFileDependencies.m
executable file
·156 lines (134 loc) · 5.43 KB
/
getFileDependencies.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
function list = getFileDependencies(file)
% searches the paths of the .m-Files the given file is using. This function
% depends on the depfun-Function of Matlab. Though it is not guaranteed,
% that all files will be found. E.g. files in evaluate-constructs won't be
% found!!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Parameters:
% - file: the file for which the dependencies should be searched. This
% could be only a string with the function-name, the filename
% or the path to a file.
%
% Returns:
% - list: a cell-Array with the paths to all files the given file uses
% as strings. list is -1 if an error occured while processing.
% See errormessage for details.
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% author: Torsten Hopp
% last change: 03.07.2007
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% checking the input-parameter
if(isempty(file))
disp('ERROR. Input Parameter is empty')
list = -1;
return;
end
if(~ischar(file))
disp('ERROR. Input Parameter is not char')
list = -1;
return;
end
% list: a cell-array for the result
list = {which(file)};
% fileList: array of strings to search in the current iteration
fileList = list;
% While new files where found in last iteration
while (~isempty(fileList))
fileListSize = length(fileList);
newOnes = [];
newCounter = 1;
currentFileList = fileList;
fileList = [];
% running trough the current file list
for k=1:fileListSize
% calling depfun. -toponly indicates non-recursive search. -quiet
% suppresses output to command line
templist = depfun(currentFileList{k},'-toponly','-quiet');
% the first file is already included
templist(1) = [];
% calling the helper-function to delete files which contain
% <matlabroot> in the path from the list.
templist = deleteMatlabFiles(templist);
listSize = length(list);
tempListSize = length(templist);
% excluding first iteration with this if-clause
if(listSize > 1)
% comparing lists --> Searching for files that are not in the
% list yet
for i=1:tempListSize
contained = 0;
j=1;
% first condition stops comparing if something was found.
while contained == 0 & j<=listSize
if((strcmp(templist{i},list{j})==1) )
contained = 1;
end
j = j+1;
end
% if file isn't in the list yet...
if(contained == 0)
% add it to a cellArray for new filenames...
% if-clause excludes first run with empty
% newOnes-variable
if(~isempty(newOnes))
% if not first run: comparing the filename with the
% filenames that are in the newOnes-List to avoid
% double-enties
a = strfind(newOnes,templist{i});
counter = 0;
for p=1:length(a)
if(~isempty(a{p}))
counter = counter +1;
end
end
% if not found in list: add it to the list!
if(counter==0)
newOnes{newCounter} = templist{i};
newCounter = newCounter + 1;
end
else
% if list is empty: add it without checking!
newOnes{newCounter} = templist{i};
newCounter = newCounter + 1;
end
end
end
% if new filenames where found in this run...
if(~isempty(newOnes))
% ... search the new found files in the next iteration
fileList = [fileList newOnes];
% ... add the new found files to the list
list(length(list)+1:length(list)+length(newOnes)) = newOnes;
newOnes = [];
newCounter = 1;
end
else
% if first iteration: set the first-level dependecies as
% filelist for next iteration and add them to the list.
fileList = templist;
list = [list; templist];
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% HELPER FUNCTIONS %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function rList = deleteMatlabFiles(pList)
% deletes filenames with matlabroot in path from the given list.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameters:
% - pList: a cell-Array of filenames as string
%
% Returns:
% - rList: a cell-Array of filenames as string
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
excludedDir = matlabroot;
indexes = strfind(pList,excludedDir);
keepIndexes = cellfun(@isempty,indexes);
rList = pList(keepIndexes);