示例#1
0
文件: tty.c 项目: DragonQuan/minix3
/*
 * nocbreak --
 *	Disable cbreak mode
 */
int
nocbreak(void)
{
#ifdef DEBUG
	__CTRACE(__CTRACE_MISC, "nocbreak()\n");
#endif
	/* Check if we need to restart ... */
	if (_cursesi_screen->endwin)
		__restartwin();

	__rawmode = 0;
	if (_cursesi_screen->notty == TRUE)
		return OK;
	  /* if we were in halfdelay mode then nuke the timeout */
	if ((_cursesi_screen->half_delay == TRUE) &&
	    (__notimeout() == ERR))
		return ERR;

	_cursesi_screen->half_delay = FALSE;
	_cursesi_screen->curt = _cursesi_screen->useraw ?
		&_cursesi_screen->rawt : &_cursesi_screen->baset;
	return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
			  TCSASOFT | TCSADRAIN : TCSADRAIN,
			  _cursesi_screen->curt) ? ERR : OK);
}
示例#2
0
文件: getch.c 项目: AgamAgarwal/minix
wchar_t
inkey(int to, int delay)
{
	wchar_t		 k;
	int              c, mapping;
	keymap_t	*current = _cursesi_screen->base_keymap;
	FILE            *infd = _cursesi_screen->infd;

	k = 0;		/* XXX gcc -Wuninitialized */

#ifdef DEBUG
	__CTRACE(__CTRACE_INPUT, "inkey (%d, %d)\n", to, delay);
#endif
	for (;;) {		/* loop until we get a complete key sequence */
reread:
		if (state == INKEY_NORM) {
			if (delay && __timeout(delay) == ERR)
				return ERR;
			c = fgetc(infd);
			if (c == EOF) {
				clearerr(infd);
				return ERR;
			}

			if (delay && (__notimeout() == ERR))
				return ERR;

			k = (wchar_t) c;
#ifdef DEBUG
			__CTRACE(__CTRACE_INPUT,
			    "inkey (state normal) got '%s'\n", unctrl(k));
#endif

			working = start;
			inbuf[working] = k;
			INC_POINTER(working);
			end = working;
			state = INKEY_ASSEMBLING;	/* go to the assembling
							 * state now */
		} else if (state == INKEY_BACKOUT) {
			k = inbuf[working];
			INC_POINTER(working);
			if (working == end) {	/* see if we have run
						 * out of keys in the
						 * backlog */

				/* if we have then switch to assembling */
				state = INKEY_ASSEMBLING;
			}
		} else if (state == INKEY_ASSEMBLING) {
			/* assembling a key sequence */
			if (delay) {
				if (__timeout(to ? (ESCDELAY / 100) : delay)
				    == ERR)
					return ERR;
			} else {
				if (to && (__timeout(ESCDELAY / 100) == ERR))
					return ERR;
			}

			c = fgetc(infd);
			if (ferror(infd)) {
				clearerr(infd);
				return ERR;
			}

			if ((to || delay) && (__notimeout() == ERR))
					return ERR;

#ifdef DEBUG
			__CTRACE(__CTRACE_INPUT,
			    "inkey (state assembling) got '%s'\n", unctrl(k));
#endif
			if (feof(infd) || c == -1) {	/* inter-char timeout,
							 * start backing out */
				clearerr(infd);
				if (start == end)
					/* no chars in the buffer, restart */
					goto reread;

				k = inbuf[start];
				state = INKEY_TIMEOUT;
			} else {
				k = (wchar_t) c;
				inbuf[working] = k;
				INC_POINTER(working);
				end = working;
			}
		} else {
			fprintf(stderr, "Inkey state screwed - exiting!!!");
			exit(2);
		}

		  /*
		   * Check key has no special meaning and we have not
		   * timed out and the key has not been disabled
		   */
		mapping = current->mapping[k];
		if (((state == INKEY_TIMEOUT) || (mapping < 0))
			|| ((current->key[mapping]->type == KEYMAP_LEAF)
			    && (current->key[mapping]->enable == FALSE))) {
			/* return the first key we know about */
			k = inbuf[start];

			INC_POINTER(start);
			working = start;

			if (start == end) {	/* only one char processed */
				state = INKEY_NORM;
			} else {/* otherwise we must have more than one char
				 * to backout */
				state = INKEY_BACKOUT;
			}
			return k;
		} else {	/* must be part of a multikey sequence */
			/* check for completed key sequence */
			if (current->key[current->mapping[k]]->type == KEYMAP_LEAF) {
				start = working;	/* eat the key sequence
							 * in inbuf */

				/* check if inbuf empty now */
				if (start == end) {
					/* if it is go back to normal */
					state = INKEY_NORM;
				} else {
					/* otherwise go to backout state */
					state = INKEY_BACKOUT;
				}

				/* return the symbol */
				return current->key[current->mapping[k]]->value.symbol;

			} else {
				/*
				 * Step on to next part of the multi-key
				 * sequence.
				 */
				current = current->key[current->mapping[k]]->value.next;
			}
		}
	}
}