]> Creatis software - CreaPhase.git/blob - octave_packages/m/help/which.m
update packages
[CreaPhase.git] / octave_packages / m / help / which.m
1 ## Copyright (C) 2009-2012 John W. Eaton
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Command} {} which name @dots{}
21 ## Display the type of each @var{name}.  If @var{name} is defined from a
22 ## function file, the full name of the file is also displayed.
23 ## @seealso{help, lookfor}
24 ## @end deftypefn
25
26 function varargout = which (varargin)
27
28   if (nargin > 0 && iscellstr (varargin))
29     m = __which__ (varargin{:});
30
31     if (nargout == 0)
32       for i = 1:nargin
33         if (isempty (m(i).file))
34           if (! isempty (m(i).type))
35             printf ("`%s' is a %s\n",
36                     m(i).name, m(i).type);
37           endif
38         else
39           if (isempty (m(i).type))
40             printf ("`%s' is the file %s\n",
41                     m(i).name, m(i).file);
42           else
43             printf ("`%s' is a %s from the file %s\n",
44                     m(i).name, m(i).type, m(i).file);
45           endif
46         endif
47       endfor
48     else
49       varargout = {m.file};
50     endif
51   else
52     print_usage ();
53   endif
54
55 endfunction
56
57
58 %!test
59 %! str = which ("ls");
60 %! assert (str(end-17:end), strcat ("miscellaneous", filesep(), "ls.m"));
61 %!test
62 %! str = which ("dot");
63 %! assert (str(end-6:end), "dot.oct");
64
65 %!assert (which ("NO_NAME"), "");