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 >
Wrap
Text File
|
1988-08-01
|
2KB
|
112 lines
/* shell.c
* a simple shell escape available at all times.
*/
#include <signal.h>
#include <curses.h>
/* default shell */
static char *shell_name = {"/bin/sh"};
static char *default_base = {"(yahtzee)"};
shell(BackWindow)
WINDOW *BackWindow;
{
int pid, wait_status, fork_status;
char *shell_choice, *getenv(), *basename, *strrchr();
#ifdef BSD
int (*oldint)(), (*oldquit)();
#else
void (*oldint)(), (*oldquit)();
#endif
#if (defined(SYS5) || defined(SYS5_3)) && ! defined(cyber)
extern int shell_window_active;
WINDOW *BadNews;
if (shell_window_active)
{
BadNews = newwin(3, 46, 11, 20);
BoxUp(BadNews, 3, 46);
mvwaddstr(BadNews, 1, 1,
"Cannot exec shell with shell window active.");
touchwin(BadNews);
flash();
wrefresh(BadNews);
sleep(3);
touchwin(BackWindow);
wrefresh(BackWindow);
delwin(BadNews);
return;
}
#endif
/* move cursor to bottom of screen */
wmove(stdscr, LINES - 1, 0);
refresh();
/* save the curses terminal state */
savetty();
/* set the terminal to the 'out of curses' state */
#ifdef BSD
echo();
nocbreak();
#else
resetterm();
#endif
# ifndef OSK
/* create the new process */
if((pid = fork()) == 0)
/* code executed by the child... */
{
/* see if the user has a preference for a shell */
if (((shell_choice = getenv("SHELL"))) == NULL ||
(strlen(shell_choice) == 0))
shell_choice = shell_name;
/* determine the basename for use as the 2nd parm to execl */
if ((basename = strrchr(shell_choice, '/')) == NULL)
basename = default_base;
else
++basename;
/* zap what is left of yahtzee and start a shell */
(void) execl(shell_choice, basename, "-i", 0);
exit(-1);
}
/* parent process */
/* ignore pesky signals */
oldint = signal(SIGINT, SIG_IGN);
oldquit = signal(SIGQUIT, SIG_IGN);
/* wait for child process to terminate */
while((wait_status = wait(&fork_status)) != pid && wait_status != -1);
# else OSK
if (shell_choice = getenv("SHELL"))
system (shell_choice);
else
system ("shell");
# endif OSK
/* reset (pesky) signals */
(void) signal(SIGINT, oldint);
(void) signal(SIGQUIT, oldquit);
/* set terminal back to 'in curses' state */
resetty();
/* complete redraw of the previous window */
redraw(BackWindow);
}