missing ncurses sources
[tomato.git] / release / src / router / libncurses / ncurses / base / lib_ungetch.c
blob63a14cff7594b0fbcbf612eb24fae6e0658c7361
1 /****************************************************************************
2 * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. *
3 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
11 * *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
14 * *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
22 * *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
26 * authorization. *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 * and: Thomas E. Dickey 1996-on *
33 * and: Juergen Pfeifer 2009 *
34 ****************************************************************************/
37 ** lib_ungetch.c
39 ** The routine ungetch().
43 #include <curses.priv.h>
45 MODULE_ID("$Id: lib_ungetch.c,v 1.14 2009/10/24 22:12:21 tom Exp $")
47 #include <fifo_defs.h>
49 #ifdef TRACE
50 NCURSES_EXPORT(void)
51 _nc_fifo_dump(SCREEN *sp)
53 int i;
54 T(("head = %d, tail = %d, peek = %d", head, tail, peek));
55 for (i = 0; i < 10; i++)
56 T(("char %d = %s", i, _nc_tracechar(sp, sp->_fifo[i])));
58 #endif /* TRACE */
60 NCURSES_EXPORT(int)
61 safe_ungetch(SCREEN *sp, int ch)
63 int rc = ERR;
65 T((T_CALLED("ungetch(%p,%s)"), (void *) sp, _nc_tracechar(sp, ch)));
67 if (tail != -1) {
68 if (head == -1) {
69 head = 0;
70 t_inc();
71 peek = tail; /* no raw keys */
72 } else
73 h_dec();
75 sp->_fifo[head] = ch;
76 T(("ungetch %s ok", _nc_tracechar(sp, ch)));
77 #ifdef TRACE
78 if (USE_TRACEF(TRACE_IEVENT)) {
79 _nc_fifo_dump(sp);
80 _nc_unlock_global(tracef);
82 #endif
83 rc = OK;
85 returnCode(rc);
88 NCURSES_EXPORT(int)
89 ungetch(int ch)
91 return safe_ungetch(CURRENT_SCREEN, ch);