n_shell.c

来自「通讯程序源码」· C语言 代码 · 共 68 行

C
68
字号
/* * Spawn a "native" shell.  Native means the shell found in the SHELL * environmental variable. */#include <stdio.h>#include <signal.h>#include <curses.h>#include "config.h"voidn_shell(){	WINDOW *sh_win, *newwin();	SIG_TYPE (*istat)(), (*qstat)();	int sig_status, spid, w;	char *shell, *shellpath, *getenv(), *strrchr();	unsigned int sleep();	void _exit();					/* a full window */	sh_win = newwin(LINES, COLS, 0, 0);	touchwin(sh_win);	waddstr(sh_win, "Pcomm <=> Unix gateway, use ^D or 'exit' to return\n");	wrefresh(sh_win);					/* out of curses mode */	resetterm();	shellpath = getenv("SHELL");	if (shellpath == NULL || *shellpath == '\0')		shellpath = "/bin/sh";	if (shell = strrchr(shellpath, '/'))		shell++;	else {		shellpath = "/bin/sh";		shell = "sh";	}	if (!(spid = fork())) {		signal(SIGINT, SIG_DFL);		signal(SIGQUIT, SIG_DFL);		setgid(getgid());		setuid(getuid());		execl(shellpath, shell, "-i", (char *) 0);		_exit(1);	}	istat = signal(SIGINT, SIG_IGN);	qstat = signal(SIGQUIT, SIG_IGN);	while ((w = wait(&sig_status)) != spid && w != -1)		;	signal(SIGINT, istat);	signal(SIGQUIT, qstat);					/* back to curses mode */	sleep(1);	fixterm();	clearok(curscr, TRUE);	werase(sh_win);	wrefresh(sh_win);	delwin(sh_win);	return;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?