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

  1.  
  2. static char rcsid[] = "@(#)$Id: quit.c,v 5.4 1992/11/26 00:46:13 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: quit.c,v $
  17.  * Revision 5.4  1992/11/26  00:46:13  syd
  18.  * changes to first change screen back (Raw off) and then issue final
  19.  * error message.
  20.  * From: Syd
  21.  *
  22.  * Revision 5.3  1992/10/24  13:35:39  syd
  23.  * changes found by using codecenter on Elm 2.4.3
  24.  * From: Graham Hudspith <gwh@inmos.co.uk>
  25.  *
  26.  * Revision 5.2  1992/10/17  22:47:09  syd
  27.  * adds the function bytemap() and the macros MAPIN and MAPOUT from the file
  28.  * lib/ndbz.c in the file src/alias.c.
  29.  *
  30.  * prevent elm from exiting when resyncing the empty incoming mailbox.
  31.  * From: vogt@isa.de (Gerald Vogt)
  32.  *
  33.  * Revision 5.1  1992/10/03  22:58:40  syd
  34.  * Initial checkin as of 2.4 Release at PL0
  35.  *
  36.  *
  37.  ******************************************************************************/
  38.  
  39. /** quit: leave the current folder and quit the program.
  40.   
  41. **/
  42.  
  43. #include "headers.h"
  44. #include "s_elm.h"
  45. #include <errno.h>
  46.  
  47. extern int errno;        /* system error number on failure */
  48.  
  49. long bytes();
  50. char *error_description();
  51. extern void init_helpmsg();
  52.  
  53. quit(prompt)
  54. int prompt;
  55. {
  56.     /* a wonderfully short routine!! */
  57.  
  58.     if (leave_mbox(FALSE, TRUE, prompt) == -1)
  59.       /* new mail - leave not done - can't change to another file yet
  60.        * check for change in mailfile_size in main() will do the work
  61.        * of calling newmbox to add in the new messages to the current
  62.        * file and fix the sorting sequence that leave_mbox may have
  63.        * changed for its own purposes */
  64.       return;
  65.  
  66.     leave(0);
  67. }
  68.  
  69. int
  70. resync()
  71. {
  72.     /** Resync on the current folder. Leave current and read it back in.
  73.         Return indicates whether a redraw of the screen is needed.
  74.      **/
  75.     int  err;
  76.  
  77.       if(leave_mbox(TRUE, FALSE, TRUE) ==-1)
  78.         /* new mail - leave not done - can't change to another file yet
  79.          * check for change in mailfile_size in main() will do the work
  80.          * of calling newmbox to add in the new messages to the current
  81.          * file and fix the sorting sequence that leave_mbox may have
  82.          * changed for its own purposes */
  83.         return(FALSE);
  84.  
  85.       if ((errno = can_access(cur_folder, READ_ACCESS)) != 0) {
  86.         if (strcmp(cur_folder, defaultfile) != 0 || errno != ENOENT) {
  87.           err = errno;
  88.           MoveCursor(LINES, 0);
  89.           Raw(OFF);
  90.           dprint(1, (debugfile,
  91.              "Error: given file %s as folder - unreadable (%s)!\n", 
  92.              cur_folder, error_description(err)));
  93.           fprintf(stderr, catgets(elm_msg_cat, ElmSet, ElmCantOpenFolderRead,
  94.             "Can't open folder '%s' for reading!\n"), cur_folder);
  95.           leave(0);
  96.         }
  97.       }
  98.  
  99.       newmbox(cur_folder, FALSE);
  100.       return(TRUE);
  101. }
  102.  
  103. char helpmsg[VERY_LONG_STRING];
  104.  
  105. change_file()
  106. {
  107.       /* Prompt user for name of folder to change to.
  108.        * If all okay with that folder, leave the current folder.
  109.        * If leave goes okay (i.e. no new messages in current folder),
  110.        * change to the folder that the user specified.
  111.        *
  112.        * Return value indicates whether a redraw is needed.
  113.        */
  114.  
  115.       int redraw = FALSE;
  116.       char newfile[SLEN];
  117.  
  118.       char    *nameof();
  119.  
  120.  
  121.       /* get new file name */
  122.  
  123.       MoveCursor(LINES-3, 30);
  124.       CleartoEOS();
  125.       PutLine0(LINES-3, 38, catgets(elm_msg_cat, ElmSet, ElmUseForHelp,
  126.         "(Use '?' for help)"));
  127.       PutLine0(LINES-2,0, catgets(elm_msg_cat, ElmSet, ElmChangeToWhichFolder,
  128.         "Change to which folder: "));
  129.       while(1) {
  130.         newfile[0] = '\0';
  131.         (void) optionally_enter(newfile, LINES-2, 24, FALSE, FALSE);
  132.         clear_error();
  133.  
  134.         if(*newfile == '\0') {    /* if user didn't enter a file name */
  135.           MoveCursor(LINES-3, 30);    /* abort changing file process */
  136.           CleartoEOS();
  137.           return(redraw);
  138.  
  139.         }
  140.         if (strcmp(newfile, "?") == 0) {
  141.  
  142.           /* user wants to list folders */
  143.           if(!*helpmsg)     /* format helpmsg if not yet done */
  144.         init_helpmsg( helpmsg, change_word, FALSE );
  145.           ClearScreen();
  146.           printf( helpmsg ) ;
  147.           PutLine0(LINES-2,0,catgets(elm_msg_cat, ElmSet, ElmChangeToWhichFolder,
  148.         "Change to which folder: "));    /* reprompt */
  149.           redraw = TRUE;        /* we'll need to clean the screen */
  150.           continue ;
  151.         }
  152.  
  153.         /* if user entered wildcard, list expansions and try again */
  154.         if ( has_wildcards( newfile ) ) {
  155.           list_folders( 4, NULL, newfile ) ;
  156.           PutLine0(LINES-2,0,catgets(elm_msg_cat, ElmSet, ElmChangeToWhichFolder,
  157.         "Change to which folder: "));    /* reprompt */
  158.           redraw = TRUE ;
  159.           continue ;  
  160.         }
  161.  
  162.         /* user entered a file name - expand it */
  163.         if (! expand_filename(newfile, TRUE))
  164.           continue;    /* prompt again */
  165.  
  166.         /* don't accept the same file as the current */
  167.         if (strcmp(newfile, cur_folder) == 0) {
  168.           error(catgets(elm_msg_cat, ElmSet, ElmAlreadyReadingThatFolder,
  169.         "Already reading that folder!"));
  170.           continue;    /* prompt again */
  171.         }
  172.  
  173.         /* Make sure this is a file the user can open, unless it's the
  174.          * default mailfile, which is openable even if empty */
  175.         if ((errno = can_access(newfile, READ_ACCESS)) != 0 ) {
  176.           if (strcmp(newfile, defaultfile) != 0 || errno != ENOENT) {
  177.         error1(catgets(elm_msg_cat, ElmSet, ElmCantOpenFolderReadNONL,
  178.             "Can't open folder '%s' for reading!"), newfile);
  179.         continue;     /* prompt again */
  180.           }
  181.         }
  182.         break;    /* exit loop - we got the name of a good file */
  183.       }
  184.  
  185.       /* All's clear with the new file to go ahead and leave the current. */
  186.       MoveCursor(LINES-3, 30);
  187.       CleartoEOS();
  188.  
  189.       if(leave_mbox(FALSE, FALSE, TRUE) ==-1) {
  190.         /* new mail - leave not done - can't change to another file yet
  191.          * check for change in mailfile_size in main() will do the work
  192.          * of calling newmbox to add in the new messages to the current
  193.          * file and fix the sorting sequence that leave_mbox may have
  194.          * changed for its own purposes */
  195.         return(redraw);
  196.       }
  197.  
  198.       redraw = 1;
  199.       newmbox(newfile, FALSE);
  200.       return(redraw);
  201. }
  202.