1 /****************************************************************************
2 * Copyright (c) 1998,2008,2009 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.50 2009/03/21 21:34:20 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.
44 #include <ncurses_cfg.h>
55 #define RES_NAME "Reserved"
57 static const char *model = "";
58 static int little_endian = 0;
68 find_pos(char *s, unsigned len, int *low, int *high)
76 for (i = 0; i < len; i++, s++)
80 for (j = 0; j < 8 * sizeof(char); j++)
83 if (((little_endian && ((*s) & 0x01)) ||
84 (!little_endian && ((*s) & 0x80))))
101 return (*high >= 0 && (*low <= *high)) ? *low : -1;
105 * This helper routine generates a representation clause for a
106 * record type defined in the binding.
107 * We are only dealing with record types which are of 32 or 16
108 * bit size, i.e. they fit into an (u)int or a (u)short.
112 (const name_attribute_pair * nap, /* array of name_attribute_pair records */
113 const char *name, /* name of the represented record type */
114 int len, /* size of the record in bytes */
117 int i, n, l, cnt = 0, low, high;
118 int width = strlen(RES_NAME) + 3;
120 unsigned long mask = 0;
124 for (i = 0; nap[i].name != (char *)0; i++)
127 l = strlen(nap[i].name);
133 printf(" type %s is\n", name);
135 for (i = 0; nap[i].name != (char *)0; i++)
137 printf(" %-*s : Boolean;\n", width, nap[i].name);
139 printf(" end record;\n");
140 printf(" pragma Convention (C, %s);\n\n", name);
142 printf(" for %s use\n", name);
145 for (i = 0; nap[i].name != (char *)0; i++)
149 l = find_pos((char *)&a, sizeof(a), &low, &high);
151 printf(" %-*s at 0 range %2d .. %2d;\n", width, nap[i].name,
152 low - bias, high - bias);
156 printf(" end record;\n");
157 printf(" for %s'Size use %d;\n", name, 8 * len);
158 printf(" -- Please note: this rep. clause is generated and may be\n");
159 printf(" -- different on your system.");
163 chtype_rep(const char *name, attr_t mask)
168 int l = find_pos((char *)&t, sizeof(t), &low, &high);
171 printf(" %-5s at 0 range %2d .. %2d;\n", name, low, high);
175 gen_chtype_rep(const char *name)
177 printf(" for %s use\n record\n", name);
178 chtype_rep("Ch", A_CHARTEXT);
179 chtype_rep("Color", A_COLOR);
180 chtype_rep("Attr", (A_ATTRIBUTES & ~A_COLOR));
181 printf(" end record;\n for %s'Size use %ld;\n",
182 name, (long)(8 * sizeof(chtype)));
184 printf(" -- Please note: this rep. clause is generated and may be\n");
185 printf(" -- different on your system.\n");
189 mrep_rep(const char *name, void *rec)
192 int l = find_pos((char *)rec, sizeof(MEVENT), &low, &high);
195 printf(" %-7s at 0 range %3d .. %3d;\n", name, low, high);
199 gen_mrep_rep(const char *name)
203 printf(" for %s use\n record\n", name);
205 memset(&x, 0, sizeof(x));
209 memset(&x, 0, sizeof(x));
213 memset(&x, 0, sizeof(x));
217 memset(&x, 0, sizeof(x));
221 memset(&x, 0, sizeof(x));
223 mrep_rep("Bstate", &x);
225 printf(" end record;\n");
226 printf(" -- Please note: this rep. clause is generated and may be\n");
227 printf(" -- different on your system.\n");
231 gen_attr_set(const char *name)
233 /* All of the A_xxx symbols are defined in ncurses, but not all are nonzero
234 * if "configure --enable-widec" is specified.
236 static const name_attribute_pair nap[] =
239 {"Stand_Out", A_STANDOUT},
242 {"Under_Line", A_UNDERLINE},
245 {"Reverse_Video", A_REVERSE},
251 {"Dim_Character", A_DIM},
254 {"Bold_Character", A_BOLD},
257 {"Alternate_Character_Set", A_ALTCHARSET},
260 {"Invisible_Character", A_INVIS},
263 {"Protected_Character", A_PROTECT},
266 {"Horizontal", A_HORIZONTAL},
281 {"Vertical", A_VERTICAL},
285 chtype attr = A_ATTRIBUTES & ~A_COLOR;
289 for (i = 0; i < (int)(8 * sizeof(chtype)); i++)
304 gen_reps(nap, name, (len + 7) / 8, little_endian ? start : 0);
308 gen_trace(const char *name)
310 static const name_attribute_pair nap[] =
312 {"Times", TRACE_TIMES},
313 {"Tputs", TRACE_TPUTS},
314 {"Update", TRACE_UPDATE},
315 {"Cursor_Move", TRACE_MOVE},
316 {"Character_Output", TRACE_CHARPUT},
317 {"Calls", TRACE_CALLS},
318 {"Virtual_Puts", TRACE_VIRTPUT},
319 {"Input_Events", TRACE_IEVENT},
320 {"TTY_State", TRACE_BITS},
321 {"Internal_Calls", TRACE_ICALLS},
322 {"Character_Calls", TRACE_CCALLS},
323 {"Termcap_TermInfo", TRACE_DATABASE},
326 gen_reps(nap, name, sizeof(int), 0);
330 gen_menu_opt_rep(const char *name)
332 static const name_attribute_pair nap[] =
335 {"One_Valued", O_ONEVALUE},
338 {"Show_Descriptions", O_SHOWDESC},
341 {"Row_Major_Order", O_ROWMAJOR},
344 {"Ignore_Case", O_IGNORECASE},
347 {"Show_Matches", O_SHOWMATCH},
350 {"Non_Cyclic", O_NONCYCLIC},
354 gen_reps(nap, name, sizeof(int), 0);
358 gen_item_opt_rep(const char *name)
360 static const name_attribute_pair nap[] =
363 {"Selectable", O_SELECTABLE},
367 gen_reps(nap, name, sizeof(int), 0);
371 gen_form_opt_rep(const char *name)
373 static const name_attribute_pair nap[] =
376 {"NL_Overload", O_NL_OVERLOAD},
379 {"BS_Overload", O_BS_OVERLOAD},
383 gen_reps(nap, name, sizeof(int), 0);
387 * Generate the representation clause for the Field_Option_Set record
390 gen_field_opt_rep(const char *name)
392 static const name_attribute_pair nap[] =
395 {"Visible", O_VISIBLE},
398 {"Active", O_ACTIVE},
401 {"Public", O_PUBLIC},
413 {"Auto_Skip", O_AUTOSKIP},
416 {"Null_Ok", O_NULLOK},
419 {"Pass_Ok", O_PASSOK},
422 {"Static", O_STATIC},
426 gen_reps(nap, name, sizeof(int), 0);
430 * Generate a single key code constant definition.
433 keydef(const char *name, const char *old_name, int value, int mode)
435 if (mode == 0) /* Generate the new name */
436 printf(" %-30s : constant Special_Key_Code := 8#%3o#;\n", name, value);
438 { /* generate the old name, but only if it doesn't conflict with the old
439 * name (Ada95 isn't case sensitive!)
441 const char *s = old_name;
442 const char *t = name;
444 while (*s && *t && (toupper(*s++) == toupper(*t++)));
446 printf(" %-16s : Special_Key_Code renames %s;\n", old_name, name);
451 * Generate constants for the key codes. When called with mode==0, a
452 * complete list with nice constant names in proper casing style will
453 * be generated. Otherwise a list of old (i.e. C-style) names will be
454 * generated, given that the name wasn't already defined in the "nice"
458 gen_keydefs(int mode)
465 keydef("Key_Code_Yes", "KEY_CODE_YES", KEY_CODE_YES, mode);
468 keydef("Key_Min", "KEY_MIN", KEY_MIN, mode);
471 keydef("Key_Break", "KEY_BREAK", KEY_BREAK, mode);
474 keydef("Key_Cursor_Down", "KEY_DOWN", KEY_DOWN, mode);
477 keydef("Key_Cursor_Up", "KEY_UP", KEY_UP, mode);
480 keydef("Key_Cursor_Left", "KEY_LEFT", KEY_LEFT, mode);
483 keydef("Key_Cursor_Right", "KEY_RIGHT", KEY_RIGHT, mode);
486 keydef("Key_Home", "KEY_HOME", KEY_HOME, mode);
489 keydef("Key_Backspace", "KEY_BACKSPACE", KEY_BACKSPACE, mode);
492 keydef("Key_F0", "KEY_F0", KEY_F0, mode);
495 for (i = 1; i <= 24; i++)
497 sprintf(buf, "Key_F%d", i);
498 sprintf(obuf, "KEY_F%d", i);
499 keydef(buf, obuf, KEY_F(i), mode);
503 keydef("Key_Delete_Line", "KEY_DL", KEY_DL, mode);
506 keydef("Key_Insert_Line", "KEY_IL", KEY_IL, mode);
509 keydef("Key_Delete_Char", "KEY_DC", KEY_DC, mode);
512 keydef("Key_Insert_Char", "KEY_IC", KEY_IC, mode);
515 keydef("Key_Exit_Insert_Mode", "KEY_EIC", KEY_EIC, mode);
518 keydef("Key_Clear_Screen", "KEY_CLEAR", KEY_CLEAR, mode);
521 keydef("Key_Clear_End_Of_Screen", "KEY_EOS", KEY_EOS, mode);
524 keydef("Key_Clear_End_Of_Line", "KEY_EOL", KEY_EOL, mode);
527 keydef("Key_Scroll_1_Forward", "KEY_SF", KEY_SF, mode);
530 keydef("Key_Scroll_1_Backward", "KEY_SR", KEY_SR, mode);
533 keydef("Key_Next_Page", "KEY_NPAGE", KEY_NPAGE, mode);
536 keydef("Key_Previous_Page", "KEY_PPAGE", KEY_PPAGE, mode);
539 keydef("Key_Set_Tab", "KEY_STAB", KEY_STAB, mode);
542 keydef("Key_Clear_Tab", "KEY_CTAB", KEY_CTAB, mode);
545 keydef("Key_Clear_All_Tabs", "KEY_CATAB", KEY_CATAB, mode);
548 keydef("Key_Enter_Or_Send", "KEY_ENTER", KEY_ENTER, mode);
551 keydef("Key_Soft_Reset", "KEY_SRESET", KEY_SRESET, mode);
554 keydef("Key_Reset", "KEY_RESET", KEY_RESET, mode);
557 keydef("Key_Print", "KEY_PRINT", KEY_PRINT, mode);
560 keydef("Key_Bottom", "KEY_LL", KEY_LL, mode);
563 keydef("Key_Upper_Left_Of_Keypad", "KEY_A1", KEY_A1, mode);
566 keydef("Key_Upper_Right_Of_Keypad", "KEY_A3", KEY_A3, mode);
569 keydef("Key_Center_Of_Keypad", "KEY_B2", KEY_B2, mode);
572 keydef("Key_Lower_Left_Of_Keypad", "KEY_C1", KEY_C1, mode);
575 keydef("Key_Lower_Right_Of_Keypad", "KEY_C3", KEY_C3, mode);
578 keydef("Key_Back_Tab", "KEY_BTAB", KEY_BTAB, mode);
581 keydef("Key_Beginning", "KEY_BEG", KEY_BEG, mode);
584 keydef("Key_Cancel", "KEY_CANCEL", KEY_CANCEL, mode);
587 keydef("Key_Close", "KEY_CLOSE", KEY_CLOSE, mode);
590 keydef("Key_Command", "KEY_COMMAND", KEY_COMMAND, mode);
593 keydef("Key_Copy", "KEY_COPY", KEY_COPY, mode);
596 keydef("Key_Create", "KEY_CREATE", KEY_CREATE, mode);
599 keydef("Key_End", "KEY_END", KEY_END, mode);
602 keydef("Key_Exit", "KEY_EXIT", KEY_EXIT, mode);
605 keydef("Key_Find", "KEY_FIND", KEY_FIND, mode);
608 keydef("Key_Help", "KEY_HELP", KEY_HELP, mode);
611 keydef("Key_Mark", "KEY_MARK", KEY_MARK, mode);
614 keydef("Key_Message", "KEY_MESSAGE", KEY_MESSAGE, mode);
617 keydef("Key_Move", "KEY_MOVE", KEY_MOVE, mode);
620 keydef("Key_Next", "KEY_NEXT", KEY_NEXT, mode);
623 keydef("Key_Open", "KEY_OPEN", KEY_OPEN, mode);
626 keydef("Key_Options", "KEY_OPTIONS", KEY_OPTIONS, mode);
629 keydef("Key_Previous", "KEY_PREVIOUS", KEY_PREVIOUS, mode);
632 keydef("Key_Redo", "KEY_REDO", KEY_REDO, mode);
635 keydef("Key_Reference", "KEY_REFERENCE", KEY_REFERENCE, mode);
638 keydef("Key_Refresh", "KEY_REFRESH", KEY_REFRESH, mode);
641 keydef("Key_Replace", "KEY_REPLACE", KEY_REPLACE, mode);
644 keydef("Key_Restart", "KEY_RESTART", KEY_RESTART, mode);
647 keydef("Key_Resume", "KEY_RESUME", KEY_RESUME, mode);
650 keydef("Key_Save", "KEY_SAVE", KEY_SAVE, mode);
653 keydef("Key_Shift_Begin", "KEY_SBEG", KEY_SBEG, mode);
656 keydef("Key_Shift_Cancel", "KEY_SCANCEL", KEY_SCANCEL, mode);
659 keydef("Key_Shift_Command", "KEY_SCOMMAND", KEY_SCOMMAND, mode);
662 keydef("Key_Shift_Copy", "KEY_SCOPY", KEY_SCOPY, mode);
665 keydef("Key_Shift_Create", "KEY_SCREATE", KEY_SCREATE, mode);
668 keydef("Key_Shift_Delete_Char", "KEY_SDC", KEY_SDC, mode);
671 keydef("Key_Shift_Delete_Line", "KEY_SDL", KEY_SDL, mode);
674 keydef("Key_Select", "KEY_SELECT", KEY_SELECT, mode);
677 keydef("Key_Shift_End", "KEY_SEND", KEY_SEND, mode);
680 keydef("Key_Shift_Clear_End_Of_Line", "KEY_SEOL", KEY_SEOL, mode);
683 keydef("Key_Shift_Exit", "KEY_SEXIT", KEY_SEXIT, mode);
686 keydef("Key_Shift_Find", "KEY_SFIND", KEY_SFIND, mode);
689 keydef("Key_Shift_Help", "KEY_SHELP", KEY_SHELP, mode);
692 keydef("Key_Shift_Home", "KEY_SHOME", KEY_SHOME, mode);
695 keydef("Key_Shift_Insert_Char", "KEY_SIC", KEY_SIC, mode);
698 keydef("Key_Shift_Cursor_Left", "KEY_SLEFT", KEY_SLEFT, mode);
701 keydef("Key_Shift_Message", "KEY_SMESSAGE", KEY_SMESSAGE, mode);
704 keydef("Key_Shift_Move", "KEY_SMOVE", KEY_SMOVE, mode);
707 keydef("Key_Shift_Next_Page", "KEY_SNEXT", KEY_SNEXT, mode);
710 keydef("Key_Shift_Options", "KEY_SOPTIONS", KEY_SOPTIONS, mode);
713 keydef("Key_Shift_Previous_Page", "KEY_SPREVIOUS", KEY_SPREVIOUS, mode);
716 keydef("Key_Shift_Print", "KEY_SPRINT", KEY_SPRINT, mode);
719 keydef("Key_Shift_Redo", "KEY_SREDO", KEY_SREDO, mode);
722 keydef("Key_Shift_Replace", "KEY_SREPLACE", KEY_SREPLACE, mode);
725 keydef("Key_Shift_Cursor_Right", "KEY_SRIGHT", KEY_SRIGHT, mode);
728 keydef("Key_Shift_Resume", "KEY_SRSUME", KEY_SRSUME, mode);
731 keydef("Key_Shift_Save", "KEY_SSAVE", KEY_SSAVE, mode);
734 keydef("Key_Shift_Suspend", "KEY_SSUSPEND", KEY_SSUSPEND, mode);
737 keydef("Key_Shift_Undo", "KEY_SUNDO", KEY_SUNDO, mode);
740 keydef("Key_Suspend", "KEY_SUSPEND", KEY_SUSPEND, mode);
743 keydef("Key_Undo", "KEY_UNDO", KEY_UNDO, mode);
746 keydef("Key_Mouse", "KEY_MOUSE", KEY_MOUSE, mode);
749 keydef("Key_Resize", "KEY_RESIZE", KEY_RESIZE, mode);
754 * Generate a constant with the given name. The second parameter
755 * is a reference to the ACS character in the acs_map[] array and
756 * will be translated into an index.
759 acs_def(const char *name, chtype *a)
761 int c = a - &acs_map[0];
763 printf(" %-24s : constant Character := ", name);
764 if (isprint(c) && (c != '`'))
765 printf("'%c';\n", c);
767 printf("Character'Val (%d);\n", c);
771 * Generate the constants for the ACS characters
776 printf(" type C_ACS_Map is array (Character'Val (0) .. Character'Val (127))\n");
777 printf(" of Attributed_Character;\n");
778 #if USE_REENTRANT || BROKEN_LINKER
779 printf(" type C_ACS_Ptr is access C_ACS_Map;\n");
780 printf(" function ACS_Map return C_ACS_Ptr;\n");
781 printf(" pragma Import (C, ACS_Map, \""
785 printf(" ACS_Map : C_ACS_Map;\n");
786 printf(" pragma Import (C, ACS_Map, \"acs_map\");\n");
790 printf(" -- Constants for several characters from the Alternate Character Set\n");
791 printf(" -- You must use these constants as indices into the ACS_Map array\n");
792 printf(" -- to get the corresponding attributed character at runtime.\n");
796 acs_def("ACS_Upper_Left_Corner", &ACS_ULCORNER);
799 acs_def("ACS_Lower_Left_Corner", &ACS_LLCORNER);
802 acs_def("ACS_Upper_Right_Corner", &ACS_URCORNER);
805 acs_def("ACS_Lower_Right_Corner", &ACS_LRCORNER);
808 acs_def("ACS_Left_Tee", &ACS_LTEE);
811 acs_def("ACS_Right_Tee", &ACS_RTEE);
814 acs_def("ACS_Bottom_Tee", &ACS_BTEE);
817 acs_def("ACS_Top_Tee", &ACS_TTEE);
820 acs_def("ACS_Horizontal_Line", &ACS_HLINE);
823 acs_def("ACS_Vertical_Line", &ACS_VLINE);
826 acs_def("ACS_Plus_Symbol", &ACS_PLUS);
829 acs_def("ACS_Scan_Line_1", &ACS_S1);
832 acs_def("ACS_Scan_Line_9", &ACS_S9);
835 acs_def("ACS_Diamond", &ACS_DIAMOND);
838 acs_def("ACS_Checker_Board", &ACS_CKBOARD);
841 acs_def("ACS_Degree", &ACS_DEGREE);
844 acs_def("ACS_Plus_Minus", &ACS_PLMINUS);
847 acs_def("ACS_Bullet", &ACS_BULLET);
850 acs_def("ACS_Left_Arrow", &ACS_LARROW);
853 acs_def("ACS_Right_Arrow", &ACS_RARROW);
856 acs_def("ACS_Down_Arrow", &ACS_DARROW);
859 acs_def("ACS_Up_Arrow", &ACS_UARROW);
862 acs_def("ACS_Board_Of_Squares", &ACS_BOARD);
865 acs_def("ACS_Lantern", &ACS_LANTERN);
868 acs_def("ACS_Solid_Block", &ACS_BLOCK);
871 acs_def("ACS_Scan_Line_3", &ACS_S3);
874 acs_def("ACS_Scan_Line_7", &ACS_S7);
877 acs_def("ACS_Less_Or_Equal", &ACS_LEQUAL);
880 acs_def("ACS_Greater_Or_Equal", &ACS_GEQUAL);
883 acs_def("ACS_PI", &ACS_PI);
886 acs_def("ACS_Not_Equal", &ACS_NEQUAL);
889 acs_def("ACS_Sterling", &ACS_STERLING);
893 #define GEN_EVENT(name,value) \
894 printf(" %-25s : constant Event_Mask := 8#%011lo#;\n", \
897 #define GEN_MEVENT(name) \
898 printf(" %-25s : constant Event_Mask := 8#%011lo#;\n", \
902 gen_mouse_events(void)
909 #ifdef BUTTON1_RELEASED
910 GEN_MEVENT(BUTTON1_RELEASED);
911 all1 |= BUTTON1_RELEASED;
913 #ifdef BUTTON1_PRESSED
914 GEN_MEVENT(BUTTON1_PRESSED);
915 all1 |= BUTTON1_PRESSED;
917 #ifdef BUTTON1_CLICKED
918 GEN_MEVENT(BUTTON1_CLICKED);
919 all1 |= BUTTON1_CLICKED;
921 #ifdef BUTTON1_DOUBLE_CLICKED
922 GEN_MEVENT(BUTTON1_DOUBLE_CLICKED);
923 all1 |= BUTTON1_DOUBLE_CLICKED;
925 #ifdef BUTTON1_TRIPLE_CLICKED
926 GEN_MEVENT(BUTTON1_TRIPLE_CLICKED);
927 all1 |= BUTTON1_TRIPLE_CLICKED;
929 #ifdef BUTTON1_RESERVED_EVENT
930 GEN_MEVENT(BUTTON1_RESERVED_EVENT);
931 all1 |= BUTTON1_RESERVED_EVENT;
933 #ifdef BUTTON2_RELEASED
934 GEN_MEVENT(BUTTON2_RELEASED);
935 all2 |= BUTTON2_RELEASED;
937 #ifdef BUTTON2_PRESSED
938 GEN_MEVENT(BUTTON2_PRESSED);
939 all2 |= BUTTON2_PRESSED;
941 #ifdef BUTTON2_CLICKED
942 GEN_MEVENT(BUTTON2_CLICKED);
943 all2 |= BUTTON2_CLICKED;
945 #ifdef BUTTON2_DOUBLE_CLICKED
946 GEN_MEVENT(BUTTON2_DOUBLE_CLICKED);
947 all2 |= BUTTON2_DOUBLE_CLICKED;
949 #ifdef BUTTON2_TRIPLE_CLICKED
950 GEN_MEVENT(BUTTON2_TRIPLE_CLICKED);
951 all2 |= BUTTON2_TRIPLE_CLICKED;
953 #ifdef BUTTON2_RESERVED_EVENT
954 GEN_MEVENT(BUTTON2_RESERVED_EVENT);
955 all2 |= BUTTON2_RESERVED_EVENT;
957 #ifdef BUTTON3_RELEASED
958 GEN_MEVENT(BUTTON3_RELEASED);
959 all3 |= BUTTON3_RELEASED;
961 #ifdef BUTTON3_PRESSED
962 GEN_MEVENT(BUTTON3_PRESSED);
963 all3 |= BUTTON3_PRESSED;
965 #ifdef BUTTON3_CLICKED
966 GEN_MEVENT(BUTTON3_CLICKED);
967 all3 |= BUTTON3_CLICKED;
969 #ifdef BUTTON3_DOUBLE_CLICKED
970 GEN_MEVENT(BUTTON3_DOUBLE_CLICKED);
971 all3 |= BUTTON3_DOUBLE_CLICKED;
973 #ifdef BUTTON3_TRIPLE_CLICKED
974 GEN_MEVENT(BUTTON3_TRIPLE_CLICKED);
975 all3 |= BUTTON3_TRIPLE_CLICKED;
977 #ifdef BUTTON3_RESERVED_EVENT
978 GEN_MEVENT(BUTTON3_RESERVED_EVENT);
979 all3 |= BUTTON3_RESERVED_EVENT;
981 #ifdef BUTTON4_RELEASED
982 GEN_MEVENT(BUTTON4_RELEASED);
983 all4 |= BUTTON4_RELEASED;
985 #ifdef BUTTON4_PRESSED
986 GEN_MEVENT(BUTTON4_PRESSED);
987 all4 |= BUTTON4_PRESSED;
989 #ifdef BUTTON4_CLICKED
990 GEN_MEVENT(BUTTON4_CLICKED);
991 all4 |= BUTTON4_CLICKED;
993 #ifdef BUTTON4_DOUBLE_CLICKED
994 GEN_MEVENT(BUTTON4_DOUBLE_CLICKED);
995 all4 |= BUTTON4_DOUBLE_CLICKED;
997 #ifdef BUTTON4_TRIPLE_CLICKED
998 GEN_MEVENT(BUTTON4_TRIPLE_CLICKED);
999 all4 |= BUTTON4_TRIPLE_CLICKED;
1001 #ifdef BUTTON4_RESERVED_EVENT
1002 GEN_MEVENT(BUTTON4_RESERVED_EVENT);
1003 all4 |= BUTTON4_RESERVED_EVENT;
1006 GEN_MEVENT(BUTTON_CTRL);
1009 GEN_MEVENT(BUTTON_SHIFT);
1012 GEN_MEVENT(BUTTON_ALT);
1014 #ifdef REPORT_MOUSE_POSITION
1015 GEN_MEVENT(REPORT_MOUSE_POSITION);
1017 #ifdef ALL_MOUSE_EVENTS
1018 GEN_MEVENT(ALL_MOUSE_EVENTS);
1021 GEN_EVENT(BUTTON1_EVENTS, all1);
1022 GEN_EVENT(BUTTON2_EVENTS, all2);
1023 GEN_EVENT(BUTTON3_EVENTS, all3);
1024 GEN_EVENT(BUTTON4_EVENTS, all4);
1028 wrap_one_var(const char *c_var,
1030 const char *ada_func,
1031 const char *ada_type)
1034 /* must wrap variables */
1036 printf(" function %s return %s\n", ada_func, ada_type);
1038 printf(" function Result return %s;\n", c_type);
1039 printf(" pragma Import (C, Result, \"" NCURSES_WRAP_PREFIX "%s\");\n", c_var);
1041 if (strcmp(c_type, ada_type))
1042 printf(" return %s (Result);\n", ada_type);
1044 printf(" return Result;\n");
1045 printf(" end %s;\n", ada_func);
1047 /* global variables are really global */
1049 printf(" function %s return %s\n", ada_func, ada_type);
1051 printf(" Result : %s;\n", c_type);
1052 printf(" pragma Import (C, Result, \"%s\");\n", c_var);
1054 if (strcmp(c_type, ada_type))
1055 printf(" return %s (Result);\n", ada_type);
1057 printf(" return Result;\n");
1058 printf(" end %s;\n", ada_func);
1062 #define GEN_PUBLIC_VAR(c_var, c_type, ada_func, ada_type) \
1063 wrap_one_var(#c_var, #c_type, #ada_func, #ada_type)
1066 gen_public_vars(void)
1068 GEN_PUBLIC_VAR(stdscr, Window, Standard_Window, Window);
1069 GEN_PUBLIC_VAR(curscr, Window, Current_Window, Window);
1070 GEN_PUBLIC_VAR(LINES, C_Int, Lines, Line_Count);
1071 GEN_PUBLIC_VAR(COLS, C_Int, Columns, Column_Count);
1072 GEN_PUBLIC_VAR(TABSIZE, C_Int, Tab_Size, Natural);
1073 GEN_PUBLIC_VAR(COLORS, C_Int, Number_Of_Colors, Natural);
1074 GEN_PUBLIC_VAR(COLOR_PAIRS, C_Int, Number_Of_Color_Pairs, Natural);
1078 * Output some comment lines indicating that the file is generated.
1079 * The name parameter is the name of the facility to be used in
1083 prologue(const char *name)
1085 printf("-- %s binding.\n", name);
1086 printf("-- This module is generated. Please don't change it manually!\n");
1087 printf("-- Run the generator instead.\n-- |");
1089 printf("define(`M4_BIT_ORDER',`%s_Order_First')",
1090 little_endian ? "Low" : "High");
1094 * Write the prologue for the curses facility and make sure that
1095 * KEY_MIN and KEY_MAX are defined for the rest of this source.
1102 # define KEY_MAX 0777
1104 printf("define(`M4_KEY_MAX',`8#%o#')", KEY_MAX);
1106 # define KEY_MIN 0401
1110 fprintf(stderr, "Unexpected value for KEY_MIN: %d\n", KEY_MIN);
1113 printf("define(`M4_SPECIAL_FIRST',`8#%o#')", KEY_MIN - 1);
1117 * Write out the comment lines for the menu facility
1126 * Write out the comment lines for the form facility
1135 * Write out the comment lines for the mouse facility
1138 mouse_basedefs(void)
1144 * Write the definition of a single color
1147 color_def(const char *name, int value)
1149 printf(" %-16s : constant Color_Number := %d;\n", name, value);
1153 * Generate all color definitions
1158 #if HAVE_USE_DEFAULT_COLORS
1159 color_def("Default_Color", -1);
1162 color_def("Black", COLOR_BLACK);
1165 color_def("Red", COLOR_RED);
1168 color_def("Green", COLOR_GREEN);
1171 color_def("Yellow", COLOR_YELLOW);
1174 color_def("Blue", COLOR_BLUE);
1176 #ifdef COLOR_MAGENTA
1177 color_def("Magenta", COLOR_MAGENTA);
1180 color_def("Cyan", COLOR_CYAN);
1183 color_def("White", COLOR_WHITE);
1188 * Generate the linker options for the base facility
1193 printf(" pragma Linker_Options (\"-lncurses%s\");\n", model);
1197 * Generate the linker options for the menu facility
1200 gen_menu_linkopts(void)
1202 printf(" pragma Linker_Options (\"-lmenu%s\");\n", model);
1206 * Generate the linker options for the form facility
1209 gen_form_linkopts(void)
1211 printf(" pragma Linker_Options (\"-lform%s\");\n", model);
1215 * Generate the linker options for the panel facility
1218 gen_panel_linkopts(void)
1220 printf(" pragma Linker_Options (\"-lpanel%s\");\n", model);
1224 gen_version_info(void)
1226 static const char *v1 =
1227 " NC_Major_Version : constant := %d; -- Major version of the library\n";
1228 static const char *v2 =
1229 " NC_Minor_Version : constant := %d; -- Minor version of the library\n";
1230 static const char *v3 =
1231 " NC_Version : constant String := %c%d.%d%c; -- Version of library\n";
1233 printf(v1, NCURSES_VERSION_MAJOR);
1234 printf(v2, NCURSES_VERSION_MINOR);
1235 printf(v3, '"', NCURSES_VERSION_MAJOR, NCURSES_VERSION_MINOR, '"');
1239 eti_gen(char *buf, int code, const char *name, int *etimin, int *etimax)
1241 sprintf(buf, " E_%-16s : constant Eti_Error := %d;\n", name, code);
1252 const char *s_bool = "";
1254 if (sizeof(bool) == sizeof(char))
1258 else if (sizeof(bool) == sizeof(short))
1262 else if (sizeof(bool) == sizeof(int))
1266 printf(" Sizeof%-*s : constant Natural := %2ld; -- %s\n",
1267 12, "_bool", (long)sizeof(bool), "bool");
1269 /* In ncurses _maxy and _maxx needs an offset for the "public"
1272 printf(" Offset%-*s : constant Natural := %2d; -- %s\n",
1273 12, "_XY", 1, "int");
1275 printf(" type Curses_Bool is mod 2 ** Interfaces.C.%s'Size;\n", s_bool);
1279 * main() expects two arguments on the commandline, both single characters.
1280 * The first character denotes the facility for which we generate output.
1281 * Possible values are
1285 * P - Pointer Device (Mouse)
1286 * E - ETI base definitions
1288 * The second character then denotes the specific output that should be
1289 * generated for the selected facility.
1292 main(int argc, char *argv[])
1295 char *s = (char *)&x;
1306 /* --------------------------------------------------------------- */
1307 case 'B': /* The Base facility */
1310 case 'A': /* chtype translation into Ada95 record type */
1311 gen_attr_set("Character_Attribute_Set");
1313 case 'B': /* write some initial comment lines */
1316 case 'C': /* generate color constants */
1319 case 'D': /* generate displacements of fields in WINDOW struct. */
1322 case 'E': /* generate Mouse Event codes */
1325 case 'K': /* translation of keycodes */
1328 case 'L': /* generate the Linker_Options pragma */
1331 case 'M': /* generate constants for the ACS characters */
1334 case 'O': /* generate definitions of the old key code names */
1337 case 'P': /* generate definitions of the public variables */
1340 case 'R': /* generate representation clause for Attributed character */
1341 gen_chtype_rep("Attributed_Character");
1343 case 'T': /* generate the Trace info */
1344 gen_trace("Trace_Attribute_Set");
1346 case 'V': /* generate version info */
1353 /* --------------------------------------------------------------- */
1354 case 'M': /* The Menu facility */
1357 case 'R': /* generate representation clause for Menu_Option_Set */
1358 gen_menu_opt_rep("Menu_Option_Set");
1360 case 'B': /* write some initial comment lines */
1363 case 'L': /* generate the Linker_Options pragma */
1364 gen_menu_linkopts();
1366 case 'I': /* generate representation clause for Item_Option_Set */
1367 gen_item_opt_rep("Item_Option_Set");
1373 /* --------------------------------------------------------------- */
1374 case 'F': /* The Form facility */
1377 case 'R': /* generate representation clause for Form_Option_Set */
1378 gen_form_opt_rep("Form_Option_Set");
1380 case 'B': /* write some initial comment lines */
1383 case 'L': /* generate the Linker_Options pragma */
1384 gen_form_linkopts();
1386 case 'I': /* generate representation clause for Field_Option_Set */
1387 gen_field_opt_rep("Field_Option_Set");
1393 /* --------------------------------------------------------------- */
1394 case 'P': /* The Pointer(=Mouse) facility */
1397 case 'B': /* write some initial comment lines */
1400 case 'M': /* generate representation clause for Mouse_Event */
1401 gen_mrep_rep("Mouse_Event");
1403 case 'L': /* generate the Linker_Options pragma */
1404 gen_panel_linkopts();
1410 /* --------------------------------------------------------------- */
1411 case 'E': /* chtype size detection */
1416 const char *fmt = " type C_Chtype is new %s;\n";
1417 const char *afmt = " type C_AttrType is new %s;\n";
1419 if (sizeof(chtype) == sizeof(int))
1421 if (sizeof(int) == sizeof(long))
1422 printf(fmt, "C_ULong");
1425 printf(fmt, "C_UInt");
1427 else if (sizeof(chtype) == sizeof(long))
1429 printf(fmt, "C_ULong");
1434 if (sizeof(attr_t) == sizeof(int))
1436 if (sizeof(int) == sizeof(long))
1437 printf(afmt, "C_ULong");
1440 printf(afmt, "C_UInt");
1442 else if (sizeof(attr_t) == sizeof(long))
1444 printf(afmt, "C_ULong");
1449 printf("define(`CF_CURSES_OK',`%d')", OK);
1450 printf("define(`CF_CURSES_ERR',`%d')", ERR);
1451 printf("define(`CF_CURSES_TRUE',`%d')", TRUE);
1452 printf("define(`CF_CURSES_FALSE',`%d')", FALSE);
1457 char *buf = (char *)malloc(2048);
1464 p += eti_gen(p, E_OK, "Ok", &etimin, &etimax);
1465 p += eti_gen(p, E_SYSTEM_ERROR, "System_Error", &etimin, &etimax);
1466 p += eti_gen(p, E_BAD_ARGUMENT, "Bad_Argument", &etimin, &etimax);
1467 p += eti_gen(p, E_POSTED, "Posted", &etimin, &etimax);
1468 p += eti_gen(p, E_CONNECTED, "Connected", &etimin, &etimax);
1469 p += eti_gen(p, E_BAD_STATE, "Bad_State", &etimin, &etimax);
1470 p += eti_gen(p, E_NO_ROOM, "No_Room", &etimin, &etimax);
1471 p += eti_gen(p, E_NOT_POSTED, "Not_Posted", &etimin, &etimax);
1472 p += eti_gen(p, E_UNKNOWN_COMMAND,
1473 "Unknown_Command", &etimin, &etimax);
1474 p += eti_gen(p, E_NO_MATCH, "No_Match", &etimin, &etimax);
1475 p += eti_gen(p, E_NOT_SELECTABLE,
1476 "Not_Selectable", &etimin, &etimax);
1477 p += eti_gen(p, E_NOT_CONNECTED,
1478 "Not_Connected", &etimin, &etimax);
1479 p += eti_gen(p, E_REQUEST_DENIED,
1480 "Request_Denied", &etimin, &etimax);
1481 p += eti_gen(p, E_INVALID_FIELD,
1482 "Invalid_Field", &etimin, &etimax);
1483 p += eti_gen(p, E_CURRENT,
1484 "Current", &etimin, &etimax);
1486 printf(" subtype Eti_Error is C_Int range %d .. %d;\n\n",
1495 /* --------------------------------------------------------------- */
1496 case 'V': /* plain version dump */
1500 case '1': /* major version */
1501 #ifdef NCURSES_VERSION_MAJOR
1502 printf("%d", NCURSES_VERSION_MAJOR);
1505 case '2': /* minor version */
1506 #ifdef NCURSES_VERSION_MINOR
1507 printf("%d", NCURSES_VERSION_MINOR);
1510 case '3': /* patch level */
1511 #ifdef NCURSES_VERSION_PATCH
1512 printf("%d", NCURSES_VERSION_PATCH);
1520 /* --------------------------------------------------------------- */