home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / pcomm / part04 / pexit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-17  |  2.1 KB  |  111 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 "dial_dir.h"
  9. #include "misc.h"
  10. #include "param.h"
  11. #include "status.h"
  12.  
  13. void
  14. pexit(fd)
  15. int fd;
  16. {
  17.     WINDOW *ex_win, *newwin();
  18.     void cleanup(), status_line();
  19.  
  20.     ex_win = newwin(5, 33, 3, 7);
  21.  
  22.     box(ex_win, '|', '-');
  23.     mvwattrstr(ex_win, 0, 3, A_BOLD, " Exit ");
  24.     if (yes_prompt(ex_win, 2, 4, A_BLINK, "Exit to Unix")) {
  25.         status_line("   exiting");
  26.         cleanup(0);
  27.     }
  28.     if (fd == -1) {
  29.         werase(ex_win);
  30.         wrefresh(ex_win);
  31.     }
  32.     delwin(ex_win);
  33.     return;
  34. }
  35.  
  36. /*
  37.  * Do the cleanup detail before we exit.
  38.  */
  39.  
  40. void
  41. cleanup(val)
  42. int val;
  43. {
  44.     void release_port(), input_off(), exit(), status_line();
  45.     char *ttyname();
  46.                     /* kill the input routine */
  47.     input_off();
  48.                     /* zap the virtual screen file */
  49.     unlink(status->vs_path);
  50.                     /* release the port */
  51.     release_port(0);
  52.                     /* erase the window we made */
  53.     touchwin(stdscr);
  54.     clear();
  55.     refresh();
  56.     endwin();
  57.                     /* return the tty chmod */
  58.     chmod(ttyname(0), status->msg);
  59.     exit(val);
  60. }
  61.  
  62. /*
  63.  * Open a window to display an error message.  Handles both fatal and
  64.  * non-fatal errors
  65.  */
  66.  
  67. void
  68. error_win(code, line_one, line_two)
  69. int code;
  70. char *line_one, *line_two;
  71. {
  72.     WINDOW *e_win, *newwin();
  73.     void cleanup(), status_line();
  74.  
  75.     e_win = newwin(7, 70, 9, 5);
  76.                     /* display the nasty note */
  77.     mvwaddstr(e_win, 2, 4, line_one);
  78.     mvwaddstr(e_win, 3, 4, line_two);
  79.     box(e_win, '|', '-');
  80.  
  81.     if (code) {
  82.         mvwattrstr(e_win, 0, 4, A_BOLD, " Error ");
  83.         mvwattrstr(e_win, 5, 24, A_BLINK, "Press any key to exit");
  84.         wmove(e_win, 5, 46);
  85.     }
  86.     else {
  87.         mvwattrstr(e_win, 0, 4, A_BOLD, " Warning ");
  88.         mvwattrstr(e_win, 5, 22, A_BLINK, "Press any key to continue");
  89.         wmove(e_win, 5, 48);
  90.     }
  91.     beep();
  92.     wrefresh(e_win);
  93.  
  94.     wgetch(e_win);
  95.     werase(e_win);
  96.     wrefresh(e_win);
  97.     delwin(e_win);
  98.  
  99.     if (code) {
  100.         /*
  101.          * Since this routine gets called if there is an error reading
  102.          * the support files, the dir and param structures can't be
  103.          * guaranteed to exist yet.
  104.          */
  105.         if (dir != NULL && param != NULL)
  106.             status_line("   exiting");
  107.         cleanup(code);
  108.     }
  109.     return;
  110. }
  111.