annotate liboctave/util/pathsearch.cc @ 21882:d8104206e8a9

additional cleanups for kpse.cc * kpse.cc: Use kpse instead of kpathsea consistently. Define file and path macros using Octave functions. Style fixes.
author John W. Eaton <jwe@octave.org>
date Sun, 12 Jun 2016 11:18:55 -0400
parents 40195d04b17c
children 02add2f597a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
1 /*
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17769
diff changeset
3 Copyright (C) 1996-2015 John W. Eaton
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
4
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
6
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5777
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5777
diff changeset
10 option) any later version.
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
11
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
15 for more details.
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
16
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5777
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5777
diff changeset
19 <http://www.gnu.org/licenses/>.
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
20
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
21 */
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21202
diff changeset
24 # include "config.h"
2021
aa68db31dc34 [project @ 1996-03-23 05:53:57 by jwe]
jwe
parents: 2006
diff changeset
25 #endif
aa68db31dc34 [project @ 1996-03-23 05:53:57 by jwe]
jwe
parents: 2006
diff changeset
26
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
27 #include <cstdlib>
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
28
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
29 #include <string>
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
30
3024
95e8b5c4824a [project @ 1997-06-04 05:06:26 by jwe]
jwe
parents: 2847
diff changeset
31 #include "lo-utils.h"
3833
f3278ec3ccb7 [project @ 2001-05-17 12:31:52 by jwe]
jwe
parents: 3505
diff changeset
32 #include "oct-env.h"
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
33 #include "pathsearch.h"
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
34 #include "singleton-cleanup.h"
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
35
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
36 #include "kpse.cc"
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents: 4242
diff changeset
37
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
38 namespace octave
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
39 {
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
40 directory_path::static_members *directory_path::static_members::instance = 0;
8008
4d13a7a2f6ab dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
41
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
42 directory_path::static_members::static_members (void)
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
43 : xpath_sep_char (SEPCHAR), xpath_sep_str (SEPCHAR_STR) { }
8008
4d13a7a2f6ab dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
44
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
45 bool
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
46 directory_path::static_members::instance_ok (void)
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
47 {
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
48 bool retval = true;
5777
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5307
diff changeset
49
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
50 if (! instance)
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
51 {
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
52 instance = new static_members ();
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
53
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
54 if (instance)
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
55 singleton_cleanup_list::add (cleanup_instance);
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
56 }
5777
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5307
diff changeset
57
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
58 if (! instance)
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
59 (*current_liboctave_error_handler)
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
60 ("unable to create directory_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
61
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
62 return retval;
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
63 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
64
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
65 std::list<std::string>
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
66 directory_path::elements (void)
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
67 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
68 return m_initialized ? m_path_elements : std::list<std::string> ();
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
69 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
70
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
71 std::list<std::string>
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
72 directory_path::all_directories (void)
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
73 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
74 std::list<std::string> retval;
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
75
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
76 if (m_initialized)
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
77 {
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
78 for (const auto& elt : m_path_elements)
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
79 {
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
80 std::string elt_dir = kpse_element_dir (elt);
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
81
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
82 if (! elt_dir.empty ())
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
83 retval.push_back (elt_dir);
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
84 }
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
85 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
86
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
87 return retval;
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
88 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
89
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
90 std::string
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
91 directory_path::find_first (const std::string& nm)
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
92 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
93 return m_initialized ? kpse_path_search (m_expanded_path, nm, true) : "";
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
94 }
4242
4d3994172bd5 [project @ 2002-12-26 22:06:10 by jwe]
jwe
parents: 4126
diff changeset
95
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
96 std::list<std::string>
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
97 directory_path::find_all (const std::string& nm)
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
98 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
99 return (m_initialized
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
100 ? kpse_all_path_search (m_expanded_path, nm)
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
101 : std::list<std::string> ());
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
102 }
4242
4d3994172bd5 [project @ 2002-12-26 22:06:10 by jwe]
jwe
parents: 4126
diff changeset
103
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
104 std::string
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
105 directory_path::find_first_of (const std::list<std::string>& names)
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
106 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
107 return (m_initialized
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
108 ? kpse_path_find_first_of (m_expanded_path, names, true) : "");
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
109 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
110
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
111 std::list<std::string>
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
112 directory_path::find_all_first_of (const std::list<std::string>& names)
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
113 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
114 return (m_initialized
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
115 ? kpse_all_path_find_first_of (m_expanded_path, names)
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
116 : std::list<std::string> ());
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
117 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
118
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
119 void
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
120 directory_path::init (void)
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
121 {
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
122 static bool octave_kpse_initialized = false;
8008
4d13a7a2f6ab dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
123
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
124 if (! octave_kpse_initialized)
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
125 {
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
126 std::string val = octave::sys::env::getenv ("KPATHSEA_DEBUG");
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
127
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
128 if (! val.empty ())
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
129 kpse_debug |= atoi (val.c_str ());
3174
390d5e396682 [project @ 1998-05-04 16:36:17 by jwe]
jwe
parents: 3024
diff changeset
130
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
131 octave_kpse_initialized = true;
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
132 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
133
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
134 m_expanded_path
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
135 = kpse_path_expand (m_default_path.empty ()
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
136 ? m_orig_path
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
137 : kpse_expand_default (m_orig_path, m_default_path));
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
138
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
139 for (kpse_path_iterator pi (m_expanded_path); pi != std::string::npos; pi++)
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
140 m_path_elements.push_back (*pi);
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
141
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
142 m_initialized = true;
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
143 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
144 }