comparison scripts/miscellaneous/what.m @ 18060:427412d40f1a

what.m: Workaround file separator issues in code (bug #40726). * what.m: Check for both flavors of file separator at end of input dir name and remove if found.
author Rik <rik@octave.org>
date Tue, 03 Dec 2013 10:49:01 -0800
parents d63878346099
children ff05d5b70411
comparison
equal deleted inserted replaced
18059:b675665ce328 18060:427412d40f1a
28 28
29 function ret = what (d) 29 function ret = what (d)
30 30
31 if (nargin == 0) 31 if (nargin == 0)
32 d = pwd (); 32 d = pwd ();
33 elseif (isempty (strfind (d, filesep ())))
34 ## Find the appropriate directory on the path.
35 p = strtrim (ostrsplit (path (), pathsep ()));
36 d = p{find (cellfun (@(x) ! isempty (strfind (x, d)), p))(end)};
37 else 33 else
38 [status, msg, msgid] = fileattrib (d); 34 dtmp = canonicalize_file_name (d);
39 if (status != 1) 35 if (isempty (dtmp))
40 error ("what: could not find the file or path %s", d); 36 ## Search for directory name in path
41 else 37 if (d(end) == '/' || d(end) == '\')
42 d = msg.Name; 38 d(end) = [];
39 endif
40 dtmp = find_dir_in_path (d);
41 if (isempty (dtmp))
42 error ("what: could not find the directory %s", d);
43 endif
43 endif 44 endif
45 d = dtmp;
44 endif 46 endif
45 47
46 files = dir (d); 48 files = dir (d);
47 w.path = d; 49 w.path = d;
48 w.m = cell (0, 1); 50 w.m = cell (0, 1);
58 ## Ignore . and .. 60 ## Ignore . and ..
59 if (strcmp (n, ".") || strcmp (n, "..")) 61 if (strcmp (n, ".") || strcmp (n, ".."))
60 continue; 62 continue;
61 else 63 else
62 ## Ignore mdl and p files 64 ## Ignore mdl and p files
63 [dummy, f, e] = fileparts (n); 65 [~, f, e] = fileparts (n);
64 if (strcmp (e, ".m")) 66 if (strcmp (e, ".m"))
65 w.m{end+1} = n; 67 w.m{end+1} = n;
66 elseif (strcmp (e, ".oct")) 68 elseif (strcmp (e, ".oct"))
67 w.oct{end+1} = n; 69 w.oct{end+1} = n;
68 elseif (strcmp (e, mexext ())) 70 elseif (strcmp (e, mexext ()))