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