source: messagelist.c @ b470451

release-1.10release-1.8release-1.9
Last change on this file since b470451 was d427f08, checked in by Nelson Elhage <nelhage@mit.edu>, 13 years ago
Use G_GNUC_WARN_UNUSED_RESULT Have gcc warn us when we ignore the result of a function that requires the caller to free the result, or an initilization function that can fail. This might help (slightly) with preventing leaks and segfaults. Additionally changed some functions that should never fail to not return values. (The owl_list_* functions changed only fail if list->size < 0, which we assume is not the case elsewhere.)
  • Property mode set to 100644
File size: 2.3 KB
Line 
1#include "owl.h"
2#include <stdlib.h>
3#include <string.h>
4
5int owl_messagelist_create(owl_messagelist *ml)
6{
7  owl_list_create(&(ml->list));
8  return(0);
9}
10
11int owl_messagelist_get_size(const owl_messagelist *ml)
12{
13  return(owl_list_get_size(&(ml->list)));
14}
15
16void *owl_messagelist_get_element(const owl_messagelist *ml, int n)
17{
18  return(owl_list_get_element(&(ml->list), n));
19}
20
21owl_message *owl_messagelist_get_by_id(const owl_messagelist *ml, int target_id)
22{
23  /* return the message with id == 'id'.  If it doesn't exist return NULL. */
24  int first, last, mid, msg_id;
25  owl_message *m;
26
27  first = 0;
28  last = owl_list_get_size(&(ml->list)) - 1;
29  while (first <= last) {
30    mid = (first + last) / 2;
31    m = owl_list_get_element(&(ml->list), mid);
32    msg_id = owl_message_get_id(m);
33    if (msg_id == target_id) {
34      return(m);
35    } else if (msg_id < target_id) {
36      first = mid + 1;
37    } else {
38      last = mid - 1;
39    }
40  }
41  return(NULL);
42}
43
44void owl_messagelist_append_element(owl_messagelist *ml, void *element)
45{
46  owl_list_append_element(&ml->list, element);
47}
48
49/* do we really still want this? */
50int owl_messagelist_delete_element(owl_messagelist *ml, int n)
51{
52  /* mark a message as deleted */
53  owl_message_mark_delete(owl_list_get_element(&(ml->list), n));
54  return(0);
55}
56
57int owl_messagelist_undelete_element(owl_messagelist *ml, int n)
58{
59  /* mark a message as deleted */
60  owl_message_unmark_delete(owl_list_get_element(&(ml->list), n));
61  return(0);
62}
63
64int owl_messagelist_expunge(owl_messagelist *ml)
65{
66  /* expunge deleted messages */
67  int i, j;
68  owl_list newlist;
69  owl_message *m;
70
71  owl_list_create(&newlist);
72  /*create a new list without messages marked as deleted */
73  j=owl_list_get_size(&(ml->list));
74  for (i=0; i<j; i++) {
75    m=owl_list_get_element(&(ml->list), i);
76    if (owl_message_is_delete(m)) {
77      owl_message_delete(m);
78    } else {
79      owl_list_append_element(&newlist, m);
80    }
81  }
82
83  /* free the old list */
84  owl_list_cleanup(&(ml->list), NULL);
85
86  /* copy the new list to the old list */
87  ml->list = newlist;
88
89  return(0);
90}
91
92void owl_messagelist_invalidate_formats(const owl_messagelist *ml)
93{
94  int i, j;
95  owl_message *m;
96
97  j=owl_list_get_size(&(ml->list));
98  for (i=0; i<j; i++) {
99    m=owl_list_get_element(&(ml->list), i);
100    owl_message_invalidate_format(m);
101  }
102}
Note: See TracBrowser for help on using the repository browser.