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.52 2010/02/20 21:59:56 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 RES_NAME "Reserved"
62 static const char *model = "";
63 static int little_endian = 0;
73 find_pos(char *s, unsigned len, int *low, int *high)
79 *low = (int)(8 * len);
81 for (i = 0; i < len; i++, s++)
85 for (j = 0; j < 8 * sizeof(char); j++)
88 if (((little_endian && ((*s) & 0x01)) ||
89 (!little_endian && ((*s) & 0x80))))
103 *s = (char)(*s << 1);
110 return (*high >= 0 && (*low <= *high)) ? *low : -1;
114 * This helper routine generates a representation clause for a
115 * record type defined in the binding.
116 * We are only dealing with record types which are of 32 or 16
117 * bit size, i.e. they fit into an (u)int or a (u)short.
121 const name_attribute_pair * nap, /* array of name_attribute_pair records */
122 const char *name, /* name of the represented record type */
123 int len, /* size of the record in bytes */
126 int i, n, l, cnt = 0, low, high;
127 int width = strlen(RES_NAME) + 3;
129 unsigned long mask = 0;
133 for (i = 0; nap[i].name != (char *)0; i++)
136 l = (int)strlen(nap[i].name);
142 printf(" type %s is\n", name);
144 for (i = 0; nap[i].name != (char *)0; i++)
146 printf(" %-*s : Boolean;\n", width, nap[i].name);
148 printf(" end record;\n");
149 printf(" pragma Convention (C, %s);\n\n", name);
151 printf(" for %s use\n", name);
154 for (i = 0; nap[i].name != (char *)0; i++)
158 l = find_pos((char *)&a, sizeof(a), &low, &high);
160 printf(" %-*s at 0 range %2d .. %2d;\n", width, nap[i].name,
161 low - bias, high - bias);
165 printf(" end record;\n");
166 printf(" for %s'Size use %d;\n", name, 8 * len);
167 printf(" -- Please note: this rep. clause is generated and may be\n");
168 printf(" -- different on your system.");
172 chtype_rep(const char *name, attr_t mask)
174 attr_t x = (attr_t)-1;
177 int l = find_pos((char *)&t, sizeof(t), &low, &high);
180 printf(" %-5s at 0 range %2d .. %2d;\n", name, low, high);
184 gen_chtype_rep(const char *name)
186 printf(" for %s use\n record\n", name);
187 chtype_rep("Ch", A_CHARTEXT);
188 chtype_rep("Color", A_COLOR);
189 chtype_rep("Attr", (A_ATTRIBUTES & ~A_COLOR));
190 printf(" end record;\n for %s'Size use %ld;\n",
191 name, (long)(8 * sizeof(chtype)));
193 printf(" -- Please note: this rep. clause is generated and may be\n");
194 printf(" -- different on your system.\n");
198 mrep_rep(const char *name, void *rec)
201 int l = find_pos((char *)rec, sizeof(MEVENT), &low, &high);
204 printf(" %-7s at 0 range %3d .. %3d;\n", name, low, high);
208 gen_mrep_rep(const char *name)
212 printf(" for %s use\n record\n", name);
214 memset(&x, 0, sizeof(x));
218 memset(&x, 0, sizeof(x));
222 memset(&x, 0, sizeof(x));
226 memset(&x, 0, sizeof(x));
230 memset(&x, 0, sizeof(x));
231 x.bstate = (mmask_t) - 1;
232 mrep_rep("Bstate", &x);
234 printf(" end record;\n");
235 printf(" -- Please note: this rep. clause is generated and may be\n");
236 printf(" -- different on your system.\n");
240 gen_attr_set(const char *name)
242 /* All of the A_xxx symbols are defined in ncurses, but not all are nonzero
243 * if "configure --enable-widec" is specified.
245 static const name_attribute_pair nap[] =
248 {"Stand_Out", A_STANDOUT},
251 {"Under_Line", A_UNDERLINE},
254 {"Reverse_Video", A_REVERSE},
260 {"Dim_Character", A_DIM},
263 {"Bold_Character", A_BOLD},
266 {"Alternate_Character_Set", A_ALTCHARSET},
269 {"Invisible_Character", A_INVIS},
272 {"Protected_Character", A_PROTECT},
275 {"Horizontal", A_HORIZONTAL},
290 {"Vertical", A_VERTICAL},
294 chtype attr = A_ATTRIBUTES & ~A_COLOR;
299 for (i = 0; i < (int)(8 * sizeof(chtype)); i++)
314 gen_reps(nap, name, (len + 7) / 8, little_endian ? start : 0);
318 gen_trace(const char *name)
320 static const name_attribute_pair nap[] =
322 {"Times", TRACE_TIMES},
323 {"Tputs", TRACE_TPUTS},
324 {"Update", TRACE_UPDATE},
325 {"Cursor_Move", TRACE_MOVE},
326 {"Character_Output", TRACE_CHARPUT},
327 {"Calls", TRACE_CALLS},
328 {"Virtual_Puts", TRACE_VIRTPUT},
329 {"Input_Events", TRACE_IEVENT},
330 {"TTY_State", TRACE_BITS},
331 {"Internal_Calls", TRACE_ICALLS},
332 {"Character_Calls", TRACE_CCALLS},
333 {"Termcap_TermInfo", TRACE_DATABASE},
336 gen_reps(nap, name, sizeof(int), 0);
340 gen_menu_opt_rep(const char *name)
342 static const name_attribute_pair nap[] =
345 {"One_Valued", O_ONEVALUE},
348 {"Show_Descriptions", O_SHOWDESC},
351 {"Row_Major_Order", O_ROWMAJOR},
354 {"Ignore_Case", O_IGNORECASE},
357 {"Show_Matches", O_SHOWMATCH},
360 {"Non_Cyclic", O_NONCYCLIC},
364 gen_reps(nap, name, sizeof(int), 0);
368 gen_item_opt_rep(const char *name)
370 static const name_attribute_pair nap[] =
373 {"Selectable", O_SELECTABLE},
377 gen_reps(nap, name, sizeof(int), 0);
381 gen_form_opt_rep(const char *name)
383 static const name_attribute_pair nap[] =
386 {"NL_Overload", O_NL_OVERLOAD},
389 {"BS_Overload", O_BS_OVERLOAD},
393 gen_reps(nap, name, sizeof(int), 0);
397 * Generate the representation clause for the Field_Option_Set record
400 gen_field_opt_rep(const char *name)
402 static const name_attribute_pair nap[] =
405 {"Visible", O_VISIBLE},
408 {"Active", O_ACTIVE},
411 {"Public", O_PUBLIC},
423 {"Auto_Skip", O_AUTOSKIP},
426 {"Null_Ok", O_NULLOK},
429 {"Pass_Ok", O_PASSOK},
432 {"Static", O_STATIC},
436 gen_reps(nap, name, sizeof(int), 0);
440 * Generate a single key code constant definition.
443 keydef(const char *name, const char *old_name, int value, int mode)
445 if (mode == 0) /* Generate the new name */
446 printf(" %-30s : constant Special_Key_Code := 8#%3o#;\n", name, value);
448 { /* generate the old name, but only if it doesn't conflict with the old
449 * name (Ada95 isn't case sensitive!)
451 const char *s = old_name;
452 const char *t = name;
454 while (*s && *t && (toupper(*s++) == toupper(*t++)));
456 printf(" %-16s : Special_Key_Code renames %s;\n", old_name, name);
461 * Generate constants for the key codes. When called with mode==0, a
462 * complete list with nice constant names in proper casing style will
463 * be generated. Otherwise a list of old (i.e. C-style) names will be
464 * generated, given that the name wasn't already defined in the "nice"
468 gen_keydefs(int mode)
475 keydef("Key_Code_Yes", "KEY_CODE_YES", KEY_CODE_YES, mode);
478 keydef("Key_Min", "KEY_MIN", KEY_MIN, mode);
481 keydef("Key_Break", "KEY_BREAK", KEY_BREAK, mode);
484 keydef("Key_Cursor_Down", "KEY_DOWN", KEY_DOWN, mode);
487 keydef("Key_Cursor_Up", "KEY_UP", KEY_UP, mode);
490 keydef("Key_Cursor_Left", "KEY_LEFT", KEY_LEFT, mode);
493 keydef("Key_Cursor_Right", "KEY_RIGHT", KEY_RIGHT, mode);
496 keydef("Key_Home", "KEY_HOME", KEY_HOME, mode);
499 keydef("Key_Backspace", "KEY_BACKSPACE", KEY_BACKSPACE, mode);
502 keydef("Key_F0", "KEY_F0", KEY_F0, mode);
505 for (i = 1; i <= 24; i++)
507 sprintf(buf, "Key_F%d", i);
508 sprintf(obuf, "KEY_F%d", i);
509 keydef(buf, obuf, KEY_F(i), mode);
513 keydef("Key_Delete_Line", "KEY_DL", KEY_DL, mode);
516 keydef("Key_Insert_Line", "KEY_IL", KEY_IL, mode);
519 keydef("Key_Delete_Char", "KEY_DC", KEY_DC, mode);
522 keydef("Key_Insert_Char", "KEY_IC", KEY_IC, mode);
525 keydef("Key_Exit_Insert_Mode", "KEY_EIC", KEY_EIC, mode);
528 keydef("Key_Clear_Screen", "KEY_CLEAR", KEY_CLEAR, mode);
531 keydef("Key_Clear_End_Of_Screen", "KEY_EOS", KEY_EOS, mode);
534 keydef("Key_Clear_End_Of_Line", "KEY_EOL", KEY_EOL, mode);
537 keydef("Key_Scroll_1_Forward", "KEY_SF", KEY_SF, mode);
540 keydef("Key_Scroll_1_Backward", "KEY_SR", KEY_SR, mode);
543 keydef("Key_Next_Page", "KEY_NPAGE", KEY_NPAGE, mode);
546 keydef("Key_Previous_Page", "KEY_PPAGE", KEY_PPAGE, mode);
549 keydef("Key_Set_Tab", "KEY_STAB", KEY_STAB, mode);
552 keydef("Key_Clear_Tab", "KEY_CTAB", KEY_CTAB, mode);
555 keydef("Key_Clear_All_Tabs", "KEY_CATAB", KEY_CATAB, mode);
558 keydef("Key_Enter_Or_Send", "KEY_ENTER", KEY_ENTER, mode);
561 keydef("Key_Soft_Reset", "KEY_SRESET", KEY_SRESET, mode);
564 keydef("Key_Reset", "KEY_RESET", KEY_RESET, mode);
567 keydef("Key_Print", "KEY_PRINT", KEY_PRINT, mode);
570 keydef("Key_Bottom", "KEY_LL", KEY_LL, mode);
573 keydef("Key_Upper_Left_Of_Keypad", "KEY_A1", KEY_A1, mode);
576 keydef("Key_Upper_Right_Of_Keypad", "KEY_A3", KEY_A3, mode);
579 keydef("Key_Center_Of_Keypad", "KEY_B2", KEY_B2, mode);
582 keydef("Key_Lower_Left_Of_Keypad", "KEY_C1", KEY_C1, mode);
585 keydef("Key_Lower_Right_Of_Keypad", "KEY_C3", KEY_C3, mode);
588 keydef("Key_Back_Tab", "KEY_BTAB", KEY_BTAB, mode);
591 keydef("Key_Beginning", "KEY_BEG", KEY_BEG, mode);
594 keydef("Key_Cancel", "KEY_CANCEL", KEY_CANCEL, mode);
597 keydef("Key_Close", "KEY_CLOSE", KEY_CLOSE, mode);
600 keydef("Key_Command", "KEY_COMMAND", KEY_COMMAND, mode);
603 keydef("Key_Copy", "KEY_COPY", KEY_COPY, mode);
606 keydef("Key_Create", "KEY_CREATE", KEY_CREATE, mode);
609 keydef("Key_End", "KEY_END", KEY_END, mode);
612 keydef("Key_Exit", "KEY_EXIT", KEY_EXIT, mode);
615 keydef("Key_Find", "KEY_FIND", KEY_FIND, mode);
618 keydef("Key_Help", "KEY_HELP", KEY_HELP, mode);
621 keydef("Key_Mark", "KEY_MARK", KEY_MARK, mode);
624 keydef("Key_Message", "KEY_MESSAGE", KEY_MESSAGE, mode);
627 keydef("Key_Move", "KEY_MOVE", KEY_MOVE, mode);
630 keydef("Key_Next", "KEY_NEXT", KEY_NEXT, mode);
633 keydef("Key_Open", "KEY_OPEN", KEY_OPEN, mode);
636 keydef("Key_Options", "KEY_OPTIONS", KEY_OPTIONS, mode);
639 keydef("Key_Previous", "KEY_PREVIOUS", KEY_PREVIOUS, mode);
642 keydef("Key_Redo", "KEY_REDO", KEY_REDO, mode);
645 keydef("Key_Reference", "KEY_REFERENCE", KEY_REFERENCE, mode);
648 keydef("Key_Refresh", "KEY_REFRESH", KEY_REFRESH, mode);
651 keydef("Key_Replace", "KEY_REPLACE", KEY_REPLACE, mode);
654 keydef("Key_Restart", "KEY_RESTART", KEY_RESTART, mode);
657 keydef("Key_Resume", "KEY_RESUME", KEY_RESUME, mode);
660 keydef("Key_Save", "KEY_SAVE", KEY_SAVE, mode);
663 keydef("Key_Shift_Begin", "KEY_SBEG", KEY_SBEG, mode);
666 keydef("Key_Shift_Cancel", "KEY_SCANCEL", KEY_SCANCEL, mode);
669 keydef("Key_Shift_Command", "KEY_SCOMMAND", KEY_SCOMMAND, mode);
672 keydef("Key_Shift_Copy", "KEY_SCOPY", KEY_SCOPY, mode);
675 keydef("Key_Shift_Create", "KEY_SCREATE", KEY_SCREATE, mode);
678 keydef("Key_Shift_Delete_Char", "KEY_SDC", KEY_SDC, mode);
681 keydef("Key_Shift_Delete_Line", "KEY_SDL", KEY_SDL, mode);
684 keydef("Key_Select", "KEY_SELECT", KEY_SELECT, mode);
687 keydef("Key_Shift_End", "KEY_SEND", KEY_SEND, mode);
690 keydef("Key_Shift_Clear_End_Of_Line", "KEY_SEOL", KEY_SEOL, mode);
693 keydef("Key_Shift_Exit", "KEY_SEXIT", KEY_SEXIT, mode);
696 keydef("Key_Shift_Find", "KEY_SFIND", KEY_SFIND, mode);
699 keydef("Key_Shift_Help", "KEY_SHELP", KEY_SHELP, mode);
702 keydef("Key_Shift_Home", "KEY_SHOME", KEY_SHOME, mode);
705 keydef("Key_Shift_Insert_Char", "KEY_SIC", KEY_SIC, mode);
708 keydef("Key_Shift_Cursor_Left", "KEY_SLEFT", KEY_SLEFT, mode);
711 keydef("Key_Shift_Message", "KEY_SMESSAGE", KEY_SMESSAGE, mode);
714 keydef("Key_Shift_Move", "KEY_SMOVE", KEY_SMOVE, mode);
717 keydef("Key_Shift_Next_Page", "KEY_SNEXT", KEY_SNEXT, mode);
720 keydef("Key_Shift_Options", "KEY_SOPTIONS", KEY_SOPTIONS, mode);
723 keydef("Key_Shift_Previous_Page", "KEY_SPREVIOUS", KEY_SPREVIOUS, mode);
726 keydef("Key_Shift_Print", "KEY_SPRINT", KEY_SPRINT, mode);
729 keydef("Key_Shift_Redo", "KEY_SREDO", KEY_SREDO, mode);
732 keydef("Key_Shift_Replace", "KEY_SREPLACE", KEY_SREPLACE, mode);
735 keydef("Key_Shift_Cursor_Right", "KEY_SRIGHT", KEY_SRIGHT, mode);
738 keydef("Key_Shift_Resume", "KEY_SRSUME", KEY_SRSUME, mode);
741 keydef("Key_Shift_Save", "KEY_SSAVE", KEY_SSAVE, mode);
744 keydef("Key_Shift_Suspend", "KEY_SSUSPEND", KEY_SSUSPEND, mode);
747 keydef("Key_Shift_Undo", "KEY_SUNDO", KEY_SUNDO, mode);
750 keydef("Key_Suspend", "KEY_SUSPEND", KEY_SUSPEND, mode);
753 keydef("Key_Undo", "KEY_UNDO", KEY_UNDO, mode);
756 keydef("Key_Mouse", "KEY_MOUSE", KEY_MOUSE, mode);
759 keydef("Key_Resize", "KEY_RESIZE", KEY_RESIZE, mode);
764 * Generate a constant with the given name. The second parameter
765 * is a reference to the ACS character in the acs_map[] array and
766 * will be translated into an index.
769 acs_def(const char *name, chtype *a)
771 int c = a - &acs_map[0];
773 printf(" %-24s : constant Character := ", name);
774 if (isprint(c) && (c != '`'))
775 printf("'%c';\n", c);
777 printf("Character'Val (%d);\n", c);
781 * Generate the constants for the ACS characters
786 printf(" type C_ACS_Map is array (Character'Val (0) .. Character'Val (127))\n");
787 printf(" of Attributed_Character;\n");
788 #if USE_REENTRANT || BROKEN_LINKER
789 printf(" type C_ACS_Ptr is access C_ACS_Map;\n");
790 printf(" function ACS_Map return C_ACS_Ptr;\n");
791 printf(" pragma Import (C, ACS_Map, \""
795 printf(" ACS_Map : C_ACS_Map;\n");
796 printf(" pragma Import (C, ACS_Map, \"acs_map\");\n");
800 printf(" -- Constants for several characters from the Alternate Character Set\n");
801 printf(" -- You must use these constants as indices into the ACS_Map array\n");
802 printf(" -- to get the corresponding attributed character at runtime.\n");
806 acs_def("ACS_Upper_Left_Corner", &ACS_ULCORNER);
809 acs_def("ACS_Lower_Left_Corner", &ACS_LLCORNER);
812 acs_def("ACS_Upper_Right_Corner", &ACS_URCORNER);
815 acs_def("ACS_Lower_Right_Corner", &ACS_LRCORNER);
818 acs_def("ACS_Left_Tee", &ACS_LTEE);
821 acs_def("ACS_Right_Tee", &ACS_RTEE);
824 acs_def("ACS_Bottom_Tee", &ACS_BTEE);
827 acs_def("ACS_Top_Tee", &ACS_TTEE);
830 acs_def("ACS_Horizontal_Line", &ACS_HLINE);
833 acs_def("ACS_Vertical_Line", &ACS_VLINE);
836 acs_def("ACS_Plus_Symbol", &ACS_PLUS);
839 acs_def("ACS_Scan_Line_1", &ACS_S1);
842 acs_def("ACS_Scan_Line_9", &ACS_S9);
845 acs_def("ACS_Diamond", &ACS_DIAMOND);
848 acs_def("ACS_Checker_Board", &ACS_CKBOARD);
851 acs_def("ACS_Degree", &ACS_DEGREE);
854 acs_def("ACS_Plus_Minus", &ACS_PLMINUS);
857 acs_def("ACS_Bullet", &ACS_BULLET);
860 acs_def("ACS_Left_Arrow", &ACS_LARROW);
863 acs_def("ACS_Right_Arrow", &ACS_RARROW);
866 acs_def("ACS_Down_Arrow", &ACS_DARROW);
869 acs_def("ACS_Up_Arrow", &ACS_UARROW);
872 acs_def("ACS_Board_Of_Squares", &ACS_BOARD);
875 acs_def("ACS_Lantern", &ACS_LANTERN);
878 acs_def("ACS_Solid_Block", &ACS_BLOCK);
881 acs_def("ACS_Scan_Line_3", &ACS_S3);
884 acs_def("ACS_Scan_Line_7", &ACS_S7);
887 acs_def("ACS_Less_Or_Equal", &ACS_LEQUAL);
890 acs_def("ACS_Greater_Or_Equal", &ACS_GEQUAL);
893 acs_def("ACS_PI", &ACS_PI);
896 acs_def("ACS_Not_Equal", &ACS_NEQUAL);
899 acs_def("ACS_Sterling", &ACS_STERLING);
903 #define GEN_EVENT(name,value) \
904 printf(" %-25s : constant Event_Mask := 8#%011lo#;\n", \
907 #define GEN_MEVENT(name) \
908 printf(" %-25s : constant Event_Mask := 8#%011lo#;\n", \
912 gen_mouse_events(void)
919 #ifdef BUTTON1_RELEASED
920 GEN_MEVENT(BUTTON1_RELEASED);
921 all1 |= BUTTON1_RELEASED;
923 #ifdef BUTTON1_PRESSED
924 GEN_MEVENT(BUTTON1_PRESSED);
925 all1 |= BUTTON1_PRESSED;
927 #ifdef BUTTON1_CLICKED
928 GEN_MEVENT(BUTTON1_CLICKED);
929 all1 |= BUTTON1_CLICKED;
931 #ifdef BUTTON1_DOUBLE_CLICKED
932 GEN_MEVENT(BUTTON1_DOUBLE_CLICKED);
933 all1 |= BUTTON1_DOUBLE_CLICKED;
935 #ifdef BUTTON1_TRIPLE_CLICKED
936 GEN_MEVENT(BUTTON1_TRIPLE_CLICKED);
937 all1 |= BUTTON1_TRIPLE_CLICKED;
939 #ifdef BUTTON1_RESERVED_EVENT
940 GEN_MEVENT(BUTTON1_RESERVED_EVENT);
941 all1 |= BUTTON1_RESERVED_EVENT;
943 #ifdef BUTTON2_RELEASED
944 GEN_MEVENT(BUTTON2_RELEASED);
945 all2 |= BUTTON2_RELEASED;
947 #ifdef BUTTON2_PRESSED
948 GEN_MEVENT(BUTTON2_PRESSED);
949 all2 |= BUTTON2_PRESSED;
951 #ifdef BUTTON2_CLICKED
952 GEN_MEVENT(BUTTON2_CLICKED);
953 all2 |= BUTTON2_CLICKED;
955 #ifdef BUTTON2_DOUBLE_CLICKED
956 GEN_MEVENT(BUTTON2_DOUBLE_CLICKED);
957 all2 |= BUTTON2_DOUBLE_CLICKED;
959 #ifdef BUTTON2_TRIPLE_CLICKED
960 GEN_MEVENT(BUTTON2_TRIPLE_CLICKED);
961 all2 |= BUTTON2_TRIPLE_CLICKED;
963 #ifdef BUTTON2_RESERVED_EVENT
964 GEN_MEVENT(BUTTON2_RESERVED_EVENT);
965 all2 |= BUTTON2_RESERVED_EVENT;
967 #ifdef BUTTON3_RELEASED
968 GEN_MEVENT(BUTTON3_RELEASED);
969 all3 |= BUTTON3_RELEASED;
971 #ifdef BUTTON3_PRESSED
972 GEN_MEVENT(BUTTON3_PRESSED);
973 all3 |= BUTTON3_PRESSED;
975 #ifdef BUTTON3_CLICKED
976 GEN_MEVENT(BUTTON3_CLICKED);
977 all3 |= BUTTON3_CLICKED;
979 #ifdef BUTTON3_DOUBLE_CLICKED
980 GEN_MEVENT(BUTTON3_DOUBLE_CLICKED);
981 all3 |= BUTTON3_DOUBLE_CLICKED;
983 #ifdef BUTTON3_TRIPLE_CLICKED
984 GEN_MEVENT(BUTTON3_TRIPLE_CLICKED);
985 all3 |= BUTTON3_TRIPLE_CLICKED;
987 #ifdef BUTTON3_RESERVED_EVENT
988 GEN_MEVENT(BUTTON3_RESERVED_EVENT);
989 all3 |= BUTTON3_RESERVED_EVENT;
991 #ifdef BUTTON4_RELEASED
992 GEN_MEVENT(BUTTON4_RELEASED);
993 all4 |= BUTTON4_RELEASED;
995 #ifdef BUTTON4_PRESSED
996 GEN_MEVENT(BUTTON4_PRESSED);
997 all4 |= BUTTON4_PRESSED;
999 #ifdef BUTTON4_CLICKED
1000 GEN_MEVENT(BUTTON4_CLICKED);
1001 all4 |= BUTTON4_CLICKED;
1003 #ifdef BUTTON4_DOUBLE_CLICKED
1004 GEN_MEVENT(BUTTON4_DOUBLE_CLICKED);
1005 all4 |= BUTTON4_DOUBLE_CLICKED;
1007 #ifdef BUTTON4_TRIPLE_CLICKED
1008 GEN_MEVENT(BUTTON4_TRIPLE_CLICKED);
1009 all4 |= BUTTON4_TRIPLE_CLICKED;
1011 #ifdef BUTTON4_RESERVED_EVENT
1012 GEN_MEVENT(BUTTON4_RESERVED_EVENT);
1013 all4 |= BUTTON4_RESERVED_EVENT;
1016 GEN_MEVENT(BUTTON_CTRL);
1019 GEN_MEVENT(BUTTON_SHIFT);
1022 GEN_MEVENT(BUTTON_ALT);
1024 #ifdef REPORT_MOUSE_POSITION
1025 GEN_MEVENT(REPORT_MOUSE_POSITION);
1027 #ifdef ALL_MOUSE_EVENTS
1028 GEN_MEVENT(ALL_MOUSE_EVENTS);
1031 GEN_EVENT(BUTTON1_EVENTS, all1);
1032 GEN_EVENT(BUTTON2_EVENTS, all2);
1033 GEN_EVENT(BUTTON3_EVENTS, all3);
1034 GEN_EVENT(BUTTON4_EVENTS, all4);
1038 wrap_one_var(const char *c_var,
1040 const char *ada_func,
1041 const char *ada_type)
1044 /* must wrap variables */
1046 printf(" function %s return %s\n", ada_func, ada_type);
1048 printf(" function Result return %s;\n", c_type);
1049 printf(" pragma Import (C, Result, \"" NCURSES_WRAP_PREFIX "%s\");\n", c_var);
1051 if (strcmp(c_type, ada_type))
1052 printf(" return %s (Result);\n", ada_type);
1054 printf(" return Result;\n");
1055 printf(" end %s;\n", ada_func);
1057 /* global variables are really global */
1059 printf(" function %s return %s\n", ada_func, ada_type);
1061 printf(" Result : %s;\n", c_type);
1062 printf(" pragma Import (C, Result, \"%s\");\n", c_var);
1064 if (strcmp(c_type, ada_type))
1065 printf(" return %s (Result);\n", ada_type);
1067 printf(" return Result;\n");
1068 printf(" end %s;\n", ada_func);
1072 #define GEN_PUBLIC_VAR(c_var, c_type, ada_func, ada_type) \
1073 wrap_one_var(#c_var, #c_type, #ada_func, #ada_type)
1076 gen_public_vars(void)
1078 GEN_PUBLIC_VAR(stdscr, Window, Standard_Window, Window);
1079 GEN_PUBLIC_VAR(curscr, Window, Current_Window, Window);
1080 GEN_PUBLIC_VAR(LINES, C_Int, Lines, Line_Count);
1081 GEN_PUBLIC_VAR(COLS, C_Int, Columns, Column_Count);
1082 GEN_PUBLIC_VAR(TABSIZE, C_Int, Tab_Size, Natural);
1083 GEN_PUBLIC_VAR(COLORS, C_Int, Number_Of_Colors, Natural);
1084 GEN_PUBLIC_VAR(COLOR_PAIRS, C_Int, Number_Of_Color_Pairs, Natural);
1088 * Output some comment lines indicating that the file is generated.
1089 * The name parameter is the name of the facility to be used in
1093 prologue(const char *name)
1095 printf("-- %s binding.\n", name);
1096 printf("-- This module is generated. Please don't change it manually!\n");
1097 printf("-- Run the generator instead.\n-- |");
1099 printf("define(`M4_BIT_ORDER',`%s_Order_First')",
1100 little_endian ? "Low" : "High");
1104 * Write the prologue for the curses facility and make sure that
1105 * KEY_MIN and KEY_MAX are defined for the rest of this source.
1112 # define KEY_MAX 0777
1114 printf("define(`M4_KEY_MAX',`8#%o#')", KEY_MAX);
1116 # define KEY_MIN 0401
1120 fprintf(stderr, "Unexpected value for KEY_MIN: %d\n", KEY_MIN);
1123 printf("define(`M4_SPECIAL_FIRST',`8#%o#')", KEY_MIN - 1);
1127 * Write out the comment lines for the menu facility
1136 * Write out the comment lines for the form facility
1145 * Write out the comment lines for the mouse facility
1148 mouse_basedefs(void)
1154 * Write the definition of a single color
1157 color_def(const char *name, int value)
1159 printf(" %-16s : constant Color_Number := %d;\n", name, value);
1163 * Generate all color definitions
1168 #if HAVE_USE_DEFAULT_COLORS
1169 color_def("Default_Color", -1);
1172 color_def("Black", COLOR_BLACK);
1175 color_def("Red", COLOR_RED);
1178 color_def("Green", COLOR_GREEN);
1181 color_def("Yellow", COLOR_YELLOW);
1184 color_def("Blue", COLOR_BLUE);
1186 #ifdef COLOR_MAGENTA
1187 color_def("Magenta", COLOR_MAGENTA);
1190 color_def("Cyan", COLOR_CYAN);
1193 color_def("White", COLOR_WHITE);
1198 * Generate the linker options for the base facility
1203 printf(" pragma Linker_Options (\"-lncurses%s\");\n", model);
1207 * Generate the linker options for the menu facility
1210 gen_menu_linkopts(void)
1212 printf(" pragma Linker_Options (\"-lmenu%s\");\n", model);
1216 * Generate the linker options for the form facility
1219 gen_form_linkopts(void)
1221 printf(" pragma Linker_Options (\"-lform%s\");\n", model);
1225 * Generate the linker options for the panel facility
1228 gen_panel_linkopts(void)
1230 printf(" pragma Linker_Options (\"-lpanel%s\");\n", model);
1234 gen_version_info(void)
1236 static const char *v1 =
1237 " NC_Major_Version : constant := %d; -- Major version of the library\n";
1238 static const char *v2 =
1239 " NC_Minor_Version : constant := %d; -- Minor version of the library\n";
1240 static const char *v3 =
1241 " NC_Version : constant String := %c%d.%d%c; -- Version of library\n";
1243 printf(v1, NCURSES_VERSION_MAJOR);
1244 printf(v2, NCURSES_VERSION_MINOR);
1245 printf(v3, '"', NCURSES_VERSION_MAJOR, NCURSES_VERSION_MINOR, '"');
1249 eti_gen(char *buf, int code, const char *name, int *etimin, int *etimax)
1251 sprintf(buf, " E_%-16s : constant Eti_Error := %d;\n", name, code);
1256 return (int)strlen(buf);
1262 const char *s_bool = "";
1264 if (sizeof(bool) == sizeof(char))
1268 else if (sizeof(bool) == sizeof(short))
1272 else if (sizeof(bool) == sizeof(int))
1276 printf(" Sizeof%-*s : constant Natural := %2ld; -- %s\n",
1277 12, "_bool", (long)sizeof(bool), "bool");
1279 /* In ncurses _maxy and _maxx needs an offset for the "public"
1282 printf(" Offset%-*s : constant Natural := %2d; -- %s\n",
1283 12, "_XY", 1, "int");
1285 printf(" type Curses_Bool is mod 2 ** Interfaces.C.%s'Size;\n", s_bool);
1289 * main() expects two arguments on the commandline, both single characters.
1290 * The first character denotes the facility for which we generate output.
1291 * Possible values are
1295 * P - Pointer Device (Mouse)
1296 * E - ETI base definitions
1298 * The second character then denotes the specific output that should be
1299 * generated for the selected facility.
1302 main(int argc, char *argv[])
1305 char *s = (char *)&x;
1316 /* --------------------------------------------------------------- */
1317 case 'B': /* The Base facility */
1320 case 'A': /* chtype translation into Ada95 record type */
1321 gen_attr_set("Character_Attribute_Set");
1323 case 'B': /* write some initial comment lines */
1326 case 'C': /* generate color constants */
1329 case 'D': /* generate displacements of fields in WINDOW struct. */
1332 case 'E': /* generate Mouse Event codes */
1335 case 'K': /* translation of keycodes */
1338 case 'L': /* generate the Linker_Options pragma */
1341 case 'M': /* generate constants for the ACS characters */
1344 case 'O': /* generate definitions of the old key code names */
1347 case 'P': /* generate definitions of the public variables */
1350 case 'R': /* generate representation clause for Attributed character */
1351 gen_chtype_rep("Attributed_Character");
1353 case 'T': /* generate the Trace info */
1354 gen_trace("Trace_Attribute_Set");
1356 case 'V': /* generate version info */
1363 /* --------------------------------------------------------------- */
1364 case 'M': /* The Menu facility */
1367 case 'R': /* generate representation clause for Menu_Option_Set */
1368 gen_menu_opt_rep("Menu_Option_Set");
1370 case 'B': /* write some initial comment lines */
1373 case 'L': /* generate the Linker_Options pragma */
1374 gen_menu_linkopts();
1376 case 'I': /* generate representation clause for Item_Option_Set */
1377 gen_item_opt_rep("Item_Option_Set");
1383 /* --------------------------------------------------------------- */
1384 case 'F': /* The Form facility */
1387 case 'R': /* generate representation clause for Form_Option_Set */
1388 gen_form_opt_rep("Form_Option_Set");
1390 case 'B': /* write some initial comment lines */
1393 case 'L': /* generate the Linker_Options pragma */
1394 gen_form_linkopts();
1396 case 'I': /* generate representation clause for Field_Option_Set */
1397 gen_field_opt_rep("Field_Option_Set");
1403 /* --------------------------------------------------------------- */
1404 case 'P': /* The Pointer(=Mouse) facility */
1407 case 'B': /* write some initial comment lines */
1410 case 'M': /* generate representation clause for Mouse_Event */
1411 gen_mrep_rep("Mouse_Event");
1413 case 'L': /* generate the Linker_Options pragma */
1414 gen_panel_linkopts();
1420 /* --------------------------------------------------------------- */
1421 case 'E': /* chtype size detection */
1426 const char *fmt = " type C_Chtype is new %s;\n";
1427 const char *afmt = " type C_AttrType is new %s;\n";
1429 if (sizeof(chtype) == sizeof(int))
1431 if (sizeof(int) == sizeof(long))
1432 printf(fmt, "C_ULong");
1435 printf(fmt, "C_UInt");
1437 else if (sizeof(chtype) == sizeof(long))
1439 printf(fmt, "C_ULong");
1444 if (sizeof(attr_t) == sizeof(int))
1446 if (sizeof(int) == sizeof(long))
1447 printf(afmt, "C_ULong");
1450 printf(afmt, "C_UInt");
1452 else if (sizeof(attr_t) == sizeof(long))
1454 printf(afmt, "C_ULong");
1459 printf("define(`CF_CURSES_OK',`%d')", OK);
1460 printf("define(`CF_CURSES_ERR',`%d')", ERR);
1461 printf("define(`CF_CURSES_TRUE',`%d')", TRUE);
1462 printf("define(`CF_CURSES_FALSE',`%d')", FALSE);
1467 char *buf = (char *)malloc(2048);
1474 p += eti_gen(p, E_OK, "Ok", &etimin, &etimax);
1475 p += eti_gen(p, E_SYSTEM_ERROR, "System_Error", &etimin, &etimax);
1476 p += eti_gen(p, E_BAD_ARGUMENT, "Bad_Argument", &etimin, &etimax);
1477 p += eti_gen(p, E_POSTED, "Posted", &etimin, &etimax);
1478 p += eti_gen(p, E_CONNECTED, "Connected", &etimin, &etimax);
1479 p += eti_gen(p, E_BAD_STATE, "Bad_State", &etimin, &etimax);
1480 p += eti_gen(p, E_NO_ROOM, "No_Room", &etimin, &etimax);
1481 p += eti_gen(p, E_NOT_POSTED, "Not_Posted", &etimin, &etimax);
1482 p += eti_gen(p, E_UNKNOWN_COMMAND,
1483 "Unknown_Command", &etimin, &etimax);
1484 p += eti_gen(p, E_NO_MATCH, "No_Match", &etimin, &etimax);
1485 p += eti_gen(p, E_NOT_SELECTABLE,
1486 "Not_Selectable", &etimin, &etimax);
1487 p += eti_gen(p, E_NOT_CONNECTED,
1488 "Not_Connected", &etimin, &etimax);
1489 p += eti_gen(p, E_REQUEST_DENIED,
1490 "Request_Denied", &etimin, &etimax);
1491 p += eti_gen(p, E_INVALID_FIELD,
1492 "Invalid_Field", &etimin, &etimax);
1493 p += eti_gen(p, E_CURRENT,
1494 "Current", &etimin, &etimax);
1496 printf(" subtype Eti_Error is C_Int range %d .. %d;\n\n",
1505 /* --------------------------------------------------------------- */
1506 case 'V': /* plain version dump */
1510 case '1': /* major version */
1511 #ifdef NCURSES_VERSION_MAJOR
1512 printf("%d", NCURSES_VERSION_MAJOR);
1515 case '2': /* minor version */
1516 #ifdef NCURSES_VERSION_MINOR
1517 printf("%d", NCURSES_VERSION_MINOR);
1520 case '3': /* patch level */
1521 #ifdef NCURSES_VERSION_PATCH
1522 printf("%d", NCURSES_VERSION_PATCH);
1530 /* --------------------------------------------------------------- */