]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/report_offsets.c
ncurses 6.4 - patch 20230923
[ncurses.git] / ncurses / report_offsets.c
1 /****************************************************************************
2  * Copyright 2018-2021,2023 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.23 2023/09/23 16:47:57 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 #define show_NORMAL(type,member) { flag = "n"; show_offset(type,member); }
69 #define show_OPTION(type,member) { flag = "+"; show_offset(type,member); }
70
71 #if USE_REENTRANT
72 #define show_REENTR(type,member) { flag = "r"; show_offset(type,member); }
73 #else
74 #define show_REENTR(type,member)        /* nothing */
75 #endif
76
77 #if NCURSES_SP_FUNCS
78 #define show_SPFUNC(type,member) { flag = "s"; show_offset(type,member); }
79 #else
80 #define show_SPFUNC(type,member)        /* nothing */
81 #endif
82
83 #ifdef USE_PTHREADS
84 #define show_THREAD(type,member) { flag = "t"; show_offset(type,member); }
85 #else
86 #define show_THREAD(type,member)        /* nothing */
87 #endif
88
89 #ifdef TRACE
90 #define show_TRACES(type,member) { flag = "T"; show_offset(type,member); }
91 #else
92 #define show_TRACES(type,member)        /* nothing */
93 #endif
94
95 #if USE_WIDEC_SUPPORT
96 #define show_WIDECH(type,member) { flag = "w"; show_offset(type,member); }
97 #else
98 #define show_WIDECH(type,member)        /* nothing */
99 #endif
100
101 int
102 main(void)
103 {
104     const char *flag = 0;
105     unsigned long last, next;
106
107     printf("Size/offsets of data structures:\n");
108
109     show_size(attr_t);
110     show_size(chtype);
111 #if USE_WIDEC_SUPPORT
112     show_size(cchar_t);
113 #endif
114     show_size(mmask_t);
115     show_size(MEVENT);
116     show_size(NCURSES_BOOL);
117
118     printf("\n");
119     show_size(SCREEN);
120     show_offset(SCREEN, _ifd);
121     show_offset(SCREEN, _fifo);
122     show_offset(SCREEN, _fifohead);
123     show_offset(SCREEN, _direct_color);
124     show_offset(SCREEN, _panelHook);
125     show_offset(SCREEN, jump);
126     show_offset(SCREEN, rsp);
127 #if NCURSES_NO_PADDING
128     show_OPTION(SCREEN, _no_padding);
129 #endif
130 #if USE_HARD_TABS
131     show_OPTION(SCREEN, _ht_cost);
132 #endif
133 #if USE_ITALIC
134     show_OPTION(SCREEN, _use_ritm);
135 #endif
136 #if USE_KLIBC_KBD
137     show_OPTION(SCREEN, _extended_key);
138 #endif
139 #if NCURSES_EXT_FUNCS
140     show_OPTION(SCREEN, _assumed_color);
141 #endif
142 #if USE_GPM_SUPPORT
143     show_OPTION(SCREEN, _mouse_gpm_loaded);
144 #ifdef HAVE_LIBDL
145     show_OPTION(SCREEN, _dlopen_gpm);
146 #endif
147 #endif
148 #if USE_EMX_MOUSE
149     show_OPTION(SCREEN, _emxmouse_wfd);
150 #endif
151 #if USE_SYSMOUSE
152     show_OPTION(SCREEN, _sysmouse_fifo);
153 #endif
154     show_DRIVER(SCREEN, _drv_mouse_fifo);
155 #if USE_SIZECHANGE
156     show_OPTION(SCREEN, _resize);
157 #endif
158 #ifdef USE_SP_WINDOWLIST
159     show_NORMAL(SCREEN, _windowlist);
160 #endif
161     show_REENTR(SCREEN, _ttytype);
162     show_SPFUNC(SCREEN, use_tioctl);
163     show_WIDECH(SCREEN, _screen_acs_fix);
164     show_COLORS(SCREEN, _ordered_pairs);
165     show_TRACES(SCREEN, tracechr_buf);
166
167     printf("\n");
168     show_size(TERMINAL);
169     show_offset(TERMINAL, type);
170     show_offset(TERMINAL, Filedes);
171     show_offset(TERMINAL, Ottyb);
172     show_offset(TERMINAL, Nttyb);
173     show_offset(TERMINAL, _baudrate);
174     show_offset(TERMINAL, _termname);
175     show_offset(TERMINAL, tparm_state);
176 #if HAVE_INIT_EXTENDED_COLOR
177     show_COLORS(TERMINAL, type2);
178 #endif
179
180     printf("\n");
181     show_size(TERMTYPE);
182 #if NCURSES_XNAMES
183     show_OPTION(TERMTYPE, ext_str_table);
184     show_OPTION(TERMTYPE, ext_Strings);
185 #endif
186
187     printf("\n");
188     show_size(TPARM_STATE);
189     show_offset(TPARM_STATE, stack);
190     show_offset(TPARM_STATE, stack_ptr);
191     show_offset(TPARM_STATE, out_buff);
192     show_offset(TPARM_STATE, fmt_buff);
193     show_offset(TPARM_STATE, static_vars);
194     show_TRACES(TPARM_STATE, tname);
195
196     printf("\n");
197     show_size(WINDOW);
198     show_WIDECH(WINDOW, _bkgrnd);
199     show_COLORS(WINDOW, _color);
200
201     printf("\n");
202     show_size(NCURSES_GLOBALS);
203     show_offset(NCURSES_GLOBALS, init_signals);
204     show_offset(NCURSES_GLOBALS, tgetent_cache);
205     show_offset(NCURSES_GLOBALS, dbd_vars);
206 #if HAVE_TSEARCH
207     show_offset(NCURSES_GLOBALS, cached_tparm);
208 #endif
209     show_DRIVER(NCURSES_GLOBALS, term_driver);
210 #ifndef USE_SP_WINDOWLIST
211     show_NORMAL(NCURSES_GLOBALS, _nc_windowlist);
212 #endif
213 #if USE_HOME_TERMINFO
214     show_OPTION(NCURSES_GLOBALS, home_terminfo);
215 #endif
216 #if !USE_SAFE_SPRINTF
217     show_OPTION(NCURSES_GLOBALS, safeprint_rows);
218 #endif
219     show_THREAD(NCURSES_GLOBALS, mutex_curses);
220 #if USE_PTHREADS_EINTR
221     show_THREAD(NCURSES_GLOBALS, read_thread);
222 #endif
223     show_WIDECH(NCURSES_GLOBALS, key_name);
224     show_TRACES(NCURSES_GLOBALS, trace_opened);
225     show_MLEAKS(NCURSES_GLOBALS, leak_checking);
226
227     printf("\n");
228     show_size(NCURSES_PRESCREEN);
229     show_offset(NCURSES_PRESCREEN, tparm_state);
230     show_offset(NCURSES_PRESCREEN, saved_tty);
231     show_offset(NCURSES_PRESCREEN, use_tioctl);
232     show_offset(NCURSES_PRESCREEN, _outch);
233 #ifndef USE_SP_RIPOFF
234     show_NORMAL(NCURSES_PRESCREEN, rippedoff);
235 #endif
236 #if NCURSES_NO_PADDING
237     show_OPTION(NCURSES_PRESCREEN, _no_padding);
238 #endif
239 #if BROKEN_LINKER
240     show_offset(NCURSES_PRESCREEN, real_acs_map);
241 #else
242     show_REENTR(NCURSES_PRESCREEN, real_acs_map);
243 #endif
244 #if BROKEN_LINKER || USE_REENTRANT
245     show_TRACES(NCURSES_PRESCREEN, _outchars);
246 #endif
247
248     return EXIT_SUCCESS;
249 }