home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / TOP / USR / SRC / yahtzee.t.Z / yahtzee.t / shell.c < prev    next >
Text File  |  1988-08-01  |  2KB  |  112 lines

  1. /* shell.c
  2.  *    a simple shell escape available at all times.
  3.  */
  4. #include <signal.h>
  5. #include <curses.h>
  6.  
  7. /* default shell */
  8. static char *shell_name = {"/bin/sh"};
  9. static char *default_base = {"(yahtzee)"};
  10.  
  11. shell(BackWindow)
  12.  
  13. WINDOW *BackWindow;
  14.  
  15.     {
  16.     int pid, wait_status, fork_status;
  17.     char *shell_choice, *getenv(), *basename, *strrchr();
  18. #ifdef BSD
  19.     int (*oldint)(), (*oldquit)();
  20. #else
  21.     void (*oldint)(), (*oldquit)();
  22. #endif
  23.  
  24. #if (defined(SYS5) || defined(SYS5_3)) && ! defined(cyber)
  25.     extern int shell_window_active;
  26.     WINDOW *BadNews;
  27.  
  28.     if (shell_window_active)
  29.         {
  30.         BadNews = newwin(3, 46, 11, 20);
  31.         BoxUp(BadNews, 3, 46);
  32.         mvwaddstr(BadNews, 1, 1,
  33.             "Cannot exec shell with shell window active.");
  34.         touchwin(BadNews);
  35.         flash();
  36.         wrefresh(BadNews);
  37.         sleep(3);
  38.         touchwin(BackWindow);
  39.         wrefresh(BackWindow);
  40.         delwin(BadNews);
  41.         return;
  42.         }
  43. #endif
  44.  
  45. /* move cursor to bottom of screen */
  46.     wmove(stdscr, LINES - 1, 0);
  47.     refresh();
  48.  
  49. /* save the curses terminal state */
  50.     savetty();
  51.  
  52. /* set the terminal to the 'out of curses' state */
  53. #ifdef BSD
  54.     echo();
  55.     nocbreak();
  56. #else
  57.     resetterm();
  58. #endif
  59.  
  60. # ifndef OSK
  61.  
  62. /* create the new process */
  63.     if((pid = fork()) == 0)
  64.  
  65. /* code executed by the child... */
  66.         {
  67.  
  68. /* see if the user has a preference for a shell */
  69.         if (((shell_choice = getenv("SHELL"))) == NULL ||
  70.             (strlen(shell_choice) == 0))
  71.             shell_choice = shell_name;
  72.  
  73. /* determine the basename for use as the 2nd parm to execl */
  74.         if ((basename = strrchr(shell_choice, '/')) == NULL)
  75.             basename = default_base;
  76.         else
  77.             ++basename;
  78.  
  79. /* zap what is left of yahtzee and start a shell */
  80.         (void) execl(shell_choice, basename, "-i", 0);
  81.         exit(-1);
  82.         }
  83.  
  84. /* parent process */
  85.  
  86. /* ignore pesky signals */
  87.     oldint = signal(SIGINT, SIG_IGN);
  88.     oldquit = signal(SIGQUIT, SIG_IGN);
  89.  
  90. /* wait for child process to terminate */
  91.     while((wait_status = wait(&fork_status)) != pid && wait_status != -1);
  92.  
  93. # else OSK
  94.     if (shell_choice = getenv("SHELL"))
  95.         system (shell_choice);
  96.     else
  97.         system ("shell");
  98. # endif OSK
  99.  
  100. /* reset (pesky) signals */
  101.     (void) signal(SIGINT, oldint);
  102.     (void) signal(SIGQUIT, oldquit);
  103.  
  104. /* set terminal back to 'in curses' state */
  105.     resetty();
  106.  
  107. /* complete redraw of the previous window */
  108.     redraw(BackWindow);
  109.     }
  110.  
  111.  
  112.