home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume16 / pcomm2 / part05 / pexit.c < prev    next >
C/C++ Source or Header  |  1988-09-14  |  3KB  |  129 lines

  1. /*
  2.  * Exit Pcomm.  A user requested abort.  There are a lot of things to do
  3.  * before we exit!
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <curses.h>
  8. #include "config.h"
  9. #ifdef SHAREDMEM
  10. #include <sys/types.h>
  11. #include <sys/ipc.h>
  12. #include <sys/shm.h>
  13. #endif /* SHAREDMEM */
  14. #include "dial_dir.h"
  15. #include "misc.h"
  16. #include "param.h"
  17. #include "status.h"
  18.  
  19. void
  20. pexit()
  21. {
  22.     extern int fd;
  23.     WINDOW *ex_win, *newwin();
  24.     void cleanup(), st_line();
  25.  
  26.     ex_win = newwin(5, 33, 3, 7);
  27.  
  28.     box(ex_win, VERT, HORZ);
  29.     mvwattrstr(ex_win, 0, 3, A_BOLD, " Exit ");
  30.     if (yes_prompt(ex_win, 2, 4, A_BLINK, "Exit to Unix")) {
  31.         st_line("   exiting");
  32.         cleanup(0);
  33.     }
  34.     if (fd == -1) {
  35.         werase(ex_win);
  36.         wrefresh(ex_win);
  37.     }
  38.     delwin(ex_win);
  39.     return;
  40. }
  41.  
  42. /*
  43.  * Do the clean up detail before we exit.  Only the status structure
  44.  * is guaranteed to exit.
  45.  */
  46.  
  47. void
  48. cleanup(val)
  49. int val;
  50. {
  51.     extern int msg_status;
  52.     void release_port(), input_off(), exit();
  53.     char *ttyname();
  54. #ifdef SHAREDMEM
  55.     extern int shm_id;
  56. #endif /* SHAREDMEM */
  57.                     /* kill the input routine */
  58.     input_off();
  59.                     /* release the port */
  60.     release_port(0);
  61.                     /* zap the virtual screen */
  62. #ifdef SHAREDMEM
  63.     if (shmdt((char *) status) < 0)
  64.         perror("shmdt");
  65.     if (shmctl(shm_id, IPC_RMID, (struct shmid_ds *) NULL) < 0)
  66.         perror("shmctl");
  67. #else /* SHAREDMEM */
  68.     unlink(status->vs_path);
  69. #endif /* SHAREDMEM */
  70.  
  71.     /*
  72.      * If we die an un-natural death (such as a SIGHUP on the loss of
  73.      * the controlling terminal) we won't have a terminal to mess with.
  74.      */
  75.     if (isatty(0)) {
  76.         touchwin(stdscr);
  77.         clear();
  78.         refresh();
  79.         endwin();
  80.                     /* return the TTY chmod */
  81.         chmod(ttyname(0), msg_status);
  82.     }
  83.     exit(val);
  84. }
  85.  
  86. /*
  87.  * Open a window to display an error message.  Handles both fatal and
  88.  * non-fatal errors
  89.  */
  90.  
  91. void
  92. error_win(code, line_one, line_two)
  93. int code;
  94. char *line_one, *line_two;
  95. {
  96.     WINDOW *e_win, *newwin();
  97.     void cleanup(), st_line();
  98.  
  99.     e_win = newwin(7, 70, 9, 5);
  100.                     /* display the nasty note */
  101.     mvwaddstr(e_win, 2, 4, line_one);
  102.     mvwaddstr(e_win, 3, 4, line_two);
  103.     box(e_win, VERT, HORZ);
  104.  
  105.     if (code) {
  106.         mvwattrstr(e_win, 0, 4, A_BOLD, " Error ");
  107.         mvwattrstr(e_win, 5, 24, A_BLINK, "Press any key to exit");
  108.         wmove(e_win, 5, 46);
  109.     }
  110.     else {
  111.         mvwattrstr(e_win, 0, 4, A_BOLD, " Warning ");
  112.         mvwattrstr(e_win, 5, 22, A_BLINK, "Press any key to continue");
  113.         wmove(e_win, 5, 48);
  114.     }
  115.     beep();
  116.     wrefresh(e_win);
  117.  
  118.     wgetch(e_win);
  119.     werase(e_win);
  120.     wrefresh(e_win);
  121.     delwin(e_win);
  122.  
  123.     if (code) {
  124.         st_line("   exiting");
  125.         cleanup(code);
  126.     }
  127.     return;
  128. }
  129.