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 |
|
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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1786
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_pathsearch_h) |
|
25 #define octave_pathsearch_h 1 |
|
26 |
|
27 #include <string> |
|
28 |
|
29 #include "str-vec.h" |
|
30 |
|
31 class |
|
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 |
1786
|
85 private: |
|
86 |
3174
|
87 // The colon separated list that we were given. |
3504
|
88 std::string p_orig; |
1786
|
89 |
3196
|
90 // The default path. If specified, replaces leading, trailing, or |
|
91 // doubled colons in p_orig. |
3504
|
92 std::string p_default; |
3196
|
93 |
1786
|
94 // TRUE means we've unpacked p. |
|
95 bool initialized; |
|
96 |
3174
|
97 // A version of the colon separate list on which we have performed |
3196
|
98 // tilde, variable, and possibly default path expansion. |
3504
|
99 std::string p; |
3174
|
100 |
1786
|
101 // The elements of the list. |
|
102 string_vector pv; |
|
103 |
|
104 void init (void); |
|
105 }; |
|
106 |
|
107 #endif |
|
108 |
|
109 /* |
|
110 ;;; Local Variables: *** |
|
111 ;;; mode: C++ *** |
|
112 ;;; End: *** |
|
113 */ |