Mercurial > octave
annotate liboctave/system/oct-env.cc @ 31605:e88a07dec498 stable
maint: Use macros to begin/end C++ namespaces.
* oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE,
OCTAVE_END_NAMESPACE) that can be used to start/end a namespace.
* mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc,
__dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc,
__ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc,
__magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc,
auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h,
besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h,
call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc,
colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc,
defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc,
display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc,
ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h,
event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc,
fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc,
ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc,
getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc,
gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc,
graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc,
help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h,
interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h,
inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc,
latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h,
lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc,
ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h,
mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc,
oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h,
oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h,
oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h,
oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy,
ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc,
pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc,
qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h,
sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc,
sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h,
stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc,
symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h,
symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h,
text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc,
toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc,
url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc,
variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h,
__delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc,
audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh,
mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc,
cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h,
cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h,
cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc,
ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc,
ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h,
ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc,
ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h,
ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, 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-cell.cc,
op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.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-dm.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc,
op-fcm-fcs.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-fdm.cc, op-fm-fcm.cc,
op-fm-fcs.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-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc,
op-m-scm.cc, op-m-sm.cc, op-mi.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, ops.h,
anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h,
comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc,
oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h,
pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h,
pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h,
pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h,
pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h,
pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc,
pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc,
pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc,
pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc,
pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc,
pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc,
pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h,
pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h,
range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc,
chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h,
lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h,
oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h,
oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc,
qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc,
randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc,
sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc,
child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc,
file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h,
mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h,
oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc,
oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h,
base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h,
file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc,
lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h,
oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h,
oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h,
oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h,
pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h,
url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 01 Dec 2022 14:23:45 -0800 |
parents | 1921d9d0e62b |
children | aac27ad79be6 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30394
diff
changeset
|
3 // Copyright (C) 1996-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
2926 | 25 |
26 /* | |
27 | |
28 The functions listed below were adapted from a similar functions | |
29 from GNU Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 | |
30 Free Software Foundation, Inc. | |
31 | |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
32 octave::sys::env::do_absolute_pathname |
27276
7455523fdf01
style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents:
26836
diff
changeset
|
33 octave::sys::env::do_base_pathname |
7455523fdf01
style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents:
26836
diff
changeset
|
34 octave::sys::env::do_chdir |
7455523fdf01
style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents:
26836
diff
changeset
|
35 octave::sys::env::do_getcwd |
7455523fdf01
style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents:
26836
diff
changeset
|
36 octave::sys::env::do_make_absolute |
7455523fdf01
style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents:
26836
diff
changeset
|
37 octave::sys::env::do_polite_directory_format |
7455523fdf01
style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents:
26836
diff
changeset
|
38 octave::sys::env::pathname_backup |
2926 | 39 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
40 */ |
2926 | 41 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21614
diff
changeset
|
42 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
43 # include "config.h" |
2926 | 44 #endif |
45 | |
4093 | 46 #include <cctype> |
2926 | 47 #include <cstdlib> |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
48 #include <cstring> |
4093 | 49 |
3504 | 50 #include <string> |
2926 | 51 |
4097 | 52 #include "file-ops.h" |
2926 | 53 #include "lo-error.h" |
54 #include "lo-sysdep.h" | |
55 #include "lo-utils.h" | |
56 #include "oct-env.h" | |
30072
96a40641d86e
maint: rename liboctave oct-passwd.* to oct-password.* to match class name.
Rik <rik@octave.org>
parents:
30050
diff
changeset
|
57 #include "oct-password.h" |
2947 | 58 #include "oct-syscalls.h" |
21891
3ca0a5b1b313
hide gnulib progname.h header
John W. Eaton <jwe@octave.org>
parents:
21738
diff
changeset
|
59 #include "set-program-name-wrapper.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
60 #include "singleton-cleanup.h" |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21891
diff
changeset
|
61 #include "unistd-wrappers.h" |
2926 | 62 |
27832
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
63 #if defined (OCTAVE_USE_WINDOWS_API) |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
64 # include <windows.h> |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
65 # include <shlobj.h> |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
66 #endif |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
67 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
68 OCTAVE_BEGIN_NAMESPACE(octave) |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
69 |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
70 OCTAVE_BEGIN_NAMESPACE(sys) |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
71 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
72 env::env (void) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
73 : m_follow_symbolic_links (true), m_verbatim_pwd (true), |
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
74 m_current_directory (), m_prog_name (), m_prog_invocation_name (), |
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
75 m_user_name (), m_host_name () |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
76 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
77 // Get a real value for the current directory. |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
78 do_getcwd (); |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
79 |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
80 // Etc. |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
81 do_get_user_name (); |
2926 | 82 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
83 do_get_host_name (); |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
84 } |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
85 |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
86 env *env::m_instance = nullptr; |
2926 | 87 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
88 bool |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
89 env::instance_ok (void) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
90 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
91 bool retval = true; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
92 |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
93 if (! m_instance) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
94 { |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
95 m_instance = new env (); |
26369
0249ba4c9589
Fix static analyzer detected V668 issues (bug #55347).
Andreas Weber <octave@josoansi.de>
parents:
25916
diff
changeset
|
96 singleton_cleanup_list::add (cleanup_instance); |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
97 } |
2926 | 98 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
99 return retval; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
100 } |
2926 | 101 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
102 std::string |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
103 env::polite_directory_format (const std::string& name) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
104 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
105 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
106 ? m_instance->do_polite_directory_format (name) : ""; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
107 } |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
108 |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
109 bool |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
110 env::absolute_pathname (const std::string& s) |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
111 { |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
112 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
113 ? m_instance->do_absolute_pathname (s) : false; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
114 } |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
115 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
116 bool |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
117 env::rooted_relative_pathname (const std::string& s) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
118 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
119 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
120 ? m_instance->do_rooted_relative_pathname (s) : false; |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
121 } |
2926 | 122 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
123 std::string |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
124 env::base_pathname (const std::string& s) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
125 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
126 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
127 ? m_instance->do_base_pathname (s) : ""; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
128 } |
2926 | 129 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
130 std::string |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
131 env::make_absolute (const std::string& s, const std::string& dot_path) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
132 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
133 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
134 ? m_instance->do_make_absolute (s, dot_path) : ""; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
135 } |
2926 | 136 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
137 std::string |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
138 env::get_current_directory () |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
139 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
140 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
141 ? m_instance->do_getcwd () : ""; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
142 } |
2926 | 143 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
144 std::string |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
145 env::get_home_directory () |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
146 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
147 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
148 ? m_instance->do_get_home_directory () : ""; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
149 } |
2926 | 150 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
151 std::string |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
152 env::get_temp_directory () |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
153 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
154 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
155 ? m_instance->do_get_temp_directory () : ""; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
156 } |
2926 | 157 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
158 std::string |
27832
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
159 env::get_user_config_directory () |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
160 { |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
161 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
162 ? m_instance->do_get_user_config_directory () : ""; |
27832
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
163 } |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
164 |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
165 std::string |
28854
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
166 env::get_user_data_directory () |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
167 { |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
168 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
169 ? m_instance->do_get_user_data_directory () : ""; |
28854
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
170 } |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
171 |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
172 std::string |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
173 env::get_program_name (void) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
174 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
175 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
176 ? m_instance->m_prog_name : ""; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
177 } |
2926 | 178 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
179 std::string |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
180 env::get_program_invocation_name (void) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
181 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
182 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
183 ? m_instance->m_prog_invocation_name : ""; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
184 } |
2926 | 185 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
186 void |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
187 env::set_program_name (const std::string& s) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
188 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
189 if (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
190 m_instance->do_set_program_name (s); |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
191 } |
2926 | 192 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
193 std::string |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
194 env::get_user_name (void) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
195 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
196 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
197 ? m_instance->do_get_user_name () : ""; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
198 } |
2926 | 199 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
200 std::string |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
201 env::get_host_name (void) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
202 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
203 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
204 ? m_instance->do_get_host_name () : ""; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
205 } |
2926 | 206 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
207 std::string |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
208 env::do_get_temp_directory (void) const |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
209 { |
30881
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30863
diff
changeset
|
210 std::string tempd = do_getenv ("TMPDIR"); |
19458
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
17769
diff
changeset
|
211 |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
17769
diff
changeset
|
212 #if defined (__MINGW32__) || defined (_MSC_VER) |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19459
diff
changeset
|
213 |
30881
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30863
diff
changeset
|
214 if (tempd.empty ()) |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30863
diff
changeset
|
215 tempd = do_getenv ("TEMP"); |
19458
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
17769
diff
changeset
|
216 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
217 if (tempd.empty ()) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
218 tempd = do_getenv ("TMP"); |
19458
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
17769
diff
changeset
|
219 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
220 #if defined (P_tmpdir) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
221 if (tempd.empty ()) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
222 tempd = P_tmpdir; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
223 #endif |
19458
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
17769
diff
changeset
|
224 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
225 // Some versions of MinGW and MSVC either don't define P_tmpdir, or |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
226 // define it to a single backslash. In such cases just use C:\temp. |
23809
e56d84a16a2e
Fix "no match for 'operator=='" when comparing C++ string to char literal.
Markus Mützel <markus.muetzel@gmx.de>
parents:
23804
diff
changeset
|
227 if (tempd.empty () || tempd == R"(\)") |
23804
8057d3f0673d
Use C++11 raw string literals to avoid escaping backslashes in strings.
Rik <rik@octave.org>
parents:
23696
diff
changeset
|
228 tempd = R"(c:\temp)"; |
19458
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
17769
diff
changeset
|
229 |
20945
9d9270e2f98f
eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
230 #else |
19458
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
17769
diff
changeset
|
231 |
30881
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30863
diff
changeset
|
232 if (tempd.empty ()) |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30863
diff
changeset
|
233 tempd = do_getenv ("TMP"); |
19458
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
17769
diff
changeset
|
234 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
235 #if defined (P_tmpdir) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
236 if (tempd.empty ()) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
237 tempd = P_tmpdir; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
238 #else |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
239 if (tempd.empty ()) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
240 tempd = "/tmp"; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
241 #endif |
19458
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
17769
diff
changeset
|
242 |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
17769
diff
changeset
|
243 #endif |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
17769
diff
changeset
|
244 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
245 return tempd; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
246 } |
19458
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
17769
diff
changeset
|
247 |
27832
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
248 std::string |
30863
e2eed3610b7b
don't use mutable keyword for sys::env data members
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
249 env::do_get_user_config_directory (void) |
27832
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
250 { |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
251 std::string cfg_dir; |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
252 |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
253 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && defined (OCTAVE_USE_WINDOWS_API) |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
254 wchar_t path[MAX_PATH+1]; |
27838
659acfaaf0c9
Use APPDATA for startup file location on Windows (bug #40444).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27832
diff
changeset
|
255 if (SHGetFolderPathW (nullptr, CSIDL_APPDATA | CSIDL_FLAG_DONT_VERIFY, |
27832
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
256 nullptr, SHGFP_TYPE_CURRENT, path) == S_OK) |
29492
be4b78fb4411
Replace Unicode conversion functions from gnulib with STL functions.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
257 cfg_dir = u8_from_wstring (path); |
27832
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
258 #else |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
259 cfg_dir = do_getenv ("XDG_CONFIG_HOME"); |
29492
be4b78fb4411
Replace Unicode conversion functions from gnulib with STL functions.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
260 #endif |
27832
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
261 |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
262 if (cfg_dir.empty ()) |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
263 cfg_dir = do_get_home_directory () + sys::file_ops::dir_sep_str () |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30072
diff
changeset
|
264 + ".config"; |
27832
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
265 |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
266 return cfg_dir; |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
267 } |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
27276
diff
changeset
|
268 |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30072
diff
changeset
|
269 std::string |
30863
e2eed3610b7b
don't use mutable keyword for sys::env data members
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
270 env::do_get_user_data_directory (void) |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30072
diff
changeset
|
271 { |
28854
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
272 std::string data_dir; |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
273 |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
274 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && defined (OCTAVE_USE_WINDOWS_API) |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
275 wchar_t path[MAX_PATH+1]; |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
276 if (SHGetFolderPathW (nullptr, CSIDL_APPDATA | CSIDL_FLAG_DONT_VERIFY, |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
277 nullptr, SHGFP_TYPE_CURRENT, path) == S_OK) |
29492
be4b78fb4411
Replace Unicode conversion functions from gnulib with STL functions.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
278 data_dir = u8_from_wstring (path); |
28854
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
279 #else |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
280 data_dir = do_getenv ("XDG_DATA_HOME"); |
29492
be4b78fb4411
Replace Unicode conversion functions from gnulib with STL functions.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
281 #endif |
28854
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
282 |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
283 if (data_dir.empty ()) |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
284 data_dir = do_get_home_directory () + sys::file_ops::dir_sep_str () |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30072
diff
changeset
|
285 + ".local" + sys::file_ops::dir_sep_str () + "share"; |
28854
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
286 |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
287 return data_dir; |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30072
diff
changeset
|
288 } |
28854
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
289 |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
290 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
291 // FIXME: this leaves no way to distinguish between a |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
292 // variable that is not set and one that is set to the empty string. |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
293 // Is this a problem? |
2926 | 294 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
295 std::string |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
296 env::getenv (const std::string& name) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
297 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
298 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
299 ? m_instance->do_getenv (name) : ""; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
300 } |
2926 | 301 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
302 void |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
303 env::putenv (const std::string& name, const std::string& value) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
304 { |
25916
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
305 putenv_wrapper (name, value); |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
306 } |
2926 | 307 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
308 bool |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
309 env::have_x11_display (void) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
310 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
311 std::string display = getenv ("DISPLAY"); |
5489 | 312 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
313 return ! display.empty (); |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
314 } |
5489 | 315 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
316 bool |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
317 env::chdir (const std::string& newdir) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
318 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
319 return (instance_ok ()) |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
320 ? m_instance->do_chdir (newdir) : false; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
321 } |
2926 | 322 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
323 void |
30863
e2eed3610b7b
don't use mutable keyword for sys::env data members
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
324 env::do_set_program_name (const std::string& s) |
21610
eff26982a19b
avoid passing temp string to ::set_program_name (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
21609
diff
changeset
|
325 { |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
326 static bool initialized = false; |
21610
eff26982a19b
avoid passing temp string to ::set_program_name (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
21609
diff
changeset
|
327 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
328 if (! initialized) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
329 { |
21891
3ca0a5b1b313
hide gnulib progname.h header
John W. Eaton <jwe@octave.org>
parents:
21738
diff
changeset
|
330 // octave_set_program_name_wrapper returns a cleaned up |
3ca0a5b1b313
hide gnulib progname.h header
John W. Eaton <jwe@octave.org>
parents:
21738
diff
changeset
|
331 // version of the program name (stripping libtool's "lt-" |
3ca0a5b1b313
hide gnulib progname.h header
John W. Eaton <jwe@octave.org>
parents:
21738
diff
changeset
|
332 // prefix, for example). |
3ca0a5b1b313
hide gnulib progname.h header
John W. Eaton <jwe@octave.org>
parents:
21738
diff
changeset
|
333 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
334 // The string passed to gnulib's ::set_program_name function must |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
335 // exist for the duration of the program so allocate a copy here |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
336 // instead of passing S.c_str () which only exists as long as the |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
337 // string object S. |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
338 |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
339 m_prog_invocation_name |
21891
3ca0a5b1b313
hide gnulib progname.h header
John W. Eaton <jwe@octave.org>
parents:
21738
diff
changeset
|
340 = octave_set_program_name_wrapper (strsave (s.c_str ())); |
21610
eff26982a19b
avoid passing temp string to ::set_program_name (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
21609
diff
changeset
|
341 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
342 std::size_t pos |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
343 = m_prog_invocation_name.find_last_of (sys::file_ops::dir_sep_chars ()); |
2926 | 344 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
345 // Also keep a shortened version of the program name. |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
346 m_prog_name = (pos == std::string::npos |
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
347 ? m_prog_invocation_name |
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
348 : m_prog_invocation_name.substr (pos+1)); |
21614
9bb39b754ab1
finish previous change to octave_env::set_program_name
John W. Eaton <jwe@octave.org>
parents:
21610
diff
changeset
|
349 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
350 initialized = true; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
351 } |
21610
eff26982a19b
avoid passing temp string to ::set_program_name (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
21609
diff
changeset
|
352 } |
2926 | 353 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
354 // Return a pretty pathname. If the first part of the pathname is the |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
355 // same as $HOME, then replace that with '~'. |
2926 | 356 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
357 std::string |
30863
e2eed3610b7b
don't use mutable keyword for sys::env data members
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
358 env::do_polite_directory_format (const std::string& name) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
359 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
360 std::string retval; |
2926 | 361 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
362 std::string home_dir = do_get_home_directory (); |
2926 | 363 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
364 std::size_t len = home_dir.length (); |
2926 | 365 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
366 if (len > 1 && home_dir == name.substr (0, len) |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
367 && (name.length () == len || sys::file_ops::is_dir_sep (name[len]))) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
368 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
369 retval = "~"; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
370 retval.append (name.substr (len)); |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
371 } |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
372 else |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
373 retval = name; |
2926 | 374 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
375 return retval; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
376 } |
2926 | 377 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
378 bool |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
379 env::do_absolute_pathname (const std::string& s) const |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
380 { |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
381 std::size_t len = s.length (); |
4087 | 382 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
383 if (len == 0) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
384 return false; |
2926 | 385 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
386 if (sys::file_ops::is_dir_sep (s[0])) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
387 return true; |
2926 | 388 |
4101 | 389 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
390 if ((len == 2 && isalpha (s[0]) && s[1] == ':') |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
391 || (len > 2 && isalpha (s[0]) && s[1] == ':' |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
392 && sys::file_ops::is_dir_sep (s[2]))) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
393 return true; |
4087 | 394 #endif |
395 | |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
396 return false; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
397 } |
2926 | 398 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
399 bool |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
400 env::do_rooted_relative_pathname (const std::string& s) const |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
401 { |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
402 std::size_t len = s.length (); |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
403 |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
404 if (len == 0) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
405 return false; |
6838 | 406 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
407 if (len == 1 && s[0] == '.') |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
408 return true; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
409 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
410 if (len > 1 && s[0] == '.' && sys::file_ops::is_dir_sep (s[1])) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
411 return true; |
6838 | 412 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
413 if (len == 2 && s[0] == '.' && s[1] == '.') |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
414 return true; |
6838 | 415 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
416 if (len > 2 && s[0] == '.' && s[1] == '.' |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
417 && sys::file_ops::is_dir_sep (s[2])) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
418 return true; |
6838 | 419 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
420 return false; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
421 } |
6838 | 422 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
423 // Return the 'basename' of the pathname in STRING (the stuff after |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
424 // the last directory separator). If STRING is not a full pathname, |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
425 // simply return it. |
6838 | 426 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
427 std::string |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
428 env::do_base_pathname (const std::string& s) const |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
429 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
430 if (! (do_absolute_pathname (s) || do_rooted_relative_pathname (s))) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
431 return s; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
432 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
433 std::size_t pos = s.find_last_of (sys::file_ops::dir_sep_chars ()); |
2926 | 434 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
435 if (pos == std::string::npos) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
436 return s; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
437 else |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
438 return s.substr (pos+1); |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
439 } |
2926 | 440 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
441 // Turn STRING (a pathname) into an absolute pathname, assuming that |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
442 // DOT_PATH contains the symbolic location of the current directory. |
2926 | 443 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
444 std::string |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
445 env::do_make_absolute (const std::string& s, |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
446 const std::string& dot_path) const |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
447 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
448 if (dot_path.empty () || s.empty () || do_absolute_pathname (s)) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
449 return s; |
2926 | 450 |
22034
8df31c24dce3
Optimize do_make_absolute for most common calling usage.
Rik <rik@octave.org>
parents:
22029
diff
changeset
|
451 // Optimization: every time Octave returns to the prompt it calls |
8df31c24dce3
Optimize do_make_absolute for most common calling usage.
Rik <rik@octave.org>
parents:
22029
diff
changeset
|
452 // make_absolute_filename with '.' as argument. |
8df31c24dce3
Optimize do_make_absolute for most common calling usage.
Rik <rik@octave.org>
parents:
22029
diff
changeset
|
453 if (s == ".") |
8df31c24dce3
Optimize do_make_absolute for most common calling usage.
Rik <rik@octave.org>
parents:
22029
diff
changeset
|
454 return dot_path; |
8df31c24dce3
Optimize do_make_absolute for most common calling usage.
Rik <rik@octave.org>
parents:
22029
diff
changeset
|
455 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
456 std::string current_dir = dot_path; |
2926 | 457 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
458 if (! sys::file_ops::is_dir_sep (current_dir.back ())) |
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
459 current_dir.append (sys::file_ops::dir_sep_str ()); |
2926 | 460 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
461 std::size_t i = 0; |
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
462 std::size_t slen = s.length (); |
2926 | 463 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
464 while (i < slen) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
465 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
466 if (s[i] == '.') |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
467 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
468 if (i + 1 == slen) |
22034
8df31c24dce3
Optimize do_make_absolute for most common calling usage.
Rik <rik@octave.org>
parents:
22029
diff
changeset
|
469 break; |
4097 | 470 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
471 if (sys::file_ops::is_dir_sep (s[i+1])) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
472 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
473 i += 2; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
474 continue; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
475 } |
2926 | 476 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
477 if (s[i+1] == '.' |
22029
6e618b8277ad
Strip extra file separators with make_absolute_filename (bug #48351).
Rik <rik@octave.org>
parents:
21942
diff
changeset
|
478 && (i + 2 == slen |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
479 || sys::file_ops::is_dir_sep (s[i+2]))) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
480 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
481 i += 2; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
482 if (i != slen) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
483 i++; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
484 |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
485 pathname_backup (current_dir, 1); |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
486 |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
487 continue; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
488 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10278
diff
changeset
|
489 } |
2926 | 490 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
491 std::size_t sep_pos; |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
492 sep_pos = s.find_first_of (sys::file_ops::dir_sep_chars (), i); |
2926 | 493 |
22034
8df31c24dce3
Optimize do_make_absolute for most common calling usage.
Rik <rik@octave.org>
parents:
22029
diff
changeset
|
494 if (sep_pos == std::string::npos) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
495 { |
22034
8df31c24dce3
Optimize do_make_absolute for most common calling usage.
Rik <rik@octave.org>
parents:
22029
diff
changeset
|
496 current_dir.append (s, i, sep_pos-i); |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
497 break; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
498 } |
22034
8df31c24dce3
Optimize do_make_absolute for most common calling usage.
Rik <rik@octave.org>
parents:
22029
diff
changeset
|
499 else if (sep_pos == i) |
22029
6e618b8277ad
Strip extra file separators with make_absolute_filename (bug #48351).
Rik <rik@octave.org>
parents:
21942
diff
changeset
|
500 { |
6e618b8277ad
Strip extra file separators with make_absolute_filename (bug #48351).
Rik <rik@octave.org>
parents:
21942
diff
changeset
|
501 /* Two separators in a row, skip adding 2nd separator */ |
6e618b8277ad
Strip extra file separators with make_absolute_filename (bug #48351).
Rik <rik@octave.org>
parents:
21942
diff
changeset
|
502 i++; |
6e618b8277ad
Strip extra file separators with make_absolute_filename (bug #48351).
Rik <rik@octave.org>
parents:
21942
diff
changeset
|
503 } |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
504 else |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
505 { |
22034
8df31c24dce3
Optimize do_make_absolute for most common calling usage.
Rik <rik@octave.org>
parents:
22029
diff
changeset
|
506 current_dir.append (s, i, sep_pos-i+1); |
8df31c24dce3
Optimize do_make_absolute for most common calling usage.
Rik <rik@octave.org>
parents:
22029
diff
changeset
|
507 i = sep_pos + 1; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10278
diff
changeset
|
508 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10278
diff
changeset
|
509 } |
2926 | 510 |
22029
6e618b8277ad
Strip extra file separators with make_absolute_filename (bug #48351).
Rik <rik@octave.org>
parents:
21942
diff
changeset
|
511 // Strip any trailing directory separator |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
512 if (sys::file_ops::is_dir_sep (current_dir.back ())) |
22029
6e618b8277ad
Strip extra file separators with make_absolute_filename (bug #48351).
Rik <rik@octave.org>
parents:
21942
diff
changeset
|
513 current_dir.pop_back (); |
22066
c4ef0b3dc40c
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22034
diff
changeset
|
514 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
515 return current_dir; |
2926 | 516 } |
517 | |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
518 // Return a string which is the current working directory. |
2926 | 519 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
520 std::string |
30863
e2eed3610b7b
don't use mutable keyword for sys::env data members
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
521 env::do_getcwd (void) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
522 { |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
523 if (! m_follow_symbolic_links) |
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
524 m_current_directory = ""; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
525 |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
526 if (m_verbatim_pwd || m_current_directory.empty ()) |
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
527 m_current_directory = sys::getcwd (); |
2926 | 528 |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
529 return m_current_directory; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
530 } |
2926 | 531 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
532 // This value is not cached because it can change while Octave is |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
533 // running. |
2926 | 534 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
535 std::string |
30863
e2eed3610b7b
don't use mutable keyword for sys::env data members
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
536 env::do_get_home_directory (void) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
537 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
538 std::string hd = do_getenv ("HOME"); |
2926 | 539 |
6096 | 540 #if defined (__MINGW32__) || defined (_MSC_VER) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
541 // Maybe we are started directly from cmd.exe. |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
542 if (hd.empty ()) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
543 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
544 std::string drv = do_getenv ("HOMEDRIVE"); |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
545 if (drv.empty ()) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
546 hd = do_getenv ("HOMEPATH"); |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
547 else |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
548 hd = drv + do_getenv ("HOMEPATH"); |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
549 } |
5451 | 550 #endif |
551 | |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
552 if (hd.empty ()) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
553 { |
27276
7455523fdf01
style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents:
26836
diff
changeset
|
554 sys::password pw = sys::password::getpwuid (sys::getuid ()); |
2947 | 555 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
556 hd = (pw ? pw.dir () : std::string (sys::file_ops::dir_sep_str ())); |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
557 } |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
558 |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
559 return hd; |
2947 | 560 } |
561 | |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
562 std::string |
30863
e2eed3610b7b
don't use mutable keyword for sys::env data members
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
563 env::do_get_user_name (void) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
564 { |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
565 if (m_user_name.empty ()) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
566 { |
27276
7455523fdf01
style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents:
26836
diff
changeset
|
567 sys::password pw = sys::password::getpwuid (sys::getuid ()); |
2926 | 568 |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
569 m_user_name = (pw ? pw.name () : "unknown"); |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
570 } |
2926 | 571 |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
572 return m_user_name; |
2926 | 573 } |
574 | |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
575 std::string |
30863
e2eed3610b7b
don't use mutable keyword for sys::env data members
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
576 env::do_get_host_name (void) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
577 { |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
578 if (m_host_name.empty ()) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
579 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
580 char hostname[1024]; |
2926 | 581 |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21891
diff
changeset
|
582 int status = octave_gethostname_wrapper (hostname, 1023); |
2926 | 583 |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
584 m_host_name = (status < 0) ? "unknown" : hostname; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
585 } |
2926 | 586 |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
587 return m_host_name; |
2926 | 588 } |
589 | |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
590 std::string |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
591 env::do_getenv (const std::string& name) const |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
592 { |
25916
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
593 return getenv_wrapper (name); |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
594 } |
2926 | 595 |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23812
diff
changeset
|
596 // Do the work of changing to the directory NEWDIR. |
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23812
diff
changeset
|
597 // Handle symbolic link following, etc. |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
598 |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
599 bool |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
600 env::do_chdir (const std::string& newdir) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
601 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
602 bool retval = false; |
2926 | 603 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
604 std::string tmp; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
605 |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
606 if (m_follow_symbolic_links) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
607 { |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
608 if (m_current_directory.empty ()) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
609 do_getcwd (); |
2926 | 610 |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
611 if (m_current_directory.empty ()) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
612 tmp = newdir; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
613 else |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
614 tmp = do_make_absolute (newdir, m_current_directory); |
2926 | 615 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
616 // Get rid of trailing directory separator. |
23812
057a894914df
Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents:
23809
diff
changeset
|
617 if (tmp.length () > 1 && sys::file_ops::is_dir_sep (tmp.back ())) |
057a894914df
Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents:
23809
diff
changeset
|
618 tmp.pop_back (); |
2926 | 619 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
620 if (! sys::chdir (tmp)) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
621 { |
30050
0a8c6cafd7cc
maint: use "m_" prefix for member variables in oct-env.h.
Rik <rik@octave.org>
parents:
29655
diff
changeset
|
622 m_current_directory = tmp; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
623 retval = true; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
624 } |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
625 } |
2926 | 626 else |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
627 retval = (! sys::chdir (newdir)); |
2926 | 628 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
629 return retval; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
630 } |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
631 |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
632 // Remove the last N directories from PATH. |
2926 | 633 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
634 void |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
635 env::pathname_backup (std::string& path, int n) const |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
636 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
637 if (path.empty ()) |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
638 return; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
639 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
640 std::size_t i = path.length () - 1; |
2926 | 641 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
642 while (n--) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10278
diff
changeset
|
643 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
644 while (sys::file_ops::is_dir_sep (path[i]) && i > 0) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
645 i--; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
646 |
26819
670ebc29ec69
make_absolute_filename: Don't strip drive letter from path (bug #36677).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
647 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) |
670ebc29ec69
make_absolute_filename: Don't strip drive letter from path (bug #36677).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
648 // Don't strip file letter part. |
670ebc29ec69
make_absolute_filename: Don't strip drive letter from path (bug #36677).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
649 if (i == 1 && path[i] == ':') |
670ebc29ec69
make_absolute_filename: Don't strip drive letter from path (bug #36677).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
650 { |
670ebc29ec69
make_absolute_filename: Don't strip drive letter from path (bug #36677).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
651 // Keep path separator if present. |
670ebc29ec69
make_absolute_filename: Don't strip drive letter from path (bug #36677).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
652 i = std::min (i+2, path.length ()); |
670ebc29ec69
make_absolute_filename: Don't strip drive letter from path (bug #36677).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
653 break; |
670ebc29ec69
make_absolute_filename: Don't strip drive letter from path (bug #36677).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
654 } |
670ebc29ec69
make_absolute_filename: Don't strip drive letter from path (bug #36677).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
655 #endif |
670ebc29ec69
make_absolute_filename: Don't strip drive letter from path (bug #36677).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
656 |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
657 while (! sys::file_ops::is_dir_sep (path[i]) && i > 0) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
658 i--; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
659 |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
660 i++; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10278
diff
changeset
|
661 } |
2926 | 662 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
663 path.resize (i); |
2926 | 664 } |
665 | |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
666 void |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
667 env::error (int err_num) const |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
668 { |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
669 (*current_liboctave_error_handler) ("%s", std::strerror (err_num)); |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
670 } |
2926 | 671 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
672 void |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
673 env::error (const std::string& s) const |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
674 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
675 (*current_liboctave_error_handler) ("%s", s.c_str ()); |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
676 } |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
677 |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
678 OCTAVE_END_NAMESPACE(sys) |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
679 OCTAVE_END_NAMESPACE(octave) |