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

📄 stty.c

📁 操作系统源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
  if (match(opt, "onlcr")) {	termios.c_oflag |= ONLCR;	return 0;  }  if (match(opt, "-onlcr")) {	termios.c_oflag &= ~ONLCR;	return 0;  }  if (match(opt, "xtabs")) {	termios.c_oflag |= XTABS;	return 0;  }  if (match(opt, "-xtabs")) {	termios.c_oflag &= ~XTABS;	return 0;  }  if (match(opt, "onoeot")) {	termios.c_oflag |= ONOEOT;	return 0;  }  if (match(opt, "-onoeot")) {	termios.c_oflag &= ~ONOEOT;	return 0;  }#endif  /* Local modes. */  if (match(opt, "echo")) {	termios.c_lflag |= ECHO;	return 0;  }  if (match(opt, "-echo")) {	termios.c_lflag &= ~ECHO;	return 0;  }  if (match(opt, "echoe")) {	termios.c_lflag |= ECHOE;	return 0;  }  if (match(opt, "-echoe")) {	termios.c_lflag &= ~ECHOE;	return 0;  }  if (match(opt, "echok")) {	termios.c_lflag |= ECHOK;	return 0;  }  if (match(opt, "-echok")) {	termios.c_lflag &= ~ECHOK;	return 0;  }  if (match(opt, "echonl")) {	termios.c_lflag |= ECHONL;	return 0;  }  if (match(opt, "-echonl")) {	termios.c_lflag &= ~ECHONL;	return 0;  }  if (match(opt, "icanon")) {	termios.c_lflag |= ICANON;	return 0;  }  if (match(opt, "-icanon")) {	termios.c_lflag &= ~ICANON;	return 0;  }  if (match(opt, "iexten")) {	termios.c_lflag |= IEXTEN;	return 0;  }  if (match(opt, "-iexten")) {	termios.c_lflag &= ~IEXTEN;	return 0;  }  if (match(opt, "isig")) {	termios.c_lflag |= ISIG;	return 0;  }  if (match(opt, "-isig")) {	termios.c_lflag &= ~ISIG;	return 0;  }  if (match(opt, "noflsh")) {	termios.c_lflag |= NOFLSH;	return 0;  }  if (match(opt, "-noflsh")) {	termios.c_lflag &= ~NOFLSH;	return 0;  }  if (match(opt, "tostop")) {	termios.c_lflag |= TOSTOP;	return 0;  }  if (match(opt, "-tostop")) {	termios.c_lflag &= ~TOSTOP;	return 0;  }#ifdef __minix  if (match(opt, "lflusho")) {	termios.c_lflag |= LFLUSHO;	return 0;  }  if (match(opt, "-lflusho")) {	termios.c_lflag &= ~LFLUSHO;	return 0;  }#endif  /* The special control characters. */  if (match(opt, "eof")) {	set_control(VEOF, next);	return 1;  }  if (match(opt, "eol")) {	set_control(VEOL, next);	return 1;  }  if (match(opt, "erase")) {	set_control(VERASE, next);	return 1;  }  if (match(opt, "intr")) {	set_control(VINTR, next);	return 1;  }  if (match(opt, "kill")) {	set_control(VKILL, next);	return 1;  }  if (match(opt, "quit")) {	set_control(VQUIT, next);	return 1;  }  if (match(opt, "susp")) {	set_control(VSUSP, next);	return 1;  }  if (match(opt, "start")) {	set_control(VSTART, next);	return 1;  }  if (match(opt, "stop")) {	set_control(VSTOP, next);	return 1;  }#ifdef __minix  if (match(opt, "rprnt")) {	set_control(VREPRINT, next);	return 1;  }  if (match(opt, "lnext")) {	set_control(VLNEXT, next);	return 1;  }  if (match(opt, "flush")) {	set_control(VDISCARD, next);	return 1;  }#endif   if (match(opt, "min")) {	set_min_tim(VMIN, next);	return 1;  }  if (match(opt, "time")) {	set_min_tim(VTIME, next);	return 1;  }  /* Special modes. */  if (opt[0] == ':')  {	set_saved_settings(opt);	return 0;  }  if (match(opt, "cooked") || match(opt, "raw")) {	int x = opt[0] == 'c' ? 1 : 0;	option(x + "-icrnl", "");	/* off in raw mode, on in cooked mode */	option(x + "-ixon", "");	option(x + "-opost", "");	option(x + "-onlcr", "");	option(x + "-isig", "");	option(x + "-icanon", "");	option(x + "-iexten", "");	option(x + "-echo", "");	return 0;  }  if (match(opt, "evenp") || match(opt, "parity")) {	option("parenb", "");	option("cs7", "");	option("-parodd", "");	return 0;  }  if (match(opt, "oddp")) {	option("parenb", "");	option("cs7", "");	option("parodd", "");	return 0;  }  if (match(opt, "-parity") || match(opt, "-evenp") || match(opt, "-oddp")) {	option("-parenb", "");	option("cs8", "");	return 0;  }  if (match(opt, "nl")) {	option("icrnl", "");	return 0;  }  if (match(opt, "-nl")) {	option("-icrnl", "");	option("-inlcr", "");	option("-igncr", "");	return 0;  }  if (match(opt, "ek")) {	termios.c_cc[VERASE]= TERASE_DEF;;	termios.c_cc[VKILL]= TKILL_DEF;;	return 0;  }  if (match(opt, "sane"))  {	/* Reset all terminal attributes to a sane state, except line speed	 * and parity, because it can't be known what their sane values are.	 */	termios.c_iflag= (TINPUT_DEF & ~(IGNPAR|ISTRIP|INPCK))		| (termios.c_iflag & (IGNPAR|ISTRIP|INPCK));	termios.c_oflag= TOUTPUT_DEF;	termios.c_cflag= (TCTRL_DEF & ~(CLOCAL|CSIZE|CSTOPB|PARENB|PARODD))		| (termios.c_cflag & (CLOCAL|CSIZE|CSTOPB|PARENB|PARODD));	termios.c_lflag= TLOCAL_DEF;	if (termios.c_lflag & ICANON) {		termios.c_cc[VMIN]= TMIN_DEF;		termios.c_cc[VTIME]= TTIME_DEF;	}	termios.c_cc[VEOF]= TEOF_DEF;	termios.c_cc[VEOL]= TEOL_DEF;	termios.c_cc[VERASE]= TERASE_DEF;	termios.c_cc[VINTR]= TINTR_DEF;	termios.c_cc[VKILL]= TKILL_DEF;	termios.c_cc[VQUIT]= TQUIT_DEF;	termios.c_cc[VSUSP]= TSUSP_DEF;#ifdef __minix	termios.c_cc[VREPRINT]= TREPRINT_DEF;	termios.c_cc[VLNEXT]= TLNEXT_DEF;	termios.c_cc[VDISCARD]= TDISCARD_DEF;#endif	termios.c_cc[VSTART]= TSTART_DEF;	termios.c_cc[VSTOP]= TSTOP_DEF;	if (!(termios.c_lflag & ICANON)) {		termios.c_cc[VMIN]= TMIN_DEF;		termios.c_cc[VTIME]= TTIME_DEF;	}	return 0;  }#ifdef __minix  if (match(opt, "cols"))  {  	num= strtol(next, &check, 0);  	if (check[0] != '\0')  	{  		fprintf(stderr, "%s: illegal parameter to cols: '%s'\n",   							prog_name, next);  		return 1;  	}  	winsize.ws_col= num;	return 1;  }  if (match(opt, "rows"))  {  	num= strtol(next, &check, 0);  	if (check[0] != '\0')  	{  		fprintf(stderr, "%s: illegal parameter to rows: '%s'\n",   							prog_name, next);  		return 1;  	}  	winsize.ws_row= num;	return 1;  }#endif /* __minix */  fprintf(stderr, "%s: unknown mode: %s\n", prog_name, opt);  return 0;}int match(s1, s2)char *s1, *s2;{  while (1) {	if (*s1 == 0 && *s2 == 0) return(1);	if (*s1 == 0 || *s2 == 0) return (0);	if (*s1 != *s2) return (0);	s1++;	s2++;  }}void prctl(c)char c;{  if (c < ' ')	printf("^%c", 'A' + c - 1);  else if (c == 0177)	printf("^?");  else	printf("%c", c);}struct s2s {	speed_t ts;	long ns;} s2s[] = {	{ B0,		     0 },	{ B50,		    50 },	{ B75,		    75 },	{ B110,		   110 },	{ B134,		   134 },	{ B150,		   150 },	{ B200,		   200 },	{ B300,		   300 },	{ B600,		   600 },	{ B1200,	  1200 },	{ B1800,	  1800 },	{ B2400,	  2400 },	{ B4800,	  4800 },	{ B9600,	  9600 },	{ B19200,	 19200 },	{ B38400,	 38400 },#ifdef __minix	{ B57600,	 57600 },	{ B115200,	115200 },#endif};speed_t long2speed(num)long num;{	struct s2s *sp;	for (sp = s2s; sp < s2s + (sizeof(s2s) / sizeof(s2s[0])); sp++) {		if (sp->ns == num) return sp->ts;	}	return -1;}long speed2long(speed)unsigned long speed;{	struct s2s *sp;	for (sp = s2s; sp < s2s + (sizeof(s2s) / sizeof(s2s[0])); sp++) {		if (sp->ts == speed) return sp->ns;	}	return -1;}		void print_flags(flags, flag, def, string, all)unsigned long flags;unsigned long flag;unsigned long def;char *string;int all;{	if (!(flags & flag))	{		if (all || (def & flag))			output(string);		return;	}	string++;	if (all || !(def & flag))		output(string);}void output(s)char *s;{	int len;	len= strlen(s);	if (column + len + 3 >= max_column)	{		printf("\n");		column= 0;	}	if (column)	{		putchar(' ');		column++;	}	fputs(s, stdout);	column += len;}void do_print_char(chr, def, name, all)unsigned chr;unsigned def;char *name;int all;{	char line[20];	if (!all && chr == def)		return;	#ifdef _POSIX_VDISABLE	if (chr == _POSIX_VDISABLE)		sprintf(line, "%s = <undef>", name);	else#endif	if (chr < ' ')		sprintf(line, "%s = ^%c", name, chr + '@');	else if (chr == 127)		sprintf(line, "%s = ^?", name);	else		sprintf(line, "%s = %c", name, chr);	output(line);}void do_print_num(num, def, name, all)unsigned num;unsigned def;char *name;int all;{	char line[20];			if (!all && num == def)		return;	sprintf(line, "%s = %u", name, num);	output(line);}void set_saved_settings(opt)char *opt;{	long num;	char *check;	tcflag_t c_oflag, c_cflag, c_lflag, c_iflag;	cc_t c_cc[NCCS];	speed_t ispeed, ospeed;	int i;	check= opt;	num= strtol(check+1, &check, 16);	if (check[0] != ':')	{		fprintf(stderr, "error in saved settings '%s'\n", opt);		return;	}	c_iflag= num;	num= strtol(check+1, &check, 16);	if (check[0] != ':')	{		fprintf(stderr, "error in saved settings '%s'\n", opt);		return;	}	c_oflag= num;	num= strtol(check+1, &check, 16);	if (check[0] != ':')	{		fprintf(stderr, "error in saved settings '%s'\n", opt);		return;	}	c_cflag= num;	num= strtol(check+1, &check, 16);	if (check[0] != ':')	{		fprintf(stderr, "error in saved settings '%s'\n", opt);		return;	}	c_lflag= num;	num= strtol(check+1, &check, 16);	if (check[0] != ':')	{		fprintf(stderr, "error in saved settings '%s'\n", opt);		return;	}	ispeed= num;	num= strtol(check+1, &check, 16);	if (check[0] != ':')	{		fprintf(stderr, "error in saved settings '%s'\n", opt);		return;	}	ospeed= num;	for(i=0; i<NCCS; i++)	{		num= strtol(check+1, &check, 16);		if (check[0] != ':')		{			fprintf(stderr, "error in saved settings '%s'\n", opt);			return;		}		c_cc[i]= num;	}	if (check[1] != '\0')	{		fprintf(stderr, "error in saved settings '%s'\n", opt);		return;	}	termios.c_iflag= c_iflag;	termios.c_oflag= c_oflag;	termios.c_cflag= c_cflag;	termios.c_lflag= c_lflag;	cfsetispeed(&termios, ispeed);	cfsetospeed(&termios, ospeed);	for(i=0; i<NCCS; i++)		termios.c_cc[i]= c_cc[i];}void set_control(option, value)int option;char *value;{	int chr;	if (match(value, "undef") || match(value, "^-")) {#ifdef _POSIX_VDISABLE		chr= _POSIX_VDISABLE;#else		fprintf(stderr, 			"stty: unable to set option to _POSIX_VDISABLE\n");		return;#endif	} else if (match(value, "^?"))		chr= '\177';	else if (strlen(value) == 2 && value[0] == '^') {		chr= toupper(value[1]) - '@';		if (chr < 0 || chr >= 32) {			fprintf(stderr, "stty: illegal option value: '%s'\n",				value);			return;		}	} else if (strlen(value) == 1)		chr= value[0];	else {		fprintf(stderr, "stty: illegal option value: '%s'\n", value);		return;	}	assert(option >= 0 && option < NCCS);	termios.c_cc[option]= chr;}		void set_min_tim(option, value)int option;char *value;{	long num;	char *check;	num= strtol(value, &check, 0);	if (check[0] != '\0') {		fprintf(stderr, "stty: illegal option value: '%s'\n", value);		return;	}	if ((cc_t)num != num) {		fprintf(stderr, "stty: illegal option value: '%s'\n", value);		return;	}	assert(option >= 0 && option < NCCS);	termios.c_cc[option]= num;}/* * $PchHeader: /mount/hd2/minix/cmd/simple/RCS/stty.c,v 1.4 1995/05/23 08:23:16 philip Exp $ */

⌨️ 快捷键说明

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