Mercurial > octave
comparison src/dirfns.cc @ 4691:bdc51b369a78
[project @ 2004-01-10 18:16:02 by jwe]
author | jwe |
---|---|
date | Sat, 10 Jan 2004 18:16:03 +0000 |
parents | 93ad80b6eef6 |
children | 1cf16fb3459a |
comparison
equal
deleted
inserted
replaced
4690:b6dc2aad574a | 4691:bdc51b369a78 |
---|---|
138 cleanup_iprocstream (void *p) | 138 cleanup_iprocstream (void *p) |
139 { | 139 { |
140 delete static_cast <iprocstream *> (p); | 140 delete static_cast <iprocstream *> (p); |
141 } | 141 } |
142 | 142 |
143 DEFCMD (ls, args, , | 143 DEFCMD (ls, args, nargout, |
144 "-*- texinfo -*-\n\ | 144 "-*- texinfo -*-\n\ |
145 @deffn {Command} ls options\n\ | 145 @deffn {Command} ls options\n\ |
146 @deffnx {Command} dir options\n\ | |
147 List directory contents. For example,\n\ | 146 List directory contents. For example,\n\ |
148 \n\ | 147 \n\ |
149 @example\n\ | 148 @example\n\ |
150 ls -l\n\ | 149 ls -l\n\ |
151 @print{} total 12\n\ | 150 @print{} total 12\n\ |
156 The @code{dir} and @code{ls} commands are implemented by calling your\n\ | 155 The @code{dir} and @code{ls} commands are implemented by calling your\n\ |
157 system's directory listing command, so the available options may vary\n\ | 156 system's directory listing command, so the available options may vary\n\ |
158 from system to system.\n\ | 157 from system to system.\n\ |
159 @end deffn") | 158 @end deffn") |
160 { | 159 { |
161 octave_value_list retval; | 160 octave_value retval; |
162 | 161 |
163 int argc = args.length () + 1; | 162 int argc = args.length () + 1; |
164 | 163 |
165 string_vector argv = args.make_argv ("ls"); | 164 string_vector argv = args.make_argv ("ls"); |
166 | 165 |
191 | 190 |
192 octave_usleep (100); | 191 octave_usleep (100); |
193 | 192 |
194 char ch; | 193 char ch; |
195 | 194 |
195 OSSTREAM output_buf; | |
196 | |
196 for (;;) | 197 for (;;) |
197 { | 198 { |
198 if (cmd->get (ch)) | 199 if (cmd->get (ch)) |
199 octave_stdout << ch; | 200 { |
201 octave_stdout << ch; | |
202 output_buf << ch; | |
203 } | |
200 else | 204 else |
201 { | 205 { |
202 if (! cmd->eof () && errno == EAGAIN) | 206 if (! cmd->eof () && errno == EAGAIN) |
203 { | 207 { |
204 cmd->clear (); | 208 cmd->clear (); |
207 } | 211 } |
208 else | 212 else |
209 break; | 213 break; |
210 } | 214 } |
211 } | 215 } |
216 | |
217 output_buf << OSSTREAM_ENDS; | |
218 | |
219 if (nargout > 0) | |
220 retval = OSSTREAM_STR (output_buf); | |
221 | |
222 OSSTREAM_FREEZE (output_buf); | |
212 } | 223 } |
213 else | 224 else |
214 error ("couldn't start process for ls!"); | 225 error ("couldn't start process for ls!"); |
215 | 226 |
216 unwind_protect::run (); | 227 unwind_protect::run (); |
217 | 228 |
218 return retval; | 229 return retval; |
219 } | 230 } |
220 | |
221 DEFALIAS (dir, ls); | |
222 | 231 |
223 DEFUN (pwd, , nargout, | 232 DEFUN (pwd, , nargout, |
224 "-*- texinfo -*-\n\ | 233 "-*- texinfo -*-\n\ |
225 @deftypefn {Built-in Function} {} pwd ()\n\ | 234 @deftypefn {Built-in Function} {} pwd ()\n\ |
226 Return the current working directory.\n\ | 235 Return the current working directory.\n\ |
244 } | 253 } |
245 | 254 |
246 DEFUN (readdir, args, , | 255 DEFUN (readdir, args, , |
247 "-*- texinfo -*-\n\ | 256 "-*- texinfo -*-\n\ |
248 @deftypefn {Built-in Function} {[@var{files}, @var{err}, @var{msg}] =} readdir (@var{dir})\n\ | 257 @deftypefn {Built-in Function} {[@var{files}, @var{err}, @var{msg}] =} readdir (@var{dir})\n\ |
249 Return names of the files in the directory @var{dir} as an array of\n\ | 258 Return names of the files in the directory @var{dir} as a cell array of\n\ |
250 strings. If an error occurs, return an empty matrix in @var{files}.\n\ | 259 strings. If an error occurs, return an empty cell array in @var{files}.\n\ |
251 \n\ | 260 \n\ |
252 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ | 261 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
253 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | 262 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ |
254 system-dependent error message.\n\ | 263 system-dependent error message.\n\ |
255 @end deftypefn") | 264 @end deftypefn") |
256 { | 265 { |
257 octave_value_list retval; | 266 octave_value_list retval; |
258 | 267 |
259 retval(2) = std::string (); | 268 retval(2) = std::string (); |
260 retval(1) = -1.0; | 269 retval(1) = -1.0; |
261 retval(0) = Matrix (); | 270 retval(0) = Cell (); |
262 | 271 |
263 if (args.length () == 1) | 272 if (args.length () == 1) |
264 { | 273 { |
265 std::string dirname = args(0).string_value (); | 274 std::string dirname = args(0).string_value (); |
266 | 275 |
271 dir_entry dir (file_ops::tilde_expand (dirname)); | 280 dir_entry dir (file_ops::tilde_expand (dirname)); |
272 | 281 |
273 if (dir) | 282 if (dir) |
274 { | 283 { |
275 string_vector dirlist = dir.read (); | 284 string_vector dirlist = dir.read (); |
276 retval(0) = dirlist.qsort (); | 285 retval(0) = Cell (dirlist.qsort ()); |
277 retval(1) = 0.0; | 286 retval(1) = 0.0; |
278 } | 287 } |
279 else | 288 else |
280 { | 289 { |
281 retval(2) = dir.error (); | 290 retval(2) = dir.error (); |
553 } | 562 } |
554 | 563 |
555 DEFUN (glob, args, , | 564 DEFUN (glob, args, , |
556 "-*- texinfo -*-\n\ | 565 "-*- texinfo -*-\n\ |
557 @deftypefn {Built-in Function} {} glob (@var{pattern})\n\ | 566 @deftypefn {Built-in Function} {} glob (@var{pattern})\n\ |
558 Given an array of strings in @var{pattern}, return the list of file\n\ | 567 Given an array of strings in @var{pattern}, return a cell array of file\n\ |
559 names that match any of them, or an empty string if no patterns match.\n\ | 568 names that match any of them, or an empty cell array if no patterns match.\n\ |
560 Tilde expansion is performed on each of the patterns before looking for\n\ | 569 Tilde expansion is performed on each of the patterns before looking for\n\ |
561 matching file names. For example,\n\ | 570 matching file names. For example,\n\ |
562 \n\ | 571 \n\ |
563 @example\n\ | 572 @example\n\ |
564 @group\n\ | 573 @group\n\ |
565 glob (\"/vm*\")\n\ | 574 glob (\"/vm*\")\n\ |
566 @result{} \"/vmlinuz\"\n\ | 575 @result{} \"/vmlinuz\"\n\ |
567 @end group\n\ | 576 @end group\n\ |
568 @end example\n\ | 577 @end example\n\ |
569 \n\ | |
570 Note that multiple values are returned in a string matrix with the fill\n\ | |
571 character set to ASCII NUL.\n\ | |
572 @end deftypefn") | 578 @end deftypefn") |
573 { | 579 { |
574 octave_value retval; | 580 octave_value retval; |
575 | 581 |
576 if (args.length () == 1) | 582 if (args.length () == 1) |
581 gripe_wrong_type_arg ("glob", args(0)); | 587 gripe_wrong_type_arg ("glob", args(0)); |
582 else | 588 else |
583 { | 589 { |
584 glob_match pattern (file_ops::tilde_expand (pat)); | 590 glob_match pattern (file_ops::tilde_expand (pat)); |
585 | 591 |
586 string_vector list = pattern.glob (); | 592 retval = Cell (pattern.glob ()); |
587 | |
588 if (list.empty ()) | |
589 retval = ""; | |
590 else | |
591 retval = list; | |
592 } | 593 } |
593 } | 594 } |
594 else | 595 else |
595 print_usage ("glob"); | 596 print_usage ("glob"); |
596 | 597 |