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