Changeset 67b959c for commands.c


Ignore:
Timestamp:
Jun 25, 2011, 10:01:22 AM (11 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
  • commands.c

    re6d7e4e r67b959c  
    693693              "current view.\n"),
    694694  OWLCMD_ALIAS("del", "delete"),
     695
     696  OWLCMD_ARGS("delete-and-expunge", owl_command_delete_and_expunge, OWL_CTX_INTERACTIVE,
     697              "delete a message",
     698              "delete-and-expunge [-id msgid] [-q | --quiet]",
     699              "If no message id is specified the current message is deleted.\n"
     700              "Otherwise the message with the given message id is deleted.\n"
     701              "If --quiet is specified, then there is no message displayed on\n"
     702              "success.\n"),
     703  OWLCMD_ALIAS("delx", "delete-and-expunge"),
    695704
    696705  OWLCMD_ARGS("undelete", owl_command_undelete, OWL_CTX_INTERACTIVE,
     
    23312340}
    23322341
     2342char *owl_command_delete_and_expunge(int argc, const char *const *argv, const char *buff)
     2343{
     2344  bool exclaim_success = true;
     2345
     2346  if (argc > 1 && (!strcmp(argv[1], "-q") || !strcmp(argv[1], "--quiet"))) {
     2347    exclaim_success = false;
     2348    argc--;
     2349    argv++;
     2350  } else if (!strcmp(argv[argc - 1], "-q") || !strcmp(argv[argc - 1], "--quiet")) {
     2351    exclaim_success = false;
     2352    argc--;
     2353  }
     2354
     2355  if (argc == 1) {
     2356    owl_function_delete_and_expunge_cur(exclaim_success);
     2357    return NULL;
     2358  }
     2359
     2360  if (argc == 3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
     2361    owl_function_delete_and_expunge_by_id(atoi(argv[2]), exclaim_success);
     2362    return NULL;
     2363  }
     2364
     2365  owl_function_makemsg("Unknown arguments to delete-and-expunge command");
     2366  return NULL;
     2367}
     2368
    23332369char *owl_command_undelete(int argc, const char *const *argv, const char *buff)
    23342370{
Note: See TracChangeset for help on using the changeset viewer.