1bacd15cpeter/****************************************************************************
201cf73abapt * Copyright 2020 Thomas E. Dickey                                          *
301cf73abapt * Copyright 1998-2005,2012 Free Software Foundation, Inc.                  *
4bacd15cpeter *                                                                          *
5bacd15cpeter * Permission is hereby granted, free of charge, to any person obtaining a  *
6bacd15cpeter * copy of this software and associated documentation files (the            *
7bacd15cpeter * "Software"), to deal in the Software without restriction, including      *
8bacd15cpeter * without limitation the rights to use, copy, modify, merge, publish,      *
9bacd15cpeter * distribute, distribute with modifications, sublicense, and/or sell       *
10bacd15cpeter * copies of the Software, and to permit persons to whom the Software is    *
11bacd15cpeter * furnished to do so, subject to the following conditions:                 *
12bacd15cpeter *                                                                          *
13bacd15cpeter * The above copyright notice and this permission notice shall be included  *
14bacd15cpeter * in all copies or substantial portions of the Software.                   *
15bacd15cpeter *                                                                          *
16bacd15cpeter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17bacd15cpeter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18bacd15cpeter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19bacd15cpeter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20bacd15cpeter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21bacd15cpeter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22bacd15cpeter * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23bacd15cpeter *                                                                          *
24bacd15cpeter * Except as contained in this notice, the name(s) of the above copyright   *
25bacd15cpeter * holders shall not be used in advertising or otherwise to promote the     *
26bacd15cpeter * sale, use or other dealings in this Software without prior written       *
27bacd15cpeter * authorization.                                                           *
28bacd15cpeter ****************************************************************************/
29bacd15cpeter
30bacd15cpeter/****************************************************************************
31de9cbefrafan *   Author:  Juergen Pfeifer, 1995,1997                                    *
32bacd15cpeter ****************************************************************************/
33bacd15cpeter
3401cf73abapt/* $Id: mf_common.h,v 0.25 2020/02/02 23:34:34 tom Exp $ */
35de9cbefrafan
36bacd15cpeter/* Common internal header for menu and form library */
37bacd15cpeter
389a7523dpeter#ifndef MF_COMMON_H_incl
399a7523dpeter#define MF_COMMON_H_incl 1
409a7523dpeter
419a7523dpeter#include <ncurses_cfg.h>
429a7523dpeter#include <curses.h>
43bacd15cpeter
44bacd15cpeter#include <stdlib.h>
45bacd15cpeter#include <sys/types.h>
46bacd15cpeter#include <assert.h>
47bacd15cpeter#include <string.h>
48bacd15cpeter#include <ctype.h>
49bacd15cpeter#include <errno.h>
50bacd15cpeter
51bacd15cpeter#if DECL_ERRNO
52bacd15cpeterextern int errno;
53bacd15cpeter#endif
54bacd15cpeter
55bacd15cpeter/* in case of debug version we ignore the suppression of assertions */
56bacd15cpeter#ifdef TRACE
57bacd15cpeter#  ifdef NDEBUG
58bacd15cpeter#    undef NDEBUG
59bacd15cpeter#  endif
60bacd15cpeter#endif
61bacd15cpeter
62bacd15cpeter#include <nc_alloc.h>
63bacd15cpeter
64a81407apeter#if USE_RCS_IDS
65bacd15cpeter#define MODULE_ID(id) static const char Ident[] = id;
66bacd15cpeter#else
677dbeededelphij#define MODULE_ID(id)		/*nothing */
68bacd15cpeter#endif
69bacd15cpeter
70bacd15cpeter/* Maximum regular 8-bit character code */
71bacd15cpeter#define MAX_REGULAR_CHARACTER (0xff)
72bacd15cpeter
73bacd15cpeter#define SET_ERROR(code) (errno=(code))
74de9cbefrafan#define GET_ERROR()     (errno)
75de9cbefrafan
76de9cbefrafan#ifdef TRACE
77de9cbefrafan#define RETURN(code)    returnCode( SET_ERROR(code) )
78de9cbefrafan#else
79de9cbefrafan#define RETURN(code)    return( SET_ERROR(code) )
80de9cbefrafan#endif
81bacd15cpeter
82bacd15cpeter/* The few common values in the status fields for menus and forms */
837dbeededelphij#define _POSTED         (0x01U)	/* menu or form is posted                  */
847dbeededelphij#define _IN_DRIVER      (0x02U)	/* menu or form is processing hook routine */
857dbeededelphij
867dbeededelphij#define SetStatus(target,mask) (target)->status |= (unsigned short) (mask)
877dbeededelphij#define ClrStatus(target,mask) (target)->status = (unsigned short) (target->status & (~mask))
88bacd15cpeter
89bacd15cpeter/* Call object hook */
90bacd15cpeter#define Call_Hook( object, handler ) \
91de9cbefrafan   if ( (object) != 0 && ((object)->handler) != (void *) 0 )\
92bacd15cpeter   {\
937dbeededelphij	SetStatus(object, _IN_DRIVER);\
94bacd15cpeter	(object)->handler(object);\
957dbeededelphij	ClrStatus(object, _IN_DRIVER);\
96bacd15cpeter   }
97bacd15cpeter
989a7523dpeter#endif /* MF_COMMON_H_incl */
99