source: messagelist.c @ ad37b39

release-1.10release-1.8release-1.9
Last change on this file since ad37b39 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
RevLine 
[7d4fbcd]1#include "owl.h"
2#include <stdlib.h>
3#include <string.h>
4
[bd3f232]5int owl_messagelist_create(owl_messagelist *ml)
6{
[7d4fbcd]7  owl_list_create(&(ml->list));
8  return(0);
9}
10
[3eb599d]11int owl_messagelist_get_size(const owl_messagelist *ml)
[bd3f232]12{
[7d4fbcd]13  return(owl_list_get_size(&(ml->list)));
14}
15
[3eb599d]16void *owl_messagelist_get_element(const owl_messagelist *ml, int n)
[bd3f232]17{
[7d4fbcd]18  return(owl_list_get_element(&(ml->list), n));
19}
20
[3eb599d]21owl_message *owl_messagelist_get_by_id(const owl_messagelist *ml, int target_id)
[bd3f232]22{
[7d4fbcd]23  /* return the message with id == 'id'.  If it doesn't exist return NULL. */
[0c8ab5e]24  int first, last, mid, msg_id;
[7d4fbcd]25  owl_message *m;
26
[0c8ab5e]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    }
[7d4fbcd]40  }
41  return(NULL);
42}
43
[d427f08]44void owl_messagelist_append_element(owl_messagelist *ml, void *element)
[bd3f232]45{
[d427f08]46  owl_list_append_element(&ml->list, element);
[7d4fbcd]47}
48
49/* do we really still want this? */
[bd3f232]50int owl_messagelist_delete_element(owl_messagelist *ml, int n)
51{
[7d4fbcd]52  /* mark a message as deleted */
53  owl_message_mark_delete(owl_list_get_element(&(ml->list), n));
54  return(0);
55}
56
[bd3f232]57int owl_messagelist_undelete_element(owl_messagelist *ml, int n)
58{
[7d4fbcd]59  /* mark a message as deleted */
60  owl_message_unmark_delete(owl_list_get_element(&(ml->list), n));
61  return(0);
62}
63
[bd3f232]64int owl_messagelist_expunge(owl_messagelist *ml)
65{
[7d4fbcd]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)) {
[91634ec]77      owl_message_delete(m);
[7d4fbcd]78    } else {
79      owl_list_append_element(&newlist, m);
80    }
81  }
82
83  /* free the old list */
[5e5f08f]84  owl_list_cleanup(&(ml->list), NULL);
[7d4fbcd]85
86  /* copy the new list to the old list */
[66a8cd6]87  ml->list = newlist;
[7d4fbcd]88
89  return(0);
90}
[bd3f232]91
[3eb599d]92void owl_messagelist_invalidate_formats(const owl_messagelist *ml)
[bd3f232]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.