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