1 ## Copyright (C) 2009-2012 John W. Eaton
3 ## This file is part of Octave.
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.
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.
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/>.
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}
26 function varargout = which (varargin)
28 if (nargin > 0 && iscellstr (varargin))
29 m = __which__ (varargin{:});
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);
39 if (isempty (m(i).type))
40 printf ("`%s' is the file %s\n",
41 m(i).name, m(i).file);
43 printf ("`%s' is a %s from the file %s\n",
44 m(i).name, m(i).type, m(i).file);
59 %! str = which ("ls");
60 %! assert (str(end-17:end), strcat ("miscellaneous", filesep(), "ls.m"));
62 %! str = which ("dot");
63 %! assert (str(end-6:end), "dot.oct");
65 %!assert (which ("NO_NAME"), "");