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