annotate liboctave/system/dir-ops.cc @ 30080:dbbf3d44535d

maint: use "m_" prefix for member variables in class dir_entry. * dir-ops.cc, dir-ops.h: use "m_" prefix for member variables in class dir_entry.
author Rik <rik@octave.org>
date Mon, 30 Aug 2021 12:03:27 -0700
parents 0a5b15007766
children 796f54d4ddbf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
3 // Copyright (C) 1996-2021 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21202
diff changeset
27 # include "config.h"
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
28 #endif
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
29
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
30 #include <cerrno>
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
31 #include <cstdlib>
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
32 #include <cstring>
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
33
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
34 #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
35 #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
36
21926
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
37 #include "dirent-wrappers.h"
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
38
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
39 #include "dir-ops.h"
5871
b9fd54407c8d [project @ 2006-06-30 16:48:39 by jwe]
jwe
parents: 5307
diff changeset
40 #include "file-ops.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
41 #include "lo-error.h"
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
42 #include "lo-sysdep.h"
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
43 #include "str-vec.h"
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
44
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
45 namespace octave
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
46 {
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
47 namespace sys
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
48 {
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
49 bool
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
50 dir_entry::open (const std::string& n)
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
51 {
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
52 if (! n.empty ())
30080
dbbf3d44535d maint: use "m_" prefix for member variables in class dir_entry.
Rik <rik@octave.org>
parents: 29358
diff changeset
53 m_name = n;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
54
30080
dbbf3d44535d maint: use "m_" prefix for member variables in class dir_entry.
Rik <rik@octave.org>
parents: 29358
diff changeset
55 if (! m_name.empty ())
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
56 {
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
57 close ();
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
58
30080
dbbf3d44535d maint: use "m_" prefix for member variables in class dir_entry.
Rik <rik@octave.org>
parents: 29358
diff changeset
59 std::string fullname = sys::file_ops::tilde_expand (m_name);
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
60
30080
dbbf3d44535d maint: use "m_" prefix for member variables in class dir_entry.
Rik <rik@octave.org>
parents: 29358
diff changeset
61 m_dir = octave_opendir_wrapper (fullname.c_str ());
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
62
30080
dbbf3d44535d maint: use "m_" prefix for member variables in class dir_entry.
Rik <rik@octave.org>
parents: 29358
diff changeset
63 if (! m_dir)
dbbf3d44535d maint: use "m_" prefix for member variables in class dir_entry.
Rik <rik@octave.org>
parents: 29358
diff changeset
64 m_errmsg = std::strerror (errno);
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
65 }
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
66 else
30080
dbbf3d44535d maint: use "m_" prefix for member variables in class dir_entry.
Rik <rik@octave.org>
parents: 29358
diff changeset
67 m_errmsg = "dir_entry::open: empty filename";
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
68
30080
dbbf3d44535d maint: use "m_" prefix for member variables in class dir_entry.
Rik <rik@octave.org>
parents: 29358
diff changeset
69 return m_dir != nullptr;
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
70 }
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
71
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
72 string_vector
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
73 dir_entry::read (void)
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
74 {
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
75 string_vector retval;
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
76
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
77 if (ok ())
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
78 {
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
79 std::list<std::string> dirlist;
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
80
21926
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
81 char *fname;
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
82
30080
dbbf3d44535d maint: use "m_" prefix for member variables in class dir_entry.
Rik <rik@octave.org>
parents: 29358
diff changeset
83 while ((fname = octave_readdir_wrapper (m_dir)))
21926
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
84 dirlist.push_back (fname);
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
85
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
86 retval = string_vector (dirlist);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
87 }
6145
14906c2745e3 [project @ 2006-11-08 20:33:51 by jwe]
jwe
parents: 5871
diff changeset
88
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
89 return retval;
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
90 }
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
91
21926
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
92 bool
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
93 dir_entry::close (void)
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
94 {
21969
b3d19ade4cd5 * dir-ops.cc (dir_entry::close): Don't pass NULL to closedir.
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
95 bool retval = true;
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
96
30080
dbbf3d44535d maint: use "m_" prefix for member variables in class dir_entry.
Rik <rik@octave.org>
parents: 29358
diff changeset
97 if (m_dir)
21969
b3d19ade4cd5 * dir-ops.cc (dir_entry::close): Don't pass NULL to closedir.
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
98 {
30080
dbbf3d44535d maint: use "m_" prefix for member variables in class dir_entry.
Rik <rik@octave.org>
parents: 29358
diff changeset
99 retval = (octave_closedir_wrapper (m_dir) == 0);
21969
b3d19ade4cd5 * dir-ops.cc (dir_entry::close): Don't pass NULL to closedir.
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
100
30080
dbbf3d44535d maint: use "m_" prefix for member variables in class dir_entry.
Rik <rik@octave.org>
parents: 29358
diff changeset
101 m_dir = nullptr;
21969
b3d19ade4cd5 * dir-ops.cc (dir_entry::close): Don't pass NULL to closedir.
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
102 }
21926
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
103
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
104 return retval;
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
105 }
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
106
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
107 unsigned int
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
108 dir_entry::max_name_length (void)
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
109 {
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
110 return octave_name_max_wrapper ();
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
111 }
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
112 }
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
113 }