<commit_before>/************************************************************************ 
 * This file is part of PDCurses. PDCurses is public domain software;	*
 * you may use it for any purpose. This software is provided AS IS with	*
 * NO WARRANTY whatsoever.						*
 *									*
 * If you use PDCurses in an application, an acknowledgement would be	*
 * appreciated, but is not mandatory. If you make corrections or	*
 * enhancements to PDCurses, please forward them to the current		*
 * maintainer for the benefit of other users.				*
 *									*
 * See the file maintain.er for details of the current maintainer.	*
 ************************************************************************/

#include <curspriv.h>

#define _INBUFSIZ	512	/* size of terminal input buffer */
#define NUNGETCH	256	/* max # chars to ungetch() */

RCSID("$Id: getch.c,v 1.41 2006/10/23 05:03:30 wmcbrine Exp $");

static int c_pindex = 0;	/* putter index */
static int c_gindex = 1;	/* getter index */
static int c_ungind = 0;	/* wungetch() push index */
static int c_ungch[NUNGETCH];	/* array of ungotten chars */

/*man-start**************************************************************

  Name:                                                         getch

  Synopsis:
	int getch(void);
	int wgetch(WINDOW *win);
	int mvgetch(int y, int x);
	int mvwgetch(WINDOW *win, int y, int x);
	int ungetch(int ch);
	int flushinp(void);

	int PDC_get_key_modifiers(void);

  X/Open Description:
	With the getch(), wgetch(), mvgetch(), and mvwgetch() functions, 
	a character is read from the terminal associated with the window. 
	In nodelay mode, if there is no input waiting, the value ERR is 
	returned. In delay mode, the program will hang until the system 
	passes text through to the program. Depending on the setting of 
	cbreak(), this will be after one character or after the first 
	newline.  Unless noecho() has been set, the character will also 
	be echoed into the designated window.

	If keypad() is TRUE, and a function key is pressed, the token for
	that function key will be returned instead of the raw characters.
	Possible function keys are defined in <curses.h> with integers
	beginning with 0401, whose names begin with KEY_.  If a character
	is received that could be the beginning of a function key (such as
	escape), curses will set a timer.  If the remainder of the sequence
	does not come in within the designated time, the character will be
	passed through, otherwise the function key value will be returned.
	For this reason, on many terminals, there will be a delay after a
	user presses the escape key before the escape is returned to the
	program.  (Use by a programmer of the escape key for a single
	character function is discouraged.)

	If nodelay(win,TRUE) has been called on the window and no input
	is waiting, the value ERR is returned.

	The ungetch() function places ch back onto the input queue to be
	returned by the next call to wgetch().

	The flushinp() routine throws away any type-ahead that has been
	typed by the user and has not yet been read by the program.

	NOTE: getch() and ungetch() are implemented as macros.

  PDCurses Description:
	Given the nature of the PC, there is no such timer set for an
	incoming ESCAPE value, because function keys generate unique
	scan codes that are not prefixed with the ESCAPE character.

	Also, note that the getch() definition will conflict with
	many DOS compiler's runtime libraries.

	PDC_get_key_modifiers() returns the keyboard modifiers effective 
	at the time of the last getch() call, only if 
	PDC_save_key_modifiers(TRUE) has been called before the getch(). 
	Use the macros; PDC_KEY_MODIFIER_* to determine which 
	modifier(s) were set.

  X/Open Return Value:
	These functions return ERR or the value of the character, meta 
	character or function key token.

  Portability				     X/Open    BSD    SYS V
	getch					Y	Y	Y
	wgetch					Y	Y	Y
	mvgetch					Y	Y	Y
	mvwgetch				Y	Y	Y
	ungetch					Y	Y	Y
	PDC_get_key_modifiers			-	-	-

**man-end****************************************************************/

WINDOW *pdc_getch_win = NULL;

/* _breakout() - Check if input is pending, either directly from the
   keyboard, or previously buffered. */

static bool _breakout(void)<commit_msg>Portability chart for flushinp() belongs here now.<commit_after>/************************************************************************ 
 * This file is part of PDCurses. PDCurses is public domain software;	*
 * you may use it for any purpose. This software is provided AS IS with	*
 * NO WARRANTY whatsoever.						*
 *									*
 * If you use PDCurses in an application, an acknowledgement would be	*
 * appreciated, but is not mandatory. If you make corrections or	*
 * enhancements to PDCurses, please forward them to the current		*
 * maintainer for the benefit of other users.				*
 *									*
 * See the file maintain.er for details of the current maintainer.	*
 ************************************************************************/

#include <curspriv.h>

#define _INBUFSIZ	512	/* size of terminal input buffer */
#define NUNGETCH	256	/* max # chars to ungetch() */

RCSID("$Id: getch.c,v 1.42 2006/10/23 05:47:34 wmcbrine Exp $");

static int c_pindex = 0;	/* putter index */
static int c_gindex = 1;	/* getter index */
static int c_ungind = 0;	/* wungetch() push index */
static int c_ungch[NUNGETCH];	/* array of ungotten chars */

/*man-start**************************************************************

  Name:                                                         getch

  Synopsis:
	int getch(void);
	int wgetch(WINDOW *win);
	int mvgetch(int y, int x);
	int mvwgetch(WINDOW *win, int y, int x);
	int ungetch(int ch);
	int flushinp(void);

	int PDC_get_key_modifiers(void);

  X/Open Description:
	With the getch(), wgetch(), mvgetch(), and mvwgetch() functions, 
	a character is read from the terminal associated with the window. 
	In nodelay mode, if there is no input waiting, the value ERR is 
	returned. In delay mode, the program will hang until the system 
	passes text through to the program. Depending on the setting of 
	cbreak(), this will be after one character or after the first 
	newline.  Unless noecho() has been set, the character will also 
	be echoed into the designated window.

	If keypad() is TRUE, and a function key is pressed, the token for
	that function key will be returned instead of the raw characters.
	Possible function keys are defined in <curses.h> with integers
	beginning with 0401, whose names begin with KEY_.  If a character
	is received that could be the beginning of a function key (such as
	escape), curses will set a timer.  If the remainder of the sequence
	does not come in within the designated time, the character will be
	passed through, otherwise the function key value will be returned.
	For this reason, on many terminals, there will be a delay after a
	user presses the escape key before the escape is returned to the
	program.  (Use by a programmer of the escape key for a single
	character function is discouraged.)

	If nodelay(win,TRUE) has been called on the window and no input
	is waiting, the value ERR is returned.

	The ungetch() function places ch back onto the input queue to be
	returned by the next call to wgetch().

	The flushinp() routine throws away any type-ahead that has been
	typed by the user and has not yet been read by the program.

	NOTE: getch() and ungetch() are implemented as macros.

  PDCurses Description:
	Given the nature of the PC, there is no such timer set for an
	incoming ESCAPE value, because function keys generate unique
	scan codes that are not prefixed with the ESCAPE character.

	Also, note that the getch() definition will conflict with
	many DOS compiler's runtime libraries.

	PDC_get_key_modifiers() returns the keyboard modifiers effective 
	at the time of the last getch() call, only if 
	PDC_save_key_modifiers(TRUE) has been called before the getch(). 
	Use the macros; PDC_KEY_MODIFIER_* to determine which 
	modifier(s) were set.

  X/Open Return Value:
	These functions return ERR or the value of the character, meta 
	character or function key token.

  Portability				     X/Open    BSD    SYS V
	getch					Y	Y	Y
	wgetch					Y	Y	Y
	mvgetch					Y	Y	Y
	mvwgetch				Y	Y	Y
	ungetch					Y	Y	Y
	flushinp				Y	Y	Y
	PDC_get_key_modifiers			-	-	-

**man-end****************************************************************/

WINDOW *pdc_getch_win = NULL;

/* _breakout() - Check if input is pending, either directly from the
   keyboard, or previously buffered. */

static bool _breakout(void)
{'fraction_non_alphanumeric': 0.12098276665114113, 'fraction_numerical': 0.0069864927806241265, 'mean_word_length': 3.607832618025751, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2080092', 'n_tokens_mistral': 2693, 'n_tokens_neox': 2433, 'n_words': 1177}