00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026
00027 #if defined (USE_READLINE)
00028
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032
00033 #include <readline/history.h>
00034
00035 void
00036 octave_add_history (const char *line)
00037 {
00038 add_history (line);
00039 }
00040
00041 int
00042 octave_where_history (void)
00043 {
00044 return where_history ();
00045 }
00046
00047 int
00048 octave_history_length (void)
00049 {
00050 return history_length;
00051 }
00052
00053 int
00054 octave_max_input_history (void)
00055 {
00056 return max_input_history;
00057 }
00058
00059 int
00060 octave_history_base (void)
00061 {
00062 return history_base;
00063 }
00064
00065 void
00066 octave_stifle_history (int n)
00067 {
00068 stifle_history (n);
00069 }
00070
00071 int
00072 octave_unstifle_history (void)
00073 {
00074 return unstifle_history ();
00075 }
00076
00077 int
00078 octave_history_is_stifled (void)
00079 {
00080 return history_is_stifled ();
00081 }
00082
00083 int
00084 octave_history_set_pos (int n)
00085 {
00086 return history_set_pos (n);
00087 }
00088
00089 int
00090 octave_read_history (const char *f)
00091 {
00092 return read_history (f);
00093 }
00094
00095 void
00096 octave_using_history (void)
00097 {
00098 using_history ();
00099 }
00100
00101 int
00102 octave_read_history_range (const char *f, int b, int e)
00103 {
00104 return read_history_range (f, b, e);
00105 }
00106
00107 int
00108 octave_write_history (const char *f)
00109 {
00110 return write_history (f);
00111 }
00112
00113 int
00114 octave_append_history (int n, const char *f)
00115 {
00116 return append_history (n, f);
00117 }
00118
00119 int
00120 octave_history_truncate_file (const char *f, int n)
00121 {
00122 return history_truncate_file (f, n);
00123 }
00124
00125 void
00126 octave_remove_history (int n)
00127 {
00128 HIST_ENTRY *discard = remove_history (n);
00129
00130 if (discard)
00131 {
00132 if (discard->line)
00133 free (discard->line);
00134
00135 free (discard);
00136 }
00137 }
00138
00139 char *
00140 octave_history_goto_mark (int n)
00141 {
00142 HIST_ENTRY *h;
00143
00144 char *retval = 0;
00145
00146 if (history_set_pos (n))
00147 {
00148 h = current_history ();
00149
00150 if (h)
00151 retval = h->line;
00152 }
00153
00154 return retval;
00155 }
00156
00157 char *
00158 octave_history_get (int n)
00159 {
00160 char *retval = 0;
00161
00162 HIST_ENTRY *h = history_get (n);
00163
00164 if (h)
00165 retval = h->line;
00166
00167 return retval;
00168 }
00169
00170 char **
00171 octave_history_list (int limit, int number_lines)
00172 {
00173 static char **retval = 0;
00174
00175 HIST_ENTRY **hlist = 0;
00176
00177 if (retval)
00178 {
00179 char **p = retval;
00180
00181 while (*p)
00182 free (*p++);
00183
00184 free (retval);
00185
00186 retval = 0;
00187 }
00188
00189 hlist = history_list ();
00190
00191 if (hlist)
00192 {
00193 int i, k;
00194
00195 int beg = 0;
00196 int end = 0;
00197 while (hlist[end])
00198 end++;
00199
00200 beg = (limit < 0 || end < limit) ? 0 : (end - limit);
00201
00202 retval = malloc ((end - beg + 1) * sizeof (char **));
00203
00204 k = 0;
00205 for (i = beg; i < end; i++)
00206 {
00207 char *line = hlist[i]->line;
00208 int len = line ? strlen (line) : 0;
00209 char *tmp = malloc (len + 64);
00210
00211 if (number_lines)
00212 sprintf (tmp, "%5d%c%s", i + history_base,
00213 hlist[i]->data ? '*' : ' ',
00214 line ? line : "");
00215 else
00216 sprintf (tmp, "%c%s", hlist[i]->data ? '*' : ' ',
00217 line ? line : "");
00218
00219 retval[k++] = tmp;
00220 }
00221
00222 retval[k] = 0;
00223 }
00224
00225 return retval;
00226 }
00227
00228 void
00229 octave_replace_history_entry (int which, const char *line)
00230 {
00231 HIST_ENTRY *discard = replace_history_entry (which, line, 0);
00232
00233 if (discard)
00234 {
00235 if (discard->line)
00236 free (discard->line);
00237
00238 free (discard);
00239 }
00240 }
00241
00242 #endif
00243
00244
00245
00246
00247
00248