annotate liboctave/util/kpse.cc @ 27679:748aea34aecd

* kpse.cc (READABLE): Prefixing "\\?\" only works for absolute paths (bug #57215).
author Markus Mützel <markus.muetzel@gmx.de>
date Tue, 12 Nov 2019 22:36:17 +0100
parents 12f28f9368ec
children b442ec6dda5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
1 // This file is not compiled to a separate object file.
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
2 // It is included in pathsearch.cc.
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
3
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
4 /* Look up a filename in a path.
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
5
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26175
diff changeset
6 Copyright (C) 2003-2019 John W. Eaton
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
7 Copyright (C) 1993, 94, 95, 96, 97, 98 Karl Berry.
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
8 Copyright (C) 1993, 94, 95, 96, 97 Karl Berry & O. Weber.
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
9 Copyright (C) 1992, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
10
16768
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
11 This file is part of Octave.
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
12
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24199
diff changeset
13 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
14 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24199
diff changeset
15 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
16 (at your option) any later version.
16768
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
17
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
18 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
19 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
21 GNU General Public License for more details.
16768
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
22
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
23 You should have received a copy of the GNU General Public License
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
24 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24199
diff changeset
25 <https://www.gnu.org/licenses/>.
16768
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
26
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
27 */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
28
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
29 #if defined (HAVE_CONFIG_H)
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
30 # include "config.h"
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
31 #endif
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
32
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
33 #include <cctype>
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
34 #include <cerrno>
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
35 #include <cstdlib>
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
36
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
37 #include <map>
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
38 #include <fstream>
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
39 #include <iostream>
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
40 #include <string>
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
41
21926
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
42 #include "dir-ops.h"
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
43 #include "file-ops.h"
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
44 #include "file-stat.h"
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
45 #include "kpse.h"
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
46 #include "oct-env.h"
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
47 #include "oct-passwd.h"
22061
737b1d9d7ee3 use octave::sys::time instead of C library time function
John W. Eaton <jwe@octave.org>
parents: 21979
diff changeset
48 #include "oct-time.h"
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
49 #include "pathsearch.h"
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21887
diff changeset
50 #include "unistd-wrappers.h"
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
51
21979
d04da18a407a use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents: 21926
diff changeset
52 #if defined (OCTAVE_USE_WINDOWS_API)
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
53 # define WIN32_LEAN_AND_MEAN 1
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
54 # include <windows.h>
27617
12f28f9368ec * kpse.cc (READABLE): Use wide character file system API on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
55
12f28f9368ec * kpse.cc (READABLE): Use wide character file system API on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
56 # include "lo-sysdep.h"
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
57 #endif
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
58
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
59 // Define the characters which separate components of filenames and
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
60 // environment variable paths.
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
61
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
62 #define IS_DEVICE_SEP(ch) octave::sys::file_ops::is_dev_sep (ch)
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22115
diff changeset
63 #define NAME_BEGINS_WITH_DEVICE(name) \
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
64 (name.length () > 0 && IS_DEVICE_SEP ((name)[1]))
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
65
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
66 #define DIR_SEP_STRING octave::sys::file_ops::dir_sep_str ()
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
67 #define IS_DIR_SEP(ch) octave::sys::file_ops::is_dir_sep (ch)
21863
a25110491607 eliminate obsolete sysdir.h header file
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
68
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
69 #define ENV_SEP octave::directory_path::path_sep_char ()
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
70 #define ENV_SEP_STRING octave::directory_path::path_sep_str ()
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
71 #define IS_ENV_SEP(ch) octave::directory_path::is_path_sep (ch)
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
72
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
73 // If NO_DEBUG is defined (not recommended), skip all this.
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
74 #if ! defined (NO_DEBUG)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
75
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
76 // OK, we'll have tracing support.
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
77 # define KPSE_DEBUG
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
78
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
79 // Test if a bit is on.
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
80 # define KPSE_DEBUG_P(bit) (kpse_debug & (1 << (bit)))
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
81
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
82 # define KPSE_DEBUG_STAT 0 // stat calls
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
83 # define KPSE_DEBUG_EXPAND 1 // path element expansion
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
84 # define KPSE_DEBUG_SEARCH 2 // searches
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
85 # define KPSE_DEBUG_VARS 3 // variable values
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
86 # define KPSE_LAST_DEBUG KPSE_DEBUG_VARS
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
87
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
88 #endif
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
89
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
90 unsigned int kpse_debug = 0;
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
91
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
92 void
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
93 kpse_path_iterator::set_end (void)
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
94 {
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
95 m_e = m_b + 1;
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
96
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
97 if (m_e == m_len)
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
98 ; // OK, we have found the last element.
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
99 else if (m_e > m_len)
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
100 m_b = m_e = std::string::npos;
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
101 else
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
102 {
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
103 // Find the next colon not enclosed by braces (or the end of the
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
104 // path).
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
105
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
106 while (m_e < m_len && ! octave::directory_path::is_path_sep (m_path[m_e]))
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
107 m_e++;
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
108 }
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
109 }
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
110
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
111 void
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
112 kpse_path_iterator::next (void)
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
113 {
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
114 m_b = m_e + 1;
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
115
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
116 // Skip any consecutive colons.
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
117 while (m_b < m_len && octave::directory_path::is_path_sep (m_path[m_b]))
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
118 m_b++;
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
119
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
120 if (m_b >= m_len)
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
121 m_b = m_e = std::string::npos;
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
122 else
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
123 set_end ();
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
124 }
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
125
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
126 /* Truncate any too-long components in NAME, returning the result. It's
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
127 too bad this is necessary. See comments in readable.c for why. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
128
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
129 static std::string
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
130 kpse_truncate_filename (const std::string& name)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
131 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
132 unsigned c_len = 0; /* Length of current component. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
133 unsigned ret_len = 0; /* Length of constructed result. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
134
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
135 std::string ret = name;
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
136
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
137 size_t m_len = name.length ();
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
138
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
139 for (size_t i = 0; i < m_len; i++)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
140 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
141 if (IS_DIR_SEP (name[i]) || IS_DEVICE_SEP (name[i]))
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
142 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
143 /* At a directory delimiter, reset component length. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
144 c_len = 0;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
145 }
22115
b017351e92e1 * kpse.cc (kpse_truncate_filename): Use namespace qualifier for static dir_entry function.
John W. Eaton <jwe@octave.org>
parents: 22061
diff changeset
146 else if (c_len > octave::sys::dir_entry::max_name_length ())
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
147 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
148 /* If past the max for a component, ignore this character. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
149 continue;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
150 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
151
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
152 /* Copy this character. */
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
153 ret[ret_len++] = name[i];
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
154 c_len++;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
155 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
156
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
157 ret.resize (ret_len);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
158
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
159 return ret;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
160 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
161
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
162 /* If access can read FN, run stat (assigning to stat buffer ST) and
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
163 check that fn is not a directory. Don't check for just being a
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
164 regular file, as it is potentially useful to read fifo's or some
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
165 kinds of devices. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
166
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
167 static inline bool
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
168 READABLE (const std::string& fn)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
169 {
27617
12f28f9368ec * kpse.cc (READABLE): Use wide character file system API on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
170 #if defined (OCTAVE_USE_WINDOWS_API)
12f28f9368ec * kpse.cc (READABLE): Use wide character file system API on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
171
27679
748aea34aecd * kpse.cc (READABLE): Prefixing "\\?\" only works for absolute paths (bug #57215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27617
diff changeset
172 std::wstring w_fn = octave::sys::u8_to_wstring (fn);
27617
12f28f9368ec * kpse.cc (READABLE): Use wide character file system API on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
173
12f28f9368ec * kpse.cc (READABLE): Use wide character file system API on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
174 DWORD f_attr = GetFileAttributesW (w_fn.c_str ());
12f28f9368ec * kpse.cc (READABLE): Use wide character file system API on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
175
12f28f9368ec * kpse.cc (READABLE): Use wide character file system API on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
176 return (f_attr != 0xFFFFFFFF && ! (f_attr & FILE_ATTRIBUTE_DIRECTORY));
12f28f9368ec * kpse.cc (READABLE): Use wide character file system API on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
177
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
178 #else
27617
12f28f9368ec * kpse.cc (READABLE): Use wide character file system API on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
179
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
180 bool retval = false;
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
181
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
182 const char *t = fn.c_str ();
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
183
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21887
diff changeset
184 if (octave_access_wrapper (t, octave_access_r_ok ()) == 0)
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
185 {
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
186 octave::sys::file_stat fs (fn);
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
187
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
188 retval = fs && ! fs.is_dir ();
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
189 }
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
190
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
191 return retval;
27617
12f28f9368ec * kpse.cc (READABLE): Use wide character file system API on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
192
12f28f9368ec * kpse.cc (READABLE): Use wide character file system API on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
193 #endif
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
194 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
195
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
196 /* POSIX invented the brain-damage of not necessarily truncating
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
197 filename components; the system's behavior is defined by the value of
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
198 the symbol _POSIX_NO_TRUNC, but you can't change it dynamically!
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
199
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
200 Generic const return warning. See extend-fname.c. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
201
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
202 static std::string
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
203 kpse_readable_file (const std::string& name)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
204 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
205 std::string ret;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
206
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
207 if (READABLE (name))
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
208 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
209 ret = name;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
210
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
211 #if defined (ENAMETOOLONG)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
212 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
213 else if (errno == ENAMETOOLONG)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
214 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
215 ret = kpse_truncate_filename (name);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
216
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
217 /* Perhaps some other error will occur with the truncated name,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
218 so let's call access again. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
219
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
220 if (! READABLE (ret))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
221 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
222 /* Failed. */
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20955
diff changeset
223 ret = "";
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
224 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
225 #endif /* ENAMETOOLONG */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
226
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
227 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
228 else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
229 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
230 /* Some other error. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
231 if (errno == EACCES)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
232 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
233 /* Maybe warn them if permissions are bad. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
234 perror (name.c_str ());
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
235 }
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
236
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20955
diff changeset
237 ret = "";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
238 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
239
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
240 return ret;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
241 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
242
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
243 static bool
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
244 kpse_absolute_p (const std::string& filename, int relative_ok)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
245 {
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
246 return (octave::sys::env::absolute_pathname (filename)
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
247 || (relative_ok
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
248 && octave::sys::env::rooted_relative_pathname (filename)));
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
249 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
250
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
251 /* The very first search is for texmf.cnf, called when someone tries to
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
252 initialize the TFM path or whatever. init_path calls kpse_cnf_get
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
253 which calls kpse_all_path_search to find all the texmf.cnf's. We
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
254 need to do various special things in this case, since we obviously
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
255 don't yet have the configuration files when we're searching for the
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
256 configuration files. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
257 static bool first_search = true;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
258
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
259 /* This function is called after every search. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
260
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
261 static void
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
262 log_search (const std::list<std::string>& filenames)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
263 {
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
264 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
265 {
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
266 for (const auto& filename : filenames)
22061
737b1d9d7ee3 use octave::sys::time instead of C library time function
John W. Eaton <jwe@octave.org>
parents: 21979
diff changeset
267 {
737b1d9d7ee3 use octave::sys::time instead of C library time function
John W. Eaton <jwe@octave.org>
parents: 21979
diff changeset
268 octave::sys::time now;
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
269 std::cerr << now.unix_time () << ' ' << filename << std::endl;
22061
737b1d9d7ee3 use octave::sys::time instead of C library time function
John W. Eaton <jwe@octave.org>
parents: 21979
diff changeset
270 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
271 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
272 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
273
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
274 /* Concatenate each element in DIRS with NAME (assume each ends with a
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
275 /, to save time). If SEARCH_ALL is false, return the first readable
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
276 regular file. Else continue to search for more. In any case, if
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
277 none, return a list containing just NULL.
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
278
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
279 We keep a single buffer for the potential filenames and reallocate
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
280 only when necessary. I'm not sure it's noticeably faster, but it
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
281 does seem cleaner. (We do waste a bit of space in the return
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
282 value, though, since we don't shrink it to the final size returned.) */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
283
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
284 static std::list<std::string>
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
285 dir_search (const std::string& dir, const std::string& name,
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
286 bool search_all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
287 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
288 std::list<std::string> ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
289
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
290 std::string potential = dir + name;
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
291
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
292 std::string tmp = kpse_readable_file (potential);
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
293
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
294 if (! tmp.empty ())
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
295 {
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
296 ret.push_back (potential);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
297
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
298 if (! search_all)
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
299 return ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
300 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
301
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
302 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
303 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
304
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
305 /* This is called when NAME is absolute or explicitly relative; if it's
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
306 readable, return (a list containing) it; otherwise, return NULL. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
307
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
308 static std::list<std::string>
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
309 absolute_search (const std::string& name)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
310 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
311 std::list<std::string> ret_list;
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
312 std::string found = kpse_readable_file (name);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
313
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
314 /* Add 'found' to the return list even if it's null; that tells
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
315 the caller we didn't find anything. */
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
316 ret_list.push_back (found);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
317
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
318 return ret_list;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
319 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
320
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
321 /* This is the hard case -- look for NAME in PATH. If ALL is false,
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
322 return the first file found. Otherwise, search all elements of PATH. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
323
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
324 static std::list<std::string>
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
325 path_search (const std::string& path, const std::string& name, bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
326 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
327 std::list<std::string> ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
328 bool done = false;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
329
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
330 for (kpse_path_iterator pi (path); ! done && pi != std::string::npos; pi++)
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
331 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
332 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
333
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
334 std::list<std::string> found;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
335
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
336 /* Do not touch the device if present */
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
337 if (NAME_BEGINS_WITH_DEVICE (elt))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
338 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
339 while (elt.length () > 3
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
340 && IS_DIR_SEP (elt[2]) && IS_DIR_SEP (elt[3]))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
341 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
342 elt[2] = elt[1];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
343 elt[1] = elt[0];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
344 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
345 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
346 }
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
347 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
348 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
349 /* We never want to search the whole disk. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
350 while (elt.length () > 1
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
351 && IS_DIR_SEP (elt[0]) && IS_DIR_SEP (elt[1]))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
352 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
353 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
354
21872
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
355 /* Our caller (search), also tests first_search, and does
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
356 the resetting. */
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
357 if (first_search)
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
358 found = std::list<std::string> ();
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
359
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
360 /* Search the filesystem. */
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
361
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
362 if (found.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
363 {
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
364 std::string dir = kpse_element_dir (elt);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
365
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
366 if (! dir.empty ())
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
367 found = dir_search (dir, name, all);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
368 }
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
369
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
370 /* Did we find anything anywhere? */
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
371 if (! found.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
372 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
373 if (all)
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
374 ret_list.splice (ret_list.end (), found);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
375 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
376 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
377 ret_list.push_back (found.front ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
378 done = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
379 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
380 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
381 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
382
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
383 return ret_list;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
384 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
385
26175
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
386 /* If NAME has a leading ~ or ~user, Unix-style, expand it to the user's
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
387 home directory, and return a new malloced string. If no ~, or no
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
388 <pwd.h>, just return NAME. */
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
389
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
390 static std::string
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
391 kpse_tilde_expand (const std::string& name)
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
392 {
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
393 std::string expansion;
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
394
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
395 /* If no leading tilde, do nothing. */
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
396 if (name.empty () || name[0] != '~')
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
397 {
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
398 expansion = name;
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
399
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
400 /* If a bare tilde, return the home directory or '.'. (Very
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
401 unlikely that the directory name will do anyone any good, but
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
402 ... */
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
403 }
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
404 else if (name.length () == 1)
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
405 {
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
406 expansion = octave::sys::env::get_home_directory ();
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
407
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
408 if (expansion.empty ())
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
409 expansion = ".";
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
410
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
411 /* If '~/', remove any trailing / or replace leading // in $HOME.
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
412 Should really check for doubled intermediate slashes, too. */
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
413 }
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
414 else if (IS_DIR_SEP (name[1]))
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
415 {
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
416 unsigned c = 1;
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
417 std::string home = octave::sys::env::get_home_directory ();
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
418
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
419 if (home.empty ())
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
420 home = ".";
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
421
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
422 size_t home_len = home.length ();
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
423
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
424 /* handle leading // */
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
425 if (home_len > 1 && IS_DIR_SEP (home[0]) && IS_DIR_SEP (home[1]))
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
426 home = home.substr (1);
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
427
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
428 /* omit / after ~ */
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
429 if (IS_DIR_SEP (home[home_len - 1]))
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
430 c++;
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
431
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
432 expansion = home + name.substr (c);
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
433
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
434 /* If '~user' or '~user/', look up user in the passwd database (but
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
435 OS/2 doesn't have this concept. */
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
436 }
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
437 else
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
438 #if defined (HAVE_PWD_H)
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
439 {
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
440 unsigned c = 2;
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
441
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
442 /* find user name */
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
443 while (name.length () > c && ! IS_DIR_SEP (name[c]))
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
444 c++;
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
445
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
446 std::string user = name.substr (1, c-1);
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
447
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
448 /* We only need the cast here for (deficient) systems
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
449 which do not declare 'getpwnam' in <pwd.h>. */
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
450 octave::sys::password p = octave::sys::password::getpwnam (user);
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
451
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
452 /* If no such user, just use '.'. */
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
453 std::string home = (p ? p.dir () : ".");
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
454
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
455 if (home.empty ())
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
456 home = ".";
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
457
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
458 /* handle leading // */
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
459 if (home.length () > 1 && IS_DIR_SEP (home[0]) && IS_DIR_SEP (home[1]))
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
460 home = home.substr (1);
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
461
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
462 /* If HOME ends in /, omit the / after ~user. */
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
463 if (name.length () > c && IS_DIR_SEP (home.back ()))
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
464 c++;
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
465
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
466 expansion = (name.length () > c ? home : home + name.substr (c));
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
467 }
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
468 #else /* not HAVE_PWD_H */
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
469 expansion = name;
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
470 #endif /* not HAVE_PWD_H */
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
471
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
472 return expansion;
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
473 }
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
474
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
475 /* Search PATH for ORIGINAL_NAME. If ALL is false, or ORIGINAL_NAME is
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
476 absolute_p, check ORIGINAL_NAME itself. Otherwise, look at each
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
477 element of PATH for the first readable ORIGINAL_NAME.
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
478
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
479 Always return a list; if no files are found, the list will
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
480 contain just NULL. If ALL is true, the list will be
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
481 terminated with NULL. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
482
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
483 static std::list<std::string>
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
484 search (const std::string& path, const std::string& original_name,
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
485 bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
486 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
487 std::list<std::string> ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
488 bool absolute_p;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
489
26175
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
490 /* Make a leading ~ count as an absolute filename. */
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
491 std::string name = kpse_tilde_expand (original_name);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
492
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
493 /* If the first name is absolute or explicitly relative, no need to
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
494 consider PATH at all. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
495 absolute_p = kpse_absolute_p (name, true);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
496
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
497 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
498 std::cerr << "kdebug: start search (file=" << name
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
499 << ", find_all=" << all << ", path=" << path << ")."
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
500 << std::endl;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
501
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
502 /* Find the file(s). */
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
503 ret_list = (absolute_p
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
504 ? absolute_search (name)
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
505 : path_search (path, name, all));
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
506
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
507 /* The very first search is for texmf.cnf. We can't log that, since
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
508 we want to allow setting TEXMFLOG in texmf.cnf. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
509 if (first_search)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
510 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
511 first_search = false;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
512 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
513 else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
514 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
515 /* Record the filenames we found, if desired. And wrap them in a
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
516 debugging line if we're doing that. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
517
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
518 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
519 std::cerr << "kdebug: search (" << original_name << ") =>";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
520
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
521 log_search (ret_list);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
522
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
523 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
524 std::cerr << std::endl;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
525 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
526
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
527 return ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
528 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
529
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
530 /* Search PATH for the first NAME. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
531
26175
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
532 /* Perform tilde expansion on NAME. If the result is an absolute or
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
533 explicitly relative filename, check whether it is a readable
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
534 (regular) file.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11501
diff changeset
535
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
536 Otherwise, look in each of the directories specified in PATH (also do
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
537 tilde and variable expansion on elements in PATH).
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11501
diff changeset
538
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
539 The caller must expand PATH. This is because it makes more sense to
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
540 do this once, in advance, instead of for every search using it.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11501
diff changeset
541
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
542 In any case, return the complete filename if found, otherwise NULL. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
543
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
544 std::string
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
545 kpse_path_search (const std::string& path, const std::string& name)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
546 {
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
547 std::list<std::string> ret_list = search (path, name, false);
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
548
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
549 return ret_list.empty () ? "" : ret_list.front ();
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
550 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
551
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
552 /* Like 'kpse_path_search' with MUST_EXIST true, but return a list of
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
553 all the filenames (or NULL if none), instead of taking the first. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
554
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
555 std::list<std::string>
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
556 kpse_all_path_search (const std::string& path, const std::string& name)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
557 {
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
558 return search (path, name, true);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
559 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
560
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
561 /* This is the hard case -- look in each element of PATH for each
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
562 element of NAMES. If ALL is false, return the first file found.
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
563 Otherwise, search all elements of PATH. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
564
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
565 std::list<std::string>
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
566 path_find_first_of (const std::string& path,
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
567 const std::list<std::string>& names, bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
568 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
569 std::list<std::string> ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
570 bool done = false;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
571
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
572 for (kpse_path_iterator pi (path); ! done && pi != std::string::npos; pi++)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
573 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
574 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
575
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
576 std::string dir;
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
577 std::list<std::string> found;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
578
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
579 /* Do not touch the device if present */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
580
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
581 if (NAME_BEGINS_WITH_DEVICE (elt))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
582 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
583 while (elt.length () > 3
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
584 && IS_DIR_SEP (elt[2]) && IS_DIR_SEP (elt[3]))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
585 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
586 elt[2] = elt[1];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
587 elt[1] = elt[0];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
588 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
589 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
590 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
591 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
592 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
593 /* We never want to search the whole disk. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
594 while (elt.length () > 1
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
595 && IS_DIR_SEP (elt[0]) && IS_DIR_SEP (elt[1]))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
596 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
597 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
598
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
599 /* We have to search one directory at a time. */
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
600 dir = kpse_element_dir (elt);
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
601
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
602 if (! dir.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
603 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
604 for (auto it = names.cbegin (); it != names.cend () && ! done; it++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
605 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
606 std::string name = *it;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
607
21872
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
608 /* Our caller (find_first_of), also tests first_search,
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
609 and does the resetting. */
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
610 if (first_search)
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
611 found = std::list<std::string> ();
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
612
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
613 /* Search the filesystem. */
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
614
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
615 if (found.empty ())
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
616 found = dir_search (dir, name, all);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
617
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
618 /* Did we find anything anywhere? */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
619 if (! found.empty ())
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
620 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
621 if (all)
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
622 ret_list.splice (ret_list.end (), found);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
623 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
624 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
625 ret_list.push_back (found.front ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
626 done = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
627 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
628 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
629 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
630 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
631 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
632
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
633 return ret_list;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
634 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
635
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
636 static std::list<std::string>
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
637 find_first_of (const std::string& path, const std::list<std::string>& names,
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
638 bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
639 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
640 std::list<std::string> ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
641
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
642 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
643 {
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
644 std::cerr << "kdebug: start find_first_of (";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
645
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
646 for (auto p = names.cbegin (); p != names.cend (); p++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
647 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
648 if (p == names.cbegin ())
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
649 std::cerr << *p;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
650 else
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
651 std::cerr << ", " << *p;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
652 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
653
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
654 std::cerr << "), path=" << path << '.' << std::endl;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
655 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
656
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
657 for (const auto& name : names)
4409
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
658 {
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
659 if (kpse_absolute_p (name, true))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
660 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
661 /* If the name is absolute or explicitly relative, no need
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
662 to consider PATH at all. If we find something, then we
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
663 are done. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
664
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
665 ret_list = absolute_search (name);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
666
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
667 if (! ret_list.empty ())
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
668 return ret_list;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
669 }
4409
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
670 }
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
671
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
672 /* Find the file. */
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
673 ret_list = path_find_first_of (path, names, all);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
674
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
675 /* The very first search is for texmf.cnf. We can't log that, since
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
676 we want to allow setting TEXMFLOG in texmf.cnf. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
677 if (first_search)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
678 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
679 first_search = false;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
680 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
681 else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
682 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
683 /* Record the filenames we found, if desired. And wrap them in a
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
684 debugging line if we're doing that. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
685
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
686 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
687 {
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
688 std::cerr << "kdebug: find_first_of (";
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
689
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
690 for (auto p = names.cbegin (); p != names.cend (); p++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
691 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
692 if (p == names.cbegin ())
24199
2ac103974d00 Remove extra space between scope operator '::' and function.
Rik <rik@octave.org>
parents: 23829
diff changeset
693 std::cerr << *p;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
694 else
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
695 std::cerr << ", " << *p;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
696 }
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
697
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
698 std::cerr << ") =>";
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
699 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
700
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
701 log_search (ret_list);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
702
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
703 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
21887
525b46f1d48f * kpse.cc (find_first_of): Use iostream instead of stdio for debug message.
John W. Eaton <jwe@octave.org>
parents: 21884
diff changeset
704 std::cerr << std::endl;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
705 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
706
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
707 return ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
708 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
709
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
710 /* Search each element of PATH for each element of NAMES. Return the
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
711 first one found. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
712
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
713 /* Search each element of PATH for each element in the list of NAMES.
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
714 Return the first one found. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
715
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
716 std::string
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
717 kpse_path_find_first_of (const std::string& path,
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
718 const std::list<std::string>& names)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
719 {
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
720 std::list<std::string> ret_list = find_first_of (path, names, false);
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
721
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
722 return ret_list.empty () ? "" : ret_list.front ();
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
723 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
724
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
725 /* Search each element of PATH for each element of NAMES and return a
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
726 list containing everything found, in the order found. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
727
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
728 /* Like 'kpse_path_find_first_of' with MUST_EXIST true, but return a
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
729 list of all the filenames (or NULL if none), instead of taking the
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
730 first. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
731
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
732 std::list<std::string>
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
733 kpse_all_path_find_first_of (const std::string& path,
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
734 const std::list<std::string>& names)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
735 {
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
736 return find_first_of (path, names, true);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
737 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
738
26175
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
739 /* Perform tilde expansion on each element of the path, and include
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
740 canonical directory names for only the the actually existing
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
741 directories in the result. */
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
742
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
743 std::string
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
744 kpse_path_expand (const std::string& path)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
745 {
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
746 std::string ret;
26175
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
747 unsigned len = 0;
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
748
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
749 /* Now expand each of the path elements, printing the results */
26175
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
750 for (kpse_path_iterator pi (path); pi != std::string::npos; pi++)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
751 {
26175
6e1a800dd365 eliminate brace and variable expansion in PATH search code
John W. Eaton <jwe@octave.org>
parents: 26174
diff changeset
752 std::string elt = kpse_tilde_expand (*pi);
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
753
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
754 std::string dir;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
755
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
756 /* Do not touch the device if present */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
757 if (NAME_BEGINS_WITH_DEVICE (elt))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
758 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
759 while (elt.length () > 3
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
760 && IS_DIR_SEP (elt[2]) && IS_DIR_SEP (elt[3]))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
761 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
762 elt[2] = elt[1];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
763 elt[1] = elt[0];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
764 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
765 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
766 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
767 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
768 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
769 /* We never want to search the whole disk. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
770 while (elt.length () > 1
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
771 && IS_DIR_SEP (elt[0]) && IS_DIR_SEP (elt[1]))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
772 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
773 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
774
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
775 /* Search the disk for all dirs in the component specified.
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
776 Be faster to check the database, but this is more reliable. */
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
777 dir = kpse_element_dir (elt);
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
778
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
779 size_t dirlen = dir.length ();
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
780
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
781 if (dirlen > 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
782 {
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
783 ret += dir;
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
784 len += dirlen;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
785
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
786 /* Retain trailing slash if that's the root directory. */
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
787 if (dirlen == 1
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
788 || (dirlen == 3 && NAME_BEGINS_WITH_DEVICE (dir)
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
789 && IS_DIR_SEP (dir[2])))
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
790 {
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
791 ret += ENV_SEP_STRING;
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
792 len++;
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
793 }
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
794
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
795 ret[len-1] = ENV_SEP;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
796 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
797 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
798
23812
057a894914df Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents: 23807
diff changeset
799 if (! ret.empty ())
057a894914df Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents: 23807
diff changeset
800 ret.pop_back ();
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
801
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
802 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
803 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
804
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
805 /* braces.c -- code for doing word expansion in curly braces. Taken from
16768
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
806 bash 1.14.5. [And subsequently modified for kpatshea.]
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
807
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
808 Copyright (C) 1987,1991 Free Software Foundation, Inc. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
809
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
810 #define brace_whitespace(c) (! (c) || (c) == ' ' || (c) == '\t' || (c) == '\n')
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
811
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
812 /* Basic idea:
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
813
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
814 Segregate the text into 3 sections: preamble (stuff before an open brace),
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
815 postamble (stuff after the matching close brace) and amble (stuff after
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
816 preamble, and before postamble). Expand amble, and then tack on the
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
817 expansions to preamble. Expand postamble, and tack on the expansions to
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
818 the result so far. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
819
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
820 /* Return a new array of strings which is the result of appending each
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
821 string in ARR2 to each string in ARR1. The resultant array is
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
822 len (arr1) * len (arr2) long. For convenience, ARR1 (and its contents)
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
823 are free ()'ed. ARR1 can be NULL, in that case, a new version of ARR2
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
824 is returned. */
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
825
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
826 static std::list<std::string>
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
827 array_concat (const std::list<std::string>& arr1,
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
828 const std::list<std::string>& arr2)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
829 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
830 std::list<std::string> result;
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
831
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
832 if (arr1.empty ())
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
833 result = arr2;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
834 else if (arr2.empty ())
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
835 result = arr1;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
836 else
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
837 {
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
838 for (const auto& elt_2 : arr2)
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
839 for (const auto& elt_1 : arr1)
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
840 result.push_back (elt_1 + elt_2);
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
841 }
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
842
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
843 return result;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
844 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
845
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
846 static int brace_gobbler (const std::string&, int&, int);
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
847 static std::list<std::string> expand_amble (const std::string&);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
848
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
849 /* Return an array of strings; the brace expansion of TEXT. */
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
850 static std::list<std::string>
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
851 brace_expand (const std::string& text)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
852 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
853 /* Find the text of the preamble. */
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
854 int i = 0;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
855 int c = brace_gobbler (text, i, '{');
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
856
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
857 std::string preamble = text.substr (0, i);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
858
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
859 std::list<std::string> result (1, preamble);
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
860
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
861 if (c == '{')
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
862 {
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
863 /* Find the amble. This is the stuff inside this set of braces. */
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
864 int start = ++i;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
865 c = brace_gobbler (text, i, '}');
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
866
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
867 /* What if there isn't a matching close brace? */
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
868 if (! c)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
869 {
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
870 (*current_liboctave_warning_with_id_handler)
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
871 ("Octave:pathsearch-syntax",
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
872 "%s: Unmatched {", text.c_str ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
873
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
874 result = std::list<std::string> (1, text);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
875 }
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
876 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
877 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
878 std::string amble = text.substr (start, i-start);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
879 result = array_concat (result, expand_amble (amble));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
880
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
881 std::string postamble = text.substr (i+1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
882 result = array_concat (result, brace_expand (postamble));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
883 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
884 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
885
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
886 return result;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
887 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
888
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
889 /* The character which is used to separate arguments. */
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
890 static int brace_arg_separator = ',';
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
891
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
892 /* Expand the text found inside of braces. We simply try to split the
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
893 text at BRACE_ARG_SEPARATORs into separate strings. We then brace
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
894 expand each slot which needs it, until there are no more slots which
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
895 need it. */
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
896 static std::list<std::string>
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
897 expand_amble (const std::string& text)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
898 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
899 std::list<std::string> result;
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
900
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
901 size_t text_len = text.length ();
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
902 size_t start;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
903 int i, c;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
904
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
905 for (start = 0, i = 0, c = 1; c && start < text_len; start = ++i)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
906 {
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
907 int i0 = i;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
908 int c0 = brace_gobbler (text, i0, brace_arg_separator);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
909 int i1 = i;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
910 int c1 = brace_gobbler (text, i1, ENV_SEP);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
911 c = c0 | c1;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
912 i = (i0 < i1 ? i0 : i1);
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
913
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
914 std::string tem = text.substr (start, i-start);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
915
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
916 std::list<std::string> partial = brace_expand (tem);
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
917
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
918 if (result.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
919 result = partial;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
920 else
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
921 result.splice (result.end (), partial);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
922 }
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
923
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
924 return result;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
925 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
926
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
927 /* Start at INDEX, and skip characters in TEXT. Set INDEX to the
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
928 index of the character matching SATISFY. This understands about
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
929 quoting. Return the character that caused us to stop searching;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
930 this is either the same as SATISFY, or 0. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
931 static int
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
932 brace_gobbler (const std::string& text, int& indx, int satisfy)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
933 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
934 int c = 0;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
935 int level = 0;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
936 int quoted = 0;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
937 int pass_next = 0;
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
938
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
939 size_t text_len = text.length ();
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
940
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
941 size_t i = indx;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
942
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
943 for (; i < text_len; i++)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
944 {
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
945 c = text[i];
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
946
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
947 if (pass_next)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
948 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
949 pass_next = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
950 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
951 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
952
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
953 /* A backslash escapes the next character. This allows backslash to
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
954 escape the quote character in a double-quoted string. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
955 if (c == '\\' && (quoted == 0 || quoted == '"' || quoted == '`'))
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
956 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
957 pass_next = 1;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
958 continue;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
959 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
960
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
961 if (quoted)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
962 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
963 if (c == quoted)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
964 quoted = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
965 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
966 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
967
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
968 if (c == '"' || c == '\'' || c == '`')
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
969 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
970 quoted = c;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
971 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
972 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
973
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20791
diff changeset
974 if (c == satisfy && ! level && ! quoted)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
975 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
976 /* We ignore an open brace surrounded by whitespace, and also
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
977 an open brace followed immediately by a close brace, that
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
978 was preceded with whitespace. */
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
979 if (c == '{'
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
980 && ((i == 0 || brace_whitespace (text[i-1]))
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
981 && (i+1 < text_len
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
982 && (brace_whitespace (text[i+1]) || text[i+1] == '}'))))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
983 continue;
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
984 /* If this is being compiled as part of bash, ignore the '{'
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
985 in a '${ }' construct */
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
986 if ((c != '{') || i == 0 || (text[i-1] != '$'))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
987 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
988 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
989
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
990 if (c == '{')
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
991 level++;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
992 else if (c == '}' && level)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
993 level--;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
994 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
995
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
996 indx = i;
26084
8eae32b6bce0 Don't segfault for unmatched brace in PATH (bug #55013).
Rik <rik@octave.org>
parents: 25054
diff changeset
997 c = (c == satisfy) ? c : 0;
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
998 return c;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
999 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1000
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1001 /* Return true if FN is a directory or a symlink to a directory,
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1002 false if not. */
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1003
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1004 static bool
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1005 dir_p (const std::string& fn)
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1006 {
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1007 octave::sys::file_stat fs (fn);
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1008
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1009 return (fs && fs.is_dir ());
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1010 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1011
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1012 /* Given a path element ELT, return a the element with a trailing slash
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1013 or an empty string if the element is not a directory.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11501
diff changeset
1014
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1015 It's up to the caller to expand ELT. This is because this routine is
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1016 most likely only useful to be called from 'kpse_path_search', which
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1017 has already assumed expansion has been done. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1018
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
1019 std::string
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1020 kpse_element_dir (const std::string& elt)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1021 {
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1022 std::string ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1023
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1024 /* If given nothing, return nothing. */
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1025 if (elt.empty ())
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1026 return ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1027
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1028 if (dir_p (elt))
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1029 {
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1030 ret = elt;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1031
23812
057a894914df Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents: 23807
diff changeset
1032 char last_char = ret.back ();
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1033
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1034 if (! (IS_DIR_SEP (last_char) || IS_DEVICE_SEP (last_char)))
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1035 ret += DIR_SEP_STRING;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1036 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1037
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1038 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1039 }