source: history.c @ 7d4fbcd

barnowl_perlaimdebianowlrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 7d4fbcd was 7d4fbcd, checked in by James M. Kretchmar <kretch@mit.edu>, 18 years ago
Initial check in
  • Property mode set to 100644
File size: 1.3 KB
Line 
1#include "owl.h"
2
3void owl_history_init(owl_history *h) {
4  owl_list_create(&(h->hist));
5  h->cur=0;
6  h->touched=0;
7  h->partial=0;
8}
9
10char *owl_history_get_prev(owl_history *h) {
11  h->touched=1;
12
13  if (owl_list_get_size(&(h->hist))==0) return(NULL);
14
15  if (h->cur == owl_list_get_size(&(h->hist))-1) {
16    return(NULL);
17  }
18
19  h->cur++;
20  return(owl_list_get_element(&(h->hist), h->cur));
21}
22
23char *owl_history_get_next(owl_history *h) {
24  if (owl_list_get_size(&(h->hist))==0) return(NULL);
25
26  if (h->cur==0) {
27    return(NULL);
28  }
29
30  h->cur--;
31  return(owl_list_get_element(&(h->hist), h->cur));
32}
33
34void owl_history_store(owl_history *h, char *line) {
35  int size;
36
37  /* if partial is set, remove the first entry first */
38  if (h->partial) {
39    owl_list_remove_element(&(h->hist), 0);
40  }
41   
42  /* if we've reached the max history size, pop off the last element */
43  size=owl_list_get_size(&(h->hist));
44  if (size>OWL_HISTORYSIZE) {
45    owl_free(owl_list_get_element(&(h->hist), size-1));
46    owl_list_remove_element(&(h->hist), size-1);
47  }
48
49  /* add the new line */
50  owl_list_prepend_element(&(h->hist), owl_strdup(line));
51}
52
53void owl_history_set_partial(owl_history *h) {
54  h->partial=1;
55}
56
57void owl_history_reset(owl_history *h) {
58  h->cur=0;
59  h->touched=0;
60  h->partial=0;
61}
62
63int owl_history_is_touched(owl_history *h) {
64  if (h->touched) return(1);
65  return(0);
66}
Note: See TracBrowser for help on using the repository browser.