1786
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1786
|
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. |
1786
|
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/>. |
1786
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_pathsearch_h) |
|
24 #define octave_pathsearch_h 1 |
|
25 |
|
26 #include <string> |
|
27 |
|
28 #include "str-vec.h" |
|
29 |
|
30 class |
6108
|
31 OCTAVE_API |
1786
|
32 dir_path |
|
33 { |
|
34 public: |
|
35 |
3504
|
36 dir_path (const std::string& s = std::string (), |
|
37 const std::string& d = std::string ()) |
3196
|
38 : p_orig (s), p_default (d), initialized (false) |
1786
|
39 { |
3174
|
40 if (! p_orig.empty ()) |
1786
|
41 init (); |
|
42 } |
|
43 |
|
44 dir_path (const dir_path& dp) |
3196
|
45 : p_orig (dp.p_orig), p_default (dp.p_default), |
|
46 initialized (dp.initialized), p (dp.p), pv (dp.pv) |
3174
|
47 { } |
1786
|
48 |
|
49 dir_path& operator = (const dir_path& dp) |
|
50 { |
3174
|
51 p_orig = dp.p_orig; |
3196
|
52 p_default = dp.p_default; |
3174
|
53 initialized = dp.initialized; |
1786
|
54 p = dp.p; |
|
55 pv = dp.pv; |
|
56 return *this; |
|
57 } |
|
58 |
|
59 ~dir_path (void) { } |
|
60 |
3504
|
61 void set (const std::string& s) |
1786
|
62 { |
|
63 initialized = false; |
3174
|
64 p_orig = s; |
1786
|
65 init (); |
|
66 } |
|
67 |
|
68 string_vector elements (void); |
|
69 string_vector all_directories (void); |
|
70 |
3504
|
71 std::string find_first (const std::string&); |
|
72 std::string find (const std::string& nm) { return find_first (nm); } |
1786
|
73 |
3504
|
74 string_vector find_all (const std::string&); |
1786
|
75 |
4242
|
76 std::string find_first_of (const string_vector& names); |
|
77 string_vector find_all_first_of (const string_vector& names); |
|
78 |
3185
|
79 void rehash (void) |
|
80 { |
|
81 initialized = false; |
|
82 init (); |
|
83 } |
|
84 |
5777
|
85 static bool is_path_sep (char c) { return c == path_sep_char; } |
|
86 |
|
87 static char path_sep_char; |
|
88 static std::string path_sep_str; |
|
89 |
1786
|
90 private: |
|
91 |
3174
|
92 // The colon separated list that we were given. |
3504
|
93 std::string p_orig; |
1786
|
94 |
3196
|
95 // The default path. If specified, replaces leading, trailing, or |
|
96 // doubled colons in p_orig. |
3504
|
97 std::string p_default; |
3196
|
98 |
1786
|
99 // TRUE means we've unpacked p. |
|
100 bool initialized; |
|
101 |
3174
|
102 // A version of the colon separate list on which we have performed |
3196
|
103 // tilde, variable, and possibly default path expansion. |
3504
|
104 std::string p; |
3174
|
105 |
1786
|
106 // The elements of the list. |
|
107 string_vector pv; |
|
108 |
|
109 void init (void); |
|
110 }; |
|
111 |
|
112 #endif |
|
113 |
|
114 /* |
|
115 ;;; Local Variables: *** |
|
116 ;;; mode: C++ *** |
|
117 ;;; End: *** |
|
118 */ |