Mercurial > octave
annotate liboctave/util/oct-rl-hist.c @ 21202:f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
* Array-C.cc, Array-b.cc, Array-ch.cc, Array-d.cc, Array-f.cc, Array-fC.cc,
Array-i.cc, Array-idx-vec.cc, Array-s.cc, Array-str.cc, Array-util.cc,
Array-voidp.cc, Array.cc, CColVector.cc, CDiagMatrix.cc, CMatrix.cc,
CNDArray.cc, CRowVector.cc, CSparse.cc, CSparse.h, DiagArray2.cc, MArray-C.cc,
MArray-d.cc, MArray-f.cc, MArray-fC.cc, MArray-i.cc, MArray-s.cc, MArray.cc,
MDiagArray2.cc, MSparse-C.cc, MSparse-d.cc, MSparse.h, MatrixType.cc,
PermMatrix.cc, Range.cc, Sparse-C.cc, Sparse-b.cc, Sparse-d.cc, Sparse.cc,
boolMatrix.cc, boolNDArray.cc, boolSparse.cc, chMatrix.cc, chNDArray.cc,
dColVector.cc, dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc,
dSparse.cc, dSparse.h, dim-vector.cc, fCColVector.cc, fCDiagMatrix.cc,
fCMatrix.cc, fCNDArray.cc, fCRowVector.cc, fColVector.cc, fDiagMatrix.cc,
fMatrix.cc, fNDArray.cc, fRowVector.cc, idx-vector.cc, int16NDArray.cc,
int32NDArray.cc, int64NDArray.cc, int8NDArray.cc, intNDArray.cc,
uint16NDArray.cc, uint32NDArray.cc, uint64NDArray.cc, uint8NDArray.cc,
blaswrap.c, cquit.c, f77-extern.cc, f77-fcn.c, f77-fcn.h, lo-error.c, quit.cc,
quit.h, CmplxAEPBAL.cc, CmplxCHOL.cc, CmplxGEPBAL.cc, CmplxHESS.cc, CmplxLU.cc,
CmplxQR.cc, CmplxQRP.cc, CmplxSCHUR.cc, CmplxSVD.cc, CollocWt.cc, DASPK.cc,
DASRT.cc, DASSL.cc, EIG.cc, LSODE.cc, ODES.cc, Quad.cc, base-lu.cc, base-qr.cc,
dbleAEPBAL.cc, dbleCHOL.cc, dbleGEPBAL.cc, dbleHESS.cc, dbleLU.cc, dbleQR.cc,
dbleQRP.cc, dbleSCHUR.cc, dbleSVD.cc, eigs-base.cc, fCmplxAEPBAL.cc,
fCmplxCHOL.cc, fCmplxGEPBAL.cc, fCmplxHESS.cc, fCmplxLU.cc, fCmplxQR.cc,
fCmplxQRP.cc, fCmplxSCHUR.cc, fCmplxSVD.cc, fEIG.cc, floatAEPBAL.cc,
floatCHOL.cc, floatGEPBAL.cc, floatHESS.cc, floatLU.cc, floatQR.cc,
floatQRP.cc, floatSCHUR.cc, floatSVD.cc, lo-mappers.cc, lo-specfun.cc,
oct-convn.cc, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-rand.cc,
oct-spparms.cc, randgamma.c, randmtzig.c, randpoisson.c, sparse-chol.cc,
sparse-dmsolve.cc, sparse-lu.cc, sparse-qr.cc, mx-defs.h, dir-ops.cc,
file-ops.cc, file-stat.cc, lo-sysdep.cc, mach-info.cc, oct-env.cc,
oct-group.cc, oct-openmp.h, oct-passwd.cc, oct-syscalls.cc, oct-time.cc,
oct-uname.cc, pathlen.h, sysdir.h, syswait.h, cmd-edit.cc, cmd-hist.cc,
data-conv.cc, f2c-main.c, glob-match.cc, lo-array-errwarn.cc,
lo-array-gripes.cc, lo-cutils.c, lo-cutils.h, lo-ieee.cc, lo-math.h,
lo-regexp.cc, lo-utils.cc, oct-base64.cc, oct-glob.cc, oct-inttypes.cc,
oct-inttypes.h, oct-locbuf.cc, oct-mutex.cc, oct-refcount.h, oct-rl-edit.c,
oct-rl-hist.c, oct-shlib.cc, oct-sort.cc, pathsearch.cc, singleton-cleanup.cc,
sparse-sort.cc, sparse-util.cc, statdefs.h, str-vec.cc, unwind-prot.cc,
url-transfer.cc, display-available.h, main-cli.cc, main-gui.cc, main.in.cc,
mkoctfile.in.cc, octave-config.in.cc, shared-fcns.h:
indent #ifdef blocks in liboctave and src directories.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 06 Feb 2016 06:40:13 -0800 |
parents | cfb58d9805fa |
children | 40de9f8f23a6 |
rev | line source |
---|---|
3519 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
3 Copyright (C) 2000-2015 John W. Eaton |
3519 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
3519 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
3519 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
20919
diff
changeset
|
24 # include <config.h> |
3519 | 25 #endif |
26 | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
27 #include "oct-rl-hist.h" |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
28 |
3519 | 29 #if defined (USE_READLINE) |
30 | |
31 #include <stdio.h> | |
32 #include <stdlib.h> | |
4587 | 33 #include <string.h> |
3519 | 34 |
35 #include <readline/history.h> | |
36 | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
37 /* check_history_control, hc_erasedup, and the core of |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
38 octave_add_history were borrowed from Bash. */ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
39 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
40 /* Check LINE against what HISTCONTROL says to do. Returns 1 if the line |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
41 should be saved; 0 if it should be discarded. */ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
42 static int |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
43 check_history_control (const char *line, int history_control) |
3519 | 44 { |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
45 HIST_ENTRY *temp; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
46 int r; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
47 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
48 if (history_control == 0) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
49 return 1; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
50 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
51 /* ignorespace or ignoreboth */ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
52 if ((history_control & HC_IGNSPACE) && *line == ' ') |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
53 return 0; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
54 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
55 /* ignoredups or ignoreboth */ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
56 if (history_control & HC_IGNDUPS) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
57 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
58 using_history (); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
59 temp = previous_history (); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
60 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
61 r = (temp == 0 || strcmp (temp->line, line)); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
62 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
63 using_history (); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
64 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
65 if (r == 0) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
66 return r; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
67 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
68 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
69 return 1; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
70 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
71 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
72 /* Remove all entries matching LINE from the history list. Triggered when |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
73 HISTCONTROL includes `erasedups'. */ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
74 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
75 static void |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
76 hc_erasedups (const char *line) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
77 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
78 HIST_ENTRY *temp; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
79 int r; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
80 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
81 using_history (); |
11490
0a4dfc867e60
avoid GCC warning for oct-rl-hist.c
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
82 while ((temp = previous_history ())) |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
83 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
84 if (! strcmp (temp->line, line)) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
85 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
86 r = where_history (); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
87 remove_history (r); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
88 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
89 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
90 using_history (); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
91 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
92 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
93 /* Check LINE against HISTCONTROL and add it to the history if it's OK. |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
94 Returns 1 if the line was saved in the history, 0 otherwise. */ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
95 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
96 int |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
97 octave_add_history (const char *line, int history_control) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
98 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
99 if (check_history_control (line, history_control)) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
100 { |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
101 /* We're committed to saving the line. If the user has requested it, |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
102 remove other matching lines from the history. */ |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
103 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
104 if (history_control & HC_ERASEDUPS) |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
105 hc_erasedups (line); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
106 |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
107 add_history (line); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
108 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
109 return 1; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
110 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
111 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
112 return 0; |
3519 | 113 } |
114 | |
115 int | |
116 octave_where_history (void) | |
117 { | |
118 return where_history (); | |
119 } | |
120 | |
121 int | |
122 octave_history_length (void) | |
123 { | |
124 return history_length; | |
125 } | |
126 | |
127 int | |
128 octave_max_input_history (void) | |
129 { | |
130 return max_input_history; | |
131 } | |
132 | |
133 int | |
134 octave_history_base (void) | |
135 { | |
136 return history_base; | |
137 } | |
138 | |
139 void | |
140 octave_stifle_history (int n) | |
141 { | |
3520 | 142 stifle_history (n); |
3519 | 143 } |
144 | |
145 int | |
146 octave_unstifle_history (void) | |
147 { | |
148 return unstifle_history (); | |
149 } | |
150 | |
151 int | |
152 octave_history_is_stifled (void) | |
153 { | |
154 return history_is_stifled (); | |
155 } | |
156 | |
157 int | |
158 octave_history_set_pos (int n) | |
159 { | |
160 return history_set_pos (n); | |
161 } | |
162 | |
163 int | |
164 octave_read_history (const char *f) | |
165 { | |
166 return read_history (f); | |
167 } | |
168 | |
169 void | |
170 octave_using_history (void) | |
171 { | |
3520 | 172 using_history (); |
3519 | 173 } |
174 | |
175 int | |
176 octave_read_history_range (const char *f, int b, int e) | |
177 { | |
178 return read_history_range (f, b, e); | |
179 } | |
180 | |
181 int | |
182 octave_write_history (const char *f) | |
183 { | |
184 return write_history (f); | |
185 } | |
186 | |
187 int | |
188 octave_append_history (int n, const char *f) | |
189 { | |
190 return append_history (n, f); | |
191 } | |
192 | |
193 int | |
194 octave_history_truncate_file (const char *f, int n) | |
195 { | |
196 return history_truncate_file (f, n); | |
197 } | |
198 | |
199 void | |
200 octave_remove_history (int n) | |
201 { | |
202 HIST_ENTRY *discard = remove_history (n); | |
203 | |
204 if (discard) | |
205 { | |
206 if (discard->line) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
207 free (discard->line); |
3519 | 208 |
209 free (discard); | |
210 } | |
211 } | |
212 | |
15397
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
213 void |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
214 octave_clear_history (void) |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
215 { |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
216 clear_history (); |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
217 } |
231d8d3b8225
provide command_hist::clear_history function
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
218 |
3519 | 219 char * |
220 octave_history_goto_mark (int n) | |
221 { | |
222 HIST_ENTRY *h; | |
223 | |
224 char *retval = 0; | |
225 | |
226 if (history_set_pos (n)) | |
227 { | |
228 h = current_history (); | |
229 | |
230 if (h) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
231 retval = h->line; |
3519 | 232 } |
233 | |
234 return retval; | |
235 } | |
236 | |
237 char * | |
238 octave_history_get (int n) | |
239 { | |
240 char *retval = 0; | |
241 | |
242 HIST_ENTRY *h = history_get (n); | |
243 | |
244 if (h) | |
245 retval = h->line; | |
246 | |
247 return retval; | |
248 } | |
249 | |
250 char ** | |
251 octave_history_list (int limit, int number_lines) | |
252 { | |
253 static char **retval = 0; | |
254 | |
255 HIST_ENTRY **hlist = 0; | |
256 | |
257 if (retval) | |
258 { | |
259 char **p = retval; | |
260 | |
3598 | 261 while (*p) |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
262 free (*p++); |
3519 | 263 |
264 free (retval); | |
265 | |
266 retval = 0; | |
267 } | |
268 | |
269 hlist = history_list (); | |
270 | |
271 if (hlist) | |
272 { | |
273 int i, k; | |
274 | |
275 int beg = 0; | |
276 int end = 0; | |
277 while (hlist[end]) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
278 end++; |
3519 | 279 |
280 beg = (limit < 0 || end < limit) ? 0 : (end - limit); | |
281 | |
20919
cfb58d9805fa
eliminate some type conversion warnings
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
282 retval = malloc ((size_t) (end - beg + 1) * sizeof (char **)); |
3519 | 283 |
284 k = 0; | |
285 for (i = beg; i < end; i++) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
286 { |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
287 char *line = hlist[i]->line; |
20919
cfb58d9805fa
eliminate some type conversion warnings
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
288 size_t len = line ? strlen (line) : 0; |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
289 char *tmp = malloc (len + 64); |
3519 | 290 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
291 if (number_lines) |
17225
06824c3b1ff3
Remove spurious leading space in unnumbered history list (bug #39724)
Mike Miller <mtmiller@ieee.org>
parents:
15397
diff
changeset
|
292 sprintf (tmp, "%5d %s", i + history_base, |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
293 line ? line : ""); |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
294 else |
17225
06824c3b1ff3
Remove spurious leading space in unnumbered history list (bug #39724)
Mike Miller <mtmiller@ieee.org>
parents:
15397
diff
changeset
|
295 strcpy (tmp, line ? line : ""); |
3519 | 296 |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
297 retval[k++] = tmp; |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
298 } |
3519 | 299 |
300 retval[k] = 0; | |
301 } | |
302 | |
303 return retval; | |
304 } | |
305 | |
306 void | |
307 octave_replace_history_entry (int which, const char *line) | |
308 { | |
309 HIST_ENTRY *discard = replace_history_entry (which, line, 0); | |
310 | |
311 if (discard) | |
312 { | |
313 if (discard->line) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
314 free (discard->line); |
3519 | 315 |
316 free (discard); | |
317 } | |
318 } | |
319 | |
320 #endif |