Mercurial > hg > octave-lyh
annotate liboctave/pathsearch.cc @ 10396:a0b51ac0f88a
optimize accumdim with summation
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 05 Mar 2010 12:31:30 +0100 |
parents | 07ebe522dac2 |
children | fd0a3ac60b0e |
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) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
56 ("unable to create dir_path::static_members object!"); |
8008
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++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
85 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
86 str_llist_type *elt_dirs = kpse_element_dirs (pv[i]); |
1786 | 87 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
88 if (elt_dirs) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
89 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
90 str_llist_elt_type *dir; |
1786 | 91 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
92 for (dir = *elt_dirs; dir; dir = STR_LLIST_NEXT (*dir)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
93 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
94 const std::string elt_dir = STR_LLIST (*dir); |
1786 | 95 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
96 if (! elt_dir.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
97 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
98 if (count == nmax) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
99 nmax *= 2; |
1786 | 100 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
101 retval.resize (nmax); |
3415 | 102 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
103 retval[count++] = elt_dir; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
104 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
105 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
106 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
107 } |
1786 | 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 ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
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 () |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
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 } |