source: history.c @ 3c7d007a

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 3c7d007a was 3c7d007a, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Really revert history dup feature
  • Property mode set to 100644
File size: 2.0 KB
Line 
1#include "owl.h"
2
3static const char fileIdent[] = "$Id$";
4
5void owl_history_init(owl_history *h)
6{
7  owl_list_create(&(h->hist));
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? */
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;
17}
18
19char *owl_history_get_prev(owl_history *h)
20{
21
22  if (!h) return NULL;
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++;
32
33  return(owl_list_get_element(&(h->hist), h->cur));
34}
35
36char *owl_history_get_next(owl_history *h)
37{
38  if (!h) return NULL;
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
48void owl_history_store(owl_history *h, char *line)
49{
50  int i, size;
51
52  if (!h) return;
53  size=owl_list_get_size(&(h->hist));
54
55  /* if repeats are disallowed, check if the line is present already */
56  if (!h->repeats) {
57    for (i=0; i<size; i++) {
58      if (!strcmp(line, owl_list_get_element(&(h->hist), i))) return;
59    }
60  }
61
62  /* if partial is set, remove the first entry first */
63  if (h->partial) {
64    owl_list_remove_element(&(h->hist), 0);
65  }
66
67  /* if we've reached the max history size, pop off the last element */
68  if (size>OWL_HISTORYSIZE) {
69    owl_free(owl_list_get_element(&(h->hist), size-1));
70    owl_list_remove_element(&(h->hist), size-1);
71  }
72
73  /* add the new line */
74  owl_list_prepend_element(&(h->hist), owl_strdup(line));
75}
76
77void owl_history_set_partial(owl_history *h)
78{
79  if (!h) return;
80  h->partial=1;
81}
82
83void owl_history_reset(owl_history *h)
84{
85  if (!h) return;
86  h->cur=0;
87  h->touched=0;
88  h->partial=0;
89}
90
91int owl_history_is_touched(owl_history *h)
92{
93  if (!h) return(0);
94  if (h->touched) return(1);
95  return(0);
96}
Note: See TracBrowser for help on using the repository browser.