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

📄 tty.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
#else  sun386	  if (running == GO)	    tty_message(inactivated_msg);	  else	  {	    window_type = OTHER_TTY;	    other_type = OTHER_EEPROM;	    (void)wclear(tty_other);	    eeprom_get_proc();	    tty_eeprom();		/* display the eeprom settings */	  }	  return;#endif	sun386	case 'f':			/* option files */	  if (running == GO)	    tty_message(inactivated_msg);	  else	  {	    window_type = OTHER_TTY;	    other_type = OTHER_OPFILE;	    (void)wclear(tty_other);	    tty_opfiles(TRUE);	  }	  return;        case 'c':                       /* test times */          if (running == GO)            tty_message(inactivated_msg);          else          {               window_type = OTHER_TTY;            other_type = OTHER_PROCESSORS;            (void)wclear(tty_other);            tty_processors();           /* display the processors enable menu */          }          return;	case 'i':			/* intervention enable/disable */	  interven_proc((Panel_item)0, !intervention, (Event *)0);	  return;	    	case 'l':			/* log files */	  if (running == GO)	    tty_message(inactivated_msg);	  else	  {	    window_type = OTHER_TTY;	    other_type = OTHER_LOGFILE;	    (void)wclear(tty_other);	    tty_log_files();	  }	  return;	case 'm':			/* test times */	  if (running == GO)	    tty_message(inactivated_msg);	  else	  {	    window_type = OTHER_TTY;	    other_type = OTHER_SCHEDULE;	    (void)wclear(tty_other);	    tty_schedule();		/* display the schedule menu */	  }	  return;        case 'n':			/* display next control window */	  if (control_max == 0)	  {	    tty_message("No next control screen!");	    return;	  }	  if (control_index == control_max)	    control_index = 0;	  else	    ++control_index;	  touchwin(tty_control[control_index]);	  (void)wrefresh(tty_control[control_index]);	  (void)refresh();		/* restore the cursor */	  return;	case 'o':			/* system options */	  if (running == GO)	    tty_message(inactivated_msg);	  else	  {	    window_type = OTHER_TTY;	    other_type = OTHER_OPTION;	    (void)wclear(tty_other);	    tty_options();		/* display the current options */	  }	  return;	case 'p':			/* suspend tests */	  suspend_proc();	  return;	case 'q':			/* quit sundiag */	  (void)kill_proc();		/* no return */	case 'r':	  reset_proc();			/* reset tests */	  return;	case 's':			/* start tests */	  start_proc();	  return;	case 't':	  stop_proc();			/* stop tests */	  return;	case 'u':			/* resume tests */	  resume_proc();	  return;	case 'h':			/* help */	  tty_help();	  return;	default:      	  tty_test_sel_proc(arg[0]);	  return;      }  }  else if (arg_no == 2)  {    switch (get_com(control_tbl2, arg[0]))    {	case 'c':			/* global test selection */	  switch (get_com(control_tbl3, arg[1]))	  {	    case 'd':	      select_proc((Panel_item)0, SEL_DEF, (Event *)0);	      return;	    case 'a':	      select_proc((Panel_item)0, SEL_ALL, (Event *)0);	      return;	    case 'n':	      select_proc((Panel_item)0, SEL_NON, (Event *)0);	      return;	    default:	      break;	  }	default:	  tty_test_opt_proc(arg[0], arg[1]);	  return;    }  }  tty_message(format_err);}/****************************************************************************** * proc_status_com(), processes status window command.			      * ******************************************************************************/static	proc_status_com()		/* process status window command */{  if (arg_no == 1)  {    switch (get_com(status_tbl, arg[0]))    {      case 'd':				/* go back to control window */	switch_to_control();	return;      case 'n':				/* display next status window */	if (status_max == 0)	{	  tty_message("No next status screen!");	  return;	}	if (status_index == status_max)	  status_index = 0;	else	  ++status_index;	touchwin(tty_status[status_index]);	(void)wrefresh(tty_status[status_index]);	(void)refresh();		/* restore the cursor */	return;      case 'h':				/* help */	tty_help();	return;      default:	break;    }  }  tty_message(com_err);}/****************************************************************************** * proc_option_com(), processes option window command.			      * ******************************************************************************/static	proc_option_com()		/* process option window command */{  if (arg_no == 1)    switch (get_com(popup_tbl, arg[0]))    {      case 'd':				/* go back to control window */	switch_to_control();	return;      case 'f':				/* default options */	option_default_proc((Panel_item)option_id);	/* process default */	(void)init_opt_panel(option_id);	/* redisplay the options */	return;      case 'h':				/* help */	tty_help();	return;      default:	break;    }  if (tty_test_option_proc())		/* process individual test option */    (void)init_opt_panel(option_id);	/* redisplay(update) the options */}/****************************************************************************** * proc_help_com(), processes help window command.			      * ******************************************************************************/static	proc_help_com()			/* process help window command */{}/****************************************************************************** * proc_other_com(), processes other window command.			      * ******************************************************************************/static	proc_other_com()		/* process other window command */{  switch (other_type)  {    case OTHER_OPTION:			/* handling "system options" */	tty_option_proc();	break;    case OTHER_OPFILE:			/* handling "option files" */	tty_opfile_proc();	break;    case OTHER_LOGFILE:			/* handling "log files" */	tty_logfile_proc();	break;    case OTHER_EEPROM:			/* handling "eeprom entries" */	tty_eeprom_proc();	break;    case OTHER_PROCESSORS:              /* handling "processors entries" */        tty_processors_proc();        break;    case OTHER_SCHEDULE:			/* handling "ttime entries" */	tty_schedule_proc();	break;  }}/****************************************************************************** * com_parser(), executes the user's command.				      * ******************************************************************************/com_parser(command)char	*command;			/* the command line */{  char	*ptr;  if (*command == '\0') return;	/* nothing in there */  arg_no = 0;  if ((ptr=strtok(command, " \t")) != NULL)  {    do      arg[arg_no++] = ptr;		/* parse out the tokens */    while ((ptr=strtok((char *)NULL, " \t")) != NULL && arg_no < 20);  }   switch (window_type)  {    case CONTROL_TTY:			/* control window is up */      proc_control_com();		/* process control window command */      break;    case STATUS_TTY:			/* status window is up */      proc_status_com();		/* process status window command */      break;    case OPTION_TTY:			/* option window is up */      proc_option_com();		/* process option window command */      break;    case HELP_TTY:			/* help window is up */      proc_help_com();			/* process help window command */      break;    case OTHER_TTY:			/* other windows is up */      proc_other_com();			/* process other window command */      break;  }}/****************************************************************************** * message_input(), the event handler for the "pipe" read data available.     * ******************************************************************************/Notify_value	message_input(){  char	temp_buf[82];  int	n;  n = read(pfd[0], temp_buf, 81);	/* read as much as we can */  if (n > 0)  {    temp_buf[n] = '\0';	/* NULL-terminated */    console_message(temp_buf);		/* display the message */  }  return(NOTIFY_DONE);}/****************************************************************************** * console_input(), the event handler for pseudo console data available.      * ******************************************************************************/Notify_value	console_input(){  char	temp_buf[82];  int	n;  n = read(pty_fd, temp_buf, 81);	/* read as much as we can */  if (n > 0)  {    temp_buf[n] = '\0';	/* NULL-terminated */    console_message(temp_buf);		/* display the message */  }  return(NOTIFY_DONE);}/****************************************************************************** * handle_input(), the event handler for the "stdin" input pending.	      * ******************************************************************************/#define	BEG_COMMAND	11		/* starting command line prompt */static	int	ind=BEG_COMMAND;	/* current command line column number */Notify_value	handle_input(){  char	ch;  int	i, j;  if ((ch=getch()) != ERR)  {    if (ind == BEG_COMMAND)		/* clear the last command */    {      move(command_row, ind-1);		/* get rid of possible garbage too */      clrtoeol();      mvaddch(command_row, COLS-1, '|');      move(message_row, BEG_MESSAGE);      if (inch() != ' ') tty_message((char *)NULL);      move(command_row, ind);    }    if (ch >= ' ' && ch <= '~' && ind < MIN_WIDTH-4)    {      ++ind;      addch(ch);    }    else if (ch == '\r')		/* Return key */    {      for (i=BEG_COMMAND, j=0; i != ind; ++i, ++j)      {	move(command_row, i);	com_line[j] = inch();		/* read them back from glass */      }      com_line[j] = '\0';		/* NULL-terminated */      ind = BEG_COMMAND;      move(command_row, ind);      com_parser(com_line);		/* execute the command */    }    else if (ch == del_char)		/* del-char key */    {      if (ind > BEG_COMMAND)      {	--ind;        move(command_row, ind);	addch(' ');	move(command_row, ind);      }    }    else if (ch == kill_char)		/* del-line key */    {      ind = BEG_COMMAND;      move(command_row, ind-1);		/* get rid of possible garbage too */      clrtoeol();      mvaddch(command_row, COLS-1, '|');      move(command_row, ind);    }    else if (ch == 0x0c)		/* ctrl-L, redisplay */      (void)wrefresh(curscr);		/* redraw the screen */    else if (ch == 0x18 || ch == -1)	/* ctrl-X(or ATS mode), background it */    {	ind = BEG_COMMAND;	puts(CL);	resetty();	unset_input_notify();		/* unregistered before closing */	(void)close(0);	/* redirect stdin, stdout, and stderr to /dev/null */	(void)open("/dev/null", O_RDWR);	(void)dup2(0, 1);	(void)dup2(0, 2);	(void)kill(tty_ppid, SIGTERM);	/* wake up shell */	tty_ppid = 0;	(void)signal(SIGHUP, SIG_IGN);	/* ignore SIGHUP */	return(NOTIFY_DONE);    }    (void)refresh();  }  return(NOTIFY_DONE);}/****************************************************************************** * tty_int_sel(), updates both "intervention:" and "test selection:".	      * ******************************************************************************/tty_int_sel(){  char	temp_buf[82];  (void)sprintf(temp_buf, "[INTERVENTION]: %-18s [TESTS]: %-20s", 	intervention?"Enable":"Disable",	select_value!=0?	(select_value>1?"ALL [DEFAULT/NONE]":"NONE [ALL/DEFAULT]"):	"DEFAULT [NONE/ALL]");  (void)mvwaddstr(control_button, 3, 6, temp_buf);  if (window_type == CONTROL_TTY)  {    (void)wrefresh(control_button);    (void)refresh();			/* restore cursor */  }}/****************************************************************************** * display_enable(), dispaly "->" for the specified enabled test.	      * * Input: test_id, the test number to be enabled.			      * *	  enable, TRUE, if to be enabled; FALSE, if to be disabled.	      * ******************************************************************************/display_enable(test_id, enable)int	test_id;int	enable;{  int	row;  int	page;  char	*temp;  row = (int)tests[test_id]->select & 0xff;  page = (int)tests[test_id]->select >> 8;  if (enable)    temp = "->";  else    temp = "  ";		/* erase the "->" mark */  (void)mvwaddstr(tty_control[page], row, TEST_COL, temp);  if (window_type == CONTROL_TTY && control_index == page)  {    (void)wrefresh(tty_control[page]);    (void)refresh();		/* restore cursor */  }}/****************************************************************************** * term_tty(), cleans up curses routine before exit. it restores the terminal * * to the state it was before initscr().				      * ******************************************************************************/term_tty(){  clear();				/* clear the screen before exit */  (void)refresh();  endwin();				/* restore terminal state */}/****************************************************************************** * restore_term_tty_state(), cleans up curses routine before exiting from an  * * abnormal condition. It restores the terminal (shelltool/cmdtool)           * * to the state it was before the initscr().                                  * ******************************************************************************/restore_term_tty_state(){  clear();                              /* clear the screen before exit */  scroll();                             /* scrolls 1 line for cmdtool */  endwin();                             /* restore terminal state */}

⌨️ 快捷键说明

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