home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / src / a_quit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-11  |  5.5 KB  |  187 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: a_quit.c,v 5.4 1993/04/12 02:34:36 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.4 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1988-1992 USENET Community Trust
  8.  *             Copyright (c) 1986,1987 Dave Taylor
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log: a_quit.c,v $
  17.  * Revision 5.4  1993/04/12  02:34:36  syd
  18.  * I have now added a parameter which controls whether want_to clears the
  19.  * line and centers the question or behaves like it did before. I also
  20.  * added a 0 at the end of the parameter list to all the other calls to
  21.  * want_to where a centered question on a clean line is not desirable.
  22.  * From: Jukka Ukkonen <ukkonen@csc.fi>
  23.  *
  24.  * Revision 5.3  1992/12/24  21:42:01  syd
  25.  * Fix messages and nls messages to match.  Plus use want_to
  26.  * where appropriate.
  27.  * From: Syd, via prompting from Jan Djarv <Jan.Djarv@sa.erisoft.se>
  28.  *
  29.  * Revision 5.2  1992/12/11  02:09:06  syd
  30.  * Fix where the user creates a first new alias, then deletes it, the
  31.  * alias stays on screen, but the file really will be empty if it was the
  32.  * last alias, so the retry to delete gives 'cannot open ...file' messages
  33.  * From: "Robert L. Howard" <robert.howard@matd.gatech.edu>
  34.  *
  35.  * Revision 5.1  1992/10/03  22:58:40  syd
  36.  * Initial checkin as of 2.4 Release at PL0
  37.  *
  38.  *
  39.  ******************************************************************************/
  40.  
  41. /** a_quit: leave the aliases menu and return to the main menu.
  42.   
  43. **/
  44.  
  45. #include "headers.h"
  46. #include "s_aliases.h"
  47. #include <errno.h>
  48.  
  49.  
  50. extern int errno;        /* system error number on failure */
  51.  
  52. int
  53. delete_aliases(newaliases, prompt)
  54. int newaliases, prompt;
  55. {
  56. /*
  57.  *    Update aliases by processing deletions.  Prompting is
  58.  *    done as directed by user input and elmrc options.
  59.  *
  60.  *    If "prompt" is false, then no prompting is done.
  61.  *    Otherwise prompting is dependent upon the variable
  62.  *    question_me, as set by an elmrc option.  This behavior
  63.  *    makes the 'q' command prompt just like '$', while
  64.  *    retaining the 'Q' command for a quick exit that never
  65.  *    prompts.
  66.  *
  67.  *    Return    1        Aliases were deleted
  68.  *         newalias    Aliases were not deleted
  69.  *
  70.  *    The return allows the caller to determine if the "newalias"
  71.  *    routine should be run.
  72.  */
  73.  
  74.     char buffer[SLEN];
  75.     char **list;
  76.  
  77.     register int to_delete = 0, to_keep = 0, i,
  78.              marked_deleted = 0,
  79.              ask_questions;
  80.     char answer;
  81.  
  82.     dprint(1, (debugfile, "\n\n-- leaving aliases --\n\n"));
  83.  
  84.     if (message_count == 0)
  85.       return(newaliases);    /* nothing changed */
  86.  
  87.     ask_questions = ((!prompt) ? FALSE : question_me);
  88.  
  89.     /* YES or NO on softkeys */
  90.     if (hp_softkeys && ask_questions) {
  91.       define_softkeys(YESNO);
  92.       softkeys_on();
  93.     }
  94.  
  95.     /* Determine if deleted messages are really to be deleted */
  96.  
  97.     /* we need to know how many there are to delete */
  98.     for (i=0; i<message_count; i++)
  99.       if (ison(aliases[i]->status, DELETED))
  100.         marked_deleted++;
  101.  
  102.     dprint(6, (debugfile, "Number of aliases marked deleted = %d\n",
  103.                 marked_deleted));
  104.  
  105.         if(marked_deleted) {
  106.       answer = (always_del ? *def_ans_yes : *def_ans_no);    /* default answer */
  107.       if(ask_questions) {
  108.         if (marked_deleted == 1)
  109.           MCsprintf(buffer, catgets(elm_msg_cat, AliasesSet, AliasesDelete,
  110.             "Delete 1 alias? (%c/%c) "), *def_ans_yes, *def_ans_no);
  111.         else
  112.           MCsprintf(buffer, catgets(elm_msg_cat, AliasesSet, AliasesDeletePlural,
  113.             "Delete %d aliases? (%c/%c) "),
  114.             marked_deleted, *def_ans_yes, *def_ans_no);
  115.                         
  116.         answer = want_to(buffer, answer, LINES-3, 0);
  117.       }
  118.  
  119.       if(answer == *def_ans_yes) {
  120.         list = (char **) malloc(marked_deleted*sizeof(*list));
  121.         for (i = 0; i < message_count; i++) {
  122.           if (ison(aliases[i]->status, DELETED)) {
  123.         list[to_delete] = aliases[i]->alias;
  124.             dprint(8,(debugfile, "Alias number %d, %s is deletion %d\n",
  125.                    i, list[to_delete], to_delete));
  126.             to_delete++;
  127.           }
  128.           else {
  129.             to_keep++;
  130.           }
  131.         }
  132.        /*
  133.         * Formulate message as to number of keeps and deletes.
  134.         * This is only complex so that the message is good English.
  135.         */
  136.         if (to_keep > 0) {
  137.           current = 1;        /* Reset current alias */
  138.           if (to_keep == 1)
  139.         sprintf(buffer, catgets(elm_msg_cat, AliasesSet, AliasesKeepDelete,
  140.               "[Keeping 1 alias and deleting %d.]"), to_delete);
  141.           else
  142.         MCsprintf(buffer, catgets(elm_msg_cat, AliasesSet, AliasesKeepDeletePlural,
  143.               "[Keeping %d aliases and deleting %d.]"), to_keep, to_delete);
  144.         }
  145.         else {
  146.           current = 0;        /* No aliases left */
  147.           sprintf(buffer, catgets(elm_msg_cat, AliasesSet, AliasesDeleteAll,
  148.               "[Deleting all aliases.]"));
  149.         }
  150.  
  151.         dprint(2, (debugfile, "Action: %s\n", buffer));
  152.         error(buffer);
  153.  
  154.         delete_from_alias_text(list, to_delete);
  155.  
  156.         free((char *) list);
  157.       }
  158.     }
  159.     dprint(3, (debugfile, "Aliases deleted: %d\n", to_delete));
  160.  
  161.     /* If all aliases are to be kept we don't need to do anything
  162.      * (like run newalias for the deleted messages).
  163.      */
  164.  
  165.     if(to_delete == 0) {
  166.       dprint(3, (debugfile, "Aliases kept as is!\n"));
  167.       return(newaliases);
  168.     }
  169.  
  170.     return(1);
  171. }
  172.  
  173. exit_alias()
  174. {
  175.  
  176.     register int i;
  177.  
  178.     /* Clear the deletes from all aliases.  */
  179.  
  180.     for(i = 0; i < message_count; i++)
  181.       if (ison(aliases[i]->status, DELETED))
  182.         clearit(aliases[i]->status, DELETED);
  183.  
  184.     dprint(6, (debugfile, "\nexit_alias:  Done clearing deletes.\n"));
  185.  
  186. }
  187.