source: history.c @ 12c35df

barnowl_perlaimdebianowlrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 12c35df was 12c35df, checked in by James M. Kretchmar <kretch@mit.edu>, 17 years ago
Fixed replies to loopback messages Fixed smartnarrow on classes/instances with spaces Don't allow duplicates in command history Added the 'loggingdirection' variable All loopback messages log to 'loopback' now Print an error message if trying an invalid color for a filter Fixed bug causing > not to go to end of editwin every time
  • Property mode set to 100644
File size: 1.9 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  for (i=0; i<size; i++) {
57    if (!strcmp(line, owl_list_get_element(&(h->hist), i))) return;
58  }
59
60  /* if partial is set, remove the first entry first */
61  if (h->partial) {
62    owl_list_remove_element(&(h->hist), 0);
63  }
64
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
75void owl_history_set_partial(owl_history *h)
76{
77  if (!h) return;
78  h->partial=1;
79}
80
81void owl_history_reset(owl_history *h)
82{
83  if (!h) return;
84  h->cur=0;
85  h->touched=0;
86  h->partial=0;
87}
88
89int owl_history_is_touched(owl_history *h)
90{
91  if (!h) return(0);
92  if (h->touched) return(1);
93  return(0);
94}
Note: See TracBrowser for help on using the repository browser.