home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / ELM23-2 / ELM23-2.ZIP / src / quit.c < prev    next >
C/C++ Source or Header  |  1992-02-01  |  6KB  |  179 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: quit.c,v 4.1 90/04/28 22:43:44 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 4.1 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1986, 1987 Dave Taylor
  8.  *             Copyright (c) 1988, 1989, 1990 USENET Community Trust
  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 4.1  90/04/28  22:43:44  syd
  18.  * checkin of Elm 2.3 as of Release PL0
  19.  *
  20.  *
  21.  ******************************************************************************/
  22.  
  23. /** quit: leave the current folder and quit the program.
  24.  
  25. **/
  26.  
  27. #include "headers.h"
  28. #include <errno.h>
  29.  
  30. #ifndef OS2
  31. extern int errno;        /* system error number on failure */
  32. #endif
  33.  
  34. long bytes();
  35.  
  36. quit(prompt)
  37. int prompt;
  38. {
  39.     /* a wonderfully short routine!! */
  40.  
  41.     if (leave_mbox(FALSE, TRUE, prompt) == -1)
  42.       /* new mail - leave not done - can't change to another file yet
  43.        * check for change in mailfile_size in main() will do the work
  44.        * of calling newmbox to add in the new messages to the current
  45.        * file and fix the sorting sequence that leave_mbox may have
  46.        * changed for its own purposes */
  47.       return;
  48.  
  49.     leave();
  50. }
  51.  
  52. int
  53. resync()
  54. {
  55.     /** Resync on the current folder. Leave current and read it back in.
  56.         Return indicates whether a redraw of the screen is needed.
  57.      **/
  58.  
  59.       if(leave_mbox(TRUE, FALSE, TRUE) ==-1)
  60.         /* new mail - leave not done - can't change to another file yet
  61.          * check for change in mailfile_size in main() will do the work
  62.          * of calling newmbox to add in the new messages to the current
  63.          * file and fix the sorting sequence that leave_mbox may have
  64.          * changed for its own purposes */
  65.         return(FALSE);
  66.  
  67.       if ((errno = can_access(cur_folder, READ_ACCESS)) != 0) {
  68.         dprint(1, (debugfile,
  69.           "Error: given file %s as folder - unreadable (%s)!\n",
  70.           cur_folder, error_name(errno)));
  71.         fprintf(stderr,"Can't open folder '%s' for reading!\n", cur_folder);
  72.         leave();
  73.         }
  74.  
  75.       newmbox(cur_folder, FALSE);
  76.       return(TRUE);
  77. }
  78.  
  79. change_file()
  80. {
  81.       /* Prompt user for name of folder to change to.
  82.        * If all okay with that folder, leave the current folder.
  83.        * If leave goes okay (i.e. no new messages in current folder),
  84.        * change to the folder that the user specified.
  85.        *
  86.        * Return value indicates whether a redraw is needed.
  87.        */
  88.  
  89.       int redraw = FALSE;
  90.       char newfile[SLEN];
  91.       static char helpmsg[LONG_STRING];
  92.  
  93.       char    *nameof();
  94.  
  95.  
  96.       /* get new file name */
  97.  
  98.       MoveCursor(LINES-3, 30);
  99.       CleartoEOS();
  100.       PutLine0(LINES-3, 38, "(Use '?' for help/to list your folders.)");
  101.       PutLine0(LINES-2,0,"Change to which folder: ");
  102.       while(1) {
  103.         newfile[0] = '\0';
  104.         (void) optionally_enter(newfile, LINES-2, 24, FALSE, FALSE);
  105.         clear_error();
  106.  
  107.         if(*newfile == '\0') {    /* if user didn't enter a file name */
  108.           MoveCursor(LINES-3, 30);    /* abort changing file process */
  109.           CleartoEOS();
  110.           return(redraw);
  111.  
  112.         } else if (strcmp(newfile, "?") == 0) {
  113.  
  114.           /* user wants to list folders */
  115.           if(!*helpmsg) {    /* format helpmsg if not yet done */
  116.  
  117.         strcpy(helpmsg,
  118.           "\n\r\n\rEnter: <nothing> to not change to a new folder,");
  119.         strcat(helpmsg,
  120.           "\n\r       '!' to change to your incoming mailbox (");
  121.         strcat(helpmsg, defaultfile);
  122.         strcat(helpmsg,
  123.           ")\n\r       '>' to change to your \"received\" folder (");
  124.         strcat(helpmsg, nameof(recvd_mail));
  125.         strcat(helpmsg,
  126.           ")\n\r       '<' to change to your \"sent\" folder (");
  127.         strcat(helpmsg, nameof(sent_mail));
  128.         strcat(helpmsg, ")\n\r       or a filename");
  129.         strcat(helpmsg,
  130.           " (leading '=' denotes your folder directory ");
  131.         strcat(helpmsg, folders);
  132.         strcat(helpmsg, ").\n\r");
  133.           }
  134.           list_folders(4, helpmsg);
  135.           PutLine0(LINES-2,0,"Change to which folder: ");    /* reprompt */
  136.           redraw = TRUE;        /* we'll need to clean the screen */
  137.  
  138.         } else {
  139.  
  140.           /* user entered a file name - expand it */
  141.           if (! expand_filename(newfile, TRUE))
  142.         continue;    /* prompt again */
  143.  
  144.           /* don't accept the same file as the current */
  145.           if (strcmp(newfile, cur_folder) == 0) {
  146.         error("Already reading that folder!");
  147.         continue;    /* prompt again */
  148.           }
  149.  
  150.           /* Make sure this is a file the user can open, unless it's the
  151.            * default mailfile, which is openable even if empty */
  152.           if ((errno = can_access(newfile, READ_ACCESS)) != 0 ) {
  153.         if (strcmp(newfile, defaultfile) != 0 || errno != ENOENT) {
  154.           error1("Can't open folder '%s' for reading!", newfile);
  155.           continue;     /* prompt again */
  156.         }
  157.           }
  158.           break;    /* exit loop - we got the name of a good file */
  159.         }
  160.       }
  161.  
  162.       /* All's clear with the new file to go ahead and leave the current. */
  163.       MoveCursor(LINES-3, 30);
  164.       CleartoEOS();
  165.  
  166.       if(leave_mbox(FALSE, FALSE, TRUE) ==-1) {
  167.         /* new mail - leave not done - can't change to another file yet
  168.          * check for change in mailfile_size in main() will do the work
  169.          * of calling newmbox to add in the new messages to the current
  170.          * file and fix the sorting sequence that leave_mbox may have
  171.          * changed for its own purposes */
  172.         return(redraw);
  173.       }
  174.  
  175.       redraw = 1;
  176.       newmbox(newfile, FALSE);
  177.       return(redraw);
  178. }
  179.