blob: d8ea44f74d5bd81b4841e516708be40c30c149dc [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
2 * Copyright (c) 1998,2007,2008 Free Software Foundation, Inc. *
3 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
11 * *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
14 * *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
22 * *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
26 * authorization. *
27 ****************************************************************************/
28
29/****************************************************************************
30 * Author: Juergen Pfeifer, 1996 *
31 ****************************************************************************/
32
33/*
34 Version Control
35 $Id: gen.c,v 1.49 2008/10/04 21:59:37 tom Exp $
36 --------------------------------------------------------------------------*/
37/*
38 This program generates various record structures and constants from the
39 ncurses header file for the Ada95 packages. Essentially it produces
40 Ada95 source on stdout, which is then merged using m4 into a template
41 to produce the real source.
42 */
43
44#include <ncurses_cfg.h>
45
46#include <stdlib.h>
47#include <stddef.h>
48#include <string.h>
49#include <assert.h>
50#include <ctype.h>
51
52#include <menu.h>
53#include <form.h>
54
55#define RES_NAME "Reserved"
56
57static const char *model = "";
58static int little_endian = 0;
59
60typedef struct
61 {
62 const char *name;
63 unsigned long attr;
64 }
65name_attribute_pair;
66
67static int
68find_pos(char *s, unsigned len, int *low, int *high)
69{
70 unsigned int i, j;
71 int l = 0;
72
73 *high = -1;
74 *low = 8 * len;
75
76 for (i = 0; i < len; i++, s++)
77 {
78 if (*s)
79 {
80 for (j = 0; j < 8 * sizeof(char); j++)
81
82 {
83 if (((little_endian && ((*s) & 0x01)) ||
84 (!little_endian && ((*s) & 0x80))))
85 {
86 if (l > *high)
87 *high = l;
88 if (l < *low)
89 *low = l;
90 }
91 l++;
92 if (little_endian)
93 *s >>= 1;
94 else
95 *s <<= 1;
96 }
97 }
98 else
99 l += 8;
100 }
101 return (*high >= 0 && (*low <= *high)) ? *low : -1;
102}
103
104/*
105 * This helper routine generates a representation clause for a
106 * record type defined in the binding.
107 * We are only dealing with record types which are of 32 or 16
108 * bit size, i.e. they fit into an (u)int or a (u)short.
109 */
110static void
111 gen_reps
112 (const name_attribute_pair * nap, /* array of name_attribute_pair records */
113 const char *name, /* name of the represented record type */
114 int len, /* size of the record in bytes */
115 int bias)
116{
117 int i, n, l, cnt = 0, low, high;
118 int width = strlen(RES_NAME) + 3;
119 unsigned long a;
120 unsigned long mask = 0;
121
122 assert(nap != NULL);
123
124 for (i = 0; nap[i].name != (char *)0; i++)
125 {
126 cnt++;
127 l = strlen(nap[i].name);
128 if (l > width)
129 width = l;
130 }
131 assert(width > 0);
132
133 printf(" type %s is\n", name);
134 printf(" record\n");
135 for (i = 0; nap[i].name != (char *)0; i++)
136 {
137 printf(" %-*s : Boolean;\n", width, nap[i].name);
138 }
139 printf(" end record;\n");
140 printf(" pragma Convention (C, %s);\n\n", name);
141
142 printf(" for %s use\n", name);
143 printf(" record\n");
144
145 for (i = 0; nap[i].name != (char *)0; i++)
146 {
147 a = nap[i].attr;
148 mask |= a;
149 l = find_pos((char *)&a, sizeof(a), &low, &high);
150 if (l >= 0)
151 printf(" %-*s at 0 range %2d .. %2d;\n", width, nap[i].name,
152 low - bias, high - bias);
153 }
154 i = 1;
155 n = cnt;
156 printf(" end record;\n");
157 printf(" for %s'Size use %d;\n", name, 8 * len);
158 printf(" -- Please note: this rep. clause is generated and may be\n");
159 printf(" -- different on your system.");
160}
161
162static void
163chtype_rep(const char *name, attr_t mask)
164{
165 attr_t x = -1;
166 attr_t t = x & mask;
167 int low, high;
168 int l = find_pos((char *)&t, sizeof(t), &low, &high);
169
170 if (l >= 0)
171 printf(" %-5s at 0 range %2d .. %2d;\n", name, low, high);
172}
173
174static void
175gen_chtype_rep(const char *name)
176{
177 printf(" for %s use\n record\n", name);
178 chtype_rep("Ch", A_CHARTEXT);
179 chtype_rep("Color", A_COLOR);
180 chtype_rep("Attr", (A_ATTRIBUTES & ~A_COLOR));
181 printf(" end record;\n for %s'Size use %ld;\n",
182 name, (long)(8 * sizeof(chtype)));
183
184 printf(" -- Please note: this rep. clause is generated and may be\n");
185 printf(" -- different on your system.\n");
186}
187
188static void
189mrep_rep(const char *name, void *rec)
190{
191 int low, high;
192 int l = find_pos((char *)rec, sizeof(MEVENT), &low, &high);
193
194 if (l >= 0)
195 printf(" %-7s at 0 range %3d .. %3d;\n", name, low, high);
196}
197
198static void
199gen_mrep_rep(const char *name)
200{
201 MEVENT x;
202
203 printf(" for %s use\n record\n", name);
204
205 memset(&x, 0, sizeof(x));
206 x.id = -1;
207 mrep_rep("Id", &x);
208
209 memset(&x, 0, sizeof(x));
210 x.x = -1;
211 mrep_rep("X", &x);
212
213 memset(&x, 0, sizeof(x));
214 x.y = -1;
215 mrep_rep("Y", &x);
216
217 memset(&x, 0, sizeof(x));
218 x.z = -1;
219 mrep_rep("Z", &x);
220
221 memset(&x, 0, sizeof(x));
222 x.bstate = -1;
223 mrep_rep("Bstate", &x);
224
225 printf(" end record;\n");
226 printf(" -- Please note: this rep. clause is generated and may be\n");
227 printf(" -- different on your system.\n");
228}
229
230static void
231gen_attr_set(const char *name)
232{
233 /* All of the A_xxx symbols are defined in ncurses, but not all are nonzero
234 * if "configure --enable-widec" is specified.
235 */
236 static const name_attribute_pair nap[] =
237 {
238#if A_STANDOUT
239 {"Stand_Out", A_STANDOUT},
240#endif
241#if A_UNDERLINE
242 {"Under_Line", A_UNDERLINE},
243#endif
244#if A_REVERSE
245 {"Reverse_Video", A_REVERSE},
246#endif
247#if A_BLINK
248 {"Blink", A_BLINK},
249#endif
250#if A_DIM
251 {"Dim_Character", A_DIM},
252#endif
253#if A_BOLD
254 {"Bold_Character", A_BOLD},
255#endif
256#if A_ALTCHARSET
257 {"Alternate_Character_Set", A_ALTCHARSET},
258#endif
259#if A_INVIS
260 {"Invisible_Character", A_INVIS},
261#endif
262#if A_PROTECT
263 {"Protected_Character", A_PROTECT},
264#endif
265#if A_HORIZONTAL
266 {"Horizontal", A_HORIZONTAL},
267#endif
268#if A_LEFT
269 {"Left", A_LEFT},
270#endif
271#if A_LOW
272 {"Low", A_LOW},
273#endif
274#if A_RIGHT
275 {"Right", A_RIGHT},
276#endif
277#if A_TOP
278 {"Top", A_TOP},
279#endif
280#if A_VERTICAL
281 {"Vertical", A_VERTICAL},
282#endif
283 {(char *)0, 0}
284 };
285 chtype attr = A_ATTRIBUTES & ~A_COLOR;
286 int start = -1;
287 int len = 0;
288 int i, set;
289 for (i = 0; i < (int)(8 * sizeof(chtype)); i++)
290
291 {
292 set = attr & 1;
293 if (set)
294 {
295 if (start < 0)
296 start = i;
297 if (start >= 0)
298 {
299 len++;
300 }
301 }
302 attr = attr >> 1;
303 }
304 gen_reps(nap, name, (len + 7) / 8, little_endian ? start : 0);
305}
306
307static void
308gen_trace(const char *name)
309{
310 static const name_attribute_pair nap[] =
311 {
312 {"Times", TRACE_TIMES},
313 {"Tputs", TRACE_TPUTS},
314 {"Update", TRACE_UPDATE},
315 {"Cursor_Move", TRACE_MOVE},
316 {"Character_Output", TRACE_CHARPUT},
317 {"Calls", TRACE_CALLS},
318 {"Virtual_Puts", TRACE_VIRTPUT},
319 {"Input_Events", TRACE_IEVENT},
320 {"TTY_State", TRACE_BITS},
321 {"Internal_Calls", TRACE_ICALLS},
322 {"Character_Calls", TRACE_CCALLS},
323 {"Termcap_TermInfo", TRACE_DATABASE},
324 {(char *)0, 0}
325 };
326 gen_reps(nap, name, sizeof(int), 0);
327}
328
329static void
330gen_menu_opt_rep(const char *name)
331{
332 static const name_attribute_pair nap[] =
333 {
334#ifdef O_ONEVALUE
335 {"One_Valued", O_ONEVALUE},
336#endif
337#ifdef O_SHOWDESC
338 {"Show_Descriptions", O_SHOWDESC},
339#endif
340#ifdef O_ROWMAJOR
341 {"Row_Major_Order", O_ROWMAJOR},
342#endif
343#ifdef O_IGNORECASE
344 {"Ignore_Case", O_IGNORECASE},
345#endif
346#ifdef O_SHOWMATCH
347 {"Show_Matches", O_SHOWMATCH},
348#endif
349#ifdef O_NONCYCLIC
350 {"Non_Cyclic", O_NONCYCLIC},
351#endif
352 {(char *)0, 0}
353 };
354 gen_reps(nap, name, sizeof(int), 0);
355}
356
357static void
358gen_item_opt_rep(const char *name)
359{
360 static const name_attribute_pair nap[] =
361 {
362#ifdef O_SELECTABLE
363 {"Selectable", O_SELECTABLE},
364#endif
365 {(char *)0, 0}
366 };
367 gen_reps(nap, name, sizeof(int), 0);
368}
369
370static void
371gen_form_opt_rep(const char *name)
372{
373 static const name_attribute_pair nap[] =
374 {
375#ifdef O_NL_OVERLOAD
376 {"NL_Overload", O_NL_OVERLOAD},
377#endif
378#ifdef O_BS_OVERLOAD
379 {"BS_Overload", O_BS_OVERLOAD},
380#endif
381 {(char *)0, 0}
382 };
383 gen_reps(nap, name, sizeof(int), 0);
384}
385
386/*
387 * Generate the representation clause for the Field_Option_Set record
388 */
389static void
390gen_field_opt_rep(const char *name)
391{
392 static const name_attribute_pair nap[] =
393 {
394#ifdef O_VISIBLE
395 {"Visible", O_VISIBLE},
396#endif
397#ifdef O_ACTIVE
398 {"Active", O_ACTIVE},
399#endif
400#ifdef O_PUBLIC
401 {"Public", O_PUBLIC},
402#endif
403#ifdef O_EDIT
404 {"Edit", O_EDIT},
405#endif
406#ifdef O_WRAP
407 {"Wrap", O_WRAP},
408#endif
409#ifdef O_BLANK
410 {"Blank", O_BLANK},
411#endif
412#ifdef O_AUTOSKIP
413 {"Auto_Skip", O_AUTOSKIP},
414#endif
415#ifdef O_NULLOK
416 {"Null_Ok", O_NULLOK},
417#endif
418#ifdef O_PASSOK
419 {"Pass_Ok", O_PASSOK},
420#endif
421#ifdef O_STATIC
422 {"Static", O_STATIC},
423#endif
424 {(char *)0, 0}
425 };
426 gen_reps(nap, name, sizeof(int), 0);
427}
428
429/*
430 * Generate a single key code constant definition.
431 */
432static void
433keydef(const char *name, const char *old_name, int value, int mode)
434{
435 if (mode == 0) /* Generate the new name */
436 printf(" %-30s : constant Special_Key_Code := 8#%3o#;\n", name, value);
437 else
438 { /* generate the old name, but only if it doesn't conflict with the old
439 * name (Ada95 isn't case sensitive!)
440 */
441 const char *s = old_name;
442 const char *t = name;
443
444 while (*s && *t && (toupper(*s++) == toupper(*t++)));
445 if (*s || *t)
446 printf(" %-16s : Special_Key_Code renames %s;\n", old_name, name);
447 }
448}
449
450/*
451 * Generate constants for the key codes. When called with mode==0, a
452 * complete list with nice constant names in proper casing style will
453 * be generated. Otherwise a list of old (i.e. C-style) names will be
454 * generated, given that the name wasn't already defined in the "nice"
455 * list.
456 */
457static void
458gen_keydefs(int mode)
459{
460 char buf[16];
461 char obuf[16];
462 int i;
463
464#ifdef KEY_CODE_YES
465 keydef("Key_Code_Yes", "KEY_CODE_YES", KEY_CODE_YES, mode);
466#endif
467#ifdef KEY_MIN
468 keydef("Key_Min", "KEY_MIN", KEY_MIN, mode);
469#endif
470#ifdef KEY_BREAK
471 keydef("Key_Break", "KEY_BREAK", KEY_BREAK, mode);
472#endif
473#ifdef KEY_DOWN
474 keydef("Key_Cursor_Down", "KEY_DOWN", KEY_DOWN, mode);
475#endif
476#ifdef KEY_UP
477 keydef("Key_Cursor_Up", "KEY_UP", KEY_UP, mode);
478#endif
479#ifdef KEY_LEFT
480 keydef("Key_Cursor_Left", "KEY_LEFT", KEY_LEFT, mode);
481#endif
482#ifdef KEY_RIGHT
483 keydef("Key_Cursor_Right", "KEY_RIGHT", KEY_RIGHT, mode);
484#endif
485#ifdef KEY_HOME
486 keydef("Key_Home", "KEY_HOME", KEY_HOME, mode);
487#endif
488#ifdef KEY_BACKSPACE
489 keydef("Key_Backspace", "KEY_BACKSPACE", KEY_BACKSPACE, mode);
490#endif
491#ifdef KEY_F0
492 keydef("Key_F0", "KEY_F0", KEY_F0, mode);
493#endif
494#ifdef KEY_F
495 for (i = 1; i <= 24; i++)
496 {
497 sprintf(buf, "Key_F%d", i);
498 sprintf(obuf, "KEY_F%d", i);
499 keydef(buf, obuf, KEY_F(i), mode);
500 }
501#endif
502#ifdef KEY_DL
503 keydef("Key_Delete_Line", "KEY_DL", KEY_DL, mode);
504#endif
505#ifdef KEY_IL
506 keydef("Key_Insert_Line", "KEY_IL", KEY_IL, mode);
507#endif
508#ifdef KEY_DC
509 keydef("Key_Delete_Char", "KEY_DC", KEY_DC, mode);
510#endif
511#ifdef KEY_IC
512 keydef("Key_Insert_Char", "KEY_IC", KEY_IC, mode);
513#endif
514#ifdef KEY_EIC
515 keydef("Key_Exit_Insert_Mode", "KEY_EIC", KEY_EIC, mode);
516#endif
517#ifdef KEY_CLEAR
518 keydef("Key_Clear_Screen", "KEY_CLEAR", KEY_CLEAR, mode);
519#endif
520#ifdef KEY_EOS
521 keydef("Key_Clear_End_Of_Screen", "KEY_EOS", KEY_EOS, mode);
522#endif
523#ifdef KEY_EOL
524 keydef("Key_Clear_End_Of_Line", "KEY_EOL", KEY_EOL, mode);
525#endif
526#ifdef KEY_SF
527 keydef("Key_Scroll_1_Forward", "KEY_SF", KEY_SF, mode);
528#endif
529#ifdef KEY_SR
530 keydef("Key_Scroll_1_Backward", "KEY_SR", KEY_SR, mode);
531#endif
532#ifdef KEY_NPAGE
533 keydef("Key_Next_Page", "KEY_NPAGE", KEY_NPAGE, mode);
534#endif
535#ifdef KEY_PPAGE
536 keydef("Key_Previous_Page", "KEY_PPAGE", KEY_PPAGE, mode);
537#endif
538#ifdef KEY_STAB
539 keydef("Key_Set_Tab", "KEY_STAB", KEY_STAB, mode);
540#endif
541#ifdef KEY_CTAB
542 keydef("Key_Clear_Tab", "KEY_CTAB", KEY_CTAB, mode);
543#endif
544#ifdef KEY_CATAB
545 keydef("Key_Clear_All_Tabs", "KEY_CATAB", KEY_CATAB, mode);
546#endif
547#ifdef KEY_ENTER
548 keydef("Key_Enter_Or_Send", "KEY_ENTER", KEY_ENTER, mode);
549#endif
550#ifdef KEY_SRESET
551 keydef("Key_Soft_Reset", "KEY_SRESET", KEY_SRESET, mode);
552#endif
553#ifdef KEY_RESET
554 keydef("Key_Reset", "KEY_RESET", KEY_RESET, mode);
555#endif
556#ifdef KEY_PRINT
557 keydef("Key_Print", "KEY_PRINT", KEY_PRINT, mode);
558#endif
559#ifdef KEY_LL
560 keydef("Key_Bottom", "KEY_LL", KEY_LL, mode);
561#endif
562#ifdef KEY_A1
563 keydef("Key_Upper_Left_Of_Keypad", "KEY_A1", KEY_A1, mode);
564#endif
565#ifdef KEY_A3
566 keydef("Key_Upper_Right_Of_Keypad", "KEY_A3", KEY_A3, mode);
567#endif
568#ifdef KEY_B2
569 keydef("Key_Center_Of_Keypad", "KEY_B2", KEY_B2, mode);
570#endif
571#ifdef KEY_C1
572 keydef("Key_Lower_Left_Of_Keypad", "KEY_C1", KEY_C1, mode);
573#endif
574#ifdef KEY_C3
575 keydef("Key_Lower_Right_Of_Keypad", "KEY_C3", KEY_C3, mode);
576#endif
577#ifdef KEY_BTAB
578 keydef("Key_Back_Tab", "KEY_BTAB", KEY_BTAB, mode);
579#endif
580#ifdef KEY_BEG
581 keydef("Key_Beginning", "KEY_BEG", KEY_BEG, mode);
582#endif
583#ifdef KEY_CANCEL
584 keydef("Key_Cancel", "KEY_CANCEL", KEY_CANCEL, mode);
585#endif
586#ifdef KEY_CLOSE
587 keydef("Key_Close", "KEY_CLOSE", KEY_CLOSE, mode);
588#endif
589#ifdef KEY_COMMAND
590 keydef("Key_Command", "KEY_COMMAND", KEY_COMMAND, mode);
591#endif
592#ifdef KEY_COPY
593 keydef("Key_Copy", "KEY_COPY", KEY_COPY, mode);
594#endif
595#ifdef KEY_CREATE
596 keydef("Key_Create", "KEY_CREATE", KEY_CREATE, mode);
597#endif
598#ifdef KEY_END
599 keydef("Key_End", "KEY_END", KEY_END, mode);
600#endif
601#ifdef KEY_EXIT
602 keydef("Key_Exit", "KEY_EXIT", KEY_EXIT, mode);
603#endif
604#ifdef KEY_FIND
605 keydef("Key_Find", "KEY_FIND", KEY_FIND, mode);
606#endif
607#ifdef KEY_HELP
608 keydef("Key_Help", "KEY_HELP", KEY_HELP, mode);
609#endif
610#ifdef KEY_MARK
611 keydef("Key_Mark", "KEY_MARK", KEY_MARK, mode);
612#endif
613#ifdef KEY_MESSAGE
614 keydef("Key_Message", "KEY_MESSAGE", KEY_MESSAGE, mode);
615#endif
616#ifdef KEY_MOVE
617 keydef("Key_Move", "KEY_MOVE", KEY_MOVE, mode);
618#endif
619#ifdef KEY_NEXT
620 keydef("Key_Next", "KEY_NEXT", KEY_NEXT, mode);
621#endif
622#ifdef KEY_OPEN
623 keydef("Key_Open", "KEY_OPEN", KEY_OPEN, mode);
624#endif
625#ifdef KEY_OPTIONS
626 keydef("Key_Options", "KEY_OPTIONS", KEY_OPTIONS, mode);
627#endif
628#ifdef KEY_PREVIOUS
629 keydef("Key_Previous", "KEY_PREVIOUS", KEY_PREVIOUS, mode);
630#endif
631#ifdef KEY_REDO
632 keydef("Key_Redo", "KEY_REDO", KEY_REDO, mode);
633#endif
634#ifdef KEY_REFERENCE
635 keydef("Key_Reference", "KEY_REFERENCE", KEY_REFERENCE, mode);
636#endif
637#ifdef KEY_REFRESH
638 keydef("Key_Refresh", "KEY_REFRESH", KEY_REFRESH, mode);
639#endif
640#ifdef KEY_REPLACE
641 keydef("Key_Replace", "KEY_REPLACE", KEY_REPLACE, mode);
642#endif
643#ifdef KEY_RESTART
644 keydef("Key_Restart", "KEY_RESTART", KEY_RESTART, mode);
645#endif
646#ifdef KEY_RESUME
647 keydef("Key_Resume", "KEY_RESUME", KEY_RESUME, mode);
648#endif
649#ifdef KEY_SAVE
650 keydef("Key_Save", "KEY_SAVE", KEY_SAVE, mode);
651#endif
652#ifdef KEY_SBEG
653 keydef("Key_Shift_Begin", "KEY_SBEG", KEY_SBEG, mode);
654#endif
655#ifdef KEY_SCANCEL
656 keydef("Key_Shift_Cancel", "KEY_SCANCEL", KEY_SCANCEL, mode);
657#endif
658#ifdef KEY_SCOMMAND
659 keydef("Key_Shift_Command", "KEY_SCOMMAND", KEY_SCOMMAND, mode);
660#endif
661#ifdef KEY_SCOPY
662 keydef("Key_Shift_Copy", "KEY_SCOPY", KEY_SCOPY, mode);
663#endif
664#ifdef KEY_SCREATE
665 keydef("Key_Shift_Create", "KEY_SCREATE", KEY_SCREATE, mode);
666#endif
667#ifdef KEY_SDC
668 keydef("Key_Shift_Delete_Char", "KEY_SDC", KEY_SDC, mode);
669#endif
670#ifdef KEY_SDL
671 keydef("Key_Shift_Delete_Line", "KEY_SDL", KEY_SDL, mode);
672#endif
673#ifdef KEY_SELECT
674 keydef("Key_Select", "KEY_SELECT", KEY_SELECT, mode);
675#endif
676#ifdef KEY_SEND
677 keydef("Key_Shift_End", "KEY_SEND", KEY_SEND, mode);
678#endif
679#ifdef KEY_SEOL
680 keydef("Key_Shift_Clear_End_Of_Line", "KEY_SEOL", KEY_SEOL, mode);
681#endif
682#ifdef KEY_SEXIT
683 keydef("Key_Shift_Exit", "KEY_SEXIT", KEY_SEXIT, mode);
684#endif
685#ifdef KEY_SFIND
686 keydef("Key_Shift_Find", "KEY_SFIND", KEY_SFIND, mode);
687#endif
688#ifdef KEY_SHELP
689 keydef("Key_Shift_Help", "KEY_SHELP", KEY_SHELP, mode);
690#endif
691#ifdef KEY_SHOME
692 keydef("Key_Shift_Home", "KEY_SHOME", KEY_SHOME, mode);
693#endif
694#ifdef KEY_SIC
695 keydef("Key_Shift_Insert_Char", "KEY_SIC", KEY_SIC, mode);
696#endif
697#ifdef KEY_SLEFT
698 keydef("Key_Shift_Cursor_Left", "KEY_SLEFT", KEY_SLEFT, mode);
699#endif
700#ifdef KEY_SMESSAGE
701 keydef("Key_Shift_Message", "KEY_SMESSAGE", KEY_SMESSAGE, mode);
702#endif
703#ifdef KEY_SMOVE
704 keydef("Key_Shift_Move", "KEY_SMOVE", KEY_SMOVE, mode);
705#endif
706#ifdef KEY_SNEXT
707 keydef("Key_Shift_Next_Page", "KEY_SNEXT", KEY_SNEXT, mode);
708#endif
709#ifdef KEY_SOPTIONS
710 keydef("Key_Shift_Options", "KEY_SOPTIONS", KEY_SOPTIONS, mode);
711#endif
712#ifdef KEY_SPREVIOUS
713 keydef("Key_Shift_Previous_Page", "KEY_SPREVIOUS", KEY_SPREVIOUS, mode);
714#endif
715#ifdef KEY_SPRINT
716 keydef("Key_Shift_Print", "KEY_SPRINT", KEY_SPRINT, mode);
717#endif
718#ifdef KEY_SREDO
719 keydef("Key_Shift_Redo", "KEY_SREDO", KEY_SREDO, mode);
720#endif
721#ifdef KEY_SREPLACE
722 keydef("Key_Shift_Replace", "KEY_SREPLACE", KEY_SREPLACE, mode);
723#endif
724#ifdef KEY_SRIGHT
725 keydef("Key_Shift_Cursor_Right", "KEY_SRIGHT", KEY_SRIGHT, mode);
726#endif
727#ifdef KEY_SRSUME
728 keydef("Key_Shift_Resume", "KEY_SRSUME", KEY_SRSUME, mode);
729#endif
730#ifdef KEY_SSAVE
731 keydef("Key_Shift_Save", "KEY_SSAVE", KEY_SSAVE, mode);
732#endif
733#ifdef KEY_SSUSPEND
734 keydef("Key_Shift_Suspend", "KEY_SSUSPEND", KEY_SSUSPEND, mode);
735#endif
736#ifdef KEY_SUNDO
737 keydef("Key_Shift_Undo", "KEY_SUNDO", KEY_SUNDO, mode);
738#endif
739#ifdef KEY_SUSPEND
740 keydef("Key_Suspend", "KEY_SUSPEND", KEY_SUSPEND, mode);
741#endif
742#ifdef KEY_UNDO
743 keydef("Key_Undo", "KEY_UNDO", KEY_UNDO, mode);
744#endif
745#ifdef KEY_MOUSE
746 keydef("Key_Mouse", "KEY_MOUSE", KEY_MOUSE, mode);
747#endif
748#ifdef KEY_RESIZE
749 keydef("Key_Resize", "KEY_RESIZE", KEY_RESIZE, mode);
750#endif
751}
752
753/*
754 * Generate a constant with the given name. The second parameter
755 * is a reference to the ACS character in the acs_map[] array and
756 * will be translated into an index.
757 */
758static void
759acs_def(const char *name, chtype *a)
760{
761 int c = a - &acs_map[0];
762
763 printf(" %-24s : constant Character := ", name);
764 if (isprint(c) && (c != '`'))
765 printf("'%c';\n", c);
766 else
767 printf("Character'Val (%d);\n", c);
768}
769
770/*
771 * Generate the constants for the ACS characters
772 */
773static void
774gen_acs(void)
775{
776 printf(" type C_ACS_Map is array (Character'Val (0) .. Character'Val (127))\n");
777 printf(" of Attributed_Character;\n");
778#if USE_REENTRANT || BROKEN_LINKER
779 printf(" type C_ACS_Ptr is access C_ACS_Map;\n");
780 printf(" function ACS_Map return C_ACS_Ptr;\n");
781 printf(" pragma Import (C, ACS_Map, \"_nc_acs_map\");\n");
782#else
783 printf(" ACS_Map : C_ACS_Map;\n");
784 printf(" pragma Import (C, ACS_Map, \"acs_map\");\n");
785#endif
786 printf(" --\n");
787 printf(" --\n");
788 printf(" -- Constants for several characters from the Alternate Character Set\n");
789 printf(" -- You must use these constants as indices into the ACS_Map array\n");
790 printf(" -- to get the corresponding attributed character at runtime.\n");
791 printf(" --\n");
792
793#ifdef ACS_ULCORNER
794 acs_def("ACS_Upper_Left_Corner", &ACS_ULCORNER);
795#endif
796#ifdef ACS_LLCORNER
797 acs_def("ACS_Lower_Left_Corner", &ACS_LLCORNER);
798#endif
799#ifdef ACS_URCORNER
800 acs_def("ACS_Upper_Right_Corner", &ACS_URCORNER);
801#endif
802#ifdef ACS_LRCORNER
803 acs_def("ACS_Lower_Right_Corner", &ACS_LRCORNER);
804#endif
805#ifdef ACS_LTEE
806 acs_def("ACS_Left_Tee", &ACS_LTEE);
807#endif
808#ifdef ACS_RTEE
809 acs_def("ACS_Right_Tee", &ACS_RTEE);
810#endif
811#ifdef ACS_BTEE
812 acs_def("ACS_Bottom_Tee", &ACS_BTEE);
813#endif
814#ifdef ACS_TTEE
815 acs_def("ACS_Top_Tee", &ACS_TTEE);
816#endif
817#ifdef ACS_HLINE
818 acs_def("ACS_Horizontal_Line", &ACS_HLINE);
819#endif
820#ifdef ACS_VLINE
821 acs_def("ACS_Vertical_Line", &ACS_VLINE);
822#endif
823#ifdef ACS_PLUS
824 acs_def("ACS_Plus_Symbol", &ACS_PLUS);
825#endif
826#ifdef ACS_S1
827 acs_def("ACS_Scan_Line_1", &ACS_S1);
828#endif
829#ifdef ACS_S9
830 acs_def("ACS_Scan_Line_9", &ACS_S9);
831#endif
832#ifdef ACS_DIAMOND
833 acs_def("ACS_Diamond", &ACS_DIAMOND);
834#endif
835#ifdef ACS_CKBOARD
836 acs_def("ACS_Checker_Board", &ACS_CKBOARD);
837#endif
838#ifdef ACS_DEGREE
839 acs_def("ACS_Degree", &ACS_DEGREE);
840#endif
841#ifdef ACS_PLMINUS
842 acs_def("ACS_Plus_Minus", &ACS_PLMINUS);
843#endif
844#ifdef ACS_BULLET
845 acs_def("ACS_Bullet", &ACS_BULLET);
846#endif
847#ifdef ACS_LARROW
848 acs_def("ACS_Left_Arrow", &ACS_LARROW);
849#endif
850#ifdef ACS_RARROW
851 acs_def("ACS_Right_Arrow", &ACS_RARROW);
852#endif
853#ifdef ACS_DARROW
854 acs_def("ACS_Down_Arrow", &ACS_DARROW);
855#endif
856#ifdef ACS_UARROW
857 acs_def("ACS_Up_Arrow", &ACS_UARROW);
858#endif
859#ifdef ACS_BOARD
860 acs_def("ACS_Board_Of_Squares", &ACS_BOARD);
861#endif
862#ifdef ACS_LANTERN
863 acs_def("ACS_Lantern", &ACS_LANTERN);
864#endif
865#ifdef ACS_BLOCK
866 acs_def("ACS_Solid_Block", &ACS_BLOCK);
867#endif
868#ifdef ACS_S3
869 acs_def("ACS_Scan_Line_3", &ACS_S3);
870#endif
871#ifdef ACS_S7
872 acs_def("ACS_Scan_Line_7", &ACS_S7);
873#endif
874#ifdef ACS_LEQUAL
875 acs_def("ACS_Less_Or_Equal", &ACS_LEQUAL);
876#endif
877#ifdef ACS_GEQUAL
878 acs_def("ACS_Greater_Or_Equal", &ACS_GEQUAL);
879#endif
880#ifdef ACS_PI
881 acs_def("ACS_PI", &ACS_PI);
882#endif
883#ifdef ACS_NEQUAL
884 acs_def("ACS_Not_Equal", &ACS_NEQUAL);
885#endif
886#ifdef ACS_STERLING
887 acs_def("ACS_Sterling", &ACS_STERLING);
888#endif
889}
890
891#define GEN_EVENT(name,value) \
892 printf(" %-25s : constant Event_Mask := 8#%011lo#;\n", \
893 #name, value)
894
895#define GEN_MEVENT(name) \
896 printf(" %-25s : constant Event_Mask := 8#%011lo#;\n", \
897 #name, name)
898
899static void
900gen_mouse_events(void)
901{
902 mmask_t all1 = 0;
903 mmask_t all2 = 0;
904 mmask_t all3 = 0;
905 mmask_t all4 = 0;
906
907#ifdef BUTTON1_RELEASED
908 GEN_MEVENT(BUTTON1_RELEASED);
909 all1 |= BUTTON1_RELEASED;
910#endif
911#ifdef BUTTON1_PRESSED
912 GEN_MEVENT(BUTTON1_PRESSED);
913 all1 |= BUTTON1_PRESSED;
914#endif
915#ifdef BUTTON1_CLICKED
916 GEN_MEVENT(BUTTON1_CLICKED);
917 all1 |= BUTTON1_CLICKED;
918#endif
919#ifdef BUTTON1_DOUBLE_CLICKED
920 GEN_MEVENT(BUTTON1_DOUBLE_CLICKED);
921 all1 |= BUTTON1_DOUBLE_CLICKED;
922#endif
923#ifdef BUTTON1_TRIPLE_CLICKED
924 GEN_MEVENT(BUTTON1_TRIPLE_CLICKED);
925 all1 |= BUTTON1_TRIPLE_CLICKED;
926#endif
927#ifdef BUTTON1_RESERVED_EVENT
928 GEN_MEVENT(BUTTON1_RESERVED_EVENT);
929 all1 |= BUTTON1_RESERVED_EVENT;
930#endif
931#ifdef BUTTON2_RELEASED
932 GEN_MEVENT(BUTTON2_RELEASED);
933 all2 |= BUTTON2_RELEASED;
934#endif
935#ifdef BUTTON2_PRESSED
936 GEN_MEVENT(BUTTON2_PRESSED);
937 all2 |= BUTTON2_PRESSED;
938#endif
939#ifdef BUTTON2_CLICKED
940 GEN_MEVENT(BUTTON2_CLICKED);
941 all2 |= BUTTON2_CLICKED;
942#endif
943#ifdef BUTTON2_DOUBLE_CLICKED
944 GEN_MEVENT(BUTTON2_DOUBLE_CLICKED);
945 all2 |= BUTTON2_DOUBLE_CLICKED;
946#endif
947#ifdef BUTTON2_TRIPLE_CLICKED
948 GEN_MEVENT(BUTTON2_TRIPLE_CLICKED);
949 all2 |= BUTTON2_TRIPLE_CLICKED;
950#endif
951#ifdef BUTTON2_RESERVED_EVENT
952 GEN_MEVENT(BUTTON2_RESERVED_EVENT);
953 all2 |= BUTTON2_RESERVED_EVENT;
954#endif
955#ifdef BUTTON3_RELEASED
956 GEN_MEVENT(BUTTON3_RELEASED);
957 all3 |= BUTTON3_RELEASED;
958#endif
959#ifdef BUTTON3_PRESSED
960 GEN_MEVENT(BUTTON3_PRESSED);
961 all3 |= BUTTON3_PRESSED;
962#endif
963#ifdef BUTTON3_CLICKED
964 GEN_MEVENT(BUTTON3_CLICKED);
965 all3 |= BUTTON3_CLICKED;
966#endif
967#ifdef BUTTON3_DOUBLE_CLICKED
968 GEN_MEVENT(BUTTON3_DOUBLE_CLICKED);
969 all3 |= BUTTON3_DOUBLE_CLICKED;
970#endif
971#ifdef BUTTON3_TRIPLE_CLICKED
972 GEN_MEVENT(BUTTON3_TRIPLE_CLICKED);
973 all3 |= BUTTON3_TRIPLE_CLICKED;
974#endif
975#ifdef BUTTON3_RESERVED_EVENT
976 GEN_MEVENT(BUTTON3_RESERVED_EVENT);
977 all3 |= BUTTON3_RESERVED_EVENT;
978#endif
979#ifdef BUTTON4_RELEASED
980 GEN_MEVENT(BUTTON4_RELEASED);
981 all4 |= BUTTON4_RELEASED;
982#endif
983#ifdef BUTTON4_PRESSED
984 GEN_MEVENT(BUTTON4_PRESSED);
985 all4 |= BUTTON4_PRESSED;
986#endif
987#ifdef BUTTON4_CLICKED
988 GEN_MEVENT(BUTTON4_CLICKED);
989 all4 |= BUTTON4_CLICKED;
990#endif
991#ifdef BUTTON4_DOUBLE_CLICKED
992 GEN_MEVENT(BUTTON4_DOUBLE_CLICKED);
993 all4 |= BUTTON4_DOUBLE_CLICKED;
994#endif
995#ifdef BUTTON4_TRIPLE_CLICKED
996 GEN_MEVENT(BUTTON4_TRIPLE_CLICKED);
997 all4 |= BUTTON4_TRIPLE_CLICKED;
998#endif
999#ifdef BUTTON4_RESERVED_EVENT
1000 GEN_MEVENT(BUTTON4_RESERVED_EVENT);
1001 all4 |= BUTTON4_RESERVED_EVENT;
1002#endif
1003#ifdef BUTTON_CTRL
1004 GEN_MEVENT(BUTTON_CTRL);
1005#endif
1006#ifdef BUTTON_SHIFT
1007 GEN_MEVENT(BUTTON_SHIFT);
1008#endif
1009#ifdef BUTTON_ALT
1010 GEN_MEVENT(BUTTON_ALT);
1011#endif
1012#ifdef REPORT_MOUSE_POSITION
1013 GEN_MEVENT(REPORT_MOUSE_POSITION);
1014#endif
1015#ifdef ALL_MOUSE_EVENTS
1016 GEN_MEVENT(ALL_MOUSE_EVENTS);
1017#endif
1018
1019 GEN_EVENT(BUTTON1_EVENTS, all1);
1020 GEN_EVENT(BUTTON2_EVENTS, all2);
1021 GEN_EVENT(BUTTON3_EVENTS, all3);
1022 GEN_EVENT(BUTTON4_EVENTS, all4);
1023}
1024
1025static void
1026wrap_one_var(const char *c_var,
1027 const char *c_type,
1028 const char *ada_func,
1029 const char *ada_type)
1030{
1031#if USE_REENTRANT
1032 /* must wrap variables */
1033 printf("\n");
1034 printf(" function %s return %s\n", ada_func, ada_type);
1035 printf(" is\n");
1036 printf(" function Result return %s;\n", c_type);
1037 printf(" pragma Import (C, Result, \"_nc_%s\");\n", c_var);
1038 printf(" begin\n");
1039 if (strcmp(c_type, ada_type))
1040 printf(" return %s (Result);\n", ada_type);
1041 else
1042 printf(" return Result;\n");
1043 printf(" end %s;\n", ada_func);
1044#else
1045 /* global variables are really global */
1046 printf("\n");
1047 printf(" function %s return %s\n", ada_func, ada_type);
1048 printf(" is\n");
1049 printf(" Result : %s;\n", c_type);
1050 printf(" pragma Import (C, Result, \"%s\");\n", c_var);
1051 printf(" begin\n");
1052 if (strcmp(c_type, ada_type))
1053 printf(" return %s (Result);\n", ada_type);
1054 else
1055 printf(" return Result;\n");
1056 printf(" end %s;\n", ada_func);
1057#endif
1058}
1059
1060#define GEN_PUBLIC_VAR(c_var, c_type, ada_func, ada_type) \
1061 wrap_one_var(#c_var, #c_type, #ada_func, #ada_type)
1062
1063static void
1064gen_public_vars(void)
1065{
1066 GEN_PUBLIC_VAR(stdscr, Window, Standard_Window, Window);
1067 GEN_PUBLIC_VAR(curscr, Window, Current_Window, Window);
1068 GEN_PUBLIC_VAR(LINES, C_Int, Lines, Line_Count);
1069 GEN_PUBLIC_VAR(COLS, C_Int, Columns, Column_Count);
1070 GEN_PUBLIC_VAR(TABSIZE, C_Int, Tab_Size, Natural);
1071 GEN_PUBLIC_VAR(COLORS, C_Int, Number_Of_Colors, Natural);
1072 GEN_PUBLIC_VAR(COLOR_PAIRS, C_Int, Number_Of_Color_Pairs, Natural);
1073}
1074
1075/*
1076 * Output some comment lines indicating that the file is generated.
1077 * The name parameter is the name of the facility to be used in
1078 * the comment.
1079 */
1080static void
1081prologue(const char *name)
1082{
1083 printf("-- %s binding.\n", name);
1084 printf("-- This module is generated. Please don't change it manually!\n");
1085 printf("-- Run the generator instead.\n-- |");
1086
1087 printf("define(`M4_BIT_ORDER',`%s_Order_First')",
1088 little_endian ? "Low" : "High");
1089}
1090
1091/*
1092 * Write the prologue for the curses facility and make sure that
1093 * KEY_MIN and KEY_MAX are defined for the rest of this source.
1094 */
1095static void
1096basedefs(void)
1097{
1098 prologue("curses");
1099#ifndef KEY_MAX
1100# define KEY_MAX 0777
1101#endif
1102 printf("define(`M4_KEY_MAX',`8#%o#')", KEY_MAX);
1103#ifndef KEY_MIN
1104# define KEY_MIN 0401
1105#endif
1106 if (KEY_MIN == 256)
1107 {
1108 fprintf(stderr, "Unexpected value for KEY_MIN: %d\n", KEY_MIN);
1109 exit(1);
1110 }
1111 printf("define(`M4_SPECIAL_FIRST',`8#%o#')", KEY_MIN - 1);
1112}
1113
1114/*
1115 * Write out the comment lines for the menu facility
1116 */
1117static void
1118menu_basedefs(void)
1119{
1120 prologue("menu");
1121}
1122
1123/*
1124 * Write out the comment lines for the form facility
1125 */
1126static void
1127form_basedefs(void)
1128{
1129 prologue("form");
1130}
1131
1132/*
1133 * Write out the comment lines for the mouse facility
1134 */
1135static void
1136mouse_basedefs(void)
1137{
1138 prologue("mouse");
1139}
1140
1141/*
1142 * Write the definition of a single color
1143 */
1144static void
1145color_def(const char *name, int value)
1146{
1147 printf(" %-16s : constant Color_Number := %d;\n", name, value);
1148}
1149
1150/*
1151 * Generate all color definitions
1152 */
1153static void
1154gen_color(void)
1155{
1156#if HAVE_USE_DEFAULT_COLORS
1157 color_def("Default_Color", -1);
1158#endif
1159#ifdef COLOR_BLACK
1160 color_def("Black", COLOR_BLACK);
1161#endif
1162#ifdef COLOR_RED
1163 color_def("Red", COLOR_RED);
1164#endif
1165#ifdef COLOR_GREEN
1166 color_def("Green", COLOR_GREEN);
1167#endif
1168#ifdef COLOR_YELLOW
1169 color_def("Yellow", COLOR_YELLOW);
1170#endif
1171#ifdef COLOR_BLUE
1172 color_def("Blue", COLOR_BLUE);
1173#endif
1174#ifdef COLOR_MAGENTA
1175 color_def("Magenta", COLOR_MAGENTA);
1176#endif
1177#ifdef COLOR_CYAN
1178 color_def("Cyan", COLOR_CYAN);
1179#endif
1180#ifdef COLOR_WHITE
1181 color_def("White", COLOR_WHITE);
1182#endif
1183}
1184
1185/*
1186 * Generate the linker options for the base facility
1187 */
1188static void
1189gen_linkopts(void)
1190{
1191 printf(" pragma Linker_Options (\"-lncurses%s\");\n", model);
1192}
1193
1194/*
1195 * Generate the linker options for the menu facility
1196 */
1197static void
1198gen_menu_linkopts(void)
1199{
1200 printf(" pragma Linker_Options (\"-lmenu%s\");\n", model);
1201}
1202
1203/*
1204 * Generate the linker options for the form facility
1205 */
1206static void
1207gen_form_linkopts(void)
1208{
1209 printf(" pragma Linker_Options (\"-lform%s\");\n", model);
1210}
1211
1212/*
1213 * Generate the linker options for the panel facility
1214 */
1215static void
1216gen_panel_linkopts(void)
1217{
1218 printf(" pragma Linker_Options (\"-lpanel%s\");\n", model);
1219}
1220
1221static void
1222gen_version_info(void)
1223{
1224 static const char *v1 =
1225 " NC_Major_Version : constant := %d; -- Major version of the library\n";
1226 static const char *v2 =
1227 " NC_Minor_Version : constant := %d; -- Minor version of the library\n";
1228 static const char *v3 =
1229 " NC_Version : constant String := %c%d.%d%c; -- Version of library\n";
1230
1231 printf(v1, NCURSES_VERSION_MAJOR);
1232 printf(v2, NCURSES_VERSION_MINOR);
1233 printf(v3, '"', NCURSES_VERSION_MAJOR, NCURSES_VERSION_MINOR, '"');
1234}
1235
1236static int
1237eti_gen(char *buf, int code, const char *name, int *etimin, int *etimax)
1238{
1239 sprintf(buf, " E_%-16s : constant Eti_Error := %d;\n", name, code);
1240 if (code < *etimin)
1241 *etimin = code;
1242 if (code > *etimax)
1243 *etimax = code;
1244 return strlen(buf);
1245}
1246
1247static void
1248gen_offsets(void)
1249{
1250 const char *s_bool = "";
1251
1252 if (sizeof(bool) == sizeof(char))
1253 {
1254 s_bool = "char";
1255 }
1256 else if (sizeof(bool) == sizeof(short))
1257 {
1258 s_bool = "short";
1259 }
1260 else if (sizeof(bool) == sizeof(int))
1261 {
1262 s_bool = "int";
1263 }
1264 printf(" Sizeof%-*s : constant Natural := %2ld; -- %s\n",
1265 12, "_bool", (long)sizeof(bool), "bool");
1266
1267 /* In ncurses _maxy and _maxx needs an offset for the "public"
1268 * value
1269 */
1270 printf(" Offset%-*s : constant Natural := %2d; -- %s\n",
1271 12, "_XY", 1, "int");
1272 printf("\n");
1273 printf(" type Curses_Bool is mod 2 ** Interfaces.C.%s'Size;\n", s_bool);
1274}
1275
1276/*
1277 * main() expects two arguments on the commandline, both single characters.
1278 * The first character denotes the facility for which we generate output.
1279 * Possible values are
1280 * B - Base
1281 * M - Menus
1282 * F - Forms
1283 * P - Pointer Device (Mouse)
1284 * E - ETI base definitions
1285 *
1286 * The second character then denotes the specific output that should be
1287 * generated for the selected facility.
1288 */
1289int
1290main(int argc, char *argv[])
1291{
1292 int x = 0x12345678;
1293 char *s = (char *)&x;
1294
1295 if (*s == 0x78)
1296 little_endian = 1;
1297
1298 if (argc != 4)
1299 exit(1);
1300 model = *++argv;
1301
1302 switch (argv[1][0])
1303 {
1304 /* --------------------------------------------------------------- */
1305 case 'B': /* The Base facility */
1306 switch (argv[2][0])
1307 {
1308 case 'A': /* chtype translation into Ada95 record type */
1309 gen_attr_set("Character_Attribute_Set");
1310 break;
1311 case 'B': /* write some initial comment lines */
1312 basedefs();
1313 break;
1314 case 'C': /* generate color constants */
1315 gen_color();
1316 break;
1317 case 'D': /* generate displacements of fields in WINDOW struct. */
1318 gen_offsets();
1319 break;
1320 case 'E': /* generate Mouse Event codes */
1321 gen_mouse_events();
1322 break;
1323 case 'K': /* translation of keycodes */
1324 gen_keydefs(0);
1325 break;
1326 case 'L': /* generate the Linker_Options pragma */
1327 gen_linkopts();
1328 break;
1329 case 'M': /* generate constants for the ACS characters */
1330 gen_acs();
1331 break;
1332 case 'O': /* generate definitions of the old key code names */
1333 gen_keydefs(1);
1334 break;
1335 case 'P': /* generate definitions of the public variables */
1336 gen_public_vars();
1337 break;
1338 case 'R': /* generate representation clause for Attributed character */
1339 gen_chtype_rep("Attributed_Character");
1340 break;
1341 case 'T': /* generate the Trace info */
1342 gen_trace("Trace_Attribute_Set");
1343 break;
1344 case 'V': /* generate version info */
1345 gen_version_info();
1346 break;
1347 default:
1348 break;
1349 }
1350 break;
1351 /* --------------------------------------------------------------- */
1352 case 'M': /* The Menu facility */
1353 switch (argv[2][0])
1354 {
1355 case 'R': /* generate representation clause for Menu_Option_Set */
1356 gen_menu_opt_rep("Menu_Option_Set");
1357 break;
1358 case 'B': /* write some initial comment lines */
1359 menu_basedefs();
1360 break;
1361 case 'L': /* generate the Linker_Options pragma */
1362 gen_menu_linkopts();
1363 break;
1364 case 'I': /* generate representation clause for Item_Option_Set */
1365 gen_item_opt_rep("Item_Option_Set");
1366 break;
1367 default:
1368 break;
1369 }
1370 break;
1371 /* --------------------------------------------------------------- */
1372 case 'F': /* The Form facility */
1373 switch (argv[2][0])
1374 {
1375 case 'R': /* generate representation clause for Form_Option_Set */
1376 gen_form_opt_rep("Form_Option_Set");
1377 break;
1378 case 'B': /* write some initial comment lines */
1379 form_basedefs();
1380 break;
1381 case 'L': /* generate the Linker_Options pragma */
1382 gen_form_linkopts();
1383 break;
1384 case 'I': /* generate representation clause for Field_Option_Set */
1385 gen_field_opt_rep("Field_Option_Set");
1386 break;
1387 default:
1388 break;
1389 }
1390 break;
1391 /* --------------------------------------------------------------- */
1392 case 'P': /* The Pointer(=Mouse) facility */
1393 switch (argv[2][0])
1394 {
1395 case 'B': /* write some initial comment lines */
1396 mouse_basedefs();
1397 break;
1398 case 'M': /* generate representation clause for Mouse_Event */
1399 gen_mrep_rep("Mouse_Event");
1400 break;
1401 case 'L': /* generate the Linker_Options pragma */
1402 gen_panel_linkopts();
1403 break;
1404 default:
1405 break;
1406 }
1407 break;
1408 /* --------------------------------------------------------------- */
1409 case 'E': /* chtype size detection */
1410 switch (argv[2][0])
1411 {
1412 case 'C':
1413 {
1414 const char *fmt = " type C_Chtype is new %s;\n";
1415 const char *afmt = " type C_AttrType is new %s;\n";
1416
1417 if (sizeof(chtype) == sizeof(int))
1418 {
1419 if (sizeof(int) == sizeof(long))
1420 printf(fmt, "C_ULong");
1421
1422 else
1423 printf(fmt, "C_UInt");
1424 }
1425 else if (sizeof(chtype) == sizeof(long))
1426 {
1427 printf(fmt, "C_ULong");
1428 }
1429 else
1430 printf("Error\n");
1431
1432 if (sizeof(attr_t) == sizeof(int))
1433 {
1434 if (sizeof(int) == sizeof(long))
1435 printf(afmt, "C_ULong");
1436
1437 else
1438 printf(afmt, "C_UInt");
1439 }
1440 else if (sizeof(attr_t) == sizeof(long))
1441 {
1442 printf(afmt, "C_ULong");
1443 }
1444 else
1445 printf("Error\n");
1446
1447 printf("define(`CF_CURSES_OK',`%d')", OK);
1448 printf("define(`CF_CURSES_ERR',`%d')", ERR);
1449 printf("define(`CF_CURSES_TRUE',`%d')", TRUE);
1450 printf("define(`CF_CURSES_FALSE',`%d')", FALSE);
1451 }
1452 break;
1453 case 'E':
1454 {
1455 char *buf = (char *)malloc(2048);
1456 char *p = buf;
1457 int etimin = E_OK;
1458 int etimax = E_OK;
1459
1460 if (p)
1461 {
1462 p += eti_gen(p, E_OK, "Ok", &etimin, &etimax);
1463 p += eti_gen(p, E_SYSTEM_ERROR, "System_Error", &etimin, &etimax);
1464 p += eti_gen(p, E_BAD_ARGUMENT, "Bad_Argument", &etimin, &etimax);
1465 p += eti_gen(p, E_POSTED, "Posted", &etimin, &etimax);
1466 p += eti_gen(p, E_CONNECTED, "Connected", &etimin, &etimax);
1467 p += eti_gen(p, E_BAD_STATE, "Bad_State", &etimin, &etimax);
1468 p += eti_gen(p, E_NO_ROOM, "No_Room", &etimin, &etimax);
1469 p += eti_gen(p, E_NOT_POSTED, "Not_Posted", &etimin, &etimax);
1470 p += eti_gen(p, E_UNKNOWN_COMMAND,
1471 "Unknown_Command", &etimin, &etimax);
1472 p += eti_gen(p, E_NO_MATCH, "No_Match", &etimin, &etimax);
1473 p += eti_gen(p, E_NOT_SELECTABLE,
1474 "Not_Selectable", &etimin, &etimax);
1475 p += eti_gen(p, E_NOT_CONNECTED,
1476 "Not_Connected", &etimin, &etimax);
1477 p += eti_gen(p, E_REQUEST_DENIED,
1478 "Request_Denied", &etimin, &etimax);
1479 p += eti_gen(p, E_INVALID_FIELD,
1480 "Invalid_Field", &etimin, &etimax);
1481 p += eti_gen(p, E_CURRENT,
1482 "Current", &etimin, &etimax);
1483 }
1484 printf(" subtype Eti_Error is C_Int range %d .. %d;\n\n",
1485 etimin, etimax);
1486 printf(buf);
1487 }
1488 break;
1489 default:
1490 break;
1491 }
1492 break;
1493 /* --------------------------------------------------------------- */
1494 case 'V': /* plain version dump */
1495 {
1496 switch (argv[2][0])
1497 {
1498 case '1': /* major version */
1499#ifdef NCURSES_VERSION_MAJOR
1500 printf("%d", NCURSES_VERSION_MAJOR);
1501#endif
1502 break;
1503 case '2': /* minor version */
1504#ifdef NCURSES_VERSION_MINOR
1505 printf("%d", NCURSES_VERSION_MINOR);
1506#endif
1507 break;
1508 case '3': /* patch level */
1509#ifdef NCURSES_VERSION_PATCH
1510 printf("%d", NCURSES_VERSION_PATCH);
1511#endif
1512 break;
1513 default:
1514 break;
1515 }
1516 }
1517 break;
1518 /* --------------------------------------------------------------- */
1519 default:
1520 break;
1521 }
1522 return 0;
1523}