source: history.c @ faf71b5

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since faf71b5 was 70b53ec, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Fixed formatting in history.c
  • Property mode set to 100644
File size: 1.6 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}
12
13char *owl_history_get_prev(owl_history *h)
14{
15
16  if (!h) return NULL;
17  h->touched=1;
18
19  if (owl_list_get_size(&(h->hist))==0) return(NULL);
20
21  if (h->cur == owl_list_get_size(&(h->hist))-1) {
22    return(NULL);
23  }
24
25  h->cur++;
26
27  return(owl_list_get_element(&(h->hist), h->cur));
28}
29
30char *owl_history_get_next(owl_history *h)
31{
32  if (!h) return NULL;
33  if (owl_list_get_size(&(h->hist))==0) return(NULL);
34  if (h->cur==0) {
35    return(NULL);
36  }
37
38  h->cur--;
39  return(owl_list_get_element(&(h->hist), h->cur));
40}
41
42void owl_history_store(owl_history *h, char *line)
43{
44  int size;
45
46  if (!h) return;
47
48  /* if partial is set, remove the first entry first */
49  if (h->partial) {
50    owl_list_remove_element(&(h->hist), 0);
51  }
52
53  /* if we've reached the max history size, pop off the last element */
54  size=owl_list_get_size(&(h->hist));
55  if (size>OWL_HISTORYSIZE) {
56    owl_free(owl_list_get_element(&(h->hist), size-1));
57    owl_list_remove_element(&(h->hist), size-1);
58  }
59
60  /* add the new line */
61  owl_list_prepend_element(&(h->hist), owl_strdup(line));
62}
63
64void owl_history_set_partial(owl_history *h)
65{
66  if (!h) return;
67  h->partial=1;
68}
69
70void owl_history_reset(owl_history *h)
71{
72  if (!h) return;
73  h->cur=0;
74  h->touched=0;
75  h->partial=0;
76}
77
78int owl_history_is_touched(owl_history *h)
79{
80  if (!h) return(0);
81  if (h->touched) return(1);
82  return(0);
83}
Note: See TracBrowser for help on using the repository browser.