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

📄 transp.c

📁 mips架构的bootloader,99左右的版本 但源代码现在没人更新了
💻 C
字号:
/************************************************************* * File: mon/transp.c * Purpose: Part of core Monitor * Author: Phil Bunce (pjb@carmel.com) * Revision History: *	970304	Start of revision history */#include <termio.h>#include <fcntl.h>#include <mon.h>#define STDOUT 1Optdesc tr_opts[] = {	{"[-2][dev]","transparent mode"},	{"-2","two-port mode"},	{"dev","use device dev"},	{0}};/**************************************************************  transp(ac,av)*	the 'tr' command */transp(ac,av)int ac;char *av[];{int fd,n,i,j,auxA,auxB,twoflg;jmp_buf intrsave;char *hostport,buf[80],abortch,*trabort,*auxport,auxportB[10];struct termio tbuf,consave,hostsave;trabort = getMonEnv("trabort");abortch = str2cc(trabort);if (abortch == 0) {	printf("tr: error: trabort not set\n");	return;	}auxport = 0;twoflg = 0;for (i=1;i<ac;i++) {	if (av[i][0] == '-') {		for (j=1;av[i][j];j++) {			if (av[i][j] == '2') twoflg = 1;			else {				printf("%c: unknown option\n",av[i][j]);				return;				}			}		}	else {		if (!auxport) auxport = av[i];		else {			printf("%s: unknown option\n",av[i]);			return;			}		}	}hostport = getMonEnv("hostport");if (auxport) {	if (strequ(auxport,"tty0")) {		printf("can't use tty0 for transparent mode\n");		return;		}	fd = open(auxport,O_RDWR);	if (fd == -1) {		printf("can't open %s\n",auxport);		return;		}	if (twoflg) {		if (!hostport) {			printf("hostport not defined\n");			return;			}		auxA = open(hostport,O_RDWR);		if (auxA == -1) {			close(fd);			printf("can't open %s\n",hostport);			return;			}		atob(&n,&auxport[3],10);		n++;		sprintf(auxportB,"tty%d",n);		auxB = open(auxportB,O_RDWR);		if (auxB == -1) {			close(fd);			close(auxA);			printf("can't open %s\n",auxportB);			return;			}		}	}else {	if (!hostport) {		printf("hostport not defined\n");		return;		}	if (strequ(hostport,"tty0")) {		printf("can't use tty0 for transparent mode\n");		return;		}	fd = open(hostport,O_RDWR);	if (fd == -1) {		printf("can't open %s\n",hostport);		return;		}	}printf("Entering transparent mode. %s to abort\n",trabort);ioctl(fd,TCGETA,&tbuf);hostsave = tbuf;tbuf.c_lflag &= ~(ICANON|ECHO|ECHOE);tbuf.c_iflag &= ~(ICRNL);tbuf.c_iflag |= IXOFF; /* enable tandem mode */tbuf.c_oflag &= ~ONLCR;tbuf.c_cc[4] = 1;ioctl(fd,TCSETAF,&tbuf);ioctl(STDIN,TCGETA,&tbuf);consave = tbuf;tbuf.c_lflag &= ~(ICANON|ECHO|ECHOE);tbuf.c_iflag &= ~(ICRNL|IXON);tbuf.c_oflag &= ~ONLCR;tbuf.c_cc[4] = 1;ioctl(STDIN,TCSETAF,&tbuf);if (twoflg) {	ioctl(auxA,TCGETA,&tbuf);	tbuf.c_lflag &= ~(ICANON|ECHO|ECHOE);	tbuf.c_iflag &= ~(ICRNL);	tbuf.c_iflag |= IXOFF; /* enable tandem mode */	tbuf.c_oflag &= ~ONLCR;	tbuf.c_cc[4] = 1;	ioctl(auxA,TCSETAF,&tbuf);	ioctl(auxB,TCGETA,&tbuf);	tbuf.c_lflag &= ~(ICANON|ECHO|ECHOE);	tbuf.c_iflag &= ~(ICRNL|IXON);	tbuf.c_oflag &= ~ONLCR;	tbuf.c_cc[4] = 1;	ioctl(auxB,TCSETAF,&tbuf);	}#if 0/* disable INTR char */ioctl(STDIN,GETINTR,intrsave);ioctl(STDIN,SETINTR,0);#endiffor (;;) {	n = ioctl_fionread(STDIN);	if (n > 0) {		n = read(STDIN,buf,n);		if (strchr(buf,abortch)) break;#ifdef PMCC		if (ioctl(fd,TXRDY,0)) write(fd,buf,n);#endif		}	n = ioctl_fionread(fd);	if (n > 0) {		n = read(fd,buf,n);		write(STDOUT,buf,n);		}	if (twoflg) {		n = ioctl_fionread(auxA);		if (n > 0) {			n = read(auxA,buf,n);			write(auxB,buf,n);			}		n = ioctl_fionread(auxB);		if (n > 0) {			n = read(auxB,buf,n);			write(auxA,buf,n);			}		}	}ioctl(STDIN,TCSETAF,&consave);ioctl(fd,TCSETAF,&hostsave);#if 0ioctl(STDIN,SETINTR,intrsave);#endif}

⌨️ 快捷键说明

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