1782
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
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 |
|
31 #include "sysdir.h" |
|
32 |
|
33 #include "dir-ops.h" |
2926
|
34 #include "lo-error.h" |
|
35 #include "lo-sysdep.h" |
1782
|
36 #include "str-vec.h" |
|
37 |
|
38 bool |
3504
|
39 dir_entry::open (const std::string& n) |
1782
|
40 { |
|
41 fail = true; |
|
42 |
|
43 if (! n.empty ()) |
|
44 name = n; |
|
45 |
|
46 if (! name.empty ()) |
|
47 { |
|
48 close (); |
|
49 |
2800
|
50 dir = static_cast<void *> (opendir (name.c_str ())); |
1782
|
51 |
|
52 if (dir) |
|
53 fail = false; |
|
54 else |
3504
|
55 { |
|
56 using namespace std; |
|
57 errmsg = strerror (errno); |
|
58 } |
1782
|
59 } |
|
60 else |
|
61 errmsg = "dir_entry::open: empty file name"; |
|
62 |
|
63 return ! fail; |
|
64 } |
|
65 |
|
66 string_vector |
|
67 dir_entry::read (void) |
|
68 { |
|
69 string_vector dirlist; |
|
70 |
|
71 if (ok ()) |
|
72 { |
|
73 int count = 0; |
|
74 |
|
75 struct dirent *dir_ent; |
|
76 |
2800
|
77 while ((dir_ent = readdir (static_cast<DIR *> (dir)))) |
1782
|
78 count++; |
|
79 |
2800
|
80 rewinddir (static_cast<DIR *> (dir)); |
1782
|
81 |
|
82 dirlist.resize (count); |
|
83 |
|
84 for (int i = 0; i < count; i++) |
|
85 { |
2800
|
86 dir_ent = readdir (static_cast<DIR *> (dir)); |
1782
|
87 |
|
88 if (dir_ent) |
|
89 dirlist[i] = dir_ent->d_name; |
|
90 else |
|
91 break; |
|
92 } |
|
93 } |
|
94 |
|
95 return dirlist; |
|
96 } |
|
97 |
|
98 void |
|
99 dir_entry::close (void) |
|
100 { |
|
101 if (dir) |
2800
|
102 closedir (static_cast<DIR *> (dir)); |
1782
|
103 |
|
104 dir = 0; |
|
105 } |
|
106 |
|
107 void |
|
108 dir_entry::copy (const dir_entry& de) |
|
109 { |
|
110 name = de.name; |
|
111 dir = de.dir; |
|
112 fail = de.fail; |
|
113 errmsg = de.errmsg; |
|
114 } |
|
115 |
|
116 /* |
|
117 ;;; Local Variables: *** |
|
118 ;;; mode: C++ *** |
|
119 ;;; End: *** |
|
120 */ |