]> ncurses.scripts.mit.edu Git - ncurses.git/blob - include/MKterm.h.awk.in
ncurses 6.2 - patch 20200926
[ncurses.git] / include / MKterm.h.awk.in
1 # vile:awkmode
2 function declare_termtype(number,suffix) {
3         printf "typedef struct termtype%s {     /* in-core form of terminfo data */\n", suffix;
4         print  "    char  *term_names;          /* str_table offset of term names */"
5         print  "    char  *str_table;           /* pointer to string table */"
6         print  "    NCURSES_SBOOL  *Booleans;   /* array of boolean values */"
7         printf "    %-5s *Numbers;              /* array of integer values */\n", number;
8         print  "    char  **Strings;            /* array of string offsets */"
9         print  ""
10         print  "#if NCURSES_XNAMES"
11         print  "    char  *ext_str_table;       /* pointer to extended string table */"
12         print  "    char  **ext_Names;          /* corresponding names */"
13         print  ""
14         print  "    unsigned short num_Booleans;/* count total Booleans */";
15         print  "    unsigned short num_Numbers; /* count total Numbers */";
16         print  "    unsigned short num_Strings; /* count total Strings */";
17         print  ""
18         print  "    unsigned short ext_Booleans;/* count extensions to Booleans */";
19         print  "    unsigned short ext_Numbers; /* count extensions to Numbers */";
20         print  "    unsigned short ext_Strings; /* count extensions to Strings */";
21         print  "#endif /* NCURSES_XNAMES */"
22         print  ""
23         printf "} TERMTYPE%s;\n", suffix;
24 }
25 BEGIN {
26         lcurl = "{";
27         rcurl = "}";
28         print  "/****************************************************************************"
29         print  " * Copyright 2018-2019,2020 Thomas E. Dickey                                *"
30         print  " * Copyright 1998-2013,2017 Free Software Foundation, Inc.                  *"
31         print  " *                                                                          *"
32         print  " * Permission is hereby granted, free of charge, to any person obtaining a  *"
33         print  " * copy of this software and associated documentation files (the            *"
34         print  " * \"Software\"), to deal in the Software without restriction, including      *"
35         print  " * without limitation the rights to use, copy, modify, merge, publish,      *"
36         print  " * distribute, distribute with modifications, sublicense, and/or sell       *"
37         print  " * copies of the Software, and to permit persons to whom the Software is    *"
38         print  " * furnished to do so, subject to the following conditions:                 *"
39         print  " *                                                                          *"
40         print  " * The above copyright notice and this permission notice shall be included  *"
41         print  " * in all copies or substantial portions of the Software.                   *"
42         print  " *                                                                          *"
43         print  " * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *"
44         print  " * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *"
45         print  " * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *"
46         print  " * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *"
47         print  " * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *"
48         print  " * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *"
49         print  " * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *"
50         print  " *                                                                          *"
51         print  " * Except as contained in this notice, the name(s) of the above copyright   *"
52         print  " * holders shall not be used in advertising or otherwise to promote the     *"
53         print  " * sale, use or other dealings in this Software without prior written       *"
54         print  " * authorization.                                                           *"
55         print  " ****************************************************************************/"
56         print  ""
57         print  "/****************************************************************************/"
58         print  "/* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995                */"
59         print  "/*    and: Eric S. Raymond <esr@snark.thyrsus.com>                          */"
60         print  "/*    and: Thomas E. Dickey                        1995-on                  */"
61         print  "/****************************************************************************/"
62         print  ""
63         print  "/* $Id: MKterm.h.awk.in,v 1.77 2020/09/05 23:08:27 tom Exp $ */"
64         print  ""
65         print  "/*"
66         print  "**      term.h -- Definition of struct term"
67         print  "*/"
68         print  ""
69         print  "#ifndef NCURSES_TERM_H_incl"
70         print  "#define NCURSES_TERM_H_incl 1"
71         print  ""
72         print  "#undef  NCURSES_VERSION"
73         print  "#define NCURSES_VERSION \"@NCURSES_MAJOR@.@NCURSES_MINOR@\""
74         print  ""
75         print  "#include <ncurses_dll.h>"
76         print  ""
77         print  "#ifdef __cplusplus"
78         printf "extern \"C\" %s\n", lcurl;
79         print  "#endif"
80         print  ""
81         print  "/* Make this file self-contained by providing defaults for the HAVE_TERMIO[S]_H"
82         print  " * definition (based on the system for which this was configured)."
83         print  " */"
84         print  ""
85         print  "#undef  NCURSES_CONST"
86         print  "#define NCURSES_CONST @NCURSES_CONST@"
87         print  ""
88         print  "#undef  NCURSES_SBOOL"
89         print  "#define NCURSES_SBOOL @NCURSES_SBOOL@"
90         print  ""
91         print  "#undef  NCURSES_USE_DATABASE"
92         print  "#define NCURSES_USE_DATABASE @NCURSES_USE_DATABASE@"
93         print  ""
94         print  "#undef  NCURSES_USE_TERMCAP"
95         print  "#define NCURSES_USE_TERMCAP @NCURSES_USE_TERMCAP@"
96         print  ""
97         print  "#undef  NCURSES_XNAMES"
98         print  "#define NCURSES_XNAMES @NCURSES_XNAMES@"
99         print  ""
100         print  "/* We will use these symbols to hide differences between"
101         print  " * termios/termio/sgttyb interfaces."
102         print  " */"
103         print  "#undef  TTY"
104         print  "#undef  SET_TTY"
105         print  "#undef  GET_TTY"
106         print  ""
107         print  "/* Assume POSIX termio if we have the header and function */"
108         print  "/* #if HAVE_TERMIOS_H && HAVE_TCGETATTR */"
109         print  "#if @HAVE_TERMIOS_H@ && @HAVE_TCGETATTR@"
110         print  ""
111         print  "#undef  TERMIOS"
112         print  "#define TERMIOS 1"
113         print  ""
114         print  "#include <termios.h>"
115         print  "#define TTY struct termios"
116         print  ""
117         print  "#else /* !HAVE_TERMIOS_H */"
118         print  ""
119         print  "/* #if HAVE_TERMIO_H */"
120         print  "#if @HAVE_TERMIO_H@"
121         print  ""
122         print  "#undef  TERMIOS"
123         print  "#define TERMIOS 1"
124         print  ""
125         print  "#include <termio.h>"
126         print  "#define TTY struct termio"
127         print  ""
128         print  "#else /* !HAVE_TERMIO_H */"
129         print  ""
130         print  "#if (defined(_WIN32) || defined(_WIN64))"
131         print  "#if @EXP_WIN32_DRIVER@"
132         print  "#include <win32_curses.h>"
133         print  "#define TTY struct winconmode"
134         print  "#else"
135         print  "#include <ncurses_mingw.h>"
136         print  "#define TTY struct termios"
137         print  "#endif"
138         print  "#else"
139         print  "#undef TERMIOS"
140         print  "#include <sgtty.h>"
141         print  "#include <sys/ioctl.h>"
142         print  "#define TTY struct sgttyb"
143         print  "#endif /* MINGW32 */"
144         print  "#endif /* HAVE_TERMIO_H */"
145         print  ""
146         print  "#endif /* HAVE_TERMIOS_H */"
147         print  ""
148         print  "#ifdef TERMIOS"
149         print  "#define GET_TTY(fd, buf) tcgetattr(fd, buf)"
150         print  "#define SET_TTY(fd, buf) tcsetattr(fd, TCSADRAIN, buf)"
151         print  "#elif @EXP_WIN32_DRIVER@ && (defined(_WIN32) || defined(_WIN64))"
152         print  "#define GET_TTY(fd, buf) _nc_console_getmode(_nc_console_fd2handle(fd),buf)"
153         print  "#define SET_TTY(fd, buf) _nc_console_setmode(_nc_console_fd2handle(fd),buf)"
154         print  "#else"
155         print  "#define GET_TTY(fd, buf) gtty(fd, buf)"
156         print  "#define SET_TTY(fd, buf) stty(fd, buf)"
157         print  "#endif"
158         print  ""
159         print  "#ifndef GCC_NORETURN"
160         print  "#define GCC_NORETURN /* nothing */"
161         print  "#endif"
162         print  ""
163         print  "#define NAMESIZE 256"
164         print  ""
165         print  "/* The cast works because TERMTYPE is the first data in TERMINAL */"
166         print  "#define CUR ((TERMTYPE *)(cur_term))->"
167         print  ""
168 }
169
170 $2 == "%%-STOP-HERE-%%" {
171         print  ""
172         printf "#define BOOLWRITE %d\n", BoolCount
173         printf "#define NUMWRITE  %d\n", NumberCount
174         printf "#define STRWRITE  %d\n", StringCount
175         print  ""
176         print  "/* older synonyms for some capabilities */"
177         print  "#define beehive_glitch  no_esc_ctlc"
178         print  "#define teleray_glitch  dest_tabs_magic_smso"
179         print  ""
180         print  "/* HPUX-11 uses this name rather than the standard one */"
181         print  "#ifndef micro_char_size"
182         print  "#define micro_char_size micro_col_size"
183         print  "#endif"
184         print  ""
185         print  "#ifdef __INTERNAL_CAPS_VISIBLE"
186 }
187
188 /^#/ { next; }
189
190 /^used_by/ { next ; }
191 /^userdef/ { next ; }
192
193 $1 == "acs_chars" {
194         acsindex = StringCount;
195 }
196
197 $3 == "bool" {
198         printf "#define %-30s CUR Booleans[%d]\n", $1, BoolCount++
199 }
200
201 $3 == "num" {
202         printf "#define %-30s CUR Numbers[%d]\n", $1, NumberCount++
203 }
204
205 $3 == "str" {
206         printf "#define %-30s CUR Strings[%d]\n", $1, StringCount++
207 }
208
209 END {
210         print  "#endif /* __INTERNAL_CAPS_VISIBLE */"
211         print  ""
212         print  ""
213         print  "/*"
214         print  " * Predefined terminfo array sizes"
215         print  " */"
216         printf "#define BOOLCOUNT %d\n", BoolCount
217         printf "#define NUMCOUNT  %d\n", NumberCount
218         printf "#define STRCOUNT  %d\n", StringCount
219         print  ""
220         print  "/* used by code for comparing entries */"
221         print  "#define acs_chars_index ", acsindex
222         print  ""
223         declare_termtype("short","");
224         print  ""
225         print  "/*"
226         print  " * The only reason these structures are visible is for read-only use."
227         print  " * Programs which modify the data are not, never were, portable across"
228         print  " * curses implementations."
229         print  " */"
230         print  "#ifdef NCURSES_INTERNALS"
231         print  ""
232         if (@NCURSES_EXT_COLORS@) {
233         declare_termtype("int","2");
234         } else {
235         print  "typedef TERMTYPE TERMTYPE2;"
236         }
237         print  ""
238         print  "typedef struct term {           /* describe an actual terminal */"
239         print  "    TERMTYPE    type;           /* terminal type description */"
240         print  "    short       Filedes;        /* file description being written to */"
241         print  "    TTY         Ottyb;          /* original state of the terminal */"
242         print  "    TTY         Nttyb;          /* current state of the terminal */"
243         print  "    int         _baudrate;      /* used to compute padding */"
244         print  "    char *      _termname;      /* used for termname() */"
245         if (@NCURSES_EXT_COLORS@) {
246         print  "    TERMTYPE2   type2;          /* extended terminal type description */"
247         }
248         print  "} TERMINAL;"
249         print  "#else"
250         print  "typedef struct term TERMINAL;"
251         print  "#endif /* NCURSES_INTERNALS */"
252         print  ""
253         print  ""
254         print  "#if @BROKEN_LINKER@ && !@cf_cv_enable_reentrant@"
255         print  "extern NCURSES_EXPORT_VAR(TERMINAL *) cur_term;"
256         print  "#elif @cf_cv_enable_reentrant@"
257         print  "NCURSES_WRAPPED_VAR(TERMINAL *, cur_term);"
258         print  "#define cur_term   NCURSES_PUBLIC_VAR(cur_term())"
259         print  "#else"
260         print  "extern NCURSES_EXPORT_VAR(TERMINAL *) cur_term;"
261         print  "#endif"
262         print  ""
263         print  "#if @BROKEN_LINKER@ || @cf_cv_enable_reentrant@"
264         print  "NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, boolnames);"
265         print  "NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, boolcodes);"
266         print  "NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, boolfnames);"
267         print  "NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, numnames);"
268         print  "NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, numcodes);"
269         print  "NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, numfnames);"
270         print  "NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, strnames);"
271         print  "NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, strcodes);"
272         print  "NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, strfnames);"
273         print  ""
274         print  "#define boolnames  NCURSES_PUBLIC_VAR(boolnames())"
275         print  "#define boolcodes  NCURSES_PUBLIC_VAR(boolcodes())"
276         print  "#define boolfnames NCURSES_PUBLIC_VAR(boolfnames())"
277         print  "#define numnames   NCURSES_PUBLIC_VAR(numnames())"
278         print  "#define numcodes   NCURSES_PUBLIC_VAR(numcodes())"
279         print  "#define numfnames  NCURSES_PUBLIC_VAR(numfnames())"
280         print  "#define strnames   NCURSES_PUBLIC_VAR(strnames())"
281         print  "#define strcodes   NCURSES_PUBLIC_VAR(strcodes())"
282         print  "#define strfnames  NCURSES_PUBLIC_VAR(strfnames())"
283         print  ""
284         print  "#else"
285         print  ""
286         print  "extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolnames[];"
287         print  "extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolcodes[];"
288         print  "extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolfnames[];"
289         print  "extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) numnames[];"
290         print  "extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) numcodes[];"
291         print  "extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) numfnames[];"
292         print  "extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) strnames[];"
293         print  "extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) strcodes[];"
294         print  "extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) strfnames[];"
295         print  ""
296         print  "#endif"
297         print  ""
298         print  "/*"
299         print  " * These entrypoints are used only by the ncurses utilities such as tic."
300         print  " */"
301         print  "#ifdef NCURSES_INTERNALS"
302         print  ""
303         print  "extern NCURSES_EXPORT(int) _nc_set_tty_mode (TTY *buf);"
304         print  "extern NCURSES_EXPORT(int) _nc_read_entry2 (const char * const, char * const, TERMTYPE2 *const);"
305         print  "extern NCURSES_EXPORT(int) _nc_read_file_entry (const char *const, TERMTYPE2 *);"
306         print  "extern NCURSES_EXPORT(int) _nc_read_termtype (TERMTYPE2 *, char *, int);"
307         print  "extern NCURSES_EXPORT(char *) _nc_first_name (const char *const);"
308         print  "extern NCURSES_EXPORT(int) _nc_name_match (const char *const, const char *const, const char *const);"
309         print  "extern NCURSES_EXPORT(char *) _nc_tiparm(int, const char *, ...);"
310         print  ""
311         print  "#endif /* NCURSES_INTERNALS */"
312         print  ""
313         print  ""
314         print  "/*"
315         print  " * These entrypoints are used by tack 1.07."
316         print  " */"
317         print  "extern NCURSES_EXPORT(const TERMTYPE *) _nc_fallback (const char *);"
318         print  "extern NCURSES_EXPORT(int) _nc_read_entry (const char * const, char * const, TERMTYPE *const);"
319         print  ""
320         print  "/*"
321         print  " * Normal entry points"
322         print  " */"
323         print  "extern NCURSES_EXPORT(TERMINAL *) set_curterm (TERMINAL *);"
324         print  "extern NCURSES_EXPORT(int) del_curterm (TERMINAL *);"
325         print  ""
326         print  "/* miscellaneous entry points */"
327         print  "extern NCURSES_EXPORT(int) restartterm (NCURSES_CONST char *, int, int *);"
328         print  "extern NCURSES_EXPORT(int) setupterm (const char *,int,int *);"
329         print  ""
330         print  "/* terminfo entry points, also declared in curses.h */"
331         print  "#if !defined(__NCURSES_H)"
332         print  "extern NCURSES_EXPORT(char *) tigetstr (const char *);"
333         print  "extern NCURSES_EXPORT_VAR(char) ttytype[];"
334         print  "extern NCURSES_EXPORT(int) putp (const char *);"
335         print  "extern NCURSES_EXPORT(int) tigetflag (const char *);"
336         print  "extern NCURSES_EXPORT(int) tigetnum (const char *);"
337         print  ""
338         print  "#if @NCURSES_TPARM_VARARGS@ /* NCURSES_TPARM_VARARGS */"
339         print  "extern NCURSES_EXPORT(char *) tparm (const char *, ...);        /* special */"
340         print  "#else"
341         print  "extern NCURSES_EXPORT(char *) tparm (const char *, long,long,long,long,long,long,long,long,long);       /* special */"
342         print  "#endif"
343         print  ""
344         print  "extern NCURSES_EXPORT(char *) tiparm (const char *, ...);               /* special */"
345         print  ""
346         print  "#endif /* __NCURSES_H */"
347         print  ""
348         print  "/* termcap database emulation (XPG4 uses const only for 2nd param of tgetent) */"
349         print  "#if !defined(NCURSES_TERMCAP_H_incl)"
350         print  "extern NCURSES_EXPORT(char *) tgetstr (const char *, char **);"
351         print  "extern NCURSES_EXPORT(char *) tgoto (const char *, int, int);"
352         print  "extern NCURSES_EXPORT(int) tgetent (char *, const char *);"
353         print  "extern NCURSES_EXPORT(int) tgetflag (const char *);"
354         print  "extern NCURSES_EXPORT(int) tgetnum (const char *);"
355         print  "extern NCURSES_EXPORT(int) tputs (const char *, int, int (*)(int));"
356         print  "#endif /* NCURSES_TERMCAP_H_incl */"
357         print  ""
358         print  "/*"
359         print  " * Include curses.h before term.h to enable these extensions."
360         print  " */"
361         print  "#if defined(NCURSES_SP_FUNCS) && (NCURSES_SP_FUNCS != 0)"
362         print  ""
363         print  "extern NCURSES_EXPORT(char *)  NCURSES_SP_NAME(tigetstr) (SCREEN*, const char *);"
364         print  "extern NCURSES_EXPORT(int)     NCURSES_SP_NAME(putp) (SCREEN*, const char *);"
365         print  "extern NCURSES_EXPORT(int)     NCURSES_SP_NAME(tigetflag) (SCREEN*, const char *);"
366         print  "extern NCURSES_EXPORT(int)     NCURSES_SP_NAME(tigetnum) (SCREEN*, const char *);"
367         print  ""
368         print  "#if @NCURSES_TPARM_VARARGS@ /* NCURSES_TPARM_VARARGS */"
369         print  "extern NCURSES_EXPORT(char *)  NCURSES_SP_NAME(tparm) (SCREEN*, const char *, ...);     /* special */"
370         print  "#else"
371         print  "extern NCURSES_EXPORT(char *)  NCURSES_SP_NAME(tparm) (SCREEN*, const char *, long,long,long,long,long,long,long,long,long);    /* special */"
372         print  "#endif"
373         print  ""
374         print  "/* termcap database emulation (XPG4 uses const only for 2nd param of tgetent) */"
375         print  "extern NCURSES_EXPORT(char *)  NCURSES_SP_NAME(tgetstr) (SCREEN*, const char *, char **);"
376         print  "extern NCURSES_EXPORT(char *)  NCURSES_SP_NAME(tgoto) (SCREEN*, const char *, int, int);"
377         print  "extern NCURSES_EXPORT(int)     NCURSES_SP_NAME(tgetent) (SCREEN*, char *, const char *);"
378         print  "extern NCURSES_EXPORT(int)     NCURSES_SP_NAME(tgetflag) (SCREEN*, const char *);"
379         print  "extern NCURSES_EXPORT(int)     NCURSES_SP_NAME(tgetnum) (SCREEN*, const char *);"
380         print  "extern NCURSES_EXPORT(int)     NCURSES_SP_NAME(tputs) (SCREEN*, const char *, int, NCURSES_SP_OUTC);"
381         print  ""
382         print  "extern NCURSES_EXPORT(TERMINAL *) NCURSES_SP_NAME(set_curterm) (SCREEN*, TERMINAL *);"
383         print  "extern NCURSES_EXPORT(int)     NCURSES_SP_NAME(del_curterm) (SCREEN*, TERMINAL *);"
384         print  ""
385         print  "extern NCURSES_EXPORT(int)     NCURSES_SP_NAME(restartterm) (SCREEN*, NCURSES_CONST char *, int, int *);"
386         print  "#endif /* NCURSES_SP_FUNCS */"
387         print  ""
388         print  "/*"
389         print  " * Debugging features."
390         print  " */"
391         print  "extern NCURSES_EXPORT(void)    exit_terminfo(int) GCC_NORETURN;"
392         print  ""
393         print  "#ifdef __cplusplus"
394         printf "%s\n", rcurl;
395         print  "#endif"
396         print  ""
397         print  "#endif /* NCURSES_TERM_H_incl */"
398 }