matthiasm@8
|
1 function list = getFileDependencies(file)
|
matthiasm@8
|
2 % searches the paths of the .m-Files the given file is using. This function
|
matthiasm@8
|
3 % depends on the depfun-Function of Matlab. Though it is not guaranteed,
|
matthiasm@8
|
4 % that all files will be found. E.g. files in evaluate-constructs won't be
|
matthiasm@8
|
5 % found!!
|
matthiasm@8
|
6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@8
|
7 %
|
matthiasm@8
|
8 % Parameters:
|
matthiasm@8
|
9 % - file: the file for which the dependencies should be searched. This
|
matthiasm@8
|
10 % could be only a string with the function-name, the filename
|
matthiasm@8
|
11 % or the path to a file.
|
matthiasm@8
|
12 %
|
matthiasm@8
|
13 % Returns:
|
matthiasm@8
|
14 % - list: a cell-Array with the paths to all files the given file uses
|
matthiasm@8
|
15 % as strings. list is -1 if an error occured while processing.
|
matthiasm@8
|
16 % See errormessage for details.
|
matthiasm@8
|
17 %
|
matthiasm@8
|
18 %
|
matthiasm@8
|
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@8
|
20 %
|
matthiasm@8
|
21 % author: Torsten Hopp
|
matthiasm@8
|
22 % last change: 03.07.2007
|
matthiasm@8
|
23 %
|
matthiasm@8
|
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@8
|
25
|
matthiasm@8
|
26
|
matthiasm@8
|
27 % checking the input-parameter
|
matthiasm@8
|
28 if(isempty(file))
|
matthiasm@8
|
29 disp('ERROR. Input Parameter is empty')
|
matthiasm@8
|
30 list = -1;
|
matthiasm@8
|
31 return;
|
matthiasm@8
|
32 end
|
matthiasm@8
|
33 if(~ischar(file))
|
matthiasm@8
|
34 disp('ERROR. Input Parameter is not char')
|
matthiasm@8
|
35 list = -1;
|
matthiasm@8
|
36 return;
|
matthiasm@8
|
37 end
|
matthiasm@8
|
38
|
matthiasm@8
|
39
|
matthiasm@8
|
40 % list: a cell-array for the result
|
matthiasm@8
|
41 list = {which(file)};
|
matthiasm@8
|
42 % fileList: array of strings to search in the current iteration
|
matthiasm@8
|
43 fileList = list;
|
matthiasm@8
|
44
|
matthiasm@8
|
45 % While new files where found in last iteration
|
matthiasm@8
|
46 while (~isempty(fileList))
|
matthiasm@8
|
47 fileListSize = length(fileList);
|
matthiasm@8
|
48 newOnes = [];
|
matthiasm@8
|
49 newCounter = 1;
|
matthiasm@8
|
50 currentFileList = fileList;
|
matthiasm@8
|
51 fileList = [];
|
matthiasm@8
|
52
|
matthiasm@8
|
53 % running trough the current file list
|
matthiasm@8
|
54 for k=1:fileListSize
|
matthiasm@8
|
55 % calling depfun. -toponly indicates non-recursive search. -quiet
|
matthiasm@8
|
56 % suppresses output to command line
|
matthiasm@8
|
57 templist = depfun(currentFileList{k},'-toponly','-quiet');
|
matthiasm@8
|
58
|
matthiasm@8
|
59 % the first file is already included
|
matthiasm@8
|
60 templist(1) = [];
|
matthiasm@8
|
61
|
matthiasm@8
|
62 % calling the helper-function to delete files which contain
|
matthiasm@8
|
63 % <matlabroot> in the path from the list.
|
matthiasm@8
|
64 templist = deleteMatlabFiles(templist);
|
matthiasm@8
|
65
|
matthiasm@8
|
66 listSize = length(list);
|
matthiasm@8
|
67 tempListSize = length(templist);
|
matthiasm@8
|
68
|
matthiasm@8
|
69 % excluding first iteration with this if-clause
|
matthiasm@8
|
70 if(listSize > 1)
|
matthiasm@8
|
71
|
matthiasm@8
|
72 % comparing lists --> Searching for files that are not in the
|
matthiasm@8
|
73 % list yet
|
matthiasm@8
|
74 for i=1:tempListSize
|
matthiasm@8
|
75 contained = 0;
|
matthiasm@8
|
76 j=1;
|
matthiasm@8
|
77 % first condition stops comparing if something was found.
|
matthiasm@8
|
78 while contained == 0 & j<=listSize
|
matthiasm@8
|
79 if((strcmp(templist{i},list{j})==1) )
|
matthiasm@8
|
80 contained = 1;
|
matthiasm@8
|
81 end
|
matthiasm@8
|
82 j = j+1;
|
matthiasm@8
|
83 end
|
matthiasm@8
|
84
|
matthiasm@8
|
85 % if file isn't in the list yet...
|
matthiasm@8
|
86 if(contained == 0)
|
matthiasm@8
|
87
|
matthiasm@8
|
88 % add it to a cellArray for new filenames...
|
matthiasm@8
|
89 % if-clause excludes first run with empty
|
matthiasm@8
|
90 % newOnes-variable
|
matthiasm@8
|
91 if(~isempty(newOnes))
|
matthiasm@8
|
92
|
matthiasm@8
|
93 % if not first run: comparing the filename with the
|
matthiasm@8
|
94 % filenames that are in the newOnes-List to avoid
|
matthiasm@8
|
95 % double-enties
|
matthiasm@8
|
96 a = strfind(newOnes,templist{i});
|
matthiasm@8
|
97 counter = 0;
|
matthiasm@8
|
98 for p=1:length(a)
|
matthiasm@8
|
99 if(~isempty(a{p}))
|
matthiasm@8
|
100 counter = counter +1;
|
matthiasm@8
|
101 end
|
matthiasm@8
|
102 end
|
matthiasm@8
|
103 % if not found in list: add it to the list!
|
matthiasm@8
|
104 if(counter==0)
|
matthiasm@8
|
105 newOnes{newCounter} = templist{i};
|
matthiasm@8
|
106 newCounter = newCounter + 1;
|
matthiasm@8
|
107 end
|
matthiasm@8
|
108 else
|
matthiasm@8
|
109 % if list is empty: add it without checking!
|
matthiasm@8
|
110 newOnes{newCounter} = templist{i};
|
matthiasm@8
|
111 newCounter = newCounter + 1;
|
matthiasm@8
|
112 end
|
matthiasm@8
|
113 end
|
matthiasm@8
|
114 end
|
matthiasm@8
|
115
|
matthiasm@8
|
116 % if new filenames where found in this run...
|
matthiasm@8
|
117 if(~isempty(newOnes))
|
matthiasm@8
|
118 % ... search the new found files in the next iteration
|
matthiasm@8
|
119 fileList = [fileList newOnes];
|
matthiasm@8
|
120 % ... add the new found files to the list
|
matthiasm@8
|
121 list(length(list)+1:length(list)+length(newOnes)) = newOnes;
|
matthiasm@8
|
122 newOnes = [];
|
matthiasm@8
|
123 newCounter = 1;
|
matthiasm@8
|
124 end
|
matthiasm@8
|
125 else
|
matthiasm@8
|
126 % if first iteration: set the first-level dependecies as
|
matthiasm@8
|
127 % filelist for next iteration and add them to the list.
|
matthiasm@8
|
128 fileList = templist;
|
matthiasm@8
|
129 list = [list; templist];
|
matthiasm@8
|
130 end
|
matthiasm@8
|
131 end
|
matthiasm@8
|
132 end
|
matthiasm@8
|
133
|
matthiasm@8
|
134
|
matthiasm@8
|
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@8
|
136 % HELPER FUNCTIONS %
|
matthiasm@8
|
137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@8
|
138
|
matthiasm@8
|
139
|
matthiasm@8
|
140 function rList = deleteMatlabFiles(pList)
|
matthiasm@8
|
141 % deletes filenames with matlabroot in path from the given list.
|
matthiasm@8
|
142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@8
|
143 % Parameters:
|
matthiasm@8
|
144 % - pList: a cell-Array of filenames as string
|
matthiasm@8
|
145 %
|
matthiasm@8
|
146 % Returns:
|
matthiasm@8
|
147 % - rList: a cell-Array of filenames as string
|
matthiasm@8
|
148 %
|
matthiasm@8
|
149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@8
|
150 excludedDir = matlabroot;
|
matthiasm@8
|
151 indexes = strfind(pList,excludedDir);
|
matthiasm@8
|
152 keepIndexes = cellfun(@isempty,indexes);
|
matthiasm@8
|
153 rList = pList(keepIndexes);
|
matthiasm@8
|
154
|
matthiasm@8
|
155
|
matthiasm@8
|
156
|