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