xref: /openbsd-src/lib/libmenu/mf_common.h (revision c7ef0cfc17afcba97172c25e1e3a943e893bc632)
1*c7ef0cfcSnicm /* $OpenBSD: mf_common.h,v 1.8 2023/10/17 09:52:10 nicm Exp $ */
29f1aa62bSmillert 
3457960bfSmillert /****************************************************************************
4*c7ef0cfcSnicm  * Copyright 2020 Thomas E. Dickey                                          *
5*c7ef0cfcSnicm  * Copyright 1998-2005,2012 Free Software Foundation, Inc.                  *
6457960bfSmillert  *                                                                          *
7457960bfSmillert  * Permission is hereby granted, free of charge, to any person obtaining a  *
8457960bfSmillert  * copy of this software and associated documentation files (the            *
9457960bfSmillert  * "Software"), to deal in the Software without restriction, including      *
10457960bfSmillert  * without limitation the rights to use, copy, modify, merge, publish,      *
11457960bfSmillert  * distribute, distribute with modifications, sublicense, and/or sell       *
12457960bfSmillert  * copies of the Software, and to permit persons to whom the Software is    *
13457960bfSmillert  * furnished to do so, subject to the following conditions:                 *
14457960bfSmillert  *                                                                          *
15457960bfSmillert  * The above copyright notice and this permission notice shall be included  *
16457960bfSmillert  * in all copies or substantial portions of the Software.                   *
17457960bfSmillert  *                                                                          *
18457960bfSmillert  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
19457960bfSmillert  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
20457960bfSmillert  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
21457960bfSmillert  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
22457960bfSmillert  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
23457960bfSmillert  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
24457960bfSmillert  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
25457960bfSmillert  *                                                                          *
26457960bfSmillert  * Except as contained in this notice, the name(s) of the above copyright   *
27457960bfSmillert  * holders shall not be used in advertising or otherwise to promote the     *
28457960bfSmillert  * sale, use or other dealings in this Software without prior written       *
29457960bfSmillert  * authorization.                                                           *
30457960bfSmillert  ****************************************************************************/
31457960bfSmillert 
32457960bfSmillert /****************************************************************************
3381d8c4e1Snicm  *   Author:  Juergen Pfeifer, 1995,1997                                    *
34457960bfSmillert  ****************************************************************************/
35c166cd22Stholo 
36*c7ef0cfcSnicm /* $Id: mf_common.h,v 1.8 2023/10/17 09:52:10 nicm Exp $ */
3781d8c4e1Snicm 
38c166cd22Stholo /* Common internal header for menu and form library */
39c166cd22Stholo 
4081d8c4e1Snicm #ifndef MF_COMMON_H_incl
4181d8c4e1Snicm #define MF_COMMON_H_incl 1
4281d8c4e1Snicm 
430107aba4Smillert #include <ncurses_cfg.h>
4481d8c4e1Snicm #include <curses.h>
45c166cd22Stholo 
46c166cd22Stholo #include <stdlib.h>
470107aba4Smillert #include <sys/types.h>
48c166cd22Stholo #include <assert.h>
49c166cd22Stholo #include <string.h>
50c166cd22Stholo #include <ctype.h>
51c166cd22Stholo #include <errno.h>
529f1aa62bSmillert 
539f1aa62bSmillert #if DECL_ERRNO
549f1aa62bSmillert extern int errno;
55c166cd22Stholo #endif
56c166cd22Stholo 
57c166cd22Stholo /* in case of debug version we ignore the suppression of assertions */
58c166cd22Stholo #ifdef TRACE
59c166cd22Stholo #  ifdef NDEBUG
60c166cd22Stholo #    undef NDEBUG
61c166cd22Stholo #  endif
62c166cd22Stholo #endif
63c166cd22Stholo 
640107aba4Smillert #include <nc_alloc.h>
650107aba4Smillert 
6691421ef5Smillert #if USE_RCS_IDS
670107aba4Smillert #define MODULE_ID(id) static const char Ident[] = id;
680107aba4Smillert #else
690107aba4Smillert #define MODULE_ID(id)		/*nothing */
700107aba4Smillert #endif
710107aba4Smillert 
72c166cd22Stholo /* Maximum regular 8-bit character code */
73c166cd22Stholo #define MAX_REGULAR_CHARACTER (0xff)
74c166cd22Stholo 
75c166cd22Stholo #define SET_ERROR(code) (errno=(code))
769f1aa62bSmillert #define GET_ERROR()     (errno)
7781d8c4e1Snicm 
7881d8c4e1Snicm #ifdef TRACE
7981d8c4e1Snicm #define RETURN(code)    returnCode( SET_ERROR(code) )
8081d8c4e1Snicm #else
81c166cd22Stholo #define RETURN(code)    return( SET_ERROR(code) )
8281d8c4e1Snicm #endif
83c166cd22Stholo 
84c166cd22Stholo /* The few common values in the status fields for menus and forms */
8581d8c4e1Snicm #define _POSTED         (0x01U)	/* menu or form is posted                  */
8681d8c4e1Snicm #define _IN_DRIVER      (0x02U)	/* menu or form is processing hook routine */
87c166cd22Stholo 
88*c7ef0cfcSnicm #define SetStatus(target,mask) (target)->status |= (unsigned short) (mask)
89*c7ef0cfcSnicm #define ClrStatus(target,mask) (target)->status = (unsigned short) (target->status & (~mask))
90*c7ef0cfcSnicm 
91c166cd22Stholo /* Call object hook */
92c166cd22Stholo #define Call_Hook( object, handler ) \
9381d8c4e1Snicm    if ( (object) != 0 && ((object)->handler) != (void *) 0 )\
94c166cd22Stholo    {\
95*c7ef0cfcSnicm 	SetStatus(object, _IN_DRIVER);\
96c166cd22Stholo 	(object)->handler(object);\
97*c7ef0cfcSnicm 	ClrStatus(object, _IN_DRIVER);\
98c166cd22Stholo    }
99c166cd22Stholo 
10081d8c4e1Snicm #endif /* MF_COMMON_H_incl */
101