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