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