1 /****************************************************************************
2 * Copyright (c) 1998,2004,2005 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.40 2005/01/22 17:03:48 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.
53 #define RES_NAME "Reserved"
55 static const char *model = "";
56 static int little_endian = 0;
66 find_pos(char *s, unsigned len, int *low, int *high)
74 for (i = 0; i < len; i++, s++)
78 for (j = 0; j < 8 * sizeof(char); j++)
81 if (((little_endian && ((*s) & 0x01)) ||
82 (!little_endian && ((*s) & 0x80))))
99 return (*high >= 0 && (*low <= *high)) ? *low : -1;
103 * This helper routine generates a representation clause for a
104 * record type defined in the binding.
105 * We are only dealing with record types which are of 32 or 16
106 * bit size, i.e. they fit into an (u)int or a (u)short.
110 (const name_attribute_pair * nap, /* array of name_attribute_pair records */
111 const char *name, /* name of the represented record type */
112 int len, /* size of the record in bytes */
115 int i, n, l, cnt = 0, low, high;
116 int width = strlen(RES_NAME) + 3;
118 unsigned long mask = 0;
122 for (i = 0; nap[i].name != (char *)0; i++)
125 l = strlen(nap[i].name);
131 printf(" type %s is\n", name);
133 for (i = 0; nap[i].name != (char *)0; i++)
135 printf(" %-*s : Boolean;\n", width, nap[i].name);
137 printf(" end record;\n");
138 printf(" pragma Convention (C, %s);\n\n", name);
140 printf(" for %s use\n", name);
143 for (i = 0; nap[i].name != (char *)0; i++)
147 l = find_pos((char *)&a, sizeof(a), &low, &high);
149 printf(" %-*s at 0 range %2d .. %2d;\n", width, nap[i].name,
150 low - bias, high - bias);
154 printf(" end record;\n");
155 printf(" for %s'Size use %d;\n", name, 8 * len);
156 printf(" -- Please note: this rep. clause is generated and may be\n");
157 printf(" -- different on your system.");
161 chtype_rep(const char *name, attr_t mask)
166 int l = find_pos((char *)&t, sizeof(t), &low, &high);
169 printf(" %-5s at 0 range %2d .. %2d;\n", name, low, high);
173 gen_chtype_rep(const char *name)
175 printf(" for %s use\n record\n", name);
176 chtype_rep("Ch", A_CHARTEXT);
177 chtype_rep("Color", A_COLOR);
178 chtype_rep("Attr", (A_ATTRIBUTES & ~A_COLOR));
179 printf(" end record;\n for %s'Size use %ld;\n",
180 name, (long)(8 * sizeof(chtype)));
182 printf(" -- Please note: this rep. clause is generated and may be\n");
183 printf(" -- different on your system.\n");
187 mrep_rep(const char *name, void *rec)
190 int l = find_pos((char *)rec, sizeof(MEVENT), &low, &high);
193 printf(" %-7s at 0 range %3d .. %3d;\n", name, low, high);
197 gen_mrep_rep(const char *name)
201 printf(" for %s use\n record\n", name);
203 memset(&x, 0, sizeof(x));
207 memset(&x, 0, sizeof(x));
211 memset(&x, 0, sizeof(x));
215 memset(&x, 0, sizeof(x));
219 memset(&x, 0, sizeof(x));
221 mrep_rep("Bstate", &x);
223 printf(" end record;\n");
224 printf(" -- Please note: this rep. clause is generated and may be\n");
225 printf(" -- different on your system.\n");
229 gen_attr_set(const char *name)
231 /* All of the A_xxx symbols are defined in ncurses, but not all are nonzero
232 * if "configure --enable-widec" is specified.
234 static const name_attribute_pair nap[] =
237 {"Stand_Out", A_STANDOUT},
240 {"Under_Line", A_UNDERLINE},
243 {"Reverse_Video", A_REVERSE},
249 {"Dim_Character", A_DIM},
252 {"Bold_Character", A_BOLD},
255 {"Alternate_Character_Set", A_ALTCHARSET},
258 {"Invisible_Character", A_INVIS},
261 {"Protected_Character", A_PROTECT},
264 {"Horizontal", A_HORIZONTAL},
279 {"Vertical", A_VERTICAL},
283 chtype attr = A_ATTRIBUTES & ~A_COLOR;
287 for (i = 0; i < (int)(8 * sizeof(chtype)); i++)
302 gen_reps(nap, name, (len + 7) / 8, little_endian ? start : 0);
306 gen_trace(const char *name)
308 static const name_attribute_pair nap[] =
310 {"Times", TRACE_TIMES},
311 {"Tputs", TRACE_TPUTS},
312 {"Update", TRACE_UPDATE},
313 {"Cursor_Move", TRACE_MOVE},
314 {"Character_Output", TRACE_CHARPUT},
315 {"Calls", TRACE_CALLS},
316 {"Virtual_Puts", TRACE_VIRTPUT},
317 {"Input_Events", TRACE_IEVENT},
318 {"TTY_State", TRACE_BITS},
319 {"Internal_Calls", TRACE_ICALLS},
320 {"Character_Calls", TRACE_CCALLS},
321 {"Termcap_TermInfo", TRACE_DATABASE},
324 gen_reps(nap, name, sizeof(int), 0);
328 gen_menu_opt_rep(const char *name)
330 static const name_attribute_pair nap[] =
333 {"One_Valued", O_ONEVALUE},
336 {"Show_Descriptions", O_SHOWDESC},
339 {"Row_Major_Order", O_ROWMAJOR},
342 {"Ignore_Case", O_IGNORECASE},
345 {"Show_Matches", O_SHOWMATCH},
348 {"Non_Cyclic", O_NONCYCLIC},
352 gen_reps(nap, name, sizeof(int), 0);
356 gen_item_opt_rep(const char *name)
358 static const name_attribute_pair nap[] =
361 {"Selectable", O_SELECTABLE},
365 gen_reps(nap, name, sizeof(int), 0);
369 gen_form_opt_rep(const char *name)
371 static const name_attribute_pair nap[] =
374 {"NL_Overload", O_NL_OVERLOAD},
377 {"BS_Overload", O_BS_OVERLOAD},
381 gen_reps(nap, name, sizeof(int), 0);
385 * Generate the representation clause for the Field_Option_Set record
388 gen_field_opt_rep(const char *name)
390 static const name_attribute_pair nap[] =
393 {"Visible", O_VISIBLE},
396 {"Active", O_ACTIVE},
399 {"Public", O_PUBLIC},
411 {"Auto_Skip", O_AUTOSKIP},
414 {"Null_Ok", O_NULLOK},
417 {"Pass_Ok", O_PASSOK},
420 {"Static", O_STATIC},
424 gen_reps(nap, name, sizeof(int), 0);
428 * Generate a single key code constant definition.
431 keydef(const char *name, const char *old_name, int value, int mode)
433 if (mode == 0) /* Generate the new name */
434 printf(" %-30s : constant Special_Key_Code := 8#%3o#;\n", name, value);
436 { /* generate the old name, but only if it doesn't conflict with the old
437 * name (Ada95 isn't case sensitive!)
439 const char *s = old_name;
440 const char *t = name;
442 while (*s && *t && (toupper(*s++) == toupper(*t++)));
444 printf(" %-16s : Special_Key_Code renames %s;\n", old_name, name);
449 * Generate constants for the key codes. When called with mode==0, a
450 * complete list with nice constant names in proper casing style will
451 * be generated. Otherwise a list of old (i.e. C-style) names will be
452 * generated, given that the name wasn't already defined in the "nice"
456 gen_keydefs(int mode)
463 keydef("Key_Code_Yes", "KEY_CODE_YES", KEY_CODE_YES, mode);
466 keydef("Key_Min", "KEY_MIN", KEY_MIN, mode);
469 keydef("Key_Break", "KEY_BREAK", KEY_BREAK, mode);
472 keydef("Key_Cursor_Down", "KEY_DOWN", KEY_DOWN, mode);
475 keydef("Key_Cursor_Up", "KEY_UP", KEY_UP, mode);
478 keydef("Key_Cursor_Left", "KEY_LEFT", KEY_LEFT, mode);
481 keydef("Key_Cursor_Right", "KEY_RIGHT", KEY_RIGHT, mode);
484 keydef("Key_Home", "KEY_HOME", KEY_HOME, mode);
487 keydef("Key_Backspace", "KEY_BACKSPACE", KEY_BACKSPACE, mode);
490 keydef("Key_F0", "KEY_F0", KEY_F0, mode);
493 for (i = 1; i <= 24; i++)
495 sprintf(buf, "Key_F%d", i);
496 sprintf(obuf, "KEY_F%d", i);
497 keydef(buf, obuf, KEY_F(i), mode);
501 keydef("Key_Delete_Line", "KEY_DL", KEY_DL, mode);
504 keydef("Key_Insert_Line", "KEY_IL", KEY_IL, mode);
507 keydef("Key_Delete_Char", "KEY_DC", KEY_DC, mode);
510 keydef("Key_Insert_Char", "KEY_IC", KEY_IC, mode);
513 keydef("Key_Exit_Insert_Mode", "KEY_EIC", KEY_EIC, mode);
516 keydef("Key_Clear_Screen", "KEY_CLEAR", KEY_CLEAR, mode);
519 keydef("Key_Clear_End_Of_Screen", "KEY_EOS", KEY_EOS, mode);
522 keydef("Key_Clear_End_Of_Line", "KEY_EOL", KEY_EOL, mode);
525 keydef("Key_Scroll_1_Forward", "KEY_SF", KEY_SF, mode);
528 keydef("Key_Scroll_1_Backward", "KEY_SR", KEY_SR, mode);
531 keydef("Key_Next_Page", "KEY_NPAGE", KEY_NPAGE, mode);
534 keydef("Key_Previous_Page", "KEY_PPAGE", KEY_PPAGE, mode);
537 keydef("Key_Set_Tab", "KEY_STAB", KEY_STAB, mode);
540 keydef("Key_Clear_Tab", "KEY_CTAB", KEY_CTAB, mode);
543 keydef("Key_Clear_All_Tabs", "KEY_CATAB", KEY_CATAB, mode);
546 keydef("Key_Enter_Or_Send", "KEY_ENTER", KEY_ENTER, mode);
549 keydef("Key_Soft_Reset", "KEY_SRESET", KEY_SRESET, mode);
552 keydef("Key_Reset", "KEY_RESET", KEY_RESET, mode);
555 keydef("Key_Print", "KEY_PRINT", KEY_PRINT, mode);
558 keydef("Key_Bottom", "KEY_LL", KEY_LL, mode);
561 keydef("Key_Upper_Left_Of_Keypad", "KEY_A1", KEY_A1, mode);
564 keydef("Key_Upper_Right_Of_Keypad", "KEY_A3", KEY_A3, mode);
567 keydef("Key_Center_Of_Keypad", "KEY_B2", KEY_B2, mode);
570 keydef("Key_Lower_Left_Of_Keypad", "KEY_C1", KEY_C1, mode);
573 keydef("Key_Lower_Right_Of_Keypad", "KEY_C3", KEY_C3, mode);
576 keydef("Key_Back_Tab", "KEY_BTAB", KEY_BTAB, mode);
579 keydef("Key_Beginning", "KEY_BEG", KEY_BEG, mode);
582 keydef("Key_Cancel", "KEY_CANCEL", KEY_CANCEL, mode);
585 keydef("Key_Close", "KEY_CLOSE", KEY_CLOSE, mode);
588 keydef("Key_Command", "KEY_COMMAND", KEY_COMMAND, mode);
591 keydef("Key_Copy", "KEY_COPY", KEY_COPY, mode);
594 keydef("Key_Create", "KEY_CREATE", KEY_CREATE, mode);
597 keydef("Key_End", "KEY_END", KEY_END, mode);
600 keydef("Key_Exit", "KEY_EXIT", KEY_EXIT, mode);
603 keydef("Key_Find", "KEY_FIND", KEY_FIND, mode);
606 keydef("Key_Help", "KEY_HELP", KEY_HELP, mode);
609 keydef("Key_Mark", "KEY_MARK", KEY_MARK, mode);
612 keydef("Key_Message", "KEY_MESSAGE", KEY_MESSAGE, mode);
615 keydef("Key_Move", "KEY_MOVE", KEY_MOVE, mode);
618 keydef("Key_Next", "KEY_NEXT", KEY_NEXT, mode);
621 keydef("Key_Open", "KEY_OPEN", KEY_OPEN, mode);
624 keydef("Key_Options", "KEY_OPTIONS", KEY_OPTIONS, mode);
627 keydef("Key_Previous", "KEY_PREVIOUS", KEY_PREVIOUS, mode);
630 keydef("Key_Redo", "KEY_REDO", KEY_REDO, mode);
633 keydef("Key_Reference", "KEY_REFERENCE", KEY_REFERENCE, mode);
636 keydef("Key_Refresh", "KEY_REFRESH", KEY_REFRESH, mode);
639 keydef("Key_Replace", "KEY_REPLACE", KEY_REPLACE, mode);
642 keydef("Key_Restart", "KEY_RESTART", KEY_RESTART, mode);
645 keydef("Key_Resume", "KEY_RESUME", KEY_RESUME, mode);
648 keydef("Key_Save", "KEY_SAVE", KEY_SAVE, mode);
651 keydef("Key_Shift_Begin", "KEY_SBEG", KEY_SBEG, mode);
654 keydef("Key_Shift_Cancel", "KEY_SCANCEL", KEY_SCANCEL, mode);
657 keydef("Key_Shift_Command", "KEY_SCOMMAND", KEY_SCOMMAND, mode);
660 keydef("Key_Shift_Copy", "KEY_SCOPY", KEY_SCOPY, mode);
663 keydef("Key_Shift_Create", "KEY_SCREATE", KEY_SCREATE, mode);
666 keydef("Key_Shift_Delete_Char", "KEY_SDC", KEY_SDC, mode);
669 keydef("Key_Shift_Delete_Line", "KEY_SDL", KEY_SDL, mode);
672 keydef("Key_Select", "KEY_SELECT", KEY_SELECT, mode);
675 keydef("Key_Shift_End", "KEY_SEND", KEY_SEND, mode);
678 keydef("Key_Shift_Clear_End_Of_Line", "KEY_SEOL", KEY_SEOL, mode);
681 keydef("Key_Shift_Exit", "KEY_SEXIT", KEY_SEXIT, mode);
684 keydef("Key_Shift_Find", "KEY_SFIND", KEY_SFIND, mode);
687 keydef("Key_Shift_Help", "KEY_SHELP", KEY_SHELP, mode);
690 keydef("Key_Shift_Home", "KEY_SHOME", KEY_SHOME, mode);
693 keydef("Key_Shift_Insert_Char", "KEY_SIC", KEY_SIC, mode);
696 keydef("Key_Shift_Cursor_Left", "KEY_SLEFT", KEY_SLEFT, mode);
699 keydef("Key_Shift_Message", "KEY_SMESSAGE", KEY_SMESSAGE, mode);
702 keydef("Key_Shift_Move", "KEY_SMOVE", KEY_SMOVE, mode);
705 keydef("Key_Shift_Next_Page", "KEY_SNEXT", KEY_SNEXT, mode);
708 keydef("Key_Shift_Options", "KEY_SOPTIONS", KEY_SOPTIONS, mode);
711 keydef("Key_Shift_Previous_Page", "KEY_SPREVIOUS", KEY_SPREVIOUS, mode);
714 keydef("Key_Shift_Print", "KEY_SPRINT", KEY_SPRINT, mode);
717 keydef("Key_Shift_Redo", "KEY_SREDO", KEY_SREDO, mode);
720 keydef("Key_Shift_Replace", "KEY_SREPLACE", KEY_SREPLACE, mode);
723 keydef("Key_Shift_Cursor_Right", "KEY_SRIGHT", KEY_SRIGHT, mode);
726 keydef("Key_Shift_Resume", "KEY_SRSUME", KEY_SRSUME, mode);
729 keydef("Key_Shift_Save", "KEY_SSAVE", KEY_SSAVE, mode);
732 keydef("Key_Shift_Suspend", "KEY_SSUSPEND", KEY_SSUSPEND, mode);
735 keydef("Key_Shift_Undo", "KEY_SUNDO", KEY_SUNDO, mode);
738 keydef("Key_Suspend", "KEY_SUSPEND", KEY_SUSPEND, mode);
741 keydef("Key_Undo", "KEY_UNDO", KEY_UNDO, mode);
744 keydef("Key_Mouse", "KEY_MOUSE", KEY_MOUSE, mode);
747 keydef("Key_Resize", "KEY_RESIZE", KEY_RESIZE, mode);
752 * Generate a constant with the given name. The second parameter
753 * is a reference to the ACS character in the acs_map[] array and
754 * will be translated into an index.
757 acs_def(const char *name, chtype *a)
759 int c = a - &acs_map[0];
761 printf(" %-24s : constant Character := ", name);
762 if (isprint(c) && (c != '`'))
763 printf("'%c';\n", c);
765 printf("Character'Val (%d);\n", c);
769 * Generate the constants for the ACS characters
775 acs_def("ACS_Upper_Left_Corner", &ACS_ULCORNER);
778 acs_def("ACS_Lower_Left_Corner", &ACS_LLCORNER);
781 acs_def("ACS_Upper_Right_Corner", &ACS_URCORNER);
784 acs_def("ACS_Lower_Right_Corner", &ACS_LRCORNER);
787 acs_def("ACS_Left_Tee", &ACS_LTEE);
790 acs_def("ACS_Right_Tee", &ACS_RTEE);
793 acs_def("ACS_Bottom_Tee", &ACS_BTEE);
796 acs_def("ACS_Top_Tee", &ACS_TTEE);
799 acs_def("ACS_Horizontal_Line", &ACS_HLINE);
802 acs_def("ACS_Vertical_Line", &ACS_VLINE);
805 acs_def("ACS_Plus_Symbol", &ACS_PLUS);
808 acs_def("ACS_Scan_Line_1", &ACS_S1);
811 acs_def("ACS_Scan_Line_9", &ACS_S9);
814 acs_def("ACS_Diamond", &ACS_DIAMOND);
817 acs_def("ACS_Checker_Board", &ACS_CKBOARD);
820 acs_def("ACS_Degree", &ACS_DEGREE);
823 acs_def("ACS_Plus_Minus", &ACS_PLMINUS);
826 acs_def("ACS_Bullet", &ACS_BULLET);
829 acs_def("ACS_Left_Arrow", &ACS_LARROW);
832 acs_def("ACS_Right_Arrow", &ACS_RARROW);
835 acs_def("ACS_Down_Arrow", &ACS_DARROW);
838 acs_def("ACS_Up_Arrow", &ACS_UARROW);
841 acs_def("ACS_Board_Of_Squares", &ACS_BOARD);
844 acs_def("ACS_Lantern", &ACS_LANTERN);
847 acs_def("ACS_Solid_Block", &ACS_BLOCK);
850 acs_def("ACS_Scan_Line_3", &ACS_S3);
853 acs_def("ACS_Scan_Line_7", &ACS_S7);
856 acs_def("ACS_Less_Or_Equal", &ACS_LEQUAL);
859 acs_def("ACS_Greater_Or_Equal", &ACS_GEQUAL);
862 acs_def("ACS_PI", &ACS_PI);
865 acs_def("ACS_Not_Equal", &ACS_NEQUAL);
868 acs_def("ACS_Sterling", &ACS_STERLING);
872 #define GEN_EVENT(name,value) \
873 printf(" %-25s : constant Event_Mask := 8#%011lo#;\n", \
876 #define GEN_MEVENT(name) \
877 printf(" %-25s : constant Event_Mask := 8#%011lo#;\n", \
882 gen_mouse_events(void)
889 #ifdef BUTTON1_RELEASED
890 GEN_MEVENT(BUTTON1_RELEASED);
891 all1 |= BUTTON1_RELEASED;
893 #ifdef BUTTON1_PRESSED
894 GEN_MEVENT(BUTTON1_PRESSED);
895 all1 |= BUTTON1_PRESSED;
897 #ifdef BUTTON1_CLICKED
898 GEN_MEVENT(BUTTON1_CLICKED);
899 all1 |= BUTTON1_CLICKED;
901 #ifdef BUTTON1_DOUBLE_CLICKED
902 GEN_MEVENT(BUTTON1_DOUBLE_CLICKED);
903 all1 |= BUTTON1_DOUBLE_CLICKED;
905 #ifdef BUTTON1_TRIPLE_CLICKED
906 GEN_MEVENT(BUTTON1_TRIPLE_CLICKED);
907 all1 |= BUTTON1_TRIPLE_CLICKED;
909 #ifdef BUTTON1_RESERVED_EVENT
910 GEN_MEVENT(BUTTON1_RESERVED_EVENT);
911 all1 |= BUTTON1_RESERVED_EVENT;
913 #ifdef BUTTON2_RELEASED
914 GEN_MEVENT(BUTTON2_RELEASED);
915 all2 |= BUTTON2_RELEASED;
917 #ifdef BUTTON2_PRESSED
918 GEN_MEVENT(BUTTON2_PRESSED);
919 all2 |= BUTTON2_PRESSED;
921 #ifdef BUTTON2_CLICKED
922 GEN_MEVENT(BUTTON2_CLICKED);
923 all2 |= BUTTON2_CLICKED;
925 #ifdef BUTTON2_DOUBLE_CLICKED
926 GEN_MEVENT(BUTTON2_DOUBLE_CLICKED);
927 all2 |= BUTTON2_DOUBLE_CLICKED;
929 #ifdef BUTTON2_TRIPLE_CLICKED
930 GEN_MEVENT(BUTTON2_TRIPLE_CLICKED);
931 all2 |= BUTTON2_TRIPLE_CLICKED;
933 #ifdef BUTTON2_RESERVED_EVENT
934 GEN_MEVENT(BUTTON2_RESERVED_EVENT);
935 all2 |= BUTTON2_RESERVED_EVENT;
937 #ifdef BUTTON3_RELEASED
938 GEN_MEVENT(BUTTON3_RELEASED);
939 all3 |= BUTTON3_RELEASED;
941 #ifdef BUTTON3_PRESSED
942 GEN_MEVENT(BUTTON3_PRESSED);
943 all3 |= BUTTON3_PRESSED;
945 #ifdef BUTTON3_CLICKED
946 GEN_MEVENT(BUTTON3_CLICKED);
947 all3 |= BUTTON3_CLICKED;
949 #ifdef BUTTON3_DOUBLE_CLICKED
950 GEN_MEVENT(BUTTON3_DOUBLE_CLICKED);
951 all3 |= BUTTON3_DOUBLE_CLICKED;
953 #ifdef BUTTON3_TRIPLE_CLICKED
954 GEN_MEVENT(BUTTON3_TRIPLE_CLICKED);
955 all3 |= BUTTON3_TRIPLE_CLICKED;
957 #ifdef BUTTON3_RESERVED_EVENT
958 GEN_MEVENT(BUTTON3_RESERVED_EVENT);
959 all3 |= BUTTON3_RESERVED_EVENT;
961 #ifdef BUTTON4_RELEASED
962 GEN_MEVENT(BUTTON4_RELEASED);
963 all4 |= BUTTON4_RELEASED;
965 #ifdef BUTTON4_PRESSED
966 GEN_MEVENT(BUTTON4_PRESSED);
967 all4 |= BUTTON4_PRESSED;
969 #ifdef BUTTON4_CLICKED
970 GEN_MEVENT(BUTTON4_CLICKED);
971 all4 |= BUTTON4_CLICKED;
973 #ifdef BUTTON4_DOUBLE_CLICKED
974 GEN_MEVENT(BUTTON4_DOUBLE_CLICKED);
975 all4 |= BUTTON4_DOUBLE_CLICKED;
977 #ifdef BUTTON4_TRIPLE_CLICKED
978 GEN_MEVENT(BUTTON4_TRIPLE_CLICKED);
979 all4 |= BUTTON4_TRIPLE_CLICKED;
981 #ifdef BUTTON4_RESERVED_EVENT
982 GEN_MEVENT(BUTTON4_RESERVED_EVENT);
983 all4 |= BUTTON4_RESERVED_EVENT;
986 GEN_MEVENT(BUTTON_CTRL);
989 GEN_MEVENT(BUTTON_SHIFT);
992 GEN_MEVENT(BUTTON_ALT);
994 #ifdef REPORT_MOUSE_POSITION
995 GEN_MEVENT(REPORT_MOUSE_POSITION);
997 #ifdef ALL_MOUSE_EVENTS
998 GEN_MEVENT(ALL_MOUSE_EVENTS);
1001 GEN_EVENT(BUTTON1_EVENTS, all1);
1002 GEN_EVENT(BUTTON2_EVENTS, all2);
1003 GEN_EVENT(BUTTON3_EVENTS, all3);
1004 GEN_EVENT(BUTTON4_EVENTS, all4);
1008 * Output some comment lines indicating that the file is generated.
1009 * The name parameter is the name of the facility to be used in
1013 prologue(const char *name)
1015 printf("-- %s binding.\n", name);
1016 printf("-- This module is generated. Please don't change it manually!\n");
1017 printf("-- Run the generator instead.\n-- |");
1019 printf("define(`M4_BIT_ORDER',`%s_Order_First')",
1020 little_endian ? "Low" : "High");
1024 * Write the prologue for the curses facility and make sure that
1025 * KEY_MIN and KEY_MAX are defined for the rest of this source.
1032 # define KEY_MAX 0777
1034 printf("define(`M4_KEY_MAX',`8#%o#')", KEY_MAX);
1036 # define KEY_MIN 0401
1040 fprintf(stderr, "Unexpected value for KEY_MIN: %d\n", KEY_MIN);
1043 printf("define(`M4_SPECIAL_FIRST',`8#%o#')", KEY_MIN - 1);
1047 * Write out the comment lines for the menu facility
1056 * Write out the comment lines for the form facility
1065 * Write out the comment lines for the mouse facility
1068 mouse_basedefs(void)
1074 * Write the definition of a single color
1077 color_def(const char *name, int value)
1079 printf(" %-16s : constant Color_Number := %d;\n", name, value);
1082 #define HAVE_USE_DEFAULT_COLORS 1
1085 * Generate all color definitions
1090 #ifdef HAVE_USE_DEFAULT_COLORS
1091 color_def("Default_Color", -1);
1094 color_def("Black", COLOR_BLACK);
1097 color_def("Red", COLOR_RED);
1100 color_def("Green", COLOR_GREEN);
1103 color_def("Yellow", COLOR_YELLOW);
1106 color_def("Blue", COLOR_BLUE);
1108 #ifdef COLOR_MAGENTA
1109 color_def("Magenta", COLOR_MAGENTA);
1112 color_def("Cyan", COLOR_CYAN);
1115 color_def("White", COLOR_WHITE);
1120 * Generate the linker options for the base facility
1125 printf(" pragma Linker_Options (\"-lncurses%s\");\n", model);
1129 * Generate the linker options for the menu facility
1132 gen_menu_linkopts(void)
1134 printf(" pragma Linker_Options (\"-lmenu%s\");\n", model);
1138 * Generate the linker options for the form facility
1141 gen_form_linkopts(void)
1143 printf(" pragma Linker_Options (\"-lform%s\");\n", model);
1147 * Generate the linker options for the panel facility
1150 gen_panel_linkopts(void)
1152 printf(" pragma Linker_Options (\"-lpanel%s\");\n", model);
1156 gen_version_info(void)
1158 static const char *v1 =
1159 " NC_Major_Version : constant := %d; -- Major version of the library\n";
1160 static const char *v2 =
1161 " NC_Minor_Version : constant := %d; -- Minor version of the library\n";
1162 static const char *v3 =
1163 " NC_Version : constant String := %c%d.%d%c; -- Version of library\n";
1165 printf(v1, NCURSES_VERSION_MAJOR);
1166 printf(v2, NCURSES_VERSION_MINOR);
1167 printf(v3, '"', NCURSES_VERSION_MAJOR, NCURSES_VERSION_MINOR, '"');
1171 eti_gen(char *buf, int code, const char *name, int *etimin, int *etimax)
1173 sprintf(buf, " E_%-16s : constant Eti_Error := %d;\n", name, code);
1181 #define GEN_OFFSET(member,itype) \
1182 if (sizeof(((WINDOW*)0)->member)==sizeof(itype)) { \
1183 o = offsetof(WINDOW, member); \
1184 if ((o%sizeof(itype) == 0)) { \
1185 printf(" Offset%-*s : constant Natural := %2ld; -- %s\n", \
1186 12, #member, (long)(o/sizeof(itype)),#itype); \
1194 const char *s_bool = "";
1196 GEN_OFFSET(_maxy, short);
1197 GEN_OFFSET(_maxx, short);
1198 GEN_OFFSET(_begy, short);
1199 GEN_OFFSET(_begx, short);
1200 GEN_OFFSET(_cury, short);
1201 GEN_OFFSET(_curx, short);
1202 GEN_OFFSET(_yoffset, short);
1203 GEN_OFFSET(_pary, int);
1204 GEN_OFFSET(_parx, int);
1205 if (sizeof(bool) == sizeof(char))
1207 GEN_OFFSET(_notimeout, char);
1208 GEN_OFFSET(_clear, char);
1209 GEN_OFFSET(_leaveok, char);
1210 GEN_OFFSET(_scroll, char);
1211 GEN_OFFSET(_idlok, char);
1212 GEN_OFFSET(_idcok, char);
1213 GEN_OFFSET(_immed, char);
1214 GEN_OFFSET(_sync, char);
1215 GEN_OFFSET(_use_keypad, char);
1219 else if (sizeof(bool) == sizeof(short))
1221 GEN_OFFSET(_notimeout, short);
1222 GEN_OFFSET(_clear, short);
1223 GEN_OFFSET(_leaveok, short);
1224 GEN_OFFSET(_scroll, short);
1225 GEN_OFFSET(_idlok, short);
1226 GEN_OFFSET(_idcok, short);
1227 GEN_OFFSET(_immed, short);
1228 GEN_OFFSET(_sync, short);
1229 GEN_OFFSET(_use_keypad, short);
1233 else if (sizeof(bool) == sizeof(int))
1235 GEN_OFFSET(_notimeout, int);
1236 GEN_OFFSET(_clear, int);
1237 GEN_OFFSET(_leaveok, int);
1238 GEN_OFFSET(_scroll, int);
1239 GEN_OFFSET(_idlok, int);
1240 GEN_OFFSET(_idcok, int);
1241 GEN_OFFSET(_immed, int);
1242 GEN_OFFSET(_sync, int);
1243 GEN_OFFSET(_use_keypad, int);
1247 printf(" Sizeof%-*s : constant Natural := %2ld; -- %s\n",
1248 12, "_bool", (long)sizeof(bool), "bool");
1250 /* In ncurses _maxy and _maxx needs an offset for the "public"
1253 printf(" Offset%-*s : constant Natural := %2d; -- %s\n",
1254 12, "_XY", 1, "int");
1256 printf(" type Curses_Bool is mod 2 ** Interfaces.C.%s'Size;\n", s_bool);
1260 * main() expects two arguments on the commandline, both single characters.
1261 * The first character denotes the facility for which we generate output.
1262 * Possible values are
1266 * P - Pointer Device (Mouse)
1267 * E - ETI base definitions
1269 * The second character then denotes the specific output that should be
1270 * generated for the selected facility.
1273 main(int argc, char *argv[])
1276 char *s = (char *)&x;
1287 /* --------------------------------------------------------------- */
1288 case 'B': /* The Base facility */
1291 case 'A': /* chtype translation into Ada95 record type */
1292 gen_attr_set("Character_Attribute_Set");
1294 case 'K': /* translation of keycodes */
1297 case 'B': /* write some initial comment lines */
1300 case 'C': /* generate color constants */
1303 case 'D': /* generate displacements of fields in WINDOW struct. */
1306 case 'E': /* generate Mouse Event codes */
1309 case 'M': /* generate constants for the ACS characters */
1312 case 'L': /* generate the Linker_Options pragma */
1315 case 'O': /* generate definitions of the old key code names */
1318 case 'R': /* generate representation clause for Attributed character */
1319 gen_chtype_rep("Attributed_Character");
1321 case 'V': /* generate version info */
1324 case 'T': /* generate the Trace info */
1325 gen_trace("Trace_Attribute_Set");
1331 /* --------------------------------------------------------------- */
1332 case 'M': /* The Menu facility */
1335 case 'R': /* generate representation clause for Menu_Option_Set */
1336 gen_menu_opt_rep("Menu_Option_Set");
1338 case 'B': /* write some initial comment lines */
1341 case 'L': /* generate the Linker_Options pragma */
1342 gen_menu_linkopts();
1344 case 'I': /* generate representation clause for Item_Option_Set */
1345 gen_item_opt_rep("Item_Option_Set");
1351 /* --------------------------------------------------------------- */
1352 case 'F': /* The Form facility */
1355 case 'R': /* generate representation clause for Form_Option_Set */
1356 gen_form_opt_rep("Form_Option_Set");
1358 case 'B': /* write some initial comment lines */
1361 case 'L': /* generate the Linker_Options pragma */
1362 gen_form_linkopts();
1364 case 'I': /* generate representation clause for Field_Option_Set */
1365 gen_field_opt_rep("Field_Option_Set");
1371 /* --------------------------------------------------------------- */
1372 case 'P': /* The Pointer(=Mouse) facility */
1375 case 'B': /* write some initial comment lines */
1378 case 'M': /* generate representation clause for Mouse_Event */
1379 gen_mrep_rep("Mouse_Event");
1381 case 'L': /* generate the Linker_Options pragma */
1382 gen_panel_linkopts();
1388 /* --------------------------------------------------------------- */
1389 case 'E': /* chtype size detection */
1394 const char *fmt = " type C_Chtype is new %s;\n";
1395 const char *afmt = " type C_AttrType is new %s;\n";
1397 if (sizeof(chtype) == sizeof(int))
1399 if (sizeof(int) == sizeof(long))
1400 printf(fmt, "C_ULong");
1403 printf(fmt, "C_UInt");
1405 else if (sizeof(chtype) == sizeof(long))
1407 printf(fmt, "C_ULong");
1412 if (sizeof(attr_t) == sizeof(int))
1414 if (sizeof(int) == sizeof(long))
1415 printf(afmt, "C_ULong");
1418 printf(afmt, "C_UInt");
1420 else if (sizeof(attr_t) == sizeof(long))
1422 printf(afmt, "C_ULong");
1427 printf("define(`CF_CURSES_OK',`%d')", OK);
1428 printf("define(`CF_CURSES_ERR',`%d')", ERR);
1429 printf("define(`CF_CURSES_TRUE',`%d')", TRUE);
1430 printf("define(`CF_CURSES_FALSE',`%d')", FALSE);
1435 char *buf = (char *)malloc(2048);
1442 p += eti_gen(p, E_OK, "Ok", &etimin, &etimax);
1443 p += eti_gen(p, E_SYSTEM_ERROR, "System_Error", &etimin, &etimax);
1444 p += eti_gen(p, E_BAD_ARGUMENT, "Bad_Argument", &etimin, &etimax);
1445 p += eti_gen(p, E_POSTED, "Posted", &etimin, &etimax);
1446 p += eti_gen(p, E_CONNECTED, "Connected", &etimin, &etimax);
1447 p += eti_gen(p, E_BAD_STATE, "Bad_State", &etimin, &etimax);
1448 p += eti_gen(p, E_NO_ROOM, "No_Room", &etimin, &etimax);
1449 p += eti_gen(p, E_NOT_POSTED, "Not_Posted", &etimin, &etimax);
1450 p += eti_gen(p, E_UNKNOWN_COMMAND,
1451 "Unknown_Command", &etimin, &etimax);
1452 p += eti_gen(p, E_NO_MATCH, "No_Match", &etimin, &etimax);
1453 p += eti_gen(p, E_NOT_SELECTABLE,
1454 "Not_Selectable", &etimin, &etimax);
1455 p += eti_gen(p, E_NOT_CONNECTED,
1456 "Not_Connected", &etimin, &etimax);
1457 p += eti_gen(p, E_REQUEST_DENIED,
1458 "Request_Denied", &etimin, &etimax);
1459 p += eti_gen(p, E_INVALID_FIELD,
1460 "Invalid_Field", &etimin, &etimax);
1461 p += eti_gen(p, E_CURRENT,
1462 "Current", &etimin, &etimax);
1464 printf(" subtype Eti_Error is C_Int range %d .. %d;\n\n",
1473 /* --------------------------------------------------------------- */
1474 case 'V': /* plain version dump */
1478 case '1': /* major version */
1479 #ifdef NCURSES_VERSION_MAJOR
1480 printf("%d", NCURSES_VERSION_MAJOR);
1483 case '2': /* minor version */
1484 #ifdef NCURSES_VERSION_MINOR
1485 printf("%d", NCURSES_VERSION_MINOR);
1488 case '3': /* patch level */
1489 #ifdef NCURSES_VERSION_PATCH
1490 printf("%d", NCURSES_VERSION_PATCH);
1498 /* --------------------------------------------------------------- */