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