1 /****************************************************************************
2 * Copyright 2018-2023,2024 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 #define NEW_PAIR_INTERNAL 1
35 #include <curses.priv.h>
36
37 MODULE_ID("$Id: report_offsets.c,v 1.28 2024/02/24 15:59:09 tom Exp $")
38
39 #define show_size(type) \
40 flag = 0; \
41 last = 0; \
42 printf("%5lu " #type "\n", (unsigned long)sizeof(type))
43 #define show_name(name) \
44 printf("%5lu " #name "\n", (unsigned long)(name))
45 #define show_offset(type,member) \
46 next = (unsigned long)offsetof(type,member); \
47 if (last > next) \
48 printf("?? incorrect order for " #type "." #member "\n"); \
49 printf("%5lu %c " #type "." #member "\n", next, flag ? *flag : ' '); \
50 last = next; \
51 flag = 0
52
53 #if NCURSES_WIDECHAR && NCURSES_EXT_COLORS
54 #define show_COLORS(type,member) { flag = "c"; show_offset(type,member); }
55 #else
56 #define show_COLORS(type,member) /* nothing */
57 #endif
58
59 #ifdef USE_TERM_DRIVER
60 #define show_DRIVER(type,member) { flag = "d"; show_offset(type,member); }
61 #else
62 #define show_DRIVER(type,member) /* nothing */
63 #endif
64
65 #if NO_LEAKS
66 #define show_MLEAKS(type,member) { flag = "L"; show_offset(type,member); }
67 #else
68 #define show_MLEAKS(type,member) /* nothing */
69 #endif
70
71 #define show_NORMAL(type,member) { flag = "n"; show_offset(type,member); }
72 #define show_OPTION(type,member) { flag = "+"; show_offset(type,member); }
73
74 #if USE_REENTRANT
75 #define show_REENTR(type,member) { flag = "r"; show_offset(type,member); }
76 #else
77 #define show_REENTR(type,member) /* nothing */
78 #endif
79
80 #if NCURSES_SP_FUNCS
81 #define show_SPFUNC(type,member) { flag = "s"; show_offset(type,member); }
82 #else
83 #define show_SPFUNC(type,member) /* nothing */
84 #endif
85
86 #ifdef USE_PTHREADS
87 #define show_THREAD(type,member) { flag = "t"; show_offset(type,member); }
88 #else
89 #define show_THREAD(type,member) /* nothing */
90 #endif
91
92 #ifdef TRACE
93 #define show_TRACES(type,member) { flag = "T"; show_offset(type,member); }
94 #else
95 #define show_TRACES(type,member) /* nothing */
96 #endif
97
98 #if USE_WIDEC_SUPPORT
99 #define show_WIDECH(type,member) { flag = "w"; show_offset(type,member); }
100 #else
101 #define show_WIDECH(type,member) /* nothing */
102 #endif
103
104 int
main(void)105 main(void)
106 {
107 const char *flag = 0;
108 unsigned long last, next;
109
110 printf("Size/offsets of data structures:\n");
111
112 show_size(attr_t);
113 show_size(chtype);
114 #if USE_WIDEC_SUPPORT
115 show_size(cchar_t);
116 #endif
117 show_size(color_t);
118 show_size(colorpair_t);
119 show_size(mmask_t);
120 show_size(rgb_bits_t);
121 show_size(MEVENT);
122 show_size(NCURSES_BOOL);
123 show_size(TRIES);
124
125 printf("\n");
126 printf("Sizes of buffers/arrays:\n");
127 #if USE_WIDEC_SUPPORT
128 show_name(CCHARW_MAX);
129 #endif
130 show_name(EV_MAX);
131 show_name(FIFO_SIZE);
132 show_name(NAMESIZE);
133 show_name(MB_LEN_MAX);
134 show_name(PATH_MAX);
135 #ifdef TRACE
136 show_name(TRACECHR_BUF);
137 show_name(TRACEMSE_MAX);
138 #endif
139
140 printf("\n");
141 show_size(SCREEN);
142 show_offset(SCREEN, _ifd);
143 show_offset(SCREEN, _fifo);
144 show_offset(SCREEN, _fifohead);
145 show_offset(SCREEN, _direct_color);
146 show_offset(SCREEN, _panelHook);
147 show_offset(SCREEN, jump);
148 show_offset(SCREEN, rsp);
149 #if NCURSES_NO_PADDING
150 show_OPTION(SCREEN, _no_padding);
151 #endif
152 #if USE_HARD_TABS
153 show_OPTION(SCREEN, _ht_cost);
154 #endif
155 #if USE_ITALIC
156 show_OPTION(SCREEN, _use_ritm);
157 #endif
158 #if USE_KLIBC_KBD
159 show_OPTION(SCREEN, _extended_key);
160 #endif
161 #if NCURSES_EXT_FUNCS
162 show_OPTION(SCREEN, _assumed_color);
163 #endif
164 #if USE_GPM_SUPPORT
165 show_OPTION(SCREEN, _mouse_gpm_loaded);
166 #ifdef HAVE_LIBDL
167 show_OPTION(SCREEN, _dlopen_gpm);
168 #endif
169 #endif
170 #if USE_EMX_MOUSE
171 show_OPTION(SCREEN, _emxmouse_wfd);
172 #endif
173 #if USE_SYSMOUSE
174 show_OPTION(SCREEN, _sysmouse_fifo);
175 #endif
176 show_DRIVER(SCREEN, _drv_mouse_fifo);
177 #if USE_SIZECHANGE
178 show_OPTION(SCREEN, _resize);
179 #endif
180 #ifdef USE_SP_WINDOWLIST
181 show_NORMAL(SCREEN, _windowlist);
182 #endif
183 show_REENTR(SCREEN, _ttytype);
184 show_SPFUNC(SCREEN, use_tioctl);
185 show_WIDECH(SCREEN, _screen_acs_fix);
186 show_COLORS(SCREEN, _ordered_pairs);
187 show_TRACES(SCREEN, tracechr_buf);
188
189 printf("\n");
190 show_size(TERMINAL);
191 show_offset(TERMINAL, type);
192 show_offset(TERMINAL, Filedes);
193 show_offset(TERMINAL, Ottyb);
194 show_offset(TERMINAL, Nttyb);
195 show_offset(TERMINAL, _baudrate);
196 show_offset(TERMINAL, _termname);
197 show_offset(TERMINAL, tparm_state);
198 #if HAVE_INIT_EXTENDED_COLOR
199 show_COLORS(TERMINAL, type2);
200 #endif
201
202 printf("\n");
203 show_size(TERMTYPE);
204 #if NCURSES_XNAMES
205 show_OPTION(TERMTYPE, ext_str_table);
206 show_OPTION(TERMTYPE, ext_Strings);
207 #endif
208
209 printf("\n");
210 show_size(TPARM_STATE);
211 show_offset(TPARM_STATE, stack);
212 show_offset(TPARM_STATE, stack_ptr);
213 show_offset(TPARM_STATE, out_buff);
214 show_offset(TPARM_STATE, fmt_buff);
215 show_offset(TPARM_STATE, static_vars);
216 show_TRACES(TPARM_STATE, tname);
217
218 printf("\n");
219 show_size(WINDOW);
220 show_WIDECH(WINDOW, _bkgrnd);
221 show_COLORS(WINDOW, _color);
222
223 printf("\n");
224 show_size(NCURSES_GLOBALS);
225 show_offset(NCURSES_GLOBALS, init_signals);
226 show_offset(NCURSES_GLOBALS, tgetent_cache);
227 show_offset(NCURSES_GLOBALS, dbd_vars);
228 #if HAVE_TSEARCH
229 show_offset(NCURSES_GLOBALS, cached_tparm);
230 #endif
231 show_DRIVER(NCURSES_GLOBALS, term_driver);
232 #ifndef USE_SP_WINDOWLIST
233 show_NORMAL(NCURSES_GLOBALS, _nc_windowlist);
234 #endif
235 #if USE_HOME_TERMINFO
236 show_OPTION(NCURSES_GLOBALS, home_terminfo);
237 #endif
238 #if !USE_SAFE_SPRINTF
239 show_OPTION(NCURSES_GLOBALS, safeprint_rows);
240 #endif
241 show_THREAD(NCURSES_GLOBALS, mutex_curses);
242 #if USE_PTHREADS_EINTR
243 show_THREAD(NCURSES_GLOBALS, read_thread);
244 #endif
245 show_WIDECH(NCURSES_GLOBALS, key_name);
246 show_TRACES(NCURSES_GLOBALS, trace_opened);
247 show_TRACES(NCURSES_GLOBALS, trace_level);
248 show_MLEAKS(NCURSES_GLOBALS, leak_checking);
249
250 printf("\n");
251 show_size(NCURSES_PRESCREEN);
252 show_offset(NCURSES_PRESCREEN, tparm_state);
253 show_offset(NCURSES_PRESCREEN, saved_tty);
254 show_offset(NCURSES_PRESCREEN, use_tioctl);
255 show_offset(NCURSES_PRESCREEN, _outch);
256 #ifndef USE_SP_RIPOFF
257 show_NORMAL(NCURSES_PRESCREEN, rippedoff);
258 #endif
259 #if NCURSES_NO_PADDING
260 show_OPTION(NCURSES_PRESCREEN, _no_padding);
261 #endif
262 #if BROKEN_LINKER
263 show_offset(NCURSES_PRESCREEN, real_acs_map);
264 #else
265 show_REENTR(NCURSES_PRESCREEN, real_acs_map);
266 #endif
267 #if BROKEN_LINKER || USE_REENTRANT
268 show_TRACES(NCURSES_PRESCREEN, _outchars);
269 #endif
270
271 return EXIT_SUCCESS;
272 }
273