⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 init.c

📁 rxvt经典的linux下的终端.小巧实用
💻 C
📖 第 1 页 / 共 3 页
字号:
					       r->TermWin.ext_bwidth,					       r->PixColors[Color_border],					       r->PixColors[Color_fg]);#endif    rxvt_xterm_seq(r, XTerm_title, r->h->rs[Rs_title], CHAR_ST);    rxvt_xterm_seq(r, XTerm_iconName, r->h->rs[Rs_iconName], CHAR_ST);    classHint.res_name = (char *)r->h->rs[Rs_name];    classHint.res_class = (char *)APL_CLASS;    wmHint.flags = (InputHint | StateHint | WindowGroupHint);    wmHint.input = True;    wmHint.initial_state = (r->Options & Opt_iconic ? IconicState						    : NormalState);    wmHint.window_group = r->TermWin.parent[0];    XSetWMProperties(r->Xdisplay, r->TermWin.parent[0], NULL, NULL,		     (char **)argv, argc, &r->szHint, &wmHint, &classHint);    XSelectInput(r->Xdisplay, r->TermWin.parent[0],		 (KeyPressMask#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)		  | KeyReleaseMask#endif		  | FocusChangeMask | VisibilityChangeMask		  | StructureNotifyMask));/* vt cursor: Black-on-White is standard, but this is more popular */    r->TermWin_cursor = XCreateFontCursor(r->Xdisplay, XC_xterm);    rxvt_recolour_cursor(r);#if defined(HAVE_SCROLLBARS) || defined(MENUBAR)/* cursor (menuBar/scrollBar): Black-on-White */    r->h->cursor_leftptr = XCreateFontCursor(r->Xdisplay, XC_left_ptr);#endif/* the vt window */    r->TermWin.vt = XCreateSimpleWindow(r->Xdisplay, r->TermWin.parent[0],					r->h->window_vt_x, r->h->window_vt_y,					TermWin_TotalWidth(),					TermWin_TotalHeight(),					0,					r->PixColors[Color_fg],					r->PixColors[Color_bg]);#ifdef DEBUG_X    XStoreName(r->Xdisplay, r->TermWin.vt, "vt window");#endif    XDefineCursor(r->Xdisplay, r->TermWin.vt, r->TermWin_cursor);    XSelectInput(r->Xdisplay, r->TermWin.vt,		 (ExposureMask | ButtonPressMask | ButtonReleaseMask		  | PropertyChangeMask		  | Button1MotionMask | Button3MotionMask));#if defined(MENUBAR) && (MENUBAR_MAX > 1)    if (menuBar_height()) {	r->menuBar.win = XCreateSimpleWindow(r->Xdisplay, r->TermWin.parent[0],					     r->h->window_vt_x, 0,					     TermWin_TotalWidth(),					     menuBar_TotalHeight(),					     0,					     r->PixColors[Color_fg],					     r->PixColors[Color_scroll]);#ifdef DEBUG_X    XStoreName(r->Xdisplay, r->menuBar.win, "menubar");#endif	XDefineCursor(r->Xdisplay, r->menuBar.win, r->h->cursor_leftptr);	XSelectInput(r->Xdisplay, r->menuBar.win,		     (ExposureMask | ButtonPressMask | ButtonReleaseMask		      | Button1MotionMask));    }#endif#ifdef XPM_BACKGROUND    if (r->h->rs[Rs_backgroundPixmap] != NULL	&& !(r->Options & Opt_transparent)) {	const char     *p = r->h->rs[Rs_backgroundPixmap];	if ((p = STRCHR(p, ';')) != NULL) {	    p++;	    rxvt_scale_pixmap(r, p);	}	rxvt_set_bgPixmap(r, r->h->rs[Rs_backgroundPixmap]);	rxvt_scr_touch(r, True);    }#endif/* graphics context for the vt window */    gcvalue.font = r->TermWin.font->fid;    gcvalue.foreground = r->PixColors[Color_fg];    gcvalue.background = r->PixColors[Color_bg];    gcvalue.graphics_exposures = 1;    r->TermWin.gc = XCreateGC(r->Xdisplay, r->TermWin.vt,			      GCForeground | GCBackground			      | GCFont | GCGraphicsExposures, &gcvalue);#if defined(MENUBAR) || defined(RXVT_SCROLLBAR)    gcvalue.foreground = r->PixColors[Color_topShadow];    r->h->topShadowGC = XCreateGC(r->Xdisplay, r->TermWin.vt,				  GCForeground, &gcvalue);    gcvalue.foreground = r->PixColors[Color_bottomShadow];    r->h->botShadowGC = XCreateGC(r->Xdisplay, r->TermWin.vt,				  GCForeground, &gcvalue);    gcvalue.foreground = r->PixColors[(XDEPTH <= 2 ? Color_fg						   : Color_scroll)];    r->h->scrollbarGC = XCreateGC(r->Xdisplay, r->TermWin.vt,				  GCForeground, &gcvalue);#endif}/*----------------------------------------------------------------------*//* * Run the command in a subprocess and return a file descriptor for the * master end of the pseudo-teletype pair with the command talking to * the slave. *//* INTPROTO */intrxvt_run_command(rxvt_t *r, const char *const *argv){    int             i, cfd;/* * Close all unused file descriptors * We don't want them, we don't need them. */    if ((i = open("/dev/null", O_RDONLY)) < 0) {	/* TODO: BOO HISS */	dup2(STDERR_FILENO, STDIN_FILENO);    } else if (i > STDIN_FILENO) {	dup2(i, STDIN_FILENO);	close(i);    }    dup2(STDERR_FILENO, STDOUT_FILENO);    for (i = STDERR_FILENO + 1; i < r->num_fds; i++) {	if (#ifdef __sgi			/* Alex Coventry says we need 4 & 7 too */	    i == 4 || i == 7 ||#endif	    i == r->Xfd)	    continue;	close(i);    }    if ((r->Xfd < STDERR_FILENO + 1#ifdef FD_SETSIZE	 || r->Xfd > FD_SETSIZE#endif        ) && dup2(r->Xfd, STDERR_FILENO + 1) != -1) {	close(r->Xfd);	r->Xfd = STDERR_FILENO + 1;    }/* get master (pty) */    if ((cfd = rxvt_get_pty(&(r->tty_fd), &(r->h->ttydev))) < 0) {	rxvt_print_error("can't open pseudo-tty");	return -1;    }#ifdef FD_SETSIZE    if (r->Xfd > FD_SETSIZE || cfd > FD_SETSIZE) {	rxvt_print_error("fd too high: %d max", FD_SETSIZE);	rxvt_clean_exit();	exit(EXIT_FAILURE);    }#endif    fcntl(cfd, F_SETFL, O_NDELAY);/* get slave (tty) */    if (r->tty_fd < 0) {	rxvt_privileged_ttydev(r, SAVE);	if ((r->tty_fd = rxvt_get_tty(r->h->ttydev)) < 0) {	    close(cfd);	    rxvt_print_error("can't open slave tty %s", r->h->ttydev);	    return -1;	}    }    rxvt_get_ttymode(&(r->h->tio));/* install exit handler for cleanup */#ifdef HAVE_ATEXIT    atexit(rxvt_clean_exit);#else# ifdef HAVE_ON_EXIT    on_exit(rxvt_clean_exit, NULL);	/* non-ANSI exit handler */# endif#endif    signal(SIGHUP, rxvt_Exit_signal);#ifndef __svr4__    signal(SIGINT, rxvt_Exit_signal);#endif    signal(SIGQUIT, rxvt_Exit_signal);    signal(SIGTERM, rxvt_Exit_signal);    signal(SIGCHLD, rxvt_Child_signal);/* need to trap SIGURG for SVR4 (Unixware) rlogin *//* signal (SIGURG, SIG_DFL); */#ifndef __QNX__/* spin off the command interpreter */    switch (r->h->cmd_pid = fork()) {    case -1:	rxvt_print_error("can't fork");	return -1;    case 0:	close(cfd);		/* only keep r->tty_fd and STDERR open */	close(r->Xfd);#ifdef __QNX__	rxvt_run_child(r, argv);#else	if (rxvt_control_tty(r->tty_fd, r->h->ttydev) < 0)	    rxvt_print_error("could not obtain control of tty");	else {	/* Reopen stdin, stdout and stderr over the tty file descriptor */	    dup2(r->tty_fd, STDIN_FILENO);	    dup2(r->tty_fd, STDOUT_FILENO);	    dup2(r->tty_fd, STDERR_FILENO);	    if (r->tty_fd > 2)		close(r->tty_fd);	    rxvt_run_child(r, argv);	}#endif	exit(EXIT_FAILURE);	/* NOTREACHED */    default:	close(r->tty_fd);	/* keep STDERR_FILENO, r->cmd_fd, r->Xfd open */	break;    }#else				/* __QNX__ uses qnxspawn() */    fchmod(r->tty_fd, 0622);    fcntl(r->tty_fd, F_SETFD, FD_CLOEXEC);    fcntl(cfd, F_SETFD, FD_CLOEXEC);    if (rxvt_run_child(r, argv) == -1)	exit(EXIT_FAILURE);#endif/* * Reduce r->num_fds to what we use, so select() is more efficient */    r->num_fds = max(STDERR_FILENO, cfd);    MAX_IT(r->num_fds, r->Xfd);#ifdef __sgi			/* Alex Coventry says we need 4 & 7 too */    MAX_IT(r->num_fds, 7);#endif    r->num_fds++;		/* counts from 0 */    rxvt_privileged_utmp(r, SAVE);    return cfd;}/* ------------------------------------------------------------------------- * *                          CHILD PROCESS OPERATIONS                         * * ------------------------------------------------------------------------- *//* * The only open file descriptor is the slave tty - so no error messages. * returns are fatal *//* INTPROTO */intrxvt_run_child(rxvt_t *r, const char *const *argv){    char           *login;    SET_TTYMODE(STDIN_FILENO, &(r->h->tio));	/* init terminal attributes */    if (r->Options & Opt_console) {	/* be virtual console, fail silently */#ifdef TIOCCONS	unsigned int    on = 1;	ioctl(STDIN_FILENO, TIOCCONS, &on);#elif defined (SRIOCSREDIR)	int             fd;	fd = open(CONSOLE, O_WRONLY, 0);	if (fd >= 0) {	    if (ioctl(fd, SRIOCSREDIR, NULL) < 0)		close(fd);	}#endif				/* SRIOCSREDIR */    }    /* set window size */    rxvt_tt_winsize(STDIN_FILENO, r->TermWin.ncol, r->TermWin.nrow);/* reset signals and spin off the command interpreter */    signal(SIGINT, SIG_DFL);    signal(SIGQUIT, SIG_DFL);    signal(SIGCHLD, SIG_DFL);/* * mimick login's behavior by disabling the job control signals * a shell that wants them can turn them back on */#ifdef SIGTSTP    signal(SIGTSTP, SIG_IGN);    signal(SIGTTIN, SIG_IGN);    signal(SIGTTOU, SIG_IGN);#endif				/* SIGTSTP */#ifndef __QNX__/* command interpreter path */    if (argv != NULL) {# ifdef DEBUG_CMD	int             i;	for (i = 0; argv[i]; i++)	    fprintf(stderr, "argv [%d] = \"%s\"\n", i, argv[i]);# endif	execvp(argv[0], (char *const *)argv);	/* no error message: STDERR is closed! */    } else {	const char     *argv0, *shell;	if ((shell = getenv("SHELL")) == NULL || *shell == '\0')	    shell = "/bin/sh";	argv0 = (const char *)rxvt_r_basename(shell);	if (r->Options & Opt_loginShell) {	    login = rxvt_malloc((STRLEN(argv0) + 2) * sizeof(char));	    login[0] = '-';	    STRCPY(&login[1], argv0);	    argv0 = login;	}	execlp(shell, argv0, NULL);	/* no error message: STDERR is closed! */    }#else				/* __QNX__ uses qnxspawn() */    {	char            iov_a[10] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };	char           *command = NULL, fullcommand[_MAX_PATH];	char          **arg_v, *arg_a[2] = { NULL, NULL };	if (argv != NULL) {	    if (access(argv[0], X_OK) == -1) {		if (STRCHR(argv[0], '/') == NULL) {		    searchenv(argv[0], "PATH", fullcommand);		    if (fullcommand[0] != '\0')			command = fullcommand;		}		if (access(command, X_OK) == -1)		    return -1;	    } else		command = argv[0];	    arg_v = argv;	} else {	    if ((command = getenv("SHELL")) == NULL || *command == '\0')		command = "/bin/sh";	    arg_a[0] = my_basename(command);	    if (r->Options & Opt_loginShell) {		login = rxvt_malloc((STRLEN(arg_a[0]) + 2) * sizeof(char));		login[0] = '-';		STRCPY(&login[1], arg_a[0]);		arg_a[0] = login;	    }	    arg_v = arg_a;	}	iov_a[0] = iov_a[1] = iov_a[2] = r->tty_fd;	r->h->cmd_pid = qnx_spawn(0, 0, 0, -1, -1,				  _SPAWN_SETSID | _SPAWN_TCSETPGRP,				  command, arg_v, environ, iov_a, 0);	if (login)	    free(login);	close(r->tty_fd);	return r->cmd_fd;    }#endif    return -1;}/* ------------------------------------------------------------------------- * *                            GET TTY CURRENT STATE                          * * ------------------------------------------------------------------------- *//* rxvt_get_ttymode() *//* INTPROTO */voidrxvt_get_ttymode(ttymode_t *tio){#ifdef HAVE_TERMIOS_H/* * standard System V termios interface */    if (GET_TERMIOS(STDIN_FILENO, tio) < 0) {	/* return error - use system defaults */	tio->c_cc[VINTR] = CINTR;	tio->c_cc[VQUIT] = CQUIT;	tio->c_cc[VERASE] = CERASE;	tio->c_cc[VKILL] = CKILL;	tio->c_cc[VSTART] = CSTART;	tio->c_cc[VSTOP] = CSTOP;	tio->c_cc[VSUSP] = CSUSP;# ifdef VDSUSP	tio->c_cc[VDSUSP] = CDSUSP;# endif# ifdef VREPRINT	tio->c_cc[VREPRINT] = CRPRNT;# endif# ifdef VDISCRD	tio->c_cc[VDISCRD] = CFLUSH;# endif# ifdef VWERSE	tio->c_cc[VWERSE] = CWERASE;# endif# ifdef VLNEXT	tio->c_cc[VLNEXT] = CLNEXT;# endif    }    tio->c_cc[VEOF] = CEOF;    tio->c_cc[VEOL] = VDISABLE;# ifdef VEOL2    tio->c_cc[VEOL2] = VDISABLE;# endif# ifdef VSWTC    tio->c_cc[VSWTC] = VDISABLE;# endif# ifdef VSWTCH    tio->c_cc[VSWTCH] = VDISABLE;# endif# if VMIN != VEOF    tio->c_cc[VMIN] = 1;# endif# if VTIME != VEOL    tio->c_cc[VTIME] = 0;# endif/* input modes */    tio->c_iflag = (BRKINT | IGNPAR | ICRNL# ifdef IMAXBEL		    | IMAXBEL# endif	            | IXON);/* output modes */    tio->c_oflag = (OPOST | ONLCR);/* control modes */    tio->c_cflag = (CS8 | CREAD);/* line discipline modes */    tio->c_lflag = (ISIG | ICANON | IEXTEN | ECHO# if defined (ECHOCTL) && defined (ECHOKE)		    | ECHOCTL | ECHOKE# endif	            | ECHOE | ECHOK);# else				/* HAVE_TERMIOS_H *//* * sgtty interface *//* get parameters -- gtty */    if (ioctl(STDIN_FILENO, TIOCGETP, &(tio->sg)) < 0) {	tio->sg.sg_erase = CERASE;	/* ^H */	tio->sg.sg_kill = CKILL;	/* ^U */    }    tio->sg.sg_flags = (CRMOD | ECHO | EVENP | ODDP);/* get special characters */    if (ioctl(STDIN_FILENO, TIOCGETC, &(tio->tc)) < 0) {	tio->tc.t_intrc = CINTR;	/* ^C */	tio->tc.t_quitc = CQUIT;	/* ^\ */	tio->tc.t_startc = CSTART;	/* ^Q */	tio->tc.t_stopc = CSTOP;	/* ^S */	tio->tc.t_eofc = CEOF;	/* ^D */	tio->tc.t_brkc = -1;    }/* get local special chars */    if (ioctl(STDIN_FILENO, TIOCGLTC, &(tio->lc)) < 0) {	tio->lc.t_suspc = CSUSP;	/* ^Z */	tio->lc.t_dsuspc = CDSUSP;	/* ^Y */	tio->lc.t_rprntc = CRPRNT;	/* ^R */	tio->lc.t_flushc = CFLUSH;	/* ^O */	tio->lc.t_werasc = CWERASE;	/* ^W */	tio->lc.t_lnextc = CLNEXT;	/* ^V */    }/* get line discipline */    ioctl(STDIN_FILENO, TIOCGETD, &(tio->line));# ifdef NTTYDISC    tio->line = NTTYDISC;# endif				/* NTTYDISC */    tio->local = (LCRTBS | LCRTERA | LCTLECH | LPASS8 | LCRTKIL);#endif				/* HAVE_TERMIOS_H *//* * Debugging */#ifdef DEBUG_TTYMODE#ifdef HAVE_TERMIOS_H/* c_iflag bits */    fprintf(stderr, "Input flags\n");/* cpp token stringize doesn't work on all machines <sigh> */# define FOO(flag,name)			\    if ((tio->c_iflag) & flag)		\	fprintf (stderr, "%s ", name)/* c_iflag bits */    FOO(IGNBRK, "IGNBRK");    FOO(BRKINT, "BRKINT");    FOO(IGNPAR, "IGNPAR");    FOO(PARMRK, "PARMRK");    FOO(INPCK, "INPCK");    FOO(ISTRIP, "ISTRIP");    FOO(INLCR, "INLCR");    FOO(IGNCR, "IGNCR");    FOO(ICRNL, "ICRNL");    FOO(IXON, "IXON");    FOO(IXOFF, "IXOFF");# ifdef IUCLC    FOO(IUCLC, "IUCLC");# endif# ifdef IXANY    FOO(IXANY, "IXANY");# endif# ifdef IMAXBEL    FOO(IMAXBEL, "IMAXBEL");# endif    fprintf(stderr, "\n");# undef FOO# define FOO(entry, name)					\    fprintf(stderr, "%-8s = %#04o\n", name, tio->c_cc [entry])    FOO(VINTR, "VINTR");    FOO(VQUIT, "VQUIT");    FOO(VERASE, "VERASE");    FOO(VKILL, "VKILL");    FOO(VEOF, "VEOF");    FOO(VEOL, "VEOL");# ifdef VEOL2    FOO(VEOL2, "VEOL2");# endif# ifdef VSWTC    FOO(VSWTC, "VSWTC");# endif# ifdef VSWTCH    FOO(VSWTCH, "VSWTCH");# endif    FOO(VSTART, "VSTART");    FOO(VSTOP, "VSTOP");    FOO(VSUSP, "VSUSP");# ifdef VDSUSP    FOO(VDSUSP, "VDSUSP");# endif# ifdef VREPRINT    FOO(VREPRINT, "VREPRINT");# endif# ifdef VDISCRD    FOO(VDISCRD, "VDISCRD");# endif# ifdef VWERSE    FOO(VWERSE, "VWERSE");# endif# ifdef VLNEXT    FOO(VLNEXT, "VLNEXT");# endif    fprintf(stderr, "\n");# undef FOO# endif				/* HAVE_TERMIOS_H */#endif				/* DEBUG_TTYMODE */}/*----------------------- end-of-file (C source) -----------------------*/

⌨️ 快捷键说明

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