annotate liboctave/util/kpse.cc @ 21865:0469ae203a1d

more kpse.cc updates * kpse.cc (KPATHSEA, stat, EXPAND_DEFAULT): Delete unused macros. (kpse_db_search, kpse_hash, hash_lookup, elt_in_db): Delete unused functions. (hash_element_type, hash_table_type, kpse_format_info_type): Delete struct definitions. (READABLE): Implement using octave::sys::file_stat. Eliminate struct stat argument. (dir_p, dir_links): Implement using octave::sys::file_stat. (kpse_readable_file): Update. (kpse_absolute_p): Implement using octave::sys::env::absolute_pathname and octave::sys::env::rooted_relative_pathname. (path_search, search, path_find_first_of): Always search disk. (kpse_format_info, db, alias_db, db_dir_list): Delete unused static variables.
author John W. Eaton <jwe@octave.org>
date Fri, 10 Jun 2016 22:27:22 -0400
parents f3487b21e879
children 0cdfd6d230e6
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>
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
34 #include <string>
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
35
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
36 /* 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
37 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
38 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
39 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
40
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
41 /* 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
42 #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
43 #define DOSISH
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
44 #endif
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
45
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
46 extern "C" {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14155
diff changeset
47 #if defined (__MINGW32__)
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
48 #include <windows.h>
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
49 #include <fcntl.h>
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14155
diff changeset
50 #elif defined (WIN32)
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
51 #if ! defined (_MSC_VER)
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
52 #define __STDC__ 1
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
53 #include "win32lib.h"
6106
82fff8a063c2 [project @ 2006-10-26 21:52:14 by jwe]
jwe
parents: 5765
diff changeset
54 #endif
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
55 #endif /* not WIN32 */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
56 }
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
57
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
58 /* 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
59 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
60 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
61 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
62 cpp directory (i.e., kpathsea/) won't be searched. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
63
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
64 /* 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
65 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
66 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
67 #if ! defined (DOSISH)
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
68 #define ST_NLINK_TRICK
21864
f3487b21e879 * kpse.cc: Remove obsolete and unused code.
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
69 #endif /* not DOSISH */
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
70
11236
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
71 /* Define the characters which separate components of
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
72 filenames and environment variable paths. */
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
73
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
74 /* What separates filename components? */
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
75 #if ! defined (DIR_SEP)
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
76 #if defined (DOSISH)
11236
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
77 /* 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
78 go with that. */
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
79 #define DIR_SEP '/'
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
80 #define DIR_SEP_STRING "/"
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
81 #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
82 #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
83 /* On DOS, it's good to allow both \ and / between directories. */
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
84 #define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
85 #else
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
86 #define DIR_SEP '/'
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
87 #define DIR_SEP_STRING "/"
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
88 #endif /* not DOSISH */
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
89 #endif /* not DIR_SEP */
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
90
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
91 #if ! defined (IS_DIR_SEP)
11236
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
92 #define IS_DIR_SEP(ch) ((ch) == DIR_SEP)
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
93 #endif
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
94 #if ! defined (IS_DEVICE_SEP)
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
95 /* No 'devices' on, e.g., Unix. */
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11501
diff changeset
96 #define IS_DEVICE_SEP(ch) 0
11236
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
97 #endif
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
98 #if ! defined (NAME_BEGINS_WITH_DEVICE)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11501
diff changeset
99 #define NAME_BEGINS_WITH_DEVICE(name) 0
11236
6ccf1130f23c kpse cleanups
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
100 #endif
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
101
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
102 #include "file-stat.h"
4396
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
103 #include "lo-error.h"
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
104 #include "oct-env.h"
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
105 #include "oct-passwd.h"
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
106 #include "str-vec.h"
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
107
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
108 /* 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
109 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
110 NULL being defined multiple times. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
111 #include <cstdio>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
112 #include <cstdarg>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
113 #include <cstdlib>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
114 #include <cerrno>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
115 #include <cassert>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
116
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
117 #include <sys/types.h>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
118 #include <unistd.h>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
119
21863
a25110491607 eliminate obsolete sysdir.h header file
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
120 #include <dirent.h>
a25110491607 eliminate obsolete sysdir.h header file
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
121
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
122 /* define NAME_MAX, the maximum length of a single
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
123 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
124 depending on the filesystem. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
125
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
126 /* 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
127 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
128 #if ! defined (_POSIX_NAME_MAX)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
129 #define _POSIX_NAME_MAX 255
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
130 #endif
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
131
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
132 #if ! defined (NAME_MAX)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
133 #define NAME_MAX _POSIX_NAME_MAX
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
134 #endif
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
135
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
136 #include <cctype>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
137
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
138 /* 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
139 #if ! defined (ENV_SEP)
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
140 #if defined (SEPCHAR) && defined (SEPCHAR_STR)
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
141 #define ENV_SEP SEPCHAR
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
142 #define ENV_SEP_STRING SEPCHAR_STR
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
143 #elif defined (DOSISH)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
144 #define ENV_SEP ';'
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
145 #define ENV_SEP_STRING ";"
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
146 #else
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
147 #define ENV_SEP ':'
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
148 #define ENV_SEP_STRING ":"
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
149 #endif /* not DOS */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
150 #endif /* not ENV_SEP */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
151
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
152 #if ! defined (IS_ENV_SEP)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
153 #define IS_ENV_SEP(ch) ((ch) == ENV_SEP)
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
154 #endif
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
155
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
156 /* define PATH_MAX, the maximum length of a filename. Since no such
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
157 limit may exist, it's preferable to dynamically grow filenames as
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
158 needed. */
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 /* Cheat and define this as a manifest constant no matter what, instead
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
161 of using pathconf. I forget why we want to do this. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
162
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
163 #if ! defined (_POSIX_PATH_MAX)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
164 #define _POSIX_PATH_MAX 255
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
165 #endif
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
166
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
167 #if ! defined (PATH_MAX)
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
168 #if defined (MAXPATHLEN)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
169 #define PATH_MAX MAXPATHLEN
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
170 #else
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
171 #define PATH_MAX _POSIX_PATH_MAX
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
172 #endif
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
173 #endif /* not PATH_MAX */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
174
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
175 /* 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
176 #if ! defined (NO_DEBUG)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
177
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
178 /* OK, we'll have tracing support. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
179 #define KPSE_DEBUG
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
180
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
181 /* Test if a bit is on. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
182 #define KPSE_DEBUG_P(bit) (kpathsea_debug & (1 << (bit)))
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
183
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
184 #define KPSE_DEBUG_STAT 0 /* stat calls */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
185 #define KPSE_DEBUG_HASH 1 /* hash lookups */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
186 #define KPSE_DEBUG_FOPEN 2 /* fopen/fclose calls */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
187 #define KPSE_DEBUG_PATHS 3 /* search path initializations */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
188 #define KPSE_DEBUG_EXPAND 4 /* path element expansion */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
189 #define KPSE_DEBUG_SEARCH 5 /* searches */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
190 #define KPSE_DEBUG_VARS 6 /* variable values */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
191 #define KPSE_LAST_DEBUG KPSE_DEBUG_VARS
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
192
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
193 /* A printf for the debugging. */
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
194 #define DEBUGF_START() do { gnulib::fputs ("kdebug:", stderr)
12912
e116dd862879 use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
195 #define DEBUGF_END() gnulib::fflush (stderr); } while (0)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
196
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
197 #define DEBUGF(str) \
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
198 DEBUGF_START (); gnulib::fputs (str, stderr); DEBUGF_END ()
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
199 #define DEBUGF1(str, e1) \
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
200 DEBUGF_START (); gnulib::fprintf (stderr, str, e1); DEBUGF_END ()
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
201 #define DEBUGF2(str, e1, e2) \
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
202 DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2); DEBUGF_END ()
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
203 #define DEBUGF3(str, e1, e2, e3) \
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
204 DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2, e3); DEBUGF_END ()
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
205 #define DEBUGF4(str, e1, e2, e3, e4) \
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
206 DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2, e3, e4); DEBUGF_END ()
4385
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 #endif /* not NO_DEBUG */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
209
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
210 #if defined (KPSE_DEBUG)
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
211 static unsigned int kpathsea_debug = 0;
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
212 #endif
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
213
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20443
diff changeset
214 #if defined (WIN32) && ! defined (__MINGW32__)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
215
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
216 /* System description file for Windows NT. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
217
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
218 /*
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
219 * 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
220 * Define all the symbols that apply correctly.
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
221 */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
222
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
223 #if ! defined (DOSISH)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
224 #define DOSISH
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
225 #endif
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
226
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
227 #if ! defined (MAXPATHLEN)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
228 #define MAXPATHLEN _MAX_PATH
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
229 #endif
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
230
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
231 /* 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
232 defined (most of them anyway). */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
233
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
234 #define access _access
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
235 #define strdup _strdup
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
236
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
237 #define S_IFMT _S_IFMT
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
238 #define S_IFDIR _S_IFDIR
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
239
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
240 /* 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
241 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
242 always be included before windows.h. */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
243 #define _WINSOCKAPI_ 1
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
244
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
245 #include <windows.h>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
246
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
247 /* For proper declaration of environ. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
248 #include <io.h>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
249 #include <fcntl.h>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
250 #include <process.h>
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
251
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
252 /* ============================================================ */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
253
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
254 #endif /* WIN32 */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
255
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
256 /* Define common sorts of messages. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
257
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
258 /* 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
259 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
260 success (exit statuses are truncated to eight bits). */
4396
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
261 #define FATAL_PERROR(str) \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
262 do \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
263 { \
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
264 gnulib::fputs ("pathsearch: ", stderr); \
4396
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
265 perror (str); exit (EXIT_FAILURE); \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
266 } \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
267 while (0)
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
268
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
269 #define FATAL(str) \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
270 do \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
271 { \
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
272 gnulib::fputs ("pathsearch: fatal: ", stderr); \
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
273 gnulib::fputs (str, stderr); \
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
274 gnulib::fputs (".\n", stderr); \
4396
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
275 exit (1); \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
276 } \
452698dd6ed9 [project @ 2003-04-28 19:04:05 by jwe]
jwe
parents: 4395
diff changeset
277 while (0)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
278
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
279 #if ! defined (WIN32)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
280 static void xclosedir (DIR *d);
4386
112a509bd2e6 [project @ 2003-04-24 18:41:02 by jwe]
jwe
parents: 4385
diff changeset
281 #endif
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
282
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
283 /* It's a little bizarre to be using the same type for the list and the
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
284 elements of the list, but no reason not to in this case, I think --
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
285 we never need a NULL string in the middle of the list, and an extra
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
286 NULL/NULL element always at the end is inconsequential. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
287
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
288 struct str_llist_elt
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
289 {
11501
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 11236
diff changeset
290 str_llist_elt (void) : str (), moved (0), next (0) { }
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 11236
diff changeset
291
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 11236
diff changeset
292 ~str_llist_elt (void) { }
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 11236
diff changeset
293
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
294 std::string str;
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
295 int moved;
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
296 struct str_llist_elt *next;
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
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
299 typedef str_llist_elt str_llist_elt_type;
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
300 typedef str_llist_elt *str_llist_type;
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
301
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
302 #define STR_LLIST(sl) ((sl).str)
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
303 #define STR_LLIST_MOVED(sl) ((sl).moved)
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
304 #define STR_LLIST_NEXT(sl) ((sl).next)
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
305
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
306 static void str_llist_add (str_llist_type *l, const std::string& str);
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
307
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
308 static void str_llist_float (str_llist_type *l, str_llist_elt_type *mover);
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
309
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
310 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
311
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
312 static str_llist_type *kpse_element_dirs (const std::string& elt);
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
313
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
314 static std::string kpse_expand (const std::string& s);
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
315
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
316 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
317 const std::string& dflt);
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
318
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
319 #include <ctime> /* for 'time' */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
320
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
321 static bool
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
322 kpse_is_env_sep (char c)
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
323 {
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
324 return IS_ENV_SEP (c);
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
325 }
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
326
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
327 /* These routines just check the return status from standard library
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
328 routines and abort if an error happens. */
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
329
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
330 static FILE *
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
331 xfopen (const std::string& filename, const char *mode)
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
332 {
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
333 FILE *f;
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
334
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
335 assert (! filename.empty () && mode);
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
336
14153
06aa17228706 use gnulib::fopen
John W. Eaton <jwe@octave.org>
parents: 13718
diff changeset
337 f = gnulib::fopen (filename.c_str (), mode);
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
338
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
339 if (! f)
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
340 FATAL_PERROR (filename.c_str ());
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
341
14153
06aa17228706 use gnulib::fopen
John W. Eaton <jwe@octave.org>
parents: 13718
diff changeset
342 if (KPSE_DEBUG_P (KPSE_DEBUG_FOPEN))
06aa17228706 use gnulib::fopen
John W. Eaton <jwe@octave.org>
parents: 13718
diff changeset
343 DEBUGF3 ("fopen (%s, %s) => 0x%lx\n", filename.c_str (), mode,
16314
0723ea02dcdb use intptr_t instead of long
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
344 reinterpret_cast<intptr_t> (f));
14153
06aa17228706 use gnulib::fopen
John W. Eaton <jwe@octave.org>
parents: 13718
diff changeset
345
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
346 return f;
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
347 }
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
348
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
349 /* 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
350 time. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
351
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
352 class kpse_path_iterator
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
353 {
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
354 public:
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
355
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
356 kpse_path_iterator (const std::string& p)
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
357 : 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
358
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
359 kpse_path_iterator (const kpse_path_iterator& pi)
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
360 : 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
361
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
362 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
363 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
364 kpse_path_iterator retval (*this);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
365 next ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
366 return retval;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
367 }
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
368
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
369 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
370
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
371 bool operator != (const size_t sz) { return b != sz; }
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
372
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
373 private:
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
374
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
375 const std::string& path;
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
376 size_t b;
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
377 size_t e;
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
378 size_t len;
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
379
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
380 void set_end (void)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
381 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
382 e = b + 1;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
383
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
384 if (e == len)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
385 ; /* 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
386 else if (e > len)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
387 b = e = std::string::npos;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
388 else
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
389 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
390 /* 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
391 the path). */
20443
610c74748518 maint: Clean up code based on static analysis suggestions.
Rik <rik@octave.org>
parents: 20232
diff changeset
392 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
393 e++;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
394 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
395 }
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
396
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
397 void next (void)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
398 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
399 b = e + 1;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
400
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
401 /* Skip any consecutive colons. */
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
402 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
403 b++;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
404
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
405 if (b >= len)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
406 b = e = std::string::npos;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
407 else
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
408 set_end ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
409 }
5617
e92411b7eb21 [project @ 2006-02-13 17:21:31 by jwe]
jwe
parents: 5451
diff changeset
410
e92411b7eb21 [project @ 2006-02-13 17:21:31 by jwe]
jwe
parents: 5451
diff changeset
411 // No assignment.
e92411b7eb21 [project @ 2006-02-13 17:21:31 by jwe]
jwe
parents: 5451
diff changeset
412 kpse_path_iterator& operator = (const kpse_path_iterator&);
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
413 };
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
414
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
415 /* Here's the simple one, when a program just wants a value. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
416
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
417 static std::string
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
418 kpse_var_value (const std::string& var)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
419 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
420 std::string ret;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
421
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21729
diff changeset
422 std::string tmp = octave::sys::env::getenv (var);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
423
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
424 if (! tmp.empty ())
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
425 ret = kpse_var_expand (tmp);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
426
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
427 #if defined (KPSE_DEBUG)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
428 if (KPSE_DEBUG_P (KPSE_DEBUG_VARS))
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
429 DEBUGF2 ("variable: %s = %s\n", var.c_str (),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
430 tmp.empty () ? "(nil)" : tmp.c_str ());
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
431 #endif
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
432
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
433 return ret;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
434 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
435
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
436 /* 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
437 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
438
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
439 static std::string
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
440 kpse_truncate_filename (const std::string& name)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
441 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
442 unsigned c_len = 0; /* Length of current component. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
443 unsigned ret_len = 0; /* Length of constructed result. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
444
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
445 std::string ret = name;
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
446
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
447 size_t len = name.length ();
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
448
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
449 for (size_t i = 0; i < len; i++)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
450 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
451 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
452 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
453 /* At a directory delimiter, reset component length. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
454 c_len = 0;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
455 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
456 else if (c_len > NAME_MAX)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
457 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
458 /* 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
459 continue;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
460 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
461
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
462 /* Copy this character. */
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
463 ret[ret_len++] = name[i];
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
464 c_len++;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
465 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
466
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
467 ret.resize (ret_len);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
468
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
469 return ret;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
470 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
471
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
472 /* 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
473 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
474 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
475 kinds of devices. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
476
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
477 #if defined (WIN32)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
478 static inline bool
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
479 READABLE (const std::string& fn)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
480 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
481 const char *t = fn.c_str ();
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
482 return (GetFileAttributes (t) != 0xFFFFFFFF
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
483 && ! (GetFileAttributes (t) & FILE_ATTRIBUTE_DIRECTORY));
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 #else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
486 static inline bool
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
487 READABLE (const std::string& fn)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
488 {
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
489 bool retval = false;
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
490
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
491 const char *t = fn.c_str ();
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
492
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
493 if (access (t, R_OK) == 0)
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
494 {
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
495 octave::sys::file_stat fs (fn);
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
496
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
497 retval = fs && ! fs.is_dir ();
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
498 }
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
499
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
500 return retval;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
501 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
502 #endif
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
503
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
504 /* POSIX invented the brain-damage of not necessarily truncating
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
505 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
506 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
507
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
508 Generic const return warning. See extend-fname.c. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
509
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
510 static std::string
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
511 kpse_readable_file (const std::string& name)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
512 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
513 std::string ret;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
514
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
515 if (READABLE (name))
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
516 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
517 ret = name;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
518
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
519 #if defined (ENAMETOOLONG)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
520 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
521 else if (errno == ENAMETOOLONG)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
522 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
523 ret = kpse_truncate_filename (name);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
524
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
525 /* 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
526 so let's call access again. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
527
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
528 if (! READABLE (ret))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
529 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
530 /* Failed. */
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20955
diff changeset
531 ret = "";
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
532 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
533 #endif /* ENAMETOOLONG */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
534
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
535 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
536 else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
537 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
538 /* Some other error. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
539 if (errno == EACCES)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
540 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
541 /* Maybe warn them if permissions are bad. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
542 perror (name.c_str ());
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
543 }
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
544
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20955
diff changeset
545 ret = "";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
546 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
547
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
548 return ret;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
549 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
550
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
551 static bool
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
552 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
553 {
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
554 return (octave::sys::env::absolute_pathname (filename)
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
555 || (relative_ok
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
556 && octave::sys::env::rooted_relative_pathname (filename)));
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
557 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
558
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
559 /* 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
560 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
561 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
562 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
563 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
564 configuration files. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
565 static bool first_search = true;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
566
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
567 /* This function is called after every search (except the first, since
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
568 we definitely want to allow enabling the logging in texmf.cnf) to
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
569 record the filename(s) found in $TEXMFLOG. */
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 static void
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
572 log_search (const string_vector& filenames)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
573 {
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
574 static FILE *log_file = 0;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
575 static bool first_time = true; /* Need to open the log file? */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
576
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
577 if (first_time)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
578 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
579 first_time = false;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
580
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
581 /* Get name from either envvar or config file. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
582 std::string log_name = kpse_var_value ("TEXMFLOG");
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
583
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
584 if (! log_name.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
585 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
586 log_file = xfopen (log_name.c_str (), "a");
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
587
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
588 if (! log_file)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
589 perror (log_name.c_str ());
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
590 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
591 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
592
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
593 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH) || log_file)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
594 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
595 /* FILENAMES should never be null, but safety doesn't hurt. */
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20017
diff changeset
596 for (int e = 0; e < filenames.numel () && ! filenames[e].empty (); e++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
597 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
598 std::string filename = filenames[e];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
599
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
600 /* Only record absolute filenames, for privacy. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
601 if (log_file && kpse_absolute_p (filename.c_str (), false))
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
602 gnulib::fprintf (log_file, "%lu %s\n",
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
603 static_cast<unsigned long> (time (0)),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
604 filename.c_str ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
605
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
606 /* And show them online, if debugging. We've already started
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
607 the debugging line in 'search', where this is called, so
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
608 just print the filename here, don't use DEBUGF. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
609 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
610 gnulib::fputs (filename.c_str (), stderr);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
611 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
612 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
613 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
614
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
615 /* 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
616 /, 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
617 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
618 none, return a list containing just NULL.
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
619
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
620 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
621 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
622 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
623 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
624
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
625 static string_vector
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
626 dir_list_search (str_llist_type *dirs, const std::string& name,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
627 bool search_all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
628 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
629 str_llist_elt_type *elt;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
630 string_vector ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
631
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
632 for (elt = *dirs; elt; elt = STR_LLIST_NEXT (*elt))
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
633 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
634 const std::string dir = STR_LLIST (*elt);
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
635
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
636 std::string potential = dir + name;
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
637
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
638 std::string tmp = kpse_readable_file (potential);
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
639
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
640 if (! tmp.empty ())
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
641 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
642 ret.append (potential);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
643
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
644 /* Move this element towards the top of the list. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
645 str_llist_float (dirs, elt);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
646
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
647 if (! search_all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
648 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
649 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
650 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
651
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
652 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
653 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
654
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
655 /* 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
656 readable, return (a list containing) it; otherwise, return NULL. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
657
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
658 static string_vector
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
659 absolute_search (const std::string& name)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
660 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
661 string_vector ret_list;
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
662 std::string found = kpse_readable_file (name);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
663
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
664 /* 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
665 the caller we didn't find anything. */
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
666 ret_list.append (found);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
667
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
668 return ret_list;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
669 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
670
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
671 /* 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
672 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
673
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
674 static string_vector
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
675 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
676 bool /* must_exist */, bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
677 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
678 string_vector ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
679 bool done = false;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
680
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
681 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
682 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
683 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
684
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
685 string_vector found;
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
686
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
687 /* Do not touch the device if present */
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
688 if (NAME_BEGINS_WITH_DEVICE (elt))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
689 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
690 while (elt.length () > 3
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
691 && 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
692 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
693 elt[2] = elt[1];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
694 elt[1] = elt[0];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
695 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
696 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
697 }
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
698 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
699 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
700 /* We never want to search the whole disk. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
701 while (elt.length () > 1
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
702 && 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
703 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
704 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
705
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
706 /* Try ls-R, unless we're searching for texmf.cnf. Our caller
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
707 (search), also tests first_search, and does the resetting. */
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
708 if (first_search)
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
709 found = string_vector ();
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
710
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
711 /* Search the filesystem. */
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
712
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
713 if (found.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
714 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
715 str_llist_type *dirs = kpse_element_dirs (elt);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
716
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
717 if (dirs && *dirs)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
718 found = dir_list_search (dirs, name, all);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
719 }
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
720
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
721 /* Did we find anything anywhere? */
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
722 if (! found.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
723 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
724 if (all)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
725 ret_list.append (found);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
726 else
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 ret_list.append (found[0]);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
729 done = true;
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 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
732 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
733
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
734 return ret_list;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
735 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
736
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
737 /* 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
738 absolute_p, check ORIGINAL_NAME itself. Otherwise, look at each
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
739 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
740
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
741 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
742 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
743 terminated with NULL. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
744
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
745 static string_vector
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
746 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
747 bool must_exist, bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
748 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
749 string_vector ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
750 bool absolute_p;
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 /* 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
753 std::string name = kpse_expand (original_name);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
754
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
755 /* 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
756 consider PATH at all. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
757 absolute_p = kpse_absolute_p (name, true);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
758
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
759 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
760 DEBUGF4 ("start search (file=%s, must_exist=%d, find_all=%d, path=%s).\n",
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
761 name.c_str (), must_exist, all, path.c_str ());
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
762
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
763 /* Find the file(s). */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
764 ret_list = absolute_p ? absolute_search (name)
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
765 : path_search (path, name, must_exist, all);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
766
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
767 /* 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
768 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
769 if (first_search)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
770 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
771 first_search = false;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
772 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
773 else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
774 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
775 /* 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
776 debugging line if we're doing that. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
777
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
778 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
779 DEBUGF1 ("search (%s) =>", original_name.c_str ());
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
780
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
781 log_search (ret_list);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
782
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
783 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
784 gnulib::putc ('\n', stderr);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
785 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
786
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
787 return ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
788 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
789
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
790 /* Search PATH for the first NAME. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
791
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
792 /* 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
793 explicitly relative filename, check whether it is a readable
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
794 (regular) file.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11501
diff changeset
795
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
796 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
797 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
798
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
799 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
800 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
801
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
802 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
803
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
804 static std::string
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
805 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
806 bool must_exist)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
807 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
808 string_vector ret_list = search (path, name, must_exist, false);
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
809
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20955
diff changeset
810 return ret_list.empty () ? "" : ret_list[0];
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
811 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
812
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
813 /* 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
814 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
815
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
816 /* 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
817 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
818
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
819 static string_vector
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
820 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
821 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
822 return search (path, name, true, true);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
823 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
824
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
825 /* 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
826 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
827 Otherwise, search all elements of PATH. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
828
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
829 static string_vector
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
830 path_find_first_of (const std::string& path, const string_vector& names,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
831 bool /* must_exist */, bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
832 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
833 string_vector ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
834 bool done = false;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
835
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
836 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
837 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
838 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
839
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
840 str_llist_type *dirs;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
841 str_llist_elt_type *dirs_elt;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
842 string_vector found;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
843
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
844 /* Do not touch the device if present */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
845
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
846 if (NAME_BEGINS_WITH_DEVICE (elt))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
847 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
848 while (elt.length () > 3
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
849 && 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
850 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
851 elt[2] = elt[1];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
852 elt[1] = elt[0];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
853 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
854 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
855 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
856 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
857 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
858 /* We never want to search the whole disk. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
859 while (elt.length () > 1
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
860 && 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
861 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
862 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
863
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
864 /* We have to search one directory at a time. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
865 dirs = kpse_element_dirs (elt);
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
866 for (dirs_elt = *dirs; dirs_elt; dirs_elt = STR_LLIST_NEXT (*dirs_elt))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
867 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
868 const std::string dir = STR_LLIST (*dirs_elt);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
869
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20017
diff changeset
870 int len = names.numel ();
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20791
diff changeset
871 for (int i = 0; i < len && ! done; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
872 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
873 std::string name = names[i];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
874
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
875 /* Try ls-R, unless we're searching for texmf.cnf. Our caller
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
876 (find_first_of), also tests first_search, and does the
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
877 resetting. */
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
878 if (first_search)
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
879 found = string_vector ();
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
880
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
881 /* Search the filesystem. */
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
882
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
883 if (found.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
884 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
885 static str_llist_type *tmp = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
886
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
887 if (! tmp)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
888 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
889 tmp = new str_llist_type;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
890 *tmp = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
891 str_llist_add (tmp, "");
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
892 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
893
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
894 STR_LLIST (*(*tmp)) = dir;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
895
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
896 found = dir_list_search (tmp, name, all);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
897 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
898
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
899 /* Did we find anything anywhere? */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
900 if (! found.empty ())
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
901 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
902 if (all)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
903 ret_list.append (found);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
904 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
905 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
906 ret_list.append (found[0]);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
907 done = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
908 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
909 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
910 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
911 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
912 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
913
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
914 return ret_list;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
915 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
916
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
917 static string_vector
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
918 find_first_of (const std::string& path, const string_vector& names,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
919 bool must_exist, bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
920 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
921 string_vector ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
922
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
923 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
924 {
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
925 gnulib::fputs ("start find_first_of ((", stderr);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
926
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20017
diff changeset
927 int len = names.numel ();
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
928
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
929 for (int i = 0; i < len; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
930 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
931 if (i == 0)
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
932 gnulib::fputs (names[i].c_str (), stderr);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
933 else
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
934 gnulib::fprintf (stderr, ", %s", names[i].c_str ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
935 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
936
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
937 gnulib::fprintf (stderr, "), path=%s, must_exist=%d).\n",
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
938 path.c_str (), must_exist);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
939 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
940
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20017
diff changeset
941 for (int i = 0; i < names.numel (); i++)
4409
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
942 {
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
943 std::string name = names[i];
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
944
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
945 if (kpse_absolute_p (name, true))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
946 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
947 /* 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
948 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
949 are done. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
950
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
951 ret_list = absolute_search (name);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
952
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
953 if (! ret_list.empty ())
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
954 return ret_list;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
955 }
4409
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
956 }
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
957
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
958 /* Find the file. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
959 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
960
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
961 /* 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
962 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
963 if (first_search)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
964 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
965 first_search = false;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
966 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
967 else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
968 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
969 /* 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
970 debugging line if we're doing that. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
971
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
972 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
973 {
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
974 gnulib::fputs ("find_first_of (", stderr);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
975
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20017
diff changeset
976 int len = names.numel ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
977
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
978 for (int i = 0; i < len; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
979 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
980 if (i == 0)
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
981 gnulib::fputs (names[i].c_str (), stderr);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
982 else
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
983 gnulib::fprintf (stderr, ", %s", names[i].c_str ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
984 }
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
985
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
986 gnulib::fputs (") =>", stderr);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
987 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
988
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
989 log_search (ret_list);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
990
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
991 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
992 gnulib::putc ('\n', stderr);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
993 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
994
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
995 return ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
996 }
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 /* 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
999 first one found. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1000
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1001 /* 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
1002 Return the first one found. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1003
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1004 static std::string
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1005 kpse_path_find_first_of (const std::string& path, const string_vector& names,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1006 bool must_exist)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1007 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1008 string_vector ret_list = find_first_of (path, names, must_exist, false);
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1009
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20955
diff changeset
1010 return ret_list.empty () ? "" : ret_list[0];
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1011 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1012
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1013 /* 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
1014 list containing everything found, in the order found. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1015
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1016 /* 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
1017 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
1018 first. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1019
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1020 static string_vector
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1021 kpse_all_path_find_first_of (const std::string& path,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1022 const string_vector& names)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1023 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1024 return find_first_of (path, names, true, true);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1025 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1026
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1027 /* General expansion. Some of this file (the brace-expansion
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1028 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
1029 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
1030 couple of functions) is covered by the LGPL. */
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 /* 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
1033 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
1034 <pwd.h>, just return NAME. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1035
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1036 static std::string
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1037 kpse_tilde_expand (const std::string& name)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1038 {
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1039 std::string expansion;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1040
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1041 /* If no leading tilde, do nothing. */
5137
5ee7da8b8a4b [project @ 2005-02-09 17:59:19 by jwe]
jwe
parents: 5085
diff changeset
1042 if (name.empty () || name[0] != '~')
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1043 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1044 expansion = name;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1045
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1046 /* 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
1047 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
1048 ... */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1049 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1050 else if (name.length () == 1)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1051 {
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21729
diff changeset
1052 expansion = octave::sys::env::get_home_directory ();
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1053
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1054 if (expansion.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1055 expansion = ".";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1056
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1057 /* 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
1058 Should really check for doubled intermediate slashes, too. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1059 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1060 else if (IS_DIR_SEP (name[1]))
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1061 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1062 unsigned c = 1;
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21729
diff changeset
1063 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
1064
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1065 if (home.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1066 home = ".";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1067
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1068 size_t home_len = home.length ();
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1069
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1070 /* handle leading // */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1071 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
1072 home = home.substr (1);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1073
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1074 /* omit / after ~ */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1075 if (IS_DIR_SEP (home[home_len - 1]))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1076 c++;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1077
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1078 expansion = home + name.substr (c);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1079
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1080 /* 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
1081 OS/2 doesn't have this concept. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1082 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1083 else
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1084 #if defined (HAVE_PWD_H)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1085 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1086 unsigned c = 2;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1087
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1088 /* find user name */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1089 while (name.length () > c && ! IS_DIR_SEP (name[c]))
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1090 c++;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1091
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1092 std::string user = name.substr (1, c-1);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1093
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1094 /* 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
1095 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
1096 octave::sys::password p = octave::sys::password::getpwnam (user);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1097
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1098 /* If no such user, just use '.'. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1099 std::string home = p ? p.dir () : std::string (".");
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1100
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1101 if (home.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1102 home = ".";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1103
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1104 /* handle leading // */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1105 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
1106 home = home.substr (1);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1107
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1108 /* If HOME ends in /, omit the / after ~user. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1109 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
1110 c++;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1111
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1112 expansion = name.length () > c ? home : home + name.substr (c);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1113 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1114 #else /* not HAVE_PWD_H */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1115 expansion = name;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1116 #endif /* not HAVE_PWD_H */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1117
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1118 return expansion;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1119 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1120
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1121 /* 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
1122 shells do.) */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1123
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1124 /* 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
1125 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
1126
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1127 static std::string
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1128 kpse_expand (const std::string& s)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1129 {
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1130 std::string var_expansion = kpse_var_expand (s);
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1131 return kpse_tilde_expand (var_expansion);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1132 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1133
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1134 /* Forward declarations of functions from the original expand.c */
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1135 static string_vector brace_expand (const std::string&);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1136
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1137 /* 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
1138 path components. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1139
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1140 static std::string
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1141 kpse_expand_kpse_dot (const std::string& path)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1142 {
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1143 std::string ret;
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21729
diff changeset
1144 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
1145
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1146 if (kpse_dot.empty ())
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1147 return path;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1148
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
1149 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
1150 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1151 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1152
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1153 /* We assume that the !! magic is only used on absolute components.
21562
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 21340
diff changeset
1154 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
1155
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1156 size_t elt_len = elt.length ();
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1157
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1158 if (kpse_absolute_p (elt, false)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1159 || (elt_len > 1 && elt[0] == '!' && elt[1] == '!'))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1160 ret += elt + ENV_SEP_STRING;
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1161 else if (elt_len == 1 && elt[0] == '.')
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1162 ret += kpse_dot + ENV_SEP_STRING;
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1163 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
1164 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
1165 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1166 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
1167 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1168
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1169 int len = ret.length ();
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1170 if (len > 0)
4395
cc6d369355ec [project @ 2003-04-28 18:14:56 by jwe]
jwe
parents: 4394
diff changeset
1171 ret.resize (len-1);
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1172
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1173 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1174 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1175
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1176 /* 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
1177 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
1178 variable definition contained braces (e.g., $TEXMF). Return a
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1179 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
1180
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1181 static std::string
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1182 kpse_brace_expand_element (const std::string& elt)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1183 {
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1184 std::string ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1185
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1186 string_vector expansions = brace_expand (elt);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1187
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20017
diff changeset
1188 for (int i = 0; i < expansions.numel (); i++)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1189 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1190 /* Do $ and ~ expansion on each element. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1191 std::string x = kpse_expand (expansions[i]);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1192
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1193 if (x != expansions[i])
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1194 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1195 /* 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
1196 recursive variable definitions are not allowed, this recursion
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1197 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
1198 more than one level of recursion.) */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1199 x = kpse_brace_expand_element (x);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1200 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1201
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1202 ret += x + ENV_SEP_STRING;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1203 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1204
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1205 ret.resize (ret.length () - 1);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1206
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1207 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1208 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1209
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1210 /* 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
1211 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
1212 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
1213 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
1214 'kpse_init_format'. */
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1215
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1216 static std::string
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1217 kpse_brace_expand (const std::string& path)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1218 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1219 /* Must do variable expansion first because if we have
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1220 foo = .:~
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1221 TEXINPUTS = $foo
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1222 we want to end up with TEXINPUTS = .:/home/karl.
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1223 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
1224 the path elements before we start the loop. */
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1225 std::string tmp = kpse_var_expand (path);
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1226
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1227 std::string ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1228
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
1229 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
1230 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1231 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1232
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1233 /* 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
1234 std::string expansion = kpse_brace_expand_element (elt);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1235 ret += expansion + ENV_SEP_STRING;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1236 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1237
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1238 size_t len = ret.length ();
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1239 if (len > 0)
4395
cc6d369355ec [project @ 2003-04-28 18:14:56 by jwe]
jwe
parents: 4394
diff changeset
1240 ret.resize (len-1);
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1241
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1242 return kpse_expand_kpse_dot (ret);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1243 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1244
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1245 /* 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
1246 existing directories in the result. */
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1247
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1248 /* 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
1249 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
1250 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
1251 the pattern. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1252
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1253 static std::string
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1254 kpse_path_expand (const std::string& path)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1255 {
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1256 std::string ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1257 unsigned len;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1258
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1259 len = 0;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1260
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1261 /* Expand variables and braces first. */
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1262 std::string tmp = kpse_brace_expand (path);
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1263
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1264 /* 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
1265 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
1266 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1267 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1268
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1269 str_llist_type *dirs;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1270
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1271 /* Skip and ignore magic leading chars. */
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1272 if (elt.length () > 1 && elt[0] == '!' && elt[1] == '!')
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1273 elt = elt.substr (2);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1274
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1275 /* Do not touch the device if present */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1276 if (NAME_BEGINS_WITH_DEVICE (elt))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1277 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1278 while (elt.length () > 3
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1279 && 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
1280 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1281 elt[2] = elt[1];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1282 elt[1] = elt[0];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1283 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1284 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1285 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1286 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1287 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1288 /* We never want to search the whole disk. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1289 while (elt.length () > 1
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1290 && 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
1291 elt = elt.substr (1);
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
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1294 /* 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
1295 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
1296 dirs = kpse_element_dirs (elt);
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1297
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1298 if (dirs && *dirs)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1299 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1300 str_llist_elt_type *dir;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1301
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1302 for (dir = *dirs; dir; dir = STR_LLIST_NEXT (*dir))
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 const std::string thedir = STR_LLIST (*dir);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1305 unsigned dirlen = thedir.length ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1306
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1307 ret += thedir;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1308 len += dirlen;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1309
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1310 /* Retain trailing slash if that's the root directory. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1311 if (dirlen == 1
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1312 || (dirlen == 3 && NAME_BEGINS_WITH_DEVICE (thedir)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1313 && IS_DIR_SEP (thedir[2])))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1314 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1315 ret += ENV_SEP_STRING;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1316 len++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1317 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1318
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1319 ret[len-1] = ENV_SEP;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1320 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1321 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1322 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1323
4395
cc6d369355ec [project @ 2003-04-28 18:14:56 by jwe]
jwe
parents: 4394
diff changeset
1324 if (len > 0)
cc6d369355ec [project @ 2003-04-28 18:14:56 by jwe]
jwe
parents: 4394
diff changeset
1325 ret.resize (len-1);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1326
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1327 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1328 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1329
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
1330 /* 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
1331 bash 1.14.5. [And subsequently modified for kpatshea.]
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
1332
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
1333 Copyright (C) 1987,1991 Free Software Foundation, Inc. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1334
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1335 #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
1336
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1337 /* Basic idea:
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1338
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1339 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
1340 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
1341 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
1342 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
1343 the result so far. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1344
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1345 /* 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
1346 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
1347 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
1348 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
1349 is returned. */
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1350
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1351 static string_vector
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1352 array_concat (const string_vector& arr1, const string_vector& arr2)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1353 {
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1354 string_vector result;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1355
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1356 if (arr1.empty ())
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1357 result = arr2;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1358 else if (arr2.empty ())
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1359 result = arr1;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1360 else
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1361 {
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20017
diff changeset
1362 int len1 = arr1.numel ();
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20017
diff changeset
1363 int len2 = arr2.numel ();
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1364
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1365 result = string_vector (len1 * len2);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1366
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1367 int k = 0;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1368 for (int i = 0; i < len2; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1369 for (int j = 0; j < len1; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1370 result[k++] = arr1[j] + arr2[i];
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1371 }
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1372
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1373 return result;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1374 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1375
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1376 static int brace_gobbler (const std::string&, int&, int);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1377 static string_vector expand_amble (const std::string&);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1379 /* Return an array of strings; the brace expansion of TEXT. */
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1380 static string_vector
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1381 brace_expand (const std::string& text)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1382 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1383 /* Find the text of the preamble. */
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1384 int i = 0;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1385 int c = brace_gobbler (text, i, '{');
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1386
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1387 std::string preamble = text.substr (0, i);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1388
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1389 string_vector result = string_vector (preamble);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1390
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1391 if (c == '{')
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1392 {
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1393 /* 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
1394 int start = ++i;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1395 c = brace_gobbler (text, i, '}');
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1396
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1397 /* What if there isn't a matching close brace? */
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1398 if (! c)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1399 {
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1400 (*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
1401 ("Octave:pathsearch-syntax",
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1402 "%s: Unmatched {", text.c_str ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1403
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1404 result = string_vector (text);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1405 }
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1406 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1407 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1408 std::string amble = text.substr (start, i-start);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1409 result = array_concat (result, expand_amble (amble));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1410
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1411 std::string postamble = text.substr (i+1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1412 result = array_concat (result, brace_expand (postamble));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1413 }
4378
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
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1416 return result;
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
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1419 /* The character which is used to separate arguments. */
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1420 static int brace_arg_separator = ',';
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1421
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1422 /* 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
1423 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
1424 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
1425 need it. */
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1426 static string_vector
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1427 expand_amble (const std::string& text)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1428 {
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1429 string_vector result;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1430
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1431 size_t text_len = text.length ();
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1432 size_t start;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1433 int i, c;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1434
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1435 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
1436 {
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1437 int i0 = i;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1438 int c0 = brace_gobbler (text, i0, brace_arg_separator);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1439 int i1 = i;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1440 int c1 = brace_gobbler (text, i1, ENV_SEP);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1441 c = c0 | c1;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1442 i = (i0 < i1 ? i0 : i1);
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1443
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1444 std::string tem = text.substr (start, i-start);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1445
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1446 string_vector partial = brace_expand (tem);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1447
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1448 if (result.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1449 result = partial;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1450 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1451 result.append (partial);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1452 }
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1453
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1454 return result;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1455 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1456
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
1457 /* 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
1458 index of the character matching SATISFY. This understands about
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1459 quoting. Return the character that caused us to stop searching;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1460 this is either the same as SATISFY, or 0. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1461 static int
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1462 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
1463 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
1464 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
1465 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
1466 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
1467 int pass_next = 0;
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1468
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1469 size_t text_len = text.length ();
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1470
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1471 size_t i = indx;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1472
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1473 for (; i < text_len; i++)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1474 {
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1475 c = text[i];
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1476
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1477 if (pass_next)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1478 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1479 pass_next = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1480 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1481 }
4378
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 /* 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
1484 escape the quote character in a double-quoted string. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1485 if (c == '\\' && (quoted == 0 || quoted == '"' || quoted == '`'))
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1486 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1487 pass_next = 1;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1488 continue;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1489 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1490
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1491 if (quoted)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1492 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1493 if (c == quoted)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1494 quoted = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1495 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1496 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1497
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1498 if (c == '"' || c == '\'' || c == '`')
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1499 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1500 quoted = c;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1501 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1502 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1503
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20791
diff changeset
1504 if (c == satisfy && ! level && ! quoted)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1505 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1506 /* 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
1507 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
1508 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
1509 if (c == '{'
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1510 && ((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
1511 && (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
1512 && (brace_whitespace (text[i+1]) || text[i+1] == '}'))))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1513 continue;
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1514 /* 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
1515 in a '${ }' construct */
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1516 if ((c != '{') || i == 0 || (text[i-1] != '$'))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1517 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1518 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1519
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1520 if (c == '{')
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1521 level++;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1522 else if (c == '}' && level)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1523 level--;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1524 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1525
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1526 indx = i;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1527 return c;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1528 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1529
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1530 /* 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
1531 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
1532 $ and ~ expansion have already been done. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1533
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1534 static bool
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1535 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
1536 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1537 const char *filename = filename_arg.c_str ();
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1538 const char *path_elt = path_elt_arg.c_str ();
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1539
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1540 const char *original_filename = filename;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1541 bool matched = false;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1542
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1543 for (; *filename && *path_elt; filename++, path_elt++)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1544 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1545 if (*filename == *path_elt) /* normal character match */
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1546 ;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1547
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1548 else if (IS_DIR_SEP (*path_elt) /* at // */
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1549 && original_filename < filename && IS_DIR_SEP (path_elt[-1]))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1550 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1551 while (IS_DIR_SEP (*path_elt))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1552 path_elt++; /* get past second and any subsequent /'s */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1553
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1554 if (*path_elt == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1555 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
1556 /* Trailing //, matches anything. We could make this
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1557 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
1558 the extra work. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1559 matched = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1560 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1561 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1562 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1563 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1564 /* 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
1565 for (; ! matched && *filename; filename++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1566 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1567 /* Try matching at each possible character. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1568 if (IS_DIR_SEP (filename[-1]) && *filename == *path_elt)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1569 matched = match (filename, path_elt);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1570 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1571
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1572 /* Prevent filename++ when *filename='\0'. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1573 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1574 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1575 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1576 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1577 /* normal character nonmatch, quit */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1578 break;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1579 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1580
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1581 /* 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
1582 component of FILENAME, we've matched. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1583 if (! matched && *path_elt == 0)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1584 {
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1585 /* 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
1586 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
1587 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
1588 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
1589 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
1590 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
1591 are no more dir separators. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1592
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1593 if (IS_DIR_SEP (*filename))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1594 filename++;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1595
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20791
diff changeset
1596 while (*filename && ! IS_DIR_SEP (*filename))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1597 filename++;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1598
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1599 matched = *filename == 0;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1600 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1601
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1602 return matched;
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
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1605 /* Expand extra colons. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1606
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1607 /* Check for leading colon first, then trailing, then doubled, since
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1608 that is fastest. Usually it will be leading or trailing. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1609
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1610 /* 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
1611 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
1612 DFLT may not be NULL. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1613
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1614 static std::string
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1615 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
1616 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1617 std::string expansion;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1618
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1619 size_t path_len = path.length ();
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1620
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1621 if (path_len == 0)
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1622 expansion = fallback;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1623
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1624 /* Solitary or leading :? */
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1625 else if (IS_ENV_SEP (path[0]))
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1626 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1627 expansion = path_len == 1 ? fallback : fallback + path;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1628 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1629
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1630 /* 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
1631 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
1632 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
1633 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
1634 such great length). */
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1635 else if (IS_ENV_SEP (path[path_len-1]))
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1636 expansion = path + fallback;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1637
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1638 /* OK, not leading or trailing. Check for doubled. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1639 else
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1640 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1641 /* What we'll return if we find none. */
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1642 expansion = path;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1643
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1644 for (size_t i = 0; i < path_len; i++)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1645 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1646 if (i + 1 < path_len
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1647 && 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
1648 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1649 /* We have a doubled colon. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1650
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1651 /* Copy stuff up to and including the first colon. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1652 /* 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
1653 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
1654
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1655 break;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1656 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1657 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1658 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1659
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1660 return expansion;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1661 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1662
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1663 /* 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
1664
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1665 /* 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
1666 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
1667 the last routine in the file. */
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1668
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1669 /* 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
1670 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
1671
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1672 static void
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1673 dir_list_add (str_llist_type *l, const std::string& dir)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1674 {
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1675 char last_char = dir[dir.length () - 1];
4407
16e8acbd19d5 [project @ 2003-05-05 19:00:56 by jwe]
jwe
parents: 4399
diff changeset
1676
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1677 std::string saved_dir = dir;
4407
16e8acbd19d5 [project @ 2003-05-05 19:00:56 by jwe]
jwe
parents: 4399
diff changeset
1678
16e8acbd19d5 [project @ 2003-05-05 19:00:56 by jwe]
jwe
parents: 4399
diff changeset
1679 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
1680 saved_dir += DIR_SEP_STRING;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1681
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1682 str_llist_add (l, saved_dir);
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1683 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1684
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1685 /* 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
1686 false if not. */
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1687
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1688 static bool
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1689 dir_p (const std::string& fn)
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1690 {
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1691 octave::sys::file_stat fs (fn);
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1692
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1693 return (fs && fs.is_dir ());
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1694 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1695
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1696 /* 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
1697
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1698 static void
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1699 checked_dir_list_add (str_llist_type *l, const std::string& dir)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1700 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1701 if (dir_p (dir))
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1702 dir_list_add (l, dir);
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1703 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1704
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1705 /* The cache. Typically, several paths have the same element; for
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1706 example, /usr/local/lib/texmf/fonts//. We don't want to compute the
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1707 expansion of such a thing more than once. Even though we also cache
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1708 the dir_links call, that's not enough -- without this path element
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1709 caching as well, the execution time doubles. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1710
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1711 struct cache_entry
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1712 {
11501
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 11236
diff changeset
1713 cache_entry (void) : key (), value (0) { }
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 11236
diff changeset
1714
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 11236
diff changeset
1715 ~cache_entry (void) { }
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 11236
diff changeset
1716
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1717 std::string key;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1718 str_llist_type *value;
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1719 };
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1720
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1721 static cache_entry *the_cache = 0;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1722 static unsigned cache_length = 0;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1723
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1724 /* 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
1725 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
1726 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
1727 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
1728 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
1729
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1730 static void
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1731 cache (const std::string key, str_llist_type *value)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1732 {
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1733 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
1734
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1735 for (unsigned i = 0; i < cache_length; i++)
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1736 {
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1737 new_cache[i].key = the_cache[i].key;
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1738 new_cache[i].value = the_cache[i].value;
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1739 }
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1740
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1741 delete [] the_cache;
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1742
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1743 the_cache = new_cache;
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1744
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1745 the_cache[cache_length].key = key;
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1746 the_cache[cache_length].value = value;
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1747
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1748 cache_length++;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1749 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1750
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1751 /* To retrieve, just check the list in order. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1752
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1753 static str_llist_type *
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1754 cached (const std::string& key)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1755 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1756 unsigned p;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1757
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1758 for (p = 0; p < cache_length; p++)
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1759 {
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1760 if (key == the_cache[p].key)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1761 return the_cache[p].value;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1762 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1763
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1764 return 0;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1765 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1766
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1767 #if defined (WIN32)
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1768
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1769 /* 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
1770 static std::string dirname;
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1771
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1772 #else /* WIN32 */
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1773
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1774 /* Return -1 if FN isn't a directory, else its number of links.
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1775 Duplicate the call to stat; no need to incur overhead of a function
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1776 call for that little bit of cleanliness. */
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1777
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1778 static int
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1779 dir_links (const std::string& fn)
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1780 {
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1781 int retval;
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1782
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1783 octave::sys::file_stat fs (fn);
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1784
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1785 retval = fs && (fs.is_dir () ? fs.nlink () : -1);
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1786
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1787 #if defined (KPSE_DEBUG)
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1788 if (KPSE_DEBUG_P (KPSE_DEBUG_STAT))
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1789 DEBUGF2 ("dir_links (%s) => %ld\n", fn.c_str (), retval);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1790 #endif
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1791
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1792 return retval;
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1793 }
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1794
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1795 #endif /* WIN32 */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1796
21340
9f838471a5da * kpse.cc: Avoid warning about static function in "header" file.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1797 static inline void
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1798 do_subdir (str_llist_type *str_list_ptr, const std::string& elt,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1799 unsigned elt_length, const std::string& post)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1800 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1801 #if defined (WIN32)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1802 WIN32_FIND_DATA find_file_data;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1803 HANDLE hnd;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1804 int proceed;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1805 #else
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1806 DIR *dir;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1807 struct dirent *e;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1808 #endif /* not WIN32 */
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1809
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1810 std::string name = elt.substr (0, elt_length);
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1811
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1812 assert (IS_DIR_SEP (elt[elt_length - 1])
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1813 || IS_DEVICE_SEP (elt[elt_length - 1]));
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1814
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1815 #if defined (WIN32)
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1816
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1817 dirname = name + "/*.*"; /* "*.*" or "*" -- seems equivalent. */
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1818
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1819 hnd = FindFirstFile (dirname.c_str (), &find_file_data);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1820
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1821 if (hnd == INVALID_HANDLE_VALUE)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1822 return;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1823
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1824 /* Include top level before subdirectories, if nothing to match. */
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1825 if (post.empty ())
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1826 dir_list_add (str_list_ptr, name);
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1827 else
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1828 {
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1829 /* If we do have something to match, see if it exists. For
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1830 example, POST might be 'pk/ljfour', and they might have a
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1831 directory '$TEXMF/fonts/pk/ljfour' that we should find. */
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1832 name += post;
21864
f3487b21e879 * kpse.cc: Remove obsolete and unused code.
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
1833 checked_dir_list_add (str_list_ptr, name);
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1834 name.resize (elt_length);
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1835 }
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1836
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1837 proceed = 1;
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1838
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1839 while (proceed)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1840 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1841 if (find_file_data.cFileName[0] != '.')
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1842 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1843 /* Construct the potential subdirectory name. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1844 name += find_file_data.cFileName;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1845
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1846 if (find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1847 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1848 /* It's a directory, so append the separator. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1849 name += DIR_SEP_STRING;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1850 unsigned potential_len = name.length ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1851
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1852 do_subdir (str_list_ptr, name, potential_len, post);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1853 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1854 name.resize (elt_length);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1855 }
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1856
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1857 proceed = FindNextFile (hnd, &find_file_data);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1858 }
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1859
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1860 FindClose (hnd);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1861
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1862 #else /* not WIN32 */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1863
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1864 /* If we can't open it, quit. */
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
1865 dir = gnulib::opendir (name.c_str ());
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1866
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1867 if (! dir)
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1868 return;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1869
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1870 /* Include top level before subdirectories, if nothing to match. */
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1871 if (post.empty ())
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1872 dir_list_add (str_list_ptr, name);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1873 else
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1874 {
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1875 /* If we do have something to match, see if it exists. For
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1876 example, POST might be 'pk/ljfour', and they might have a
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1877 directory '$TEXMF/fonts/pk/ljfour' that we should find. */
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1878 name += post;
21864
f3487b21e879 * kpse.cc: Remove obsolete and unused code.
John W. Eaton <jwe@octave.org>
parents: 21863
diff changeset
1879 checked_dir_list_add (str_list_ptr, name);
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1880 name.resize (elt_length);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1881 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1882
14155
583d3d6f6fde use gnulib::readdir
John W. Eaton <jwe@octave.org>
parents: 14153
diff changeset
1883 while ((e = gnulib::readdir (dir)))
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1884 {
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1885 /* If it begins with a '.', never mind. (This allows "hidden"
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1886 directories that the algorithm won't find.) */
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1887
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1888 if (e->d_name[0] != '.')
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1889 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1890 /* Construct the potential subdirectory name. */
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1891 name += e->d_name;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1892
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1893 /* If we can't stat it, or if it isn't a directory, continue. */
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1894 int links = dir_links (name);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1895
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1896 if (links >= 0)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1897 {
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1898 /* It's a directory, so append the separator. */
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1899 name += DIR_SEP_STRING;
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1900 unsigned potential_len = name.length ();
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1901
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1902 /* Should we recurse? To see if the subdirectory is a
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1903 leaf, check if it has two links (one for . and one for
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1904 ..). This means that symbolic links to directories do
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1905 not affect the leaf-ness. This is arguably wrong, but
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1906 the only alternative I know of is to stat every entry
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1907 in the directory, and that is unacceptably slow.
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1908
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1909 The #if here makes all this configurable at
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1910 compile-time, so that if we're using VMS directories or
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1911 some such, we can still find subdirectories, even if it
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1912 is much slower. */
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1913 #if defined (ST_NLINK_TRICK)
5622
8b7046423d1e [project @ 2006-02-15 16:36:32 by jwe]
jwe
parents: 5618
diff changeset
1914 if (links != 2)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1915 #endif /* not ST_NLINK_TRICK */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1916 /* All criteria are met; find subdirectories. */
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1917 do_subdir (str_list_ptr, name, potential_len, post);
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1918 #if defined (ST_NLINK_TRICK)
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1919 else if (post.empty ())
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1920 /* Nothing to match, no recursive subdirectories to
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1921 look for: we're done with this branch. Add it. */
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1922 dir_list_add (str_list_ptr, name);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1923 #endif
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1924 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1925
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1926 /* Remove the directory entry we just checked from 'name'. */
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1927 name.resize (elt_length);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1928 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1929 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1930
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1931 xclosedir (dir);
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1932 #endif /* not WIN32 */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1933 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1934
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1935 /* Here is the entry point. Returns directory list for ELT. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1936
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1937 /* 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
1938 of the corresponding (existing) directory or directories, with
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1939 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
1940 current working directory.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11501
diff changeset
1941
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1942 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
1943 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
1944 has already assumed expansion has been done. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1945
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1946 static str_llist_type *
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1947 kpse_element_dirs (const std::string& elt)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1948 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1949 str_llist_type *ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1950
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1951 /* If given nothing, return nothing. */
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1952 if (elt.empty ())
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1953 return 0;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1954
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1955 /* 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
1956 ret = cached (elt);
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1957 if (ret)
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1958 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1959
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1960 /* We're going to have a real directory list to return. */
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1961 ret = new str_llist_type;
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1962 *ret = 0;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1963
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1964 /* 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
1965 checked_dir_list_add (ret, elt);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1966
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1967 /* 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
1968 made with the same ELT. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1969 cache (elt, ret);
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1970
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1971 #if defined (KPSE_DEBUG)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1972 if (KPSE_DEBUG_P (KPSE_DEBUG_EXPAND))
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1973 {
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1974 DEBUGF1 ("path element %s =>", elt.c_str ());
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1975 if (ret)
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1976 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1977 str_llist_elt_type *e;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1978 for (e = *ret; e; e = STR_LLIST_NEXT (*e))
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
1979 gnulib::fprintf (stderr, " %s", (STR_LLIST (*e)).c_str ());
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1980 }
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
1981 gnulib::putc ('\n', stderr);
12912
e116dd862879 use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
1982 gnulib::fflush (stderr);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1983 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1984 #endif /* KPSE_DEBUG */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1985
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1986 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1987 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1988
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1989 #if ! defined (WIN32)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1990 void
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1991 xclosedir (DIR *d)
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1992 {
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
1993 int ret = gnulib::closedir (d);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1994
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1995 if (ret != 0)
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1996 FATAL ("closedir failed");
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1997 }
4386
112a509bd2e6 [project @ 2003-04-24 18:41:02 by jwe]
jwe
parents: 4385
diff changeset
1998 #endif
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1999
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
2000 /* Implementation of a linked list of strings. */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2001
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2002 /* Add the new string STR to the end of the list L. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2003
5085
6861a84b1d47 [project @ 2004-11-19 03:26:32 by jwe]
jwe
parents: 4928
diff changeset
2004 static void
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
2005 str_llist_add (str_llist_type *l, const std::string& str)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2006 {
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2007 str_llist_elt_type *e;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
2008 str_llist_elt_type *new_elt = new str_llist_elt_type;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2009
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2010 /* The new element will be at the end of the list. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2011 STR_LLIST (*new_elt) = str;
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2012 STR_LLIST_MOVED (*new_elt) = 0;
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
2013 STR_LLIST_NEXT (*new_elt) = 0;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2014
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2015 /* Find the current end of the list. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2016 for (e = *l; e && STR_LLIST_NEXT (*e); e = STR_LLIST_NEXT (*e))
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2017 ;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2018
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2019 if (! e)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2020 *l = new_elt;
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2021 else
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2022 STR_LLIST_NEXT (*e) = new_elt;
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2023 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
2024
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
2025 /* Move an element towards the top. The idea is that when a file is
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2026 found in a given directory, later files will likely be in that same
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2027 directory, and looking for the file in all the directories in between
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2028 is thus a waste. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2029
5085
6861a84b1d47 [project @ 2004-11-19 03:26:32 by jwe]
jwe
parents: 4928
diff changeset
2030 static void
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2031 str_llist_float (str_llist_type *l, str_llist_elt_type *mover)
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2032 {
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2033 str_llist_elt_type *last_moved, *unmoved;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2034
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2035 /* If we've already moved this element, never mind. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2036 if (STR_LLIST_MOVED (*mover))
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2037 return;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2038
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2039 /* Find the first unmoved element (to insert before). We're
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2040 guaranteed this will terminate, since MOVER itself is currently
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2041 unmoved, and it must be in L (by hypothesis). */
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
2042 for (last_moved = 0, unmoved = *l; STR_LLIST_MOVED (*unmoved);
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2043 last_moved = unmoved, unmoved = STR_LLIST_NEXT (*unmoved))
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2044 ;
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2045
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2046 /* If we are the first unmoved element, nothing to relink. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2047 if (unmoved != mover)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2048 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2049 /* Remember 'mover's current successor, so we can relink 'mover's
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2050 predecessor to it. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2051 str_llist_elt_type *before_mover;
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2052 str_llist_elt_type *after_mover = STR_LLIST_NEXT (*mover);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2053
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
2054 /* Find 'mover's predecessor. */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2055 for (before_mover = unmoved; STR_LLIST_NEXT (*before_mover) != mover;
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2056 before_mover = STR_LLIST_NEXT (*before_mover))
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2057 ;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2058
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
2059 /* 'before_mover' now links to 'after_mover'. */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2060 STR_LLIST_NEXT (*before_mover) = after_mover;
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2061
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
2062 /* Insert 'mover' before 'unmoved' and after 'last_moved' (or at
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2063 the head of the list). */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2064 STR_LLIST_NEXT (*mover) = unmoved;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2065 if (! last_moved)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2066 *l = mover;
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2067 else
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2068 STR_LLIST_NEXT (*last_moved) = mover;
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2069 }
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2070
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2071 /* We've moved it. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2072 STR_LLIST_MOVED (*mover) = 1;
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2073 }
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2074
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
2075 /* Variable expansion. */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2076
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2077 /* 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
2078 constructs like TEXINPUTS = $TEXINPUTS result in an infinite loop.
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2079 (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
2080 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
2081 before expanding. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2082
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2083 static std::map <std::string, bool> expansions;
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2084
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2085 static void
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2086 expanding (const std::string& var, bool xp)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2087 {
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2088 expansions[var] = xp;
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2089 }
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2090
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2091 /* Return whether VAR is currently being expanding. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2092
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2093 static bool
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2094 expanding_p (const std::string& var)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2095 {
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2096 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
2097 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
2098
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
2099 /* 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
2100 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
2101 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
2102
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2103 static void
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2104 expand (std::string &expansion, const std::string& var)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2105 {
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2106 if (expanding_p (var))
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2107 {
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
2108 (*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
2109 ("Octave:pathsearch-syntax",
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
2110 "kpathsea: variable '%s' references itself (eventually)",
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2111 var.c_str ());
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2112 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2113 else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2114 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2115 /* Check for an environment variable. */
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21729
diff changeset
2116 std::string value = octave::sys::env::getenv (var);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2117
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2118 if (! value.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2119 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2120 expanding (var, true);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2121 std::string tmp = kpse_var_expand (value);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2122 expanding (var, false);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2123 expansion += tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2124 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2125 }
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2126 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
2127
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2128 /* 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
2129 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
2130 #if ! defined (IS_VAR_START)
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
2131 /* starts all variable references */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2132 #define IS_VAR_START(c) ((c) == '$')
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2133 #endif
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
2134 #if ! defined (IS_VAR_CHAR)
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
2135 /* variable name constituent */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2136 #define IS_VAR_CHAR(c) (isalnum (c) || (c) == '_')
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2137 #endif
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
2138 #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
2139 /* start delimited variable name (after $) */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2140 #define IS_VAR_BEGIN_DELIMITER(c) ((c) == '{')
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2141 #endif
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
2142 #if ! defined (IS_VAR_END_DELIMITER)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2143 #define IS_VAR_END_DELIMITER(c) ((c) == '}')
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2144 #endif
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2145
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2146 /* 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
2147 constructs, especially ${var-value}. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2148
5085
6861a84b1d47 [project @ 2004-11-19 03:26:32 by jwe]
jwe
parents: 4928
diff changeset
2149 static std::string
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2150 kpse_var_expand (const std::string& src)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2151 {
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
2152 std::string expansion;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2153
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2154 size_t src_len = src.length ();
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2155
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2156 /* Copy everything but variable constructs. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2157 for (size_t i = 0; i < src_len; i++)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2158 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2159 if (IS_VAR_START (src[i]))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2160 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2161 i++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2162
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
2163 /* Three cases: '$VAR', '${VAR}', '$<anything-else>'. */
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2164 if (IS_VAR_CHAR (src[i]))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2165 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2166 /* $V: collect name constituents, then expand. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2167 size_t var_end = i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2168
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2169 do
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2170 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2171 var_end++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2172 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2173 while (IS_VAR_CHAR (src[var_end]));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2174
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2175 var_end--; /* had to go one past */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2176 expand (expansion, src.substr (i, var_end - i + 1));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2177 i = var_end;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2178
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2179 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2180 else if (IS_VAR_BEGIN_DELIMITER (src[i]))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2181 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2182 /* ${: scan ahead for matching delimiter, then expand. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2183 size_t var_end = ++i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2184
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20791
diff changeset
2185 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
2186 var_end++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2187
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2188 if (var_end == src_len)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2189 {
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
2190 (*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
2191 ("Octave:pathsearch-syntax",
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
2192 "%s: No matching } for ${", src.c_str ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2193 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
2194 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2195 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2196 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2197 expand (expansion, src.substr (i, var_end - i));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2198 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
2199 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2200 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2201 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2202 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2203 /* $<something-else>: error. */
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
2204 (*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
2205 ("Octave:pathsearch-syntax",
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
2206 "%s: Unrecognized variable construct '$%c'",
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2207 src.c_str (), src[i]);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2208
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2209 /* Just ignore those chars and keep going. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2210 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2211 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2212 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
2213 expansion += src[i];
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
2214 }
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
2215
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
2216 return expansion;
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
2217 }