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