Deleted Added
full compact
history.c (157184) history.c (165670)
1/* history.c -- standalone history library */
2
3/* Copyright (C) 1989-2005 Free Software Foundation, Inc.
4
5 This file contains the GNU History Library (the Library), a set of
6 routines for managing the text of previously typed lines.
7
8 The Library is free software; you can redistribute it and/or modify

--- 195 unchanged lines hidden (view full) ---

204 int local_index;
205
206 local_index = offset - history_base;
207 return (local_index >= history_length || local_index < 0 || the_history == 0)
208 ? (HIST_ENTRY *)NULL
209 : the_history[local_index];
210}
211
1/* history.c -- standalone history library */
2
3/* Copyright (C) 1989-2005 Free Software Foundation, Inc.
4
5 This file contains the GNU History Library (the Library), a set of
6 routines for managing the text of previously typed lines.
7
8 The Library is free software; you can redistribute it and/or modify

--- 195 unchanged lines hidden (view full) ---

204 int local_index;
205
206 local_index = offset - history_base;
207 return (local_index >= history_length || local_index < 0 || the_history == 0)
208 ? (HIST_ENTRY *)NULL
209 : the_history[local_index];
210}
211
212HIST_ENTRY *
213alloc_history_entry (string, ts)
214 char *string;
215 char *ts;
216{
217 HIST_ENTRY *temp;
218
219 temp = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY));
220
221 temp->line = string ? savestring (string) : string;
222 temp->data = (char *)NULL;
223 temp->timestamp = ts;
224
225 return temp;
226}
227
212time_t
213history_get_time (hist)
214 HIST_ENTRY *hist;
215{
216 char *ts;
217 time_t t;
218
219 if (hist == 0 || hist->timestamp == 0)

--- 65 unchanged lines hidden (view full) ---

285 history_size += DEFAULT_HISTORY_GROW_SIZE;
286 the_history = (HIST_ENTRY **)
287 xrealloc (the_history, history_size * sizeof (HIST_ENTRY *));
288 }
289 history_length++;
290 }
291 }
292
228time_t
229history_get_time (hist)
230 HIST_ENTRY *hist;
231{
232 char *ts;
233 time_t t;
234
235 if (hist == 0 || hist->timestamp == 0)

--- 65 unchanged lines hidden (view full) ---

301 history_size += DEFAULT_HISTORY_GROW_SIZE;
302 the_history = (HIST_ENTRY **)
303 xrealloc (the_history, history_size * sizeof (HIST_ENTRY *));
304 }
305 history_length++;
306 }
307 }
308
293 temp = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY));
294 temp->line = savestring (string);
295 temp->data = (char *)NULL;
309 temp = alloc_history_entry (string, hist_inittime ());
296
310
297 temp->timestamp = hist_inittime ();
298
299 the_history[history_length] = (HIST_ENTRY *)NULL;
300 the_history[history_length - 1] = temp;
301}
302
303/* Change the time stamp of the most recent history entry to STRING. */
304void
305add_history_time (string)
306 const char *string;

--- 16 unchanged lines hidden (view full) ---

323 if (hist == 0)
324 return ((histdata_t) 0);
325 FREE (hist->line);
326 FREE (hist->timestamp);
327 x = hist->data;
328 free (hist);
329 return (x);
330}
311 the_history[history_length] = (HIST_ENTRY *)NULL;
312 the_history[history_length - 1] = temp;
313}
314
315/* Change the time stamp of the most recent history entry to STRING. */
316void
317add_history_time (string)
318 const char *string;

--- 16 unchanged lines hidden (view full) ---

335 if (hist == 0)
336 return ((histdata_t) 0);
337 FREE (hist->line);
338 FREE (hist->timestamp);
339 x = hist->data;
340 free (hist);
341 return (x);
342}
343
344HIST_ENTRY *
345copy_history_entry (hist)
346 HIST_ENTRY *hist;
347{
348 HIST_ENTRY *ret;
349 char *ts;
350
351 if (hist == 0)
352 return hist;
353
354 ret = alloc_history_entry (hist->line, (char *)NULL);
355
356 ts = hist->timestamp ? savestring (hist->timestamp) : hist->timestamp;
357 ret->timestamp = ts;
358
359 ret->data = hist->data;
360
361 return ret;
362}
331
332/* Make the history entry at WHICH have LINE and DATA. This returns
333 the old entry so you can dispose of the data. In the case of an
334 invalid WHICH, a NULL pointer is returned. */
335HIST_ENTRY *
336replace_history_entry (which, line, data)
337 int which;
338 const char *line;

--- 10 unchanged lines hidden (view full) ---

349 temp->line = savestring (line);
350 temp->data = data;
351 temp->timestamp = savestring (old_value->timestamp);
352 the_history[which] = temp;
353
354 return (old_value);
355}
356
363
364/* Make the history entry at WHICH have LINE and DATA. This returns
365 the old entry so you can dispose of the data. In the case of an
366 invalid WHICH, a NULL pointer is returned. */
367HIST_ENTRY *
368replace_history_entry (which, line, data)
369 int which;
370 const char *line;

--- 10 unchanged lines hidden (view full) ---

381 temp->line = savestring (line);
382 temp->data = data;
383 temp->timestamp = savestring (old_value->timestamp);
384 the_history[which] = temp;
385
386 return (old_value);
387}
388
389/* Replace the DATA in the specified history entries, replacing OLD with
390 NEW. WHICH says which one(s) to replace: WHICH == -1 means to replace
391 all of the history entries where entry->data == OLD; WHICH == -2 means
392 to replace the `newest' history entry where entry->data == OLD; and
393 WHICH >= 0 means to replace that particular history entry's data, as
394 long as it matches OLD. */
395void
396replace_history_data (which,old, new)
397 int which;
398 histdata_t *old, *new;
399{
400 HIST_ENTRY *entry;
401 register int i, last;
402
403 if (which < -2 || which >= history_length || history_length == 0 || the_history == 0)
404 return;
405
406 if (which >= 0)
407 {
408 entry = the_history[which];
409 if (entry && entry->data == old)
410 entry->data = new;
411 return;
412 }
413
414 last = -1;
415 for (i = 0; i < history_length; i++)
416 {
417 entry = the_history[i];
418 if (entry == 0)
419 continue;
420 if (entry->data == old)
421 {
422 last = i;
423 if (which == -1)
424 entry->data = new;
425 }
426 }
427 if (which == -2 && last >= 0)
428 {
429 entry = the_history[last];
430 entry->data = new; /* XXX - we don't check entry->old */
431 }
432}
433
357/* Remove history element WHICH from the history. The removed
358 element is returned to you so you can free the line, data,
359 and containing structure. */
360HIST_ENTRY *
361remove_history (which)
362 int which;
363{
364 HIST_ENTRY *return_value;

--- 77 unchanged lines hidden ---
434/* Remove history element WHICH from the history. The removed
435 element is returned to you so you can free the line, data,
436 and containing structure. */
437HIST_ENTRY *
438remove_history (which)
439 int which;
440{
441 HIST_ENTRY *return_value;

--- 77 unchanged lines hidden ---