comparison _misc/tools/.svn/text-base/getFileDependencies.m.svn-base @ 8:b5b38998ef3b

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