1 /* 2 * $Id: dlg_internals.h,v 1.9 2022/04/08 21:01:58 tom Exp $ 3 * 4 * dlg_internals.h -- internal definitions for dialog 5 * 6 * Copyright 2019-2021,2022 Thomas E. Dickey 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License, version 2.1 10 * as published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this program; if not, write to 19 * Free Software Foundation, Inc. 20 * 51 Franklin St., Fifth Floor 21 * Boston, MA 02110, USA. 22 */ 23 24 #ifndef DLG_INTERNALS_H_included 25 #define DLG_INTERNALS_H_included 1 26 27 #include <dialog.h> 28 29 #ifdef NEED_WCHAR_H 30 #include <wchar.h> 31 #endif 32 33 #ifdef ENABLE_NLS 34 #include <libintl.h> 35 #include <langinfo.h> 36 #define _(s) dgettext(PACKAGE, s) 37 #else 38 #undef _ 39 #define _(s) s 40 #endif 41 42 #include <time.h> 43 44 #ifdef HAVE_STDINT_H 45 #include <stdint.h> 46 #else 47 #define intptr_t long 48 #endif 49 50 #include <errno.h> 51 #include <string.h> 52 #include <sys/types.h> 53 #include <sys/stat.h> 54 55 #ifdef HAVE_SETLOCALE 56 #include <locale.h> 57 #endif 58 59 #ifdef STDC_HEADERS 60 #include <stddef.h> /* for offsetof, usually via stdlib.h */ 61 #endif 62 63 #ifdef HAVE_SYS_PARAM_H 64 #include <sys/param.h> 65 #endif 66 67 #if defined(TIME_WITH_SYS_TIME) 68 # include <sys/time.h> 69 # include <time.h> 70 #else 71 # if defined(HAVE_SYS_TIME_H) 72 # include <sys/time.h> 73 # else 74 # include <time.h> 75 # endif 76 #endif 77 78 #if defined(HAVE_DIRENT_H) 79 # include <dirent.h> 80 # define NAMLEN(dirent) strlen((dirent)->d_name) 81 #else 82 # define dirent direct 83 # define NAMLEN(dirent) (dirent)->d_namlen 84 # if defined(HAVE_SYS_NDIR_H) 85 # include <sys/ndir.h> 86 # endif 87 # if defined(HAVE_SYS_DIR_H) 88 # include <sys/dir.h> 89 # endif 90 # if defined(HAVE_NDIR_H) 91 # include <ndir.h> 92 # endif 93 #endif 94 95 # if defined(_FILE_OFFSET_BITS) && defined(HAVE_STRUCT_DIRENT64) 96 # if !defined(_LP64) && (_FILE_OFFSET_BITS == 64) 97 # define DIRENT struct dirent64 98 # else 99 # define DIRENT struct dirent 100 # endif 101 # else 102 # define DIRENT struct dirent 103 # endif 104 105 #if defined(HAVE_SEARCH_H) && defined(HAVE_TSEARCH) 106 #include <search.h> 107 #define leaf leaf2 /* Solaris name-conflict */ 108 #else 109 #undef HAVE_TSEARCH 110 #endif 111 112 /* possible conflicts with <term.h> which may be included in <curses.h> */ 113 #ifdef color_names 114 #undef color_names 115 #endif 116 117 #ifdef buttons 118 #undef buttons 119 #endif 120 121 #ifndef HAVE_WGET_WCH 122 #undef USE_WIDE_CURSES 123 #endif 124 125 #ifdef __cplusplus 126 extern "C" { 127 #endif 128 129 /* these definitions may work for antique versions of curses */ 130 #ifndef HAVE_GETBEGYX 131 #undef getbegyx 132 #define getbegyx(win,y,x) (y = (win)?(win)->_begy:ERR, x = (win)?(win)->_begx:ERR) 133 #endif 134 135 #ifndef HAVE_GETMAXYX 136 #undef getmaxyx 137 #define getmaxyx(win,y,x) (y = (win)?(win)->_maxy:ERR, x = (win)?(win)->_maxx:ERR) 138 #endif 139 140 #ifndef HAVE_GETPARYX 141 #undef getparyx 142 #define getparyx(win,y,x) (y = (win)?(win)->_pary:ERR, x = (win)?(win)->_parx:ERR) 143 #endif 144 145 #if !defined(HAVE_WSYNCUP) 146 #undef wsyncup 147 #define wsyncup(win) /* nothing */ 148 #endif 149 150 #if !defined(HAVE_WCURSYNCUP) 151 #undef wcursyncup 152 #define wcursyncup(win) /* nothing */ 153 #endif 154 155 /* these definitions may be needed for bleeding-edge curses implementations */ 156 #if !(defined(HAVE_GETBEGX) && defined(HAVE_GETBEGY)) 157 #undef getbegx 158 #undef getbegy 159 #define getbegx(win) dlg_getbegx(win) 160 #define getbegy(win) dlg_getbegy(win) 161 extern int dlg_getbegx(WINDOW * /*win*/); 162 extern int dlg_getbegy(WINDOW * /*win*/); 163 #endif 164 165 #if !(defined(HAVE_GETCURX) && defined(HAVE_GETCURY)) 166 #undef getcurx 167 #undef getcury 168 #define getcurx(win) dlg_getcurx(win) 169 #define getcury(win) dlg_getcury(win) 170 extern int dlg_getcurx(WINDOW * /*win*/); 171 extern int dlg_getcury(WINDOW * /*win*/); 172 #endif 173 174 #if !(defined(HAVE_GETMAXX) && defined(HAVE_GETMAXY)) 175 #undef getmaxx 176 #undef getmaxy 177 #define getmaxx(win) dlg_getmaxx(win) 178 #define getmaxy(win) dlg_getmaxy(win) 179 extern int dlg_getmaxx(WINDOW * /*win*/); 180 extern int dlg_getmaxy(WINDOW * /*win*/); 181 #endif 182 183 #if !(defined(HAVE_GETPARX) && defined(HAVE_GETPARY)) 184 #undef getparx 185 #undef getpary 186 #define getparx(win) dlg_getparx(win) 187 #define getpary(win) dlg_getpary(win) 188 extern int dlg_getparx(WINDOW * /*win*/); 189 extern int dlg_getpary(WINDOW * /*win*/); 190 #endif 191 192 #if !(defined(HAVE_WGETPARENT) && defined(HAVE_WINDOW__PARENT)) 193 #undef wgetparent 194 #define wgetparent(win) dlg_wgetparent(win) 195 extern WINDOW * dlg_wgetparent(WINDOW * /*win*/); 196 #elif !defined(HAVE_WGETPARENT) && defined(HAVE_WINDOW__PARENT) 197 #undef wgetparent 198 #define wgetparent(win) ((win) ? (win)->_parent : 0) 199 #endif 200 /* 201 * Use attributes. 202 */ 203 #ifdef PDCURSES 204 #define dlg_attrset(w,a) (void) wattrset((w), (a)) 205 #define dlg_attron(w,a) (void) wattron((w), (a)) 206 #define dlg_attroff(w,a) (void) wattroff((w), (a)) 207 #else 208 #define dlg_attrset(w,a) (void) wattrset((w), (int)(a)) 209 #define dlg_attron(w,a) (void) wattron((w), (int)(a)) 210 #define dlg_attroff(w,a) (void) wattroff((w), (int)(a)) 211 #endif 212 213 #ifndef isblank 214 #define isblank(c) ((c) == ' ' || (c) == TAB) 215 #endif 216 217 #define MAX_LEN 2048 218 #define BUF_SIZE (10L*1024) 219 220 #undef MIN 221 #define MIN(x,y) ((x) < (y) ? (x) : (y)) 222 223 #undef MAX 224 #define MAX(x,y) ((x) > (y) ? (x) : (y)) 225 226 #define UCH(ch) ((unsigned char)(ch)) 227 228 #define assert_ptr(ptr,msg) if ((ptr) == 0) dlg_exiterr("cannot allocate memory in " msg) 229 230 #define dlg_malloc(t,n) (t *) malloc((size_t)(n) * sizeof(t)) 231 #define dlg_calloc(t,n) (t *) calloc((size_t)(n), sizeof(t)) 232 #define dlg_realloc(t,n,p) (t *) realloc((p), (n) * sizeof(t)) 233 234 #define TableSize(name) (sizeof(name)/sizeof((name)[0])) 235 236 /* *INDENT-OFF* */ 237 #define resizeit(name, NAME) \ 238 name = ((NAME >= old_##NAME) \ 239 ? (NAME - (old_##NAME - old_##name)) \ 240 : old_##name) 241 242 #define AddLastKey() \ 243 if (dialog_vars.last_key) { \ 244 if (dlg_need_separator()) \ 245 dlg_add_separator(); \ 246 dlg_add_last_key(-1); \ 247 } 248 249 /* 250 * This is used only for debugging (FIXME: should have a separate header). 251 */ 252 #ifdef NO_LEAKS 253 extern void _dlg_inputstr_leaks(void); 254 #if defined(NCURSES_VERSION) 255 #if defined(HAVE_EXIT_CURSES) 256 /* just use exit_curses() */ 257 #elif defined(HAVE__NC_FREE_AND_EXIT) 258 extern void _nc_free_and_exit(int); /* nc_alloc.h normally not installed */ 259 #define exit_curses(code) _nc_free_and_exit(code) 260 #endif 261 #endif /* NCURSES_VERSION */ 262 #endif /* NO_LEAKS */ 263 264 /* *INDENT-ON* */ 265 266 #ifdef __cplusplus 267 } 268 #endif 269 /* *INDENT-ON* */ 270 271 #endif /* DLG_INTERNALS_H_included */ 272