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