Mercurial > hg > octave-lyh
annotate scripts/miscellaneous/what.m @ 9724:f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
which were causing bad entries in the function index.
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Tue, 13 Oct 2009 21:10:37 -0700 |
parents | 4cb9f994dcec |
children | 95c3e38098bf |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2007, 2009 David Bateman |
7050 | 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 -*- | |
9724
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9037
diff
changeset
|
20 ## @deftypefn {Command} {} what |
7050 | 21 ## @deftypefnx {Command} {} what @var{dir} |
22 ## @deftypefnx {Function File} {w =} what (@var{dir}) | |
9037
4cb9f994dcec
Documentation cleanup of var.texi, expr.texi, eval.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
23 ## List the Octave specific files in a directory. If the variable @var{dir} |
4cb9f994dcec
Documentation cleanup of var.texi, expr.texi, eval.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
24 ## is given then check that directory rather than the current directory. If |
7050 | 25 ## a return argument is requested, the files found are returned in the |
26 ## structure @var{w}. | |
27 ## @seealso{which} | |
28 ## @end deftypefn | |
29 | |
30 function ret = what (d) | |
31 | |
32 if (nargin == 0) | |
33 d = pwd (); | |
34 elseif (isempty (strfind (d, filesep ()))) | |
8507 | 35 ## Find the appropriate directory on the path. |
8877
2c8b2399247b
implement strsplit; deprecate split
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
36 p = strtrim (strsplit (path (), pathsep())); |
7050 | 37 d = p{find (cellfun (@(x) ! isempty (strfind (x, d)), p))(end)}; |
38 else | |
39 [status, msg, msgid] = fileattrib (d); | |
40 if (status != 1) | |
41 error ("could not find the file or path %s", d); | |
42 else | |
43 d = msg.Name; | |
44 endif | |
45 endif | |
46 | |
47 files = dir (d); | |
48 w.path = d; | |
49 w.m = cell (0, 1); | |
50 w.mex = cell (0, 1); | |
51 w.oct = cell (0, 1); | |
52 w.mat = cell (0, 1); | |
53 w.mdl = cell (0, 1); | |
54 w.p = cell (0, 1); | |
55 w.classes = cell (0, 1); | |
56 | |
57 for i = 1 : length (files) | |
58 n = files(i).name; | |
59 ## Ignore . and .. | |
60 if (strcmp (n, ".") || strcmp (n, "..")) | |
61 continue; | |
62 else | |
63 ## Ignore mdl and p files | |
64 [dummy, f, e] = fileparts (n); | |
65 if (strcmp (e, ".m")) | |
7208 | 66 w.m{end+1} = n; |
7050 | 67 elseif (strcmp (e, mexext ())) |
7208 | 68 w.mex{end+1} = n; |
7050 | 69 elseif (strcmp (e, ".oct")) |
7208 | 70 w.oct{end+1} = n; |
7050 | 71 elseif (strcmp (e, ".mat")) |
7208 | 72 w.mat{end+1} = n; |
7050 | 73 elseif(strcmp (n(1), "@")) |
7208 | 74 w.classes{end+1} = n; |
7050 | 75 endif |
76 endif | |
77 endfor | |
78 | |
79 if (nargout == 0) | |
80 __display_filenames__ ("M-files in directory", w.path, w.m); | |
81 __display_filenames__ ("\nMEX-files in directory", w.path, w.mex); | |
82 __display_filenames__ ("\nOCT-files in directory", w.path, w.oct); | |
83 __display_filenames__ ("\nMAT-files in directory", w.path, w.mat); | |
84 __display_filenames__ ("\nClasses in directory", w.path, w.classes); | |
85 else | |
86 ret = w; | |
87 endif | |
88 endfunction | |
89 | |
90 function __display_filenames__ (msg, p, f) | |
91 if (length (f) > 0) | |
92 printf ("%s %s:\n\n", msg, p) | |
93 | |
94 maxlen = max (cellfun (@(x) length (x), f)); | |
95 ncols = max (1, floor (terminal_size()(2) / (maxlen + 3))); | |
96 fmt = ""; | |
97 for i = 1: ncols | |
98 fmt = sprintf ("%s %%-%ds", fmt, maxlen); | |
99 endfor | |
100 fmt = [fmt, "\n"]; | |
101 | |
102 nrows = ceil (length (f) / ncols); | |
103 for i = 1 : nrows | |
104 args = f(i:nrows:end); | |
105 if (length (args) < ncols) | |
8455
fd11a08a9b31
disallow invalid {}-indexed assigments
Jaroslav Hajek <highegg@gmail.com>
parents:
7208
diff
changeset
|
106 args(end : ncols) = {""}; |
7050 | 107 endif |
108 printf (fmt, args{:}); | |
109 endfor | |
110 endif | |
111 endfunction |