www.pudn.com > vxWorks_Lab.rar > rawChar.c


/* 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); 
	}