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