annotate scripts/miscellaneous/ls.m @ 6115:bade9ff1814b

[project @ 2006-10-27 17:58:06 by jwe]
author jwe
date Fri, 27 Oct 2006 17:58:06 +0000
parents
children f6d78960f674
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6115
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 2006 John W. Eaton
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
2 ##
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
4 ##
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
7 ## the Free Software Foundation; either version 2, or (at your option)
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
8 ## any later version.
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
9 ##
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
14 ##
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
18 ## 02110-1301, USA.
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
19
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
20 ## -*- texinfo -*-
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
21 ## @deffn {Command} ls options
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
22 ## List directory contents. For example,
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
23 ##
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
24 ## @example
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
25 ## ls -l
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
26 ## @print{} total 12
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
27 ## @print{} -rw-r--r-- 1 jwe users 4488 Aug 19 04:02 foo.m
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
28 ## @print{} -rw-r--r-- 1 jwe users 1315 Aug 17 23:14 bar.m
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
29 ## @end example
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
30 ##
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
31 ## The @code{dir} and @code{ls} commands are implemented by calling your
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
32 ## system's directory listing command, so the available options may vary
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
33 ## from system to system.
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
34 ## @seealso{dir, stat, readdir, glob, filesep, ls_command}
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
35 ## @end deffn
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
36
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
37 ## Author: jwe
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
38
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
39 ## PKG_ADD: mark_as_command ls
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
40
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
41 function retval = ls (varargin)
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
42
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
43 global __ls_command__;
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
44
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
45 if (isempty (__ls_command__) || ! ischar (__ls_command__))
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
46 ## Initialize value for __ls_command__.
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
47 ls_command ();
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
48 endif
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
49
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
50 if (iscellstr (varargin))
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
51
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
52 args = tilde_expand (varargin);
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
53
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
54 cmd = sprintf ("%s ", __ls_command__, args{:});
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
55
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
56 if (page_screen_output ())
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
57
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
58 [status, output] = system (cmd);
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
59
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
60 if (status == 0)
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
61 puts (output);
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
62 else
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
63 error ("ls: command exited abnormally with status %d", status);
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
64 endif
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
65
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
66 else
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
67 ## Just let the output flow if the pager is off. That way the
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
68 ## output from things like "ls -R /" will show up immediately and
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
69 ## we won't have to buffer all the output.
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
70 system (cmd);
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
71 endif
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
72
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
73 else
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
74 error ("ls: expecting all arguments to be character strings");
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
75 endif
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
76
bade9ff1814b [project @ 2006-10-27 17:58:06 by jwe]
jwe
parents:
diff changeset
77 endfunction