matthiasm@8: function list = getFileDependencies(file) matthiasm@8: % searches the paths of the .m-Files the given file is using. This function matthiasm@8: % depends on the depfun-Function of Matlab. Though it is not guaranteed, matthiasm@8: % that all files will be found. E.g. files in evaluate-constructs won't be matthiasm@8: % found!! matthiasm@8: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@8: % matthiasm@8: % Parameters: matthiasm@8: % - file: the file for which the dependencies should be searched. This matthiasm@8: % could be only a string with the function-name, the filename matthiasm@8: % or the path to a file. matthiasm@8: % matthiasm@8: % Returns: matthiasm@8: % - list: a cell-Array with the paths to all files the given file uses matthiasm@8: % as strings. list is -1 if an error occured while processing. matthiasm@8: % See errormessage for details. matthiasm@8: % matthiasm@8: % matthiasm@8: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@8: % matthiasm@8: % author: Torsten Hopp matthiasm@8: % last change: 03.07.2007 matthiasm@8: % matthiasm@8: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@8: matthiasm@8: matthiasm@8: % checking the input-parameter matthiasm@8: if(isempty(file)) matthiasm@8: disp('ERROR. Input Parameter is empty') matthiasm@8: list = -1; matthiasm@8: return; matthiasm@8: end matthiasm@8: if(~ischar(file)) matthiasm@8: disp('ERROR. Input Parameter is not char') matthiasm@8: list = -1; matthiasm@8: return; matthiasm@8: end matthiasm@8: matthiasm@8: matthiasm@8: % list: a cell-array for the result matthiasm@8: list = {which(file)}; matthiasm@8: % fileList: array of strings to search in the current iteration matthiasm@8: fileList = list; matthiasm@8: matthiasm@8: % While new files where found in last iteration matthiasm@8: while (~isempty(fileList)) matthiasm@8: fileListSize = length(fileList); matthiasm@8: newOnes = []; matthiasm@8: newCounter = 1; matthiasm@8: currentFileList = fileList; matthiasm@8: fileList = []; matthiasm@8: matthiasm@8: % running trough the current file list matthiasm@8: for k=1:fileListSize matthiasm@8: % calling depfun. -toponly indicates non-recursive search. -quiet matthiasm@8: % suppresses output to command line matthiasm@8: templist = depfun(currentFileList{k},'-toponly','-quiet'); matthiasm@8: matthiasm@8: % the first file is already included matthiasm@8: templist(1) = []; matthiasm@8: matthiasm@8: % calling the helper-function to delete files which contain matthiasm@8: % in the path from the list. matthiasm@8: templist = deleteMatlabFiles(templist); matthiasm@8: matthiasm@8: listSize = length(list); matthiasm@8: tempListSize = length(templist); matthiasm@8: matthiasm@8: % excluding first iteration with this if-clause matthiasm@8: if(listSize > 1) matthiasm@8: matthiasm@8: % comparing lists --> Searching for files that are not in the matthiasm@8: % list yet matthiasm@8: for i=1:tempListSize matthiasm@8: contained = 0; matthiasm@8: j=1; matthiasm@8: % first condition stops comparing if something was found. matthiasm@8: while contained == 0 & j<=listSize matthiasm@8: if((strcmp(templist{i},list{j})==1) ) matthiasm@8: contained = 1; matthiasm@8: end matthiasm@8: j = j+1; matthiasm@8: end matthiasm@8: matthiasm@8: % if file isn't in the list yet... matthiasm@8: if(contained == 0) matthiasm@8: matthiasm@8: % add it to a cellArray for new filenames... matthiasm@8: % if-clause excludes first run with empty matthiasm@8: % newOnes-variable matthiasm@8: if(~isempty(newOnes)) matthiasm@8: matthiasm@8: % if not first run: comparing the filename with the matthiasm@8: % filenames that are in the newOnes-List to avoid matthiasm@8: % double-enties matthiasm@8: a = strfind(newOnes,templist{i}); matthiasm@8: counter = 0; matthiasm@8: for p=1:length(a) matthiasm@8: if(~isempty(a{p})) matthiasm@8: counter = counter +1; matthiasm@8: end matthiasm@8: end matthiasm@8: % if not found in list: add it to the list! matthiasm@8: if(counter==0) matthiasm@8: newOnes{newCounter} = templist{i}; matthiasm@8: newCounter = newCounter + 1; matthiasm@8: end matthiasm@8: else matthiasm@8: % if list is empty: add it without checking! matthiasm@8: newOnes{newCounter} = templist{i}; matthiasm@8: newCounter = newCounter + 1; matthiasm@8: end matthiasm@8: end matthiasm@8: end matthiasm@8: matthiasm@8: % if new filenames where found in this run... matthiasm@8: if(~isempty(newOnes)) matthiasm@8: % ... search the new found files in the next iteration matthiasm@8: fileList = [fileList newOnes]; matthiasm@8: % ... add the new found files to the list matthiasm@8: list(length(list)+1:length(list)+length(newOnes)) = newOnes; matthiasm@8: newOnes = []; matthiasm@8: newCounter = 1; matthiasm@8: end matthiasm@8: else matthiasm@8: % if first iteration: set the first-level dependecies as matthiasm@8: % filelist for next iteration and add them to the list. matthiasm@8: fileList = templist; matthiasm@8: list = [list; templist]; matthiasm@8: end matthiasm@8: end matthiasm@8: end matthiasm@8: matthiasm@8: matthiasm@8: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@8: % HELPER FUNCTIONS % matthiasm@8: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@8: matthiasm@8: matthiasm@8: function rList = deleteMatlabFiles(pList) matthiasm@8: % deletes filenames with matlabroot in path from the given list. matthiasm@8: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@8: % Parameters: matthiasm@8: % - pList: a cell-Array of filenames as string matthiasm@8: % matthiasm@8: % Returns: matthiasm@8: % - rList: a cell-Array of filenames as string matthiasm@8: % matthiasm@8: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@8: excludedDir = matlabroot; matthiasm@8: indexes = strfind(pList,excludedDir); matthiasm@8: keepIndexes = cellfun(@isempty,indexes); matthiasm@8: rList = pList(keepIndexes); matthiasm@8: matthiasm@8: matthiasm@8: