Mercurial > octave
annotate libinterp/corefcn/oct-hist.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 | 96f751f8392c |
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:
30356
diff
changeset
|
3 // Copyright (C) 1993-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 //////////////////////////////////////////////////////////////////////// |
2939 | 25 |
26 /* | |
27 | |
1 | 28 The functions listed below were adapted from similar functions from |
29 GNU Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free | |
30 Software Foundation, Inc. | |
31 | |
32 do_history edit_history_readline | |
33 do_edit_history edit_history_add_hist | |
34 | |
35 */ | |
36 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
37 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
38 # include "config.h" |
1 | 39 #endif |
40 | |
1343 | 41 #include <cstdlib> |
42 #include <cstring> | |
43 | |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21748
diff
changeset
|
44 #include <fstream> |
1750 | 45 #include <string> |
46 | |
1799 | 47 #include "cmd-hist.h" |
1802 | 48 #include "file-ops.h" |
3016 | 49 #include "lo-mappers.h" |
28467
159b6a1eb408
Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28088
diff
changeset
|
50 #include "lo-sysdep.h" |
2926 | 51 #include "oct-env.h" |
5305 | 52 #include "oct-time.h" |
1755 | 53 #include "str-vec.h" |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21748
diff
changeset
|
54 #include "unistd-wrappers.h" |
1755 | 55 |
1352 | 56 #include "defun.h" |
1 | 57 #include "error.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20983
diff
changeset
|
58 #include "errwarn.h" |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
59 #include "event-manager.h" |
1 | 60 #include "input.h" |
1742 | 61 #include "oct-hist.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
62 #include "ovl.h" |
1352 | 63 #include "pager.h" |
3018 | 64 #include "parse.h" |
1352 | 65 #include "sighandlers.h" |
1690 | 66 #include "sysdep.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
67 #include "interpreter.h" |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
68 #include "interpreter-private.h" |
1352 | 69 #include "unwind-prot.h" |
70 #include "utils.h" | |
2205 | 71 #include "variables.h" |
1 | 72 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31375
diff
changeset
|
73 OCTAVE_BEGIN_NAMESPACE(octave) |
29960
939bef0b66e0
merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
74 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
75 // Read the edited history lines from STREAM and return them |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
76 // one at a time. This can read unlimited length lines. The |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
77 // caller should free the storage. |
1 | 78 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
79 static char * |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
80 edit_history_readline (std::fstream& stream) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
81 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
82 char c; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
83 int line_len = 128; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
84 int lindex = 0; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
85 char *line = new char [line_len]; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
86 line[0] = '\0'; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
87 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
88 while (stream.get (c)) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
89 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
90 if (lindex + 2 >= line_len) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
91 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
92 char *tmp_line = new char [line_len += 128]; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
93 strcpy (tmp_line, line); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
94 delete [] line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
95 line = tmp_line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
96 } |
1799 | 97 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
98 if (c == '\n') |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
99 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
100 line[lindex++] = '\n'; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
101 line[lindex++] = '\0'; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
102 return line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
103 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
104 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
105 line[lindex++] = c; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
106 } |
1 | 107 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
108 if (! lindex) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
109 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
110 delete [] line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
111 return nullptr; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
112 } |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
113 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
114 if (lindex + 2 >= line_len) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
115 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
116 char *tmp_line = new char [lindex+3]; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
117 strcpy (tmp_line, line); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
118 delete [] line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
119 line = tmp_line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
120 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
121 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
122 // Finish with newline if none in file. |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
123 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
124 line[lindex++] = '\n'; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
125 line[lindex++] = '\0'; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
126 return line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
127 } |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
128 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
129 static void |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
130 edit_history_add_hist (const std::string& line) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
131 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
132 if (! line.empty ()) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
133 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
134 std::string tmp = line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
135 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
136 int len = tmp.length (); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
137 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
138 if (len > 0 && tmp[len-1] == '\n') |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
139 tmp.resize (len - 1); |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
140 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
141 if (! tmp.empty ()) |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
142 { |
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
143 if (command_history::add (tmp)) |
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
144 { |
31105
670a0d878af1
eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents:
30888
diff
changeset
|
145 event_manager& evmgr = __get_event_manager__ (); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
146 |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
147 evmgr.append_history (tmp); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
148 } |
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
149 } |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
150 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
151 } |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
152 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
153 static bool |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
154 get_int_arg (const octave_value& arg, int& val) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
155 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
156 bool ok = true; |
1 | 157 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
158 if (arg.is_string ()) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
159 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
160 std::string tmp = arg.string_value (); |
1 | 161 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
162 ok = sscanf (tmp.c_str (), "%d", &val) == 1; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
163 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
164 else if (arg.isnumeric ()) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
165 val = arg.int_value (); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
166 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
167 ok = false; |
1 | 168 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
169 return ok; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
170 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
171 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
172 static std::string |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
173 mk_tmp_hist_file (const octave_value_list& args, |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
174 bool insert_curr, const char *warn_for) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
175 { |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26485
diff
changeset
|
176 string_vector hlist = command_history::list (); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
177 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
178 int hist_count = hlist.numel () - 1; // switch to zero-based indexing |
1799 | 179 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
180 // The current command line is already part of the history list by |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
181 // the time we get to this point. Delete the cmd from the list when |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
182 // executing 'edit_history' so that it doesn't show up in the history |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
183 // but the actual commands performed will. |
1 | 184 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
185 if (! insert_curr) |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26485
diff
changeset
|
186 command_history::remove (hist_count); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
187 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
188 hist_count--; // skip last entry in history list |
1 | 189 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
190 // If no numbers have been specified, the default is to edit the |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
191 // last command in the history list. |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
192 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
193 int hist_beg = hist_count; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
194 int hist_end = hist_count; |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
195 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
196 bool reverse = false; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
197 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
198 // Process options. |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
199 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
200 int nargin = args.length (); |
1 | 201 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
202 if (nargin == 2) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
203 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
204 if (! get_int_arg (args(0), hist_beg) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
205 || ! get_int_arg (args(1), hist_end)) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
206 error ("%s: arguments must be integers", warn_for); |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
207 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
208 if (hist_beg < 0) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
209 hist_beg += (hist_count + 1); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
210 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
211 hist_beg--; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
212 if (hist_end < 0) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
213 hist_end += (hist_count + 1); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
214 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
215 hist_end--; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
216 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
217 else if (nargin == 1) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
218 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
219 if (! get_int_arg (args(0), hist_beg)) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
220 error ("%s: argument must be an integer", warn_for); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
221 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
222 if (hist_beg < 0) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
223 hist_beg += (hist_count + 1); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
224 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
225 hist_beg--; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
226 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
227 hist_end = hist_beg; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
228 } |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
229 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
230 if (hist_beg > hist_count || hist_end > hist_count) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
231 error ("%s: history specification out of range", warn_for); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
232 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
233 if (hist_end < hist_beg) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
234 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
235 std::swap (hist_end, hist_beg); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
236 reverse = true; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
237 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
238 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26485
diff
changeset
|
239 std::string name = sys::tempnam ("", "oct-"); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
240 |
28467
159b6a1eb408
Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28088
diff
changeset
|
241 std::ofstream file = sys::ofstream (name.c_str (), std::ios::out); |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
242 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
243 if (! file) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
244 error ("%s: couldn't open temporary file '%s'", warn_for, |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
245 name.c_str ()); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
246 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
247 if (reverse) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
248 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
249 for (int i = hist_end; i >= hist_beg; i--) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
250 file << hlist[i] << "\n"; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
251 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
252 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
253 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
254 for (int i = hist_beg; i <= hist_end; i++) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
255 file << hlist[i] << "\n"; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
256 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
257 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
258 file.close (); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
259 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
260 return name; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
261 } |
1 | 262 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
263 history_system::history_system (interpreter& interp) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
264 : m_interpreter (interp), m_input_from_tmp_file (false), |
26485
597fd034d212
restore default history file timestamp (bug #55329)
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
265 m_timestamp_format_string (default_timestamp_format ()) |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
266 { } |
1 | 267 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
268 void history_system::initialize (bool read_history_file) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
269 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
270 command_history::initialize (read_history_file, default_file (), |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
271 default_size (), |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
272 sys::env::getenv ("OCTAVE_HISTCONTROL")); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
273 |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
274 event_manager& evmgr = m_interpreter.get_event_manager (); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
275 |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
276 evmgr.set_history (command_history::list ()); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
277 } |
1 | 278 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
279 void history_system::write_timestamp (void) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
280 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
281 sys::localtime now; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
282 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
283 std::string timestamp = now.strftime (m_timestamp_format_string); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
284 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
285 if (! timestamp.empty ()) |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
286 { |
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
287 if (command_history::add (timestamp)) |
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
288 { |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
289 event_manager& evmgr = m_interpreter.get_event_manager (); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
290 |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
291 evmgr.append_history (timestamp); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
292 } |
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
293 } |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
294 } |
1 | 295 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
296 octave_value |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
297 history_system::input_from_tmp_file (const octave_value_list& args, |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
298 int nargout) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
299 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
300 return set_internal_variable (m_input_from_tmp_file, args, nargout, |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
301 "input_from_tmp_file"); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
302 } |
1 | 303 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
304 octave_value |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
305 history_system::timestamp_format_string (const octave_value_list& args, |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
306 int nargout) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
307 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
308 return set_internal_variable (m_timestamp_format_string, args, nargout, |
28088
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
309 "timestamp_format_string"); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
310 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
311 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
312 // Display, save, or load history. Stolen and modified from bash. |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
313 // |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
314 // Arg of -w FILENAME means write file, arg of -r FILENAME |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
315 // means read file, arg of -q means don't number lines. Arg of N |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
316 // means only display that many items. |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
317 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
318 string_vector history_system::do_history (const octave_value_list& args, |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
319 int nargout) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
320 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
321 bool numbered_output = nargout == 0; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
322 |
28857
43ad651cf5a0
eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents:
28854
diff
changeset
|
323 unwind_action restore_history_filename |
28850
445e5ac1f58d
in unwind_action objects, capture variables in lambda expressions when possible
John W. Eaton <jwe@octave.org>
parents:
28823
diff
changeset
|
324 ([] (const std::string& old_filename) |
28823
26cfccfee9a0
Replace unwind_protect with more efficient constructs (bug #59192).
Rik <rik@octave.org>
parents:
28467
diff
changeset
|
325 { |
26cfccfee9a0
Replace unwind_protect with more efficient constructs (bug #59192).
Rik <rik@octave.org>
parents:
28467
diff
changeset
|
326 command_history::set_file (old_filename); |
26cfccfee9a0
Replace unwind_protect with more efficient constructs (bug #59192).
Rik <rik@octave.org>
parents:
28467
diff
changeset
|
327 }, command_history::file ()); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
328 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
329 string_vector hlist; |
1 | 330 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
331 int nargin = args.length (); |
1 | 332 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
333 // Number of history lines to show (-1 = all) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
334 int limit = -1; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
335 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
336 for (octave_idx_type i = 0; i < nargin; i++) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
337 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
338 octave_value arg = args(i); |
64 | 339 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
340 std::string option; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
341 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
342 if (arg.is_string ()) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
343 option = arg.string_value (); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
344 else if (arg.isnumeric ()) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
345 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
346 limit = arg.int_value (); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
347 if (limit < 0) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
348 limit = -limit; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
349 continue; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
350 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
351 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
352 err_wrong_type_arg ("history", arg); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
353 |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
354 event_manager& evmgr = m_interpreter.get_event_manager (); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
355 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
356 if (option == "-r" || option == "-w" || option == "-a" |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
357 || option == "-n") |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
358 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
359 if (i < nargin - 1) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
360 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
361 std::string fname |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
362 = args(++i).xstring_value ("history: filename must be a string for %s option", |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
363 option.c_str ()); |
64 | 364 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
365 command_history::set_file (fname); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
366 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
367 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
368 command_history::set_file (default_file ()); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
369 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
370 if (option == "-a") |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
371 // Append 'new' lines to file. |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
372 command_history::append (); |
64 | 373 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
374 else if (option == "-w") |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
375 // Write entire history. |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
376 command_history::write (); |
1 | 377 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
378 else if (option == "-r") |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
379 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
380 // Read entire file. |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
381 command_history::read (); |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
382 evmgr.set_history (command_history::list ()); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
383 } |
1 | 384 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
385 else if (option == "-n") |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
386 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
387 // Read 'new' history from file. |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
388 command_history::read_range (); |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
389 evmgr.set_history (command_history::list ()); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
390 } |
1 | 391 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
392 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
393 panic_impossible (); |
1 | 394 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
395 return hlist; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
396 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
397 else if (option == "-c") |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
398 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
399 command_history::clear (); |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
400 evmgr.clear_history (); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
401 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
402 else if (option == "-q") |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
403 numbered_output = false; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
404 else if (option == "--") |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
405 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
406 i++; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
407 break; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
408 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
409 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
410 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
411 // The last argument found in the command list that looks like |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
412 // an integer will be used |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
413 int tmp; |
1 | 414 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
415 if (sscanf (option.c_str (), "%d", &tmp) == 1) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
416 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
417 if (tmp > 0) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
418 limit = tmp; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
419 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
420 limit = -tmp; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
421 } |
1 | 422 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
423 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
424 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
425 if (option.length () > 0 && option[0] == '-') |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
426 error ("history: unrecognized option '%s'", option.c_str ()); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
427 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
428 error ("history: bad non-numeric arg '%s'", option.c_str ()); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
429 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
430 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
431 } |
1 | 432 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
433 hlist = command_history::list (limit, numbered_output); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
434 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
435 int len = hlist.numel (); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
436 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
437 if (nargout == 0) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
438 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
439 for (octave_idx_type i = 0; i < len; i++) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
440 octave_stdout << hlist[i] << "\n"; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
441 } |
1 | 442 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
443 return hlist; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
444 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
445 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
446 void history_system::do_edit_history (const octave_value_list& args) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
447 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
448 std::string name = mk_tmp_hist_file (args, false, "edit_history"); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
449 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
450 if (name.empty ()) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
451 return; |
16016 | 452 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
453 // Call up our favorite editor on the file of commands. |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
454 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
455 environment& env = m_interpreter.get_environment (); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
456 std::string cmd = env.editor (); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
457 cmd.append (R"( ")" + name + '"'); |
1 | 458 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
459 // Ignore interrupts while we are off editing commands. Should we |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
460 // maybe avoid using system()? |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
461 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
462 volatile interrupt_handler old_interrupt_handler |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
463 = ignore_interrupts (); |
1 | 464 |
29950
6549fa7558ba
eliminate some unnecessary octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
465 int status = sys::system (cmd); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
466 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
467 set_interrupt_handler (old_interrupt_handler); |
3018 | 468 |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
27546
diff
changeset
|
469 // Check if text edition was successful. Abort the operation |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
470 // in case of failure. |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
471 if (status != EXIT_SUCCESS) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
472 error ("edit_history: text editor command failed"); |
3018 | 473 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
474 // Write the commands to the history file since source_file |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
475 // disables command line history while it executes. |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
476 |
28467
159b6a1eb408
Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28088
diff
changeset
|
477 std::fstream file = sys::fstream (name.c_str (), std::ios::in); |
1 | 478 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
479 char *line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
480 //int first = 1; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
481 while ((line = edit_history_readline (file)) != nullptr) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
482 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
483 // Skip blank lines. |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23719
diff
changeset
|
484 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
485 if (line[0] == '\n') |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
486 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
487 delete [] line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
488 continue; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
489 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
490 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
491 edit_history_add_hist (line); |
1 | 492 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
493 delete [] line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
494 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
495 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
496 file.close (); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
497 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
498 int(*unlink_fptr)(const std::string&) = sys::unlink; |
29253
28913793f678
prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents:
29141
diff
changeset
|
499 unwind_action unlink_action (unlink_fptr, name); |
28913793f678
prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents:
29141
diff
changeset
|
500 unwind_protect_var<bool> upv (m_input_from_tmp_file, true); |
64 | 501 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
502 // FIXME: instead of sourcing a file, we should just iterate through |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
503 // the list of commands, parsing and executing them one at a time as |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
504 // if they were entered interactively. |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
505 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
506 source_file (name); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
507 } |
3018 | 508 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
509 void history_system::do_run_history (const octave_value_list& args) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
510 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
511 std::string name = mk_tmp_hist_file (args, false, "run_history"); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
512 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
513 if (name.empty ()) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
514 return; |
3018 | 515 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
516 int(*unlink_fptr)(const std::string&) = sys::unlink; |
29253
28913793f678
prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents:
29141
diff
changeset
|
517 unwind_action unlink_action (unlink_fptr, name); |
28913793f678
prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents:
29141
diff
changeset
|
518 unwind_protect_var<bool> upv (m_input_from_tmp_file, true); |
64 | 519 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
520 // FIXME: instead of sourcing a file, we should just iterate through |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
521 // the list of commands, parsing and executing them one at a time as |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
522 // if they were entered interactively. |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
523 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
524 source_file (name); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
525 } |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23719
diff
changeset
|
526 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
527 std::string history_system::default_file (void) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
528 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
529 std::string file; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
530 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
531 std::string env_file = sys::env::getenv ("OCTAVE_HISTFILE"); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
532 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
533 if (! env_file.empty ()) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
534 file = env_file; |
64 | 535 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
536 if (file.empty ()) |
28854
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
537 { |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
538 // Default to $DATA/octave/history, where $DATA is the platform- |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
539 // dependent location for (roaming) user data files. |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
540 |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
541 std::string user_data_dir = sys::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:
28850
diff
changeset
|
542 |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
543 std::string hist_dir = user_data_dir + sys::file_ops::dir_sep_str () |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
544 + "octave"; |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
545 |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
546 file = sys::env::make_absolute ("history", hist_dir); |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
547 } |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
548 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
549 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
550 return file; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
551 } |
16431
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
552 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
553 int history_system::default_size (void) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
554 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
555 int size = 1000; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
556 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
557 std::string env_size = sys::env::getenv ("OCTAVE_HISTSIZE"); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
558 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
559 if (! env_size.empty ()) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
560 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
561 int val; |
5794 | 562 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
563 if (sscanf (env_size.c_str (), "%d", &val) == 1) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
564 size = (val > 0 ? val : 0); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
565 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
566 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
567 return size; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
568 } |
5305 | 569 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
570 std::string history_system::default_timestamp_format (void) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
571 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
572 return |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
573 "# Octave " OCTAVE_VERSION ", %a %b %d %H:%M:%S %Y %Z <" |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
574 + sys::env::get_user_name () |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
575 + '@' |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
576 + sys::env::get_host_name () |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
577 + '>'; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
578 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29950
diff
changeset
|
579 |
23719
69a111259a2c
eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
580 DEFMETHOD (edit_history, interp, args, , |
69a111259a2c
eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
581 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
582 @deftypefn {} {} edit_history |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
583 @deftypefnx {} {} edit_history @var{cmd_number} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
584 @deftypefnx {} {} edit_history @var{first} @var{last} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
585 Edit the history list using the editor named by the variable @env{EDITOR}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
586 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
587 The commands to be edited are first copied to a temporary file. When you |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
588 exit the editor, Octave executes the commands that remain in the file. It |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
589 is often more convenient to use @code{edit_history} to define functions |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
590 rather than attempting to enter them directly on the command line. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
591 The block of commands is executed as soon as you exit the editor. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
592 To avoid executing any commands, simply delete all the lines from the buffer |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
593 before leaving the editor. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
594 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
595 When invoked with no arguments, edit the previously executed command; |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
596 With one argument, edit the specified command @var{cmd_number}; |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
597 With two arguments, edit the list of commands between @var{first} and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
598 @var{last}. Command number specifiers may also be negative where -1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
599 refers to the most recently executed command. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
600 The following are equivalent and edit the most recently executed command. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
601 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
602 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
603 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
604 edit_history |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
605 edit_history -1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
606 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
607 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
608 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
609 When using ranges, specifying a larger number for the first command than the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
610 last command reverses the list of commands before they are placed in the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
611 buffer to be edited. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
612 @seealso{run_history, history} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
613 @end deftypefn */) |
529 | 614 { |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23719
diff
changeset
|
615 // FIXME: should this be limited to the top-level context? |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
616 if (args.length () > 2) |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
617 print_usage (); |
529 | 618 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
619 history_system& history_sys = interp.get_history_system (); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
620 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
621 history_sys.do_edit_history (args); |
529 | 622 |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
623 return ovl (); |
529 | 624 } |
625 | |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
626 DEFMETHOD (history, interp, args, nargout, |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
627 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
628 @deftypefn {} {} history |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
629 @deftypefnx {} {} history @var{opt1} @dots{} |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
630 @deftypefnx {} {@var{H} =} history () |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
631 @deftypefnx {} {@var{H} =} history (@var{opt1}, @dots{}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
632 If invoked with no arguments, @code{history} displays a list of commands |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
633 that you have executed. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
634 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
635 Valid options are: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
636 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
637 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
638 @item @var{n} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
639 @itemx -@var{n} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
640 Display only the most recent @var{n} lines of history. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
641 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
642 @item -c |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
643 Clear the history list. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
644 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
645 @item -q |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
646 Don't number the displayed lines of history. This is useful for cutting |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
647 and pasting commands using the X Window System. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
648 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
649 @item -r @var{file} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
650 Read the file @var{file}, appending its contents to the current |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
651 history list. If the name is omitted, use the default history file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
652 (normally @file{~/.octave_hist}). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
653 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
654 @item -w @var{file} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
655 Write the current history to the file @var{file}. If the name is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
656 omitted, use the default history file (normally @file{~/.octave_hist}). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
657 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
658 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
659 For example, to display the five most recent commands that you have |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
660 typed without displaying line numbers, use the command |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
661 @kbd{history -q 5}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
662 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
663 If invoked with a single output argument, the history will be saved to that |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
664 argument as a cell string and will not be output to screen. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
665 @seealso{edit_history, run_history} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
666 @end deftypefn */) |
529 | 667 { |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23719
diff
changeset
|
668 // FIXME: should this be limited to the top-level context? |
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23719
diff
changeset
|
669 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
670 history_system& history_sys = interp.get_history_system (); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
671 |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
672 // Call do_history even if nargout is zero to display history list. |
529 | 673 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
674 string_vector hlist = history_sys.do_history (args, nargout); |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
675 |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
676 return nargout > 0 ? ovl (Cell (hlist)) : ovl (); |
529 | 677 } |
678 | |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
679 DEFMETHOD (run_history, interp, args, , |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
680 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
681 @deftypefn {} {} run_history |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
682 @deftypefnx {} {} run_history @var{cmd_number} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
683 @deftypefnx {} {} run_history @var{first} @var{last} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
684 Run commands from the history list. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
685 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
686 When invoked with no arguments, run the previously executed command; |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
687 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
688 With one argument, run the specified command @var{cmd_number}; |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
689 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
690 With two arguments, run the list of commands between @var{first} and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
691 @var{last}. Command number specifiers may also be negative where -1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
692 refers to the most recently executed command. For example, the command |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
693 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
694 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
695 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
696 run_history |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
697 OR |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
698 run_history -1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
699 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
700 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
701 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
702 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
703 executes the most recent command again. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
704 The command |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
705 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
706 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
707 run_history 13 169 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
708 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
709 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
710 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
711 executes commands 13 through 169. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
712 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
713 Specifying a larger number for the first command than the last command |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
714 reverses the list of commands before executing them. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
715 For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
716 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
717 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
718 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
719 disp (1) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
720 disp (2) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
721 run_history -1 -2 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
722 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
723 2 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
724 1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
725 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
726 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
727 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
728 @seealso{edit_history, history} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
729 @end deftypefn */) |
529 | 730 { |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23719
diff
changeset
|
731 // FIXME: should this be limited to the top-level context? |
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23719
diff
changeset
|
732 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
733 history_system& history_sys = interp.get_history_system (); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
734 |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
735 if (args.length () > 2) |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
736 print_usage (); |
529 | 737 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
738 history_sys.do_run_history (args); |
529 | 739 |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
740 return ovl (); |
529 | 741 } |
742 | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
743 DEFUN (history_control, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
744 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
745 @deftypefn {} {@var{val} =} history_control () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
746 @deftypefnx {} {@var{old_val} =} history_control (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
747 Query or set the internal variable that specifies how commands are saved |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
748 to the history list. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
749 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
750 The default value is an empty character string, but may be overridden by the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
751 environment variable @w{@env{OCTAVE_HISTCONTROL}}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
752 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
753 The value of @code{history_control} is a colon-separated list of values |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
754 controlling how commands are saved on the history list. If the list |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
755 of values includes @code{ignorespace}, lines which begin with a space |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
756 character are not saved in the history list. A value of @code{ignoredups} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
757 causes lines matching the previous history entry to not be saved. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
758 A value of @code{ignoreboth} is shorthand for @code{ignorespace} and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
759 @code{ignoredups}. A value of @code{erasedups} causes all previous lines |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
760 matching the current line to be removed from the history list before that |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
761 line is saved. Any value not in the above list is ignored. If |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
762 @code{history_control} is the empty string, all commands are saved on |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
763 the history list, subject to the value of @code{history_save}. |
30329
81d26e8481a6
maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
764 @seealso{history_file, history_size, history_timestamp_format_string, |
81d26e8481a6
maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
765 history_save} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
766 @end deftypefn */) |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
767 { |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
768 octave_value retval; |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
769 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
770 std::string old_history_control = command_history::histcontrol (); |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
771 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
772 std::string tmp = old_history_control; |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
773 |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
774 retval = set_internal_variable (tmp, args, nargout, "history_control"); |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
775 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
776 if (tmp != old_history_control) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
777 command_history::process_histcontrol (tmp); |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
778 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
779 return retval; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
780 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
781 |
5794 | 782 DEFUN (history_size, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
783 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
784 @deftypefn {} {@var{val} =} history_size () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
785 @deftypefnx {} {@var{old_val} =} history_size (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
786 Query or set the internal variable that specifies how many entries |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
787 to store in the history file. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
788 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
789 The default value is @code{1000}, but may be overridden by the environment |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
790 variable @w{@env{OCTAVE_HISTSIZE}}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
791 @seealso{history_file, history_timestamp_format_string, history_save} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
792 @end deftypefn */) |
3016 | 793 { |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
794 octave_value retval; |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
795 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
796 int old_history_size = command_history::size (); |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
797 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
798 int tmp = old_history_size; |
5800 | 799 |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
800 retval = set_internal_variable (tmp, args, nargout, |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
801 "history_size", -1, |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
802 std::numeric_limits<int>::max ()); |
5800 | 803 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
804 if (tmp != old_history_size) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
805 command_history::set_size (tmp); |
5800 | 806 |
807 return retval; | |
3016 | 808 } |
809 | |
5794 | 810 DEFUN (history_file, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
811 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
812 @deftypefn {} {@var{val} =} history_file () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
813 @deftypefnx {} {@var{old_val} =} history_file (@var{new_val}) |
27546
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
814 Query or set the internal variable that specifies the name of the file used to |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
815 store command history. |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
816 |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
817 All future commands issued during the current Octave session will be written to |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
818 this new file (if the current setting of @code{history_save} allows for this). |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
819 |
28854
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
820 The default value is @file{@w{@env{$DATA}}/octave/history}, where |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
821 @w{@env{$DATA}} is the platform-specific location for (roaming) user data files |
31375
96f751f8392c
doc: grammar check documentation ahead of 8.1 release.
Rik <rik@octave.org>
parents:
31105
diff
changeset
|
822 (e.g., @w{@env{$XDG_DATA_HOME}} or, if that is not set, @file{~/.local/share} |
96f751f8392c
doc: grammar check documentation ahead of 8.1 release.
Rik <rik@octave.org>
parents:
31105
diff
changeset
|
823 on Unix-like operating systems or @w{@env{%APPDATA%}} on Windows). The default |
30356
95c2ac7b43d6
doc: Fix two more instances of long lines in libinterp/ directory.
Rik <rik@octave.org>
parents:
30354
diff
changeset
|
824 value may be overridden by the environment variable @w{@env{OCTAVE_HISTFILE}}. |
27546
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
825 |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
826 Programming Notes: |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
827 |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
828 If you want to permanently change the location of Octave's history file you |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
829 need to issue the @code{history_file} command in every new Octave session. |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
830 This can be achieved by using Octave's @file{.octaverc} startup file. |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
831 |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
832 If you also want to read the saved history commands of past Octave sessions |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
833 from this different history file, then you need to use the additional command |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
834 @code{history -r} after setting the new value of the history file. Example |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
835 code in Octave's startup file to do this might look like this: |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
836 |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
837 @example |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
838 @group |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
839 history_file ("~/new/.octave_hist"); |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
840 if (exist (history_file ())) |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
841 history ("-r", history_file()); |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
842 endif |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
843 @end group |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
844 @end example |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
845 |
30329
81d26e8481a6
maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
846 @seealso{history, history_control, history_save, history_size, |
81d26e8481a6
maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
847 history_timestamp_format_string} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
848 @end deftypefn */) |
5305 | 849 { |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
850 octave_value retval; |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
851 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
852 std::string old_history_file = command_history::file (); |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
853 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
854 std::string tmp = old_history_file; |
5305 | 855 |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
856 retval = set_internal_variable (tmp, args, nargout, "history_file"); |
5305 | 857 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
858 if (tmp != old_history_file) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
859 command_history::set_file (tmp); |
5305 | 860 |
5800 | 861 return retval; |
3016 | 862 } |
863 | |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
864 DEFMETHOD (history_timestamp_format_string, interp, args, nargout, |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
865 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
866 @deftypefn {} {@var{val} =} history_timestamp_format_string () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
867 @deftypefnx {} {@var{old_val} =} history_timestamp_format_string (@var{new_val}) |
30588
ed17822e7662
doc: Always have a return value for functions which set internal variables (bug #61681)
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
868 @deftypefnx {} {@var{old_val} =} history_timestamp_format_string (@var{new_val}, "local") |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
869 Query or set the internal variable that specifies the format string |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
870 for the comment line that is written to the history file when Octave |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
871 exits. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
872 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
873 The format string is passed to @code{strftime}. The default value is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
874 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
875 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
876 "# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>" |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
877 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
878 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
879 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
880 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
881 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
882 @seealso{strftime, history_file, history_size, history_save} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
883 @end deftypefn */) |
5794 | 884 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
885 history_system& history_sys = interp.get_history_system (); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
886 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
887 return history_sys.timestamp_format_string (args, nargout); |
5794 | 888 } |
5305 | 889 |
28088
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
890 /* |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
891 %!test |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
892 %! history_timestamp_format_string ("# Example history marker", "local"); |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
893 %! assert (history_timestamp_format_string (), "# Example history marker") |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
894 %!test <*57843> |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
895 %! history_timestamp_format_string ("", "local"); |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
896 %! assert (history_timestamp_format_string (), "") |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
897 */ |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
898 |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
899 DEFUN (history_save, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
900 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
901 @deftypefn {} {@var{val} =} history_save () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
902 @deftypefnx {} {@var{old_val} =} history_save (@var{new_val}) |
30588
ed17822e7662
doc: Always have a return value for functions which set internal variables (bug #61681)
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
903 @deftypefnx {} {@var{old_val} =} history_save (@var{new_val}, "local") |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
904 Query or set the internal variable that controls whether commands entered |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
905 on the command line are saved in the history file. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
906 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
907 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
908 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
909 The original variable value is restored when exiting the function. |
30329
81d26e8481a6
maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
910 @seealso{history_control, history_file, history_size, |
81d26e8481a6
maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
911 history_timestamp_format_string} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
912 @end deftypefn */) |
5794 | 913 { |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
914 octave_value retval; |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
915 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
916 bool old_history_save = ! command_history::ignoring_entries (); |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
917 |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
918 bool tmp = old_history_save; |
5794 | 919 |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
920 retval = set_internal_variable (tmp, args, nargout, "history_save"); |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
921 |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
922 if (tmp != old_history_save) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
923 command_history::ignore_entries (! tmp); |
5794 | 924 |
925 return retval; | |
3016 | 926 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29950
diff
changeset
|
927 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31375
diff
changeset
|
928 OCTAVE_END_NAMESPACE(octave) |