rawchar.c

来自「Vxworks的培训教程,大家分享下啊,」· C语言 代码 · 共 73 行

C
73
字号
/* rawChar.c - read characters in raw mode */

#include "vxWorks.h"
#include "ioLib.h"

LOCAL int myOptions = OPT_TERMINAL;

/**************************************************
* rawOn -- Set raw mode on STD_IN.
*
* RETURNS: OK or ERROR on failure.
*/

STATUS rawOn ()
	{

	if (( myOptions = ioctl (STD_IN, FIOGETOPTIONS, 0)) == ERROR)
		return (ERROR);

	if ( ioctl (STD_IN, FIOSETOPTIONS, OPT_RAW) == ERROR)
		return (ERROR);
	
	return (OK);
	}

/**************************************************
* rawOff -- Restores previous mode on STD_IN.
*
* If no previous mode saved, sets mode to
* OPT_TERMINAL.
*
* RETURNS: OK or ERROR on failure.
*/

STATUS rawOff ()
	{
	if (ioctl (STD_IN, FIOSETOPTIONS, myOptions) == ERROR)
		return (ERROR);

	/*
	 * This is just to guard against successive calls
	 * to rawOff()
	 */
	
	myOptions = OPT_TERMINAL;

	return (OK);
	}

/**************************************************
* charGet -- Reads one character from STD_IN in raw
* mode.
*
* RETURNS: character read or ERROR on failure.
*/

int charGet (void)
	{
	int status;
	char c = 0;

	if (rawOn() == ERROR)
		return (ERROR);

	status = read (STD_IN, (char *) &c, 1);

	if (rawOff () == ERROR)
		return (ERROR);

	return ((status == ERROR) ? ERROR : c);
	}

⌨️ 快捷键说明

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