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

📄 ukey.c

📁 ICCP Toolkit 是在 Tru64下开发Tase.2通信协议的开发包
💻 C
📖 第 1 页 / 共 2 页
字号:
/* check_key - function to check for local command pending, execute if so.*//**************************************************************************//* Check for key pressed, if not just return.				  *//* If so, check to see if function key, if not: illegal key.		  *//* If function key, execute the function.					  */ST_INT check_key ()  {ST_INT key;		     /* key gets character code 		  */  if (kbhit())			/* Key Pressed ?			*/    {#ifdef PSOS_SYSTEM    key = (ST_INT) get_a_char();#else    key = (ST_INT) getchar();#endif    if (key == MENU_KEY)      {      if (funct_menu)        (*funct_menu) ();	/* may be used to refresh menu screen	*/      return (0);      }    else if (key < 0x30 || key > 0x39)	/* check for 1-10		*/      {      return (0);			/* ret if not			*/      }    else      {      if (key == 0x30)	return (1);      else	{	fun_exe (key);	return (0);	}      }    }  else    {    return (0);    }  }/**************************************************************************//* Function to make all function keys illegal				  *//**************************************************************************/ST_VOID fun_null (){  funct_1  = bad_key;  funct_2  = bad_key;  funct_3  = bad_key;  funct_4  = bad_key;  funct_5  = bad_key;  funct_6  = bad_key;  funct_7  = bad_key;  funct_8  = bad_key;  funct_9  = bad_key;  funct_10 = bad_key;  }/**************************************************************************//* Illegal Key routine							  *//* Need to Beep Here							  *//**************************************************************************/ST_VOID bad_key ()  {  flush_keys ();  ; /* just ignore for now */  }/**************************************************************************//* Message display and wait function, used to display error messages	  *//**************************************************************************/#define DELAY_COUNT 32000ST_VOID key_err (msg)ST_CHAR msg [];  {ST_INT i;  CLEARSCR;  printf ("\n\n\n\n\n");  printf ("%s",msg);#ifdef PSOS_SYSTEM    t_suspend(0);#else  for (i = 0; i < DELAY_COUNT; ++i)	/* just delay here		  */    ;  for (i = 0; i < DELAY_COUNT; ++i)	/* just delay here		  */    ;#endif    }/************************************************************************//* Function to display a message and wait for a key hit 		*/ST_VOID wait_msg (str)ST_CHAR *str;  {#ifndef PSOS_SYSTEM  flush_keys ();  printf ("\n %s",str);  while (!kbhit())    (*servefun) ();			/* execute background task	*/  flush_keys ();#else  flush_keys ();  printf ("\n %s",str);  t_suspend(0);#endif  }ST_VOID wait_key ()  {#ifdef PSOS_SYSTEM  t_suspend(0);#else  while (!kbhit())    (*servefun) ();			/* execute background task	*/#endif  }/**************************************************************************//*	    Function Key Function Select Routine			  *//* Select the key function by using the function pointer		  *//**************************************************************************/ST_VOID fun_exe (ST_INT key)   /* key code is passed to this routine        */  {			  /* This must be the second ST_CHAR key sequence */  switch (key)     {     case 0x31: 	  /* F1 */       (*funct_1) ();     break;     case 0x32: 	  /* F2 */       (*funct_2) ();     break;     case 0x33: 	  /* F3 */       (*funct_3) ();     break;     case 0x34: 	  /* F4 */       (*funct_4) ();     break;     case 0x35: 	  /* F5 */       (*funct_5) ();     break;     case 0x36: 	  /* F6 */       (*funct_6) ();     break;     case 0x37: 	  /* F7 */       (*funct_7) ();     break;     case 0x38: 	  /* F8 */       (*funct_8) ();     break;     case 0x39: 	  /* F9 */	(*funct_9) ();     break;     case 0x30: 	 /* F10 */       (*funct_10) ();     break;     default:		 /* Not a Function Key */       bad_key ();     break;     }  }/************************************************************************//*				getkch					*//************************************************************************/ST_CHAR	getkch(ST_VOID){  return( console_char );}/************************************************************************//*				get_a_char				*//************************************************************************/#ifdef PSOS_SYSTEMST_CHAR	get_a_char()  {  if (AKeyWasHit == 0)    {    /* Put Me to Sleep for some time */    t_suspend(TasksInSystemID[0]);    }  if (AKeyWasHit == 1)    {    console_char = LastKeyHit;    AKeyWasHit = 0;    }      return( console_char );}#elseST_CHAR	get_a_char(){  while(!kbhit());  console_char = (ST_CHAR) getchar();  return( console_char );}#endif/*************************************************************************//* Function to flush the keyboard character buffer			 */ST_VOID flush_keys ()  {#ifdef PSOS_SYSTEM  AKeyWasHit = 0;  console_char = 0x00;  LastKeyHit = 0x00;#else  while (kbhit()) /* this gets all pending characters & trashs them */    get_a_char();  return;#endif  }/************************************************************************//*				set_echo_on				*//************************************************************************/#if (SYSTEM_SEL & (QNX_C86))ST_VOID	set_echo_on (ST_VOID){	int option_save;		if ((option_save = get_option (stdin))  ==  -1)		perror( "\nset_echo_on: Couldn't get the terminal characteristics" );	else		{		if (set_option (stdin, option_save | ECHO)  ==  -1)			perror( "\nset_echo_on: Couldn't set the terminal for echo" );		}}#elseST_VOID	set_echo_on (ST_VOID){#if !(SYSTEM_SEL & (SYSVXWORKS | SYS_QNX4 | NEW_SYSTEM))#ifndef PSOS_SYSTEMstatic struct	termio	terminal_control_block;static struct	termio	*arg;  arg = &terminal_control_block;  if (ioctl( 0, TCGETA, arg ) )    perror( "\nset_echo_on: Couldn't get the terminal characteristics" );  else    {    arg->c_lflag |= ECHO;		/* enable echo			*/    if ( ioctl( 0, TCSETA, arg ) )      perror( "\nset_echo_on: Couldn't set the terminal for echo" );    }#endif   /* Not PSOS System */#endif	/* !SYSVXWORKS	*/}#endif/************************************************************************//*				set_echo_off				*//************************************************************************/#if (SYSTEM_SEL & (QNX_C86))ST_VOID	set_echo_off (ST_VOID){	int option_save;		if ((option_save = get_option (stdin))  ==  -1)		perror( "\nset_echo_off: Couldn't get the terminal characteristics" );	else		{		if (set_option (stdin, option_save & (~ECHO))  ==  -1)			perror( "\nset_echo_off: Couldn't set the terminal for noecho" );		}}#elseST_VOID	set_echo_off (ST_VOID){#if !(SYSTEM_SEL & (SYSVXWORKS | SYS_QNX4 | NEW_SYSTEM))#ifndef PSOS_SYSTEMstatic struct	termio	terminal_control_block;static struct	termio	*arg;  arg = &terminal_control_block;  if (ioctl( 0, TCGETA, arg ) )    perror( "\nset_echo_off: Couldn't get the terminal characteristics" );  else    {    arg->c_lflag &= ~ECHO;		/* disable the echo bit 	*/    if ( ioctl( 0, TCSETA, arg ) )      perror( "\nset_echo_off: Couldn't set the terminal for noecho" );    }#endif  /* PSOS System */#endif	/* !SYSVXWORKS	*/}#endifST_VOID list_bytes (ST_UCHAR *ptr, ST_INT len)  {  while (len)    {    printf (" %02X",*(ptr++) &0xff);    len--;    }  }/************************************************************************//*			list_ascii					*//************************************************************************/ST_VOID list_ascii (ST_CHAR *ptr, ST_INT len)  {  while (len)    {    printf ("%c",*(ptr++) );    len--;    }  }/************************************************************************//*			ask						*//* Ask a yes/no question and return the answer. 			*//************************************************************************/ST_VOID  strget (char *);ST_BOOLEAN ask (ST_CHAR *question, ST_BOOLEAN default_ans)  {ST_CHAR  ans [100];ST_INT	ret_ans;  printf ("%s", question);  flush_keys ();  ans [0] = '?';  strget (ans);  if (ans [0] == 'n' || ans [0] == 'N')    ret_ans = 0;  else    {    if (ans [0] == 'y' || ans [0] == 'Y')      ret_ans = 1;    else      ret_ans = default_ans;    }  return (ret_ans);  }/**************************************************************************//* Function to execute function key table until F10 is pressed. 	  *//**************************************************************************/ST_VOID do_fun (ST_VOID)  {ST_INT key;if (SD_TRUE) return;  for (;;)    {#ifdef PSOS_SYSTEM    key = (ST_INT) get_a_char();#else    key = (ST_INT) getchar();#endif    if (key)				/* function keys start with 0	  */      bad_key ();			/* Error if not function key	  */    else      {#ifndef PSOS_SYSTEM      key = (ST_INT) getchar();#else      key = (ST_INT) get_a_char();#endif      if (key != F10)    	fun_exe (key);			/* Execute function key 	  */      else	return;      }    }  }/************************************************************************/ST_VOID list_words (ST_UINT *ptr, ST_INT len)  {  while (len)    {    printf (" %04X",*(ptr++));    len--;    }  }#else	/* UTIL_LIB	*/ST_VOID wait_msg (str)ST_CHAR *str;  {  printf ("\n %s",str);  }#endif	/* UTIL_LIB	*/

⌨️ 快捷键说明

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