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