Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/lib/readline/history.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||
4 | - | |||||||||||||||||||||||||
5 | - | |||||||||||||||||||||||||
6 | - | |||||||||||||||||||||||||
7 | - | |||||||||||||||||||||||||
8 | - | |||||||||||||||||||||||||
9 | static char *hist_inittime (void); | - | ||||||||||||||||||||||||
10 | static HIST_ENTRY **the_history = (HIST_ENTRY **) | - | ||||||||||||||||||||||||
11 | ((void *)0) | - | ||||||||||||||||||||||||
12 | ; | - | ||||||||||||||||||||||||
13 | - | |||||||||||||||||||||||||
14 | - | |||||||||||||||||||||||||
15 | - | |||||||||||||||||||||||||
16 | static int history_stifled; | - | ||||||||||||||||||||||||
17 | - | |||||||||||||||||||||||||
18 | - | |||||||||||||||||||||||||
19 | static int history_size; | - | ||||||||||||||||||||||||
20 | - | |||||||||||||||||||||||||
21 | - | |||||||||||||||||||||||||
22 | - | |||||||||||||||||||||||||
23 | int history_max_entries; | - | ||||||||||||||||||||||||
24 | int max_input_history; | - | ||||||||||||||||||||||||
25 | - | |||||||||||||||||||||||||
26 | - | |||||||||||||||||||||||||
27 | - | |||||||||||||||||||||||||
28 | int history_offset; | - | ||||||||||||||||||||||||
29 | - | |||||||||||||||||||||||||
30 | - | |||||||||||||||||||||||||
31 | int history_length; | - | ||||||||||||||||||||||||
32 | - | |||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||
34 | int history_base = 1; | - | ||||||||||||||||||||||||
35 | - | |||||||||||||||||||||||||
36 | - | |||||||||||||||||||||||||
37 | HISTORY_STATE * | - | ||||||||||||||||||||||||
38 | history_get_history_state (void) | - | ||||||||||||||||||||||||
39 | { | - | ||||||||||||||||||||||||
40 | HISTORY_STATE *state; | - | ||||||||||||||||||||||||
41 | - | |||||||||||||||||||||||||
42 | state = (HISTORY_STATE *)xmalloc (sizeof (HISTORY_STATE)); | - | ||||||||||||||||||||||||
43 | state->entries = the_history; | - | ||||||||||||||||||||||||
44 | state->offset = history_offset; | - | ||||||||||||||||||||||||
45 | state->length = history_length; | - | ||||||||||||||||||||||||
46 | state->size = history_size; | - | ||||||||||||||||||||||||
47 | state->flags = 0; | - | ||||||||||||||||||||||||
48 | if (history_stifled
| 0 | ||||||||||||||||||||||||
49 | state->flags |= 0x01; never executed: state->flags |= 0x01; | 0 | ||||||||||||||||||||||||
50 | - | |||||||||||||||||||||||||
51 | return never executed: (state);return (state); never executed: return (state); | 0 | ||||||||||||||||||||||||
52 | } | - | ||||||||||||||||||||||||
53 | - | |||||||||||||||||||||||||
54 | - | |||||||||||||||||||||||||
55 | void | - | ||||||||||||||||||||||||
56 | history_set_history_state (HISTORY_STATE *state) | - | ||||||||||||||||||||||||
57 | { | - | ||||||||||||||||||||||||
58 | the_history = state->entries; | - | ||||||||||||||||||||||||
59 | history_offset = state->offset; | - | ||||||||||||||||||||||||
60 | history_length = state->length; | - | ||||||||||||||||||||||||
61 | history_size = state->size; | - | ||||||||||||||||||||||||
62 | if (state->flags & 0x01
| 0 | ||||||||||||||||||||||||
63 | history_stifled = 1; never executed: history_stifled = 1; | 0 | ||||||||||||||||||||||||
64 | } never executed: end of block | 0 | ||||||||||||||||||||||||
65 | - | |||||||||||||||||||||||||
66 | - | |||||||||||||||||||||||||
67 | - | |||||||||||||||||||||||||
68 | void | - | ||||||||||||||||||||||||
69 | using_history (void) | - | ||||||||||||||||||||||||
70 | { | - | ||||||||||||||||||||||||
71 | history_offset = history_length; | - | ||||||||||||||||||||||||
72 | } executed 1028 times by 1 test: end of block Executed by:
| 1028 | ||||||||||||||||||||||||
73 | - | |||||||||||||||||||||||||
74 | - | |||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||
76 | - | |||||||||||||||||||||||||
77 | int | - | ||||||||||||||||||||||||
78 | history_total_bytes (void) | - | ||||||||||||||||||||||||
79 | { | - | ||||||||||||||||||||||||
80 | register int i, result; | - | ||||||||||||||||||||||||
81 | - | |||||||||||||||||||||||||
82 | for (i = result = 0; the_history
| 0 | ||||||||||||||||||||||||
83 | result += (strlen ((the_history[i])->line) + strlen ((the_history[i])->timestamp)); never executed: result += (strlen ((the_history[i])->line) + strlen ((the_history[i])->timestamp)); | 0 | ||||||||||||||||||||||||
84 | - | |||||||||||||||||||||||||
85 | return never executed: (result);return (result); never executed: return (result); | 0 | ||||||||||||||||||||||||
86 | } | - | ||||||||||||||||||||||||
87 | - | |||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||
89 | - | |||||||||||||||||||||||||
90 | int | - | ||||||||||||||||||||||||
91 | where_history (void) | - | ||||||||||||||||||||||||
92 | { | - | ||||||||||||||||||||||||
93 | return executed 58 times by 1 test: (history_offset);return (history_offset); Executed by:
executed 58 times by 1 test: return (history_offset); Executed by:
| 58 | ||||||||||||||||||||||||
94 | } | - | ||||||||||||||||||||||||
95 | - | |||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||
97 | - | |||||||||||||||||||||||||
98 | int | - | ||||||||||||||||||||||||
99 | history_set_pos (int pos) | - | ||||||||||||||||||||||||
100 | { | - | ||||||||||||||||||||||||
101 | if (pos > history_length
| 0-5 | ||||||||||||||||||||||||
102 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||||||||
103 | history_offset = pos; | - | ||||||||||||||||||||||||
104 | return executed 5 times by 1 test: (1);return (1); Executed by:
executed 5 times by 1 test: return (1); Executed by:
| 5 | ||||||||||||||||||||||||
105 | } | - | ||||||||||||||||||||||||
106 | - | |||||||||||||||||||||||||
107 | - | |||||||||||||||||||||||||
108 | - | |||||||||||||||||||||||||
109 | - | |||||||||||||||||||||||||
110 | HIST_ENTRY ** | - | ||||||||||||||||||||||||
111 | history_list (void) | - | ||||||||||||||||||||||||
112 | { | - | ||||||||||||||||||||||||
113 | return executed 53 times by 1 test: (the_history);return (the_history); Executed by:
executed 53 times by 1 test: return (the_history); Executed by:
| 53 | ||||||||||||||||||||||||
114 | } | - | ||||||||||||||||||||||||
115 | - | |||||||||||||||||||||||||
116 | - | |||||||||||||||||||||||||
117 | - | |||||||||||||||||||||||||
118 | HIST_ENTRY * | - | ||||||||||||||||||||||||
119 | current_history (void) | - | ||||||||||||||||||||||||
120 | { | - | ||||||||||||||||||||||||
121 | return executed 11 times by 1 test: ((history_offset == history_length) || the_history == 0)return ((history_offset == history_length) || the_history == 0) ? (HIST_ENTRY *) ((void *)0) : the_history[history_offset]; Executed by:
executed 11 times by 1 test: return ((history_offset == history_length) || the_history == 0) ? (HIST_ENTRY *) ((void *)0) : the_history[history_offset]; Executed by:
| 11 | ||||||||||||||||||||||||
122 | ? (HIST_ENTRY *) executed 11 times by 1 test: return ((history_offset == history_length) || the_history == 0) ? (HIST_ENTRY *) ((void *)0) : the_history[history_offset]; Executed by:
| 11 | ||||||||||||||||||||||||
123 | ((void *)0) executed 11 times by 1 test: return ((history_offset == history_length) || the_history == 0) ? (HIST_ENTRY *) ((void *)0) : the_history[history_offset]; Executed by:
| 11 | ||||||||||||||||||||||||
124 | executed 11 times by 1 test: return ((history_offset == history_length) || the_history == 0) ? (HIST_ENTRY *) ((void *)0) : the_history[history_offset]; Executed by:
| 11 | ||||||||||||||||||||||||
125 | : the_history[history_offset]; executed 11 times by 1 test: return ((history_offset == history_length) || the_history == 0) ? (HIST_ENTRY *) ((void *)0) : the_history[history_offset]; Executed by:
| 11 | ||||||||||||||||||||||||
126 | } | - | ||||||||||||||||||||||||
127 | - | |||||||||||||||||||||||||
128 | - | |||||||||||||||||||||||||
129 | - | |||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||
131 | HIST_ENTRY * | - | ||||||||||||||||||||||||
132 | previous_history (void) | - | ||||||||||||||||||||||||
133 | { | - | ||||||||||||||||||||||||
134 | return executed 295 times by 1 test: history_offset ? the_history[--history_offset] : (HIST_ENTRY *)return history_offset ? the_history[--history_offset] : (HIST_ENTRY *) ((void *)0) ; Executed by:
executed 295 times by 1 test: return history_offset ? the_history[--history_offset] : (HIST_ENTRY *) ((void *)0) ; Executed by:
| 295 | ||||||||||||||||||||||||
135 | ((void *)0) executed 295 times by 1 test: return history_offset ? the_history[--history_offset] : (HIST_ENTRY *) ((void *)0) ; Executed by:
| 295 | ||||||||||||||||||||||||
136 | ; executed 295 times by 1 test: return history_offset ? the_history[--history_offset] : (HIST_ENTRY *) ((void *)0) ; Executed by:
| 295 | ||||||||||||||||||||||||
137 | } | - | ||||||||||||||||||||||||
138 | - | |||||||||||||||||||||||||
139 | - | |||||||||||||||||||||||||
140 | - | |||||||||||||||||||||||||
141 | - | |||||||||||||||||||||||||
142 | HIST_ENTRY * | - | ||||||||||||||||||||||||
143 | next_history (void) | - | ||||||||||||||||||||||||
144 | { | - | ||||||||||||||||||||||||
145 | return never executed: (history_offset == history_length) ? (HIST_ENTRY *)return (history_offset == history_length) ? (HIST_ENTRY *) ((void *)0) : the_history[++history_offset]; never executed: return (history_offset == history_length) ? (HIST_ENTRY *) ((void *)0) : the_history[++history_offset]; | 0 | ||||||||||||||||||||||||
146 | ((void *)0) never executed: return (history_offset == history_length) ? (HIST_ENTRY *) ((void *)0) : the_history[++history_offset]; | 0 | ||||||||||||||||||||||||
147 | : the_history[++history_offset]; never executed: return (history_offset == history_length) ? (HIST_ENTRY *) ((void *)0) : the_history[++history_offset]; | 0 | ||||||||||||||||||||||||
148 | } | - | ||||||||||||||||||||||||
149 | - | |||||||||||||||||||||||||
150 | - | |||||||||||||||||||||||||
151 | - | |||||||||||||||||||||||||
152 | HIST_ENTRY * | - | ||||||||||||||||||||||||
153 | history_get (int offset) | - | ||||||||||||||||||||||||
154 | { | - | ||||||||||||||||||||||||
155 | int local_index; | - | ||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||
157 | local_index = offset - history_base; | - | ||||||||||||||||||||||||
158 | return executed 126 times by 1 test: (local_index >= history_length || local_index < 0 || the_history == 0)return (local_index >= history_length || local_index < 0 || the_history == 0) ? (HIST_ENTRY *) ((void *)0) : the_history[local_index]; Executed by:
executed 126 times by 1 test: return (local_index >= history_length || local_index < 0 || the_history == 0) ? (HIST_ENTRY *) ((void *)0) : the_history[local_index]; Executed by:
| 126 | ||||||||||||||||||||||||
159 | ? (HIST_ENTRY *) executed 126 times by 1 test: return (local_index >= history_length || local_index < 0 || the_history == 0) ? (HIST_ENTRY *) ((void *)0) : the_history[local_index]; Executed by:
| 126 | ||||||||||||||||||||||||
160 | ((void *)0) executed 126 times by 1 test: return (local_index >= history_length || local_index < 0 || the_history == 0) ? (HIST_ENTRY *) ((void *)0) : the_history[local_index]; Executed by:
| 126 | ||||||||||||||||||||||||
161 | executed 126 times by 1 test: return (local_index >= history_length || local_index < 0 || the_history == 0) ? (HIST_ENTRY *) ((void *)0) : the_history[local_index]; Executed by:
| 126 | ||||||||||||||||||||||||
162 | : the_history[local_index]; executed 126 times by 1 test: return (local_index >= history_length || local_index < 0 || the_history == 0) ? (HIST_ENTRY *) ((void *)0) : the_history[local_index]; Executed by:
| 126 | ||||||||||||||||||||||||
163 | } | - | ||||||||||||||||||||||||
164 | - | |||||||||||||||||||||||||
165 | HIST_ENTRY * | - | ||||||||||||||||||||||||
166 | alloc_history_entry (char *string, char *ts) | - | ||||||||||||||||||||||||
167 | { | - | ||||||||||||||||||||||||
168 | HIST_ENTRY *temp; | - | ||||||||||||||||||||||||
169 | - | |||||||||||||||||||||||||
170 | temp = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY)); | - | ||||||||||||||||||||||||
171 | - | |||||||||||||||||||||||||
172 | temp->line = string
| 0-447 | ||||||||||||||||||||||||
173 | temp->data = (char *) | - | ||||||||||||||||||||||||
174 | ((void *)0) | - | ||||||||||||||||||||||||
175 | ; | - | ||||||||||||||||||||||||
176 | temp->timestamp = ts; | - | ||||||||||||||||||||||||
177 | - | |||||||||||||||||||||||||
178 | return executed 447 times by 1 test: temp;return temp; Executed by:
executed 447 times by 1 test: return temp; Executed by:
| 447 | ||||||||||||||||||||||||
179 | } | - | ||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||
181 | time_t | - | ||||||||||||||||||||||||
182 | history_get_time (HIST_ENTRY *hist) | - | ||||||||||||||||||||||||
183 | { | - | ||||||||||||||||||||||||
184 | char *ts; | - | ||||||||||||||||||||||||
185 | time_t t; | - | ||||||||||||||||||||||||
186 | - | |||||||||||||||||||||||||
187 | if (hist == 0
| 0 | ||||||||||||||||||||||||
188 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
189 | ts = hist->timestamp; | - | ||||||||||||||||||||||||
190 | if (ts[0] != history_comment_char
| 0 | ||||||||||||||||||||||||
191 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
192 | - | |||||||||||||||||||||||||
193 | (*__errno_location ()) | - | ||||||||||||||||||||||||
194 | = 0; | - | ||||||||||||||||||||||||
195 | t = (time_t) strtol (ts + 1, (char **) | - | ||||||||||||||||||||||||
196 | ((void *)0) | - | ||||||||||||||||||||||||
197 | , 10); | - | ||||||||||||||||||||||||
198 | if ( | - | ||||||||||||||||||||||||
199 | (*
| 0 | ||||||||||||||||||||||||
200 | ==
| 0 | ||||||||||||||||||||||||
201 | 34
| 0 | ||||||||||||||||||||||||
202 | ) | - | ||||||||||||||||||||||||
203 | return never executed: (time_t)0;return (time_t)0; never executed: return (time_t)0; | 0 | ||||||||||||||||||||||||
204 | return never executed: t;return t; never executed: return t; | 0 | ||||||||||||||||||||||||
205 | } | - | ||||||||||||||||||||||||
206 | - | |||||||||||||||||||||||||
207 | static char * | - | ||||||||||||||||||||||||
208 | hist_inittime (void) | - | ||||||||||||||||||||||||
209 | { | - | ||||||||||||||||||||||||
210 | time_t t; | - | ||||||||||||||||||||||||
211 | char ts[64], *ret; | - | ||||||||||||||||||||||||
212 | - | |||||||||||||||||||||||||
213 | t = (time_t) time ((time_t *)0); | - | ||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||
215 | snprintf (ts, sizeof (ts) - 1, "X%lu", (unsigned long) t); | - | ||||||||||||||||||||||||
216 | - | |||||||||||||||||||||||||
217 | - | |||||||||||||||||||||||||
218 | - | |||||||||||||||||||||||||
219 | ret = strcpy (xmalloc (1 + strlen (ts)), (ts)); | - | ||||||||||||||||||||||||
220 | ret[0] = history_comment_char; | - | ||||||||||||||||||||||||
221 | - | |||||||||||||||||||||||||
222 | return executed 447 times by 1 test: ret;return ret; Executed by:
executed 447 times by 1 test: return ret; Executed by:
| 447 | ||||||||||||||||||||||||
223 | } | - | ||||||||||||||||||||||||
224 | - | |||||||||||||||||||||||||
225 | - | |||||||||||||||||||||||||
226 | - | |||||||||||||||||||||||||
227 | void | - | ||||||||||||||||||||||||
228 | add_history (const char *string) | - | ||||||||||||||||||||||||
229 | { | - | ||||||||||||||||||||||||
230 | HIST_ENTRY *temp; | - | ||||||||||||||||||||||||
231 | int new_length; | - | ||||||||||||||||||||||||
232 | - | |||||||||||||||||||||||||
233 | if (history_stifled
| 9-426 | ||||||||||||||||||||||||
234 | { | - | ||||||||||||||||||||||||
235 | register int i; | - | ||||||||||||||||||||||||
236 | - | |||||||||||||||||||||||||
237 | - | |||||||||||||||||||||||||
238 | - | |||||||||||||||||||||||||
239 | if (history_length == 0
| 0-9 | ||||||||||||||||||||||||
240 | return; never executed: return; | 0 | ||||||||||||||||||||||||
241 | - | |||||||||||||||||||||||||
242 | - | |||||||||||||||||||||||||
243 | if (the_history[0]
| 0-9 | ||||||||||||||||||||||||
244 | ( executed 9 times by 1 test: void) free_history_entry (the_history[0]);(void) free_history_entry (the_history[0]); Executed by:
executed 9 times by 1 test: (void) free_history_entry (the_history[0]); Executed by:
| 9 | ||||||||||||||||||||||||
245 | - | |||||||||||||||||||||||||
246 | - | |||||||||||||||||||||||||
247 | - | |||||||||||||||||||||||||
248 | memmove (the_history, the_history + 1, history_length * sizeof (HIST_ENTRY *)); | - | ||||||||||||||||||||||||
249 | - | |||||||||||||||||||||||||
250 | new_length = history_length; | - | ||||||||||||||||||||||||
251 | history_base++; | - | ||||||||||||||||||||||||
252 | } executed 9 times by 1 test: end of block Executed by:
| 9 | ||||||||||||||||||||||||
253 | else | - | ||||||||||||||||||||||||
254 | { | - | ||||||||||||||||||||||||
255 | if (history_size == 0
| 33-405 | ||||||||||||||||||||||||
256 | { | - | ||||||||||||||||||||||||
257 | if (history_stifled
| 0-33 | ||||||||||||||||||||||||
258 | history_size = (
executed 33 times by 1 test: history_size = (history_max_entries > 8192) ? 8192 : history_max_entries + 2; Executed by:
| 0-33 | ||||||||||||||||||||||||
259 | ? 8192 executed 33 times by 1 test: history_size = (history_max_entries > 8192) ? 8192 : history_max_entries + 2; Executed by:
| 33 | ||||||||||||||||||||||||
260 | : history_max_entries + 2; executed 33 times by 1 test: history_size = (history_max_entries > 8192) ? 8192 : history_max_entries + 2; Executed by:
| 33 | ||||||||||||||||||||||||
261 | else | - | ||||||||||||||||||||||||
262 | history_size = 502; never executed: history_size = 502; | 0 | ||||||||||||||||||||||||
263 | the_history = (HIST_ENTRY **)xmalloc (history_size * sizeof (HIST_ENTRY *)); | - | ||||||||||||||||||||||||
264 | new_length = 1; | - | ||||||||||||||||||||||||
265 | } executed 33 times by 1 test: end of block Executed by:
| 33 | ||||||||||||||||||||||||
266 | else | - | ||||||||||||||||||||||||
267 | { | - | ||||||||||||||||||||||||
268 | if (history_length == (history_size - 1)
| 1-404 | ||||||||||||||||||||||||
269 | { | - | ||||||||||||||||||||||||
270 | history_size += 50; | - | ||||||||||||||||||||||||
271 | the_history = (HIST_ENTRY **) | - | ||||||||||||||||||||||||
272 | xrealloc (the_history, history_size * sizeof (HIST_ENTRY *)); | - | ||||||||||||||||||||||||
273 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||
274 | new_length = history_length + 1; | - | ||||||||||||||||||||||||
275 | } executed 405 times by 1 test: end of block Executed by:
| 405 | ||||||||||||||||||||||||
276 | } | - | ||||||||||||||||||||||||
277 | - | |||||||||||||||||||||||||
278 | temp = alloc_history_entry ((char *)string, hist_inittime ()); | - | ||||||||||||||||||||||||
279 | - | |||||||||||||||||||||||||
280 | the_history[new_length] = (HIST_ENTRY *) | - | ||||||||||||||||||||||||
281 | ((void *)0) | - | ||||||||||||||||||||||||
282 | ; | - | ||||||||||||||||||||||||
283 | the_history[new_length - 1] = temp; | - | ||||||||||||||||||||||||
284 | history_length = new_length; | - | ||||||||||||||||||||||||
285 | } executed 447 times by 1 test: end of block Executed by:
| 447 | ||||||||||||||||||||||||
286 | - | |||||||||||||||||||||||||
287 | - | |||||||||||||||||||||||||
288 | void | - | ||||||||||||||||||||||||
289 | add_history_time (const char *string) | - | ||||||||||||||||||||||||
290 | { | - | ||||||||||||||||||||||||
291 | HIST_ENTRY *hs; | - | ||||||||||||||||||||||||
292 | - | |||||||||||||||||||||||||
293 | if (string == 0
| 0 | ||||||||||||||||||||||||
294 | return; never executed: return; | 0 | ||||||||||||||||||||||||
295 | hs = the_history[history_length - 1]; | - | ||||||||||||||||||||||||
296 | if (hs->timestamp
never executed: free (hs->timestamp); | 0 | ||||||||||||||||||||||||
297 | hs->timestamp = strcpy (xmalloc (1 + strlen (string)), (string)); | - | ||||||||||||||||||||||||
298 | } never executed: end of block | 0 | ||||||||||||||||||||||||
299 | - | |||||||||||||||||||||||||
300 | - | |||||||||||||||||||||||||
301 | - | |||||||||||||||||||||||||
302 | histdata_t | - | ||||||||||||||||||||||||
303 | free_history_entry (HIST_ENTRY *hist) | - | ||||||||||||||||||||||||
304 | { | - | ||||||||||||||||||||||||
305 | histdata_t x; | - | ||||||||||||||||||||||||
306 | - | |||||||||||||||||||||||||
307 | if (hist == 0
| 0-64 | ||||||||||||||||||||||||
308 | return never executed: ((histdata_t) 0);return ((histdata_t) 0); never executed: return ((histdata_t) 0); | 0 | ||||||||||||||||||||||||
309 | if (hist->line
executed 64 times by 1 test: free (hist->line); Executed by:
| 0-64 | ||||||||||||||||||||||||
310 | if (hist->timestamp
executed 64 times by 1 test: free (hist->timestamp); Executed by:
| 0-64 | ||||||||||||||||||||||||
311 | x = hist->data; | - | ||||||||||||||||||||||||
312 | xfree (hist); | - | ||||||||||||||||||||||||
313 | return executed 64 times by 1 test: (x);return (x); Executed by:
executed 64 times by 1 test: return (x); Executed by:
| 64 | ||||||||||||||||||||||||
314 | } | - | ||||||||||||||||||||||||
315 | - | |||||||||||||||||||||||||
316 | HIST_ENTRY * | - | ||||||||||||||||||||||||
317 | copy_history_entry (HIST_ENTRY *hist) | - | ||||||||||||||||||||||||
318 | { | - | ||||||||||||||||||||||||
319 | HIST_ENTRY *ret; | - | ||||||||||||||||||||||||
320 | char *ts; | - | ||||||||||||||||||||||||
321 | - | |||||||||||||||||||||||||
322 | if (hist == 0
| 0 | ||||||||||||||||||||||||
323 | return never executed: hist;return hist; never executed: return hist; | 0 | ||||||||||||||||||||||||
324 | - | |||||||||||||||||||||||||
325 | ret = alloc_history_entry (hist->line, (char *) | - | ||||||||||||||||||||||||
326 | ((void *)0) | - | ||||||||||||||||||||||||
327 | ); | - | ||||||||||||||||||||||||
328 | - | |||||||||||||||||||||||||
329 | ts = hist->timestamp
| 0 | ||||||||||||||||||||||||
330 | ret->timestamp = ts; | - | ||||||||||||||||||||||||
331 | - | |||||||||||||||||||||||||
332 | ret->data = hist->data; | - | ||||||||||||||||||||||||
333 | - | |||||||||||||||||||||||||
334 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
335 | } | - | ||||||||||||||||||||||||
336 | - | |||||||||||||||||||||||||
337 | - | |||||||||||||||||||||||||
338 | - | |||||||||||||||||||||||||
339 | - | |||||||||||||||||||||||||
340 | HIST_ENTRY * | - | ||||||||||||||||||||||||
341 | replace_history_entry (int which, const char *line, histdata_t data) | - | ||||||||||||||||||||||||
342 | { | - | ||||||||||||||||||||||||
343 | HIST_ENTRY *temp, *old_value; | - | ||||||||||||||||||||||||
344 | - | |||||||||||||||||||||||||
345 | if (which < 0
| 0-9 | ||||||||||||||||||||||||
346 | return never executed: ((HIST_ENTRY *)return ((HIST_ENTRY *) ((void *)0) ); never executed: return ((HIST_ENTRY *) ((void *)0) ); | 0 | ||||||||||||||||||||||||
347 | ((void *)0) never executed: return ((HIST_ENTRY *) ((void *)0) ); | 0 | ||||||||||||||||||||||||
348 | ); never executed: return ((HIST_ENTRY *) ((void *)0) ); | 0 | ||||||||||||||||||||||||
349 | - | |||||||||||||||||||||||||
350 | temp = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY)); | - | ||||||||||||||||||||||||
351 | old_value = the_history[which]; | - | ||||||||||||||||||||||||
352 | - | |||||||||||||||||||||||||
353 | temp->line = strcpy (xmalloc (1 + strlen (line)), (line)); | - | ||||||||||||||||||||||||
354 | temp->data = data; | - | ||||||||||||||||||||||||
355 | temp->timestamp = strcpy (xmalloc (1 + strlen (old_value->timestamp)), (old_value->timestamp)); | - | ||||||||||||||||||||||||
356 | the_history[which] = temp; | - | ||||||||||||||||||||||||
357 | - | |||||||||||||||||||||||||
358 | return executed 9 times by 1 test: (old_value);return (old_value); Executed by:
executed 9 times by 1 test: return (old_value); Executed by:
| 9 | ||||||||||||||||||||||||
359 | } | - | ||||||||||||||||||||||||
360 | - | |||||||||||||||||||||||||
361 | - | |||||||||||||||||||||||||
362 | - | |||||||||||||||||||||||||
363 | - | |||||||||||||||||||||||||
364 | void | - | ||||||||||||||||||||||||
365 | _hs_append_history_line (int which, const char *line) | - | ||||||||||||||||||||||||
366 | { | - | ||||||||||||||||||||||||
367 | HIST_ENTRY *hent; | - | ||||||||||||||||||||||||
368 | size_t newlen, curlen, minlen; | - | ||||||||||||||||||||||||
369 | char *newline; | - | ||||||||||||||||||||||||
370 | - | |||||||||||||||||||||||||
371 | hent = the_history[which]; | - | ||||||||||||||||||||||||
372 | curlen = strlen (hent->line); | - | ||||||||||||||||||||||||
373 | minlen = curlen + strlen (line) + 2; | - | ||||||||||||||||||||||||
374 | if (curlen > 256
| 0 | ||||||||||||||||||||||||
375 | { | - | ||||||||||||||||||||||||
376 | newlen = 512; | - | ||||||||||||||||||||||||
377 | - | |||||||||||||||||||||||||
378 | while (newlen < minlen
| 0 | ||||||||||||||||||||||||
379 | newlen <<= 1; never executed: newlen <<= 1; | 0 | ||||||||||||||||||||||||
380 | } never executed: end of block | 0 | ||||||||||||||||||||||||
381 | else | - | ||||||||||||||||||||||||
382 | newlen = minlen; never executed: newlen = minlen; | 0 | ||||||||||||||||||||||||
383 | - | |||||||||||||||||||||||||
384 | - | |||||||||||||||||||||||||
385 | newline = realloc (hent->line, newlen); | - | ||||||||||||||||||||||||
386 | if (newline
| 0 | ||||||||||||||||||||||||
387 | { | - | ||||||||||||||||||||||||
388 | hent->line = newline; | - | ||||||||||||||||||||||||
389 | hent->line[curlen++] = '\n'; | - | ||||||||||||||||||||||||
390 | strcpy (hent->line + curlen, line); | - | ||||||||||||||||||||||||
391 | } never executed: end of block | 0 | ||||||||||||||||||||||||
392 | } never executed: end of block | 0 | ||||||||||||||||||||||||
393 | - | |||||||||||||||||||||||||
394 | - | |||||||||||||||||||||||||
395 | - | |||||||||||||||||||||||||
396 | - | |||||||||||||||||||||||||
397 | - | |||||||||||||||||||||||||
398 | - | |||||||||||||||||||||||||
399 | - | |||||||||||||||||||||||||
400 | void | - | ||||||||||||||||||||||||
401 | _hs_replace_history_data (int which, histdata_t *old, histdata_t *new) | - | ||||||||||||||||||||||||
402 | { | - | ||||||||||||||||||||||||
403 | HIST_ENTRY *entry; | - | ||||||||||||||||||||||||
404 | register int i, last; | - | ||||||||||||||||||||||||
405 | - | |||||||||||||||||||||||||
406 | if (which < -2
| 0 | ||||||||||||||||||||||||
407 | return; never executed: return; | 0 | ||||||||||||||||||||||||
408 | - | |||||||||||||||||||||||||
409 | if (which >= 0
| 0 | ||||||||||||||||||||||||
410 | { | - | ||||||||||||||||||||||||
411 | entry = the_history[which]; | - | ||||||||||||||||||||||||
412 | if (entry
| 0 | ||||||||||||||||||||||||
413 | entry->data = new; never executed: entry->data = new; | 0 | ||||||||||||||||||||||||
414 | return; never executed: return; | 0 | ||||||||||||||||||||||||
415 | } | - | ||||||||||||||||||||||||
416 | - | |||||||||||||||||||||||||
417 | last = -1; | - | ||||||||||||||||||||||||
418 | for (i = 0; i < history_length
| 0 | ||||||||||||||||||||||||
419 | { | - | ||||||||||||||||||||||||
420 | entry = the_history[i]; | - | ||||||||||||||||||||||||
421 | if (entry == 0
| 0 | ||||||||||||||||||||||||
422 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
423 | if (entry->data == old
| 0 | ||||||||||||||||||||||||
424 | { | - | ||||||||||||||||||||||||
425 | last = i; | - | ||||||||||||||||||||||||
426 | if (which == -1
| 0 | ||||||||||||||||||||||||
427 | entry->data = new; never executed: entry->data = new; | 0 | ||||||||||||||||||||||||
428 | } never executed: end of block | 0 | ||||||||||||||||||||||||
429 | } never executed: end of block | 0 | ||||||||||||||||||||||||
430 | if (which == -2
| 0 | ||||||||||||||||||||||||
431 | { | - | ||||||||||||||||||||||||
432 | entry = the_history[last]; | - | ||||||||||||||||||||||||
433 | entry->data = new; | - | ||||||||||||||||||||||||
434 | } never executed: end of block | 0 | ||||||||||||||||||||||||
435 | } never executed: end of block | 0 | ||||||||||||||||||||||||
436 | - | |||||||||||||||||||||||||
437 | - | |||||||||||||||||||||||||
438 | - | |||||||||||||||||||||||||
439 | - | |||||||||||||||||||||||||
440 | HIST_ENTRY * | - | ||||||||||||||||||||||||
441 | remove_history (int which) | - | ||||||||||||||||||||||||
442 | { | - | ||||||||||||||||||||||||
443 | HIST_ENTRY *return_value; | - | ||||||||||||||||||||||||
444 | register int i; | - | ||||||||||||||||||||||||
445 | - | |||||||||||||||||||||||||
446 | int nentries; | - | ||||||||||||||||||||||||
447 | HIST_ENTRY **start, **end; | - | ||||||||||||||||||||||||
448 | - | |||||||||||||||||||||||||
449 | - | |||||||||||||||||||||||||
450 | if (which < 0
| 0-3 | ||||||||||||||||||||||||
451 | return never executed: ((HIST_ENTRY *)return ((HIST_ENTRY *) ((void *)0) ); never executed: return ((HIST_ENTRY *) ((void *)0) ); | 0 | ||||||||||||||||||||||||
452 | ((void *)0) never executed: return ((HIST_ENTRY *) ((void *)0) ); | 0 | ||||||||||||||||||||||||
453 | ); never executed: return ((HIST_ENTRY *) ((void *)0) ); | 0 | ||||||||||||||||||||||||
454 | - | |||||||||||||||||||||||||
455 | return_value = the_history[which]; | - | ||||||||||||||||||||||||
456 | - | |||||||||||||||||||||||||
457 | - | |||||||||||||||||||||||||
458 | - | |||||||||||||||||||||||||
459 | - | |||||||||||||||||||||||||
460 | nentries = history_length - which; | - | ||||||||||||||||||||||||
461 | start = the_history + which; | - | ||||||||||||||||||||||||
462 | end = start + 1; | - | ||||||||||||||||||||||||
463 | memmove (start, end, nentries * sizeof (HIST_ENTRY *)); | - | ||||||||||||||||||||||||
464 | - | |||||||||||||||||||||||||
465 | - | |||||||||||||||||||||||||
466 | - | |||||||||||||||||||||||||
467 | - | |||||||||||||||||||||||||
468 | - | |||||||||||||||||||||||||
469 | history_length--; | - | ||||||||||||||||||||||||
470 | - | |||||||||||||||||||||||||
471 | return executed 3 times by 1 test: (return_value);return (return_value); Executed by:
executed 3 times by 1 test: return (return_value); Executed by:
| 3 | ||||||||||||||||||||||||
472 | } | - | ||||||||||||||||||||||||
473 | - | |||||||||||||||||||||||||
474 | HIST_ENTRY ** | - | ||||||||||||||||||||||||
475 | remove_history_range (int first, int last) | - | ||||||||||||||||||||||||
476 | { | - | ||||||||||||||||||||||||
477 | HIST_ENTRY **return_value; | - | ||||||||||||||||||||||||
478 | register int i; | - | ||||||||||||||||||||||||
479 | int nentries; | - | ||||||||||||||||||||||||
480 | HIST_ENTRY **start, **end; | - | ||||||||||||||||||||||||
481 | - | |||||||||||||||||||||||||
482 | if (the_history == 0
| 0-2 | ||||||||||||||||||||||||
483 | return never executed: ((HIST_ENTRY **)return ((HIST_ENTRY **) ((void *)0) ); never executed: return ((HIST_ENTRY **) ((void *)0) ); | 0 | ||||||||||||||||||||||||
484 | ((void *)0) never executed: return ((HIST_ENTRY **) ((void *)0) ); | 0 | ||||||||||||||||||||||||
485 | ); never executed: return ((HIST_ENTRY **) ((void *)0) ); | 0 | ||||||||||||||||||||||||
486 | if (first < 0
| 0-2 | ||||||||||||||||||||||||
487 | return never executed: ((HIST_ENTRY **)return ((HIST_ENTRY **) ((void *)0) ); never executed: return ((HIST_ENTRY **) ((void *)0) ); | 0 | ||||||||||||||||||||||||
488 | ((void *)0) never executed: return ((HIST_ENTRY **) ((void *)0) ); | 0 | ||||||||||||||||||||||||
489 | ); never executed: return ((HIST_ENTRY **) ((void *)0) ); | 0 | ||||||||||||||||||||||||
490 | if (first > last
| 0-2 | ||||||||||||||||||||||||
491 | return never executed: (HIST_ENTRY **)return (HIST_ENTRY **) ((void *)0) ; never executed: return (HIST_ENTRY **) ((void *)0) ; | 0 | ||||||||||||||||||||||||
492 | ((void *)0) never executed: return (HIST_ENTRY **) ((void *)0) ; | 0 | ||||||||||||||||||||||||
493 | ; never executed: return (HIST_ENTRY **) ((void *)0) ; | 0 | ||||||||||||||||||||||||
494 | - | |||||||||||||||||||||||||
495 | nentries = last - first + 1; | - | ||||||||||||||||||||||||
496 | return_value = (HIST_ENTRY **)malloc ((nentries + 1) * sizeof (HIST_ENTRY *)); | - | ||||||||||||||||||||||||
497 | if (return_value == 0
| 0-2 | ||||||||||||||||||||||||
498 | return never executed: return_value;return return_value; never executed: return return_value; | 0 | ||||||||||||||||||||||||
499 | - | |||||||||||||||||||||||||
500 | - | |||||||||||||||||||||||||
501 | for (i = first ; i <= last
| 2-8 | ||||||||||||||||||||||||
502 | return_value[i - first] = the_history[i]; executed 8 times by 1 test: return_value[i - first] = the_history[i]; Executed by:
| 8 | ||||||||||||||||||||||||
503 | return_value[i - first] = (HIST_ENTRY *) | - | ||||||||||||||||||||||||
504 | ((void *)0) | - | ||||||||||||||||||||||||
505 | ; | - | ||||||||||||||||||||||||
506 | - | |||||||||||||||||||||||||
507 | - | |||||||||||||||||||||||||
508 | - | |||||||||||||||||||||||||
509 | start = the_history + first; | - | ||||||||||||||||||||||||
510 | end = the_history + last + 1; | - | ||||||||||||||||||||||||
511 | memmove (start, end, (history_length - last) * sizeof (HIST_ENTRY *)); | - | ||||||||||||||||||||||||
512 | - | |||||||||||||||||||||||||
513 | history_length -= nentries; | - | ||||||||||||||||||||||||
514 | - | |||||||||||||||||||||||||
515 | return executed 2 times by 1 test: (return_value);return (return_value); Executed by:
executed 2 times by 1 test: return (return_value); Executed by:
| 2 | ||||||||||||||||||||||||
516 | } | - | ||||||||||||||||||||||||
517 | - | |||||||||||||||||||||||||
518 | - | |||||||||||||||||||||||||
519 | void | - | ||||||||||||||||||||||||
520 | stifle_history (int max) | - | ||||||||||||||||||||||||
521 | { | - | ||||||||||||||||||||||||
522 | register int i, j; | - | ||||||||||||||||||||||||
523 | - | |||||||||||||||||||||||||
524 | if (max < 0
| 0-39 | ||||||||||||||||||||||||
525 | max = 0; never executed: max = 0; | 0 | ||||||||||||||||||||||||
526 | - | |||||||||||||||||||||||||
527 | if (history_length > max
| 0-39 | ||||||||||||||||||||||||
528 | { | - | ||||||||||||||||||||||||
529 | - | |||||||||||||||||||||||||
530 | for (i = 0, j = history_length - max; i < j
| 0 | ||||||||||||||||||||||||
531 | free_history_entry (the_history[i]); never executed: free_history_entry (the_history[i]); | 0 | ||||||||||||||||||||||||
532 | - | |||||||||||||||||||||||||
533 | history_base = i; | - | ||||||||||||||||||||||||
534 | for (j = 0, i = history_length - max; j < max
| 0 | ||||||||||||||||||||||||
535 | the_history[j] = the_history[i]; never executed: the_history[j] = the_history[i]; | 0 | ||||||||||||||||||||||||
536 | the_history[j] = (HIST_ENTRY *) | - | ||||||||||||||||||||||||
537 | ((void *)0) | - | ||||||||||||||||||||||||
538 | ; | - | ||||||||||||||||||||||||
539 | history_length = j; | - | ||||||||||||||||||||||||
540 | } never executed: end of block | 0 | ||||||||||||||||||||||||
541 | - | |||||||||||||||||||||||||
542 | history_stifled = 1; | - | ||||||||||||||||||||||||
543 | max_input_history = history_max_entries = max; | - | ||||||||||||||||||||||||
544 | } executed 39 times by 1 test: end of block Executed by:
| 39 | ||||||||||||||||||||||||
545 | - | |||||||||||||||||||||||||
546 | - | |||||||||||||||||||||||||
547 | - | |||||||||||||||||||||||||
548 | - | |||||||||||||||||||||||||
549 | int | - | ||||||||||||||||||||||||
550 | unstifle_history (void) | - | ||||||||||||||||||||||||
551 | { | - | ||||||||||||||||||||||||
552 | if (history_stifled
| 1 | ||||||||||||||||||||||||
553 | { | - | ||||||||||||||||||||||||
554 | history_stifled = 0; | - | ||||||||||||||||||||||||
555 | return executed 1 time by 1 test: (history_max_entries);return (history_max_entries); Executed by:
executed 1 time by 1 test: return (history_max_entries); Executed by:
| 1 | ||||||||||||||||||||||||
556 | } | - | ||||||||||||||||||||||||
557 | else | - | ||||||||||||||||||||||||
558 | return executed 1 time by 1 test: (-history_max_entries);return (-history_max_entries); Executed by:
executed 1 time by 1 test: return (-history_max_entries); Executed by:
| 1 | ||||||||||||||||||||||||
559 | } | - | ||||||||||||||||||||||||
560 | - | |||||||||||||||||||||||||
561 | int | - | ||||||||||||||||||||||||
562 | history_is_stifled (void) | - | ||||||||||||||||||||||||
563 | { | - | ||||||||||||||||||||||||
564 | return never executed: (history_stifled);return (history_stifled); never executed: return (history_stifled); | 0 | ||||||||||||||||||||||||
565 | } | - | ||||||||||||||||||||||||
566 | - | |||||||||||||||||||||||||
567 | void | - | ||||||||||||||||||||||||
568 | clear_history (void) | - | ||||||||||||||||||||||||
569 | { | - | ||||||||||||||||||||||||
570 | register int i; | - | ||||||||||||||||||||||||
571 | - | |||||||||||||||||||||||||
572 | - | |||||||||||||||||||||||||
573 | for (i = 0; i < history_length
| 6-35 | ||||||||||||||||||||||||
574 | { | - | ||||||||||||||||||||||||
575 | free_history_entry (the_history[i]); | - | ||||||||||||||||||||||||
576 | the_history[i] = (HIST_ENTRY *) | - | ||||||||||||||||||||||||
577 | ((void *)0) | - | ||||||||||||||||||||||||
578 | ; | - | ||||||||||||||||||||||||
579 | } executed 35 times by 1 test: end of block Executed by:
| 35 | ||||||||||||||||||||||||
580 | - | |||||||||||||||||||||||||
581 | history_offset = history_length = 0; | - | ||||||||||||||||||||||||
582 | history_base = 1; | - | ||||||||||||||||||||||||
583 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||||||||
Switch to Source code | Preprocessed file |