Mercurial > hg > octave-nkf
annotate liboctave/dir-ops.cc @ 12107:1fc9fd052f0c release-3-2-x
fix typo in expm
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 25 Nov 2009 12:05:03 +0100 |
parents | eb63fbe60fab |
children | 4c0cdbe0acca |
rev | line source |
---|---|
1782 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1996, 1997, 2000, 2005, 2006, 2007, 2008 John W. Eaton |
1782 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1782 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1782 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <cerrno> | |
2926 | 28 #include <cstdlib> |
1782 | 29 #include <cstring> |
30 | |
8326
545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
31 #include <list> |
545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
32 #include <string> |
545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
33 |
1782 | 34 #include "sysdir.h" |
35 | |
36 #include "dir-ops.h" | |
5871 | 37 #include "file-ops.h" |
2926 | 38 #include "lo-error.h" |
39 #include "lo-sysdep.h" | |
1782 | 40 #include "str-vec.h" |
41 | |
42 bool | |
3504 | 43 dir_entry::open (const std::string& n) |
1782 | 44 { |
45 fail = true; | |
46 | |
47 if (! n.empty ()) | |
48 name = n; | |
49 | |
50 if (! name.empty ()) | |
51 { | |
52 close (); | |
5871 | 53 |
54 std::string fullname = file_ops::tilde_expand (name); | |
1782 | 55 |
5871 | 56 dir = static_cast<void *> (opendir (fullname.c_str ())); |
1782 | 57 |
58 if (dir) | |
59 fail = false; | |
60 else | |
3504 | 61 { |
62 using namespace std; | |
63 errmsg = strerror (errno); | |
64 } | |
1782 | 65 } |
66 else | |
67 errmsg = "dir_entry::open: empty file name"; | |
68 | |
69 return ! fail; | |
70 } | |
71 | |
72 string_vector | |
73 dir_entry::read (void) | |
74 { | |
8326
545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
75 string_vector retval; |
1782 | 76 |
77 if (ok ()) | |
78 { | |
8326
545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
79 std::list<std::string> dirlist; |
1782 | 80 |
81 struct dirent *dir_ent; | |
82 | |
2800 | 83 while ((dir_ent = readdir (static_cast<DIR *> (dir)))) |
6145 | 84 { |
85 if (dir_ent) | |
8326
545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
86 dirlist.push_back (dir_ent->d_name); |
1782 | 87 else |
88 break; | |
89 } | |
6145 | 90 |
8326
545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
91 retval = string_vector (dirlist); |
1782 | 92 } |
93 | |
8326
545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
94 return retval; |
1782 | 95 } |
96 | |
97 void | |
98 dir_entry::close (void) | |
99 { | |
100 if (dir) | |
2800 | 101 closedir (static_cast<DIR *> (dir)); |
1782 | 102 |
103 dir = 0; | |
104 } | |
105 | |
106 void | |
107 dir_entry::copy (const dir_entry& de) | |
108 { | |
109 name = de.name; | |
110 dir = de.dir; | |
111 fail = de.fail; | |
112 errmsg = de.errmsg; | |
113 } | |
114 | |
115 /* | |
116 ;;; Local Variables: *** | |
117 ;;; mode: C++ *** | |
118 ;;; End: *** | |
119 */ |