]> ncurses.scripts.mit.edu Git - ncurses.git/blob - Ada95/gen/gen.c
48532947aa50461035138ed2433067fb400f78ab
[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@T-Online.de> 1996             *
31  ****************************************************************************/
32
33 /*
34     Version Control
35     $Revision: 1.14 $
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 <string.h>
45 #include <assert.h>
46 #include <ctype.h>
47
48 #include <menu.h>
49 #include <form.h>
50
51 #define RES_NAME "Reserved"
52
53 static int little_endian = 0;
54
55 typedef struct {
56   const char *name;
57   unsigned int attr;
58 } name_attribute_pair;
59
60 static int find_pos (char *s, unsigned len, int *low, int *high)
61 {
62   unsigned int i,j; 
63   int l = 0;
64
65   *high = -1;
66   *low  = 8*len;
67
68   for(i=0; i < len; i++,s++)
69     {
70       if (*s)
71         {
72           for(j=0;j<8*sizeof(char);j++)
73             {
74               if ((( little_endian && ((*s)&0x01)) ||
75                    (!little_endian && ((*s)&0x80))) )
76                 {
77                   if (l > *high)
78                     *high = l;
79                   if (l < *low)
80                     *low = l;
81                 }
82               l++;
83               if (little_endian)
84                 *s >>= 1;
85               else
86                 *s <<= 1;
87             }
88         }
89       else
90         l += 8;
91     }
92   return (*high >= 0 && (*low <= *high)) ? *low : -1;
93 }
94
95 /*
96  * This helper routine generates a representation clause for a
97  * record type defined in the binding.
98  * We are only dealing with record types which are of 32 or 16
99  * bit size, i.e. they fit into an (u)int or a (u)short.
100  */
101 static void gen_reps
102 (const name_attribute_pair *nap, /* array of name_attribute_pair records */
103  const char *name,               /* name of the represented record type  */
104  int len)                        /* size of the record in bytes          */
105 {
106   int i,l,cnt = 0,low,high;
107   int width = strlen(RES_NAME);
108   int bias = 0;
109   unsigned int a;
110   unsigned int mask = 0;
111   char *suffix;
112
113   assert (nap);
114
115   if (len == sizeof(int)/2)
116     {
117       bias = little_endian ? 8 * len : 0;
118       suffix = " / 2";
119     }
120   else
121     {
122       assert(len==sizeof(int));
123       suffix = "";
124     }
125
126   for (i=0; nap[i].name != (char *)0; i++)
127     {
128       cnt++;
129       l = strlen(nap[i].name);
130       if (l>width)
131         width = l;
132     }
133   assert (width > 0);
134
135   printf("   type %s is\n",name);
136   printf("      record\n");
137   for (i=0; nap[i].name != (char *)0; i++)
138     {
139       printf("         %-*s : Boolean;\n",width,nap[i].name);
140     }  
141   if (cnt != 8*len)
142     {
143       printf("         %-*s : Boolean;\n",width,RES_NAME);
144     }
145   printf("      end record;\n");
146   printf("   pragma Pack (%s);\n",name);
147   printf("   pragma Convention (C, %s);\n\n",name);
148
149   printf("   for %s use\n",name);
150   printf("      record\n");
151
152   for (i=0; nap[i].name != (char *)0; i++)
153     {
154       a = nap[i].attr;
155       mask |= a;
156       l = find_pos( (char *)&a,sizeof(a),&low,&high );
157       if (l>=0)
158         printf("         %-*s at 0 range %2d .. %2d;\n",width,nap[i].name,low-bias,high-bias);
159     }  
160   if (cnt != 8*len)
161     {
162       mask = ~mask;
163       assert(mask);
164       if (little_endian)
165         l = 8*len - 1;
166       else
167         l = 0;
168       printf("         %-*s at 0 range %2d .. %2d;\n",width,RES_NAME,l,l);
169     }
170   printf("      end record;\n");
171   printf("   for %s'Size use Interfaces.C.int'Size%s;\n", name, suffix);
172   printf("   --  Please note: this rep. clause is generated and may be\n");
173   printf("   --               different on your system.");
174 }
175
176
177 static void chtype_rep (const char *name, int mask)
178 {
179   int x = -1;
180   int t = x & mask;
181   int low, high;
182   int l = find_pos ((char *)&t, sizeof(t), &low, &high);
183   if (l>=0)
184     printf("         %-5s at 0 range %2d .. %2d;\n",name,low,high); 
185 }
186
187 static void gen_chtype_rep(const char *name)
188 {
189   printf("   for %s use\n      record\n",name);
190   chtype_rep("Ch",A_CHARTEXT);
191   chtype_rep("Color",A_COLOR);
192   chtype_rep("Attr",(A_ATTRIBUTES&~A_COLOR));
193   printf("      end record;\n   for %s'Size use Interfaces.C.int'Size;\n",name);
194   printf("      --  Please note: this rep. clause is generated and may be\n");
195   printf("      --               different on your system.\n");
196 }
197
198
199 static void mrep_rep (const char *name, void *rec)
200 {
201   int low, high;
202   int l = find_pos((char *)rec, sizeof(MEVENT), &low, &high);
203   if (l>=0)
204     printf("         %-7s at 0 range %3d .. %3d;\n",name,low,high); 
205 }
206
207
208 static void gen_mrep_rep(const char *name)
209 {
210   MEVENT x;
211
212   printf("   for %s use\n      record\n",name);
213
214   memset(&x,0,sizeof(x));
215   x.id = -1;
216   mrep_rep("Id",&x);
217
218   memset(&x,0,sizeof(x));
219   x.x = -1;
220   mrep_rep("X",&x);
221
222   memset(&x,0,sizeof(x));
223   x.y = -1;
224   mrep_rep("Y",&x);
225
226   memset(&x,0,sizeof(x));
227   x.z = -1;
228   mrep_rep("Z",&x);
229
230   memset(&x,0,sizeof(x));
231   x.bstate = -1;
232   mrep_rep("Bstate",&x);
233
234   printf("      end record;\n");
235   printf("      --  Please note: this rep. clause is generated and may be\n");
236   printf("      --               different on your system.\n");
237 }
238
239 static void gen_attr_set( const char *name )
240 {
241   static const name_attribute_pair nap[] = {
242 #ifdef A_STANDOUT
243     {"Stand_Out",               A_STANDOUT},
244 #endif
245 #ifdef A_UNDERLINE
246     {"Under_Line",              A_UNDERLINE},
247 #endif
248 #ifdef A_REVERSE
249     {"Reverse_Video",           A_REVERSE},
250 #endif
251 #ifdef A_BLINK
252     {"Blink",                   A_BLINK},
253 #endif
254 #ifdef A_DIM
255     {"Dim_Character",           A_DIM},
256 #endif
257 #ifdef A_BOLD
258     {"Bold_Character",          A_BOLD},
259 #endif
260 #ifdef A_ALTCHARSET
261     {"Alternate_Character_Set", A_ALTCHARSET},
262 #endif
263 #ifdef A_INVIS
264     {"Invisible_Character",     A_INVIS},
265 #endif
266 #ifdef A_PROTECT
267     {"Protected_Character",     A_PROTECT},
268 #endif
269 #ifdef A_HORIZONTAL
270     {"Horizontal",              A_HORIZONTAL},
271 #endif
272 #ifdef A_LEFT
273     {"Left",                    A_LEFT},
274 #endif
275 #ifdef A_LOW
276     {"Low",                     A_LOW},
277 #endif
278 #ifdef A_RIGHT
279     {"Right",                   A_RIGHT},
280 #endif
281 #ifdef A_TOP
282     {"Top",                     A_TOP},
283 #endif
284 #ifdef A_VERTICAL
285     {"Vertical",                A_VERTICAL},
286 #endif
287     {(char *)0,                 0}
288   };
289   gen_reps (nap, name, sizeof(int)/2);
290 }
291
292 static void gen_menu_opt_rep(const char *name)
293 {
294   static const name_attribute_pair nap[] = {
295 #ifdef O_ONEVALUE
296     {"One_Valued", O_ONEVALUE},
297 #endif
298 #ifdef O_SHOWDESC
299     {"Show_Descriptions", O_SHOWDESC},
300 #endif
301 #ifdef O_ROWMAJOR
302     {"Row_Major_Order", O_ROWMAJOR},
303 #endif
304 #ifdef O_IGNORECASE
305     {"Ignore_Case", O_IGNORECASE},
306 #endif
307 #ifdef O_SHOWMATCH
308     {"Show_Matches", O_SHOWMATCH},
309 #endif
310 #ifdef O_NONCYCLIC
311     {"Non_Cyclic", O_NONCYCLIC},
312 #endif
313     {(char *)0, 0}
314   };
315   gen_reps (nap, name, sizeof(int));
316 }
317
318 static void gen_item_opt_rep(const char *name)
319 {
320   static const name_attribute_pair nap[] = {
321 #ifdef O_SELECTABLE
322     {"Selectable", O_SELECTABLE},
323 #endif
324     {(char *)0   , 0}
325   };  
326   gen_reps (nap, name, sizeof(int));
327 }
328
329 static void gen_form_opt_rep(const char *name)
330 {
331   static const name_attribute_pair nap[] = {
332 #ifdef O_NL_OVERLOAD
333     {"NL_Overload", O_NL_OVERLOAD},
334 #endif
335 #ifdef O_BS_OVERLOAD
336     {"BS_Overload", O_BS_OVERLOAD},
337 #endif
338     {(char *)0    , 0}
339   };
340   gen_reps (nap, name, sizeof(int));
341 }
342
343 /*
344  * Generate the representation clause for the Field_Option_Set record
345  */
346 static void gen_field_opt_rep(const char *name)
347 {
348   static const name_attribute_pair nap[] = {
349 #ifdef O_VISIBLE
350     {"Visible",O_VISIBLE},
351 #endif
352 #ifdef O_ACTIVE
353     {"Active",O_ACTIVE},
354 #endif
355 #ifdef O_PUBLIC
356     {"Public",O_PUBLIC},
357 #endif
358 #ifdef O_EDIT
359     {"Edit",O_EDIT},
360 #endif
361 #ifdef O_WRAP
362     {"Wrap",O_WRAP},
363 #endif
364 #ifdef O_BLANK
365     {"Blank",O_BLANK},
366 #endif
367 #ifdef O_AUTOSKIP
368     {"Auto_Skip",O_AUTOSKIP},
369 #endif
370 #ifdef O_NULLOK
371     {"Null_Ok",O_NULLOK},
372 #endif
373 #ifdef O_PASSOK
374     {"Pass_Ok",O_PASSOK},
375 #endif
376 #ifdef O_STATIC
377     {"Static",O_STATIC},
378 #endif
379     {(char *)0, 0}
380   };
381   gen_reps (nap, name, sizeof(int));
382 }
383
384 /*
385  * Generate a single key code constant definition.
386  */
387 static void keydef(const char *name, const char *old_name, int value, int mode)
388 {
389   if (mode==0) /* Generate the new name */
390     printf("   %-30s : constant Special_Key_Code := 8#%3o#;\n",name,value);
391   else
392     { /* generate the old name, but only if it doesn't conflict with the old
393        * name (Ada95 isn't case sensitive!)
394        */
395       const char *s = old_name; const char *t = name;
396       while ( *s && *t && (toupper(*s++) == toupper(*t++)));
397       if (*s || *t)
398         printf("   %-16s : Special_Key_Code renames %s;\n",old_name,name);
399     }
400 }
401   
402 /*
403  * Generate constants for the key codes. When called with mode==0, a
404  * complete list with nice constant names in proper casing style will
405  * be generated. Otherwise a list of old (i.e. C-style) names will be
406  * generated, given that the name wasn't already defined in the "nice"
407  * list.
408  */
409 static void gen_keydefs (int mode)
410 {
411   char buf[16];
412   char obuf[16];
413   int i;
414
415 #ifdef KEY_CODE_YES
416   keydef("Key_Code_Yes","KEY_CODE_YES",KEY_CODE_YES,mode);
417 #endif
418 #ifdef KEY_MIN
419   keydef("Key_Min","KEY_MIN",KEY_MIN,mode);
420 #endif
421 #ifdef KEY_BREAK
422   keydef("Key_Break","KEY_BREAK",KEY_BREAK,mode);
423 #endif
424 #ifdef KEY_DOWN
425   keydef("Key_Cursor_Down","KEY_DOWN",KEY_DOWN,mode);
426 #endif
427 #ifdef KEY_UP
428   keydef("Key_Cursor_Up","KEY_UP",KEY_UP,mode);
429 #endif
430 #ifdef KEY_LEFT
431   keydef("Key_Cursor_Left","KEY_LEFT",KEY_LEFT,mode);
432 #endif
433 #ifdef KEY_RIGHT
434   keydef("Key_Cursor_Right","KEY_RIGHT",KEY_RIGHT,mode);
435 #endif
436 #ifdef KEY_HOME
437   keydef("Key_Home","KEY_HOME",KEY_HOME,mode);
438 #endif
439 #ifdef KEY_BACKSPACE
440   keydef("Key_Backspace","KEY_BACKSPACE",KEY_BACKSPACE,mode);
441 #endif
442 #ifdef KEY_F0
443   keydef("Key_F0","KEY_F0",KEY_F0,mode);
444 #endif
445 #ifdef KEY_F
446   for(i=1;i<=24;i++)
447     {
448       sprintf(buf ,"Key_F%d",i);
449       sprintf(obuf,"KEY_F%d",i);
450       keydef(buf,obuf,KEY_F(i),mode);
451     }
452 #endif
453 #ifdef KEY_DL
454   keydef("Key_Delete_Line","KEY_DL",KEY_DL,mode);
455 #endif
456 #ifdef KEY_IL
457   keydef("Key_Insert_Line","KEY_IL",KEY_IL,mode);
458 #endif
459 #ifdef KEY_DC
460   keydef("Key_Delete_Char","KEY_DC",KEY_DC,mode);
461 #endif
462 #ifdef KEY_IC
463   keydef("Key_Insert_Char","KEY_IC",KEY_IC,mode);
464 #endif
465 #ifdef KEY_EIC
466   keydef("Key_Exit_Insert_Mode","KEY_EIC",KEY_EIC,mode);
467 #endif
468 #ifdef KEY_CLEAR
469   keydef("Key_Clear_Screen","KEY_CLEAR",KEY_CLEAR,mode);
470 #endif
471 #ifdef KEY_EOS
472   keydef("Key_Clear_End_Of_Screen","KEY_EOS",KEY_EOS,mode);
473 #endif
474 #ifdef KEY_EOL
475   keydef("Key_Clear_End_Of_Line","KEY_EOL",KEY_EOL,mode);
476 #endif
477 #ifdef KEY_SF
478   keydef("Key_Scroll_1_Forward","KEY_SF",KEY_SF,mode);
479 #endif
480 #ifdef KEY_SR
481   keydef("Key_Scroll_1_Backward","KEY_SR",KEY_SR,mode);
482 #endif
483 #ifdef KEY_NPAGE
484   keydef("Key_Next_Page","KEY_NPAGE",KEY_NPAGE,mode);
485 #endif
486 #ifdef KEY_PPAGE
487   keydef("Key_Previous_Page","KEY_PPAGE",KEY_PPAGE,mode);
488 #endif
489 #ifdef KEY_STAB
490   keydef("Key_Set_Tab","KEY_STAB",KEY_STAB,mode);
491 #endif
492 #ifdef KEY_CTAB
493   keydef("Key_Clear_Tab","KEY_CTAB",KEY_CTAB,mode);
494 #endif
495 #ifdef KEY_CATAB
496   keydef("Key_Clear_All_Tabs","KEY_CATAB",KEY_CATAB,mode);
497 #endif
498 #ifdef KEY_ENTER
499   keydef("Key_Enter_Or_Send","KEY_ENTER",KEY_ENTER,mode);
500 #endif
501 #ifdef KEY_SRESET
502   keydef("Key_Soft_Reset","KEY_SRESET",KEY_SRESET,mode);
503 #endif
504 #ifdef KEY_RESET
505   keydef("Key_Reset","KEY_RESET",KEY_RESET,mode);
506 #endif
507 #ifdef KEY_PRINT
508   keydef("Key_Print","KEY_PRINT",KEY_PRINT,mode);
509 #endif
510 #ifdef KEY_LL
511   keydef("Key_Bottom","KEY_LL",KEY_LL,mode);
512 #endif
513 #ifdef KEY_A1
514   keydef("Key_Upper_Left_Of_Keypad","KEY_A1",KEY_A1,mode);
515 #endif
516 #ifdef KEY_A3
517   keydef("Key_Upper_Right_Of_Keypad","KEY_A3",KEY_A3,mode);
518 #endif
519 #ifdef KEY_B2
520   keydef("Key_Center_Of_Keypad","KEY_B2",KEY_B2,mode);
521 #endif
522 #ifdef KEY_C1
523   keydef("Key_Lower_Left_Of_Keypad","KEY_C1",KEY_C1,mode);
524 #endif
525 #ifdef KEY_C3
526   keydef("Key_Lower_Right_Of_Keypad","KEY_C3",KEY_C3,mode);
527 #endif
528 #ifdef KEY_BTAB
529   keydef("Key_Back_Tab","KEY_BTAB",KEY_BTAB,mode);
530 #endif
531 #ifdef KEY_BEG
532   keydef("Key_Beginning","KEY_BEG",KEY_BEG,mode);
533 #endif
534 #ifdef KEY_CANCEL
535   keydef("Key_Cancel","KEY_CANCEL",KEY_CANCEL,mode);
536 #endif
537 #ifdef KEY_CLOSE
538   keydef("Key_Close","KEY_CLOSE",KEY_CLOSE,mode);
539 #endif
540 #ifdef KEY_COMMAND
541   keydef("Key_Command","KEY_COMMAND",KEY_COMMAND,mode);
542 #endif
543 #ifdef KEY_COPY
544   keydef("Key_Copy","KEY_COPY",KEY_COPY,mode);
545 #endif
546 #ifdef KEY_CREATE
547   keydef("Key_Create","KEY_CREATE",KEY_CREATE,mode);
548 #endif
549 #ifdef KEY_END
550   keydef("Key_End","KEY_END",KEY_END,mode);
551 #endif
552 #ifdef KEY_EXIT
553   keydef("Key_Exit","KEY_EXIT",KEY_EXIT,mode);
554 #endif
555 #ifdef KEY_FIND
556   keydef("Key_Find","KEY_FIND",KEY_FIND,mode);
557 #endif
558 #ifdef KEY_HELP
559   keydef("Key_Help","KEY_HELP",KEY_HELP,mode);
560 #endif
561 #ifdef KEY_MARK
562   keydef("Key_Mark","KEY_MARK",KEY_MARK,mode);
563 #endif
564 #ifdef KEY_MESSAGE
565   keydef("Key_Message","KEY_MESSAGE",KEY_MESSAGE,mode);
566 #endif
567 #ifdef KEY_MOVE
568   keydef("Key_Move","KEY_MOVE",KEY_MOVE,mode);
569 #endif
570 #ifdef KEY_NEXT
571   keydef("Key_Next","KEY_NEXT",KEY_NEXT,mode);
572 #endif
573 #ifdef KEY_OPEN
574   keydef("Key_Open","KEY_OPEN",KEY_OPEN,mode);
575 #endif
576 #ifdef KEY_OPTIONS
577   keydef("Key_Options","KEY_OPTIONS",KEY_OPTIONS,mode);
578 #endif
579 #ifdef KEY_PREVIOUS
580   keydef("Key_Previous","KEY_PREVIOUS",KEY_PREVIOUS,mode);
581 #endif
582 #ifdef KEY_REDO
583   keydef("Key_Redo","KEY_REDO",KEY_REDO,mode);
584 #endif
585 #ifdef KEY_REFERENCE
586   keydef("Key_Reference","KEY_REFERENCE",KEY_REFERENCE,mode);
587 #endif
588 #ifdef KEY_REFRESH
589   keydef("Key_Refresh","KEY_REFRESH",KEY_REFRESH,mode);
590 #endif
591 #ifdef KEY_REPLACE
592   keydef("Key_Replace","KEY_REPLACE",KEY_REPLACE,mode);
593 #endif
594 #ifdef KEY_RESTART
595   keydef("Key_Restart","KEY_RESTART",KEY_RESTART,mode);
596 #endif
597 #ifdef KEY_RESUME
598   keydef("Key_Resume","KEY_RESUME",KEY_RESUME,mode);
599 #endif
600 #ifdef KEY_SAVE
601   keydef("Key_Save","KEY_SAVE",KEY_SAVE,mode);
602 #endif
603 #ifdef KEY_SBEG
604   keydef("Key_Shift_Begin","KEY_SBEG",KEY_SBEG,mode);
605 #endif
606 #ifdef KEY_SCANCEL
607   keydef("Key_Shift_Cancel","KEY_SCANCEL",KEY_SCANCEL,mode);
608 #endif
609 #ifdef KEY_SCOMMAND
610   keydef("Key_Shift_Command","KEY_SCOMMAND",KEY_SCOMMAND,mode);
611 #endif
612 #ifdef KEY_SCOPY
613   keydef("Key_Shift_Copy","KEY_SCOPY",KEY_SCOPY,mode);
614 #endif
615 #ifdef KEY_SCREATE
616   keydef("Key_Shift_Create","KEY_SCREATE",KEY_SCREATE,mode);
617 #endif
618 #ifdef KEY_SDC
619   keydef("Key_Shift_Delete_Char","KEY_SDC",KEY_SDC,mode);
620 #endif
621 #ifdef KEY_SDL
622   keydef("Key_Shift_Delete_Line","KEY_SDL",KEY_SDL,mode);
623 #endif
624 #ifdef KEY_SELECT
625   keydef("Key_Select","KEY_SELECT",KEY_SELECT,mode);
626 #endif
627 #ifdef KEY_SEND
628   keydef("Key_Shift_End","KEY_SEND",KEY_SEND,mode);
629 #endif
630 #ifdef KEY_SEOL
631   keydef("Key_Shift_Clear_End_Of_Line","KEY_SEOL",KEY_SEOL,mode);
632 #endif
633 #ifdef KEY_SEXIT
634   keydef("Key_Shift_Exit","KEY_SEXIT",KEY_SEXIT,mode);
635 #endif
636 #ifdef KEY_SFIND
637   keydef("Key_Shift_Find","KEY_SFIND",KEY_SFIND,mode);
638 #endif
639 #ifdef KEY_SHELP
640   keydef("Key_Shift_Help","KEY_SHELP",KEY_SHELP,mode);
641 #endif
642 #ifdef KEY_SHOME
643   keydef("Key_Shift_Home","KEY_SHOME",KEY_SHOME,mode);
644 #endif
645 #ifdef KEY_SIC
646   keydef("Key_Shift_Insert_Char","KEY_SIC",KEY_SIC,mode);
647 #endif
648 #ifdef KEY_SLEFT
649   keydef("Key_Shift_Cursor_Left","KEY_SLEFT",KEY_SLEFT,mode);
650 #endif
651 #ifdef KEY_SMESSAGE
652   keydef("Key_Shift_Message","KEY_SMESSAGE",KEY_SMESSAGE,mode);
653 #endif
654 #ifdef KEY_SMOVE
655   keydef("Key_Shift_Move","KEY_SMOVE",KEY_SMOVE,mode);
656 #endif
657 #ifdef KEY_SNEXT
658   keydef("Key_Shift_Next_Page","KEY_SNEXT",KEY_SNEXT,mode);
659 #endif
660 #ifdef KEY_SOPTIONS
661   keydef("Key_Shift_Options","KEY_SOPTIONS",KEY_SOPTIONS,mode);
662 #endif
663 #ifdef KEY_SPREVIOUS
664   keydef("Key_Shift_Previous_Page","KEY_SPREVIOUS",KEY_SPREVIOUS,mode);
665 #endif
666 #ifdef KEY_SPRINT
667   keydef("Key_Shift_Print","KEY_SPRINT",KEY_SPRINT,mode);
668 #endif
669 #ifdef KEY_SREDO
670   keydef("Key_Shift_Redo","KEY_SREDO",KEY_SREDO,mode);
671 #endif
672 #ifdef KEY_SREPLACE
673   keydef("Key_Shift_Replace","KEY_SREPLACE",KEY_SREPLACE,mode);
674 #endif
675 #ifdef KEY_SRIGHT
676   keydef("Key_Shift_Cursor_Right","KEY_SRIGHT",KEY_SRIGHT,mode);
677 #endif
678 #ifdef KEY_SRSUME
679   keydef("Key_Shift_Resume","KEY_SRSUME",KEY_SRSUME,mode);
680 #endif
681 #ifdef KEY_SSAVE
682   keydef("Key_Shift_Save","KEY_SSAVE",KEY_SSAVE,mode);
683 #endif
684 #ifdef KEY_SSUSPEND
685   keydef("Key_Shift_Suspend","KEY_SSUSPEND",KEY_SSUSPEND,mode);
686 #endif
687 #ifdef KEY_SUNDO
688   keydef("Key_Shift_Undo","KEY_SUNDO",KEY_SUNDO,mode);
689 #endif
690 #ifdef KEY_SUSPEND
691   keydef("Key_Suspend","KEY_SUSPEND",KEY_SUSPEND,mode);
692 #endif
693 #ifdef KEY_UNDO
694   keydef("Key_Undo","KEY_UNDO",KEY_UNDO,mode);
695 #endif
696 #ifdef KEY_MOUSE
697   keydef("Key_Mouse","KEY_MOUSE",KEY_MOUSE,mode);
698 #endif  
699 #ifdef KEY_RESIZE
700   keydef("Key_Resize","KEY_RESIZE",KEY_RESIZE,mode);
701 #endif  
702 }
703
704 /*
705  * Generate a constant with the given name. The second parameter
706  * is a reference to the ACS character in the acs_map[] array and
707  * will be translated into an index.
708  */
709 static void acs_def (const char *name, chtype *a)
710 {
711   int c = a - &acs_map[0];
712   printf("   %-24s : constant Character := ",name);
713   if (isprint(c) && (c!='`'))
714     printf("'%c';\n",c);
715   else
716     printf("Character'Val (%d);\n",c);
717 }
718
719 /*
720  * Generate the constants for the ACS characters
721  */
722 static void gen_acs (void)
723 {
724 #ifdef ACS_ULCORNER
725   acs_def("ACS_Upper_Left_Corner",&ACS_ULCORNER);
726 #endif
727 #ifdef ACS_LLCORNER
728   acs_def("ACS_Lower_Left_Corner",&ACS_LLCORNER);
729 #endif
730 #ifdef ACS_URCORNER
731   acs_def("ACS_Upper_Right_Corner",&ACS_URCORNER);
732 #endif
733 #ifdef ACS_LRCORNER
734   acs_def("ACS_Lower_Right_Corner",&ACS_LRCORNER);
735 #endif
736 #ifdef ACS_LTEE
737   acs_def("ACS_Left_Tee",&ACS_LTEE);
738 #endif
739 #ifdef ACS_RTEE
740   acs_def("ACS_Right_Tee",&ACS_RTEE);
741 #endif
742 #ifdef ACS_BTEE
743   acs_def("ACS_Bottom_Tee",&ACS_BTEE);
744 #endif
745 #ifdef ACS_TTEE
746   acs_def("ACS_Top_Tee",&ACS_TTEE);
747 #endif
748 #ifdef ACS_HLINE
749   acs_def("ACS_Horizontal_Line",&ACS_HLINE);
750 #endif
751 #ifdef ACS_VLINE
752   acs_def("ACS_Vertical_Line",&ACS_VLINE);
753 #endif
754 #ifdef ACS_PLUS
755   acs_def("ACS_Plus_Symbol",&ACS_PLUS);
756 #endif
757 #ifdef ACS_S1
758   acs_def("ACS_Scan_Line_1",&ACS_S1);
759 #endif
760 #ifdef ACS_S9
761   acs_def("ACS_Scan_Line_9",&ACS_S9);
762 #endif
763 #ifdef ACS_DIAMOND
764   acs_def("ACS_Diamond",&ACS_DIAMOND);
765 #endif
766 #ifdef ACS_CKBOARD
767   acs_def("ACS_Checker_Board",&ACS_CKBOARD);
768 #endif
769 #ifdef ACS_DEGREE
770   acs_def("ACS_Degree",&ACS_DEGREE);
771 #endif
772 #ifdef ACS_PLMINUS
773   acs_def("ACS_Plus_Minus",&ACS_PLMINUS);
774 #endif
775 #ifdef ACS_BULLET
776   acs_def("ACS_Bullet",&ACS_BULLET);
777 #endif
778 #ifdef ACS_LARROW
779   acs_def("ACS_Left_Arrow",&ACS_LARROW);
780 #endif
781 #ifdef ACS_RARROW
782   acs_def("ACS_Right_Arrow",&ACS_RARROW);
783 #endif
784 #ifdef ACS_DARROW
785   acs_def("ACS_Down_Arrow",&ACS_DARROW);
786 #endif
787 #ifdef ACS_UARROW
788   acs_def("ACS_Up_Arrow",&ACS_UARROW);
789 #endif
790 #ifdef ACS_BOARD
791   acs_def("ACS_Board_Of_Squares",&ACS_BOARD);
792 #endif
793 #ifdef ACS_LANTERN
794   acs_def("ACS_Lantern",&ACS_LANTERN);
795 #endif
796 #ifdef ACS_BLOCK
797   acs_def("ACS_Solid_Block",&ACS_BLOCK);
798 #endif
799 #ifdef ACS_S3
800   acs_def("ACS_Scan_Line_3",&ACS_S3);
801 #endif
802 #ifdef ACS_S7
803   acs_def("ACS_Scan_Line_7",&ACS_S7);
804 #endif
805 #ifdef ACS_LEQUAL
806   acs_def("ACS_Less_Or_Equal",&ACS_LEQUAL);
807 #endif
808 #ifdef ACS_GEQUAL
809   acs_def("ACS_Greater_Or_Equal",&ACS_GEQUAL);
810 #endif
811 #ifdef ACS_PI
812   acs_def("ACS_PI",&ACS_PI);
813 #endif
814 #ifdef ACS_NEQUAL
815   acs_def("ACS_Not_Equal",&ACS_NEQUAL);
816 #endif
817 #ifdef ACS_STERLING
818   acs_def("ACS_Sterling",&ACS_STERLING);
819 #endif
820 }
821
822 /*
823  * Output some comment lines indicating that the file is generated.
824  * The name parameter is the name of the facility to be used in
825  * the comment.
826  */
827 static void prologue(const char *name)
828 {
829   printf("--  %s binding.\n",name);
830   printf("--  This module is generated. Please don't change it manually!\n");
831   printf("--  Run the generator instead.\n--  |");
832
833   printf("define(`M4_BIT_ORDER',`%s_Order_First')",little_endian ? "Low":"High");
834 }
835
836 /*
837  * Write the prologue for the curses facility and make sure that
838  * KEY_MIN and KEY_MAX are defined for the rest of this source.
839  */
840 static void basedefs (void)
841 {
842   prologue("curses");
843 #ifndef KEY_MAX
844 #  define KEY_MAX 0777
845 #endif
846   printf("define(`M4_KEY_MAX',`8#%o#')",KEY_MAX);
847 #ifndef KEY_MIN
848 #  define KEY_MIN 0401
849 #endif
850   if (KEY_MIN == 256) {
851     fprintf(stderr,"Unexpected value for KEY_MIN: %d\n",KEY_MIN);
852     exit(1);
853   }
854   printf("define(`M4_SPECIAL_FIRST',`8#%o#')",KEY_MIN - 1);
855 }
856
857 /*
858  * Write out the comment lines for the menu facility
859  */
860 static void menu_basedefs (void)
861 {
862   prologue("menu");
863 }
864
865 /*
866  * Write out the comment lines for the form facility
867  */
868 static void form_basedefs (void)
869 {
870   prologue("form");
871 }
872
873 /*
874  * Write out the comment lines for the mouse facility
875  */
876 static void mouse_basedefs(void)
877 {
878   prologue("mouse");
879 }
880
881 /*
882  * Write the definition of a single color
883  */
884 static void color_def (const char *name, int value)
885 {
886   printf("   %-8s : constant Color_Number := %d;\n",name,value);
887 }
888
889 /*
890  * Generate all color definitions
891  */
892 static void gen_color (void)
893 {
894 #ifdef COLOR_BLACK
895   color_def ("Black",COLOR_BLACK);
896 #endif
897 #ifdef COLOR_RED
898   color_def ("Red",COLOR_RED);
899 #endif
900 #ifdef COLOR_GREEN
901   color_def ("Green",COLOR_GREEN);
902 #endif
903 #ifdef COLOR_YELLOW
904   color_def ("Yellow",COLOR_YELLOW);
905 #endif
906 #ifdef COLOR_BLUE
907   color_def ("Blue",COLOR_BLUE);
908 #endif
909 #ifdef COLOR_MAGENTA
910   color_def ("Magenta",COLOR_MAGENTA);
911 #endif
912 #ifdef COLOR_CYAN
913   color_def ("Cyan",COLOR_CYAN);
914 #endif
915 #ifdef COLOR_WHITE
916   color_def ("White",COLOR_WHITE);
917 #endif
918 }
919
920 /*
921  * Generate the linker options for the base facility
922  */
923 static void gen_linkopts (void)
924 {
925    printf("   pragma Linker_Options (\"-lncurses\");\n");
926 }
927
928 /*
929  * Generate the linker options for the menu facility
930  */
931 static void gen_menu_linkopts (void)
932 {
933    printf("   pragma Linker_Options (\"-lmenu\");\n");
934 }
935
936 /*
937  * Generate the linker options for the form facility
938  */
939 static void gen_form_linkopts (void)
940 {
941    printf("   pragma Linker_Options (\"-lform\");\n");
942 }
943
944 /*
945  * Generate the linker options for the panel facility
946  */
947 static void gen_panel_linkopts (void)
948 {
949    printf("   pragma Linker_Options (\"-lpanel\");\n");
950 }
951
952 static void gen_version_info (void)
953 {
954    printf("   NC_Major_Version : constant := %d; --  Major version of ncurses library\n", NCURSES_VERSION_MAJOR);
955    printf("   NC_Minor_Version : constant := %d; --  Minor version of ncurses library\n", NCURSES_VERSION_MINOR);
956    printf("   NC_Version : constant String := %c%d.%d%c;  --  Version of ncurses library\n", '"',NCURSES_VERSION_MAJOR,NCURSES_VERSION_MINOR,'"');
957 }
958
959 /*
960  * main() expects two arguments on the commandline, both single characters.
961  * The first character denotes the facility for which we generate output.
962  * Possible values are
963  *   B - Base
964  *   M - Menus
965  *   F - Forms
966  *   P - Pointer Device (Mouse)
967  *
968  * The second character then denotes the specific output that should be
969  * generated for the selected facility.
970  */
971 int main(int argc, char *argv[])
972 {
973   int x = 0x12345678;
974   char *s = (char *)&x;
975
976   if (*s == 0x78)
977     little_endian = 1;
978
979   if (argc!=3)
980     exit(1);
981
982   switch(argv[1][0])
983     {
984     case 'B': /* The Base facility */
985       switch(argv[2][0])
986         {
987         case 'A': /* chtype translation into Ada95 record type */
988           gen_attr_set("Character_Attribute_Set");
989           break;
990         case 'K': /* translation of keycodes */
991           gen_keydefs(0);
992           break;
993         case 'B': /* write some initial comment lines */
994           basedefs();
995           break;
996         case 'C': /* generate color constants */
997           gen_color();
998           break;
999         case 'M': /* generate constants for the ACS characters */
1000           gen_acs();
1001           break;
1002         case 'L': /* generate the Linker_Options pragma */
1003           gen_linkopts();
1004           break;
1005         case 'O': /* generate definitions of the old key code names */
1006           gen_keydefs(1);
1007           break;
1008         case 'R': /* generate representation clause for Attributed character */
1009           gen_chtype_rep("Attributed_Character");
1010           break;
1011         case 'V': /* generate version info */
1012           gen_version_info();
1013           break;
1014         default:
1015           break;
1016         }
1017       break;
1018     case 'M': /* The Menu facility */
1019       switch(argv[2][0])
1020         {
1021         case 'R': /* generate representation clause for Menu_Option_Set */
1022           gen_menu_opt_rep("Menu_Option_Set");
1023           break;
1024         case 'B': /* write some initial comment lines */
1025           menu_basedefs();
1026           break;
1027         case 'L': /* generate the Linker_Options pragma */
1028           gen_menu_linkopts();
1029           break;
1030         case 'I': /* generate representation clause for Item_Option_Set */
1031           gen_item_opt_rep("Item_Option_Set");
1032           break;
1033         default:
1034           break;
1035         }
1036       break;
1037     case 'F': /* The Form facility */
1038       switch(argv[2][0])
1039         {
1040         case 'R': /* generate representation clause for Form_Option_Set */
1041           gen_form_opt_rep("Form_Option_Set");
1042           break;
1043         case 'B': /* write some initial comment lines */
1044           form_basedefs();
1045           break;
1046         case 'L': /* generate the Linker_Options pragma */
1047           gen_form_linkopts();
1048           break;
1049         case 'I': /* generate representation clause for Field_Option_Set */
1050           gen_field_opt_rep("Field_Option_Set");
1051           break;
1052         default:
1053           break;
1054         }
1055       break;
1056     case 'P': /* The Pointer(=Mouse) facility */
1057       switch(argv[2][0])
1058         {
1059         case 'B': /* write some initial comment lines */
1060           mouse_basedefs();
1061           break;
1062         case 'M': /* generate representation clause for Mouse_Event */
1063           gen_mrep_rep("Mouse_Event");
1064           break;
1065         case 'L': /* generate the Linker_Options pragma */
1066           gen_panel_linkopts();
1067           break;
1068         default:
1069           break;
1070         }
1071         break;
1072     default:
1073       break;
1074     }
1075   return 0;
1076 }