source: history.c @ 0337203

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 0337203 was 52f3507, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Changed startup message to reflect new mailing list.
  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[7d4fbcd]1#include "owl.h"
2
[1aee7d9]3static const char fileIdent[] = "$Id$";
4
[70b53ec]5void owl_history_init(owl_history *h)
6{
[7d4fbcd]7  owl_list_create(&(h->hist));
[10b866d]8  h->cur=0;                     /* current position in history */
9  h->touched=0;                 /* whether we've gone into history */
10  h->partial=0;                 /* is the 0th element is partially composed? */
[12c35df]11  h->repeats=1;                 /* by default we'll allow repeat entries */
12}
13
14void owl_history_set_norepeats(owl_history *h)
15{
16  h->repeats=0;
[7d4fbcd]17}
18
[70b53ec]19char *owl_history_get_prev(owl_history *h)
20{
[10b866d]21
22  if (!h) return NULL;
[7d4fbcd]23  h->touched=1;
24
25  if (owl_list_get_size(&(h->hist))==0) return(NULL);
26
27  if (h->cur == owl_list_get_size(&(h->hist))-1) {
28    return(NULL);
29  }
30
31  h->cur++;
[10b866d]32
[7d4fbcd]33  return(owl_list_get_element(&(h->hist), h->cur));
34}
35
[70b53ec]36char *owl_history_get_next(owl_history *h)
37{
[10b866d]38  if (!h) return NULL;
[7d4fbcd]39  if (owl_list_get_size(&(h->hist))==0) return(NULL);
40  if (h->cur==0) {
41    return(NULL);
42  }
43
44  h->cur--;
45  return(owl_list_get_element(&(h->hist), h->cur));
46}
47
[70b53ec]48void owl_history_store(owl_history *h, char *line)
49{
[52f3507]50  int size;
[7d4fbcd]51
[10b866d]52  if (!h) return;
[12c35df]53  size=owl_list_get_size(&(h->hist));
54
[7d4fbcd]55  /* if partial is set, remove the first entry first */
56  if (h->partial) {
57    owl_list_remove_element(&(h->hist), 0);
58  }
[10b866d]59
[5a9f6fe]60  /* if repeats are disallowed, check if the line is the same as the last */
61  if (owl_list_get_size(&(h->hist))>0) {
62    if (!strcmp(line, owl_list_get_element(&(h->hist), 0))) return;
63  }
64
[7d4fbcd]65  /* if we've reached the max history size, pop off the last element */
66  if (size>OWL_HISTORYSIZE) {
67    owl_free(owl_list_get_element(&(h->hist), size-1));
68    owl_list_remove_element(&(h->hist), size-1);
69  }
70
71  /* add the new line */
72  owl_list_prepend_element(&(h->hist), owl_strdup(line));
73}
74
[70b53ec]75void owl_history_set_partial(owl_history *h)
76{
[10b866d]77  if (!h) return;
[7d4fbcd]78  h->partial=1;
79}
80
[70b53ec]81void owl_history_reset(owl_history *h)
82{
[10b866d]83  if (!h) return;
[7d4fbcd]84  h->cur=0;
85  h->touched=0;
86  h->partial=0;
87}
88
[70b53ec]89int owl_history_is_touched(owl_history *h)
90{
[10b866d]91  if (!h) return(0);
[7d4fbcd]92  if (h->touched) return(1);
93  return(0);
94}
Note: See TracBrowser for help on using the repository browser.