ncurses 6.2 - patch 20200212
[ncurses.git] / ncurses / report_offsets.c
1 /****************************************************************************
2  * Copyright 2018,2020 Thomas E. Dickey                                     *
3  * Copyright 2017 Free Software Foundation, Inc.                            *
4  *                                                                          *
5  * Permission is hereby granted, free of charge, to any person obtaining a  *
6  * copy of this software and associated documentation files (the            *
7  * "Software"), to deal in the Software without restriction, including      *
8  * without limitation the rights to use, copy, modify, merge, publish,      *
9  * distribute, distribute with modifications, sublicense, and/or sell       *
10  * copies of the Software, and to permit persons to whom the Software is    *
11  * furnished to do so, subject to the following conditions:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23  *                                                                          *
24  * Except as contained in this notice, the name(s) of the above copyright   *
25  * holders shall not be used in advertising or otherwise to promote the     *
26  * sale, use or other dealings in this Software without prior written       *
27  * authorization.                                                           *
28  ****************************************************************************/
29
30 /****************************************************************************
31  *  Author: Thomas E. Dickey                                                *
32  ****************************************************************************/
33
34 #include <curses.priv.h>
35
36 MODULE_ID("$Id: report_offsets.c,v 1.21 2020/02/02 23:34:34 tom Exp $")
37
38 #define show_size(type) \
39         flag = 0; \
40         last = 0; \
41         printf("%5lu   " #type "\n", (unsigned long)sizeof(type))
42 #define show_offset(type,member) \
43         next = (unsigned long)offsetof(type,member); \
44         if (last > next) \
45                 printf("?? incorrect order for " #type "." #member "\n"); \
46         printf("%5lu %c " #type "." #member "\n", next, flag ? *flag : ' '); \
47         last = next; \
48         flag = 0
49
50 #if NCURSES_WIDECHAR && NCURSES_EXT_COLORS
51 #define show_COLORS(type,member) { flag = "c"; show_offset(type,member); }
52 #else
53 #define show_COLORS(type,member)        /* nothing */
54 #endif
55
56 #ifdef USE_TERM_DRIVER
57 #define show_DRIVER(type,member) { flag = "d"; show_offset(type,member); }
58 #else
59 #define show_DRIVER(type,member)        /* nothing */
60 #endif
61
62 #if NO_LEAKS
63 #define show_MLEAKS(type,member) { flag = "L"; show_offset(type,member); }
64 #else
65 #define show_MLEAKS(type,member)        /* nothing */
66 #endif
67
68 #ifdef USE_TERM_DRIVER
69 #define show_NORMAL(type,member)        /* nothing */
70 #else
71 #define show_NORMAL(type,member) { flag = "n"; show_offset(type,member); }
72 #endif
73
74 #define show_OPTION(type,member) { flag = "+"; show_offset(type,member); }
75
76 #if USE_REENTRANT
77 #define show_REENTR(type,member) { flag = "r"; show_offset(type,member); }
78 #else
79 #define show_REENTR(type,member)        /* nothing */
80 #endif
81
82 #if NCURSES_SP_FUNCS
83 #define show_SPFUNC(type,member) { flag = "s"; show_offset(type,member); }
84 #else
85 #define show_SPFUNC(type,member)        /* nothing */
86 #endif
87
88 #ifdef USE_PTHREADS
89 #define show_THREAD(type,member) { flag = "t"; show_offset(type,member); }
90 #else
91 #define show_THREAD(type,member)        /* nothing */
92 #endif
93
94 #ifdef TRACE
95 #define show_TRACES(type,member) { flag = "T"; show_offset(type,member); }
96 #else
97 #define show_TRACES(type,member)        /* nothing */
98 #endif
99
100 #if USE_WIDEC_SUPPORT
101 #define show_WIDECH(type,member) { flag = "w"; show_offset(type,member); }
102 #else
103 #define show_WIDECH(type,member)        /* nothing */
104 #endif
105
106 int
107 main(void)
108 {
109     const char *flag = 0;
110     unsigned long last, next;
111
112     printf("Size/offsets of data structures:\n");
113
114     show_size(attr_t);
115     show_size(chtype);
116 #if USE_WIDEC_SUPPORT
117     show_size(cchar_t);
118 #endif
119     show_size(mmask_t);
120     show_size(MEVENT);
121     show_size(NCURSES_BOOL);
122
123     printf("\n");
124     show_size(SCREEN);
125     show_offset(SCREEN, _ifd);
126     show_offset(SCREEN, _fifo);
127     show_offset(SCREEN, _fifohead);
128     show_offset(SCREEN, _direct_color);
129     show_offset(SCREEN, _panelHook);
130     show_offset(SCREEN, jump);
131     show_offset(SCREEN, rsp);
132 #if NCURSES_NO_PADDING
133     show_OPTION(SCREEN, _no_padding);
134 #endif
135 #if USE_HARD_TABS
136     show_OPTION(SCREEN, _ht_cost);
137 #endif
138 #if USE_ITALIC
139     show_OPTION(SCREEN, _use_ritm);
140 #endif
141 #if USE_KLIBC_KBD
142     show_OPTION(SCREEN, _extended_key);
143 #endif
144 #if NCURSES_EXT_FUNCS
145     show_OPTION(SCREEN, _assumed_color);
146 #endif
147 #if USE_GPM_SUPPORT
148     show_OPTION(SCREEN, _mouse_gpm_loaded);
149 #ifdef HAVE_LIBDL
150     show_OPTION(SCREEN, _dlopen_gpm);
151 #endif
152 #endif
153 #if USE_EMX_MOUSE
154     show_OPTION(SCREEN, _emxmouse_wfd);
155 #endif
156 #if USE_SYSMOUSE
157     show_OPTION(SCREEN, _sysmouse_fifo);
158 #endif
159     show_DRIVER(SCREEN, _drv_mouse_fifo);
160 #if USE_SIZECHANGE
161     show_OPTION(SCREEN, _resize);
162 #endif
163     show_DRIVER(SCREEN, _windowlist);
164     show_REENTR(SCREEN, _ttytype);
165     show_SPFUNC(SCREEN, use_tioctl);
166     show_WIDECH(SCREEN, _screen_acs_fix);
167     show_COLORS(SCREEN, _ordered_pairs);
168     show_TRACES(SCREEN, tracechr_buf);
169
170     printf("\n");
171     show_size(TERMINAL);
172     show_offset(TERMINAL, type);
173     show_offset(TERMINAL, Filedes);
174     show_offset(TERMINAL, Ottyb);
175     show_offset(TERMINAL, Nttyb);
176     show_offset(TERMINAL, _baudrate);
177     show_offset(TERMINAL, _termname);
178 #if HAVE_INIT_EXTENDED_COLOR
179     show_COLORS(TERMINAL, type2);
180 #endif
181
182     printf("\n");
183     show_size(TERMTYPE);
184 #if NCURSES_XNAMES
185     show_OPTION(TERMTYPE, ext_str_table);
186     show_OPTION(TERMTYPE, ext_Strings);
187 #endif
188
189     printf("\n");
190     show_size(WINDOW);
191     show_WIDECH(WINDOW, _bkgrnd);
192     show_COLORS(WINDOW, _color);
193
194     printf("\n");
195     show_size(NCURSES_GLOBALS);
196     show_offset(NCURSES_GLOBALS, init_signals);
197     show_DRIVER(NCURSES_GLOBALS, term_driver);
198     show_NORMAL(NCURSES_GLOBALS, _nc_windowlist);
199 #if USE_HOME_TERMINFO
200     show_OPTION(NCURSES_GLOBALS, home_terminfo);
201 #endif
202 #if !USE_SAFE_SPRINTF
203     show_OPTION(NCURSES_GLOBALS, safeprint_rows);
204 #endif
205     show_THREAD(NCURSES_GLOBALS, mutex_curses);
206 #if USE_PTHREADS_EINTR
207     show_THREAD(NCURSES_GLOBALS, read_thread);
208 #endif
209     show_WIDECH(NCURSES_GLOBALS, key_name);
210     show_TRACES(NCURSES_GLOBALS, trace_opened);
211     show_MLEAKS(NCURSES_GLOBALS, leak_checking);
212
213     printf("\n");
214     show_size(NCURSES_PRESCREEN);
215     show_offset(NCURSES_PRESCREEN, saved_tty);
216     show_offset(NCURSES_PRESCREEN, use_tioctl);
217     show_offset(NCURSES_PRESCREEN, _outch);
218     show_NORMAL(NCURSES_PRESCREEN, rippedoff);
219 #if NCURSES_NO_PADDING
220     show_OPTION(NCURSES_PRESCREEN, _no_padding);
221 #endif
222 #if BROKEN_LINKER
223     show_offset(NCURSES_PRESCREEN, real_acs_map);
224 #else
225     show_REENTR(NCURSES_PRESCREEN, real_acs_map);
226 #endif
227
228     return EXIT_SUCCESS;
229 }