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