time | calls | line |
---|
| | 1 | function varargout = mdbfileonpath(inFilename, resolveSymbolicLinks)
|
| | 2 | %MDBFILEONPATH Helper function for the Editor/Debugger
|
| | 3 | % MDBFILEONPATH is passed a string containing an absolute filename of an
|
| | 4 | % file.
|
| | 5 | % It returns:
|
| | 6 | % a filename:
|
| | 7 | % the filename that will be run (may be a shadower)
|
| | 8 | % if file not found on the path and isn't shadowed, returns the
|
| | 9 | % filename passed in
|
| | 10 | % an integer defined in com.mathworks.mlwidgets.dialog.PathUpdateDialog
|
| | 11 | % describing the status:
|
| | 12 | % FILE_NOT_ON_PATH - file not on the path or error occurred
|
| | 13 | % FILE_WILL_RUN - file is the one MATLAB will run (or is shadowed by a newer
|
| | 14 | % p-file)
|
| | 15 | % FILE_SHADOWED_BY_PWD - file is shadowed by another file in the current directory
|
| | 16 | % FILE_SHADOWED_BY_TBX - file is shadowed by another file somewhere in the MATLAB path
|
| | 17 | % FILE_SHADOWED_BY_PFILE - file is shadowed by a p-file in the same directory
|
| | 18 | % FILE_SHADOWED_BY_MEXFILE - file is shadowed by a mex, mdl, or slx file in the same directory
|
| | 19 | %
|
| | 20 | % inFilename should be an absolute filename with extension ".m" (no
|
| | 21 | % checking is done).
|
| | 22 | % resolveSymbolicLinks should be a boolean specifying whether symbolic
|
| | 23 | % links should be resolved as part of determining if inFilename is on the
|
| | 24 | % path. If this argument is not specified, the default value of false is used.
|
| | 25 | %
|
| | 26 | % This file is for internal use only and is subject to change without
|
| | 27 | % notice.
|
| | 28 |
|
| | 29 | % Copyright 1984-2014 The MathWorks, Inc.
|
| | 30 |
|
| 1 | 31 | if nargin > 0
|
| 1 | 32 | try
|
| 1 | 33 | if nargin == 1
|
| | 34 | resolveSymbolicLinks = false;
|
| | 35 | end
|
| | 36 |
|
0.01 | 1 | 37 | [path, fn] = fileparts(inFilename);
|
| | 38 |
|
| | 39 | import com.mathworks.jmi.MLFileUtils;
|
| | 40 | import com.mathworks.services.mlx.MlxFileUtils;
|
| 1 | 41 | fileTypes = {
|
| | 42 | {mexext, ... Mex file type
|
| | 43 | @()MLFileUtils.isNativeMexFile(inFilename), ...
|
| | 44 | @(path)getMexShadowStatus(path)}, ...
|
| | 45 | {'slx', ... Simulink model .slx file type
|
| | 46 | @()MLFileUtils.isMdlFile(inFilename), ...
|
| | 47 | @(path)getMexShadowStatus(path)}, ...
|
| | 48 | {'mdl', ... Simulink model .mdl file type
|
| | 49 | @()MLFileUtils.isMdlFile(inFilename), ...
|
| | 50 | @(path)getMexShadowStatus(path)}, ...
|
| | 51 | {'mlx', ... MLX file type
|
| | 52 | @()MlxFileUtils.isMlxFile(inFilename), ...
|
| | 53 | @(path)getMlxFileShadowStatus(path)}, ...
|
| | 54 | {'p', ... P file type
|
| | 55 | @()MLFileUtils.isPFile(inFilename), ...
|
| | 56 | @(path)getPFileShadowStatus(path)}};
|
| | 57 |
|
| 1 | 58 | for i=1:numel(fileTypes)
|
| 5 | 59 | fileTypeEntry = fileTypes{i};
|
0.01 | 5 | 60 | pathWithExt = fullfile(path, [fn '.' fileTypeEntry{1}]);
|
| 5 | 61 | if (fileTypeEntry{2}())
|
| | 62 | break;
|
| 5 | 63 | elseif doesFileExist(pathWithExt)
|
| | 64 | fh = fileTypeEntry{3};
|
| | 65 | [shadowStatus, fullpath] = fh(pathWithExt);
|
| | 66 | break;
|
| | 67 | end
|
| 5 | 68 | end
|
| | 69 |
|
| 1 | 70 | if exist('shadowStatus', 'var') == 0
|
0.03 | 1 | 71 | [shadowStatus, fullpath] = checkIfShadowed(inFilename);
|
| 1 | 72 | end
|
| | 73 |
|
| 1 | 74 | varargout{1} = fullpath;
|
| 1 | 75 | varargout{2} = shadowStatus;
|
| | 76 | catch
|
| | 77 | varargout{1} = inFilename;
|
| | 78 | varargout{2} = 0;
|
| | 79 | end
|
| | 80 | else
|
| | 81 | varargout{1} = '';
|
| | 82 | varargout{2} = 0;
|
| | 83 | end
|
| | 84 |
|
| | 85 | function [shadowStatus, fullpath] = getMexShadowStatus(fullpath)
|
| | 86 | % Mex shadow status returned for mex, mdl and slx.
|
| | 87 | shadowStatus = com.mathworks.mlwidgets.dialog.PathUpdateDialog.FILE_SHADOWED_BY_MEXFILE;
|
| | 88 | end
|
| | 89 |
|
| | 90 | function [shadowStatus, fullpath] = getPFileShadowStatus(fullpath)
|
| | 91 | % Check if there is a p-file shadowing this file in the same
|
| | 92 | % directory. If there is (and if the ".m" file is newer), then
|
| | 93 | % report that the p-file is shadowing it.
|
| | 94 | mdirInfo = dir(inFilename);
|
| | 95 | pdirInfo = dir(fullpath);
|
| | 96 | % If the p-file is newer than the ".m" file, assume that it's OK
|
| | 97 | if (pdirInfo.datenum >= mdirInfo.datenum)
|
| | 98 | [shadowStatus, fullpath] = checkIfShadowed(internal.matlab.desktop.editor.unmapFilePath(fullpath));
|
| | 99 | else
|
| | 100 | shadowStatus = com.mathworks.mlwidgets.dialog.PathUpdateDialog.FILE_SHADOWED_BY_PFILE;
|
| | 101 | end
|
| | 102 | end
|
| | 103 |
|
| | 104 | function [shadowStatus, fullpath] = getMlxFileShadowStatus(fullpath)
|
| | 105 | % Returning 'shadowed by MLX file' since this function is only
|
| | 106 | % called if an MLX file exists.
|
| | 107 | shadowStatus = com.mathworks.mlwidgets.dialog.PathUpdateDialog.FILE_SHADOWED_BY_MLXFILE;
|
| | 108 | end
|
| | 109 |
|
| | 110 | function [shadowStatus, fullpath] = checkIfShadowed(inFilename)
|
| | 111 | [path, fn, ext] = filepartsWithoutPackages(inFilename);
|
| | 112 | xfiletorun = getFileToRun(inFilename);
|
| | 113 | import com.mathworks.mlwidgets.dialog.PathUpdateDialog;
|
| | 114 | if ~isempty(xfiletorun)
|
| | 115 | [xpath, xfn, xext] = filepartsWithoutPackages(xfiletorun);
|
| | 116 | arePathsEqual = areDirectoriesEqual(xpath, path, resolveSymbolicLinks);
|
| | 117 |
|
| | 118 | if arePathsEqual && areFilenamesEqual(xfn, fn) && ...
|
| | 119 | areFilenamesEqual(xext, ext)
|
| | 120 | % The executable fileparts are identical to the file passed in
|
| | 121 | fullpath = xfiletorun;
|
| | 122 | % MATLAB will run the file
|
| | 123 | shadowStatus = PathUpdateDialog.FILE_WILL_RUN;
|
| | 124 | elseif ~arePathsEqual || (~areFilenamesEqual(xfn, fn) && areFilenamesEqual(xext, ext))
|
| | 125 | % If paths are equal, can only happen on unix: eg foo.m and FOO.m.
|
| | 126 | fullpath = xfiletorun;
|
| | 127 | if areDirectoriesEqual(xpath, pwd, resolveSymbolicLinks)
|
| | 128 | shadowStatus = PathUpdateDialog.FILE_SHADOWED_BY_PWD;
|
| | 129 | else
|
| | 130 | % shadower on path
|
| | 131 | shadowStatus = PathUpdateDialog.FILE_SHADOWED_BY_TBX;
|
| | 132 | end
|
| | 133 | end
|
| | 134 | else
|
| | 135 | fullpath = inFilename;
|
| | 136 | shadowStatus = PathUpdateDialog.FILE_NOT_ON_PATH;
|
| | 137 | end
|
| | 138 | end
|
| 1 | 139 | end
|
Other subfunctions in this file are not included in this listing.