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