home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / pcomm / part04 / n_shell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-17  |  1.3 KB  |  71 lines

  1. /*
  2.  * Spawn a 'native' shell.  'Native' means the shell found in the SHELL
  3.  * environmental variable.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <signal.h>
  8. #include <curses.h>
  9.  
  10. void
  11. native_shell()
  12. {
  13.     WINDOW *sh_win, *newwin();
  14.     int (*istat)(), (*qstat)(), status, pid, w;
  15.     char *shell, *shellpath, *getenv(), *strrchr();
  16.     unsigned int sleep();
  17.     void _exit();
  18.                     /* a full window */
  19.     sh_win = newwin(LINES, COLS, 0, 0);
  20.  
  21.     clear_absolute(sh_win);
  22.     waddstr(sh_win, "Pcomm <=> Unix gateway, use ^D or 'exit' to return\n");
  23.     wrefresh(sh_win);
  24.                     /* out of curses mode */
  25.     resetterm();
  26.  
  27.     shellpath = getenv("SHELL");
  28.     if (shellpath == NULL || *shellpath == NULL)
  29.         shellpath = "/bin/sh";
  30.  
  31.     shell = strrchr(shellpath, '/') + 1;
  32.  
  33.     if (!(pid = fork())) {
  34. #ifdef SGID
  35.         setgid(getgid());
  36. #endif /* SGID */
  37.         execl(shellpath, shell, "-i", 0);
  38.         _exit(1);
  39.     }
  40.     istat = signal(SIGINT, SIG_IGN);
  41.     qstat = signal(SIGQUIT, SIG_IGN);
  42.  
  43.     while ((w = wait(&status)) != pid && w != -1)
  44.         ;
  45.  
  46.     signal(SIGINT, istat);
  47.     signal(SIGQUIT, qstat);
  48.                     /* back to curses mode */
  49.     fixterm();
  50.     sleep(1);
  51.  
  52.     clear_absolute(stdscr);
  53.     delwin(sh_win);
  54.     return;
  55. }
  56.  
  57. /*
  58.  * Clear the screen absolutely!  It's incrediblely hard to get curses() to
  59.  * clear the screen when it thinks its already clear.
  60.  */
  61.  
  62. int
  63. clear_absolute(win)
  64. WINDOW *win;
  65. {
  66.     clearok(curscr, 1);
  67.     wrefresh(win);
  68.     clearok(curscr, 0);
  69.     return(0);
  70. }
  71.