annotate scripts/miscellaneous/what.m @ 28127:9413b3d56e00 stable

what.m: Report mex files in directory (bug #57877) * what.m: Change comparison of extension looking for mex file from "mexext" to "['.' mexext]" because extension includes the period.
author Rik <rik@octave.org>
date Fri, 21 Feb 2020 14:07:14 -0800
parents bd51beb6205e
children 28de41192f3c 0a5b15007766
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27928
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
2 ##
27924
1891570abac8 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
3 ## Copyright (C) 2007-2020 The Octave Project Developers
27923
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27910
diff changeset
4 ##
27928
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
7 ##
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
8 ## This file is part of Octave.
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
14 ##
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
19 ##
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27928
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
24 ########################################################################
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
25
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20164
diff changeset
27 ## @deftypefn {} {} what
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20164
diff changeset
28 ## @deftypefnx {} {} what @var{dir}
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20164
diff changeset
29 ## @deftypefnx {} {w =} what (@var{dir})
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
30 ## List the Octave specific files in directory @var{dir}.
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
31 ##
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
32 ## If @var{dir} is not specified then the current directory is used.
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
33 ##
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
34 ## If a return argument is requested, the files found are returned in the
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
35 ## structure @var{w}. The structure contains the following fields:
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
36 ##
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
37 ## @table @asis
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
38 ## @item path
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
39 ## Full path to directory @var{dir}
19405
cbce5d1bcaf9 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19183
diff changeset
40 ##
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
41 ## @item m
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
42 ## Cell array of m-files
19405
cbce5d1bcaf9 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19183
diff changeset
43 ##
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
44 ## @item mat
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
45 ## Cell array of mat files
19405
cbce5d1bcaf9 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19183
diff changeset
46 ##
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
47 ## @item mex
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
48 ## Cell array of mex files
19405
cbce5d1bcaf9 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19183
diff changeset
49 ##
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
50 ## @item oct
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
51 ## Cell array of oct files
19405
cbce5d1bcaf9 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19183
diff changeset
52 ##
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
53 ## @item mdl
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
54 ## Cell array of mdl files
19405
cbce5d1bcaf9 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19183
diff changeset
55 ##
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
56 ## @item slx
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
57 ## Cell array of slx files
19405
cbce5d1bcaf9 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19183
diff changeset
58 ##
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
59 ## @item p
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
60 ## Cell array of p-files
19405
cbce5d1bcaf9 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19183
diff changeset
61 ##
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
62 ## @item classes
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
63 ## Cell array of class directories (@file{@@@var{classname}/})
19405
cbce5d1bcaf9 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19183
diff changeset
64 ##
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
65 ## @item packages
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
66 ## Cell array of package directories (@file{+@var{pkgname}/})
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
67 ## @end table
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
68 ##
27910
d1862db3bffb what.m: clean up function.
Rik <rik@octave.org>
parents: 27909
diff changeset
69 ## Compatibility Note: Octave does not support mdl, slx, and p files.
d1862db3bffb what.m: clean up function.
Rik <rik@octave.org>
parents: 27909
diff changeset
70 ## @code{what} will always return an empty list for these categories.
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
71 ## @seealso{which, ls, exist}
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
72 ## @end deftypefn
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
73
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
74 function retval = what (dir)
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
75
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
76 if (nargin > 1)
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
77 print_usage ();
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
78 endif
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
79
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
80 if (nargin == 0)
27909
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
81 dir = { pwd() };
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
82 else
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
83 dtmp = canonicalize_file_name (dir);
18060
427412d40f1a what.m: Workaround file separator issues in code (bug #40726).
Rik <rik@octave.org>
parents: 17744
diff changeset
84 if (isempty (dtmp))
27909
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
85 dtmp = {};
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
86 else
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
87 dtmp = {dtmp};
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
88 endif
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
89 ## Search for directory name in path
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
90 if (dir(end) == '/' || dir(end) == '\')
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
91 dir(end) = [];
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
92 endif
27909
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
93 dtmp = unique ([dtmp; dir_in_loadpath(dir, "all")]);
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
94
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
95 if (isempty (dtmp) && nargout == 0)
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
96 printf ("%s not found\n", dir);
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
97 return;
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
98 endif
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
99
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
100 dir = dtmp;
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
101 endif
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
102
27909
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
103 ## Lookup info for each directory
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
104 for i = 1 : numel (dir)
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
105 w(i) = __what__ (dir{i});
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
106 endfor
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
107
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
108 ## If none was found, return an empty struct
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
109 if (numel (dir) == 0)
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
110 w = __what__ ("");
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
111 w = resize (w, [0, 1]); # Matlab compatibility, return 0x1 empty array
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
112 end
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
113
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
114 if (nargout == 0)
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
115 for i = 1 : numel (w)
27910
d1862db3bffb what.m: clean up function.
Rik <rik@octave.org>
parents: 27909
diff changeset
116 __print_fnames__ ("M-files in directory", w(i).path, w(i).m);
d1862db3bffb what.m: clean up function.
Rik <rik@octave.org>
parents: 27909
diff changeset
117 __print_fnames__ ("\nMAT-files in directory", w(i).path, w(i).mat);
d1862db3bffb what.m: clean up function.
Rik <rik@octave.org>
parents: 27909
diff changeset
118 __print_fnames__ ("\nMEX-files in directory", w(i).path, w(i).mex);
d1862db3bffb what.m: clean up function.
Rik <rik@octave.org>
parents: 27909
diff changeset
119 __print_fnames__ ("\nOCT-files in directory", w(i).path, w(i).oct);
d1862db3bffb what.m: clean up function.
Rik <rik@octave.org>
parents: 27909
diff changeset
120 __print_fnames__ ("\nClasses in directory", w(i).path, w(i).classes);
d1862db3bffb what.m: clean up function.
Rik <rik@octave.org>
parents: 27909
diff changeset
121 __print_fnames__ ("\nPackages in directory", w(i).path, w(i).packages);
27909
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
122 endfor
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
123 else
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
124 retval = w;
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
125 endif
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
126
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
127 endfunction
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
128
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
129
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
130 ## what() functionality for a single directory
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
131 function w = __what__ (dir)
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
132
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
133 files = readdir (dir);
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
134 w.path = dir;
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
135 w.m = cell (0, 1);
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
136 w.mat = cell (0, 1);
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
137 w.mex = cell (0, 1);
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
138 w.oct = cell (0, 1);
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
139 w.mdl = cell (0, 1);
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
140 w.slx = cell (0, 1);
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
141 w.p = cell (0, 1);
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
142 w.classes = cell (0, 1);
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
143 w.packages = cell (0, 1);
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
144
27910
d1862db3bffb what.m: clean up function.
Rik <rik@octave.org>
parents: 27909
diff changeset
145 for i = 1 : numel (files)
27907
32f4a15c77c7 what.m: Detect and report on packages (bug #57530)
Rik <rik@octave.org>
parents: 26379
diff changeset
146 nm = files{i};
32f4a15c77c7 what.m: Detect and report on packages (bug #57530)
Rik <rik@octave.org>
parents: 26379
diff changeset
147
32f4a15c77c7 what.m: Detect and report on packages (bug #57530)
Rik <rik@octave.org>
parents: 26379
diff changeset
148 if (strcmp (nm, ".") || strcmp (nm, ".."))
32f4a15c77c7 what.m: Detect and report on packages (bug #57530)
Rik <rik@octave.org>
parents: 26379
diff changeset
149 continue; # Ignore . and ..
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
150 endif
27907
32f4a15c77c7 what.m: Detect and report on packages (bug #57530)
Rik <rik@octave.org>
parents: 26379
diff changeset
151
32f4a15c77c7 what.m: Detect and report on packages (bug #57530)
Rik <rik@octave.org>
parents: 26379
diff changeset
152 ## mdl, slx, and p are ignored (no if test) since they are not implemented
32f4a15c77c7 what.m: Detect and report on packages (bug #57530)
Rik <rik@octave.org>
parents: 26379
diff changeset
153 [~, f, e] = fileparts (nm);
32f4a15c77c7 what.m: Detect and report on packages (bug #57530)
Rik <rik@octave.org>
parents: 26379
diff changeset
154 if (strcmp (e, ".m"))
27908
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
155 if (isfile (fullfile (dir, nm)))
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
156 w.m{end+1} = nm;
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
157 endif
27907
32f4a15c77c7 what.m: Detect and report on packages (bug #57530)
Rik <rik@octave.org>
parents: 26379
diff changeset
158 elseif (strcmp (e, ".mat"))
27908
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
159 if (isfile (fullfile (dir, nm)))
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
160 w.mat{end+1} = nm;
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
161 endif
27907
32f4a15c77c7 what.m: Detect and report on packages (bug #57530)
Rik <rik@octave.org>
parents: 26379
diff changeset
162 elseif (strcmp (e, ".oct"))
27908
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
163 if (isfile (fullfile (dir, nm)))
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
164 w.oct{end+1} = nm;
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
165 endif
28127
9413b3d56e00 what.m: Report mex files in directory (bug #57877)
Rik <rik@octave.org>
parents: 27928
diff changeset
166 elseif (strcmp (e, ['.' mexext]))
27908
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
167 if (isfile (fullfile (dir, nm)))
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
168 w.mex{end+1} = nm;
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
169 endif
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
170 elseif (nm(1) == "@")
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
171 if (isfolder (fullfile (dir, nm)))
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
172 w.classes{end+1} = nm;
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
173 endif
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
174 elseif (nm(1) == "+")
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
175 if (isfolder (fullfile (dir, nm)))
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
176 w.packages{end+1} = nm;
f7279dd915d8 what.m: Check file / folder status before returning results (bug #57531).
Rik <rik@octave.org>
parents: 27907
diff changeset
177 endif
27907
32f4a15c77c7 what.m: Detect and report on packages (bug #57530)
Rik <rik@octave.org>
parents: 26379
diff changeset
178 endif
32f4a15c77c7 what.m: Detect and report on packages (bug #57530)
Rik <rik@octave.org>
parents: 26379
diff changeset
179
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
180 endfor
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
181
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
182 endfunction
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
183
27909
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
184
121d33ab44bc what.m: Find all instances in loadpath for Matlab compatibility (bug #40904).
Rik <rik@octave.org>
parents: 27908
diff changeset
185 ## Pretty print filenames to terminal
27910
d1862db3bffb what.m: clean up function.
Rik <rik@octave.org>
parents: 27909
diff changeset
186 function __print_fnames__ (msg, p, f)
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
187
27910
d1862db3bffb what.m: clean up function.
Rik <rik@octave.org>
parents: 27909
diff changeset
188 if (! isempty (f))
d1862db3bffb what.m: clean up function.
Rik <rik@octave.org>
parents: 27909
diff changeset
189 printf ("%s %s:\n\n", msg, p);
d1862db3bffb what.m: clean up function.
Rik <rik@octave.org>
parents: 27909
diff changeset
190 printf ("%s", list_in_columns (f, 0, " "));
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
191 endif
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
192
7050
bd56a0609c4f [project @ 2007-10-23 12:02:17 by dbateman]
dbateman
parents:
diff changeset
193 endfunction
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 16724
diff changeset
194
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
195
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
196 %!test
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
197 %! w = what ();
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
198 %! assert (w.path, pwd);
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
199 %! assert (fieldnames (w), {"path"; "m"; "mat"; "mex"; "oct"; "mdl"; "slx";
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
200 %! "p"; "classes"; "packages"});
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
201
27910
d1862db3bffb what.m: clean up function.
Rik <rik@octave.org>
parents: 27909
diff changeset
202 ## FIXME: Should have additional tests. Possibly create a temporary directory
d1862db3bffb what.m: clean up function.
Rik <rik@octave.org>
parents: 27909
diff changeset
203 ## within TMPDIR, create files and folders, and call what() on that dir.
19183
666c4e0aca1e what.m: Overhaul function.
Rik <rik@octave.org>
parents: 18284
diff changeset
204 %!error what (1, 2)