annotate liboctave/util/kpse.cc @ 21872:adb0b3ac4b50

more kpse.cc cleanups * kpse.cc (kpkpse_expand_kpse_dot, kpse_path_expand): Delete special treatment of leading !! in path elements since we no longer use the ls-R cache.
author John W. Eaton <jwe@octave.org>
date Sat, 11 Jun 2016 19:06:54 -0400
parents cab605836305
children 40195d04b17c
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
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19410
diff changeset
6 Copyright (C) 2003-2015 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
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
13 Octave is free software; you can redistribute it and/or modify it
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
14 under the terms of the GNU General Public License as published by the
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
15 Free Software Foundation; either version 3 of the License, or (at your
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
16 option) any later version.
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
17
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
18 Octave is distributed in the hope that it will be useful, but WITHOUT
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
21 for more details.
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
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
25 <http://www.gnu.org/licenses/>.
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
21690
b6a686543080 Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents: 21562
diff changeset
29 // This file should not include config.h. It is only included in other
b6a686543080 Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents: 21562
diff changeset
30 // C++ source files that should have included config.h before including
b6a686543080 Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents: 21562
diff changeset
31 // this file.
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
32
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
33 #include <map>
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
34 #include <fstream>
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
35 #include <iostream>
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
36 #include <string>
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
37
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
38 /* System defines are for non-Unix systems only. (Testing for all Unix
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
39 variations should be done in configure.) Presently the defines used
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
40 are: DOS OS2 WIN32. I do not use any of these systems
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
41 myself; if you do, I'd be grateful for any changes. --kb@mail.tug.org */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
42
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
43 /* If we have either DOS or OS2, we are DOSISH. */
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14155
diff changeset
44 #if defined (DOS) || defined (OS2) || defined (WIN32) || defined (__MSDOS__)
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
45 #define DOSISH
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
46 #endif
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
47
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
48 extern "C" {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14155
diff changeset
49 #if defined (__MINGW32__)
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
50 #include <windows.h>
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
51 #include <fcntl.h>
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14155
diff changeset
52 #elif defined (WIN32)
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
53 #if ! defined (_MSC_VER)
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
54 #define __STDC__ 1
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
55 #include "win32lib.h"
6106
82fff8a063c2 [project @ 2006-10-26 21:52:14 by jwe]
jwe
parents: 5765
diff changeset
56 #endif
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
57 #endif /* not WIN32 */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
58 }
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
59
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
60 /* System dependencies that are figured out by 'configure'. If we are
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
61 compiling standalone, we get our c-auto.h. Otherwise, the package
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
62 containing us must provide this (unless it can somehow generate ours
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
63 from c-auto.in). We use <...> instead of "..." so that the current
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
64 cpp directory (i.e., kpathsea/) won't be searched. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
65
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
66 /* If you want to find subdirectories in a directory with non-Unix
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
67 semantics (specifically, if a directory with no subdirectories does
5622
8b7046423d1e [project @ 2006-02-15 16:36:32 by jwe]
jwe
parents: 5618
diff changeset
68 not have exactly two links), define this. */
21864
f3487b21e879 * kpse.cc: Remove obsolete and unused code.
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
69 #if ! defined (DOSISH)
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
70 #define ST_NLINK_TRICK
21864
f3487b21e879 * kpse.cc: Remove obsolete and unused code.
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
71 #endif /* not DOSISH */
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
72
11236
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
73 /* Define the characters which separate components of
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
74 filenames and environment variable paths. */
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
75
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
76 /* What separates filename components? */
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
77 #if ! defined (DIR_SEP)
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
78 #if defined (DOSISH)
11236
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
79 /* Either \'s or 's work. Wayne Sullivan's web2pc prefers /, so we'll
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
80 go with that. */
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
81 #define DIR_SEP '/'
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
82 #define DIR_SEP_STRING "/"
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
83 #define IS_DEVICE_SEP(ch) ((ch) == ':')
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14155
diff changeset
84 #define NAME_BEGINS_WITH_DEVICE(name) ((name.length ()>0) && IS_DEVICE_SEP((name)[1]))
11236
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
85 /* On DOS, it's good to allow both \ and / between directories. */
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
86 #define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
87 #else
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
88 #define DIR_SEP '/'
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
89 #define DIR_SEP_STRING "/"
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
90 #endif /* not DOSISH */
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
91 #endif /* not DIR_SEP */
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
92
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
93 #if ! defined (IS_DIR_SEP)
11236
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
94 #define IS_DIR_SEP(ch) ((ch) == DIR_SEP)
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
95 #endif
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
96 #if ! defined (IS_DEVICE_SEP)
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
97 /* No 'devices' on, e.g., Unix. */
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11501
diff changeset
98 #define IS_DEVICE_SEP(ch) 0
11236
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
99 #endif
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
100 #if ! defined (NAME_BEGINS_WITH_DEVICE)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11501
diff changeset
101 #define NAME_BEGINS_WITH_DEVICE(name) 0
11236
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
102 #endif
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
103
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
104 #include "file-stat.h"
4396
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
105 #include "lo-error.h"
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
106 #include "oct-env.h"
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
107 #include "oct-passwd.h"
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
108 #include "str-vec.h"
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
109
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
110 /* Header files that essentially all of our sources need, and
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
111 that all implementations have. We include these first, to help with
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
112 NULL being defined multiple times. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
113 #include <cstdarg>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
114 #include <cstdlib>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
115 #include <cerrno>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
116 #include <cassert>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
117
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
118 #include <sys/types.h>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
119 #include <unistd.h>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
120
21863
a25110491607 eliminate obsolete sysdir.h header file
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
121 #include <dirent.h>
a25110491607 eliminate obsolete sysdir.h header file
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
122
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
123 /* define NAME_MAX, the maximum length of a single
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
124 component in a filename. No such limit may exist, or may vary
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
125 depending on the filesystem. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
126
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
127 /* Most likely the system will truncate filenames if it is not POSIX,
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
128 and so we can use the BSD value here. */
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
129 #if ! defined (_POSIX_NAME_MAX)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
130 #define _POSIX_NAME_MAX 255
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
131 #endif
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
132
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
133 #if ! defined (NAME_MAX)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
134 #define NAME_MAX _POSIX_NAME_MAX
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
135 #endif
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
136
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
137 #include <cctype>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
138
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
139 /* What separates elements in environment variable path lists? */
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
140 #if ! defined (ENV_SEP)
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
141 #if defined (SEPCHAR) && defined (SEPCHAR_STR)
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
142 #define ENV_SEP SEPCHAR
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
143 #define ENV_SEP_STRING SEPCHAR_STR
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
144 #elif defined (DOSISH)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
145 #define ENV_SEP ';'
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
146 #define ENV_SEP_STRING ";"
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
147 #else
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
148 #define ENV_SEP ':'
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
149 #define ENV_SEP_STRING ":"
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
150 #endif /* not DOS */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
151 #endif /* not ENV_SEP */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
152
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
153 #if ! defined (IS_ENV_SEP)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
154 #define IS_ENV_SEP(ch) ((ch) == ENV_SEP)
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
155 #endif
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
156
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
157 /* 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
158 #if ! defined (NO_DEBUG)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
159
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
160 /* OK, we'll have tracing support. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
161 #define KPSE_DEBUG
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
162
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
163 /* Test if a bit is on. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
164 #define KPSE_DEBUG_P(bit) (kpathsea_debug & (1 << (bit)))
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
165
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
166 #define KPSE_DEBUG_STAT 0 /* stat calls */
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
167 #define KPSE_DEBUG_EXPAND 1 /* path element expansion */
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
168 #define KPSE_DEBUG_SEARCH 2 /* searches */
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
169 #define KPSE_DEBUG_VARS 3 /* variable values */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
170 #define KPSE_LAST_DEBUG KPSE_DEBUG_VARS
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
171
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
172 #endif /* not NO_DEBUG */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
173
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
174 #if defined (KPSE_DEBUG)
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
175 static unsigned int kpathsea_debug = 0;
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
176 #endif
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
177
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20443
diff changeset
178 #if defined (WIN32) && ! defined (__MINGW32__)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
179
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
180 /* System description file for Windows NT. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
181
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
182 /*
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
183 * Define symbols to identify the version of Unix this is.
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
184 * Define all the symbols that apply correctly.
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
185 */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
186
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
187 #if ! defined (DOSISH)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
188 #define DOSISH
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
189 #endif
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
190
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
191 /* These have to be defined because our compilers treat __STDC__ as being
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
192 defined (most of them anyway). */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
193
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
194 #define access _access
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
195
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
196 /* Define this so that winsock.h definitions don't get included when
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
197 windows.h is... For this to have proper effect, config.h must
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
198 always be included before windows.h. */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
199 #define _WINSOCKAPI_ 1
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
200
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
201 #include <windows.h>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
202
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
203 /* For proper declaration of environ. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
204 #include <io.h>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
205 #include <fcntl.h>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
206 #include <process.h>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
207
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
208 /* ============================================================ */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
209
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
210 #endif /* WIN32 */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
211
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
212 /* Define common sorts of messages. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
213
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
214 /* This should be called only after a system call fails. Don't exit
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
215 with status 'errno', because that might be 256, which would mean
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
216 success (exit statuses are truncated to eight bits). */
4396
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
217 #define FATAL_PERROR(str) \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
218 do \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
219 { \
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
220 std::cerr << "pathsearch: "; \
4396
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
221 perror (str); exit (EXIT_FAILURE); \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
222 } \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
223 while (0)
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
224
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
225 #define FATAL(str) \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
226 do \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
227 { \
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
228 std::cerr << "pathsearch: fatal: " << str << "." << std::endl; \
4396
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
229 exit (1); \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
230 } \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
231 while (0)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
232
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
233 static std::string kpse_var_expand (const std::string& src);
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
234
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
235 static std::list<std::string> kpse_element_dirs (const std::string& elt);
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
236
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
237 static std::string kpse_expand (const std::string& s);
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
238
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
239 static std::string kpse_expand_default (const std::string& path,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
240 const std::string& dflt);
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
241
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
242 #include <ctime> /* for 'time' */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
243
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
244 static bool
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
245 kpse_is_env_sep (char c)
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
246 {
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
247 return IS_ENV_SEP (c);
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
248 }
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
249
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
250 /* A way to step through a path, extracting one directory name at a
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
251 time. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
252
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
253 class kpse_path_iterator
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
254 {
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
255 public:
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
256
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
257 kpse_path_iterator (const std::string& p)
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
258 : path (p), b (0), e (0), len (path.length ()) { set_end (); }
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
259
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
260 kpse_path_iterator (const kpse_path_iterator& pi)
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
261 : path (pi.path), b (pi.b), e (pi.e), len (pi.len) { }
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
262
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
263 kpse_path_iterator operator ++ (int)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
264 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
265 kpse_path_iterator retval (*this);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
266 next ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
267 return retval;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
268 }
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
269
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
270 std::string operator * (void) { return path.substr (b, e-b); }
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
271
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
272 bool operator != (const size_t sz) { return b != sz; }
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
273
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
274 private:
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
275
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
276 const std::string& path;
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
277 size_t b;
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
278 size_t e;
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
279 size_t len;
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
280
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
281 void set_end (void)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
282 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
283 e = b + 1;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
284
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
285 if (e == len)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
286 ; /* OK, we have found the last element. */
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
287 else if (e > len)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
288 b = e = std::string::npos;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
289 else
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
290 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
291 /* Find the next colon not enclosed by braces (or the end of
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
292 the path). */
20443
610c74748518 maint: Clean up code based on static analysis suggestions.
Rik <rik@octave.org>
parents: 20232
diff changeset
293 while (e < len && ! kpse_is_env_sep (path[e]))
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
294 e++;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
295 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
296 }
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
297
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
298 void next (void)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
299 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
300 b = e + 1;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
301
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
302 /* Skip any consecutive colons. */
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
303 while (b < len && kpse_is_env_sep (path[b]))
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
304 b++;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
305
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
306 if (b >= len)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
307 b = e = std::string::npos;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
308 else
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
309 set_end ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
310 }
5617
e92411b7eb21 [project @ 2006-02-13 17:21:31 by jwe]
jwe
parents: 5451
diff changeset
311
e92411b7eb21 [project @ 2006-02-13 17:21:31 by jwe]
jwe
parents: 5451
diff changeset
312 // No assignment.
e92411b7eb21 [project @ 2006-02-13 17:21:31 by jwe]
jwe
parents: 5451
diff changeset
313 kpse_path_iterator& operator = (const kpse_path_iterator&);
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
314 };
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
315
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
316 /* 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
317 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
318
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
319 static std::string
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
320 kpse_truncate_filename (const std::string& name)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
321 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
322 unsigned c_len = 0; /* Length of current component. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
323 unsigned ret_len = 0; /* Length of constructed result. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
324
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
325 std::string ret = name;
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
326
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
327 size_t len = name.length ();
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
328
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
329 for (size_t i = 0; i < len; i++)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
330 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
331 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
332 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
333 /* At a directory delimiter, reset component length. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
334 c_len = 0;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
335 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
336 else if (c_len > NAME_MAX)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
337 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
338 /* 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
339 continue;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
340 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
341
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
342 /* Copy this character. */
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
343 ret[ret_len++] = name[i];
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
344 c_len++;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
345 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
346
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
347 ret.resize (ret_len);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
348
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
349 return ret;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
350 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
351
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
352 /* 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
353 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
354 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
355 kinds of devices. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
356
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
357 #if defined (WIN32)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
358 static inline bool
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
359 READABLE (const std::string& fn)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
360 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
361 const char *t = fn.c_str ();
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
362 return (GetFileAttributes (t) != 0xFFFFFFFF
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
363 && ! (GetFileAttributes (t) & FILE_ATTRIBUTE_DIRECTORY));
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
364 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
365 #else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
366 static inline bool
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
367 READABLE (const std::string& fn)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
368 {
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
369 bool retval = false;
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
370
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
371 const char *t = fn.c_str ();
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
372
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
373 if (access (t, R_OK) == 0)
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
374 {
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
375 octave::sys::file_stat fs (fn);
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
376
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
377 retval = fs && ! fs.is_dir ();
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
378 }
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
379
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
380 return retval;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
381 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
382 #endif
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
383
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
384 /* POSIX invented the brain-damage of not necessarily truncating
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
385 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
386 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
387
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
388 Generic const return warning. See extend-fname.c. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
389
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
390 static std::string
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
391 kpse_readable_file (const std::string& name)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
392 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
393 std::string ret;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
394
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
395 if (READABLE (name))
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
396 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
397 ret = name;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
398
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
399 #if defined (ENAMETOOLONG)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
400 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
401 else if (errno == ENAMETOOLONG)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
402 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
403 ret = kpse_truncate_filename (name);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
404
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
405 /* 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
406 so let's call access again. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
407
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
408 if (! READABLE (ret))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
409 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
410 /* Failed. */
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20955
diff changeset
411 ret = "";
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
412 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
413 #endif /* ENAMETOOLONG */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
414
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
415 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
416 else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
417 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
418 /* Some other error. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
419 if (errno == EACCES)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
420 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
421 /* Maybe warn them if permissions are bad. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
422 perror (name.c_str ());
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
423 }
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
424
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20955
diff changeset
425 ret = "";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
426 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
427
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
428 return ret;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
429 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
430
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
431 static bool
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
432 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
433 {
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
434 return (octave::sys::env::absolute_pathname (filename)
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
435 || (relative_ok
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
436 && octave::sys::env::rooted_relative_pathname (filename)));
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
437 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
438
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
439 /* 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
440 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
441 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
442 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
443 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
444 configuration files. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
445 static bool first_search = true;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
446
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
447 /* This function is called after every search. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
448
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
449 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
450 log_search (const std::list<std::string>& filenames)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
451 {
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
452 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
453 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
454 for (const auto &filename : filenames)
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
455 std::cerr << time (0) << " " << filename << std::endl;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
456 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
457 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
458
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
459 /* 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
460 /, 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
461 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
462 none, return a list containing just NULL.
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
463
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
464 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
465 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
466 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
467 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
468
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
469 static std::list<std::string>
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
470 dir_list_search (std::list<std::string>& dirs, const std::string& name,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
471 bool search_all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
472 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
473 std::list<std::string> ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
474
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
475 for (const auto &dir : dirs)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
476 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
477 std::string potential = dir + name;
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
478
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
479 std::string tmp = kpse_readable_file (potential);
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
480
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
481 if (! tmp.empty ())
4378
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 ret.push_back (potential);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
484
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
485 if (! search_all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
486 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
487 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
488 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
489
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
490 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
491 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
492
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
493 /* 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
494 readable, return (a list containing) it; otherwise, return NULL. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
495
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
496 static std::list<std::string>
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
497 absolute_search (const std::string& name)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
498 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
499 std::list<std::string> ret_list;
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
500 std::string found = kpse_readable_file (name);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
501
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
502 /* 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
503 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
504 ret_list.push_back (found);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
505
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
506 return ret_list;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
507 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
508
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
509 /* 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
510 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
511
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
512 static std::list<std::string>
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
513 path_search (const std::string& path, const std::string& name,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
514 bool /* must_exist */, bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
515 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
516 std::list<std::string> ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
517 bool done = false;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
518
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
519 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
520 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
521 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
522
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
523 std::list<std::string> found;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
524
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
525 /* Do not touch the device if present */
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
526 if (NAME_BEGINS_WITH_DEVICE (elt))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
527 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
528 while (elt.length () > 3
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
529 && 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
530 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
531 elt[2] = elt[1];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
532 elt[1] = elt[0];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
533 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
534 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
535 }
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
536 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
537 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
538 /* We never want to search the whole disk. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
539 while (elt.length () > 1
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
540 && 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
541 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
542 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
543
21872
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
544 /* Our caller (search), also tests first_search, and does
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
545 the resetting. */
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
546 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
547 found = std::list<std::string> ();
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
548
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
549 /* Search the filesystem. */
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
550
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
551 if (found.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
552 {
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
553 std::list<std::string> dirs = kpse_element_dirs (elt);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
554
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
555 if (! dirs.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
556 found = dir_list_search (dirs, name, all);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
557 }
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
558
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
559 /* Did we find anything anywhere? */
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
560 if (! found.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
561 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
562 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
563 ret_list.splice (ret_list.end (), found);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
564 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
565 {
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 ret_list.push_back (found.front ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
567 done = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
568 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
569 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
570 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
571
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
572 return ret_list;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
573 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
574
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
575 /* 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
576 absolute_p, check ORIGINAL_NAME itself. Otherwise, look at each
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
577 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
578
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
579 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
580 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
581 terminated with NULL. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
582
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
583 static std::list<std::string>
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
584 search (const std::string& path, const std::string& original_name,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
585 bool must_exist, bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
586 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
587 std::list<std::string> ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
588 bool absolute_p;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
589
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
590 /* Make a leading ~ count as an absolute filename, and expand $FOO's. */
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
591 std::string name = kpse_expand (original_name);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
592
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
593 /* 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
594 consider PATH at all. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
595 absolute_p = kpse_absolute_p (name, true);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
596
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
597 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
598 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
599 << ", must_exist=" << must_exist
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
600 << ", find_all=" << all << ", path=" << path << ")."
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
601 << std::endl;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
602
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
603 /* Find the file(s). */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
604 ret_list = absolute_p ? absolute_search (name)
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
605 : path_search (path, name, must_exist, all);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
606
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
607 /* 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
608 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
609 if (first_search)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
610 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
611 first_search = false;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
612 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
613 else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
614 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
615 /* 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
616 debugging line if we're doing that. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
617
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
618 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
619 std::cerr << "kdebug: search (" << original_name << ") =>";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
620
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
621 log_search (ret_list);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
622
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
623 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
624 std::cerr << std::endl;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
625 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
626
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
627 return ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
628 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
629
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
630 /* Search PATH for the first NAME. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
631
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
632 /* Call 'kpse_expand' 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
633 explicitly relative filename, check whether it is a readable
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
634 (regular) file.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11501
diff changeset
635
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
636 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
637 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
638
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
639 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
640 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
641
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
642 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
643
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
644 static std::string
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
645 kpse_path_search (const std::string& path, const std::string& name,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
646 bool must_exist)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
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 std::list<std::string> ret_list = search (path, name, must_exist, false);
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
649
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
650 return ret_list.empty () ? "" : ret_list.front ();
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
651 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
652
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
653 /* Search all elements of PATH for files named NAME. Not sure if it's
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
654 right to assert 'must_exist' here, but it suffices now. */
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
655
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
656 /* 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
657 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
658
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
659 static std::list<std::string>
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
660 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
661 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
662 return search (path, name, true, true);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
663 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
664
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
665 /* 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
666 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
667 Otherwise, search all elements of PATH. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
668
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
669 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
670 path_find_first_of (const std::string& path,
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
671 const std::list<std::string>& names,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
672 bool /* must_exist */, bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
673 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
674 std::list<std::string> ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
675 bool done = false;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
676
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
677 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
678 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
679 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
680
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
681 std::list<std::string> dirs;
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
682 std::list<std::string> found;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
683
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
684 /* Do not touch the device if present */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
685
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
686 if (NAME_BEGINS_WITH_DEVICE (elt))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
687 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
688 while (elt.length () > 3
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
689 && 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
690 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
691 elt[2] = elt[1];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
692 elt[1] = elt[0];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
693 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
694 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
695 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
696 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
697 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
698 /* We never want to search the whole disk. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
699 while (elt.length () > 1
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
700 && 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
701 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
702 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
703
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
704 /* We have to search one directory at a time. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
705 dirs = kpse_element_dirs (elt);
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
706 for (const auto &dir : dirs)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
707 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
708 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
709 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
710 std::string name = *it;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
711
21872
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
712 /* Our caller (find_first_of), also tests first_search,
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
713 and does the resetting. */
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
714 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
715 found = std::list<std::string> ();
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
716
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
717 /* Search the filesystem. */
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
718
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
719 if (found.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
720 {
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
721 std::list<std::string> tmp;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
722
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
723 tmp.push_back (dir);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
724
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
725 found = dir_list_search (tmp, name, all);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
726 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
727
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
728 /* Did we find anything anywhere? */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
729 if (! found.empty ())
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
730 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
731 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
732 ret_list.splice (ret_list.end (), found);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
733 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
734 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
735 ret_list.push_back (found.front ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
736 done = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
737 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
738 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
739 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
740 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
741 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
742
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
743 return ret_list;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
744 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
745
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
746 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
747 find_first_of (const std::string& path, const std::list<std::string>& names,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
748 bool must_exist, bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
749 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
750 std::list<std::string> ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
751
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
752 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
753 {
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
754 std::cerr << "kdebug: start find_first_of ((";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
755
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
756 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
757 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
758 if (p == names.cbegin ())
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
759 std::cerr << *p;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
760 else
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
761 std::cerr << ", " << *p;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
762 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
763
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
764 std::cerr << "), path=" << path << ", must_exist="
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
765 << must_exist << "." << std::endl;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
766 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
767
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
768 for (const auto &name : names)
4409
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
769 {
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
770 if (kpse_absolute_p (name, true))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
771 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
772 /* 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
773 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
774 are done. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
775
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
776 ret_list = absolute_search (name);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
777
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
778 if (! ret_list.empty ())
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
779 return ret_list;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
780 }
4409
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
781 }
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
782
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
783 /* Find the file. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
784 ret_list = path_find_first_of (path, names, must_exist, all);
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
785
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
786 /* 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
787 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
788 if (first_search)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
789 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
790 first_search = false;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
791 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
792 else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
793 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
794 /* 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
795 debugging line if we're doing that. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
796
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
797 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
798 {
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
799 std::cerr << "kdebug: find_first_of (";
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
800
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
801 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
802 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
803 if (p == names.cbegin ())
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
804 std:: cerr << *p;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
805 else
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
806 std::cerr << ", " << *p;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
807 }
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
808
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
809 std::cerr << ") =>";
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
810 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
811
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
812 log_search (ret_list);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
813
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
814 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
815 gnulib::putc ('\n', stderr);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
816 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
817
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
818 return ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
819 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
820
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
821 /* 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
822 first one found. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
823
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
824 /* 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
825 Return the first one found. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
826
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
827 static 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
828 kpse_path_find_first_of (const std::string& path,
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
829 const std::list<std::string>& names,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
830 bool must_exist)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
831 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
832 std::list<std::string> ret_list
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
833 = find_first_of (path, names, must_exist, false);
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
834
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
835 return ret_list.empty () ? "" : ret_list.front ();
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
836 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
837
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
838 /* 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
839 list containing everything found, in the order found. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
840
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
841 /* 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
842 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
843 first. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
844
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
845 static std::list<std::string>
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
846 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
847 const std::list<std::string>& names)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
848 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
849 return find_first_of (path, names, true, true);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
850 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
851
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
852 /* General expansion. Some of this file (the brace-expansion
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
853 code from bash) is covered by the GPL; this is the only GPL-covered
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
854 code in kpathsea. The part of the file that I wrote (the first
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
855 couple of functions) is covered by the LGPL. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
856
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
857 /* If NAME has a leading ~ or ~user, Unix-style, expand it to the user's
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
858 home directory, and return a new malloced string. If no ~, or no
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
859 <pwd.h>, just return NAME. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
860
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
861 static std::string
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
862 kpse_tilde_expand (const std::string& name)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
863 {
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
864 std::string expansion;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
865
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
866 /* If no leading tilde, do nothing. */
5137
5ee7da8b8a4b [project @ 2005-02-09 17:59:19 by jwe]
jwe
parents: 5085
diff changeset
867 if (name.empty () || name[0] != '~')
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
868 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
869 expansion = name;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
870
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
871 /* If a bare tilde, return the home directory or '.'. (Very
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
872 unlikely that the directory name will do anyone any good, but
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
873 ... */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
874 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
875 else if (name.length () == 1)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
876 {
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21729
diff changeset
877 expansion = octave::sys::env::get_home_directory ();
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
878
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
879 if (expansion.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
880 expansion = ".";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
881
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
882 /* If '~/', remove any trailing / or replace leading // in $HOME.
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
883 Should really check for doubled intermediate slashes, too. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
884 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
885 else if (IS_DIR_SEP (name[1]))
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
886 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
887 unsigned c = 1;
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21729
diff changeset
888 std::string home = octave::sys::env::get_home_directory ();
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
889
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
890 if (home.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
891 home = ".";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
892
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
893 size_t home_len = home.length ();
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
894
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
895 /* handle leading // */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
896 if (home_len > 1 && IS_DIR_SEP (home[0]) && IS_DIR_SEP (home[1]))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
897 home = home.substr (1);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
898
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
899 /* omit / after ~ */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
900 if (IS_DIR_SEP (home[home_len - 1]))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
901 c++;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
902
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
903 expansion = home + name.substr (c);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
904
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
905 /* If '~user' or '~user/', look up user in the passwd database (but
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
906 OS/2 doesn't have this concept. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
907 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
908 else
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
909 #if defined (HAVE_PWD_H)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
910 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
911 unsigned c = 2;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
912
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
913 /* find user name */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
914 while (name.length () > c && ! IS_DIR_SEP (name[c]))
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
915 c++;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
916
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
917 std::string user = name.substr (1, c-1);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
918
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
919 /* We only need the cast here for (deficient) systems
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
920 which do not declare 'getpwnam' in <pwd.h>. */
21729
815b2f500fab use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
921 octave::sys::password p = octave::sys::password::getpwnam (user);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
922
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
923 /* If no such user, just use '.'. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
924 std::string home = p ? p.dir () : std::string (".");
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
925
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
926 if (home.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
927 home = ".";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
928
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
929 /* handle leading // */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
930 if (home.length () > 1 && IS_DIR_SEP (home[0]) && IS_DIR_SEP (home[1]))
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
931 home = home.substr (1);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
932
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
933 /* If HOME ends in /, omit the / after ~user. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
934 if (name.length () > c && IS_DIR_SEP (home[home.length () - 1]))
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
935 c++;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
936
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
937 expansion = name.length () > c ? home : home + name.substr (c);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
938 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
939 #else /* not HAVE_PWD_H */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
940 expansion = name;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
941 #endif /* not HAVE_PWD_H */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
942
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
943 return expansion;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
944 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
945
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
946 /* Do variable expansion first so ~${USER} works. (Besides, it's what the
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
947 shells do.) */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
948
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
949 /* Call kpse_var_expand and kpse_tilde_expand (in that order). Result
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
950 is always in fresh memory, even if no expansions were done. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
951
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
952 static std::string
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
953 kpse_expand (const std::string& s)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
954 {
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
955 std::string var_expansion = kpse_var_expand (s);
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
956 return kpse_tilde_expand (var_expansion);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
957 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
958
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
959 /* Forward declarations of functions from the original expand.c */
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
960 static std::list<std::string> brace_expand (const std::string&);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
961
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
962 /* If $KPSE_DOT is defined in the environment, prepend it to any relative
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
963 path components. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
964
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
965 static std::string
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
966 kpse_expand_kpse_dot (const std::string& path)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
967 {
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
968 std::string ret;
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21729
diff changeset
969 std::string kpse_dot = octave::sys::env::getenv ("KPSE_DOT");
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
970
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
971 if (kpse_dot.empty ())
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
972 return path;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
973
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
974 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
975 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
976 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
977
21872
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
978 /* Single "." get special treatment, as does "./" or its equivalent. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
979
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
980 size_t elt_len = elt.length ();
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
981
21872
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
982 if (kpse_absolute_p (elt, false))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
983 ret += elt + ENV_SEP_STRING;
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
984 else if (elt_len == 1 && elt[0] == '.')
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
985 ret += kpse_dot + ENV_SEP_STRING;
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
986 else if (elt_len > 1 && elt[0] == '.' && IS_DIR_SEP (elt[1]))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
987 ret += kpse_dot + elt.substr (1) + ENV_SEP_STRING;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
988 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
989 ret += kpse_dot + DIR_SEP_STRING + elt + ENV_SEP_STRING;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
990 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
991
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
992 int len = ret.length ();
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
993 if (len > 0)
4395
cc6d369355ec [project @ 2003-04-28 18:14:56 by jwe]
jwe
parents: 4394
diff changeset
994 ret.resize (len-1);
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
995
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
996 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
997 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
998
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
999 /* Do brace expansion on ELT; then do variable and ~ expansion on each
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1000 element of the result; then do brace expansion again, in case a
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1001 variable definition contained braces (e.g., $TEXMF). Return a
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1002 string comprising all of the results separated by ENV_SEP_STRING. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1003
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1004 static std::string
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1005 kpse_brace_expand_element (const std::string& elt)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1006 {
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1007 std::string ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1008
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1009 std::list<std::string> expansions = brace_expand (elt);
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1010
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1011 for (const auto &expanded_elt : expansions)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1012 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1013 /* Do $ and ~ expansion on each element. */
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1014 std::string x = kpse_expand (expanded_elt);
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1015
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1016 if (x != elt)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1017 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1018 /* If we did any expansions, do brace expansion again. Since
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1019 recursive variable definitions are not allowed, this recursion
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1020 must terminate. (In practice, it's unlikely there will ever be
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1021 more than one level of recursion.) */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1022 x = kpse_brace_expand_element (x);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1023 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1024
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1025 ret += x + ENV_SEP_STRING;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1026 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1027
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1028 ret.resize (ret.length () - 1);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1029
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1030 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1031 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1032
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1033 /* Do brace expansion and call 'kpse_expand' on each element of the
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1034 result; return the final expansion (always in fresh memory, even if
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1035 no expansions were done). We don't call 'kpse_expand_default'
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1036 because there is a whole sequence of defaults to run through; see
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1037 'kpse_init_format'. */
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1038
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1039 static std::string
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1040 kpse_brace_expand (const std::string& path)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1041 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1042 /* Must do variable expansion first because if we have
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1043 foo = .:~
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1044 TEXINPUTS = $foo
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1045 we want to end up with TEXINPUTS = .:/home/karl.
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1046 Since kpse_path_element is not reentrant, we must get all
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1047 the path elements before we start the loop. */
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1048 std::string tmp = kpse_var_expand (path);
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1049
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1050 std::string ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1051
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
1052 for (kpse_path_iterator pi (tmp); pi != std::string::npos; pi++)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1053 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1054 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1055
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1056 /* Do brace expansion first, so tilde expansion happens in {~ka,~kb}. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1057 std::string expansion = kpse_brace_expand_element (elt);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1058 ret += expansion + ENV_SEP_STRING;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1059 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1060
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1061 size_t len = ret.length ();
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1062 if (len > 0)
4395
cc6d369355ec [project @ 2003-04-28 18:14:56 by jwe]
jwe
parents: 4394
diff changeset
1063 ret.resize (len-1);
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1064
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1065 return kpse_expand_kpse_dot (ret);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1066 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1067
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1068 /* Expand all special constructs in a path, and include only the actually
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1069 existing directories in the result. */
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1070
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1071 /* Do brace expansion and call 'kpse_expand' on each argument of the
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1072 result, then expand any '//' constructs. The final expansion (always
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1073 in fresh memory) is a path of all the existing directories that match
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1074 the pattern. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1075
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1076 static std::string
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1077 kpse_path_expand (const std::string& path)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1078 {
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1079 std::string ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1080 unsigned len;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1081
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1082 len = 0;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1083
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1084 /* Expand variables and braces first. */
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1085 std::string tmp = kpse_brace_expand (path);
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1086
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1087 /* Now expand each of the path elements, printing the results */
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
1088 for (kpse_path_iterator pi (tmp); pi != std::string::npos; pi++)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1089 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1090 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1091
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1092 std::list<std::string> dirs;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1093
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1094 /* Do not touch the device if present */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1095 if (NAME_BEGINS_WITH_DEVICE (elt))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1096 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1097 while (elt.length () > 3
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1098 && 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
1099 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1100 elt[2] = elt[1];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1101 elt[1] = elt[0];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1102 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1103 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1104 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1105 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1106 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1107 /* We never want to search the whole disk. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1108 while (elt.length () > 1
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1109 && 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
1110 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1111 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1112
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1113 /* 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
1114 Be faster to check the database, but this is more reliable. */
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1115 dirs = kpse_element_dirs (elt);
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1116
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1117 if (! dirs.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1118 {
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1119 for (const auto &dir : dirs)
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1120 {
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1121 size_t dirlen = dir.length ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1122
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1123 ret += dir;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1124 len += dirlen;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1125
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1126 /* Retain trailing slash if that's the root directory. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1127 if (dirlen == 1
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1128 || (dirlen == 3 && NAME_BEGINS_WITH_DEVICE (dir)
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1129 && IS_DIR_SEP (dir[2])))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1130 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1131 ret += ENV_SEP_STRING;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1132 len++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1133 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1134
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1135 ret[len-1] = ENV_SEP;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1136 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1137 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1138 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1139
4395
cc6d369355ec [project @ 2003-04-28 18:14:56 by jwe]
jwe
parents: 4394
diff changeset
1140 if (len > 0)
cc6d369355ec [project @ 2003-04-28 18:14:56 by jwe]
jwe
parents: 4394
diff changeset
1141 ret.resize (len-1);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1142
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1143 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1144 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1145
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
1146 /* 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
1147 bash 1.14.5. [And subsequently modified for kpatshea.]
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
1148
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
1149 Copyright (C) 1987,1991 Free Software Foundation, Inc. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1150
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1151 #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
1152
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1153 /* Basic idea:
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1154
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1155 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
1156 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
1157 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
1158 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
1159 the result so far. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1160
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1161 /* 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
1162 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
1163 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
1164 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
1165 is returned. */
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1166
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1167 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
1168 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
1169 const std::list<std::string>& arr2)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1170 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1171 std::list<std::string> result;
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1172
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1173 if (arr1.empty ())
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1174 result = arr2;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1175 else if (arr2.empty ())
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1176 result = arr1;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1177 else
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1178 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1179 for (const auto &elt_2 : arr2)
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1180 for (const auto &elt_1 : arr1)
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1181 result.push_back (elt_1 + elt_2);
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1182 }
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1183
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1184 return result;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1185 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1186
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1187 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
1188 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
1189
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1190 /* 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
1191 static std::list<std::string>
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1192 brace_expand (const std::string& text)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1193 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1194 /* Find the text of the preamble. */
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1195 int i = 0;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1196 int c = brace_gobbler (text, i, '{');
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1197
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1198 std::string preamble = text.substr (0, i);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1199
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1200 std::list<std::string> result (1, preamble);
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1201
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1202 if (c == '{')
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1203 {
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1204 /* 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
1205 int start = ++i;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1206 c = brace_gobbler (text, i, '}');
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1207
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1208 /* What if there isn't a matching close brace? */
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1209 if (! c)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1210 {
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1211 (*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
1212 ("Octave:pathsearch-syntax",
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1213 "%s: Unmatched {", text.c_str ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1214
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1215 result = std::list<std::string> (1, text);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1216 }
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1217 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1218 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1219 std::string amble = text.substr (start, i-start);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1220 result = array_concat (result, expand_amble (amble));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1221
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1222 std::string postamble = text.substr (i+1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1223 result = array_concat (result, brace_expand (postamble));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1224 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1225 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1226
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1227 return result;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1228 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1229
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1230 /* The character which is used to separate arguments. */
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1231 static int brace_arg_separator = ',';
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1232
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1233 /* 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
1234 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
1235 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
1236 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
1237 static std::list<std::string>
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1238 expand_amble (const std::string& text)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1239 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1240 std::list<std::string> result;
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1241
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1242 size_t text_len = text.length ();
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1243 size_t start;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1244 int i, c;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1245
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1246 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
1247 {
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1248 int i0 = i;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1249 int c0 = brace_gobbler (text, i0, brace_arg_separator);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1250 int i1 = i;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1251 int c1 = brace_gobbler (text, i1, ENV_SEP);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1252 c = c0 | c1;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1253 i = (i0 < i1 ? i0 : i1);
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1254
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1255 std::string tem = text.substr (start, i-start);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1256
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1257 std::list<std::string> partial = brace_expand (tem);
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1258
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1259 if (result.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1260 result = partial;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1261 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
1262 result.splice (result.end (), partial);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1263 }
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1264
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1265 return result;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1266 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1267
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
1268 /* 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
1269 index of the character matching SATISFY. This understands about
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1270 quoting. Return the character that caused us to stop searching;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1271 this is either the same as SATISFY, or 0. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1272 static int
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1273 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
1274 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
1275 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
1276 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
1277 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
1278 int pass_next = 0;
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1279
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1280 size_t text_len = text.length ();
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1281
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1282 size_t i = indx;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1283
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1284 for (; i < text_len; i++)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1285 {
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1286 c = text[i];
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1287
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1288 if (pass_next)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1289 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1290 pass_next = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1291 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1292 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1293
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1294 /* 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
1295 escape the quote character in a double-quoted string. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1296 if (c == '\\' && (quoted == 0 || quoted == '"' || quoted == '`'))
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1297 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1298 pass_next = 1;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1299 continue;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1300 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1301
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1302 if (quoted)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1303 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1304 if (c == quoted)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1305 quoted = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1306 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1307 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1308
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1309 if (c == '"' || c == '\'' || c == '`')
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1310 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1311 quoted = c;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1312 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1313 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1314
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20791
diff changeset
1315 if (c == satisfy && ! level && ! quoted)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1316 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1317 /* 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
1318 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
1319 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
1320 if (c == '{'
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1321 && ((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
1322 && (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
1323 && (brace_whitespace (text[i+1]) || text[i+1] == '}'))))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1324 continue;
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1325 /* 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
1326 in a '${ }' construct */
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1327 if ((c != '{') || i == 0 || (text[i-1] != '$'))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1328 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1329 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1330
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1331 if (c == '{')
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1332 level++;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1333 else if (c == '}' && level)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1334 level--;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1335 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1336
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1337 indx = i;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1338 return c;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1339 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1340
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1341 /* Return true if FILENAME could be in PATH_ELT, i.e., if the directory
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1342 part of FILENAME matches PATH_ELT. Have to consider // wildcards, but
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1343 $ and ~ expansion have already been done. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1344
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1345 static bool
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1346 match (const std::string& filename_arg, const std::string& path_elt_arg)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1347 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1348 const char *filename = filename_arg.c_str ();
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1349 const char *path_elt = path_elt_arg.c_str ();
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1350
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1351 const char *original_filename = filename;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1352 bool matched = false;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1353
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1354 for (; *filename && *path_elt; filename++, path_elt++)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1355 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1356 if (*filename == *path_elt) /* normal character match */
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1357 ;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1358
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1359 else if (IS_DIR_SEP (*path_elt) /* at // */
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1360 && original_filename < filename && IS_DIR_SEP (path_elt[-1]))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1361 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1362 while (IS_DIR_SEP (*path_elt))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1363 path_elt++; /* get past second and any subsequent /'s */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1364
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1365 if (*path_elt == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1366 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
1367 /* Trailing //, matches anything. We could make this
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1368 part of the other case, but it seems pointless to do
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1369 the extra work. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1370 matched = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1371 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1372 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1373 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1374 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1375 /* Intermediate //, have to match rest of PATH_ELT. */
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20791
diff changeset
1376 for (; ! matched && *filename; filename++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1377 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1378 /* Try matching at each possible character. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1379 if (IS_DIR_SEP (filename[-1]) && *filename == *path_elt)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1380 matched = match (filename, path_elt);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1381 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1382
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1383 /* Prevent filename++ when *filename='\0'. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1384 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1385 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1386 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1387 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1388 /* normal character nonmatch, quit */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1389 break;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1390 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1391
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1392 /* If we've reached the end of PATH_ELT, check that we're at the last
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1393 component of FILENAME, we've matched. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1394 if (! matched && *path_elt == 0)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1395 {
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1396 /* Probably PATH_ELT ended with 'vf' or some such, and FILENAME
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1397 ends with 'vf/ptmr.vf'. In that case, we'll be at a
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1398 directory separator. On the other hand, if PATH_ELT ended
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1399 with a / (as in 'vf/'), FILENAME being the same 'vf/ptmr.vf',
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1400 we'll be at the 'p'. Upshot: if we're at a dir separator in
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1401 FILENAME, skip it. But if not, that's ok, as long as there
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1402 are no more dir separators. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1403
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1404 if (IS_DIR_SEP (*filename))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1405 filename++;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1406
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20791
diff changeset
1407 while (*filename && ! IS_DIR_SEP (*filename))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1408 filename++;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1409
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1410 matched = *filename == 0;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1411 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1412
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1413 return matched;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1414 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1415
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1416 /* Expand extra colons. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1417
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1418 /* Check for leading colon first, then trailing, then doubled, since
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1419 that is fastest. Usually it will be leading or trailing. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1420
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1421 /* Replace a leading or trailing or doubled : in PATH with DFLT. If
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1422 no extra colons, return PATH. Only one extra colon is replaced.
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1423 DFLT may not be NULL. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1424
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1425 static std::string
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1426 kpse_expand_default (const std::string& path, const std::string& fallback)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1427 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1428 std::string expansion;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1429
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1430 size_t path_len = path.length ();
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1431
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1432 if (path_len == 0)
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1433 expansion = fallback;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1434
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1435 /* Solitary or leading :? */
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1436 else if (IS_ENV_SEP (path[0]))
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1437 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1438 expansion = path_len == 1 ? fallback : fallback + path;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1439 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1440
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1441 /* Sorry about the assignment in the middle of the expression, but
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1442 conventions were made to be flouted and all that. I don't see the
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1443 point of calling strlen twice or complicating the logic just to
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1444 avoid the assignment (especially now that I've pointed it out at
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1445 such great length). */
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1446 else if (IS_ENV_SEP (path[path_len-1]))
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1447 expansion = path + fallback;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1448
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1449 /* OK, not leading or trailing. Check for doubled. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1450 else
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1451 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1452 /* What we'll return if we find none. */
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1453 expansion = path;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1454
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1455 for (size_t i = 0; i < path_len; i++)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1456 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1457 if (i + 1 < path_len
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1458 && IS_ENV_SEP (path[i]) && IS_ENV_SEP (path[i+1]))
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1459 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1460 /* We have a doubled colon. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1461
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1462 /* Copy stuff up to and including the first colon. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1463 /* Copy in FALLBACK, and then the rest of PATH. */
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1464 expansion = path.substr (0, i+1) + fallback + path.substr (i+1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1465
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1466 break;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1467 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1468 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1469 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1470
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1471 return expansion;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1472 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1473
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1474 /* Translate a path element to its corresponding director{y,ies}. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1475
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1476 /* To avoid giving prototypes for all the routines and then their real
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1477 definitions, we give all the subroutines first. The entry point is
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1478 the last routine in the file. */
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1479
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1480 /* Make a copy of DIR (unless it's null) and save it in L. Ensure that
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1481 DIR ends with a DIR_SEP for the benefit of later searches. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1482
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1483 static void
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1484 dir_list_add (std::list<std::string>& lst, const std::string& dir)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1485 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1486 char last_char = dir[dir.length () - 1];
4407
16e8acbd19d5 [project @ 2003-05-05 19:00:56 by jwe]
jwe
parents: 4399
diff changeset
1487
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1488 std::string saved_dir = dir;
4407
16e8acbd19d5 [project @ 2003-05-05 19:00:56 by jwe]
jwe
parents: 4399
diff changeset
1489
16e8acbd19d5 [project @ 2003-05-05 19:00:56 by jwe]
jwe
parents: 4399
diff changeset
1490 if (! (IS_DIR_SEP (last_char) || IS_DEVICE_SEP (last_char)))
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1491 saved_dir += DIR_SEP_STRING;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1492
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1493 lst.push_back (saved_dir);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1494 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1495
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1496 /* 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
1497 false if not. */
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1498
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1499 static bool
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1500 dir_p (const std::string& fn)
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1501 {
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1502 octave::sys::file_stat fs (fn);
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1503
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1504 return (fs && fs.is_dir ());
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1505 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1506
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1507 /* If DIR is a directory, add it to the list L. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1508
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1509 static void
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1510 checked_dir_list_add (std::list<std::string>& lst, const std::string& dir)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1511 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1512 if (dir_p (dir))
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1513 dir_list_add (lst, dir);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1514 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1515
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1516 /* The cache. Typically, several paths have the same element; for
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1517 example, /usr/local/lib/texmf/fonts//. We don't want to compute the
21870
841ce662c753 delete unused functions from pathsearch
John W. Eaton <jwe@octave.org>
parents: 21869
diff changeset
1518 expansion of such a thing more than once. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1519
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1520 struct cache_entry
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1521 {
11501
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 11236
diff changeset
1522 cache_entry (void) : key (), value (0) { }
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 11236
diff changeset
1523
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 11236
diff changeset
1524 ~cache_entry (void) { }
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 11236
diff changeset
1525
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1526 std::string key;
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1527 std::list<std::string> value;
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1528 };
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1529
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1530 static cache_entry *the_cache = 0;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1531 static unsigned cache_length = 0;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1532
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1533 /* Associate KEY with VALUE. We implement the cache as a simple linear
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1534 list, since it's unlikely to ever be more than a dozen or so elements
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1535 long. We don't bother to check here if PATH has already been saved;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1536 we always add it to our list. We copy KEY but not VALUE; not sure
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1537 that's right, but it seems to be all that's needed. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1538
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1539 static void
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1540 cache (const std::string key, std::list<std::string>& value)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1541 {
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1542 cache_entry *new_cache = new cache_entry [cache_length+1];
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1543
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1544 for (unsigned i = 0; i < cache_length; i++)
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1545 {
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1546 new_cache[i].key = the_cache[i].key;
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1547 new_cache[i].value = the_cache[i].value;
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1548 }
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1549
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1550 delete [] the_cache;
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1551
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1552 the_cache = new_cache;
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1553
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1554 the_cache[cache_length].key = key;
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1555 the_cache[cache_length].value = value;
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1556
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1557 cache_length++;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1558 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1559
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1560 /* To retrieve, just check the list in order. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1561
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1562 static std::list<std::string>
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1563 cached (const std::string& key)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1564 {
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1565 std::list<std::string> retval;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1566
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1567 for (unsigned p = 0; p < cache_length; p++)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1568 {
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1569 if (key == the_cache[p].key)
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1570 {
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1571 retval = the_cache[p].value;
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1572 break;
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1573 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1574 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1575
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1576 return retval;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1577 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1578
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1579 #if defined (WIN32)
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1580
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1581 /* Shared across recursive calls, it acts like a stack. */
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1582 static std::string dirname;
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1583
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1584 #else /* WIN32 */
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1585
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1586 #endif /* WIN32 */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1587
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1588 /* Here is the entry point. Returns directory list for ELT. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1589
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1590 /* Given a path element ELT, return a pointer to a NULL-terminated list
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1591 of the corresponding (existing) directory or directories, with
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1592 trailing slashes, or NULL. If ELT is the empty string, check the
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1593 current working directory.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11501
diff changeset
1594
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1595 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
1596 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
1597 has already assumed expansion has been done. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1598
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1599 static std::list<std::string>
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1600 kpse_element_dirs (const std::string& elt)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1601 {
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1602 std::list<std::string> ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1603
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1604 /* If given nothing, return nothing. */
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1605 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
1606 return ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1607
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1608 /* If we've already cached the answer for ELT, return it. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1609 ret = cached (elt);
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1610 if (! ret.empty ())
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1611 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1612
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1613 /* We handle the hard case in a subroutine. */
21864
f3487b21e879 * kpse.cc: Remove obsolete and unused code.
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
1614 checked_dir_list_add (ret, elt);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1615
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1616 /* Remember the directory list we just found, in case future calls are
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1617 made with the same ELT. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1618 cache (elt, ret);
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1619
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1620 #if defined (KPSE_DEBUG)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1621 if (KPSE_DEBUG_P (KPSE_DEBUG_EXPAND))
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1622 {
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
1623 std::cerr << "kdebug: path element " << elt << " =>";
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1624 if (! ret.empty ())
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1625 {
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1626 for (const auto &ret_elt : ret)
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1627 std::cerr << " " << ret_elt;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1628 }
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
1629 std::cerr << std::endl;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1630 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1631 #endif /* KPSE_DEBUG */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1632
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1633 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1634 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1635
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1636 /* Variable expansion. */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1637
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1638 /* We have to keep track of variables being expanded, otherwise
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1639 constructs like TEXINPUTS = $TEXINPUTS result in an infinite loop.
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1640 (Or indirectly recursive variables, etc.) Our simple solution is to
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1641 add to a list each time an expansion is started, and check the list
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1642 before expanding. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1643
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1644 static std::map <std::string, bool> expansions;
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1645
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1646 static void
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1647 expanding (const std::string& var, bool xp)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1648 {
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1649 expansions[var] = xp;
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1650 }
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1651
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1652 /* Return whether VAR is currently being expanding. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1653
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1654 static bool
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1655 expanding_p (const std::string& var)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1656 {
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1657 return (expansions.find (var) != expansions.end ()) ? expansions[var] : false;
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1658 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1659
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1660 /* Append the result of value of 'var' to EXPANSION, where 'var' begins
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1661 at START and ends at END. If 'var' is not set, do not complain.
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1662 This is a subroutine for the more complicated expansion function. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1663
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1664 static void
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1665 expand (std::string &expansion, const std::string& var)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1666 {
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1667 if (expanding_p (var))
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1668 {
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1669 (*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
1670 ("Octave:pathsearch-syntax",
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1671 "kpathsea: variable '%s' references itself (eventually)",
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1672 var.c_str ());
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1673 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1674 else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1675 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1676 /* Check for an environment variable. */
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21729
diff changeset
1677 std::string value = octave::sys::env::getenv (var);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1678
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1679 if (! value.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1680 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1681 expanding (var, true);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1682 std::string tmp = kpse_var_expand (value);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1683 expanding (var, false);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1684 expansion += tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1685 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1686 }
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1687 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1688
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1689 /* Can't think of when it would be useful to change these (and the
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1690 diagnostic messages assume them), but ... */
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1691 #if ! defined (IS_VAR_START)
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1692 /* starts all variable references */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1693 #define IS_VAR_START(c) ((c) == '$')
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1694 #endif
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1695 #if ! defined (IS_VAR_CHAR)
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1696 /* variable name constituent */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1697 #define IS_VAR_CHAR(c) (isalnum (c) || (c) == '_')
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1698 #endif
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1699 #if ! defined (IS_VAR_BEGIN_DELIMITER)
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1700 /* start delimited variable name (after $) */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1701 #define IS_VAR_BEGIN_DELIMITER(c) ((c) == '{')
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1702 #endif
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1703 #if ! defined (IS_VAR_END_DELIMITER)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1704 #define IS_VAR_END_DELIMITER(c) ((c) == '}')
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1705 #endif
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1706
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1707 /* Maybe we should support some or all of the various shell ${...}
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1708 constructs, especially ${var-value}. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1709
5085
6861a84b1d47 [project @ 2004-11-19 03:26:32 by jwe]
jwe
parents: 4928
diff changeset
1710 static std::string
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1711 kpse_var_expand (const std::string& src)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1712 {
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1713 std::string expansion;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1714
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1715 size_t src_len = src.length ();
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1716
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1717 /* Copy everything but variable constructs. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1718 for (size_t i = 0; i < src_len; i++)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1719 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1720 if (IS_VAR_START (src[i]))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1721 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1722 i++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1723
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1724 /* Three cases: '$VAR', '${VAR}', '$<anything-else>'. */
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1725 if (IS_VAR_CHAR (src[i]))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1726 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1727 /* $V: collect name constituents, then expand. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1728 size_t var_end = i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1729
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1730 do
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1731 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1732 var_end++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1733 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1734 while (IS_VAR_CHAR (src[var_end]));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1735
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1736 var_end--; /* had to go one past */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1737 expand (expansion, src.substr (i, var_end - i + 1));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1738 i = var_end;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1739
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1740 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1741 else if (IS_VAR_BEGIN_DELIMITER (src[i]))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1742 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1743 /* ${: scan ahead for matching delimiter, then expand. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1744 size_t var_end = ++i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1745
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20791
diff changeset
1746 while (var_end < src_len && ! IS_VAR_END_DELIMITER (src[var_end]))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1747 var_end++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1748
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1749 if (var_end == src_len)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1750 {
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1751 (*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
1752 ("Octave:pathsearch-syntax",
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1753 "%s: No matching } for ${", src.c_str ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1754 i = var_end - 1; /* will incr to eos at top of loop */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1755 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1756 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1757 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1758 expand (expansion, src.substr (i, var_end - i));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1759 i = var_end; /* will incr past } at top of loop*/
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1760 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1761 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1762 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1763 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1764 /* $<something-else>: error. */
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1765 (*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
1766 ("Octave:pathsearch-syntax",
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1767 "%s: Unrecognized variable construct '$%c'",
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1768 src.c_str (), src[i]);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1769
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1770 /* Just ignore those chars and keep going. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1771 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1772 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1773 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1774 expansion += src[i];
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1775 }
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1776
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1777 return expansion;
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1778 }