Changeset 67b959c for messagelist.c


Ignore:
Timestamp:
Jun 25, 2011, 10:01:22 AM (13 years ago)
Author:
Jason Gross <jgross@mit.edu>
Children:
caac19d
Parents:
b2bfe1f
git-author:
Jason Gross <jgross@mit.edu> (05/23/11 19:06:48)
git-committer:
Jason Gross <jgross@mit.edu> (06/25/11 10:01:22)
Message:
Added a delete-and-expunge command.

This command is analogous to the delete command, except that it also
expunges only the {current,given} message.  It also takes an optional
--quiet parameter, because I plan to use it internally and don't want
spew on success.  Perhaps there's a better way to accomplish this...

I couldn't figure out how the existing delete command is supposed to
work internally.  The logic behind the delete-and-expunge command is as
follows:
We always update both the message list and the display.  So model the
command that will do much of the work,
owl_function_delete_and_expunge_message, off of owl_function_expunge.
owl_function_delete_and_expunge_message takes one argument, which is the
position of the item in the message list.  It deletes it from the
message list with a new function
owl_messagelist_delete_and_expunge_element.  This calls delete on the
underlying owl_list, so the errors (if any) on an index that is too big
might be unhelpful.

owl_function_delete_and_expunge_cur and
owl_function_delete_and_expunge_by_id both get the index of the relevant
message (and a function owl_messagelist_get_index_by_id is added to
messagelist.c to help the latter).  They owl_function_error if no such
message exists, and conditionally owl_function_makemsg on success.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • messagelist.c

    rfc8a87a r67b959c  
    2525}
    2626
    27 owl_message *owl_messagelist_get_by_id(const owl_messagelist *ml, int target_id)
     27int owl_messagelist_get_index_by_id(const owl_messagelist *ml, int target_id)
    2828{
    29   /* return the message with id == 'id'.  If it doesn't exist return NULL. */
     29  /* return the message index with id == 'id'.  If it doesn't exist return -1. */
    3030  int first, last, mid, msg_id;
    3131  owl_message *m;
     
    3838    msg_id = owl_message_get_id(m);
    3939    if (msg_id == target_id) {
    40       return(m);
     40      return mid;
    4141    } else if (msg_id < target_id) {
    4242      first = mid + 1;
     
    4545    }
    4646  }
    47   return(NULL);
     47  return -1;
     48}
     49
     50owl_message *owl_messagelist_get_by_id(const owl_messagelist *ml, int target_id)
     51{
     52  /* return the message with id == 'id'.  If it doesn't exist return NULL. */
     53  int n = owl_messagelist_get_index_by_id(ml, target_id);
     54  if (n < 0) return NULL;
     55  return ml->list->pdata[n];
    4856}
    4957
     
    6674  owl_message_unmark_delete(ml->list->pdata[n]);
    6775  return(0);
     76}
     77
     78void owl_messagelist_delete_and_expunge_element(owl_messagelist *ml, int n)
     79{
     80  owl_message_delete(g_ptr_array_remove_index(ml->list, n));
    6881}
    6982
Note: See TracChangeset for help on using the changeset viewer.