annotate liboctave/util/kpse.cc @ 22197:e43d83253e28

refill multi-line macro definitions Use the Emacs C++ mode style for line continuation markers in multi-line macro definitions. * make_int.cc, __dsearchn__.cc, __magick_read__.cc, besselj.cc, bitfcns.cc, bsxfun.cc, cellfun.cc, data.cc, defun-dld.h, defun-int.h, defun.h, det.cc, error.h, find.cc, gcd.cc, graphics.cc, interpreter.h, jit-ir.h, jit-typeinfo.h, lookup.cc, ls-mat5.cc, max.cc, mexproto.h, mxarray.in.h, oct-stream.cc, ordschur.cc, pr-output.cc, profiler.h, psi.cc, regexp.cc, sparse-xdiv.cc, sparse-xpow.cc, tril.cc, txt-eng.h, utils.cc, variables.cc, variables.h, xdiv.cc, xpow.cc, __glpk__.cc, ov-base.cc, ov-base.h, ov-cell.cc, ov-ch-mat.cc, ov-classdef.cc, ov-complex.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-float.cc, ov-float.h, ov-flt-complex.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-int-traits.h, ov-lazy-idx.h, ov-perm.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-scalar.h, ov-str-mat.cc, ov-type-conv.h, ov.cc, ov.h, op-class.cc, op-int-conv.cc, op-int.h, op-str-str.cc, ops.h, lex.ll, Array.cc, CMatrix.cc, CSparse.cc, MArray.cc, MArray.h, MDiagArray2.cc, MDiagArray2.h, MSparse.h, Sparse.cc, dMatrix.cc, dSparse.cc, fCMatrix.cc, fMatrix.cc, idx-vector.cc, f77-fcn.h, quit.h, bsxfun-decl.h, bsxfun-defs.cc, lo-specfun.cc, oct-convn.cc, oct-convn.h, oct-norm.cc, oct-norm.h, oct-rand.cc, Sparse-op-decls.h, Sparse-op-defs.h, mx-inlines.cc, mx-op-decl.h, mx-op-defs.h, mach-info.cc, oct-group.cc, oct-passwd.cc, oct-syscalls.cc, oct-time.cc, data-conv.cc, kpse.cc, lo-ieee.h, lo-macros.h, oct-cmplx.h, oct-glob.cc, oct-inttypes.cc, oct-inttypes.h, oct-locbuf.h, oct-sparse.h, url-transfer.cc, oct-conf-post.in.h, shared-fcns.h: Refill macro definitions.
author John W. Eaton <jwe@octave.org>
date Mon, 01 Aug 2016 12:40:18 -0400
parents b017351e92e1
children bac0d6f07a3e
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
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
29 #if defined (HAVE_CONFIG_H)
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
30 # include "config.h"
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
31 #endif
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
32
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
33 #include <cctype>
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
34 #include <cerrno>
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
35 #include <cstdlib>
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
36
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
37 #include <map>
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
38 #include <fstream>
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
39 #include <iostream>
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
40 #include <string>
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
41
21926
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
42 #include "dir-ops.h"
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
43 #include "file-ops.h"
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
44 #include "file-stat.h"
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
45 #include "kpse.h"
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
46 #include "oct-env.h"
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
47 #include "oct-passwd.h"
22061
737b1d9d7ee3 use octave::sys::time instead of C library time function
John W. Eaton <jwe@octave.org>
parents: 21979
diff changeset
48 #include "oct-time.h"
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
49 #include "pathsearch.h"
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21887
diff changeset
50 #include "unistd-wrappers.h"
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
51
21979
d04da18a407a use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents: 21926
diff changeset
52 #if defined (OCTAVE_USE_WINDOWS_API)
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
53 # define WIN32_LEAN_AND_MEAN 1
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
54 # include <windows.h>
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
55 #endif
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
56
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
57 // Define the characters which separate components of filenames and
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
58 // environment variable paths.
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
59
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
60 #define IS_DEVICE_SEP(ch) octave::sys::file_ops::is_dev_sep (ch)
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22115
diff changeset
61 #define NAME_BEGINS_WITH_DEVICE(name) \
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
62 (name.length () > 0 && IS_DEVICE_SEP ((name)[1]))
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
63
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
64 #define DIR_SEP_STRING octave::sys::file_ops::dir_sep_str ()
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
65 #define IS_DIR_SEP(ch) octave::sys::file_ops::is_dir_sep (ch)
21863
a25110491607 eliminate obsolete sysdir.h header file
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
66
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
67 #define ENV_SEP octave::directory_path::path_sep_char ()
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
68 #define ENV_SEP_STRING octave::directory_path::path_sep_str ()
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
69 #define IS_ENV_SEP(ch) octave::directory_path::is_path_sep (ch)
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
70
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
71 // 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
72 #if ! defined (NO_DEBUG)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
73
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
74 // OK, we'll have tracing support.
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
75 # define KPSE_DEBUG
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
76
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
77 // Test if a bit is on.
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
78 # define KPSE_DEBUG_P(bit) (kpse_debug & (1 << (bit)))
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
79
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
80 # define KPSE_DEBUG_STAT 0 // stat calls
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
81 # define KPSE_DEBUG_EXPAND 1 // path element expansion
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
82 # define KPSE_DEBUG_SEARCH 2 // searches
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
83 # define KPSE_DEBUG_VARS 3 // variable values
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
84 # define KPSE_LAST_DEBUG KPSE_DEBUG_VARS
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
85
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
86 #endif
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
87
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
88 unsigned int kpse_debug = 0;
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
89
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
90 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
91
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
92 static std::string kpse_expand (const std::string& s);
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
93
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
94 void
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
95 kpse_path_iterator::set_end (void)
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
96 {
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
97 e = b + 1;
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
98
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
99 if (e == len)
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
100 ; // OK, we have found the last element.
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
101 else if (e > len)
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
102 b = e = std::string::npos;
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
103 else
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
104 {
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
105 // Find the next colon not enclosed by braces (or the end of the
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
106 // path).
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
107
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
108 while (e < len && ! octave::directory_path::is_path_sep (path[e]))
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
109 e++;
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
110 }
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
111 }
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
112
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
113 void
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
114 kpse_path_iterator::next (void)
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
115 {
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
116 b = e + 1;
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
117
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
118 // Skip any consecutive colons.
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
119 while (b < len && octave::directory_path::is_path_sep (path[b]))
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
120 b++;
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
121
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
122 if (b >= len)
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
123 b = e = std::string::npos;
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
124 else
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
125 set_end ();
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
126 }
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
127
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
128 /* 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
129 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
130
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
131 static std::string
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
132 kpse_truncate_filename (const std::string& name)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
133 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
134 unsigned c_len = 0; /* Length of current component. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
135 unsigned ret_len = 0; /* Length of constructed result. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
136
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
137 std::string ret = name;
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
138
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
139 size_t len = name.length ();
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
140
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
141 for (size_t i = 0; i < len; i++)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
142 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
143 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
144 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
145 /* At a directory delimiter, reset component length. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
146 c_len = 0;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
147 }
22115
b017351e92e1 * kpse.cc (kpse_truncate_filename): Use namespace qualifier for static dir_entry function.
John W. Eaton <jwe@octave.org>
parents: 22061
diff changeset
148 else if (c_len > octave::sys::dir_entry::max_name_length ())
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
149 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
150 /* 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
151 continue;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
152 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
153
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
154 /* Copy this character. */
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
155 ret[ret_len++] = name[i];
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
156 c_len++;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
157 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
158
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
159 ret.resize (ret_len);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
160
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
161 return ret;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
162 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
163
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
164 /* 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
165 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
166 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
167 kinds of devices. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
168
21979
d04da18a407a use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents: 21926
diff changeset
169 #if defined (OCTAVE_USE_WINDOWS_API)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
170 static inline bool
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
171 READABLE (const std::string& fn)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
172 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
173 const char *t = fn.c_str ();
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
174 return (GetFileAttributes (t) != 0xFFFFFFFF
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
175 && ! (GetFileAttributes (t) & FILE_ATTRIBUTE_DIRECTORY));
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
176 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
177 #else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
178 static inline bool
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
179 READABLE (const std::string& fn)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
180 {
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
181 bool retval = false;
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
182
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
183 const char *t = fn.c_str ();
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
184
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21887
diff changeset
185 if (octave_access_wrapper (t, octave_access_r_ok ()) == 0)
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
186 {
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
187 octave::sys::file_stat fs (fn);
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
188
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
189 retval = fs && ! fs.is_dir ();
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
190 }
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
191
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
192 return retval;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
193 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
194 #endif
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
195
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
196 /* POSIX invented the brain-damage of not necessarily truncating
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
197 filename components; the system's behavior is defined by the value of
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
198 the symbol _POSIX_NO_TRUNC, but you can't change it dynamically!
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
199
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
200 Generic const return warning. See extend-fname.c. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
201
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
202 static std::string
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
203 kpse_readable_file (const std::string& name)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
204 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
205 std::string ret;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
206
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
207 if (READABLE (name))
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
208 {
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
209 ret = name;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
210
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
211 #if defined (ENAMETOOLONG)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
212 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
213 else if (errno == ENAMETOOLONG)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
214 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
215 ret = kpse_truncate_filename (name);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
216
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
217 /* Perhaps some other error will occur with the truncated name,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
218 so let's call access again. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
219
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
220 if (! READABLE (ret))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
221 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
222 /* Failed. */
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20955
diff changeset
223 ret = "";
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
224 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
225 #endif /* ENAMETOOLONG */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
226
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
227 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
228 else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
229 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
230 /* Some other error. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
231 if (errno == EACCES)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
232 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
233 /* Maybe warn them if permissions are bad. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
234 perror (name.c_str ());
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
235 }
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
236
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20955
diff changeset
237 ret = "";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
238 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
239
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
240 return ret;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
241 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
242
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
243 static bool
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
244 kpse_absolute_p (const std::string& filename, int relative_ok)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
245 {
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
246 return (octave::sys::env::absolute_pathname (filename)
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
247 || (relative_ok
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
248 && octave::sys::env::rooted_relative_pathname (filename)));
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
249 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
250
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
251 /* The very first search is for texmf.cnf, called when someone tries to
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
252 initialize the TFM path or whatever. init_path calls kpse_cnf_get
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
253 which calls kpse_all_path_search to find all the texmf.cnf's. We
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
254 need to do various special things in this case, since we obviously
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
255 don't yet have the configuration files when we're searching for the
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
256 configuration files. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
257 static bool first_search = true;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
258
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
259 /* This function is called after every search. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
260
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
261 static void
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
262 log_search (const std::list<std::string>& filenames)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
263 {
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
264 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
265 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
266 for (const auto &filename : filenames)
22061
737b1d9d7ee3 use octave::sys::time instead of C library time function
John W. Eaton <jwe@octave.org>
parents: 21979
diff changeset
267 {
737b1d9d7ee3 use octave::sys::time instead of C library time function
John W. Eaton <jwe@octave.org>
parents: 21979
diff changeset
268 octave::sys::time now;
737b1d9d7ee3 use octave::sys::time instead of C library time function
John W. Eaton <jwe@octave.org>
parents: 21979
diff changeset
269 std::cerr << now.unix_time () << " " << filename << std::endl;
737b1d9d7ee3 use octave::sys::time instead of C library time function
John W. Eaton <jwe@octave.org>
parents: 21979
diff changeset
270 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
271 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
272 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
273
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
274 /* Concatenate each element in DIRS with NAME (assume each ends with a
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
275 /, to save time). If SEARCH_ALL is false, return the first readable
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
276 regular file. Else continue to search for more. In any case, if
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
277 none, return a list containing just NULL.
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
278
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
279 We keep a single buffer for the potential filenames and reallocate
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
280 only when necessary. I'm not sure it's noticeably faster, but it
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
281 does seem cleaner. (We do waste a bit of space in the return
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
282 value, though, since we don't shrink it to the final size returned.) */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
283
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
284 static std::list<std::string>
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
285 dir_search (const std::string& dir, const std::string& name,
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
286 bool search_all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
287 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
288 std::list<std::string> ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
289
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
290 std::string potential = dir + name;
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
291
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
292 std::string tmp = kpse_readable_file (potential);
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
293
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
294 if (! tmp.empty ())
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
295 {
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
296 ret.push_back (potential);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
297
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
298 if (! search_all)
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
299 return ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
300 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
301
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
302 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
303 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
304
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
305 /* This is called when NAME is absolute or explicitly relative; if it's
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
306 readable, return (a list containing) it; otherwise, return NULL. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
307
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
308 static std::list<std::string>
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
309 absolute_search (const std::string& name)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
310 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
311 std::list<std::string> ret_list;
4393
f92093e0ff78 [project @ 2003-04-26 20:58:45 by jwe]
jwe
parents: 4392
diff changeset
312 std::string found = kpse_readable_file (name);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
313
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
314 /* Add 'found' to the return list even if it's null; that tells
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
315 the caller we didn't find anything. */
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
316 ret_list.push_back (found);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
317
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
318 return ret_list;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
319 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
320
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
321 /* This is the hard case -- look for NAME in PATH. If ALL is false,
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
322 return the first file found. Otherwise, search all elements of PATH. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
323
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
324 static std::list<std::string>
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
325 path_search (const std::string& path, const std::string& name, bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
326 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
327 std::list<std::string> ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
328 bool done = false;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
329
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
330 for (kpse_path_iterator pi (path); ! done && pi != std::string::npos; pi++)
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
331 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
332 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
333
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
334 std::list<std::string> found;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
335
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
336 /* Do not touch the device if present */
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
337 if (NAME_BEGINS_WITH_DEVICE (elt))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
338 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
339 while (elt.length () > 3
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
340 && IS_DIR_SEP (elt[2]) && IS_DIR_SEP (elt[3]))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
341 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
342 elt[2] = elt[1];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
343 elt[1] = elt[0];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
344 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
345 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
346 }
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
347 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
348 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
349 /* We never want to search the whole disk. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
350 while (elt.length () > 1
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
351 && IS_DIR_SEP (elt[0]) && IS_DIR_SEP (elt[1]))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
352 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
353 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
354
21872
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
355 /* Our caller (search), also tests first_search, and does
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
356 the resetting. */
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
357 if (first_search)
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
358 found = std::list<std::string> ();
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
359
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
360 /* Search the filesystem. */
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
361
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
362 if (found.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
363 {
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
364 std::string dir = kpse_element_dir (elt);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
365
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
366 if (! dir.empty ())
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
367 found = dir_search (dir, name, all);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
368 }
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
369
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
370 /* Did we find anything anywhere? */
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
371 if (! found.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
372 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
373 if (all)
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
374 ret_list.splice (ret_list.end (), found);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
375 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
376 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
377 ret_list.push_back (found.front ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
378 done = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
379 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
380 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
381 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
382
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
383 return ret_list;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
384 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
385
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
386 /* 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
387 absolute_p, check ORIGINAL_NAME itself. Otherwise, look at each
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
388 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
389
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
390 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
391 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
392 terminated with NULL. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
393
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
394 static std::list<std::string>
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
395 search (const std::string& path, const std::string& original_name,
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
396 bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
397 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
398 std::list<std::string> ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
399 bool absolute_p;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
400
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
401 /* 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
402 std::string name = kpse_expand (original_name);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
403
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
404 /* 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
405 consider PATH at all. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
406 absolute_p = kpse_absolute_p (name, true);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
407
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
408 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
409 std::cerr << "kdebug: start search (file=" << name
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
410 << ", find_all=" << all << ", path=" << path << ")."
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
411 << std::endl;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
412
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
413 /* Find the file(s). */
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
414 ret_list = (absolute_p
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
415 ? absolute_search (name)
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
416 : path_search (path, name, all));
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
417
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
418 /* 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
419 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
420 if (first_search)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
421 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
422 first_search = false;
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 else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
425 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
426 /* 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
427 debugging line if we're doing that. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
428
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
429 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
430 std::cerr << "kdebug: search (" << original_name << ") =>";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
431
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
432 log_search (ret_list);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
433
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
434 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
435 std::cerr << std::endl;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
436 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
437
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
438 return ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
439 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
440
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
441 /* Search PATH for the first NAME. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
442
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
443 /* 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
444 explicitly relative filename, check whether it is a readable
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
445 (regular) file.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11501
diff changeset
446
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
447 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
448 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
449
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
450 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
451 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
452
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
453 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
454
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
455 std::string
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
456 kpse_path_search (const std::string& path, const std::string& name)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
457 {
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
458 std::list<std::string> ret_list = search (path, name, false);
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
459
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
460 return ret_list.empty () ? "" : ret_list.front ();
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
461 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
462
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
463 /* 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
464 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
465
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
466 std::list<std::string>
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
467 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
468 {
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
469 return search (path, name, true);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
470 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
471
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
472 /* 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
473 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
474 Otherwise, search all elements of PATH. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
475
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
476 std::list<std::string>
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
477 path_find_first_of (const std::string& path,
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
478 const std::list<std::string>& names, bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
479 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
480 std::list<std::string> ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
481 bool done = false;
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
482
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
483 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
484 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
485 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
486
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
487 std::string dir;
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
488 std::list<std::string> found;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
489
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
490 /* Do not touch the device if present */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
491
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
492 if (NAME_BEGINS_WITH_DEVICE (elt))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
493 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
494 while (elt.length () > 3
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
495 && 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
496 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
497 elt[2] = elt[1];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
498 elt[1] = elt[0];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
499 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
500 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
501 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
502 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
503 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
504 /* We never want to search the whole disk. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
505 while (elt.length () > 1
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
506 && 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
507 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
508 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
509
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
510 /* We have to search one directory at a time. */
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
511 dir = kpse_element_dir (elt);
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
512
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
513 if (! dir.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
514 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
515 for (auto it = names.cbegin (); it != names.cend () && ! done; it++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
516 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
517 std::string name = *it;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
518
21872
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
519 /* Our caller (find_first_of), also tests first_search,
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
520 and does the resetting. */
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
521 if (first_search)
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
522 found = std::list<std::string> ();
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
523
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
524 /* Search the filesystem. */
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
525
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
526 if (found.empty ())
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
527 found = dir_search (dir, name, all);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
528
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
529 /* Did we find anything anywhere? */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
530 if (! found.empty ())
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
531 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
532 if (all)
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
533 ret_list.splice (ret_list.end (), found);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
534 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
535 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
536 ret_list.push_back (found.front ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
537 done = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
538 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
539 }
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 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
542 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
543
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
544 return ret_list;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
545 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
546
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
547 static std::list<std::string>
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
548 find_first_of (const std::string& path, const std::list<std::string>& names,
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
549 bool all)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
550 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
551 std::list<std::string> ret_list;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
552
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
553 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
554 {
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
555 std::cerr << "kdebug: start find_first_of (";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
556
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
557 for (auto p = names.cbegin (); p != names.cend (); p++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
558 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
559 if (p == names.cbegin ())
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
560 std::cerr << *p;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
561 else
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
562 std::cerr << ", " << *p;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
563 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
564
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
565 std::cerr << "), path=" << path << "." << std::endl;
4378
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
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
568 for (const auto &name : names)
4409
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
569 {
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
570 if (kpse_absolute_p (name, true))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
571 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
572 /* 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
573 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
574 are done. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
575
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
576 ret_list = absolute_search (name);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
577
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
578 if (! ret_list.empty ())
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
579 return ret_list;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
580 }
4409
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
581 }
6b191c6e6875 [project @ 2003-05-11 16:41:10 by jwe]
jwe
parents: 4407
diff changeset
582
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
583 /* Find the file. */
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
584 ret_list = path_find_first_of (path, names, all);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
585
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
586 /* 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
587 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
588 if (first_search)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
589 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
590 first_search = false;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
591 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
592 else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
593 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
594 /* 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
595 debugging line if we're doing that. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
596
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
597 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
598 {
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
599 std::cerr << "kdebug: find_first_of (";
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
600
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
601 for (auto p = names.cbegin (); p != names.cend (); p++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
602 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
603 if (p == names.cbegin ())
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
604 std:: cerr << *p;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
605 else
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
606 std::cerr << ", " << *p;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
607 }
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
608
21868
e2796ea8feac * kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents: 21867
diff changeset
609 std::cerr << ") =>";
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
610 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
611
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
612 log_search (ret_list);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
613
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
614 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
21887
525b46f1d48f * kpse.cc (find_first_of): Use iostream instead of stdio for debug message.
John W. Eaton <jwe@octave.org>
parents: 21884
diff changeset
615 std::cerr << std::endl;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
616 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
617
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
618 return ret_list;
4378
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
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
621 /* 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
622 first one found. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
623
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
624 /* 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
625 Return the first one found. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
626
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
627 std::string
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
628 kpse_path_find_first_of (const std::string& path,
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
629 const std::list<std::string>& names)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
630 {
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
631 std::list<std::string> ret_list = find_first_of (path, names, false);
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
632
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
633 return ret_list.empty () ? "" : ret_list.front ();
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
634 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
635
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
636 /* 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
637 list containing everything found, in the order found. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
638
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
639 /* 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
640 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
641 first. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
642
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
643 std::list<std::string>
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
644 kpse_all_path_find_first_of (const std::string& path,
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
645 const std::list<std::string>& names)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
646 {
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
647 return find_first_of (path, names, true);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
648 }
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 /* 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
651 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
652 <pwd.h>, just return NAME. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
653
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
654 static std::string
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
655 kpse_tilde_expand (const std::string& name)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
656 {
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
657 std::string expansion;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
658
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
659 /* If no leading tilde, do nothing. */
5137
5ee7da8b8a4b [project @ 2005-02-09 17:59:19 by jwe]
jwe
parents: 5085
diff changeset
660 if (name.empty () || name[0] != '~')
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
661 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
662 expansion = name;
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 /* 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
665 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
666 ... */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
667 }
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
668 else if (name.length () == 1)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
669 {
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21729
diff changeset
670 expansion = octave::sys::env::get_home_directory ();
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
671
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
672 if (expansion.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
673 expansion = ".";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
674
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
675 /* 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
676 Should really check for doubled intermediate slashes, too. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
677 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
678 else if (IS_DIR_SEP (name[1]))
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
679 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
680 unsigned c = 1;
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21729
diff changeset
681 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
682
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
683 if (home.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
684 home = ".";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
685
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
686 size_t home_len = home.length ();
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
687
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
688 /* handle leading // */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
689 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
690 home = home.substr (1);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
691
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
692 /* omit / after ~ */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
693 if (IS_DIR_SEP (home[home_len - 1]))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
694 c++;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
695
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
696 expansion = home + name.substr (c);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
697
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
698 /* 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
699 OS/2 doesn't have this concept. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
700 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
701 else
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
702 #if defined (HAVE_PWD_H)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
703 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
704 unsigned c = 2;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
705
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
706 /* find user name */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
707 while (name.length () > c && ! IS_DIR_SEP (name[c]))
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
708 c++;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
709
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
710 std::string user = name.substr (1, c-1);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
711
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
712 /* 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
713 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
714 octave::sys::password p = octave::sys::password::getpwnam (user);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
715
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
716 /* If no such user, just use '.'. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
717 std::string home = p ? p.dir () : std::string (".");
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
718
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
719 if (home.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
720 home = ".";
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
721
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
722 /* handle leading // */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
723 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
724 home = home.substr (1);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
725
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
726 /* If HOME ends in /, omit the / after ~user. */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
727 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
728 c++;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
729
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
730 expansion = name.length () > c ? home : home + name.substr (c);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
731 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
732 #else /* not HAVE_PWD_H */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
733 expansion = name;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
734 #endif /* not HAVE_PWD_H */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
735
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
736 return expansion;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
737 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
738
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
739 /* 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
740 shells do.) */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
741
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
742 /* 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
743 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
744
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
745 static std::string
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
746 kpse_expand (const std::string& s)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
747 {
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
748 std::string var_expansion = kpse_var_expand (s);
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
749 return kpse_tilde_expand (var_expansion);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
750 }
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 /* Forward declarations of functions from the original expand.c */
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
753 static std::list<std::string> brace_expand (const std::string&);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
754
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
755 /* 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
756 path components. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
757
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
758 static std::string
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
759 kpse_expand_kpse_dot (const std::string& path)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
760 {
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
761 std::string ret;
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21729
diff changeset
762 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
763
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
764 if (kpse_dot.empty ())
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
765 return path;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
766
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
767 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
768 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
769 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
770
21872
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
771 /* 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
772
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
773 size_t elt_len = elt.length ();
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
774
21872
adb0b3ac4b50 more kpse.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
775 if (kpse_absolute_p (elt, false))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
776 ret += elt + ENV_SEP_STRING;
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
777 else if (elt_len == 1 && elt[0] == '.')
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
778 ret += kpse_dot + ENV_SEP_STRING;
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
779 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
780 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
781 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
782 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
783 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
784
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
785 int len = ret.length ();
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
786 if (len > 0)
4395
cc6d369355ec [project @ 2003-04-28 18:14:56 by jwe]
jwe
parents: 4394
diff changeset
787 ret.resize (len-1);
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
788
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
789 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
790 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
791
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
792 /* 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
793 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
794 variable definition contained braces (e.g., $TEXMF). Return a
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
795 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
796
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
797 static std::string
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
798 kpse_brace_expand_element (const std::string& elt)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
799 {
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
800 std::string ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
801
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
802 std::list<std::string> expansions = brace_expand (elt);
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
803
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
804 for (const auto &expanded_elt : expansions)
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
805 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
806 /* Do $ and ~ expansion on each element. */
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
807 std::string x = kpse_expand (expanded_elt);
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
808
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
809 if (x != elt)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
810 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
811 /* 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
812 recursive variable definitions are not allowed, this recursion
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
813 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
814 more than one level of recursion.) */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
815 x = kpse_brace_expand_element (x);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
816 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
817
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
818 ret += x + ENV_SEP_STRING;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
819 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
820
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
821 ret.resize (ret.length () - 1);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
822
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
823 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
824 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
825
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
826 /* 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
827 result; return the final expansion (always in fresh memory, even if
21874
7508f3a8e234 more cleanup in kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
828 no expansions were done). */
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
829
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
830 static std::string
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
831 kpse_brace_expand (const std::string& path)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
832 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
833 /* Must do variable expansion first because if we have
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
834 foo = .:~
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
835 TEXINPUTS = $foo
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
836 we want to end up with TEXINPUTS = .:/home/karl.
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
837 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
838 the path elements before we start the loop. */
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
839 std::string tmp = kpse_var_expand (path);
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
840
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
841 std::string ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
842
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
843 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
844 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
845 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
846
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
847 /* 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
848 std::string expansion = kpse_brace_expand_element (elt);
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
849 ret += expansion + ENV_SEP_STRING;
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
850 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
851
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
852 size_t len = ret.length ();
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
853 if (len > 0)
4395
cc6d369355ec [project @ 2003-04-28 18:14:56 by jwe]
jwe
parents: 4394
diff changeset
854 ret.resize (len-1);
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
855
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
856 return kpse_expand_kpse_dot (ret);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
857 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
858
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
859 /* 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
860 existing directories in the result. */
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
861
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
862 /* Do brace expansion and call 'kpse_expand' on each argument of the
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
863 result. The final expansion (always in fresh memory) is a path of
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
864 all the existing directories that match the pattern. */
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
865
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
866 std::string
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
867 kpse_path_expand (const std::string& path)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
868 {
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
869 std::string ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
870 unsigned len;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
871
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
872 len = 0;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
873
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
874 /* Expand variables and braces first. */
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
875 std::string tmp = kpse_brace_expand (path);
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
876
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
877 /* 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
878 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
879 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
880 std::string elt = *pi;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
881
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
882 std::string dir;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
883
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
884 /* Do not touch the device if present */
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
885 if (NAME_BEGINS_WITH_DEVICE (elt))
10314
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 while (elt.length () > 3
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
888 && 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
889 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
890 elt[2] = elt[1];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
891 elt[1] = elt[0];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
892 elt = elt.substr (1);
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 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
895 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
896 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
897 /* We never want to search the whole disk. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
898 while (elt.length () > 1
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
899 && 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
900 elt = elt.substr (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
901 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
902
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
903 /* 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
904 Be faster to check the database, but this is more reliable. */
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
905 dir = kpse_element_dir (elt);
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
906
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
907 size_t dirlen = dir.length ();
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
908
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
909 if (dirlen > 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
910 {
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
911 ret += dir;
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
912 len += dirlen;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
913
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
914 /* Retain trailing slash if that's the root directory. */
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
915 if (dirlen == 1
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
916 || (dirlen == 3 && NAME_BEGINS_WITH_DEVICE (dir)
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
917 && IS_DIR_SEP (dir[2])))
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
918 {
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
919 ret += ENV_SEP_STRING;
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
920 len++;
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
921 }
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
922
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
923 ret[len-1] = ENV_SEP;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
924 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
925 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
926
4395
cc6d369355ec [project @ 2003-04-28 18:14:56 by jwe]
jwe
parents: 4394
diff changeset
927 if (len > 0)
cc6d369355ec [project @ 2003-04-28 18:14:56 by jwe]
jwe
parents: 4394
diff changeset
928 ret.resize (len-1);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
929
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
930 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
931 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
932
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
933 /* 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
934 bash 1.14.5. [And subsequently modified for kpatshea.]
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
935
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16314
diff changeset
936 Copyright (C) 1987,1991 Free Software Foundation, Inc. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
937
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
938 #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
939
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
940 /* Basic idea:
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
941
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
942 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
943 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
944 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
945 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
946 the result so far. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
947
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
948 /* 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
949 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
950 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
951 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
952 is returned. */
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
953
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
954 static std::list<std::string>
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
955 array_concat (const std::list<std::string>& arr1,
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
956 const std::list<std::string>& arr2)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
957 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
958 std::list<std::string> result;
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
959
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
960 if (arr1.empty ())
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
961 result = arr2;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
962 else if (arr2.empty ())
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
963 result = arr1;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
964 else
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
965 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
966 for (const auto &elt_2 : arr2)
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
967 for (const auto &elt_1 : arr1)
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
968 result.push_back (elt_1 + elt_2);
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
969 }
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
970
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
971 return result;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
972 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
973
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
974 static int brace_gobbler (const std::string&, int&, int);
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
975 static std::list<std::string> expand_amble (const std::string&);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
976
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
977 /* Return an array of strings; the brace expansion of TEXT. */
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
978 static std::list<std::string>
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
979 brace_expand (const std::string& text)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
980 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
981 /* Find the text of the preamble. */
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
982 int i = 0;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
983 int c = brace_gobbler (text, i, '{');
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
984
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
985 std::string preamble = text.substr (0, i);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
986
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
987 std::list<std::string> result (1, preamble);
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
988
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
989 if (c == '{')
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
990 {
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
991 /* 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
992 int start = ++i;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
993 c = brace_gobbler (text, i, '}');
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
994
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
995 /* What if there isn't a matching close brace? */
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
996 if (! c)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
997 {
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
998 (*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
999 ("Octave:pathsearch-syntax",
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1000 "%s: Unmatched {", text.c_str ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1001
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1002 result = std::list<std::string> (1, text);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1003 }
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1004 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1005 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1006 std::string amble = text.substr (start, i-start);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1007 result = array_concat (result, expand_amble (amble));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1008
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1009 std::string postamble = text.substr (i+1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1010 result = array_concat (result, brace_expand (postamble));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1011 }
4378
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
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1014 return result;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1015 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1016
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1017 /* The character which is used to separate arguments. */
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1018 static int brace_arg_separator = ',';
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1019
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1020 /* 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
1021 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
1022 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
1023 need it. */
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1024 static std::list<std::string>
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1025 expand_amble (const std::string& text)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1026 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1027 std::list<std::string> result;
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1028
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1029 size_t text_len = text.length ();
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1030 size_t start;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1031 int i, c;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1032
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1033 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
1034 {
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1035 int i0 = i;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1036 int c0 = brace_gobbler (text, i0, brace_arg_separator);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1037 int i1 = i;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1038 int c1 = brace_gobbler (text, i1, ENV_SEP);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1039 c = c0 | c1;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1040 i = (i0 < i1 ? i0 : i1);
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1041
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1042 std::string tem = text.substr (start, i-start);
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1043
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1044 std::list<std::string> partial = brace_expand (tem);
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1045
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1046 if (result.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1047 result = partial;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1048 else
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21865
diff changeset
1049 result.splice (result.end (), partial);
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1050 }
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1051
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1052 return result;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1053 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1054
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21732
diff changeset
1055 /* 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
1056 index of the character matching SATISFY. This understands about
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1057 quoting. Return the character that caused us to stop searching;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1058 this is either the same as SATISFY, or 0. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1059 static int
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1060 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
1061 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
1062 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
1063 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
1064 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
1065 int pass_next = 0;
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1066
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1067 size_t text_len = text.length ();
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1068
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1069 size_t i = indx;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1070
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1071 for (; i < text_len; i++)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1072 {
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1073 c = text[i];
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1074
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1075 if (pass_next)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1076 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1077 pass_next = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1078 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1079 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1080
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1081 /* 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
1082 escape the quote character in a double-quoted string. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1083 if (c == '\\' && (quoted == 0 || quoted == '"' || quoted == '`'))
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1084 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1085 pass_next = 1;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1086 continue;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1087 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1088
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1089 if (quoted)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1090 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1091 if (c == quoted)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1092 quoted = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1093 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1094 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1095
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1096 if (c == '"' || c == '\'' || c == '`')
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1097 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1098 quoted = c;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1099 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1100 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1101
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20791
diff changeset
1102 if (c == satisfy && ! level && ! quoted)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1103 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1104 /* 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
1105 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
1106 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
1107 if (c == '{'
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1108 && ((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
1109 && (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
1110 && (brace_whitespace (text[i+1]) || text[i+1] == '}'))))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1111 continue;
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1112 /* 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
1113 in a '${ }' construct */
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1114 if ((c != '{') || i == 0 || (text[i-1] != '$'))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1115 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1116 }
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1117
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1118 if (c == '{')
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1119 level++;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1120 else if (c == '}' && level)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1121 level--;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1122 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1123
4397
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1124 indx = i;
f682f9258271 [project @ 2003-04-29 03:06:08 by jwe]
jwe
parents: 4396
diff changeset
1125 return c;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1126 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1127
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1128 /* Expand extra colons. */
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1129
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1130 /* Check for leading colon first, then trailing, then doubled, since
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1131 that is fastest. Usually it will be leading or trailing. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1132
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1133 /* 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
1134 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
1135 DFLT may not be NULL. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1136
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
1137 std::string
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1138 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
1139 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1140 std::string expansion;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1141
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1142 size_t path_len = path.length ();
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1143
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1144 if (path_len == 0)
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1145 expansion = fallback;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1146
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1147 /* Solitary or leading :? */
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1148 else if (IS_ENV_SEP (path[0]))
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1149 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1150 expansion = path_len == 1 ? fallback : fallback + path;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1151 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1152
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1153 /* 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
1154 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
1155 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
1156 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
1157 such great length). */
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1158 else if (IS_ENV_SEP (path[path_len-1]))
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1159 expansion = path + fallback;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1160
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1161 /* OK, not leading or trailing. Check for doubled. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1162 else
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1163 {
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1164 /* What we'll return if we find none. */
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1165 expansion = path;
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1166
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1167 for (size_t i = 0; i < path_len; i++)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1168 {
4394
13619163e159 [project @ 2003-04-28 17:40:07 by jwe]
jwe
parents: 4393
diff changeset
1169 if (i + 1 < path_len
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1170 && 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
1171 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1172 /* We have a doubled colon. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1173
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1174 /* Copy stuff up to and including the first colon. */
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1175 /* 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
1176 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
1177
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1178 break;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1179 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1180 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1181 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1182
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1183 return expansion;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1184 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1185
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1186 /* 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
1187 false if not. */
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1188
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1189 static bool
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1190 dir_p (const std::string& fn)
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1191 {
21865
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1192 octave::sys::file_stat fs (fn);
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1193
0469ae203a1d more kpse.cc updates
John W. Eaton <jwe@octave.org>
parents: 21864
diff changeset
1194 return (fs && fs.is_dir ());
4390
c378263ef911 [project @ 2003-04-25 21:05:06 by jwe]
jwe
parents: 4389
diff changeset
1195 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1196
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1197 /* Given a path element ELT, return a the element with a trailing slash
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1198 or an empty string if the element is not a directory.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11501
diff changeset
1199
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1200 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
1201 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
1202 has already assumed expansion has been done. */
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1203
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
1204 std::string
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1205 kpse_element_dir (const std::string& elt)
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1206 {
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1207 std::string ret;
4378
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 /* If given nothing, return nothing. */
4398
cd8bf2c6797a [project @ 2003-04-29 04:21:01 by jwe]
jwe
parents: 4397
diff changeset
1210 if (elt.empty ())
21871
cab605836305 use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents: 21870
diff changeset
1211 return ret;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1212
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1213 if (dir_p (elt))
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1214 {
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1215 ret = elt;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1216
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1217 char last_char = ret[ret.length () - 1];
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1218
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1219 if (! (IS_DIR_SEP (last_char) || IS_DEVICE_SEP (last_char)))
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21872
diff changeset
1220 ret += DIR_SEP_STRING;
4378
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1221 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1222
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1223 return ret;
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1224 }
7d48a8fba1d4 [project @ 2003-04-19 00:03:47 by jwe]
jwe
parents:
diff changeset
1225
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4398
diff changeset
1226 /* Variable expansion. */
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1227
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1228 /* 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
1229 constructs like TEXINPUTS = $TEXINPUTS result in an infinite loop.
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1230 (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
1231 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
1232 before expanding. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1233
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1234 static std::map <std::string, bool> expansions;
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1235
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1236 static void
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1237 expanding (const std::string& var, bool xp)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1238 {
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1239 expansions[var] = xp;
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1240 }
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1241
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1242 /* Return whether VAR is currently being expanding. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1243
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1244 static bool
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1245 expanding_p (const std::string& var)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1246 {
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1247 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
1248 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1249
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1250 /* 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
1251 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
1252 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
1253
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1254 static void
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1255 expand (std::string &expansion, const std::string& var)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1256 {
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1257 if (expanding_p (var))
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1258 {
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1259 (*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
1260 ("Octave:pathsearch-syntax",
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
1261 "pathsearch: variable '%s' references itself (eventually)",
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1262 var.c_str ());
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1263 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1264 else
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1265 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1266 /* Check for an environment variable. */
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21729
diff changeset
1267 std::string value = octave::sys::env::getenv (var);
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1268
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1269 if (! value.empty ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1270 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1271 expanding (var, true);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1272 std::string tmp = kpse_var_expand (value);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1273 expanding (var, false);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1274 expansion += tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1275 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1276 }
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1277 }
4392
dd108fa566fa [project @ 2003-04-26 17:00:24 by jwe]
jwe
parents: 4391
diff changeset
1278
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1279 /* 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
1280 diagnostic messages assume them), but ... */
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
1281
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1282 /* starts all variable references */
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
1283 #if ! defined (IS_VAR_START)
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
1284 # define IS_VAR_START(c) ((c) == '$')
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1285 #endif
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
1286
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1287 /* variable name constituent */
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
1288 #if ! defined (IS_VAR_CHAR)
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
1289 # define IS_VAR_CHAR(c) (isalnum (c) || (c) == '_')
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1290 #endif
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
1291
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1292 /* start delimited variable name (after $) */
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
1293 #if ! defined (IS_VAR_BEGIN_DELIMITER)
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
1294 # define IS_VAR_BEGIN_DELIMITER(c) ((c) == '{')
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1295 #endif
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
1296
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
1297 #if ! defined (IS_VAR_END_DELIMITER)
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21874
diff changeset
1298 # define IS_VAR_END_DELIMITER(c) ((c) == '}')
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1299 #endif
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1300
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1301 /* 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
1302 constructs, especially ${var-value}. */
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1303
5085
6861a84b1d47 [project @ 2004-11-19 03:26:32 by jwe]
jwe
parents: 4928
diff changeset
1304 static std::string
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1305 kpse_var_expand (const std::string& src)
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1306 {
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1307 std::string expansion;
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1308
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1309 size_t src_len = src.length ();
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1310
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1311 /* Copy everything but variable constructs. */
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1312 for (size_t i = 0; i < src_len; i++)
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1313 {
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1314 if (IS_VAR_START (src[i]))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1315 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1316 i++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1317
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14155
diff changeset
1318 /* Three cases: '$VAR', '${VAR}', '$<anything-else>'. */
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1319 if (IS_VAR_CHAR (src[i]))
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 /* $V: collect name constituents, then expand. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1322 size_t var_end = i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1323
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1324 do
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1325 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1326 var_end++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1327 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1328 while (IS_VAR_CHAR (src[var_end]));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1329
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1330 var_end--; /* had to go one past */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1331 expand (expansion, src.substr (i, var_end - i + 1));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1332 i = var_end;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1333
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1334 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1335 else if (IS_VAR_BEGIN_DELIMITER (src[i]))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1336 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1337 /* ${: scan ahead for matching delimiter, then expand. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1338 size_t var_end = ++i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1339
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20791
diff changeset
1340 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
1341 var_end++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1342
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1343 if (var_end == src_len)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1344 {
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1345 (*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
1346 ("Octave:pathsearch-syntax",
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1347 "%s: No matching } for ${", src.c_str ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1348 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
1349 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1350 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1351 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1352 expand (expansion, src.substr (i, var_end - i));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1353 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
1354 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1355 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1356 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1357 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1358 /* $<something-else>: error. */
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1359 (*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
1360 ("Octave:pathsearch-syntax",
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
1361 "%s: Unrecognized variable construct '$%c'",
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1362 src.c_str (), src[i]);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1363
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1364 /* Just ignore those chars and keep going. */
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1365 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1366 }
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1367 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1368 expansion += src[i];
4391
17530e977bec [project @ 2003-04-26 04:50:12 by jwe]
jwe
parents: 4390
diff changeset
1369 }
4389
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1370
fa9f6dde6c24 [project @ 2003-04-25 04:45:56 by jwe]
jwe
parents: 4386
diff changeset
1371 return expansion;
4385
de8c1d2ee728 [project @ 2003-04-24 03:27:41 by jwe]
jwe
parents: 4379
diff changeset
1372 }