Mercurial > hg > octave-lyh
annotate liboctave/pathsearch.cc @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | 85184151822e |
children | 4c0cdbe0acca |
rev | line source |
---|---|
1786 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2005, 2006, |
8920 | 4 2007, 2008 John W. Eaton |
1786 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1786 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1786 | 21 |
22 */ | |
23 | |
2021 | 24 #ifdef HAVE_CONFIG_H |
25 #include <config.h> | |
26 #endif | |
27 | |
1786 | 28 #include <cstdlib> |
29 | |
30 #include <string> | |
31 | |
3024 | 32 #include "lo-utils.h" |
3833 | 33 #include "oct-env.h" |
1786 | 34 #include "pathsearch.h" |
35 #include "str-vec.h" | |
3024 | 36 #include "str-vec.h" |
1786 | 37 |
4399 | 38 #include "kpse.cc" |
4378 | 39 |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
40 dir_path::static_members *dir_path::static_members::instance = 0; |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
41 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
42 dir_path::static_members::static_members (void) |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
43 : xpath_sep_char (SEPCHAR), xpath_sep_str (SEPCHAR_STR) { } |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
44 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
45 bool |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
46 dir_path::static_members::instance_ok (void) |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
47 { |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
48 bool retval = true; |
5777 | 49 |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
50 if (! instance) |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
51 instance = new static_members (); |
5777 | 52 |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
53 if (! instance) |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
54 { |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
55 (*current_liboctave_error_handler) |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
56 ("unable to create dir_path::static_members object!"); |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
57 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
58 retval = false; |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
59 } |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
60 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
61 return retval; |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
62 } |
1786 | 63 |
64 string_vector | |
65 dir_path::elements (void) | |
66 { | |
67 return initialized ? pv : string_vector (); | |
68 } | |
69 | |
70 string_vector | |
71 dir_path::all_directories (void) | |
72 { | |
73 int count = 0; | |
74 string_vector retval; | |
75 | |
76 if (initialized) | |
77 { | |
78 int len = pv.length (); | |
79 | |
80 int nmax = len > 32 ? len : 32; | |
81 | |
82 retval.resize (len); | |
83 | |
84 for (int i = 0; i < len; i++) | |
85 { | |
4394 | 86 str_llist_type *elt_dirs = kpse_element_dirs (pv[i]); |
1786 | 87 |
3415 | 88 if (elt_dirs) |
1786 | 89 { |
3415 | 90 str_llist_elt_type *dir; |
1786 | 91 |
3415 | 92 for (dir = *elt_dirs; dir; dir = STR_LLIST_NEXT (*dir)) |
1786 | 93 { |
4390 | 94 const std::string elt_dir = STR_LLIST (*dir); |
1786 | 95 |
4390 | 96 if (! elt_dir.empty ()) |
3415 | 97 { |
98 if (count == nmax) | |
99 nmax *= 2; | |
1786 | 100 |
3415 | 101 retval.resize (nmax); |
102 | |
103 retval[count++] = elt_dir; | |
104 } | |
1786 | 105 } |
106 } | |
107 } | |
108 | |
109 retval.resize (count); | |
110 } | |
111 | |
112 return retval; | |
113 } | |
114 | |
3504 | 115 std::string |
116 dir_path::find_first (const std::string& nm) | |
1786 | 117 { |
4390 | 118 return initialized ? kpse_path_search (p, nm, true) : std::string (); |
4242 | 119 } |
120 | |
121 string_vector | |
122 dir_path::find_all (const std::string& nm) | |
123 { | |
4390 | 124 return initialized ? kpse_all_path_search (p, nm) : string_vector (); |
4242 | 125 } |
126 | |
127 std::string | |
128 dir_path::find_first_of (const string_vector& names) | |
129 { | |
4390 | 130 return initialized |
131 ? kpse_path_find_first_of (p, names, true) : std::string (); | |
1786 | 132 } |
133 | |
134 string_vector | |
4242 | 135 dir_path::find_all_first_of (const string_vector& names) |
1786 | 136 { |
4390 | 137 return initialized |
138 ? kpse_all_path_find_first_of (p, names) : string_vector (); | |
1786 | 139 } |
140 | |
141 void | |
142 dir_path::init (void) | |
143 { | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
144 static bool octave_kpathsea_initialized = false; |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
145 |
3174 | 146 if (! octave_kpathsea_initialized) |
1786 | 147 { |
4394 | 148 std::string val = octave_env::getenv ("KPATHSEA_DEBUG"); |
1786 | 149 |
4394 | 150 if (! val.empty ()) |
151 kpathsea_debug |= atoi (val.c_str ()); | |
3174 | 152 |
153 octave_kpathsea_initialized = true; | |
1786 | 154 } |
155 | |
4395 | 156 p = kpse_path_expand (p_default.empty () |
157 ? p_orig : kpse_expand_default (p_orig, p_default)); | |
3196 | 158 |
1786 | 159 int count = 0; |
8021 | 160 for (kpse_path_iterator pi (p); pi != std::string::npos; pi++) |
4394 | 161 count++; |
1786 | 162 |
163 pv.resize (count); | |
164 | |
4394 | 165 kpse_path_iterator pi (p); |
1786 | 166 |
167 for (int i = 0; i < count; i++) | |
4398 | 168 pv[i] = *pi++; |
1786 | 169 |
170 initialized = true; | |
171 } | |
172 | |
173 /* | |
174 ;;; Local Variables: *** | |
175 ;;; mode: C++ *** | |
176 ;;; End: *** | |
177 */ |