1156283Srwatson/****************************************************************************
2156283Srwatson * Copyright (c) 1998-2008,2012 Free Software Foundation, Inc.              *
3156283Srwatson *                                                                          *
4156283Srwatson * Permission is hereby granted, free of charge, to any person obtaining a  *
5156283Srwatson * copy of this software and associated documentation files (the            *
6156283Srwatson * "Software"), to deal in the Software without restriction, including      *
7156283Srwatson * without limitation the rights to use, copy, modify, merge, publish,      *
8156283Srwatson * distribute, distribute with modifications, sublicense, and/or sell       *
9156283Srwatson * copies of the Software, and to permit persons to whom the Software is    *
10156283Srwatson * furnished to do so, subject to the following conditions:                 *
11156283Srwatson *                                                                          *
12156283Srwatson * The above copyright notice and this permission notice shall be included  *
13156283Srwatson * in all copies or substantial portions of the Software.                   *
14156283Srwatson *                                                                          *
15156283Srwatson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16156283Srwatson * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17156283Srwatson * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18156283Srwatson * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19156283Srwatson * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20156283Srwatson * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21156283Srwatson * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22156283Srwatson *                                                                          *
23156283Srwatson * Except as contained in this notice, the name(s) of the above copyright   *
24156283Srwatson * holders shall not be used in advertising or otherwise to promote the     *
25156283Srwatson * sale, use or other dealings in this Software without prior written       *
26156283Srwatson * authorization.                                                           *
27156283Srwatson ****************************************************************************/
28156283Srwatson
29156283Srwatson/****************************************************************************
30156283Srwatson *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31156283Srwatson *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32156283Srwatson ****************************************************************************/
33156283Srwatson
34156283Srwatson/*
35156283Srwatson * Common macros for lib_getch.c, lib_ungetch.c
36156283Srwatson *
37156283Srwatson * $Id: fifo_defs.h,v 1.7 2012/08/04 15:59:17 tom Exp $
38156283Srwatson */
39156283Srwatson
40156283Srwatson#ifndef FIFO_DEFS_H
41156283Srwatson#define FIFO_DEFS_H 1
42156283Srwatson
43156283Srwatson#define head	sp->_fifohead
44156283Srwatson#define tail	sp->_fifotail
45156283Srwatson/* peek points to next uninterpreted character */
46156283Srwatson#define peek	sp->_fifopeek
47156283Srwatson
48156283Srwatson#define h_inc() { \
49156283Srwatson	    (head >= FIFO_SIZE-1) \
50156283Srwatson		? head = 0 \
51156283Srwatson		: head++; \
52156283Srwatson	    if (head == tail) \
53156283Srwatson		head = -1, tail = 0; \
54156283Srwatson	}
55156283Srwatson#define h_dec() { \
56156283Srwatson	    (head <= 0) \
57156283Srwatson		? head = FIFO_SIZE-1 \
58156283Srwatson		: head--; \
59156283Srwatson	    if (head == tail) \
60156283Srwatson		tail = -1; \
61156283Srwatson	}
62156283Srwatson#define t_inc() { \
63156283Srwatson	    (tail >= FIFO_SIZE-1) \
64156283Srwatson		? tail = 0 \
65156283Srwatson		: tail++; \
66156283Srwatson	    if (tail == head) \
67156283Srwatson		tail = -1; \
68156283Srwatson	    }
69156283Srwatson#define t_dec() { \
70156283Srwatson	    (tail <= 0) \
71156283Srwatson		? tail = FIFO_SIZE-1 \
72156283Srwatson		: tail--; \
73156283Srwatson	    if (head == tail) \
74156283Srwatson		fifo_clear(sp); \
75156283Srwatson	    }
76156283Srwatson#define p_inc() { \
77156283Srwatson	    (peek >= FIFO_SIZE-1) \
78156283Srwatson		? peek = 0 \
79156283Srwatson		: peek++; \
80156283Srwatson	    }
81156283Srwatson
82156283Srwatson#define cooked_key_in_fifo()	((head >= 0) && (peek != head))
83156283Srwatson#define raw_key_in_fifo()	((head >= 0) && (peek != tail))
84156283Srwatson
85156283Srwatson#undef HIDE_EINTR
86156283Srwatson
87156283Srwatson#endif /* FIFO_DEFS_H */
88156283Srwatson