Mercurial > octave
annotate liboctave/util/kpse.cc @ 21724:aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
* configure.ac, Doxyfile.in, make_int.cc, Backend.cc, BaseControl.cc,
ButtonControl.cc, Canvas.cc, CheckBoxControl.cc, Container.cc,
ContextMenu.cc, EditControl.cc, Figure.cc, FigureWindow.cc,
GLCanvas.cc, KeyMap.cc, ListBoxControl.cc, Logger.cc, Menu.cc,
MouseModeActionGroup.cc, Object.cc, ObjectFactory.cc,
ObjectProxy.cc, Panel.cc, PopupMenuControl.cc, PushButtonControl.cc,
PushTool.cc, QtHandlesUtils.cc, RadioButtonControl.cc,
SliderControl.cc, TextControl.cc, TextEdit.cc,
ToggleButtonControl.cc, ToggleTool.cc, ToolBar.cc, __init_qt__.cc,
annotation-dialog.cc, gl-select.cc, module.mk, color-picker.cc,
dialog.cc, documentation-dock-widget.cc, files-dock-widget.cc,
find-files-dialog.cc, find-files-model.cc, history-dock-widget.cc,
liboctgui-build-info.in.cc, file-editor-tab.cc, file-editor.cc,
find-dialog.cc, marker.cc, marker.h, octave-qscintilla.cc,
octave-txt-lexer.cc, main-window.cc, octave-cmd.cc,
octave-dock-widget.cc, octave-gui.cc, octave-interpreter.cc,
octave-qt-link.cc, parser.cc, webinfo.cc, resource-manager.cc,
settings-dialog.cc, shortcut-manager.cc, terminal-dock-widget.cc,
thread-manager.cc, welcome-wizard.cc, workspace-model.cc,
workspace-view.cc, build-env.in.cc, Cell.cc, __contourc__.cc,
__dispatch__.cc, __dsearchn__.cc, __ichol__.cc, __ilu__.cc,
__lin_interpn__.cc, __luinc__.cc, __magick_read__.cc,
__pchip_deriv__.cc, __qp__.cc, balance.cc, besselj.cc, betainc.cc,
bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h,
cdisplay.c, cdisplay.h, cellfun.cc, coct-hdf5-types.c, colloc.cc,
comment-list.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc,
debug.cc, defaults.cc, defaults.in.h, defun.cc, det.cc, dirfns.cc,
display.cc, dlmread.cc, dot.cc, dynamic-ld.cc, eig.cc, ellipj.cc,
error.cc, errwarn.cc, event-queue.cc, fft.cc, fft2.cc, fftn.cc,
file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, gammainc.cc,
gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc,
gl-render.cc, gl2ps-print.cc, graphics.cc, gripes.cc, hash.cc,
help.cc, hess.cc, hex2num.cc, input.cc, inv.cc, jit-ir.cc, jit-ir.h,
jit-typeinfo.cc, jit-typeinfo.h, jit-util.cc, jit-util.h, kron.cc,
load-path.cc, load-save.cc, lookup.cc, ls-ascii-helper.cc,
ls-hdf5.cc, ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc,
ls-oct-binary.cc, ls-oct-text.cc, ls-oct-text.h, ls-utils.cc,
lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex.cc, mex.h,
mexproto.h, mgorth.cc, nproc.cc, oct-errno.in.cc, oct-fstrm.cc,
oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-iostrm.cc,
oct-lvalue.cc, oct-map.cc, oct-prcstrm.cc, oct-procbuf.cc,
oct-stdstrm.h, oct-stream.cc, oct-strstrm.cc, oct-tex-lexer.in.ll,
oct-tex-parser.in.yy, octave-link.cc, ordschur.cc, pager.cc,
pinv.cc, pr-output.cc, procstream.cc, profiler.cc, psi.cc,
pt-jit.cc, pt-jit.h, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc,
regexp.cc, schur.cc, sighandlers.cc, sighandlers.h, siglist.c,
siglist.h, sparse-xdiv.cc, sparse-xpow.cc, sparse.cc, spparms.cc,
sqrtm.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc,
sylvester.cc, symtab.cc, syscalls.cc, sysdep.cc, text-renderer.cc,
time.cc, toplev.cc, tril.cc, tsearch.cc, txt-eng.cc, typecast.cc,
urlwrite.cc, utils.cc, variables.cc, xdiv.cc, xgl2ps.c, xnorm.cc,
xpow.cc, zfstream.cc, zfstream.h, __delaunayn__.cc, __eigs__.cc,
__fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc,
audiodevinfo.cc, audioread.cc, ccolamd.cc, chol.cc, colamd.cc,
convhulln.cc, dmperm.cc, fftw.cc, qr.cc, symbfact.cc, symrcm.cc,
liboctinterp-build-info.in.cc, mkbuiltins, mkops, ov-base.cc,
ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.cc,
ov-cell.cc, ov-ch-mat.cc, ov-class.cc, ov-classdef.cc, ov-colon.cc,
ov-complex.cc, ov-cs-list.cc, ov-cx-diag.cc, ov-cx-mat.cc,
ov-cx-sparse.cc, ov-dld-fcn.cc, ov-fcn-handle.cc, ov-fcn-inline.cc,
ov-fcn.cc, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc,
ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-int16.cc,
ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-java.cc, ov-lazy-idx.cc,
ov-mex-fcn.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-perm.cc,
ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc,
ov-scalar.cc, ov-str-mat.cc, ov-struct.cc, ov-typeinfo.cc,
ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc,
ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ovl.cc, octave.cc, octave.h,
op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc,
op-bm-sbm.cc, op-cdm-cdm.cc, op-cdm-cm.cc, op-cdm-dm.cc,
op-cdm-m.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cdm.cc,
op-cm-cm.cc, op-cm-cs.cc, op-cm-dm.cc, op-cm-m.cc, op-cm-s.cc,
op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc,
op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-cdm.cc, op-dm-cm.cc,
op-dm-dm.cc, op-dm-m.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dm-template.cc, op-dms-template.cc, op-double-conv.cc,
op-fcdm-fcdm.cc, op-fcdm-fcm.cc, op-fcdm-fdm.cc, op-fcdm-fm.cc,
op-fcm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fdm.cc,
op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc,
op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fcdm.cc, op-fdm-fcm.cc,
op-fdm-fdm.cc, op-fdm-fm.cc, op-float-conv.cc, op-fm-fcdm.cc,
op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fdm.cc, op-fm-fm.cc, op-fm-fs.cc,
op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc,
op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc,
op-int-conv.cc, op-m-cdm.cc, op-m-cm.cc, op-m-cs.cc, op-m-dm.cc,
op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-pm-pm.cc,
op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc,
op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc,
op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc,
op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc,
op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc,
op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc,
op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc,
lex.ll, oct-parse.in.yy, pt-arg-list.cc, pt-array-list.cc,
pt-assign.cc, pt-binop.cc, pt-bp.cc, pt-cbinop.cc, pt-cell.cc,
pt-check.cc, pt-classdef.cc, pt-cmd.cc, pt-colon.cc, pt-const.cc,
pt-decl.cc, pt-eval.cc, pt-except.cc, pt-exp.cc, pt-fcn-handle.cc,
pt-funcall.cc, pt-id.cc, pt-idx.cc, pt-jump.cc, pt-loop.cc,
pt-loop.h, pt-mat.cc, pt-misc.cc, pt-pr-code.cc, pt-select.cc,
pt-stmt.cc, pt-unop.cc, pt.cc, token.cc, Array-jit.cc, Array-tc.cc,
version.cc, Array-C.cc, Array-b.cc, Array-ch.cc, Array-d.cc,
Array-f.cc, Array-fC.cc, Array-i.cc, Array-idx-vec.cc, Array-s.cc,
Array-str.cc, Array-util.cc, Array-voidp.cc, Array.cc,
CColVector.cc, CDiagMatrix.cc, CMatrix.cc, CNDArray.cc,
CRowVector.cc, CSparse.cc, MArray-C.cc, MArray-d.cc, MArray-f.cc,
MArray-fC.cc, MArray-i.cc, MArray-s.cc, MSparse-C.cc, MSparse-d.cc,
MatrixType.cc, PermMatrix.cc, Range.cc, Sparse-C.cc, Sparse-b.cc,
Sparse-d.cc, boolMatrix.cc, boolNDArray.cc, boolSparse.cc,
chMatrix.cc, chNDArray.cc, dColVector.cc, dDiagMatrix.cc,
dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc, dim-vector.cc,
dim-vector.h, fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc,
fCNDArray.cc, fCRowVector.cc, fColVector.cc, fDiagMatrix.cc,
fMatrix.cc, fNDArray.cc, fRowVector.cc, idx-vector.cc,
int16NDArray.cc, int32NDArray.cc, int64NDArray.cc, int8NDArray.cc,
uint16NDArray.cc, uint32NDArray.cc, uint64NDArray.cc,
uint8NDArray.cc, Faddeeva.cc, blaswrap.c, cquit.c, f77-extern.cc,
f77-fcn.c, f77-fcn.h, lo-error.c, lo-error.h, quit.cc, quit.h,
liboctave-build-info.in.cc, CollocWt.cc, DASPK.cc, DASRT.cc,
DASSL.cc, EIG.cc, LSODE.cc, ODES.cc, Quad.cc, aepbalance.cc,
chol.cc, eigs-base.cc, fEIG.cc, gepbalance.cc, hess.cc,
lo-mappers.cc, lo-specfun.cc, lu.cc, oct-convn.cc, oct-fftw.cc,
oct-norm.cc, oct-rand.cc, oct-spparms.cc, qr.cc, qrp.cc,
randmtzig.cc, randpoisson.cc, schur.cc, sparse-chol.cc,
sparse-dmsolve.cc, sparse-lu.cc, sparse-qr.cc, svd.cc, mk-ops.awk,
mx-defs.h, dir-ops.cc, file-ops.cc, file-stat.cc, lo-sysdep.cc,
mach-info.cc, oct-env.cc, oct-group.cc, oct-passwd.cc,
oct-syscalls.cc, oct-time.cc, oct-uname.cc, pathlen.h, syswait.h,
cmd-edit.cc, cmd-hist.cc, data-conv.cc, f2c-main.c, glob-match.cc,
kpse.cc, lo-array-errwarn.cc, lo-array-gripes.cc, lo-cutils.c,
lo-cutils.h, lo-ieee.cc, lo-ieee.h, lo-regexp.cc, lo-utils.cc,
oct-base64.cc, oct-glob.cc, oct-inttypes.cc, oct-inttypes.h,
oct-locbuf.cc, oct-mutex.cc, oct-rl-edit.c, oct-rl-edit.h,
oct-rl-hist.c, oct-rl-hist.h, oct-shlib.cc, oct-sort.cc,
pathsearch.cc, singleton-cleanup.cc, sparse-sort.cc, sparse-util.cc,
statdefs.h, str-vec.cc, unwind-prot.cc, url-transfer.cc,
acinclude.m4, display-available.c, display-available.h, main-cli.cc,
main-gui.cc, main.in.cc, mkoctfile.in.cc, octave-build-info.in.cc,
octave-config.in.cc, shared-fcns.h:
Use "#if ..." consistently instead of "#ifdef" and "#ifndef".
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 17 May 2016 12:09:30 -0400 |
parents | b6a686543080 |
children | 815b2f500fab |
rev | line source |
---|---|
4399 | 1 // This file is not compiled to a separate object file. It is |
2 // included in pathsearch.cc. | |
3 | |
4 /* Look up a filename in a path. | |
4378 | 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 | 7 Copyright (C) 1993, 94, 95, 96, 97, 98 Karl Berry. |
4378 | 8 Copyright (C) 1993, 94, 95, 96, 97 Karl Berry & O. Weber. |
4399 | 9 Copyright (C) 1992, 93, 94, 95, 96, 97 Free Software Foundation, Inc. |
4378 | 10 |
16768 | 11 This file is part of Octave. |
12 | |
13 Octave is free software; you can redistribute it and/or modify it | |
14 under the terms of the GNU General Public License as published by the | |
15 Free Software Foundation; either version 3 of the License, or (at your | |
16 option) any later version. | |
17 | |
18 Octave is distributed in the hope that it will be useful, but WITHOUT | |
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
21 for more details. | |
22 | |
23 You should have received a copy of the GNU General Public License | |
24 along with Octave; see the file COPYING. If not, see | |
25 <http://www.gnu.org/licenses/>. | |
26 | |
27 */ | |
4378 | 28 |
21690
b6a686543080
Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
29 // This file should not include config.h. It is only included in other |
b6a686543080
Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
30 // C++ source files that should have included config.h before including |
b6a686543080
Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
31 // this file. |
4378 | 32 |
4390 | 33 #include <map> |
4389 | 34 #include <string> |
35 | |
4399 | 36 /* System defines are for non-Unix systems only. (Testing for all Unix |
37 variations should be done in configure.) Presently the defines used | |
38 are: DOS OS2 WIN32. I do not use any of these systems | |
39 myself; if you do, I'd be grateful for any changes. --kb@mail.tug.org */ | |
40 | |
41 /* If we have either DOS or OS2, we are DOSISH. */ | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14155
diff
changeset
|
42 #if defined (DOS) || defined (OS2) || defined (WIN32) || defined (__MSDOS__) |
4399 | 43 #define DOSISH |
44 #endif | |
45 | |
46 #if defined (DOSISH) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
47 #define MONOCASE_FILENAMES /* case-insensitive filename comparisons */ |
4399 | 48 #endif |
49 | |
50 extern "C" { | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14155
diff
changeset
|
51 #if defined (__MINGW32__) |
4399 | 52 #include <windows.h> |
53 #include <fcntl.h> | |
54 #include <dirent.h> | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14155
diff
changeset
|
55 #elif defined (WIN32) |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
56 #if ! defined (_MSC_VER) |
4399 | 57 #define __STDC__ 1 |
58 #include "win32lib.h" | |
6106 | 59 #endif |
4399 | 60 #endif /* not WIN32 */ |
61 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
62 #if defined (__DJGPP__) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
63 #include <fcntl.h> /* for long filenames' stuff */ |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
64 #include <dir.h> /* for 'getdisk' */ |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
65 #include <io.h> /* for 'setmode' */ |
4399 | 66 #endif |
67 } | |
68 | |
69 /* Some drivers have partially integrated kpathsea changes. */ | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
70 #if ! defined (KPATHSEA) |
4399 | 71 #define KPATHSEA 32 |
72 #endif | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
73 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
74 /* System dependencies that are figured out by 'configure'. If we are |
4399 | 75 compiling standalone, we get our c-auto.h. Otherwise, the package |
76 containing us must provide this (unless it can somehow generate ours | |
77 from c-auto.in). We use <...> instead of "..." so that the current | |
78 cpp directory (i.e., kpathsea/) won't be searched. */ | |
79 | |
80 /* If you want to find subdirectories in a directory with non-Unix | |
81 semantics (specifically, if a directory with no subdirectories does | |
5622 | 82 not have exactly two links), define this. */ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14155
diff
changeset
|
83 #if defined (__DJGPP__) || ! defined (DOSISH) |
4399 | 84 /* Surprise! DJGPP returns st_nlink exactly like on Unix. */ |
85 #define ST_NLINK_TRICK | |
86 #endif /* either not DOSISH or __DJGPP__ */ | |
87 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
88 #if defined (OS2) |
4399 | 89 #define access ln_access |
90 #define fopen ln_fopen | |
91 #define rename ln_rename | |
92 #define stat ln_stat | |
93 #endif /* OS2 */ | |
94 | |
11236 | 95 /* Define the characters which separate components of |
96 filenames and environment variable paths. */ | |
97 | |
98 /* What separates filename components? */ | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
99 #if ! defined (DIR_SEP) |
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
100 #if defined (DOSISH) |
11236 | 101 /* Either \'s or 's work. Wayne Sullivan's web2pc prefers /, so we'll |
102 go with that. */ | |
103 #define DIR_SEP '/' | |
104 #define DIR_SEP_STRING "/" | |
105 #define IS_DEVICE_SEP(ch) ((ch) == ':') | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14155
diff
changeset
|
106 #define NAME_BEGINS_WITH_DEVICE(name) ((name.length ()>0) && IS_DEVICE_SEP((name)[1])) |
11236 | 107 /* On DOS, it's good to allow both \ and / between directories. */ |
108 #define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\') | |
109 #else | |
110 #define DIR_SEP '/' | |
111 #define DIR_SEP_STRING "/" | |
112 #endif /* not DOSISH */ | |
113 #endif /* not DIR_SEP */ | |
114 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
115 #if ! defined (IS_DIR_SEP) |
11236 | 116 #define IS_DIR_SEP(ch) ((ch) == DIR_SEP) |
117 #endif | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
118 #if ! defined (IS_DEVICE_SEP) |
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
119 /* No 'devices' on, e.g., Unix. */ |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
120 #define IS_DEVICE_SEP(ch) 0 |
11236 | 121 #endif |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
122 #if ! defined (NAME_BEGINS_WITH_DEVICE) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
123 #define NAME_BEGINS_WITH_DEVICE(name) 0 |
11236 | 124 #endif |
4378 | 125 |
4396 | 126 #include "lo-error.h" |
4391 | 127 #include "oct-env.h" |
128 #include "oct-passwd.h" | |
4399 | 129 #include "str-vec.h" |
4385 | 130 |
131 /* Header files that essentially all of our sources need, and | |
132 that all implementations have. We include these first, to help with | |
133 NULL being defined multiple times. */ | |
134 #include <cstdio> | |
135 #include <cstdarg> | |
136 #include <cstdlib> | |
137 #include <cerrno> | |
138 #include <cassert> | |
139 | |
140 #include <sys/types.h> | |
141 #include <unistd.h> | |
142 | |
143 #include "sysdir.h" | |
144 #include "statdefs.h" | |
145 | |
146 /* define NAME_MAX, the maximum length of a single | |
147 component in a filename. No such limit may exist, or may vary | |
148 depending on the filesystem. */ | |
149 | |
150 /* Most likely the system will truncate filenames if it is not POSIX, | |
151 and so we can use the BSD value here. */ | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
152 #if ! defined (_POSIX_NAME_MAX) |
4385 | 153 #define _POSIX_NAME_MAX 255 |
154 #endif | |
155 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
156 #if ! defined (NAME_MAX) |
4385 | 157 #define NAME_MAX _POSIX_NAME_MAX |
158 #endif | |
159 | |
160 #include <cctype> | |
161 | |
162 /* What separates elements in environment variable path lists? */ | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
163 #if ! defined (ENV_SEP) |
5451 | 164 #if defined (SEPCHAR) && defined (SEPCHAR_STR) |
165 #define ENV_SEP SEPCHAR | |
166 #define ENV_SEP_STRING SEPCHAR_STR | |
167 #elif defined (DOSISH) | |
4385 | 168 #define ENV_SEP ';' |
169 #define ENV_SEP_STRING ";" | |
170 #else | |
171 #define ENV_SEP ':' | |
172 #define ENV_SEP_STRING ":" | |
173 #endif /* not DOS */ | |
174 #endif /* not ENV_SEP */ | |
175 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
176 #if ! defined (IS_ENV_SEP) |
4385 | 177 #define IS_ENV_SEP(ch) ((ch) == ENV_SEP) |
178 #endif | |
179 | |
4399 | 180 /* define PATH_MAX, the maximum length of a filename. Since no such |
181 limit may exist, it's preferable to dynamically grow filenames as | |
182 needed. */ | |
4385 | 183 |
184 /* Cheat and define this as a manifest constant no matter what, instead | |
185 of using pathconf. I forget why we want to do this. */ | |
186 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
187 #if ! defined (_POSIX_PATH_MAX) |
4385 | 188 #define _POSIX_PATH_MAX 255 |
189 #endif | |
190 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
191 #if ! defined (PATH_MAX) |
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
192 #if defined (MAXPATHLEN) |
4385 | 193 #define PATH_MAX MAXPATHLEN |
194 #else | |
195 #define PATH_MAX _POSIX_PATH_MAX | |
196 #endif | |
197 #endif /* not PATH_MAX */ | |
198 | |
199 /* 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
|
200 #if ! defined (NO_DEBUG) |
4385 | 201 |
202 /* OK, we'll have tracing support. */ | |
203 #define KPSE_DEBUG | |
204 | |
205 /* Test if a bit is on. */ | |
206 #define KPSE_DEBUG_P(bit) (kpathsea_debug & (1 << (bit))) | |
207 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
208 #define KPSE_DEBUG_STAT 0 /* stat calls */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
209 #define KPSE_DEBUG_HASH 1 /* hash lookups */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
210 #define KPSE_DEBUG_FOPEN 2 /* fopen/fclose calls */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
211 #define KPSE_DEBUG_PATHS 3 /* search path initializations */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
212 #define KPSE_DEBUG_EXPAND 4 /* path element expansion */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
213 #define KPSE_DEBUG_SEARCH 5 /* searches */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
214 #define KPSE_DEBUG_VARS 6 /* variable values */ |
4385 | 215 #define KPSE_LAST_DEBUG KPSE_DEBUG_VARS |
216 | |
217 /* A printf for the debugging. */ | |
10411 | 218 #define DEBUGF_START() do { gnulib::fputs ("kdebug:", stderr) |
12912
e116dd862879
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
219 #define DEBUGF_END() gnulib::fflush (stderr); } while (0) |
4385 | 220 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
221 #define DEBUGF(str) \ |
10411 | 222 DEBUGF_START (); gnulib::fputs (str, stderr); DEBUGF_END () |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
223 #define DEBUGF1(str, e1) \ |
10411 | 224 DEBUGF_START (); gnulib::fprintf (stderr, str, e1); DEBUGF_END () |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
225 #define DEBUGF2(str, e1, e2) \ |
10411 | 226 DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2); DEBUGF_END () |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
227 #define DEBUGF3(str, e1, e2, e3) \ |
10411 | 228 DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2, e3); DEBUGF_END () |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
229 #define DEBUGF4(str, e1, e2, e3, e4) \ |
10411 | 230 DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2, e3, e4); DEBUGF_END () |
4385 | 231 |
232 #endif /* not NO_DEBUG */ | |
233 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
234 #if defined (KPSE_DEBUG) |
4399 | 235 static unsigned int kpathsea_debug = 0; |
236 #endif | |
237 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20443
diff
changeset
|
238 #if defined (WIN32) && ! defined (__MINGW32__) |
4385 | 239 |
240 /* System description file for Windows NT. */ | |
241 | |
242 /* | |
243 * Define symbols to identify the version of Unix this is. | |
244 * Define all the symbols that apply correctly. | |
245 */ | |
246 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
247 #if ! defined (DOSISH) |
4385 | 248 #define DOSISH |
249 #endif | |
250 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
251 #if ! defined (MAXPATHLEN) |
4385 | 252 #define MAXPATHLEN _MAX_PATH |
4378 | 253 #endif |
254 | |
4385 | 255 /* These have to be defined because our compilers treat __STDC__ as being |
256 defined (most of them anyway). */ | |
257 | |
258 #define access _access | |
259 #define stat _stat | |
260 #define strdup _strdup | |
261 | |
262 #define S_IFMT _S_IFMT | |
263 #define S_IFDIR _S_IFDIR | |
264 | |
265 /* Define this so that winsock.h definitions don't get included when | |
266 windows.h is... For this to have proper effect, config.h must | |
4391 | 267 always be included before windows.h. */ |
4385 | 268 #define _WINSOCKAPI_ 1 |
269 | |
270 #include <windows.h> | |
271 | |
272 /* For proper declaration of environ. */ | |
273 #include <io.h> | |
274 #include <fcntl.h> | |
275 #include <process.h> | |
276 | |
277 /* ============================================================ */ | |
278 | |
279 #endif /* WIN32 */ | |
280 | |
281 /* Define common sorts of messages. */ | |
282 | |
283 /* This should be called only after a system call fails. Don't exit | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
284 with status 'errno', because that might be 256, which would mean |
4385 | 285 success (exit statuses are truncated to eight bits). */ |
4396 | 286 #define FATAL_PERROR(str) \ |
287 do \ | |
288 { \ | |
10411 | 289 gnulib::fputs ("pathsearch: ", stderr); \ |
4396 | 290 perror (str); exit (EXIT_FAILURE); \ |
291 } \ | |
292 while (0) | |
293 | |
294 #define FATAL(str) \ | |
295 do \ | |
296 { \ | |
10411 | 297 gnulib::fputs ("pathsearch: fatal: ", stderr); \ |
298 gnulib::fputs (str, stderr); \ | |
299 gnulib::fputs (".\n", stderr); \ | |
4396 | 300 exit (1); \ |
301 } \ | |
302 while (0) | |
4385 | 303 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
304 #if ! defined (WIN32) |
4385 | 305 static void xclosedir (DIR *d); |
4386 | 306 #endif |
4385 | 307 |
4399 | 308 /* It's a little bizarre to be using the same type for the list and the |
309 elements of the list, but no reason not to in this case, I think -- | |
310 we never need a NULL string in the middle of the list, and an extra | |
311 NULL/NULL element always at the end is inconsequential. */ | |
312 | |
313 struct str_llist_elt | |
314 { | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
315 str_llist_elt (void) : str (), moved (0), next (0) { } |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
316 |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
317 ~str_llist_elt (void) { } |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
318 |
4399 | 319 std::string str; |
320 int moved; | |
321 struct str_llist_elt *next; | |
322 }; | |
323 | |
324 typedef str_llist_elt str_llist_elt_type; | |
325 typedef str_llist_elt *str_llist_type; | |
326 | |
327 #define STR_LLIST(sl) ((sl).str) | |
328 #define STR_LLIST_MOVED(sl) ((sl).moved) | |
329 #define STR_LLIST_NEXT(sl) ((sl).next) | |
330 | |
4390 | 331 static void str_llist_add (str_llist_type *l, const std::string& str); |
4385 | 332 |
333 static void str_llist_float (str_llist_type *l, str_llist_elt_type *mover); | |
334 | |
4389 | 335 static std::string kpse_var_expand (const std::string& src); |
4385 | 336 |
4399 | 337 static str_llist_type *kpse_element_dirs (const std::string& elt); |
338 | |
339 static std::string kpse_expand (const std::string& s); | |
340 | |
341 static std::string kpse_expand_default (const std::string& path, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
342 const std::string& dflt); |
4399 | 343 |
344 static string_vector kpse_db_search (const std::string& name, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
345 const std::string& path_elt, bool all); |
4399 | 346 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
347 #include <ctime> /* for 'time' */ |
4385 | 348 |
4399 | 349 static bool |
4394 | 350 kpse_is_env_sep (char c) |
351 { | |
352 return IS_ENV_SEP (c); | |
353 } | |
354 | |
4392 | 355 /* These routines just check the return status from standard library |
356 routines and abort if an error happens. */ | |
357 | |
358 static FILE * | |
4393 | 359 xfopen (const std::string& filename, const char *mode) |
4392 | 360 { |
361 FILE *f; | |
362 | |
4393 | 363 assert (! filename.empty () && mode); |
364 | |
14153 | 365 f = gnulib::fopen (filename.c_str (), mode); |
4393 | 366 |
367 if (! f) | |
368 FATAL_PERROR (filename.c_str ()); | |
4392 | 369 |
14153 | 370 if (KPSE_DEBUG_P (KPSE_DEBUG_FOPEN)) |
371 DEBUGF3 ("fopen (%s, %s) => 0x%lx\n", filename.c_str (), mode, | |
16314
0723ea02dcdb
use intptr_t instead of long
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
372 reinterpret_cast<intptr_t> (f)); |
14153 | 373 |
4392 | 374 return f; |
375 } | |
376 | |
377 /* A single (key,value) pair. */ | |
378 | |
379 struct hash_element_type | |
380 { | |
381 std::string key; | |
382 std::string value; | |
383 struct hash_element_type *next; | |
384 }; | |
385 | |
386 /* The usual arrangement of buckets initialized to null. */ | |
387 | |
388 struct hash_table_type | |
389 { | |
390 hash_element_type **buckets; | |
391 unsigned size; | |
392 }; | |
393 | |
394 static unsigned | |
5764 | 395 kpse_hash (hash_table_type table, const std::string& key) |
4392 | 396 { |
397 unsigned n = 0; | |
398 | |
399 /* Our keys aren't often anagrams of each other, so no point in | |
400 weighting the characters. */ | |
401 size_t len = key.length (); | |
402 for (size_t i = 0; i < len; i++) | |
4394 | 403 n = (n + n + key[i]) % table.size; |
4392 | 404 |
405 return n; | |
406 } | |
407 | |
408 /* Look up STR in MAP. Return a (dynamically-allocated) list of the | |
409 corresponding strings or NULL if no match. */ | |
410 | |
411 static string_vector | |
412 hash_lookup (hash_table_type table, const std::string& key) | |
413 { | |
414 hash_element_type *p; | |
415 string_vector ret; | |
5764 | 416 unsigned n = kpse_hash (table, key); |
4392 | 417 |
418 /* Look at everything in this bucket. */ | |
4398 | 419 for (p = table.buckets[n]; p; p = p->next) |
4394 | 420 if (key == p->key) |
4392 | 421 ret.append (p->value); |
422 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
423 #if defined (KPSE_DEBUG) |
4392 | 424 if (KPSE_DEBUG_P (KPSE_DEBUG_HASH)) |
425 { | |
426 DEBUGF1 ("hash_lookup (%s) =>", key.c_str ()); | |
427 if (ret.empty ()) | |
10411 | 428 gnulib::fputs (" (nil)\n", stderr); |
4392 | 429 else |
430 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20017
diff
changeset
|
431 int len = ret.numel (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
432 for (int i = 0; i < len; i++) |
4392 | 433 { |
10411 | 434 gnulib::putc (' ', stderr); |
435 gnulib::fputs (ret[i].c_str (), stderr); | |
4392 | 436 } |
10411 | 437 gnulib::putc ('\n', stderr); |
4392 | 438 } |
12912
e116dd862879
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
439 gnulib::fflush (stderr); |
4392 | 440 } |
441 #endif | |
442 | |
443 return ret; | |
444 } | |
445 | |
4399 | 446 /* A way to step through a path, extracting one directory name at a |
447 time. */ | |
448 | |
449 class kpse_path_iterator | |
450 { | |
451 public: | |
452 | |
453 kpse_path_iterator (const std::string& p) | |
454 : path (p), b (0), e (0), len (path.length ()) { set_end (); } | |
455 | |
456 kpse_path_iterator (const kpse_path_iterator& pi) | |
457 : path (pi.path), b (pi.b), e (pi.e), len (pi.len) { } | |
458 | |
459 kpse_path_iterator operator ++ (int) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
460 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
461 kpse_path_iterator retval (*this); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
462 next (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
463 return retval; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
464 } |
4399 | 465 |
466 std::string operator * (void) { return path.substr (b, e-b); } | |
467 | |
468 bool operator != (const size_t sz) { return b != sz; } | |
469 | |
470 private: | |
471 | |
472 const std::string& path; | |
473 size_t b; | |
474 size_t e; | |
475 size_t len; | |
476 | |
477 void set_end (void) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
478 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
479 e = b + 1; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
480 |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
481 if (e == len) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
482 ; /* OK, we have found the last element. */ |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
483 else if (e > len) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
484 b = e = std::string::npos; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
485 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
486 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
487 /* Find the next colon not enclosed by braces (or the end of |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
488 the path). */ |
20443
610c74748518
maint: Clean up code based on static analysis suggestions.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
489 while (e < len && ! kpse_is_env_sep (path[e])) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
490 e++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
491 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
492 } |
4399 | 493 |
494 void next (void) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
495 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
496 b = e + 1; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
497 |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
498 /* Skip any consecutive colons. */ |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
499 while (b < len && kpse_is_env_sep (path[b])) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
500 b++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
501 |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
502 if (b >= len) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
503 b = e = std::string::npos; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
504 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
505 set_end (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
506 } |
5617 | 507 |
508 // No assignment. | |
509 kpse_path_iterator& operator = (const kpse_path_iterator&); | |
4399 | 510 }; |
511 | |
4391 | 512 /* Here's the simple one, when a program just wants a value. */ |
513 | |
514 static std::string | |
515 kpse_var_value (const std::string& var) | |
516 { | |
517 std::string ret; | |
518 | |
519 std::string tmp = octave_env::getenv (var); | |
520 | |
521 if (! tmp.empty ()) | |
522 ret = kpse_var_expand (tmp); | |
523 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
524 #if defined (KPSE_DEBUG) |
4391 | 525 if (KPSE_DEBUG_P (KPSE_DEBUG_VARS)) |
526 DEBUGF2 ("variable: %s = %s\n", var.c_str (), | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
527 tmp.empty () ? "(nil)" : tmp.c_str ()); |
4391 | 528 #endif |
529 | |
530 return ret; | |
531 } | |
532 | |
533 /* Truncate any too-long components in NAME, returning the result. It's | |
534 too bad this is necessary. See comments in readable.c for why. */ | |
535 | |
4393 | 536 static std::string |
537 kpse_truncate_filename (const std::string& name) | |
4391 | 538 { |
539 unsigned c_len = 0; /* Length of current component. */ | |
540 unsigned ret_len = 0; /* Length of constructed result. */ | |
541 | |
4393 | 542 std::string ret = name; |
543 | |
544 size_t len = name.length (); | |
545 | |
546 for (size_t i = 0; i < len; i++) | |
4391 | 547 { |
4393 | 548 if (IS_DIR_SEP (name[i]) || IS_DEVICE_SEP (name[i])) |
4391 | 549 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
550 /* At a directory delimiter, reset component length. */ |
4391 | 551 c_len = 0; |
552 } | |
553 else if (c_len > NAME_MAX) | |
554 { | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
555 /* If past the max for a component, ignore this character. */ |
4391 | 556 continue; |
557 } | |
558 | |
559 /* Copy this character. */ | |
4393 | 560 ret[ret_len++] = name[i]; |
4391 | 561 c_len++; |
562 } | |
563 | |
4393 | 564 ret.resize (ret_len); |
4391 | 565 |
566 return ret; | |
567 } | |
568 | |
569 /* If access can read FN, run stat (assigning to stat buffer ST) and | |
570 check that fn is not a directory. Don't check for just being a | |
571 regular file, as it is potentially useful to read fifo's or some | |
572 kinds of devices. */ | |
573 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
574 #if defined (WIN32) |
4391 | 575 static inline bool |
4393 | 576 READABLE (const std::string& fn, struct stat&) |
4391 | 577 { |
4393 | 578 const char *t = fn.c_str (); |
579 return (GetFileAttributes (t) != 0xFFFFFFFF | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
580 && ! (GetFileAttributes (t) & FILE_ATTRIBUTE_DIRECTORY)); |
4391 | 581 } |
582 #else | |
583 static inline bool | |
4393 | 584 READABLE (const std::string& fn, struct stat& st) |
4391 | 585 { |
4393 | 586 const char *t = fn.c_str (); |
587 return (access (t, R_OK) == 0 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
588 && stat (t, &(st)) == 0 && ! S_ISDIR (st.st_mode)); |
4391 | 589 } |
590 #endif | |
591 | |
592 /* POSIX invented the brain-damage of not necessarily truncating | |
593 filename components; the system's behavior is defined by the value of | |
594 the symbol _POSIX_NO_TRUNC, but you can't change it dynamically! | |
595 | |
596 Generic const return warning. See extend-fname.c. */ | |
597 | |
4393 | 598 static std::string |
599 kpse_readable_file (const std::string& name) | |
4391 | 600 { |
601 struct stat st; | |
4393 | 602 std::string ret; |
4391 | 603 |
604 if (READABLE (name, st)) | |
605 { | |
4393 | 606 ret = name; |
4391 | 607 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
608 #if defined (ENAMETOOLONG) |
4391 | 609 } |
610 else if (errno == ENAMETOOLONG) | |
611 { | |
612 ret = kpse_truncate_filename (name); | |
613 | |
614 /* 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
|
615 so let's call access again. */ |
4391 | 616 |
617 if (! READABLE (ret, st)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
618 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
619 /* Failed. */ |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
620 ret = ""; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
621 } |
4391 | 622 #endif /* ENAMETOOLONG */ |
623 | |
624 } | |
625 else | |
626 { | |
627 /* Some other error. */ | |
628 if (errno == EACCES) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
629 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
630 /* Maybe warn them if permissions are bad. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
631 perror (name.c_str ()); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
632 } |
4393 | 633 |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
634 ret = ""; |
4391 | 635 } |
636 | |
637 return ret; | |
638 } | |
639 | |
640 /* Sorry this is such a system-dependent mess, but I can't see any way | |
641 to usefully generalize. */ | |
642 | |
643 static bool | |
644 kpse_absolute_p (const std::string& filename, int relative_ok) | |
645 { | |
646 size_t len = filename.length (); | |
647 | |
4409 | 648 int absolute = (len > 0 && IS_DIR_SEP (filename[0])) |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
649 #if defined (DOSISH) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
650 /* Novell allows non-alphanumeric drive letters. */ |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
651 || (len > 0 && IS_DEVICE_SEP (filename[1])) |
4391 | 652 #endif /* DOSISH */ |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
653 #if defined (WIN32) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
654 /* UNC names */ |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
655 || (len > 1 && filename[0] == '\\' && filename[1] == '\\') |
4391 | 656 #endif |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
657 ; |
4409 | 658 |
4391 | 659 int explicit_relative |
660 = relative_ok | |
661 && (len > 1 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
662 && filename[0] == '.' |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
663 && (IS_DIR_SEP (filename[1]) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
664 || (len > 2 && filename[1] == '.' && IS_DIR_SEP (filename[2])))); |
4391 | 665 |
666 return absolute || explicit_relative; | |
667 } | |
668 | |
4378 | 669 /* The very first search is for texmf.cnf, called when someone tries to |
670 initialize the TFM path or whatever. init_path calls kpse_cnf_get | |
671 which calls kpse_all_path_search to find all the texmf.cnf's. We | |
672 need to do various special things in this case, since we obviously | |
673 don't yet have the configuration files when we're searching for the | |
674 configuration files. */ | |
675 static bool first_search = true; | |
676 | |
677 /* This function is called after every search (except the first, since | |
678 we definitely want to allow enabling the logging in texmf.cnf) to | |
679 record the filename(s) found in $TEXMFLOG. */ | |
680 | |
681 static void | |
4391 | 682 log_search (const string_vector& filenames) |
4378 | 683 { |
4398 | 684 static FILE *log_file = 0; |
4378 | 685 static bool first_time = true; /* Need to open the log file? */ |
4391 | 686 |
687 if (first_time) | |
688 { | |
689 first_time = false; | |
690 | |
691 /* Get name from either envvar or config file. */ | |
692 std::string log_name = kpse_var_value ("TEXMFLOG"); | |
693 | |
694 if (! log_name.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
695 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
696 log_file = xfopen (log_name.c_str (), "a"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
697 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
698 if (! log_file) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
699 perror (log_name.c_str ()); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
700 } |
4378 | 701 } |
4391 | 702 |
703 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH) || log_file) | |
704 { | |
705 /* FILENAMES should never be null, but safety doesn't hurt. */ | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20017
diff
changeset
|
706 for (int e = 0; e < filenames.numel () && ! filenames[e].empty (); e++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
707 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
708 std::string filename = filenames[e]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
709 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
710 /* Only record absolute filenames, for privacy. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
711 if (log_file && kpse_absolute_p (filename.c_str (), false)) |
10411 | 712 gnulib::fprintf (log_file, "%lu %s\n", |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
713 static_cast<unsigned long> (time (0)), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
714 filename.c_str ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
715 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
716 /* And show them online, if debugging. We've already started |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
717 the debugging line in 'search', where this is called, so |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
718 just print the filename here, don't use DEBUGF. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
719 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) |
10411 | 720 gnulib::fputs (filename.c_str (), stderr); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
721 } |
4378 | 722 } |
723 } | |
4392 | 724 |
4378 | 725 /* Concatenate each element in DIRS with NAME (assume each ends with a |
726 /, to save time). If SEARCH_ALL is false, return the first readable | |
727 regular file. Else continue to search for more. In any case, if | |
728 none, return a list containing just NULL. | |
729 | |
730 We keep a single buffer for the potential filenames and reallocate | |
731 only when necessary. I'm not sure it's noticeably faster, but it | |
732 does seem cleaner. (We do waste a bit of space in the return | |
733 value, though, since we don't shrink it to the final size returned.) */ | |
734 | |
4390 | 735 static string_vector |
736 dir_list_search (str_llist_type *dirs, const std::string& name, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
737 bool search_all) |
4378 | 738 { |
739 str_llist_elt_type *elt; | |
4390 | 740 string_vector ret; |
4378 | 741 |
742 for (elt = *dirs; elt; elt = STR_LLIST_NEXT (*elt)) | |
743 { | |
4390 | 744 const std::string dir = STR_LLIST (*elt); |
4393 | 745 |
746 std::string potential = dir + name; | |
747 | |
748 std::string tmp = kpse_readable_file (potential); | |
749 | |
750 if (! tmp.empty ()) | |
4378 | 751 { |
4393 | 752 ret.append (potential); |
4391 | 753 |
4378 | 754 /* Move this element towards the top of the list. */ |
755 str_llist_float (dirs, elt); | |
4391 | 756 |
757 if (! search_all) | |
4378 | 758 return ret; |
759 } | |
760 } | |
4391 | 761 |
4378 | 762 return ret; |
763 } | |
4392 | 764 |
4378 | 765 /* This is called when NAME is absolute or explicitly relative; if it's |
766 readable, return (a list containing) it; otherwise, return NULL. */ | |
767 | |
4390 | 768 static string_vector |
4393 | 769 absolute_search (const std::string& name) |
4378 | 770 { |
4390 | 771 string_vector ret_list; |
4393 | 772 std::string found = kpse_readable_file (name); |
4391 | 773 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
774 /* Add 'found' to the return list even if it's null; that tells |
4378 | 775 the caller we didn't find anything. */ |
4394 | 776 ret_list.append (found); |
4391 | 777 |
4378 | 778 return ret_list; |
779 } | |
4392 | 780 |
4378 | 781 /* This is the hard case -- look for NAME in PATH. If ALL is false, |
782 return the first file found. Otherwise, search all elements of PATH. */ | |
783 | |
4390 | 784 static string_vector |
4394 | 785 path_search (const std::string& path, const std::string& name, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
786 bool /* must_exist */, bool all) |
4378 | 787 { |
4390 | 788 string_vector ret_list; |
4378 | 789 bool done = false; |
4390 | 790 |
8021 | 791 for (kpse_path_iterator pi (path); ! done && pi != std::string::npos; pi++) |
4390 | 792 { |
4394 | 793 std::string elt = *pi; |
794 | |
4390 | 795 string_vector found; |
796 bool allow_disk_search = true; | |
797 | |
4394 | 798 if (elt.length () > 1 && elt[0] == '!' && elt[1] == '!') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
799 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
800 /* Those magic leading chars in a path element means don't |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
801 search the disk for this elt. And move past the magic to |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
802 get to the name. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
803 allow_disk_search = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
804 elt = elt.substr (2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
805 } |
4390 | 806 |
807 /* Do not touch the device if present */ | |
808 if (NAME_BEGINS_WITH_DEVICE (elt)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
809 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
810 while (elt.length () > 3 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
811 && 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
|
812 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
813 elt[2] = elt[1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
814 elt[1] = elt[0]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
815 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
816 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
817 } |
4390 | 818 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
819 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
820 /* We never want to search the whole disk. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
821 while (elt.length () > 1 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
822 && 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
|
823 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
824 } |
4391 | 825 |
4390 | 826 /* Try ls-R, unless we're searching for texmf.cnf. Our caller |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
827 (search), also tests first_search, and does the resetting. */ |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
828 found = first_search ? string_vector () : kpse_db_search (name, elt, all); |
4390 | 829 |
830 /* Search the filesystem if (1) the path spec allows it, and either | |
4378 | 831 (2a) we are searching for texmf.cnf ; or |
4391 | 832 (2b) no db exists; or |
4378 | 833 (2c) no db's are relevant to this elt; or |
834 (3) MUST_EXIST && NAME was not in the db. | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
835 In (2*), 'found' will be NULL. |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
836 In (3), 'found' will be an empty list. */ |
4390 | 837 |
838 if (allow_disk_search && found.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
839 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
840 str_llist_type *dirs = kpse_element_dirs (elt); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
841 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
842 if (dirs && *dirs) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
843 found = dir_list_search (dirs, name, all); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
844 } |
4390 | 845 |
846 /* Did we find anything anywhere? */ | |
847 if (! found.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
848 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
849 if (all) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
850 ret_list.append (found); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
851 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
852 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
853 ret_list.append (found[0]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
854 done = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
855 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
856 } |
4378 | 857 } |
858 | |
859 return ret_list; | |
4390 | 860 } |
4392 | 861 |
4378 | 862 /* Search PATH for ORIGINAL_NAME. If ALL is false, or ORIGINAL_NAME is |
863 absolute_p, check ORIGINAL_NAME itself. Otherwise, look at each | |
864 element of PATH for the first readable ORIGINAL_NAME. | |
4391 | 865 |
4378 | 866 Always return a list; if no files are found, the list will |
867 contain just NULL. If ALL is true, the list will be | |
868 terminated with NULL. */ | |
869 | |
4390 | 870 static string_vector |
871 search (const std::string& path, const std::string& original_name, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
872 bool must_exist, bool all) |
4378 | 873 { |
4390 | 874 string_vector ret_list; |
4378 | 875 bool absolute_p; |
876 | |
877 /* Make a leading ~ count as an absolute filename, and expand $FOO's. */ | |
4390 | 878 std::string name = kpse_expand (original_name); |
4391 | 879 |
4378 | 880 /* If the first name is absolute or explicitly relative, no need to |
881 consider PATH at all. */ | |
882 absolute_p = kpse_absolute_p (name, true); | |
4391 | 883 |
4378 | 884 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) |
4391 | 885 DEBUGF4 ("start search (file=%s, must_exist=%d, find_all=%d, path=%s).\n", |
4390 | 886 name.c_str (), must_exist, all, path.c_str ()); |
4378 | 887 |
888 /* Find the file(s). */ | |
889 ret_list = absolute_p ? absolute_search (name) | |
890 : path_search (path, name, must_exist, all); | |
4391 | 891 |
4378 | 892 /* The very first search is for texmf.cnf. We can't log that, since |
893 we want to allow setting TEXMFLOG in texmf.cnf. */ | |
4391 | 894 if (first_search) |
895 { | |
896 first_search = false; | |
897 } | |
898 else | |
899 { | |
900 /* 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
|
901 debugging line if we're doing that. */ |
4391 | 902 |
903 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
904 DEBUGF1 ("search (%s) =>", original_name.c_str ()); |
4391 | 905 |
906 log_search (ret_list); | |
907 | |
908 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) | |
10411 | 909 gnulib::putc ('\n', stderr); |
4391 | 910 } |
4378 | 911 |
4390 | 912 return ret_list; |
4378 | 913 } |
4392 | 914 |
4378 | 915 /* Search PATH for the first NAME. */ |
916 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
917 /* Call 'kpse_expand' on NAME. If the result is an absolute or |
4399 | 918 explicitly relative filename, check whether it is a readable |
919 (regular) file. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
920 |
4399 | 921 Otherwise, look in each of the directories specified in PATH (also do |
922 tilde and variable expansion on elements in PATH), using a prebuilt | |
923 db (see db.h) if it's relevant for a given path element. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
924 |
4399 | 925 If the prebuilt db doesn't exist, or if MUST_EXIST is true and NAME |
926 isn't found in the prebuilt db, look on the filesystem. (I.e., if | |
927 MUST_EXIST is false, and NAME isn't found in the db, do *not* look on | |
928 the filesystem.) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
929 |
4399 | 930 The caller must expand PATH. This is because it makes more sense to |
931 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
|
932 |
4399 | 933 In any case, return the complete filename if found, otherwise NULL. */ |
934 | |
935 static std::string | |
4390 | 936 kpse_path_search (const std::string& path, const std::string& name, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
937 bool must_exist) |
4378 | 938 { |
4390 | 939 string_vector ret_list = search (path, name, must_exist, false); |
940 | |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
941 return ret_list.empty () ? "" : ret_list[0]; |
4378 | 942 } |
943 | |
944 /* Search all elements of PATH for files named NAME. Not sure if it's | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
945 right to assert 'must_exist' here, but it suffices now. */ |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
946 |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
947 /* Like 'kpse_path_search' with MUST_EXIST true, but return a list of |
4399 | 948 all the filenames (or NULL if none), instead of taking the first. */ |
949 | |
950 static string_vector | |
4390 | 951 kpse_all_path_search (const std::string& path, const std::string& name) |
4378 | 952 { |
4390 | 953 return search (path, name, true, true); |
4378 | 954 } |
4392 | 955 |
4378 | 956 /* This is the hard case -- look in each element of PATH for each |
957 element of NAMES. If ALL is false, return the first file found. | |
958 Otherwise, search all elements of PATH. */ | |
959 | |
4390 | 960 static string_vector |
4394 | 961 path_find_first_of (const std::string& path, const string_vector& names, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
962 bool /* must_exist */, bool all) |
4378 | 963 { |
4390 | 964 string_vector ret_list; |
4378 | 965 bool done = false; |
4390 | 966 |
8021 | 967 for (kpse_path_iterator pi (path); ! done && pi != std::string::npos; pi++) |
4378 | 968 { |
4394 | 969 std::string elt = *pi; |
970 | |
4378 | 971 str_llist_type *dirs; |
972 str_llist_elt_type *dirs_elt; | |
4390 | 973 string_vector found; |
4378 | 974 bool allow_disk_search = true; |
975 | |
4394 | 976 if (elt.length () > 1 && elt[0] == '!' && elt[1] == '!') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
977 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
978 /* Those magic leading chars in a path element means don't |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
979 search the disk for this elt. And move past the magic to |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
980 get to the name. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
981 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
982 allow_disk_search = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
983 elt = elt.substr (2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
984 } |
4378 | 985 |
986 /* Do not touch the device if present */ | |
987 | |
988 if (NAME_BEGINS_WITH_DEVICE (elt)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
989 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
990 while (elt.length () > 3 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
991 && 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
|
992 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
993 elt[2] = elt[1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
994 elt[1] = elt[0]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
995 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
996 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
997 } |
4378 | 998 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
999 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1000 /* We never want to search the whole disk. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1001 while (elt.length () > 1 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1002 && 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
|
1003 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1004 } |
4378 | 1005 |
1006 /* We have to search one directory at a time. */ | |
1007 dirs = kpse_element_dirs (elt); | |
1008 for (dirs_elt = *dirs; dirs_elt; dirs_elt = STR_LLIST_NEXT (*dirs_elt)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1009 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1010 const std::string dir = STR_LLIST (*dirs_elt); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1011 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20017
diff
changeset
|
1012 int len = names.numel (); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
1013 for (int i = 0; i < len && ! done; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1014 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1015 std::string name = names[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1016 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1017 /* Try ls-R, unless we're searching for texmf.cnf. Our caller |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1018 (find_first_of), also tests first_search, and does the |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1019 resetting. */ |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1020 found = first_search ? string_vector () |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1021 : kpse_db_search (name, dir.c_str (), all); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1022 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1023 /* Search the filesystem if (1) the path spec allows it, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1024 and either |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1025 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1026 (2a) we are searching for texmf.cnf ; or |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1027 (2b) no db exists; or |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1028 (2c) no db's are relevant to this elt; or |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1029 (3) MUST_EXIST && NAME was not in the db. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1030 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1031 In (2*), 'found' will be NULL. |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1032 In (3), 'found' will be an empty list. */ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1033 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1034 if (allow_disk_search && found.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1035 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1036 static str_llist_type *tmp = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1037 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1038 if (! tmp) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1039 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1040 tmp = new str_llist_type; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1041 *tmp = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1042 str_llist_add (tmp, ""); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1043 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1044 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1045 STR_LLIST (*(*tmp)) = dir; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1046 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1047 found = dir_list_search (tmp, name, all); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1048 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1049 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1050 /* Did we find anything anywhere? */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1051 if (! found.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1052 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1053 if (all) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1054 ret_list.append (found); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1055 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1056 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1057 ret_list.append (found[0]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1058 done = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1059 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1060 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1061 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1062 } |
4378 | 1063 } |
1064 | |
1065 return ret_list; | |
4391 | 1066 } |
4378 | 1067 |
4390 | 1068 static string_vector |
1069 find_first_of (const std::string& path, const string_vector& names, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1070 bool must_exist, bool all) |
4378 | 1071 { |
4390 | 1072 string_vector ret_list; |
4378 | 1073 |
1074 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) | |
1075 { | |
10411 | 1076 gnulib::fputs ("start find_first_of ((", stderr); |
4391 | 1077 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20017
diff
changeset
|
1078 int len = names.numel (); |
4391 | 1079 |
4390 | 1080 for (int i = 0; i < len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1081 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1082 if (i == 0) |
10411 | 1083 gnulib::fputs (names[i].c_str (), stderr); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1084 else |
10411 | 1085 gnulib::fprintf (stderr, ", %s", names[i].c_str ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1086 } |
4391 | 1087 |
10411 | 1088 gnulib::fprintf (stderr, "), path=%s, must_exist=%d).\n", |
1089 path.c_str (), must_exist); | |
4378 | 1090 } |
1091 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20017
diff
changeset
|
1092 for (int i = 0; i < names.numel (); i++) |
4409 | 1093 { |
1094 std::string name = names[i]; | |
1095 | |
1096 if (kpse_absolute_p (name, true)) | |
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 /* 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
|
1099 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
|
1100 are done. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1101 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1102 ret_list = absolute_search (name); |
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 if (! ret_list.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1105 return ret_list; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1106 } |
4409 | 1107 } |
1108 | |
4378 | 1109 /* Find the file. */ |
1110 ret_list = path_find_first_of (path, names, must_exist, all); | |
1111 | |
1112 /* The very first search is for texmf.cnf. We can't log that, since | |
1113 we want to allow setting TEXMFLOG in texmf.cnf. */ | |
4391 | 1114 if (first_search) |
1115 { | |
1116 first_search = false; | |
1117 } | |
1118 else | |
1119 { | |
1120 /* 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
|
1121 debugging line if we're doing that. */ |
4391 | 1122 |
1123 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1124 { |
10411 | 1125 gnulib::fputs ("find_first_of (", stderr); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1126 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20017
diff
changeset
|
1127 int len = names.numel (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1128 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1129 for (int i = 0; i < len; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1130 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1131 if (i == 0) |
10411 | 1132 gnulib::fputs (names[i].c_str (), stderr); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1133 else |
10411 | 1134 gnulib::fprintf (stderr, ", %s", names[i].c_str ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1135 } |
10411 | 1136 |
1137 gnulib::fputs (") =>", stderr); | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1138 } |
4391 | 1139 |
1140 log_search (ret_list); | |
1141 | |
1142 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) | |
10411 | 1143 gnulib::putc ('\n', stderr); |
4391 | 1144 } |
4378 | 1145 |
4390 | 1146 return ret_list; |
4378 | 1147 } |
1148 | |
1149 /* Search each element of PATH for each element of NAMES. Return the | |
1150 first one found. */ | |
1151 | |
4399 | 1152 /* Search each element of PATH for each element in the list of NAMES. |
1153 Return the first one found. */ | |
1154 | |
1155 static std::string | |
4390 | 1156 kpse_path_find_first_of (const std::string& path, const string_vector& names, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1157 bool must_exist) |
4378 | 1158 { |
4390 | 1159 string_vector ret_list = find_first_of (path, names, must_exist, false); |
1160 | |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1161 return ret_list.empty () ? "" : ret_list[0]; |
4378 | 1162 } |
1163 | |
1164 /* Search each element of PATH for each element of NAMES and return a | |
1165 list containing everything found, in the order found. */ | |
1166 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1167 /* Like 'kpse_path_find_first_of' with MUST_EXIST true, but return a |
4399 | 1168 list of all the filenames (or NULL if none), instead of taking the |
1169 first. */ | |
1170 | |
1171 static string_vector | |
4390 | 1172 kpse_all_path_find_first_of (const std::string& path, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1173 const string_vector& names) |
4378 | 1174 { |
4390 | 1175 return find_first_of (path, names, true, true); |
4378 | 1176 } |
1177 | |
4399 | 1178 /* General expansion. Some of this file (the brace-expansion |
4378 | 1179 code from bash) is covered by the GPL; this is the only GPL-covered |
1180 code in kpathsea. The part of the file that I wrote (the first | |
1181 couple of functions) is covered by the LGPL. */ | |
1182 | |
1183 /* If NAME has a leading ~ or ~user, Unix-style, expand it to the user's | |
1184 home directory, and return a new malloced string. If no ~, or no | |
1185 <pwd.h>, just return NAME. */ | |
1186 | |
4389 | 1187 static std::string |
1188 kpse_tilde_expand (const std::string& name) | |
4378 | 1189 { |
4389 | 1190 std::string expansion; |
4391 | 1191 |
4378 | 1192 /* If no leading tilde, do nothing. */ |
5137 | 1193 if (name.empty () || name[0] != '~') |
4391 | 1194 { |
1195 expansion = name; | |
1196 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1197 /* 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
|
1198 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
|
1199 ... */ |
4391 | 1200 } |
1201 else if (name.length () == 1) | |
1202 { | |
20017
4b7b7ac7af2c
use get_home_directory instead of getenv ("HOME") (bug #44694)
John W. Eaton <jwe@octave.org>
parents:
19864
diff
changeset
|
1203 expansion = octave_env::get_home_directory (); |
4391 | 1204 |
1205 if (expansion.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1206 expansion = "."; |
4391 | 1207 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1208 /* 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
|
1209 Should really check for doubled intermediate slashes, too. */ |
4378 | 1210 } |
4391 | 1211 else if (IS_DIR_SEP (name[1])) |
1212 { | |
1213 unsigned c = 1; | |
20017
4b7b7ac7af2c
use get_home_directory instead of getenv ("HOME") (bug #44694)
John W. Eaton <jwe@octave.org>
parents:
19864
diff
changeset
|
1214 std::string home = octave_env::get_home_directory (); |
4391 | 1215 |
1216 if (home.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1217 home = "."; |
4391 | 1218 |
1219 size_t home_len = home.length (); | |
1220 | |
1221 /* handle leading // */ | |
1222 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
|
1223 home = home.substr (1); |
4391 | 1224 |
1225 /* omit / after ~ */ | |
1226 if (IS_DIR_SEP (home[home_len - 1])) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1227 c++; |
4391 | 1228 |
1229 expansion = home + name.substr (c); | |
1230 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1231 /* 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
|
1232 OS/2 doesn't have this concept. */ |
4378 | 1233 } |
4391 | 1234 else |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
1235 #if defined (HAVE_PWD_H) |
4378 | 1236 { |
1237 unsigned c = 2; | |
4391 | 1238 |
1239 /* find user name */ | |
1240 while (name.length () > c && ! IS_DIR_SEP (name[c])) | |
4378 | 1241 c++; |
4391 | 1242 |
1243 std::string user = name.substr (1, c-1); | |
1244 | |
4378 | 1245 /* 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
|
1246 which do not declare 'getpwnam' in <pwd.h>. */ |
4391 | 1247 octave_passwd p = octave_passwd::getpwnam (user); |
4378 | 1248 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1249 /* If no such user, just use '.'. */ |
4391 | 1250 std::string home = p ? p.dir () : std::string ("."); |
1251 | |
1252 if (home.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1253 home = "."; |
4391 | 1254 |
1255 /* handle leading // */ | |
1256 if (home.length () > 1 && IS_DIR_SEP (home[0]) && IS_DIR_SEP (home[1])) | |
1257 home = home.substr (1); | |
1258 | |
1259 /* If HOME ends in /, omit the / after ~user. */ | |
1260 if (name.length () > c && IS_DIR_SEP (home[home.length () - 1])) | |
1261 c++; | |
1262 | |
1263 expansion = name.length () > c ? home : home + name.substr (c); | |
4378 | 1264 } |
1265 #else /* not HAVE_PWD_H */ | |
4391 | 1266 expansion = name; |
4378 | 1267 #endif /* not HAVE_PWD_H */ |
1268 | |
4389 | 1269 return expansion; |
4378 | 1270 } |
1271 | |
1272 /* Do variable expansion first so ~${USER} works. (Besides, it's what the | |
1273 shells do.) */ | |
1274 | |
4399 | 1275 /* Call kpse_var_expand and kpse_tilde_expand (in that order). Result |
1276 is always in fresh memory, even if no expansions were done. */ | |
1277 | |
1278 static std::string | |
4389 | 1279 kpse_expand (const std::string& s) |
4378 | 1280 { |
4389 | 1281 std::string var_expansion = kpse_var_expand (s); |
1282 return kpse_tilde_expand (var_expansion); | |
4378 | 1283 } |
1284 | |
1285 /* Forward declarations of functions from the original expand.c */ | |
4397 | 1286 static string_vector brace_expand (const std::string&); |
4378 | 1287 |
1288 /* If $KPSE_DOT is defined in the environment, prepend it to any relative | |
1289 path components. */ | |
1290 | |
4389 | 1291 static std::string |
1292 kpse_expand_kpse_dot (const std::string& path) | |
4378 | 1293 { |
4389 | 1294 std::string ret; |
4391 | 1295 std::string kpse_dot = octave_env::getenv ("KPSE_DOT"); |
1296 | |
1297 if (kpse_dot.empty ()) | |
4378 | 1298 return path; |
1299 | |
8021 | 1300 for (kpse_path_iterator pi (path); pi != std::string::npos; pi++) |
4391 | 1301 { |
4394 | 1302 std::string elt = *pi; |
1303 | |
4391 | 1304 /* We assume that the !! magic is only used on absolute components. |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21340
diff
changeset
|
1305 Single "." get special treatment, as does "./" or its equivalent. */ |
4391 | 1306 |
4394 | 1307 size_t elt_len = elt.length (); |
1308 | |
1309 if (kpse_absolute_p (elt, false) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1310 || (elt_len > 1 && elt[0] == '!' && elt[1] == '!')) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1311 ret += elt + ENV_SEP_STRING; |
4394 | 1312 else if (elt_len == 1 && elt[0] == '.') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1313 ret += kpse_dot + ENV_SEP_STRING; |
4394 | 1314 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
|
1315 ret += kpse_dot + elt.substr (1) + ENV_SEP_STRING; |
4391 | 1316 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1317 ret += kpse_dot + DIR_SEP_STRING + elt + ENV_SEP_STRING; |
4378 | 1318 } |
1319 | |
4389 | 1320 int len = ret.length (); |
1321 if (len > 0) | |
4395 | 1322 ret.resize (len-1); |
4389 | 1323 |
4378 | 1324 return ret; |
1325 } | |
1326 | |
1327 /* Do brace expansion on ELT; then do variable and ~ expansion on each | |
1328 element of the result; then do brace expansion again, in case a | |
1329 variable definition contained braces (e.g., $TEXMF). Return a | |
1330 string comprising all of the results separated by ENV_SEP_STRING. */ | |
1331 | |
4389 | 1332 static std::string |
4394 | 1333 kpse_brace_expand_element (const std::string& elt) |
4378 | 1334 { |
4389 | 1335 std::string ret; |
4378 | 1336 |
4397 | 1337 string_vector expansions = brace_expand (elt); |
1338 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20017
diff
changeset
|
1339 for (int i = 0; i < expansions.numel (); i++) |
4391 | 1340 { |
1341 /* Do $ and ~ expansion on each element. */ | |
1342 std::string x = kpse_expand (expansions[i]); | |
1343 | |
1344 if (x != expansions[i]) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1345 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1346 /* 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
|
1347 recursive variable definitions are not allowed, this recursion |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1348 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
|
1349 more than one level of recursion.) */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1350 x = kpse_brace_expand_element (x); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1351 } |
4391 | 1352 |
1353 ret += x + ENV_SEP_STRING; | |
4378 | 1354 } |
1355 | |
4389 | 1356 ret.resize (ret.length () - 1); |
4391 | 1357 |
4378 | 1358 return ret; |
1359 } | |
1360 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1361 /* Do brace expansion and call 'kpse_expand' on each element of the |
4399 | 1362 result; return the final expansion (always in fresh memory, even if |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1363 no expansions were done). We don't call 'kpse_expand_default' |
4399 | 1364 because there is a whole sequence of defaults to run through; see |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1365 'kpse_init_format'. */ |
4399 | 1366 |
1367 static std::string | |
4397 | 1368 kpse_brace_expand (const std::string& path) |
4378 | 1369 { |
1370 /* Must do variable expansion first because if we have | |
1371 foo = .:~ | |
1372 TEXINPUTS = $foo | |
1373 we want to end up with TEXINPUTS = .:/home/karl. | |
1374 Since kpse_path_element is not reentrant, we must get all | |
1375 the path elements before we start the loop. */ | |
4389 | 1376 std::string tmp = kpse_var_expand (path); |
4394 | 1377 |
4389 | 1378 std::string ret; |
4378 | 1379 |
8021 | 1380 for (kpse_path_iterator pi (tmp); pi != std::string::npos; pi++) |
4391 | 1381 { |
4394 | 1382 std::string elt = *pi; |
1383 | |
4391 | 1384 /* Do brace expansion first, so tilde expansion happens in {~ka,~kb}. */ |
1385 std::string expansion = kpse_brace_expand_element (elt); | |
1386 ret += expansion + ENV_SEP_STRING; | |
1387 } | |
4378 | 1388 |
4394 | 1389 size_t len = ret.length (); |
4389 | 1390 if (len > 0) |
4395 | 1391 ret.resize (len-1); |
4389 | 1392 |
1393 return kpse_expand_kpse_dot (ret); | |
4378 | 1394 } |
4392 | 1395 |
4378 | 1396 /* Expand all special constructs in a path, and include only the actually |
1397 existing directories in the result. */ | |
4399 | 1398 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1399 /* Do brace expansion and call 'kpse_expand' on each argument of the |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1400 result, then expand any '//' constructs. The final expansion (always |
4399 | 1401 in fresh memory) is a path of all the existing directories that match |
1402 the pattern. */ | |
1403 | |
1404 static std::string | |
4397 | 1405 kpse_path_expand (const std::string& path) |
4378 | 1406 { |
4392 | 1407 std::string ret; |
4378 | 1408 unsigned len; |
1409 | |
1410 len = 0; | |
4391 | 1411 |
4378 | 1412 /* Expand variables and braces first. */ |
4389 | 1413 std::string tmp = kpse_brace_expand (path); |
4392 | 1414 |
4378 | 1415 /* Now expand each of the path elements, printing the results */ |
8021 | 1416 for (kpse_path_iterator pi (tmp); pi != std::string::npos; pi++) |
4391 | 1417 { |
4394 | 1418 std::string elt = *pi; |
1419 | |
4391 | 1420 str_llist_type *dirs; |
1421 | |
1422 /* Skip and ignore magic leading chars. */ | |
4394 | 1423 if (elt.length () > 1 && elt[0] == '!' && elt[1] == '!') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1424 elt = elt.substr (2); |
4391 | 1425 |
1426 /* Do not touch the device if present */ | |
1427 if (NAME_BEGINS_WITH_DEVICE (elt)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1428 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1429 while (elt.length () > 3 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1430 && 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
|
1431 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1432 elt[2] = elt[1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1433 elt[1] = elt[0]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1434 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1435 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1436 } |
4391 | 1437 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1438 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1439 /* We never want to search the whole disk. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1440 while (elt.length () > 1 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1441 && 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
|
1442 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1443 } |
4378 | 1444 |
4394 | 1445 /* 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
|
1446 Be faster to check the database, but this is more reliable. */ |
4394 | 1447 dirs = kpse_element_dirs (elt); |
1448 | |
1449 if (dirs && *dirs) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1450 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1451 str_llist_elt_type *dir; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1452 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1453 for (dir = *dirs; dir; dir = STR_LLIST_NEXT (*dir)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1454 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1455 const std::string thedir = STR_LLIST (*dir); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1456 unsigned dirlen = thedir.length (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1457 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1458 ret += thedir; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1459 len += dirlen; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1460 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1461 /* Retain trailing slash if that's the root directory. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1462 if (dirlen == 1 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1463 || (dirlen == 3 && NAME_BEGINS_WITH_DEVICE (thedir) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1464 && IS_DIR_SEP (thedir[2]))) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1465 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1466 ret += ENV_SEP_STRING; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1467 len++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1468 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1469 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1470 ret[len-1] = ENV_SEP; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1471 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1472 } |
4378 | 1473 } |
4391 | 1474 |
4395 | 1475 if (len > 0) |
1476 ret.resize (len-1); | |
4391 | 1477 |
4378 | 1478 return ret; |
1479 } | |
4392 | 1480 |
4378 | 1481 /* braces.c -- code for doing word expansion in curly braces. Taken from |
16768 | 1482 bash 1.14.5. [And subsequently modified for kpatshea.] |
1483 | |
1484 Copyright (C) 1987,1991 Free Software Foundation, Inc. */ | |
4378 | 1485 |
4391 | 1486 #define brace_whitespace(c) (! (c) || (c) == ' ' || (c) == '\t' || (c) == '\n') |
4378 | 1487 |
1488 /* Basic idea: | |
1489 | |
1490 Segregate the text into 3 sections: preamble (stuff before an open brace), | |
1491 postamble (stuff after the matching close brace) and amble (stuff after | |
1492 preamble, and before postamble). Expand amble, and then tack on the | |
1493 expansions to preamble. Expand postamble, and tack on the expansions to | |
4391 | 1494 the result so far. */ |
4378 | 1495 |
4397 | 1496 /* Return a new array of strings which is the result of appending each |
1497 string in ARR2 to each string in ARR1. The resultant array is | |
1498 len (arr1) * len (arr2) long. For convenience, ARR1 (and its contents) | |
1499 are free ()'ed. ARR1 can be NULL, in that case, a new version of ARR2 | |
1500 is returned. */ | |
1501 | |
1502 static string_vector | |
1503 array_concat (const string_vector& arr1, const string_vector& arr2) | |
4378 | 1504 { |
4397 | 1505 string_vector result; |
1506 | |
1507 if (arr1.empty ()) | |
1508 result = arr2; | |
1509 else if (arr2.empty ()) | |
1510 result = arr1; | |
1511 else | |
1512 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20017
diff
changeset
|
1513 int len1 = arr1.numel (); |
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20017
diff
changeset
|
1514 int len2 = arr2.numel (); |
4397 | 1515 |
1516 result = string_vector (len1 * len2); | |
1517 | |
1518 int k = 0; | |
1519 for (int i = 0; i < len2; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1520 for (int j = 0; j < len1; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1521 result[k++] = arr1[j] + arr2[i]; |
4397 | 1522 } |
1523 | |
1524 return result; | |
4378 | 1525 } |
1526 | |
4397 | 1527 static int brace_gobbler (const std::string&, int&, int); |
1528 static string_vector expand_amble (const std::string&); | |
4378 | 1529 |
1530 /* Return an array of strings; the brace expansion of TEXT. */ | |
4397 | 1531 static string_vector |
1532 brace_expand (const std::string& text) | |
4378 | 1533 { |
1534 /* Find the text of the preamble. */ | |
4397 | 1535 int i = 0; |
1536 int c = brace_gobbler (text, i, '{'); | |
1537 | |
1538 std::string preamble = text.substr (0, i); | |
1539 | |
1540 string_vector result = string_vector (preamble); | |
1541 | |
1542 if (c == '{') | |
4378 | 1543 { |
4397 | 1544 /* Find the amble. This is the stuff inside this set of braces. */ |
1545 int start = ++i; | |
1546 c = brace_gobbler (text, i, '}'); | |
1547 | |
1548 /* What if there isn't a matching close brace? */ | |
1549 if (! c) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1550 { |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
1551 (*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
|
1552 ("Octave:pathsearch-syntax", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
1553 "%s: Unmatched {", text.c_str ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1554 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1555 result = string_vector (text); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1556 } |
4397 | 1557 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1558 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1559 std::string amble = text.substr (start, i-start); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1560 result = array_concat (result, expand_amble (amble)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1561 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1562 std::string postamble = text.substr (i+1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1563 result = array_concat (result, brace_expand (postamble)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1564 } |
4378 | 1565 } |
1566 | |
4397 | 1567 return result; |
4378 | 1568 } |
1569 | |
4397 | 1570 /* The character which is used to separate arguments. */ |
1571 static int brace_arg_separator = ','; | |
1572 | |
4378 | 1573 /* Expand the text found inside of braces. We simply try to split the |
1574 text at BRACE_ARG_SEPARATORs into separate strings. We then brace | |
1575 expand each slot which needs it, until there are no more slots which | |
1576 need it. */ | |
4397 | 1577 static string_vector |
1578 expand_amble (const std::string& text) | |
4378 | 1579 { |
4397 | 1580 string_vector result; |
1581 | |
1582 size_t text_len = text.length (); | |
1583 size_t start; | |
1584 int i, c; | |
1585 | |
1586 for (start = 0, i = 0, c = 1; c && start < text_len; start = ++i) | |
4378 | 1587 { |
4397 | 1588 int i0 = i; |
1589 int c0 = brace_gobbler (text, i0, brace_arg_separator); | |
1590 int i1 = i; | |
1591 int c1 = brace_gobbler (text, i1, ENV_SEP); | |
4378 | 1592 c = c0 | c1; |
1593 i = (i0 < i1 ? i0 : i1); | |
1594 | |
4397 | 1595 std::string tem = text.substr (start, i-start); |
1596 | |
1597 string_vector partial = brace_expand (tem); | |
1598 | |
1599 if (result.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1600 result = partial; |
4378 | 1601 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1602 result.append (partial); |
4378 | 1603 } |
4397 | 1604 |
1605 return result; | |
4378 | 1606 } |
1607 | |
1608 /* Start at INDEX, and skip characters in TEXT. Set INDEX to the | |
1609 index of the character matching SATISFY. This understands about | |
1610 quoting. Return the character that caused us to stop searching; | |
1611 this is either the same as SATISFY, or 0. */ | |
1612 static int | |
4397 | 1613 brace_gobbler (const std::string& text, int& indx, int satisfy) |
4378 | 1614 { |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
1615 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
|
1616 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
|
1617 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
|
1618 int pass_next = 0; |
4397 | 1619 |
1620 size_t text_len = text.length (); | |
1621 | |
1622 size_t i = indx; | |
1623 | |
1624 for (; i < text_len; i++) | |
4378 | 1625 { |
4397 | 1626 c = text[i]; |
1627 | |
4378 | 1628 if (pass_next) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1629 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1630 pass_next = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1631 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1632 } |
4378 | 1633 |
1634 /* 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
|
1635 escape the quote character in a double-quoted string. */ |
4378 | 1636 if (c == '\\' && (quoted == 0 || quoted == '"' || quoted == '`')) |
1637 { | |
1638 pass_next = 1; | |
1639 continue; | |
1640 } | |
1641 | |
1642 if (quoted) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1643 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1644 if (c == quoted) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1645 quoted = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1646 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1647 } |
4378 | 1648 |
1649 if (c == '"' || c == '\'' || c == '`') | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1650 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1651 quoted = c; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1652 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1653 } |
4391 | 1654 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
1655 if (c == satisfy && ! level && ! quoted) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1656 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1657 /* 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
|
1658 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
|
1659 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
|
1660 if (c == '{' |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1661 && ((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
|
1662 && (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
|
1663 && (brace_whitespace (text[i+1]) || text[i+1] == '}')))) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1664 continue; |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1665 /* 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
|
1666 in a '${ }' construct */ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1667 if ((c != '{') || i == 0 || (text[i-1] != '$')) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1668 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1669 } |
4378 | 1670 |
1671 if (c == '{') | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1672 level++; |
4378 | 1673 else if (c == '}' && level) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1674 level--; |
4378 | 1675 } |
1676 | |
4397 | 1677 indx = i; |
1678 return c; | |
4378 | 1679 } |
1680 | |
1681 /* For each file format, we record the following information. The main | |
1682 thing that is not part of this structure is the environment variable | |
1683 lists. They are used directly in tex-file.c. We could incorporate | |
1684 them here, but it would complicate the code a bit. We could also do | |
1685 it via variable expansion, but not now, maybe not ever: | |
1686 ${PKFONTS-${TEXFONTS-/usr/local/lib/texmf/fonts//}}. */ | |
1687 | |
4399 | 1688 struct kpse_format_info_type |
4378 | 1689 { |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
1690 kpse_format_info_type (void) |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
1691 : type (), path (), raw_path (), path_source (), override_path (), |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
1692 client_path (), cnf_path (), default_path (), suffix () |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
1693 { } |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
1694 |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
1695 ~kpse_format_info_type (void) { } |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
1696 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1697 std::string type; /* Human-readable description. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1698 std::string path; /* The search path to use. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1699 std::string raw_path; /* Pre-$~ (but post-default) expansion. */ |
4390 | 1700 std::string path_source; /* Where the path started from. */ |
1701 std::string override_path; /* From client environment variable. */ | |
1702 std::string client_path; /* E.g., from dvips's config.ps. */ | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1703 std::string cnf_path; /* From texmf.cnf. */ |
4390 | 1704 std::string default_path; /* If all else fails. */ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1705 string_vector suffix; /* For kpse_find_file to check for/append. */ |
4399 | 1706 }; |
4378 | 1707 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1708 /* The sole variable of that type, indexed by 'kpse_file_format_type'. |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1709 Initialized by calls to 'kpse_find_file' for 'kpse_init_format'. */ |
4378 | 1710 static kpse_format_info_type kpse_format_info; |
1711 | |
1712 /* And EXPAND_DEFAULT calls kpse_expand_default on try_path and the | |
1713 present info->path. */ | |
4396 | 1714 #define EXPAND_DEFAULT(try_path, source_string) \ |
1715 do \ | |
1716 { \ | |
1717 if (! try_path.empty ()) \ | |
1718 { \ | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1719 info.raw_path = try_path; \ |
4396 | 1720 info.path = kpse_expand_default (try_path, info.path); \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1721 info.path_source = source_string; \ |
4396 | 1722 } \ |
1723 } \ | |
1724 while (0) | |
4378 | 1725 |
1726 static hash_table_type db; /* The hash table for all the ls-R's. */ | |
4928 | 1727 |
4378 | 1728 static hash_table_type alias_db; |
1729 | |
4390 | 1730 static string_vector db_dir_list; |
4392 | 1731 |
4378 | 1732 /* Return true if FILENAME could be in PATH_ELT, i.e., if the directory |
1733 part of FILENAME matches PATH_ELT. Have to consider // wildcards, but | |
1734 $ and ~ expansion have already been done. */ | |
4391 | 1735 |
4378 | 1736 static bool |
4390 | 1737 match (const std::string& filename_arg, const std::string& path_elt_arg) |
4378 | 1738 { |
4390 | 1739 const char *filename = filename_arg.c_str (); |
1740 const char *path_elt = path_elt_arg.c_str (); | |
1741 | |
4378 | 1742 const char *original_filename = filename; |
1743 bool matched = false; | |
4391 | 1744 |
1745 for (; *filename && *path_elt; filename++, path_elt++) | |
1746 { | |
4394 | 1747 if (*filename == *path_elt) /* normal character match */ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1748 ; |
4391 | 1749 |
1750 else if (IS_DIR_SEP (*path_elt) /* at // */ | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1751 && original_filename < filename && IS_DIR_SEP (path_elt[-1])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1752 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1753 while (IS_DIR_SEP (*path_elt)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1754 path_elt++; /* get past second and any subsequent /'s */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1755 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1756 if (*path_elt == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1757 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1758 /* Trailing //, matches anything. We could make this |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1759 part of the other case, but it seems pointless to do |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1760 the extra work. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1761 matched = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1762 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1763 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1764 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1765 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1766 /* Intermediate //, have to match rest of PATH_ELT. */ |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
1767 for (; ! matched && *filename; filename++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1768 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1769 /* Try matching at each possible character. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1770 if (IS_DIR_SEP (filename[-1]) && *filename == *path_elt) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1771 matched = match (filename, path_elt); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1772 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1773 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1774 /* Prevent filename++ when *filename='\0'. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1775 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1776 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1777 } |
4391 | 1778 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1779 /* normal character nonmatch, quit */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1780 break; |
4378 | 1781 } |
1782 | |
1783 /* If we've reached the end of PATH_ELT, check that we're at the last | |
1784 component of FILENAME, we've matched. */ | |
4391 | 1785 if (! matched && *path_elt == 0) |
1786 { | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1787 /* Probably PATH_ELT ended with 'vf' or some such, and FILENAME |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1788 ends with 'vf/ptmr.vf'. In that case, we'll be at a |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1789 directory separator. On the other hand, if PATH_ELT ended |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1790 with a / (as in 'vf/'), FILENAME being the same 'vf/ptmr.vf', |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1791 we'll be at the 'p'. Upshot: if we're at a dir separator in |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1792 FILENAME, skip it. But if not, that's ok, as long as there |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1793 are no more dir separators. */ |
4391 | 1794 |
1795 if (IS_DIR_SEP (*filename)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1796 filename++; |
4391 | 1797 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
1798 while (*filename && ! IS_DIR_SEP (*filename)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1799 filename++; |
4391 | 1800 |
1801 matched = *filename == 0; | |
1802 } | |
1803 | |
4378 | 1804 return matched; |
1805 } | |
1806 | |
1807 /* If DB_DIR is a prefix of PATH_ELT, return true; otherwise false. | |
1808 That is, the question is whether to try the db for a file looked up | |
1809 in PATH_ELT. If PATH_ELT == ".", for example, the answer is no. If | |
1810 PATH_ELT == "/usr/local/lib/texmf/fonts//tfm", the answer is yes. | |
4391 | 1811 |
4378 | 1812 In practice, ls-R is only needed for lengthy subdirectory |
1813 comparisons, but there's no gain to checking PATH_ELT to see if it is | |
1814 a subdir match, since the only way to do that is to do a string | |
1815 search in it, which is all we do anyway. */ | |
4391 | 1816 |
4378 | 1817 static bool |
4390 | 1818 elt_in_db (const std::string& db_dir, const std::string& path_elt) |
4378 | 1819 { |
1820 bool found = false; | |
1821 | |
4390 | 1822 size_t db_dir_len = db_dir.length (); |
1823 size_t path_elt_len = path_elt.length (); | |
1824 | |
1825 size_t i = 0; | |
1826 | |
4394 | 1827 while (! found && db_dir[i] == path_elt[i]) |
4391 | 1828 { |
1829 i++; | |
1830 /* If we've matched the entire db directory, it's good. */ | |
1831 if (i == db_dir_len) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1832 found = true; |
4391 | 1833 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1834 /* If we've reached the end of PATH_ELT, but not the end of the db |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1835 directory, it's no good. */ |
4391 | 1836 else if (i == path_elt_len) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1837 break; |
4391 | 1838 } |
4378 | 1839 |
1840 return found; | |
1841 } | |
4392 | 1842 |
4378 | 1843 /* Avoid doing anything if this PATH_ELT is irrelevant to the databases. */ |
1844 | |
4399 | 1845 /* Return list of matches for NAME in the ls-R file matching PATH_ELT. If |
1846 ALL is set, return (null-terminated list) of all matches, else just | |
1847 the first. If no matches, return a pointer to an empty list. If no | |
1848 databases can be read, or PATH_ELT is not in any of the databases, | |
1849 return NULL. */ | |
1850 | |
1851 static string_vector | |
4390 | 1852 kpse_db_search (const std::string& name_arg, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1853 const std::string& orig_path_elt, bool all) |
4378 | 1854 { |
1855 bool done; | |
4390 | 1856 string_vector ret; |
1857 string_vector aliases; | |
4378 | 1858 bool relevant = false; |
4390 | 1859 |
4394 | 1860 std::string name = name_arg; |
4391 | 1861 |
4378 | 1862 /* If we failed to build the database (or if this is the recursive |
1863 call to build the db path), quit. */ | |
4398 | 1864 if (! db.buckets) |
4390 | 1865 return ret; |
4391 | 1866 |
4378 | 1867 /* When tex-glyph.c calls us looking for, e.g., dpi600/cmr10.pk, we |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1868 won't find it unless we change NAME to just 'cmr10.pk' and append |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1869 '/dpi600' to PATH_ELT. We are justified in using a literal '/' |
4378 | 1870 here, since that's what tex-glyph.c unconditionally uses in |
1871 DPI_BITMAP_SPEC. But don't do anything if the / begins NAME; that | |
1872 should never happen. */ | |
4394 | 1873 std::string path_elt; |
1874 size_t last_slash = name.rfind ('/'); | |
8021 | 1875 if (last_slash != std::string::npos && last_slash != 0) |
4390 | 1876 { |
4394 | 1877 std::string dir_part = name.substr (0, last_slash); |
1878 name = name.substr (last_slash + 1); | |
4390 | 1879 } |
1880 else | |
4394 | 1881 path_elt = orig_path_elt; |
4378 | 1882 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1883 /* Don't bother doing any lookups if this 'path_elt' isn't covered by |
4378 | 1884 any of database directories. We do this not so much because the |
1885 extra couple of hash lookups matter -- they don't -- but rather | |
1886 because we want to return NULL in this case, so path_search can | |
1887 know to do a disk search. */ | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20017
diff
changeset
|
1888 for (int e = 0; ! relevant && e < db_dir_list.numel (); e++) |
4390 | 1889 relevant = elt_in_db (db_dir_list[e], path_elt); |
1890 | |
4391 | 1891 if (! relevant) |
4390 | 1892 return ret; |
4378 | 1893 |
1894 /* If we have aliases for this name, use them. */ | |
1895 if (alias_db.buckets) | |
1896 aliases = hash_lookup (alias_db, name); | |
1897 | |
4390 | 1898 /* Push aliases up by one and insert the original name at the front. */ |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20017
diff
changeset
|
1899 int len = aliases.numel (); |
4390 | 1900 aliases.resize (len+1); |
1901 for (int i = len; i > 0; i--) | |
1902 aliases[i] = aliases[i - 1]; | |
1903 aliases[0] = name; | |
4378 | 1904 |
1905 done = false; | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20017
diff
changeset
|
1906 len = aliases.numel (); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
1907 for (int i = 0; i < len && ! done; i++) |
4390 | 1908 { |
1909 std::string atry = aliases[i]; | |
1910 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1911 /* We have an ls-R db. Look up 'atry'. */ |
4390 | 1912 string_vector db_dirs = hash_lookup (db, atry); |
1913 | |
1914 /* For each filename found, see if it matches the path element. For | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1915 example, if we have .../cx/cmr10.300pk and .../ricoh/cmr10.300pk, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1916 and the path looks like .../cx, we don't want the ricoh file. */ |
4390 | 1917 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20017
diff
changeset
|
1918 int db_dirs_len = db_dirs.numel (); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
1919 for (int j = 0; j < db_dirs_len && ! done; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1920 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1921 std::string db_file = db_dirs[j] + atry; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1922 bool matched = match (db_file, path_elt); |
4378 | 1923 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
1924 #if defined (KPSE_DEBUG) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1925 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1926 DEBUGF3 ("db:match (%s,%s) = %d\n", |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1927 db_file.c_str (), path_elt.c_str (), matched); |
4378 | 1928 #endif |
1929 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1930 /* We got a hit in the database. Now see if the file actually |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1931 exists, possibly under an alias. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1932 if (matched) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1933 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1934 std::string found; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1935 std::string tmp = kpse_readable_file (db_file); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1936 if (! tmp.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1937 found = db_file; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1938 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1939 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1940 /* The hit in the DB doesn't exist in disk. Now try |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1941 all its aliases. For example, suppose we have a |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1942 hierarchy on CD, thus 'mf.bas', but ls-R contains |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1943 'mf.base'. Find it anyway. Could probably work |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1944 around this with aliases, but this is pretty easy |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1945 and shouldn't hurt. The upshot is that if one of |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1946 the aliases actually exists, we use that. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1947 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20017
diff
changeset
|
1948 int aliases_len = aliases.numel (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1949 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1950 for (int k = 1; k < aliases_len && found.empty (); k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1951 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1952 std::string aatry = db_dirs[j] + aliases[k]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1953 tmp = kpse_readable_file (aatry); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1954 if (! tmp.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1955 found = aatry; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1956 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1957 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1958 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1959 /* If we have a real file, add it to the list, maybe done. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1960 if (! found.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1961 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1962 ret.append (found); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1963 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1964 if (! (all || found.empty ())) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1965 done = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1966 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1967 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1968 } |
4378 | 1969 } |
4391 | 1970 |
4378 | 1971 return ret; |
1972 } | |
1973 | |
4399 | 1974 /* Expand extra colons. */ |
4378 | 1975 |
1976 /* Check for leading colon first, then trailing, then doubled, since | |
1977 that is fastest. Usually it will be leading or trailing. */ | |
1978 | |
4399 | 1979 /* Replace a leading or trailing or doubled : in PATH with DFLT. If |
1980 no extra colons, return PATH. Only one extra colon is replaced. | |
1981 DFLT may not be NULL. */ | |
1982 | |
1983 static std::string | |
4394 | 1984 kpse_expand_default (const std::string& path, const std::string& fallback) |
4378 | 1985 { |
4394 | 1986 std::string expansion; |
1987 | |
1988 size_t path_len = path.length (); | |
1989 | |
1990 if (path_len == 0) | |
1991 expansion = fallback; | |
4378 | 1992 |
1993 /* Solitary or leading :? */ | |
4394 | 1994 else if (IS_ENV_SEP (path[0])) |
4378 | 1995 { |
4394 | 1996 expansion = path_len == 1 ? fallback : fallback + path; |
4378 | 1997 } |
1998 | |
1999 /* Sorry about the assignment in the middle of the expression, but | |
2000 conventions were made to be flouted and all that. I don't see the | |
2001 point of calling strlen twice or complicating the logic just to | |
2002 avoid the assignment (especially now that I've pointed it out at | |
2003 such great length). */ | |
4394 | 2004 else if (IS_ENV_SEP (path[path_len-1])) |
2005 expansion = path + fallback; | |
4378 | 2006 |
2007 /* OK, not leading or trailing. Check for doubled. */ | |
2008 else | |
2009 { | |
2010 /* What we'll return if we find none. */ | |
4394 | 2011 expansion = path; |
2012 | |
2013 for (size_t i = 0; i < path_len; i++) | |
4378 | 2014 { |
4394 | 2015 if (i + 1 < path_len |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2016 && IS_ENV_SEP (path[i]) && IS_ENV_SEP (path[i+1])) |
4394 | 2017 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2018 /* We have a doubled colon. */ |
4391 | 2019 |
4378 | 2020 /* Copy stuff up to and including the first colon. */ |
2021 /* 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
|
2022 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
|
2023 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2024 break; |
4378 | 2025 } |
2026 } | |
2027 } | |
4391 | 2028 |
4378 | 2029 return expansion; |
2030 } | |
2031 | |
4399 | 2032 /* Translate a path element to its corresponding director{y,ies}. */ |
4378 | 2033 |
2034 /* To avoid giving prototypes for all the routines and then their real | |
2035 definitions, we give all the subroutines first. The entry point is | |
2036 the last routine in the file. */ | |
4392 | 2037 |
4378 | 2038 /* Make a copy of DIR (unless it's null) and save it in L. Ensure that |
2039 DIR ends with a DIR_SEP for the benefit of later searches. */ | |
2040 | |
2041 static void | |
4390 | 2042 dir_list_add (str_llist_type *l, const std::string& dir) |
4378 | 2043 { |
4390 | 2044 char last_char = dir[dir.length () - 1]; |
4407 | 2045 |
4390 | 2046 std::string saved_dir = dir; |
4407 | 2047 |
2048 if (! (IS_DIR_SEP (last_char) || IS_DEVICE_SEP (last_char))) | |
4390 | 2049 saved_dir += DIR_SEP_STRING; |
4391 | 2050 |
4378 | 2051 str_llist_add (l, saved_dir); |
2052 } | |
2053 | |
4390 | 2054 /* Return true if FN is a directory or a symlink to a directory, |
2055 false if not. */ | |
2056 | |
2057 static bool | |
2058 dir_p (const std::string& fn) | |
2059 { | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2060 #if defined (WIN32) |
4391 | 2061 unsigned int fa = GetFileAttributes (fn.c_str ()); |
4390 | 2062 return (fa != 0xFFFFFFFF && (fa & FILE_ATTRIBUTE_DIRECTORY)); |
2063 #else | |
2064 struct stat stats; | |
2065 return stat (fn.c_str (), &stats) == 0 && S_ISDIR (stats.st_mode); | |
2066 #endif | |
2067 } | |
4391 | 2068 |
4378 | 2069 /* If DIR is a directory, add it to the list L. */ |
2070 | |
2071 static void | |
4390 | 2072 checked_dir_list_add (str_llist_type *l, const std::string& dir) |
4378 | 2073 { |
2074 if (dir_p (dir)) | |
2075 dir_list_add (l, dir); | |
2076 } | |
4392 | 2077 |
4378 | 2078 /* The cache. Typically, several paths have the same element; for |
2079 example, /usr/local/lib/texmf/fonts//. We don't want to compute the | |
2080 expansion of such a thing more than once. Even though we also cache | |
2081 the dir_links call, that's not enough -- without this path element | |
2082 caching as well, the execution time doubles. */ | |
2083 | |
4398 | 2084 struct cache_entry |
4378 | 2085 { |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
2086 cache_entry (void) : key (), value (0) { } |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
2087 |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
2088 ~cache_entry (void) { } |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
2089 |
4398 | 2090 std::string key; |
4378 | 2091 str_llist_type *value; |
4398 | 2092 }; |
2093 | |
2094 static cache_entry *the_cache = 0; | |
4378 | 2095 static unsigned cache_length = 0; |
2096 | |
2097 /* Associate KEY with VALUE. We implement the cache as a simple linear | |
2098 list, since it's unlikely to ever be more than a dozen or so elements | |
2099 long. We don't bother to check here if PATH has already been saved; | |
2100 we always add it to our list. We copy KEY but not VALUE; not sure | |
2101 that's right, but it seems to be all that's needed. */ | |
2102 | |
2103 static void | |
4398 | 2104 cache (const std::string key, str_llist_type *value) |
4378 | 2105 { |
4398 | 2106 cache_entry *new_cache = new cache_entry [cache_length+1]; |
2107 | |
4399 | 2108 for (unsigned i = 0; i < cache_length; i++) |
4398 | 2109 { |
2110 new_cache[i].key = the_cache[i].key; | |
2111 new_cache[i].value = the_cache[i].value; | |
2112 } | |
2113 | |
2114 delete [] the_cache; | |
2115 | |
2116 the_cache = new_cache; | |
2117 | |
2118 the_cache[cache_length].key = key; | |
2119 the_cache[cache_length].value = value; | |
2120 | |
4378 | 2121 cache_length++; |
2122 } | |
2123 | |
2124 /* To retrieve, just check the list in order. */ | |
2125 | |
2126 static str_llist_type * | |
4398 | 2127 cached (const std::string& key) |
4378 | 2128 { |
2129 unsigned p; | |
4391 | 2130 |
4378 | 2131 for (p = 0; p < cache_length; p++) |
2132 { | |
4398 | 2133 if (key == the_cache[p].key) |
4378 | 2134 return the_cache[p].value; |
2135 } | |
4391 | 2136 |
4398 | 2137 return 0; |
4378 | 2138 } |
4392 | 2139 |
4378 | 2140 /* Handle the magic path constructs. */ |
2141 | |
2142 /* Declare recursively called routine. */ | |
4398 | 2143 static void expand_elt (str_llist_type *, const std::string&, unsigned); |
4378 | 2144 |
2145 /* POST is a pointer into the original element (which may no longer be | |
2146 ELT) to just after the doubled DIR_SEP, perhaps to the null. Append | |
2147 subdirectories of ELT (up to ELT_LENGTH, which must be a /) to | |
2148 STR_LIST_PTR. */ | |
2149 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2150 #if defined (WIN32) |
4398 | 2151 |
4378 | 2152 /* Shared across recursive calls, it acts like a stack. */ |
4398 | 2153 static std::string dirname; |
2154 | |
2155 #else /* WIN32 */ | |
2156 | |
2157 /* Return -1 if FN isn't a directory, else its number of links. | |
2158 Duplicate the call to stat; no need to incur overhead of a function | |
2159 call for that little bit of cleanliness. */ | |
2160 | |
2161 static int | |
2162 dir_links (const std::string& fn) | |
2163 { | |
2164 std::map<std::string, long> link_table; | |
2165 | |
2166 long ret; | |
2167 | |
2168 if (link_table.find (fn) != link_table.end ()) | |
2169 ret = link_table[fn]; | |
2170 else | |
2171 { | |
2172 struct stat stats; | |
2173 | |
2174 ret = stat (fn.c_str (), &stats) == 0 && S_ISDIR (stats.st_mode) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2175 ? stats.st_nlink : static_cast<unsigned> (-1); |
4398 | 2176 |
2177 link_table[fn] = ret; | |
2178 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2179 #if defined (KPSE_DEBUG) |
4398 | 2180 if (KPSE_DEBUG_P (KPSE_DEBUG_STAT)) |
2181 DEBUGF2 ("dir_links (%s) => %ld\n", fn.c_str (), ret); | |
4378 | 2182 #endif |
4398 | 2183 } |
2184 | |
2185 return ret; | |
2186 } | |
2187 | |
2188 #endif /* WIN32 */ | |
4378 | 2189 |
21340
9f838471a5da
* kpse.cc: Avoid warning about static function in "header" file.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
2190 static inline void |
4398 | 2191 do_subdir (str_llist_type *str_list_ptr, const std::string& elt, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2192 unsigned elt_length, const std::string& post) |
4378 | 2193 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2194 #if defined (WIN32) |
4378 | 2195 WIN32_FIND_DATA find_file_data; |
2196 HANDLE hnd; | |
2197 int proceed; | |
2198 #else | |
2199 DIR *dir; | |
2200 struct dirent *e; | |
2201 #endif /* not WIN32 */ | |
4389 | 2202 |
4398 | 2203 std::string name = elt.substr (0, elt_length); |
4389 | 2204 |
4378 | 2205 assert (IS_DIR_SEP (elt[elt_length - 1]) |
2206 || IS_DEVICE_SEP (elt[elt_length - 1])); | |
4391 | 2207 |
4378 | 2208 #if defined (WIN32) |
4398 | 2209 |
2210 dirname = name + "/*.*"; /* "*.*" or "*" -- seems equivalent. */ | |
2211 | |
2212 hnd = FindFirstFile (dirname.c_str (), &find_file_data); | |
4378 | 2213 |
4389 | 2214 if (hnd == INVALID_HANDLE_VALUE) |
4378 | 2215 return; |
2216 | |
2217 /* Include top level before subdirectories, if nothing to match. */ | |
4398 | 2218 if (post.empty ()) |
4390 | 2219 dir_list_add (str_list_ptr, name); |
4398 | 2220 else |
2221 { | |
2222 /* If we do have something to match, see if it exists. For | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2223 example, POST might be 'pk/ljfour', and they might have a |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2224 directory '$TEXMF/fonts/pk/ljfour' that we should find. */ |
4398 | 2225 name += post; |
2226 expand_elt (str_list_ptr, name, elt_length); | |
2227 name.resize (elt_length); | |
2228 } | |
2229 | |
4378 | 2230 proceed = 1; |
4398 | 2231 |
4391 | 2232 while (proceed) |
2233 { | |
2234 if (find_file_data.cFileName[0] != '.') | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2235 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2236 /* Construct the potential subdirectory name. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2237 name += find_file_data.cFileName; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2238 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2239 if (find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2240 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2241 /* It's a directory, so append the separator. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2242 name += DIR_SEP_STRING; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2243 unsigned potential_len = name.length (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2244 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2245 do_subdir (str_list_ptr, name, potential_len, post); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2246 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2247 name.resize (elt_length); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2248 } |
4398 | 2249 |
4391 | 2250 proceed = FindNextFile (hnd, &find_file_data); |
4378 | 2251 } |
4398 | 2252 |
4391 | 2253 FindClose (hnd); |
4378 | 2254 |
2255 #else /* not WIN32 */ | |
2256 | |
2257 /* If we can't open it, quit. */ | |
10411 | 2258 dir = gnulib::opendir (name.c_str ()); |
4398 | 2259 |
2260 if (! dir) | |
4389 | 2261 return; |
4391 | 2262 |
4378 | 2263 /* Include top level before subdirectories, if nothing to match. */ |
4398 | 2264 if (post.empty ()) |
4390 | 2265 dir_list_add (str_list_ptr, name); |
4378 | 2266 else |
4398 | 2267 { |
2268 /* If we do have something to match, see if it exists. For | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2269 example, POST might be 'pk/ljfour', and they might have a |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2270 directory '$TEXMF/fonts/pk/ljfour' that we should find. */ |
4389 | 2271 name += post; |
4398 | 2272 expand_elt (str_list_ptr, name, elt_length); |
4389 | 2273 name.resize (elt_length); |
4378 | 2274 } |
2275 | |
14155 | 2276 while ((e = gnulib::readdir (dir))) |
4398 | 2277 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2278 /* If it begins with a '.', never mind. (This allows "hidden" |
4378 | 2279 directories that the algorithm won't find.) */ |
4398 | 2280 |
4378 | 2281 if (e->d_name[0] != '.') |
2282 { | |
2283 int links; | |
4391 | 2284 |
4378 | 2285 /* Construct the potential subdirectory name. */ |
4389 | 2286 name += e->d_name; |
4391 | 2287 |
4378 | 2288 /* If we can't stat it, or if it isn't a directory, continue. */ |
4398 | 2289 links = dir_links (name); |
4378 | 2290 |
2291 if (links >= 0) | |
4391 | 2292 { |
4378 | 2293 /* It's a directory, so append the separator. */ |
4389 | 2294 name += DIR_SEP_STRING; |
2295 unsigned potential_len = name.length (); | |
4391 | 2296 |
4378 | 2297 /* Should we recurse? To see if the subdirectory is a |
2298 leaf, check if it has two links (one for . and one for | |
2299 ..). This means that symbolic links to directories do | |
2300 not affect the leaf-ness. This is arguably wrong, but | |
2301 the only alternative I know of is to stat every entry | |
2302 in the directory, and that is unacceptably slow. | |
4391 | 2303 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2304 The #if here makes all this configurable at |
4378 | 2305 compile-time, so that if we're using VMS directories or |
2306 some such, we can still find subdirectories, even if it | |
2307 is much slower. */ | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2308 #if defined (ST_NLINK_TRICK) |
5622 | 2309 if (links != 2) |
4378 | 2310 #endif /* not ST_NLINK_TRICK */ |
2311 /* All criteria are met; find subdirectories. */ | |
4398 | 2312 do_subdir (str_list_ptr, name, potential_len, post); |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2313 #if defined (ST_NLINK_TRICK) |
4398 | 2314 else if (post.empty ()) |
4378 | 2315 /* Nothing to match, no recursive subdirectories to |
2316 look for: we're done with this branch. Add it. */ | |
4390 | 2317 dir_list_add (str_list_ptr, name); |
4378 | 2318 #endif |
2319 } | |
2320 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2321 /* Remove the directory entry we just checked from 'name'. */ |
4389 | 2322 name.resize (elt_length); |
4378 | 2323 } |
2324 } | |
4391 | 2325 |
4378 | 2326 xclosedir (dir); |
2327 #endif /* not WIN32 */ | |
2328 } | |
2329 | |
2330 /* Assume ELT is non-empty and non-NULL. Return list of corresponding | |
2331 directories (with no terminating NULL entry) in STR_LIST_PTR. Start | |
2332 looking for magic constructs at START. */ | |
2333 | |
2334 static void | |
4398 | 2335 expand_elt (str_llist_type *str_list_ptr, const std::string& elt, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2336 unsigned /* start */) |
4378 | 2337 { |
6306 | 2338 #if 0 |
2339 // We don't want magic constructs. | |
2340 | |
4398 | 2341 size_t elt_len = elt.length (); |
2342 | |
2343 size_t dir = start; | |
2344 | |
2345 | |
2346 while (dir < elt_len) | |
4378 | 2347 { |
4398 | 2348 if (IS_DIR_SEP (elt[dir])) |
4378 | 2349 { |
2350 /* If two or more consecutive /'s, find subdirectories. */ | |
4398 | 2351 if (++dir < elt_len && IS_DIR_SEP (elt[dir])) |
4378 | 2352 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2353 size_t i = dir; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2354 while (i < elt_len && IS_DIR_SEP (elt[i])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2355 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2356 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2357 std::string post = elt.substr (i); |
4398 | 2358 |
2359 do_subdir (str_list_ptr, elt, dir, post); | |
2360 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2361 return; |
4378 | 2362 } |
2363 | |
2364 /* No special stuff at this slash. Keep going. */ | |
2365 } | |
4398 | 2366 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2367 dir++; |
4378 | 2368 } |
6306 | 2369 #endif |
4391 | 2370 |
4378 | 2371 /* When we reach the end of ELT, it will be a normal filename. */ |
2372 checked_dir_list_add (str_list_ptr, elt); | |
2373 } | |
4392 | 2374 |
4378 | 2375 /* Here is the entry point. Returns directory list for ELT. */ |
2376 | |
4399 | 2377 /* Given a path element ELT, return a pointer to a NULL-terminated list |
2378 of the corresponding (existing) directory or directories, with | |
2379 trailing slashes, or NULL. If ELT is the empty string, check the | |
2380 current working directory. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
2381 |
4399 | 2382 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
|
2383 most likely only useful to be called from 'kpse_path_search', which |
4399 | 2384 has already assumed expansion has been done. */ |
2385 | |
2386 static str_llist_type * | |
4398 | 2387 kpse_element_dirs (const std::string& elt) |
4378 | 2388 { |
2389 str_llist_type *ret; | |
2390 | |
2391 /* If given nothing, return nothing. */ | |
4398 | 2392 if (elt.empty ()) |
2393 return 0; | |
4378 | 2394 |
2395 /* If we've already cached the answer for ELT, return it. */ | |
2396 ret = cached (elt); | |
2397 if (ret) | |
2398 return ret; | |
2399 | |
2400 /* We're going to have a real directory list to return. */ | |
4390 | 2401 ret = new str_llist_type; |
4398 | 2402 *ret = 0; |
4378 | 2403 |
2404 /* We handle the hard case in a subroutine. */ | |
2405 expand_elt (ret, elt, 0); | |
2406 | |
2407 /* Remember the directory list we just found, in case future calls are | |
2408 made with the same ELT. */ | |
2409 cache (elt, ret); | |
2410 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2411 #if defined (KPSE_DEBUG) |
4378 | 2412 if (KPSE_DEBUG_P (KPSE_DEBUG_EXPAND)) |
2413 { | |
4398 | 2414 DEBUGF1 ("path element %s =>", elt.c_str ()); |
4378 | 2415 if (ret) |
2416 { | |
2417 str_llist_elt_type *e; | |
2418 for (e = *ret; e; e = STR_LLIST_NEXT (*e)) | |
10411 | 2419 gnulib::fprintf (stderr, " %s", (STR_LLIST (*e)).c_str ()); |
4378 | 2420 } |
10411 | 2421 gnulib::putc ('\n', stderr); |
12912
e116dd862879
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
2422 gnulib::fflush (stderr); |
4378 | 2423 } |
2424 #endif /* KPSE_DEBUG */ | |
2425 | |
2426 return ret; | |
2427 } | |
2428 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2429 #if ! defined (WIN32) |
4385 | 2430 void |
2431 xclosedir (DIR *d) | |
2432 { | |
10411 | 2433 int ret = gnulib::closedir (d); |
4391 | 2434 |
4385 | 2435 if (ret != 0) |
2436 FATAL ("closedir failed"); | |
2437 } | |
4386 | 2438 #endif |
4385 | 2439 |
4399 | 2440 /* Implementation of a linked list of strings. */ |
4385 | 2441 |
2442 /* Add the new string STR to the end of the list L. */ | |
2443 | |
5085 | 2444 static void |
4390 | 2445 str_llist_add (str_llist_type *l, const std::string& str) |
4385 | 2446 { |
2447 str_llist_elt_type *e; | |
4390 | 2448 str_llist_elt_type *new_elt = new str_llist_elt_type; |
4391 | 2449 |
4385 | 2450 /* The new element will be at the end of the list. */ |
2451 STR_LLIST (*new_elt) = str; | |
2452 STR_LLIST_MOVED (*new_elt) = 0; | |
4398 | 2453 STR_LLIST_NEXT (*new_elt) = 0; |
4391 | 2454 |
4385 | 2455 /* Find the current end of the list. */ |
2456 for (e = *l; e && STR_LLIST_NEXT (*e); e = STR_LLIST_NEXT (*e)) | |
2457 ; | |
4391 | 2458 |
2459 if (! e) | |
4385 | 2460 *l = new_elt; |
2461 else | |
2462 STR_LLIST_NEXT (*e) = new_elt; | |
2463 } | |
4392 | 2464 |
4385 | 2465 /* Move an element towards the top. The idea is that when a file is |
2466 found in a given directory, later files will likely be in that same | |
2467 directory, and looking for the file in all the directories in between | |
2468 is thus a waste. */ | |
2469 | |
5085 | 2470 static void |
4385 | 2471 str_llist_float (str_llist_type *l, str_llist_elt_type *mover) |
2472 { | |
2473 str_llist_elt_type *last_moved, *unmoved; | |
4391 | 2474 |
4385 | 2475 /* If we've already moved this element, never mind. */ |
2476 if (STR_LLIST_MOVED (*mover)) | |
2477 return; | |
4391 | 2478 |
4385 | 2479 /* Find the first unmoved element (to insert before). We're |
2480 guaranteed this will terminate, since MOVER itself is currently | |
2481 unmoved, and it must be in L (by hypothesis). */ | |
4398 | 2482 for (last_moved = 0, unmoved = *l; STR_LLIST_MOVED (*unmoved); |
4385 | 2483 last_moved = unmoved, unmoved = STR_LLIST_NEXT (*unmoved)) |
2484 ; | |
2485 | |
2486 /* If we are the first unmoved element, nothing to relink. */ | |
2487 if (unmoved != mover) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2488 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2489 /* Remember 'mover's current successor, so we can relink 'mover's |
4385 | 2490 predecessor to it. */ |
2491 str_llist_elt_type *before_mover; | |
2492 str_llist_elt_type *after_mover = STR_LLIST_NEXT (*mover); | |
4391 | 2493 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2494 /* Find 'mover's predecessor. */ |
4385 | 2495 for (before_mover = unmoved; STR_LLIST_NEXT (*before_mover) != mover; |
2496 before_mover = STR_LLIST_NEXT (*before_mover)) | |
2497 ; | |
4391 | 2498 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2499 /* 'before_mover' now links to 'after_mover'. */ |
4385 | 2500 STR_LLIST_NEXT (*before_mover) = after_mover; |
2501 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2502 /* Insert 'mover' before 'unmoved' and after 'last_moved' (or at |
4385 | 2503 the head of the list). */ |
2504 STR_LLIST_NEXT (*mover) = unmoved; | |
4391 | 2505 if (! last_moved) |
4385 | 2506 *l = mover; |
2507 else | |
2508 STR_LLIST_NEXT (*last_moved) = mover; | |
2509 } | |
2510 | |
2511 /* We've moved it. */ | |
2512 STR_LLIST_MOVED (*mover) = 1; | |
2513 } | |
2514 | |
4399 | 2515 /* Variable expansion. */ |
4385 | 2516 |
2517 /* We have to keep track of variables being expanded, otherwise | |
2518 constructs like TEXINPUTS = $TEXINPUTS result in an infinite loop. | |
2519 (Or indirectly recursive variables, etc.) Our simple solution is to | |
2520 add to a list each time an expansion is started, and check the list | |
2521 before expanding. */ | |
2522 | |
4391 | 2523 static std::map <std::string, bool> expansions; |
4385 | 2524 |
2525 static void | |
4391 | 2526 expanding (const std::string& var, bool xp) |
4385 | 2527 { |
4391 | 2528 expansions[var] = xp; |
4385 | 2529 } |
2530 | |
2531 /* Return whether VAR is currently being expanding. */ | |
2532 | |
4391 | 2533 static bool |
2534 expanding_p (const std::string& var) | |
4385 | 2535 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2536 return (expansions.find (var) != expansions.end ()) ? expansions[var] : false; |
4385 | 2537 } |
4392 | 2538 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2539 /* 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
|
2540 at START and ends at END. If 'var' is not set, do not complain. |
4385 | 2541 This is a subroutine for the more complicated expansion function. */ |
2542 | |
2543 static void | |
4391 | 2544 expand (std::string &expansion, const std::string& var) |
4385 | 2545 { |
4391 | 2546 if (expanding_p (var)) |
2547 { | |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
2548 (*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
|
2549 ("Octave:pathsearch-syntax", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
2550 "kpathsea: variable '%s' references itself (eventually)", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2551 var.c_str ()); |
4385 | 2552 } |
4391 | 2553 else |
2554 { | |
2555 /* Check for an environment variable. */ | |
2556 std::string value = octave_env::getenv (var); | |
2557 | |
2558 if (! value.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2559 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2560 expanding (var, true); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2561 std::string tmp = kpse_var_expand (value); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2562 expanding (var, false); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2563 expansion += tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2564 } |
4391 | 2565 } |
4385 | 2566 } |
4392 | 2567 |
4385 | 2568 /* Can't think of when it would be useful to change these (and the |
2569 diagnostic messages assume them), but ... */ | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2570 #if ! defined (IS_VAR_START) |
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2571 /* starts all variable references */ |
4385 | 2572 #define IS_VAR_START(c) ((c) == '$') |
2573 #endif | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2574 #if ! defined (IS_VAR_CHAR) |
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2575 /* variable name constituent */ |
4385 | 2576 #define IS_VAR_CHAR(c) (isalnum (c) || (c) == '_') |
2577 #endif | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2578 #if ! defined (IS_VAR_BEGIN_DELIMITER) |
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2579 /* start delimited variable name (after $) */ |
4385 | 2580 #define IS_VAR_BEGIN_DELIMITER(c) ((c) == '{') |
2581 #endif | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
2582 #if ! defined (IS_VAR_END_DELIMITER) |
4385 | 2583 #define IS_VAR_END_DELIMITER(c) ((c) == '}') |
2584 #endif | |
2585 | |
2586 /* Maybe we should support some or all of the various shell ${...} | |
2587 constructs, especially ${var-value}. */ | |
2588 | |
5085 | 2589 static std::string |
4391 | 2590 kpse_var_expand (const std::string& src) |
4385 | 2591 { |
4389 | 2592 std::string expansion; |
4391 | 2593 |
2594 size_t src_len = src.length (); | |
2595 | |
4385 | 2596 /* Copy everything but variable constructs. */ |
4391 | 2597 for (size_t i = 0; i < src_len; i++) |
2598 { | |
2599 if (IS_VAR_START (src[i])) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2600 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2601 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2602 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2603 /* Three cases: '$VAR', '${VAR}', '$<anything-else>'. */ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2604 if (IS_VAR_CHAR (src[i])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2605 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2606 /* $V: collect name constituents, then expand. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2607 size_t var_end = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2608 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2609 do |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2610 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2611 var_end++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2612 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2613 while (IS_VAR_CHAR (src[var_end])); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2614 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2615 var_end--; /* had to go one past */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2616 expand (expansion, src.substr (i, var_end - i + 1)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2617 i = var_end; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2618 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2619 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2620 else if (IS_VAR_BEGIN_DELIMITER (src[i])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2621 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2622 /* ${: scan ahead for matching delimiter, then expand. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2623 size_t var_end = ++i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2624 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
2625 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
|
2626 var_end++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2627 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2628 if (var_end == src_len) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2629 { |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
2630 (*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
|
2631 ("Octave:pathsearch-syntax", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
2632 "%s: No matching } for ${", src.c_str ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2633 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
|
2634 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2635 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2636 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2637 expand (expansion, src.substr (i, var_end - i)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2638 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
|
2639 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2640 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2641 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2642 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2643 /* $<something-else>: error. */ |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
2644 (*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
|
2645 ("Octave:pathsearch-syntax", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
2646 "%s: Unrecognized variable construct '$%c'", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2647 src.c_str (), src[i]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2648 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2649 /* Just ignore those chars and keep going. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2650 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2651 } |
4391 | 2652 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2653 expansion += src[i]; |
4391 | 2654 } |
4389 | 2655 |
2656 return expansion; | |
4385 | 2657 } |