1 /****************************************************************************
2 * Copyright (c) 1998,2009,2010 Free Software Foundation, Inc. *
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: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
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. *
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 *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Juergen Pfeifer, 1996 *
31 ****************************************************************************/
35 $Id: gen.c,v 1.54 2010/09/04 21:19:50 tom Exp $
36 --------------------------------------------------------------------------*/
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.
45 #include <ncurses_cfg.h>
48 #define HAVE_USE_DEFAULT_COLORS 1
60 #define UChar(c) ((unsigned char)(c))
61 #define RES_NAME "Reserved"
63 static const char *model = "";
64 static int little_endian = 0;
74 find_pos(char *s, unsigned len, int *low, int *high)
80 *low = (int)(8 * len);
82 for (i = 0; i < len; i++, s++)
86 for (j = 0; j < 8 * sizeof(char); j++)
89 if (((little_endian && ((*s) & 0x01)) ||
90 (!little_endian && ((*s) & 0x80))))
104 *s = (char)(*s << 1);
111 return (*high >= 0 && (*low <= *high)) ? *low : -1;
115 * This helper routine generates a representation clause for a
116 * record type defined in the binding.
117 * We are only dealing with record types which are of 32 or 16
118 * bit size, i.e. they fit into an (u)int or a (u)short.
122 const name_attribute_pair * nap, /* array of name_attribute_pair records */
123 const char *name, /* name of the represented record type */
124 int len, /* size of the record in bytes */
127 int i, n, l, cnt = 0, low, high;
128 int width = strlen(RES_NAME) + 3;
130 unsigned long mask = 0;
134 for (i = 0; nap[i].name != (char *)0; i++)
137 l = (int)strlen(nap[i].name);
143 printf(" type %s is\n", name);
145 for (i = 0; nap[i].name != (char *)0; i++)
147 printf(" %-*s : Boolean;\n", width, nap[i].name);
149 printf(" end record;\n");
150 printf(" pragma Convention (C, %s);\n\n", name);
152 printf(" for %s use\n", name);
155 for (i = 0; nap[i].name != (char *)0; i++)
159 l = find_pos((char *)&a, sizeof(a), &low, &high);
161 printf(" %-*s at 0 range %2d .. %2d;\n", width, nap[i].name,
162 low - bias, high - bias);
166 printf(" end record;\n");
167 printf(" for %s'Size use %d;\n", name, 8 * len);
168 printf(" -- Please note: this rep. clause is generated and may be\n");
169 printf(" -- different on your system.");
173 chtype_rep(const char *name, attr_t mask)
175 attr_t x = (attr_t)-1;
178 int l = find_pos((char *)&t, sizeof(t), &low, &high);
181 printf(" %-5s at 0 range %2d .. %2d;\n", name, low, high);
185 gen_chtype_rep(const char *name)
187 printf(" for %s use\n record\n", name);
188 chtype_rep("Ch", A_CHARTEXT);
189 chtype_rep("Color", A_COLOR);
190 chtype_rep("Attr", (A_ATTRIBUTES & ~A_COLOR));
191 printf(" end record;\n for %s'Size use %ld;\n",
192 name, (long)(8 * sizeof(chtype)));
194 printf(" -- Please note: this rep. clause is generated and may be\n");
195 printf(" -- different on your system.\n");
199 mrep_rep(const char *name, void *rec)
202 int l = find_pos((char *)rec, sizeof(MEVENT), &low, &high);
205 printf(" %-7s at 0 range %3d .. %3d;\n", name, low, high);
209 gen_mrep_rep(const char *name)
213 printf(" for %s use\n record\n", name);
215 memset(&x, 0, sizeof(x));
219 memset(&x, 0, sizeof(x));
223 memset(&x, 0, sizeof(x));
227 memset(&x, 0, sizeof(x));
231 memset(&x, 0, sizeof(x));
232 x.bstate = (mmask_t) - 1;
233 mrep_rep("Bstate", &x);
235 printf(" end record;\n");
236 printf(" -- Please note: this rep. clause is generated and may be\n");
237 printf(" -- different on your system.\n");
241 gen_attr_set(const char *name)
243 /* All of the A_xxx symbols are defined in ncurses, but not all are nonzero
244 * if "configure --enable-widec" is specified.
246 static const name_attribute_pair nap[] =
249 {"Stand_Out", A_STANDOUT},
252 {"Under_Line", A_UNDERLINE},
255 {"Reverse_Video", A_REVERSE},
261 {"Dim_Character", A_DIM},
264 {"Bold_Character", A_BOLD},
267 {"Alternate_Character_Set", A_ALTCHARSET},
270 {"Invisible_Character", A_INVIS},
273 {"Protected_Character", A_PROTECT},
276 {"Horizontal", A_HORIZONTAL},
291 {"Vertical", A_VERTICAL},
295 chtype attr = A_ATTRIBUTES & ~A_COLOR;
300 for (i = 0; i < (int)(8 * sizeof(chtype)); i++)
315 gen_reps(nap, name, (len + 7) / 8, little_endian ? start : 0);
319 gen_trace(const char *name)
321 static const name_attribute_pair nap[] =
323 {"Times", TRACE_TIMES},
324 {"Tputs", TRACE_TPUTS},
325 {"Update", TRACE_UPDATE},
326 {"Cursor_Move", TRACE_MOVE},
327 {"Character_Output", TRACE_CHARPUT},
328 {"Calls", TRACE_CALLS},
329 {"Virtual_Puts", TRACE_VIRTPUT},
330 {"Input_Events", TRACE_IEVENT},
331 {"TTY_State", TRACE_BITS},
332 {"Internal_Calls", TRACE_ICALLS},
333 {"Character_Calls", TRACE_CCALLS},
334 {"Termcap_TermInfo", TRACE_DATABASE},
337 gen_reps(nap, name, sizeof(int), 0);
341 gen_menu_opt_rep(const char *name)
343 static const name_attribute_pair nap[] =
346 {"One_Valued", O_ONEVALUE},
349 {"Show_Descriptions", O_SHOWDESC},
352 {"Row_Major_Order", O_ROWMAJOR},
355 {"Ignore_Case", O_IGNORECASE},
358 {"Show_Matches", O_SHOWMATCH},
361 {"Non_Cyclic", O_NONCYCLIC},
365 gen_reps(nap, name, sizeof(int), 0);
369 gen_item_opt_rep(const char *name)
371 static const name_attribute_pair nap[] =
374 {"Selectable", O_SELECTABLE},
378 gen_reps(nap, name, sizeof(int), 0);
382 gen_form_opt_rep(const char *name)
384 static const name_attribute_pair nap[] =
387 {"NL_Overload", O_NL_OVERLOAD},
390 {"BS_Overload", O_BS_OVERLOAD},
394 gen_reps(nap, name, sizeof(int), 0);
398 * Generate the representation clause for the Field_Option_Set record
401 gen_field_opt_rep(const char *name)
403 static const name_attribute_pair nap[] =
406 {"Visible", O_VISIBLE},
409 {"Active", O_ACTIVE},
412 {"Public", O_PUBLIC},
424 {"Auto_Skip", O_AUTOSKIP},
427 {"Null_Ok", O_NULLOK},
430 {"Pass_Ok", O_PASSOK},
433 {"Static", O_STATIC},
437 gen_reps(nap, name, sizeof(int), 0);
441 * Generate a single key code constant definition.
444 keydef(const char *name, const char *old_name, int value, int mode)
446 if (mode == 0) /* Generate the new name */
447 printf(" %-30s : constant Special_Key_Code := 8#%3o#;\n", name, value);
450 const char *s = old_name;
451 const char *t = name;
453 /* generate the old name, but only if it doesn't conflict with the old
454 * name (Ada95 isn't case sensitive!)
456 while (*s && *t && (toupper(UChar(*s++)) == toupper(UChar(*t++))));
458 printf(" %-16s : Special_Key_Code renames %s;\n", old_name, name);
463 * Generate constants for the key codes. When called with mode==0, a
464 * complete list with nice constant names in proper casing style will
465 * be generated. Otherwise a list of old (i.e. C-style) names will be
466 * generated, given that the name wasn't already defined in the "nice"
470 gen_keydefs(int mode)
477 keydef("Key_Code_Yes", "KEY_CODE_YES", KEY_CODE_YES, mode);
480 keydef("Key_Min", "KEY_MIN", KEY_MIN, mode);
483 keydef("Key_Break", "KEY_BREAK", KEY_BREAK, mode);
486 keydef("Key_Cursor_Down", "KEY_DOWN", KEY_DOWN, mode);
489 keydef("Key_Cursor_Up", "KEY_UP", KEY_UP, mode);
492 keydef("Key_Cursor_Left", "KEY_LEFT", KEY_LEFT, mode);
495 keydef("Key_Cursor_Right", "KEY_RIGHT", KEY_RIGHT, mode);
498 keydef("Key_Home", "KEY_HOME", KEY_HOME, mode);
501 keydef("Key_Backspace", "KEY_BACKSPACE", KEY_BACKSPACE, mode);
504 keydef("Key_F0", "KEY_F0", KEY_F0, mode);
507 for (i = 1; i <= 24; i++)
509 sprintf(buf, "Key_F%d", i);
510 sprintf(obuf, "KEY_F%d", i);
511 keydef(buf, obuf, KEY_F(i), mode);
515 keydef("Key_Delete_Line", "KEY_DL", KEY_DL, mode);
518 keydef("Key_Insert_Line", "KEY_IL", KEY_IL, mode);
521 keydef("Key_Delete_Char", "KEY_DC", KEY_DC, mode);
524 keydef("Key_Insert_Char", "KEY_IC", KEY_IC, mode);
527 keydef("Key_Exit_Insert_Mode", "KEY_EIC", KEY_EIC, mode);
530 keydef("Key_Clear_Screen", "KEY_CLEAR", KEY_CLEAR, mode);
533 keydef("Key_Clear_End_Of_Screen", "KEY_EOS", KEY_EOS, mode);
536 keydef("Key_Clear_End_Of_Line", "KEY_EOL", KEY_EOL, mode);
539 keydef("Key_Scroll_1_Forward", "KEY_SF", KEY_SF, mode);
542 keydef("Key_Scroll_1_Backward", "KEY_SR", KEY_SR, mode);
545 keydef("Key_Next_Page", "KEY_NPAGE", KEY_NPAGE, mode);
548 keydef("Key_Previous_Page", "KEY_PPAGE", KEY_PPAGE, mode);
551 keydef("Key_Set_Tab", "KEY_STAB", KEY_STAB, mode);
554 keydef("Key_Clear_Tab", "KEY_CTAB", KEY_CTAB, mode);
557 keydef("Key_Clear_All_Tabs", "KEY_CATAB", KEY_CATAB, mode);
560 keydef("Key_Enter_Or_Send", "KEY_ENTER", KEY_ENTER, mode);
563 keydef("Key_Soft_Reset", "KEY_SRESET", KEY_SRESET, mode);
566 keydef("Key_Reset", "KEY_RESET", KEY_RESET, mode);
569 keydef("Key_Print", "KEY_PRINT", KEY_PRINT, mode);
572 keydef("Key_Bottom", "KEY_LL", KEY_LL, mode);
575 keydef("Key_Upper_Left_Of_Keypad", "KEY_A1", KEY_A1, mode);
578 keydef("Key_Upper_Right_Of_Keypad", "KEY_A3", KEY_A3, mode);
581 keydef("Key_Center_Of_Keypad", "KEY_B2", KEY_B2, mode);
584 keydef("Key_Lower_Left_Of_Keypad", "KEY_C1", KEY_C1, mode);
587 keydef("Key_Lower_Right_Of_Keypad", "KEY_C3", KEY_C3, mode);
590 keydef("Key_Back_Tab", "KEY_BTAB", KEY_BTAB, mode);
593 keydef("Key_Beginning", "KEY_BEG", KEY_BEG, mode);
596 keydef("Key_Cancel", "KEY_CANCEL", KEY_CANCEL, mode);
599 keydef("Key_Close", "KEY_CLOSE", KEY_CLOSE, mode);
602 keydef("Key_Command", "KEY_COMMAND", KEY_COMMAND, mode);
605 keydef("Key_Copy", "KEY_COPY", KEY_COPY, mode);
608 keydef("Key_Create", "KEY_CREATE", KEY_CREATE, mode);
611 keydef("Key_End", "KEY_END", KEY_END, mode);
614 keydef("Key_Exit", "KEY_EXIT", KEY_EXIT, mode);
617 keydef("Key_Find", "KEY_FIND", KEY_FIND, mode);
620 keydef("Key_Help", "KEY_HELP", KEY_HELP, mode);
623 keydef("Key_Mark", "KEY_MARK", KEY_MARK, mode);
626 keydef("Key_Message", "KEY_MESSAGE", KEY_MESSAGE, mode);
629 keydef("Key_Move", "KEY_MOVE", KEY_MOVE, mode);
632 keydef("Key_Next", "KEY_NEXT", KEY_NEXT, mode);
635 keydef("Key_Open", "KEY_OPEN", KEY_OPEN, mode);
638 keydef("Key_Options", "KEY_OPTIONS", KEY_OPTIONS, mode);
641 keydef("Key_Previous", "KEY_PREVIOUS", KEY_PREVIOUS, mode);
644 keydef("Key_Redo", "KEY_REDO", KEY_REDO, mode);
647 keydef("Key_Reference", "KEY_REFERENCE", KEY_REFERENCE, mode);
650 keydef("Key_Refresh", "KEY_REFRESH", KEY_REFRESH, mode);
653 keydef("Key_Replace", "KEY_REPLACE", KEY_REPLACE, mode);
656 keydef("Key_Restart", "KEY_RESTART", KEY_RESTART, mode);
659 keydef("Key_Resume", "KEY_RESUME", KEY_RESUME, mode);
662 keydef("Key_Save", "KEY_SAVE", KEY_SAVE, mode);
665 keydef("Key_Shift_Begin", "KEY_SBEG", KEY_SBEG, mode);
668 keydef("Key_Shift_Cancel", "KEY_SCANCEL", KEY_SCANCEL, mode);
671 keydef("Key_Shift_Command", "KEY_SCOMMAND", KEY_SCOMMAND, mode);
674 keydef("Key_Shift_Copy", "KEY_SCOPY", KEY_SCOPY, mode);
677 keydef("Key_Shift_Create", "KEY_SCREATE", KEY_SCREATE, mode);
680 keydef("Key_Shift_Delete_Char", "KEY_SDC", KEY_SDC, mode);
683 keydef("Key_Shift_Delete_Line", "KEY_SDL", KEY_SDL, mode);
686 keydef("Key_Select", "KEY_SELECT", KEY_SELECT, mode);
689 keydef("Key_Shift_End", "KEY_SEND", KEY_SEND, mode);
692 keydef("Key_Shift_Clear_End_Of_Line", "KEY_SEOL", KEY_SEOL, mode);
695 keydef("Key_Shift_Exit", "KEY_SEXIT", KEY_SEXIT, mode);
698 keydef("Key_Shift_Find", "KEY_SFIND", KEY_SFIND, mode);
701 keydef("Key_Shift_Help", "KEY_SHELP", KEY_SHELP, mode);
704 keydef("Key_Shift_Home", "KEY_SHOME", KEY_SHOME, mode);
707 keydef("Key_Shift_Insert_Char", "KEY_SIC", KEY_SIC, mode);
710 keydef("Key_Shift_Cursor_Left", "KEY_SLEFT", KEY_SLEFT, mode);
713 keydef("Key_Shift_Message", "KEY_SMESSAGE", KEY_SMESSAGE, mode);
716 keydef("Key_Shift_Move", "KEY_SMOVE", KEY_SMOVE, mode);
719 keydef("Key_Shift_Next_Page", "KEY_SNEXT", KEY_SNEXT, mode);
722 keydef("Key_Shift_Options", "KEY_SOPTIONS", KEY_SOPTIONS, mode);
725 keydef("Key_Shift_Previous_Page", "KEY_SPREVIOUS", KEY_SPREVIOUS, mode);
728 keydef("Key_Shift_Print", "KEY_SPRINT", KEY_SPRINT, mode);
731 keydef("Key_Shift_Redo", "KEY_SREDO", KEY_SREDO, mode);
734 keydef("Key_Shift_Replace", "KEY_SREPLACE", KEY_SREPLACE, mode);
737 keydef("Key_Shift_Cursor_Right", "KEY_SRIGHT", KEY_SRIGHT, mode);
740 keydef("Key_Shift_Resume", "KEY_SRSUME", KEY_SRSUME, mode);
743 keydef("Key_Shift_Save", "KEY_SSAVE", KEY_SSAVE, mode);
746 keydef("Key_Shift_Suspend", "KEY_SSUSPEND", KEY_SSUSPEND, mode);
749 keydef("Key_Shift_Undo", "KEY_SUNDO", KEY_SUNDO, mode);
752 keydef("Key_Suspend", "KEY_SUSPEND", KEY_SUSPEND, mode);
755 keydef("Key_Undo", "KEY_UNDO", KEY_UNDO, mode);
758 keydef("Key_Mouse", "KEY_MOUSE", KEY_MOUSE, mode);
761 keydef("Key_Resize", "KEY_RESIZE", KEY_RESIZE, mode);
766 * Generate a constant with the given name. The second parameter
767 * is a reference to the ACS character in the acs_map[] array and
768 * will be translated into an index.
771 acs_def(const char *name, chtype *a)
773 int c = a - &acs_map[0];
775 printf(" %-24s : constant Character := ", name);
776 if (isprint(UChar(c)) && (c != '`'))
777 printf("'%c';\n", c);
779 printf("Character'Val (%d);\n", c);
783 * Generate the constants for the ACS characters
788 printf(" type C_ACS_Map is array (Character'Val (0) .. Character'Val (127))\n");
789 printf(" of Attributed_Character;\n");
790 #if USE_REENTRANT || BROKEN_LINKER
791 printf(" type C_ACS_Ptr is access C_ACS_Map;\n");
792 printf(" function ACS_Map return C_ACS_Ptr;\n");
793 printf(" pragma Import (C, ACS_Map, \""
797 printf(" ACS_Map : C_ACS_Map;\n");
798 printf(" pragma Import (C, ACS_Map, \"acs_map\");\n");
802 printf(" -- Constants for several characters from the Alternate Character Set\n");
803 printf(" -- You must use these constants as indices into the ACS_Map array\n");
804 printf(" -- to get the corresponding attributed character at runtime.\n");
808 acs_def("ACS_Upper_Left_Corner", &ACS_ULCORNER);
811 acs_def("ACS_Lower_Left_Corner", &ACS_LLCORNER);
814 acs_def("ACS_Upper_Right_Corner", &ACS_URCORNER);
817 acs_def("ACS_Lower_Right_Corner", &ACS_LRCORNER);
820 acs_def("ACS_Left_Tee", &ACS_LTEE);
823 acs_def("ACS_Right_Tee", &ACS_RTEE);
826 acs_def("ACS_Bottom_Tee", &ACS_BTEE);
829 acs_def("ACS_Top_Tee", &ACS_TTEE);
832 acs_def("ACS_Horizontal_Line", &ACS_HLINE);
835 acs_def("ACS_Vertical_Line", &ACS_VLINE);
838 acs_def("ACS_Plus_Symbol", &ACS_PLUS);
841 acs_def("ACS_Scan_Line_1", &ACS_S1);
844 acs_def("ACS_Scan_Line_9", &ACS_S9);
847 acs_def("ACS_Diamond", &ACS_DIAMOND);
850 acs_def("ACS_Checker_Board", &ACS_CKBOARD);
853 acs_def("ACS_Degree", &ACS_DEGREE);
856 acs_def("ACS_Plus_Minus", &ACS_PLMINUS);
859 acs_def("ACS_Bullet", &ACS_BULLET);
862 acs_def("ACS_Left_Arrow", &ACS_LARROW);
865 acs_def("ACS_Right_Arrow", &ACS_RARROW);
868 acs_def("ACS_Down_Arrow", &ACS_DARROW);
871 acs_def("ACS_Up_Arrow", &ACS_UARROW);
874 acs_def("ACS_Board_Of_Squares", &ACS_BOARD);
877 acs_def("ACS_Lantern", &ACS_LANTERN);
880 acs_def("ACS_Solid_Block", &ACS_BLOCK);
883 acs_def("ACS_Scan_Line_3", &ACS_S3);
886 acs_def("ACS_Scan_Line_7", &ACS_S7);
889 acs_def("ACS_Less_Or_Equal", &ACS_LEQUAL);
892 acs_def("ACS_Greater_Or_Equal", &ACS_GEQUAL);
895 acs_def("ACS_PI", &ACS_PI);
898 acs_def("ACS_Not_Equal", &ACS_NEQUAL);
901 acs_def("ACS_Sterling", &ACS_STERLING);
905 #define GEN_EVENT(name,value) \
906 printf(" %-25s : constant Event_Mask := 8#%011lo#;\n", \
909 #define GEN_MEVENT(name) \
910 printf(" %-25s : constant Event_Mask := 8#%011lo#;\n", \
914 gen_mouse_events(void)
921 #ifdef BUTTON1_RELEASED
922 GEN_MEVENT(BUTTON1_RELEASED);
923 all1 |= BUTTON1_RELEASED;
925 #ifdef BUTTON1_PRESSED
926 GEN_MEVENT(BUTTON1_PRESSED);
927 all1 |= BUTTON1_PRESSED;
929 #ifdef BUTTON1_CLICKED
930 GEN_MEVENT(BUTTON1_CLICKED);
931 all1 |= BUTTON1_CLICKED;
933 #ifdef BUTTON1_DOUBLE_CLICKED
934 GEN_MEVENT(BUTTON1_DOUBLE_CLICKED);
935 all1 |= BUTTON1_DOUBLE_CLICKED;
937 #ifdef BUTTON1_TRIPLE_CLICKED
938 GEN_MEVENT(BUTTON1_TRIPLE_CLICKED);
939 all1 |= BUTTON1_TRIPLE_CLICKED;
941 #ifdef BUTTON1_RESERVED_EVENT
942 GEN_MEVENT(BUTTON1_RESERVED_EVENT);
943 all1 |= BUTTON1_RESERVED_EVENT;
945 #ifdef BUTTON2_RELEASED
946 GEN_MEVENT(BUTTON2_RELEASED);
947 all2 |= BUTTON2_RELEASED;
949 #ifdef BUTTON2_PRESSED
950 GEN_MEVENT(BUTTON2_PRESSED);
951 all2 |= BUTTON2_PRESSED;
953 #ifdef BUTTON2_CLICKED
954 GEN_MEVENT(BUTTON2_CLICKED);
955 all2 |= BUTTON2_CLICKED;
957 #ifdef BUTTON2_DOUBLE_CLICKED
958 GEN_MEVENT(BUTTON2_DOUBLE_CLICKED);
959 all2 |= BUTTON2_DOUBLE_CLICKED;
961 #ifdef BUTTON2_TRIPLE_CLICKED
962 GEN_MEVENT(BUTTON2_TRIPLE_CLICKED);
963 all2 |= BUTTON2_TRIPLE_CLICKED;
965 #ifdef BUTTON2_RESERVED_EVENT
966 GEN_MEVENT(BUTTON2_RESERVED_EVENT);
967 all2 |= BUTTON2_RESERVED_EVENT;
969 #ifdef BUTTON3_RELEASED
970 GEN_MEVENT(BUTTON3_RELEASED);
971 all3 |= BUTTON3_RELEASED;
973 #ifdef BUTTON3_PRESSED
974 GEN_MEVENT(BUTTON3_PRESSED);
975 all3 |= BUTTON3_PRESSED;
977 #ifdef BUTTON3_CLICKED
978 GEN_MEVENT(BUTTON3_CLICKED);
979 all3 |= BUTTON3_CLICKED;
981 #ifdef BUTTON3_DOUBLE_CLICKED
982 GEN_MEVENT(BUTTON3_DOUBLE_CLICKED);
983 all3 |= BUTTON3_DOUBLE_CLICKED;
985 #ifdef BUTTON3_TRIPLE_CLICKED
986 GEN_MEVENT(BUTTON3_TRIPLE_CLICKED);
987 all3 |= BUTTON3_TRIPLE_CLICKED;
989 #ifdef BUTTON3_RESERVED_EVENT
990 GEN_MEVENT(BUTTON3_RESERVED_EVENT);
991 all3 |= BUTTON3_RESERVED_EVENT;
993 #ifdef BUTTON4_RELEASED
994 GEN_MEVENT(BUTTON4_RELEASED);
995 all4 |= BUTTON4_RELEASED;
997 #ifdef BUTTON4_PRESSED
998 GEN_MEVENT(BUTTON4_PRESSED);
999 all4 |= BUTTON4_PRESSED;
1001 #ifdef BUTTON4_CLICKED
1002 GEN_MEVENT(BUTTON4_CLICKED);
1003 all4 |= BUTTON4_CLICKED;
1005 #ifdef BUTTON4_DOUBLE_CLICKED
1006 GEN_MEVENT(BUTTON4_DOUBLE_CLICKED);
1007 all4 |= BUTTON4_DOUBLE_CLICKED;
1009 #ifdef BUTTON4_TRIPLE_CLICKED
1010 GEN_MEVENT(BUTTON4_TRIPLE_CLICKED);
1011 all4 |= BUTTON4_TRIPLE_CLICKED;
1013 #ifdef BUTTON4_RESERVED_EVENT
1014 GEN_MEVENT(BUTTON4_RESERVED_EVENT);
1015 all4 |= BUTTON4_RESERVED_EVENT;
1018 GEN_MEVENT(BUTTON_CTRL);
1021 GEN_MEVENT(BUTTON_SHIFT);
1024 GEN_MEVENT(BUTTON_ALT);
1026 #ifdef REPORT_MOUSE_POSITION
1027 GEN_MEVENT(REPORT_MOUSE_POSITION);
1029 #ifdef ALL_MOUSE_EVENTS
1030 GEN_MEVENT(ALL_MOUSE_EVENTS);
1033 GEN_EVENT(BUTTON1_EVENTS, all1);
1034 GEN_EVENT(BUTTON2_EVENTS, all2);
1035 GEN_EVENT(BUTTON3_EVENTS, all3);
1036 GEN_EVENT(BUTTON4_EVENTS, all4);
1040 wrap_one_var(const char *c_var,
1042 const char *ada_func,
1043 const char *ada_type)
1046 /* must wrap variables */
1048 printf(" function %s return %s\n", ada_func, ada_type);
1050 printf(" function Result return %s;\n", c_type);
1051 printf(" pragma Import (C, Result, \"" NCURSES_WRAP_PREFIX "%s\");\n", c_var);
1053 if (strcmp(c_type, ada_type))
1054 printf(" return %s (Result);\n", ada_type);
1056 printf(" return Result;\n");
1057 printf(" end %s;\n", ada_func);
1059 /* global variables are really global */
1061 printf(" function %s return %s\n", ada_func, ada_type);
1063 printf(" Result : %s;\n", c_type);
1064 printf(" pragma Import (C, Result, \"%s\");\n", c_var);
1066 if (strcmp(c_type, ada_type))
1067 printf(" return %s (Result);\n", ada_type);
1069 printf(" return Result;\n");
1070 printf(" end %s;\n", ada_func);
1074 #define GEN_PUBLIC_VAR(c_var, c_type, ada_func, ada_type) \
1075 wrap_one_var(#c_var, #c_type, #ada_func, #ada_type)
1078 gen_public_vars(void)
1080 GEN_PUBLIC_VAR(stdscr, Window, Standard_Window, Window);
1081 GEN_PUBLIC_VAR(curscr, Window, Current_Window, Window);
1082 GEN_PUBLIC_VAR(LINES, C_Int, Lines, Line_Count);
1083 GEN_PUBLIC_VAR(COLS, C_Int, Columns, Column_Count);
1084 GEN_PUBLIC_VAR(TABSIZE, C_Int, Tab_Size, Natural);
1085 GEN_PUBLIC_VAR(COLORS, C_Int, Number_Of_Colors, Natural);
1086 GEN_PUBLIC_VAR(COLOR_PAIRS, C_Int, Number_Of_Color_Pairs, Natural);
1090 * Output some comment lines indicating that the file is generated.
1091 * The name parameter is the name of the facility to be used in
1095 prologue(const char *name)
1097 printf("-- %s binding.\n", name);
1098 printf("-- This module is generated. Please don't change it manually!\n");
1099 printf("-- Run the generator instead.\n-- |");
1101 printf("define(`M4_BIT_ORDER',`%s_Order_First')",
1102 little_endian ? "Low" : "High");
1106 * Write the prologue for the curses facility and make sure that
1107 * KEY_MIN and KEY_MAX are defined for the rest of this source.
1114 # define KEY_MAX 0777
1116 printf("define(`M4_KEY_MAX',`8#%o#')", KEY_MAX);
1118 # define KEY_MIN 0401
1122 fprintf(stderr, "Unexpected value for KEY_MIN: %d\n", KEY_MIN);
1125 printf("define(`M4_SPECIAL_FIRST',`8#%o#')", KEY_MIN - 1);
1129 * Write out the comment lines for the menu facility
1138 * Write out the comment lines for the form facility
1147 * Write out the comment lines for the mouse facility
1150 mouse_basedefs(void)
1156 * Write the definition of a single color
1159 color_def(const char *name, int value)
1161 printf(" %-16s : constant Color_Number := %d;\n", name, value);
1165 * Generate all color definitions
1170 #if HAVE_USE_DEFAULT_COLORS
1171 color_def("Default_Color", -1);
1174 color_def("Black", COLOR_BLACK);
1177 color_def("Red", COLOR_RED);
1180 color_def("Green", COLOR_GREEN);
1183 color_def("Yellow", COLOR_YELLOW);
1186 color_def("Blue", COLOR_BLUE);
1188 #ifdef COLOR_MAGENTA
1189 color_def("Magenta", COLOR_MAGENTA);
1192 color_def("Cyan", COLOR_CYAN);
1195 color_def("White", COLOR_WHITE);
1200 * Generate the linker options for the base facility
1205 printf(" pragma Linker_Options (\"-lncurses%s\");\n", model);
1209 * Generate the linker options for the menu facility
1212 gen_menu_linkopts(void)
1214 printf(" pragma Linker_Options (\"-lmenu%s\");\n", model);
1218 * Generate the linker options for the form facility
1221 gen_form_linkopts(void)
1223 printf(" pragma Linker_Options (\"-lform%s\");\n", model);
1227 * Generate the linker options for the panel facility
1230 gen_panel_linkopts(void)
1232 printf(" pragma Linker_Options (\"-lpanel%s\");\n", model);
1236 gen_version_info(void)
1238 static const char *v1 =
1239 " NC_Major_Version : constant := %d; -- Major version of the library\n";
1240 static const char *v2 =
1241 " NC_Minor_Version : constant := %d; -- Minor version of the library\n";
1242 static const char *v3 =
1243 " NC_Version : constant String := %c%d.%d%c; -- Version of library\n";
1245 printf(v1, NCURSES_VERSION_MAJOR);
1246 printf(v2, NCURSES_VERSION_MINOR);
1247 printf(v3, '"', NCURSES_VERSION_MAJOR, NCURSES_VERSION_MINOR, '"');
1251 eti_gen(char *buf, int code, const char *name, int *etimin, int *etimax)
1253 sprintf(buf, " E_%-16s : constant Eti_Error := %d;\n", name, code);
1258 return (int)strlen(buf);
1264 const char *s_bool = "";
1266 if (sizeof(bool) == sizeof(char))
1270 else if (sizeof(bool) == sizeof(short))
1274 else if (sizeof(bool) == sizeof(int))
1278 printf(" Sizeof%-*s : constant Natural := %2ld; -- %s\n",
1279 12, "_bool", (long)sizeof(bool), "bool");
1281 /* In ncurses _maxy and _maxx needs an offset for the "public"
1284 printf(" Offset%-*s : constant Natural := %2d; -- %s\n",
1285 12, "_XY", 1, "int");
1287 printf(" type Curses_Bool is mod 2 ** Interfaces.C.%s'Size;\n", s_bool);
1291 * main() expects two arguments on the commandline, both single characters.
1292 * The first character denotes the facility for which we generate output.
1293 * Possible values are
1297 * P - Pointer Device (Mouse)
1298 * E - ETI base definitions
1300 * The second character then denotes the specific output that should be
1301 * generated for the selected facility.
1304 main(int argc, char *argv[])
1307 char *s = (char *)&x;
1318 /* --------------------------------------------------------------- */
1319 case 'B': /* The Base facility */
1322 case 'A': /* chtype translation into Ada95 record type */
1323 gen_attr_set("Character_Attribute_Set");
1325 case 'B': /* write some initial comment lines */
1328 case 'C': /* generate color constants */
1331 case 'D': /* generate displacements of fields in WINDOW struct. */
1334 case 'E': /* generate Mouse Event codes */
1337 case 'K': /* translation of keycodes */
1340 case 'L': /* generate the Linker_Options pragma */
1343 case 'M': /* generate constants for the ACS characters */
1346 case 'O': /* generate definitions of the old key code names */
1349 case 'P': /* generate definitions of the public variables */
1352 case 'R': /* generate representation clause for Attributed character */
1353 gen_chtype_rep("Attributed_Character");
1355 case 'T': /* generate the Trace info */
1356 gen_trace("Trace_Attribute_Set");
1358 case 'V': /* generate version info */
1365 /* --------------------------------------------------------------- */
1366 case 'M': /* The Menu facility */
1369 case 'R': /* generate representation clause for Menu_Option_Set */
1370 gen_menu_opt_rep("Menu_Option_Set");
1372 case 'B': /* write some initial comment lines */
1375 case 'L': /* generate the Linker_Options pragma */
1376 gen_menu_linkopts();
1378 case 'I': /* generate representation clause for Item_Option_Set */
1379 gen_item_opt_rep("Item_Option_Set");
1385 /* --------------------------------------------------------------- */
1386 case 'F': /* The Form facility */
1389 case 'R': /* generate representation clause for Form_Option_Set */
1390 gen_form_opt_rep("Form_Option_Set");
1392 case 'B': /* write some initial comment lines */
1395 case 'L': /* generate the Linker_Options pragma */
1396 gen_form_linkopts();
1398 case 'I': /* generate representation clause for Field_Option_Set */
1399 gen_field_opt_rep("Field_Option_Set");
1405 /* --------------------------------------------------------------- */
1406 case 'P': /* The Pointer(=Mouse) facility */
1409 case 'B': /* write some initial comment lines */
1412 case 'M': /* generate representation clause for Mouse_Event */
1413 gen_mrep_rep("Mouse_Event");
1415 case 'L': /* generate the Linker_Options pragma */
1416 gen_panel_linkopts();
1422 /* --------------------------------------------------------------- */
1423 case 'E': /* chtype size detection */
1428 const char *fmt = " type C_Chtype is new %s;\n";
1429 const char *afmt = " type C_AttrType is new %s;\n";
1431 if (sizeof(chtype) == sizeof(int))
1433 if (sizeof(int) == sizeof(long))
1434 printf(fmt, "C_ULong");
1437 printf(fmt, "C_UInt");
1439 else if (sizeof(chtype) == sizeof(long))
1441 printf(fmt, "C_ULong");
1446 if (sizeof(attr_t) == sizeof(int))
1448 if (sizeof(int) == sizeof(long))
1449 printf(afmt, "C_ULong");
1452 printf(afmt, "C_UInt");
1454 else if (sizeof(attr_t) == sizeof(long))
1456 printf(afmt, "C_ULong");
1461 printf("define(`CF_CURSES_OK',`%d')", OK);
1462 printf("define(`CF_CURSES_ERR',`%d')", ERR);
1463 printf("define(`CF_CURSES_TRUE',`%d')", TRUE);
1464 printf("define(`CF_CURSES_FALSE',`%d')", FALSE);
1469 char *buf = (char *)malloc(2048);
1476 p += eti_gen(p, E_OK, "Ok", &etimin, &etimax);
1477 p += eti_gen(p, E_SYSTEM_ERROR, "System_Error", &etimin, &etimax);
1478 p += eti_gen(p, E_BAD_ARGUMENT, "Bad_Argument", &etimin, &etimax);
1479 p += eti_gen(p, E_POSTED, "Posted", &etimin, &etimax);
1480 p += eti_gen(p, E_CONNECTED, "Connected", &etimin, &etimax);
1481 p += eti_gen(p, E_BAD_STATE, "Bad_State", &etimin, &etimax);
1482 p += eti_gen(p, E_NO_ROOM, "No_Room", &etimin, &etimax);
1483 p += eti_gen(p, E_NOT_POSTED, "Not_Posted", &etimin, &etimax);
1484 p += eti_gen(p, E_UNKNOWN_COMMAND,
1485 "Unknown_Command", &etimin, &etimax);
1486 p += eti_gen(p, E_NO_MATCH, "No_Match", &etimin, &etimax);
1487 p += eti_gen(p, E_NOT_SELECTABLE,
1488 "Not_Selectable", &etimin, &etimax);
1489 p += eti_gen(p, E_NOT_CONNECTED,
1490 "Not_Connected", &etimin, &etimax);
1491 p += eti_gen(p, E_REQUEST_DENIED,
1492 "Request_Denied", &etimin, &etimax);
1493 p += eti_gen(p, E_INVALID_FIELD,
1494 "Invalid_Field", &etimin, &etimax);
1495 p += eti_gen(p, E_CURRENT,
1496 "Current", &etimin, &etimax);
1498 printf(" subtype Eti_Error is C_Int range %d .. %d;\n\n",
1507 /* --------------------------------------------------------------- */
1508 case 'V': /* plain version dump */
1512 case '1': /* major version */
1513 #ifdef NCURSES_VERSION_MAJOR
1514 printf("%d", NCURSES_VERSION_MAJOR);
1517 case '2': /* minor version */
1518 #ifdef NCURSES_VERSION_MINOR
1519 printf("%d", NCURSES_VERSION_MINOR);
1522 case '3': /* patch level */
1523 #ifdef NCURSES_VERSION_PATCH
1524 printf("%d", NCURSES_VERSION_PATCH);
1532 /* --------------------------------------------------------------- */