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>, 20 years ago
Fixed formatting in history.c
  • Property mode set to 100644
File size: 1.6 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? */
[7d4fbcd]11}
12
[70b53ec]13char *owl_history_get_prev(owl_history *h)
14{
[10b866d]15
16  if (!h) return NULL;
[7d4fbcd]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++;
[10b866d]26
[7d4fbcd]27  return(owl_list_get_element(&(h->hist), h->cur));
28}
29
[70b53ec]30char *owl_history_get_next(owl_history *h)
31{
[10b866d]32  if (!h) return NULL;
[7d4fbcd]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
[70b53ec]42void owl_history_store(owl_history *h, char *line)
43{
[7d4fbcd]44  int size;
45
[10b866d]46  if (!h) return;
47
[7d4fbcd]48  /* if partial is set, remove the first entry first */
49  if (h->partial) {
50    owl_list_remove_element(&(h->hist), 0);
51  }
[10b866d]52
[7d4fbcd]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
[70b53ec]64void owl_history_set_partial(owl_history *h)
65{
[10b866d]66  if (!h) return;
[7d4fbcd]67  h->partial=1;
68}
69
[70b53ec]70void owl_history_reset(owl_history *h)
71{
[10b866d]72  if (!h) return;
[7d4fbcd]73  h->cur=0;
74  h->touched=0;
75  h->partial=0;
76}
77
[70b53ec]78int owl_history_is_touched(owl_history *h)
79{
[10b866d]80  if (!h) return(0);
[7d4fbcd]81  if (h->touched) return(1);
82  return(0);
83}
Note: See TracBrowser for help on using the repository browser.