This file is indexed.

/usr/share/psychtoolbox-3/PsychOneliners/overrideBuiltInFunction.m is in psychtoolbox-3-common 3.0.12.20160126.dfsg1-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 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
% Method to override a MATLAB built-in function with a user-supplied function 
% with the same name. The way this works is that it replaces the built-in function
% with a function handle parameter whose name matches that of the overriden
% function.
%
% Usage:
%       functionName = overrideBuiltInFunction('functionName', overridingFunctionPath);
%
%       where the overridingFunctionPath string can be the full path to the overriding
%       function or a uniquely-identifying subset of the full path.
%
%       This call must be done in the script where you will use the override. 
%       To use across several scripts, make it a global function handle:
%
%       global functionName
%       functionName = overrideBuiltInFunction('functionName', overridingFunctionPath);
%
% Example Usage: 
%       Override Matlab's built-in function lab2xyz with the one supplied by ISETBIO
%       located in '/Users/Shared/Matlab/Toolboxes/ISETBIO/isettools/color/transforms'
%
%       lab2xyz = overrideBuiltInFunction('lab2xyz', 'isetbio');
%
% Test that it works:
%       clear all
%       functions(@lab2xyz)
%       lab2xyz = overrideBuiltInFunction('lab2xyz', 'isetbio');
%       functions(lab2xyz)
%
% Undoing the override:
%       To 'unoverride', simply clear the function handle. This should bring back
%       the built-in function, e.g.:
%
%       clear lab2xyz
%
%
% 10/9/2014   NPC  Wrote it.
%

function functionHandle = overrideBuiltInFunction(functionName, userPath)
    [paths, status] = which(functionName, '-all');
    
    if isempty(paths)
        error('''%s'' was not overriden. Function does not exist anywhere.\n', functionName); 
    end
    
    k = 0;
    foundInUserPath = false;
    while ((k < numel(paths)) && (~foundInUserPath))
        k = k + 1;
        if ~isempty(strfind(paths{k}, userPath))
            foundInUserPath = true;
        end
    end
    
    if (foundInUserPath)
        fullFunctionName = char(paths{k});
        [pathstr,name,~] = fileparts(fullFunctionName);
        localDir = pwd;
        cd(pathstr);
        functionHandle = str2func(name);
        cd(localDir);
    else
       error('''%s'' was not overriden. Not found in the specified path (''%s'').\n', functionName, userPath); 
    end
end