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

📄 ukey.c

📁 ICCP Toolkit 是在 Tru64下开发Tase.2通信协议的开发包
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************************************//* SISCO SOFTWARE MODULE HEADER *****************************************//************************************************************************//*   (c) Copyright Systems Integration Specialists Company, Inc.,	*//*              1986-2002 All Rights Reserved             		*//*									*//* MODULE NAME : ukey.c 						*//* PRODUCT(S)  : MMSEASE						*//*									*//* MODULE DESCRIPTION : 						*//* This module contains function key handling functions.		*//* and other misc. It should be used when working in the		*//* UNIX environment in place of 'fkey.c' or 'nkey.c'.                   *//*									*//* GLOBAL FUNCTIONS DEFINED IN THIS MODULE :				*//*									*//* MODIFICATION LOG :							*//*  Date     Who   Rev			Comments			*//* --------  ---  ------   -------------------------------------------	*//* 08/22/02  EJV     09    SYS_5: rem ISIG in term_init (blocks CTRL-C)	*//* 05/16/01  EJV     08    SYS_5: changed term_init, term_end to POSIX	*//*			   compatible (old didn't work on Tru64 csh).	*//* 08/28/98  EJV     07    Renamed functions echo to set_echo_on	*//*			                   noecho to set_echo_off.	*//* 05/22/98  EJV     06    Moved strnicmp,strcmpi,stricmp to cfg_util.c	*//* 02/27/98  EJV     05    Replaced faulty strcmpi func (strings were	*//*			   compared for len of smaller str only!).	*//* 01/26/98  EJV     04    Moved #... to beginning of line -Digital UNIX*//* 01/22/98  NAV     03    Added menu key functionality			*//* 05/27/97  DSF     02    No need to include suicacse.h		*//* 05/22/97  RKR     01    Changed the way select is called in kbhit	*//* 04/02/97  DTL   7.00    MMSEASE 7.0 release. See MODL70.DOC for	*//*			   history.					*//************************************************************************/#include "glbtypes.h"#ifndef PSOS_SYSTEM#include <stdio.h>#include <ctype.h>#endif#if defined(__alpha)#include <sys/time.h>#endif#if (SYSTEM_SEL & (QNX_C86))#include <dev.h>#include <io.h>#else#if (SYSTEM_SEL & SYSVXWORKS)#include <tyLib.h>#include <ioLib.h>#include <selectLib.h>extern int vxfd;		/* See mmsapp.c	*/#else	/* !SYSVXWORKS	*/#ifndef PSOS_SYSTEM#include <termio.h>#endif#endif	/* !SYSVXWORKS	*/#endif#if (SYSTEM_SEL & (SYS_QNX4 | NEW_SYSTEM | SYS_5))	/* POSIX compatible	*/#if defined (__hpux)#include <termio.h>#include <sys/termios.h>#else#include <termios.h>#include <sys/select.h>#endif#include <errno.h>struct termios save_settings;#endif	/* (SYS_QNX4 | NEW_SYSTEM | SYS_5)	*/#include "sysincs.h"#include "fkeydefs.h"#include "scrndefs.h"#ifdef PSOS_SYSTEMextern char LastKeyHit;  /* This is the last key that cam into the system */extern short AKeyWasHit;  /* This is the flag that say's that something happned */extern short EchoFlag; /* To echo the data on the terminal */extern unsigned long *TasksInSystemID;extern short NetReadDataPresent; /* This is a flag that say's that there is net data */#include <ctype.h>#endifstatic ST_INT nlfn (ST_VOID);ST_VOID bad_key(ST_VOID);ST_VOID fun_exe(ST_INT);int     kbhit(ST_VOID);ST_CHAR	getkch();static	ST_CHAR console_char = 0x00;ST_VOID (*funct_1) ();ST_VOID (*funct_2) ();ST_VOID (*funct_3) ();ST_VOID (*funct_4) ();ST_VOID (*funct_5) ();ST_VOID (*funct_6) ();ST_VOID (*funct_7) ();ST_VOID (*funct_8) ();ST_VOID (*funct_9) ();ST_VOID (*funct_10) ();ST_VOID (*funct_menu) ();/*************************************************************************//* A table of function pointers is used to select the actionperformed when a function key is pressed. The fun_exe () routineselects the function based on the key code. The fun_null can beused to set all fuunction key pointers to the "Illegal Key"display function. */#define F1  0x31	   /* 1 */#define F2  0x32	   /* 2 */#define F3  0x33	   /* 3 */#define F4  0x34	   /* 4 */#define F5  0x35	   /* 5 */#define F6  0x36	   /* 6 */#define F7  0x37	   /* 7 */#define F8  0x38	   /* 8 */#define F9  0x39	   /* 9 */#define F10 0x30	   /* 0 */#define MENU_KEY	0x1B	/* the escape key	*//************************************************************************//*			nlfn						*//* function to just return.  Used when need to set service routine to	*//* a dummy function							*//************************************************************************/static ST_INT nlfn (ST_VOID){  return(0);}ST_INT (*servefun)() = nlfn;/************************************************************************//*			wait_debug_log					*//************************************************************************/#ifdef UTIL_LIBST_VOID wait_debug_log (fptr,str)FILE *fptr;ST_CHAR *str;  {  fprintf (fptr,"\n %s",str);  fflush(fptr);  }#else	/* !UTIL_LIB	*/ST_VOID wait_debug_log (fptr,str)FILE *fptr;ST_CHAR *str;  {  flush_keys ();  fprintf (fptr,"\n %s",str);  fflush(fptr);  if (fptr == stdout)    {    while (!kbhit())      (*servefun) ();			/* execute background task	*/    }  flush_keys ();  }#endif	/* !UTIL_LIB	*//****************************************************************************//*                           log_hex_bytes				    *//* This function provides a hex dump facility.				    *//****************************************************************************/#define cvt_nibble(a)		((a) > 9 ? (a) + 'A' - 10 : (a) + '0')#define DEBUG_BUF_LEN 100ST_VOID log_hex_bytes (FILE *dest, ST_UCHAR *ptr, ST_INT len)                                /* pointer to hex data */                                           /* length of data */{                  register ST_INT i;  register ST_INT ascii_index;register ST_INT hex_index;ST_CHAR debug_buf[DEBUG_BUF_LEN+1]; /* output buffer			*/ST_INT curlen;ST_CHAR ch;ST_UCHAR hex;ST_INT addr = 0;  /* format hex data							*/  while (len)    {    curlen = min(len,16); 		/* # char's in current line	*/    sprintf (debug_buf," %04X  ",addr);	/* data offset 			*/    hex_index = 7;			/* where to put hex data 	*/    ascii_index = 58;			/* where to put ascii conversion */    debug_buf[ascii_index++] = '*';    for (i = 0; i < DEBUG_BUF_LEN; ++i)      debug_buf[i] = ' ';    fprintf (dest,"%s","\n");    for (i = 0; i < curlen; i++)	/* for each byte in this line	*/			    	      {	  		    		      ch = *ptr++;  			/* get next character		*/      hex = (ch >> 4) & 0x0f;		/* write HEX chars for the byte	*/      hex = cvt_nibble(hex);      debug_buf[hex_index++] = hex;      hex = ch & 0x0f;      hex = cvt_nibble(hex);      debug_buf[hex_index++] = hex;      debug_buf[hex_index++] = ' ';      if (isprint(ch))			/* print ASCII portion		*/        debug_buf[ascii_index] = ch;      else        debug_buf[ascii_index] = '.';	/* just put a '.' there 	*/      ascii_index++;      if (i == 7)			/* half way through line	*/        debug_buf[hex_index++] = ' ';   /* put an extra space here 	*/      } 				/* end of line			*/    debug_buf[ascii_index++] = '*';    debug_buf[ascii_index++] = 0;    for (i = hex_index; i < 58; i++)      debug_buf[i] = ' ';  /* clear the buffer between hex and ascii data */					/* write out the line		*/    fprintf (dest,"%s",debug_buf);    addr += 16;				/* prepare for next line	*/    len -= curlen;    }  }/************************************************************************//*				term_init				*//*  This function must be called before calling kbhit.	It initializes	*//*  the terminal to do raw types of input without having any of it	*//*  buffered.								*//************************************************************************/#if (SYSTEM_SEL & (QNX_C86))int	term_init (){	int option_save;		if ((option_save = get_option (stdin))  ==  -1)		perror( "\nterm_init: Couldn't get the terminal characteristics" );	else		{		if (set_option (stdin, option_save & (~(ECHO|EDIT)))  ==  -1)			perror( "\nterm_init: Couldn't set the terminal for Raw input" );		}	return (option_save);}#endif	/* QNX_C86	*/#if (SYSTEM_SEL & SYSVXWORKS)ST_VOID	term_init ()  {  if (ioctl( 0, FIOSETOPTIONS, OPT_RAW | OPT_ABORT | OPT_CRMOD) )    perror( "\nterm_init: Couldn't set the terminal characteristics" );  }#endif	/* SYSVXWORKS	*/#if (SYSTEM_SEL & (SYS_QNX4 | SYS_5 | NEW_SYSTEM))	/* POSIX Compatible	*/ST_VOID	term_init(){struct	termios	new_settings;  if (tcgetattr (0, &save_settings) == -1)    perror( "\nterm_init: Couldn't get the terminal characteristics" );  else    {    memcpy (&new_settings, &save_settings, sizeof (struct termios));    new_settings.c_cc[VMIN]=1;    new_settings.c_cc[VTIME]=0;    new_settings.c_lflag &= ~(ECHO|ICANON|ECHOE|ECHOK);    if (tcsetattr (0, TCSADRAIN, &new_settings) == -1)      perror( "\nterm_init: Couldn't set the terminal for Raw input" );    }  return;}#endif	/* (SYS_QNX4 | SYS_5 | NEW_SYSTEM)	*/#if 0 /* was (SYSTEM_SEL & (SYS_5) ) *//* NOTE: This code was not working properly on Tru64 csh */ST_VOID	term_init( save_ptr )struct	termio	*save_ptr;{struct	termio	terminal_control_block;struct	termio	*arg;  arg = &terminal_control_block;  if (ioctl( 0, TCGETA, save_ptr ) )    perror( "\nterm_init: Couldn't get the terminal characteristics" );  else    {    *arg = *save_ptr;    arg->c_lflag &= ~ICANON;		/* get rid of buffering input	*/    arg->c_cc[VTIME] = 0;		/* time out immediatedly	*/    arg->c_cc[VMIN]  = 0;		/* set a 0 character minimum	*/    if ( ioctl( 0, TCSETA, arg ) )      perror( "\nterm_init: Couldn't set the terminal for Raw input" );    }}#endif	/* SYS_5	*//************************************************************************//*				term_rest				*//*  This function must be called at the end of a program if term_init	*//*  has been called.  A rest of the terminal to it's state pointed to   *//*  by save_ptr will be done.						*//************************************************************************/#if (SYSTEM_SEL & (QNX_C86))ST_VOID	term_rest (option_save)int		option_save;{	if (set_option (stdin, option_save)  ==  -1)		perror( "\nterm_rest: Couldn't reset the terminal attributes." );}#endif	/* QNX_C86	*/#if (SYSTEM_SEL & SYSVXWORKS)ST_VOID	term_rest ()  {  if (ioctl( 0, FIOSETOPTIONS, OPT_TERMINAL) )    perror( "\nterm_rest: Couldn't reset the terminal characteristics" );  }#endif	/* SYSVXWORKS	*/#if (SYSTEM_SEL & (SYS_5 | SYS_QNX4 | NEW_SYSTEM))	/* POSIX Compatible	*/ST_VOID	term_rest ()  {  if (tcsetattr (0, TCSADRAIN, &save_settings) == -1)    perror( "\nterm_rest: Couldn't reset the terminal characteristics" );  }#endif	/* (SYS_5 | SYS_QNX4 | NEW_SYSTEM)	*/#if 0 /* was (SYSTEM_SEL & (SYS_5) ) *//* NOTE: This code was not working properly on Tru64 csh */ST_VOID	term_rest( save_ptr )struct	termio	*save_ptr;{  if ( ioctl( 0, TCSETA, save_ptr ) )    perror( "\nThis terminal is hosed." );}#endif	/* SYS_5	*/#ifdef PSOS_SYSTEM/************************************************************************//*				kbhit					*//************************************************************************/int  	kbhit(ST_VOID)  {  int ReturnCode = 0;  if (AKeyWasHit == 1)    {    console_char = LastKeyHit;    ReturnCode = 1;    }  return (ReturnCode);    }#else/************************************************************************//*				kbhit					*//************************************************************************/int  	kbhit(ST_VOID){int	i;ST_CHAR	ret_char;#if (SYSTEM_SEL & (SYSVXWORKS | SYS_QNX4 | NEW_SYSTEM | SYS_5))  fd_set readfds;  fd_set writefds;  fd_set exceptfds;  int nfds;    struct timeval stTimeVal;#endif  fflush( stdout );#if (SYSTEM_SEL & (QNX_C86))  if (char_waiting (stdin))		/* if a key has been hit */    i = read (0, &ret_char, 1);  else    i = 0;  if ( i )    {    console_char = ret_char;    return( SD_TRUE );    }  else    {    return( SD_FALSE );    }#else#if (SYSTEM_SEL & (SYSVXWORKS | SYS_QNX4 | NEW_SYSTEM | SYS_5))  /* Must do select before read or you'll get blocked.  */  FD_ZERO(&readfds);  FD_ZERO(&writefds);  FD_ZERO(&exceptfds);  FD_SET(0 , &readfds);		/* just do select on "stdin"	*/  stTimeVal.tv_sec  = 0;    /*** wait for 0 second ***/  stTimeVal.tv_usec = 0;  errno=0;  nfds=select(FD_SETSIZE,&readfds,&writefds,&exceptfds,&stTimeVal);  if (nfds <= 0)    return (SD_FALSE); /* nothing to read.     */  else    return (SD_TRUE);  /* got something        */#endif	/* SYSVXWORKS | SYS_QNX4 | NEW_SYSTEMi | SYS_5*/#endif}#endif/************************************************************************//* Functions unused by the MMS provider.                                *//************************************************************************/#ifndef UTIL_LIB/**************************************************************************/

⌨️ 快捷键说明

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