1 /****************************************************************************
2 * Copyright (c) 1998,2010,2011 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.57 2011/03/19 19:09:38 Nicolas.Boulenguez 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 const char *unused_name = "Unused";
128 int long_bits = (8 * (int)sizeof(unsigned long));
129 int len_bits = (8 * len);
130 int i, j, n, l, cnt = 0, low, high;
131 int width = strlen(RES_NAME) + 3;
133 unsigned long mask = 0;
137 for (i = 0; nap[i].name != (char *)0; i++)
140 l = (int)strlen(nap[i].name);
146 printf(" type %s is\n", name);
148 for (i = 0; nap[i].name != (char *)0; i++)
151 printf(" %-*s : Boolean;\n", width, nap[i].name);
155 * Compute a mask for the unused bits in this target.
159 * Bits in the biased area are unused by the target.
161 for (j = 0; j < bias; ++j)
163 mask &= (unsigned long)(~(1L << j));
166 * Bits past the target's size are really unused.
168 for (j = len_bits + bias; j < long_bits; ++j)
170 mask &= (unsigned long)(~(1L << j));
174 printf(" %-*s : Boolean;\n", width, unused_name);
176 printf(" end record;\n");
177 printf(" pragma Convention (C, %s);\n\n", name);
179 printf(" for %s use\n", name);
182 for (i = 0; nap[i].name != (char *)0; i++)
185 l = find_pos((char *)&a, sizeof(a), &low, &high);
187 printf(" %-*s at 0 range %2d .. %2d;\n", width, nap[i].name,
188 low - bias, high - bias);
192 l = find_pos((char *)&mask, sizeof(mask), &low, &high);
194 printf(" %-*s at 0 range %2d .. %2d;\n", width, unused_name,
195 low - bias, high - bias);
199 printf(" end record;\n");
200 printf(" for %s'Size use %d;\n", name, len_bits);
201 printf(" -- Please note: this rep. clause is generated and may be\n");
202 printf(" -- different on your system.");
206 chtype_rep(const char *name, attr_t mask)
208 attr_t x = (attr_t)-1;
211 int l = find_pos((char *)&t, sizeof(t), &low, &high);
214 printf(" %-5s at 0 range %2d .. %2d;\n", name, low, high);
218 gen_chtype_rep(const char *name)
220 printf(" for %s use\n record\n", name);
221 chtype_rep("Ch", A_CHARTEXT);
222 chtype_rep("Color", A_COLOR);
223 chtype_rep("Attr", (A_ATTRIBUTES & ~A_COLOR));
224 printf(" end record;\n for %s'Size use %ld;\n",
225 name, (long)(8 * sizeof(chtype)));
227 printf(" -- Please note: this rep. clause is generated and may be\n");
228 printf(" -- different on your system.\n");
232 mrep_rep(const char *name, void *rec)
235 int l = find_pos((char *)rec, sizeof(MEVENT), &low, &high);
238 printf(" %-7s at 0 range %3d .. %3d;\n", name, low, high);
242 gen_mrep_rep(const char *name)
246 printf(" for %s use\n record\n", name);
248 memset(&x, 0, sizeof(x));
252 memset(&x, 0, sizeof(x));
256 memset(&x, 0, sizeof(x));
260 memset(&x, 0, sizeof(x));
264 memset(&x, 0, sizeof(x));
265 x.bstate = (mmask_t) - 1;
266 mrep_rep("Bstate", &x);
268 printf(" end record;\n");
269 printf(" -- Please note: this rep. clause is generated and may be\n");
270 printf(" -- different on your system.\n");
274 gen_attr_set(const char *name)
276 /* All of the A_xxx symbols are defined in ncurses, but not all are nonzero
277 * if "configure --enable-widec" is specified.
279 static const name_attribute_pair nap[] =
282 {"Stand_Out", A_STANDOUT},
285 {"Under_Line", A_UNDERLINE},
288 {"Reverse_Video", A_REVERSE},
294 {"Dim_Character", A_DIM},
297 {"Bold_Character", A_BOLD},
300 {"Alternate_Character_Set", A_ALTCHARSET},
303 {"Invisible_Character", A_INVIS},
306 {"Protected_Character", A_PROTECT},
309 {"Horizontal", A_HORIZONTAL},
324 {"Vertical", A_VERTICAL},
328 chtype attr = A_ATTRIBUTES & ~A_COLOR;
333 for (i = 0; i < (int)(8 * sizeof(chtype)); i++)
348 gen_reps(nap, name, (len + 7) / 8, little_endian ? start : 0);
352 gen_trace(const char *name)
354 static const name_attribute_pair nap[] =
356 {"Times", TRACE_TIMES},
357 {"Tputs", TRACE_TPUTS},
358 {"Update", TRACE_UPDATE},
359 {"Cursor_Move", TRACE_MOVE},
360 {"Character_Output", TRACE_CHARPUT},
361 {"Calls", TRACE_CALLS},
362 {"Virtual_Puts", TRACE_VIRTPUT},
363 {"Input_Events", TRACE_IEVENT},
364 {"TTY_State", TRACE_BITS},
365 {"Internal_Calls", TRACE_ICALLS},
366 {"Character_Calls", TRACE_CCALLS},
367 {"Termcap_TermInfo", TRACE_DATABASE},
368 {"Attributes_And_Colors", TRACE_ATTRS},
371 gen_reps(nap, name, sizeof(int), 0);
375 gen_menu_opt_rep(const char *name)
377 static const name_attribute_pair nap[] =
380 {"One_Valued", O_ONEVALUE},
383 {"Show_Descriptions", O_SHOWDESC},
386 {"Row_Major_Order", O_ROWMAJOR},
389 {"Ignore_Case", O_IGNORECASE},
392 {"Show_Matches", O_SHOWMATCH},
395 {"Non_Cyclic", O_NONCYCLIC},
399 gen_reps(nap, name, sizeof(int), 0);
403 gen_item_opt_rep(const char *name)
405 static const name_attribute_pair nap[] =
408 {"Selectable", O_SELECTABLE},
412 gen_reps(nap, name, sizeof(int), 0);
416 gen_form_opt_rep(const char *name)
418 static const name_attribute_pair nap[] =
421 {"NL_Overload", O_NL_OVERLOAD},
424 {"BS_Overload", O_BS_OVERLOAD},
428 gen_reps(nap, name, sizeof(int), 0);
432 * Generate the representation clause for the Field_Option_Set record
435 gen_field_opt_rep(const char *name)
437 static const name_attribute_pair nap[] =
440 {"Visible", O_VISIBLE},
443 {"Active", O_ACTIVE},
446 {"Public", O_PUBLIC},
458 {"Auto_Skip", O_AUTOSKIP},
461 {"Null_Ok", O_NULLOK},
464 {"Pass_Ok", O_PASSOK},
467 {"Static", O_STATIC},
471 gen_reps(nap, name, sizeof(int), 0);
475 * Generate a single key code constant definition.
478 keydef(const char *name, const char *old_name, int value, int mode)
480 if (mode == 0) /* Generate the new name */
481 printf(" %-30s : constant Special_Key_Code := 8#%3o#;\n", name, value);
484 const char *s = old_name;
485 const char *t = name;
487 /* generate the old name, but only if it doesn't conflict with the old
488 * name (Ada95 isn't case sensitive!)
490 while (*s && *t && (toupper(UChar(*s++)) == toupper(UChar(*t++))));
492 printf(" %-16s : Special_Key_Code renames %s;\n", old_name, name);
497 * Generate constants for the key codes. When called with mode==0, a
498 * complete list with nice constant names in proper casing style will
499 * be generated. Otherwise a list of old (i.e. C-style) names will be
500 * generated, given that the name wasn't already defined in the "nice"
504 gen_keydefs(int mode)
511 keydef("Key_Code_Yes", "KEY_CODE_YES", KEY_CODE_YES, mode);
514 keydef("Key_Min", "KEY_MIN", KEY_MIN, mode);
517 keydef("Key_Break", "KEY_BREAK", KEY_BREAK, mode);
520 keydef("Key_Cursor_Down", "KEY_DOWN", KEY_DOWN, mode);
523 keydef("Key_Cursor_Up", "KEY_UP", KEY_UP, mode);
526 keydef("Key_Cursor_Left", "KEY_LEFT", KEY_LEFT, mode);
529 keydef("Key_Cursor_Right", "KEY_RIGHT", KEY_RIGHT, mode);
532 keydef("Key_Home", "KEY_HOME", KEY_HOME, mode);
535 keydef("Key_Backspace", "KEY_BACKSPACE", KEY_BACKSPACE, mode);
538 keydef("Key_F0", "KEY_F0", KEY_F0, mode);
541 for (i = 1; i <= 24; i++)
543 sprintf(buf, "Key_F%d", i);
544 sprintf(obuf, "KEY_F%d", i);
545 keydef(buf, obuf, KEY_F(i), mode);
549 keydef("Key_Delete_Line", "KEY_DL", KEY_DL, mode);
552 keydef("Key_Insert_Line", "KEY_IL", KEY_IL, mode);
555 keydef("Key_Delete_Char", "KEY_DC", KEY_DC, mode);
558 keydef("Key_Insert_Char", "KEY_IC", KEY_IC, mode);
561 keydef("Key_Exit_Insert_Mode", "KEY_EIC", KEY_EIC, mode);
564 keydef("Key_Clear_Screen", "KEY_CLEAR", KEY_CLEAR, mode);
567 keydef("Key_Clear_End_Of_Screen", "KEY_EOS", KEY_EOS, mode);
570 keydef("Key_Clear_End_Of_Line", "KEY_EOL", KEY_EOL, mode);
573 keydef("Key_Scroll_1_Forward", "KEY_SF", KEY_SF, mode);
576 keydef("Key_Scroll_1_Backward", "KEY_SR", KEY_SR, mode);
579 keydef("Key_Next_Page", "KEY_NPAGE", KEY_NPAGE, mode);
582 keydef("Key_Previous_Page", "KEY_PPAGE", KEY_PPAGE, mode);
585 keydef("Key_Set_Tab", "KEY_STAB", KEY_STAB, mode);
588 keydef("Key_Clear_Tab", "KEY_CTAB", KEY_CTAB, mode);
591 keydef("Key_Clear_All_Tabs", "KEY_CATAB", KEY_CATAB, mode);
594 keydef("Key_Enter_Or_Send", "KEY_ENTER", KEY_ENTER, mode);
597 keydef("Key_Soft_Reset", "KEY_SRESET", KEY_SRESET, mode);
600 keydef("Key_Reset", "KEY_RESET", KEY_RESET, mode);
603 keydef("Key_Print", "KEY_PRINT", KEY_PRINT, mode);
606 keydef("Key_Bottom", "KEY_LL", KEY_LL, mode);
609 keydef("Key_Upper_Left_Of_Keypad", "KEY_A1", KEY_A1, mode);
612 keydef("Key_Upper_Right_Of_Keypad", "KEY_A3", KEY_A3, mode);
615 keydef("Key_Center_Of_Keypad", "KEY_B2", KEY_B2, mode);
618 keydef("Key_Lower_Left_Of_Keypad", "KEY_C1", KEY_C1, mode);
621 keydef("Key_Lower_Right_Of_Keypad", "KEY_C3", KEY_C3, mode);
624 keydef("Key_Back_Tab", "KEY_BTAB", KEY_BTAB, mode);
627 keydef("Key_Beginning", "KEY_BEG", KEY_BEG, mode);
630 keydef("Key_Cancel", "KEY_CANCEL", KEY_CANCEL, mode);
633 keydef("Key_Close", "KEY_CLOSE", KEY_CLOSE, mode);
636 keydef("Key_Command", "KEY_COMMAND", KEY_COMMAND, mode);
639 keydef("Key_Copy", "KEY_COPY", KEY_COPY, mode);
642 keydef("Key_Create", "KEY_CREATE", KEY_CREATE, mode);
645 keydef("Key_End", "KEY_END", KEY_END, mode);
648 keydef("Key_Exit", "KEY_EXIT", KEY_EXIT, mode);
651 keydef("Key_Find", "KEY_FIND", KEY_FIND, mode);
654 keydef("Key_Help", "KEY_HELP", KEY_HELP, mode);
657 keydef("Key_Mark", "KEY_MARK", KEY_MARK, mode);
660 keydef("Key_Message", "KEY_MESSAGE", KEY_MESSAGE, mode);
663 keydef("Key_Move", "KEY_MOVE", KEY_MOVE, mode);
666 keydef("Key_Next", "KEY_NEXT", KEY_NEXT, mode);
669 keydef("Key_Open", "KEY_OPEN", KEY_OPEN, mode);
672 keydef("Key_Options", "KEY_OPTIONS", KEY_OPTIONS, mode);
675 keydef("Key_Previous", "KEY_PREVIOUS", KEY_PREVIOUS, mode);
678 keydef("Key_Redo", "KEY_REDO", KEY_REDO, mode);
681 keydef("Key_Reference", "KEY_REFERENCE", KEY_REFERENCE, mode);
684 keydef("Key_Refresh", "KEY_REFRESH", KEY_REFRESH, mode);
687 keydef("Key_Replace", "KEY_REPLACE", KEY_REPLACE, mode);
690 keydef("Key_Restart", "KEY_RESTART", KEY_RESTART, mode);
693 keydef("Key_Resume", "KEY_RESUME", KEY_RESUME, mode);
696 keydef("Key_Save", "KEY_SAVE", KEY_SAVE, mode);
699 keydef("Key_Shift_Begin", "KEY_SBEG", KEY_SBEG, mode);
702 keydef("Key_Shift_Cancel", "KEY_SCANCEL", KEY_SCANCEL, mode);
705 keydef("Key_Shift_Command", "KEY_SCOMMAND", KEY_SCOMMAND, mode);
708 keydef("Key_Shift_Copy", "KEY_SCOPY", KEY_SCOPY, mode);
711 keydef("Key_Shift_Create", "KEY_SCREATE", KEY_SCREATE, mode);
714 keydef("Key_Shift_Delete_Char", "KEY_SDC", KEY_SDC, mode);
717 keydef("Key_Shift_Delete_Line", "KEY_SDL", KEY_SDL, mode);
720 keydef("Key_Select", "KEY_SELECT", KEY_SELECT, mode);
723 keydef("Key_Shift_End", "KEY_SEND", KEY_SEND, mode);
726 keydef("Key_Shift_Clear_End_Of_Line", "KEY_SEOL", KEY_SEOL, mode);
729 keydef("Key_Shift_Exit", "KEY_SEXIT", KEY_SEXIT, mode);
732 keydef("Key_Shift_Find", "KEY_SFIND", KEY_SFIND, mode);
735 keydef("Key_Shift_Help", "KEY_SHELP", KEY_SHELP, mode);
738 keydef("Key_Shift_Home", "KEY_SHOME", KEY_SHOME, mode);
741 keydef("Key_Shift_Insert_Char", "KEY_SIC", KEY_SIC, mode);
744 keydef("Key_Shift_Cursor_Left", "KEY_SLEFT", KEY_SLEFT, mode);
747 keydef("Key_Shift_Message", "KEY_SMESSAGE", KEY_SMESSAGE, mode);
750 keydef("Key_Shift_Move", "KEY_SMOVE", KEY_SMOVE, mode);
753 keydef("Key_Shift_Next_Page", "KEY_SNEXT", KEY_SNEXT, mode);
756 keydef("Key_Shift_Options", "KEY_SOPTIONS", KEY_SOPTIONS, mode);
759 keydef("Key_Shift_Previous_Page", "KEY_SPREVIOUS", KEY_SPREVIOUS, mode);
762 keydef("Key_Shift_Print", "KEY_SPRINT", KEY_SPRINT, mode);
765 keydef("Key_Shift_Redo", "KEY_SREDO", KEY_SREDO, mode);
768 keydef("Key_Shift_Replace", "KEY_SREPLACE", KEY_SREPLACE, mode);
771 keydef("Key_Shift_Cursor_Right", "KEY_SRIGHT", KEY_SRIGHT, mode);
774 keydef("Key_Shift_Resume", "KEY_SRSUME", KEY_SRSUME, mode);
777 keydef("Key_Shift_Save", "KEY_SSAVE", KEY_SSAVE, mode);
780 keydef("Key_Shift_Suspend", "KEY_SSUSPEND", KEY_SSUSPEND, mode);
783 keydef("Key_Shift_Undo", "KEY_SUNDO", KEY_SUNDO, mode);
786 keydef("Key_Suspend", "KEY_SUSPEND", KEY_SUSPEND, mode);
789 keydef("Key_Undo", "KEY_UNDO", KEY_UNDO, mode);
792 keydef("Key_Mouse", "KEY_MOUSE", KEY_MOUSE, mode);
795 keydef("Key_Resize", "KEY_RESIZE", KEY_RESIZE, mode);
800 * Generate a constant with the given name. The second parameter
801 * is a reference to the ACS character in the acs_map[] array and
802 * will be translated into an index.
805 acs_def(const char *name, chtype *a)
807 int c = a - &acs_map[0];
809 printf(" %-24s : constant Character := ", name);
810 if (isprint(UChar(c)) && (c != '`'))
811 printf("'%c';\n", c);
813 printf("Character'Val (%d);\n", c);
817 * Generate the constants for the ACS characters
822 printf(" type C_ACS_Map is array (Character'Val (0) .. Character'Val (127))\n");
823 printf(" of Attributed_Character;\n");
824 #if USE_REENTRANT || BROKEN_LINKER
825 printf(" type C_ACS_Ptr is access C_ACS_Map;\n");
826 printf(" function ACS_Map return C_ACS_Ptr;\n");
827 printf(" pragma Import (C, ACS_Map, \""
831 printf(" ACS_Map : C_ACS_Map;\n");
832 printf(" pragma Import (C, ACS_Map, \"acs_map\");\n");
836 printf(" -- Constants for several characters from the Alternate Character Set\n");
837 printf(" -- You must use these constants as indices into the ACS_Map array\n");
838 printf(" -- to get the corresponding attributed character at runtime.\n");
842 acs_def("ACS_Upper_Left_Corner", &ACS_ULCORNER);
845 acs_def("ACS_Lower_Left_Corner", &ACS_LLCORNER);
848 acs_def("ACS_Upper_Right_Corner", &ACS_URCORNER);
851 acs_def("ACS_Lower_Right_Corner", &ACS_LRCORNER);
854 acs_def("ACS_Left_Tee", &ACS_LTEE);
857 acs_def("ACS_Right_Tee", &ACS_RTEE);
860 acs_def("ACS_Bottom_Tee", &ACS_BTEE);
863 acs_def("ACS_Top_Tee", &ACS_TTEE);
866 acs_def("ACS_Horizontal_Line", &ACS_HLINE);
869 acs_def("ACS_Vertical_Line", &ACS_VLINE);
872 acs_def("ACS_Plus_Symbol", &ACS_PLUS);
875 acs_def("ACS_Scan_Line_1", &ACS_S1);
878 acs_def("ACS_Scan_Line_9", &ACS_S9);
881 acs_def("ACS_Diamond", &ACS_DIAMOND);
884 acs_def("ACS_Checker_Board", &ACS_CKBOARD);
887 acs_def("ACS_Degree", &ACS_DEGREE);
890 acs_def("ACS_Plus_Minus", &ACS_PLMINUS);
893 acs_def("ACS_Bullet", &ACS_BULLET);
896 acs_def("ACS_Left_Arrow", &ACS_LARROW);
899 acs_def("ACS_Right_Arrow", &ACS_RARROW);
902 acs_def("ACS_Down_Arrow", &ACS_DARROW);
905 acs_def("ACS_Up_Arrow", &ACS_UARROW);
908 acs_def("ACS_Board_Of_Squares", &ACS_BOARD);
911 acs_def("ACS_Lantern", &ACS_LANTERN);
914 acs_def("ACS_Solid_Block", &ACS_BLOCK);
917 acs_def("ACS_Scan_Line_3", &ACS_S3);
920 acs_def("ACS_Scan_Line_7", &ACS_S7);
923 acs_def("ACS_Less_Or_Equal", &ACS_LEQUAL);
926 acs_def("ACS_Greater_Or_Equal", &ACS_GEQUAL);
929 acs_def("ACS_PI", &ACS_PI);
932 acs_def("ACS_Not_Equal", &ACS_NEQUAL);
935 acs_def("ACS_Sterling", &ACS_STERLING);
939 #define GEN_EVENT(name,value) \
940 printf(" %-25s : constant Event_Mask := 8#%011lo#;\n", \
943 #define GEN_MEVENT(name) \
944 printf(" %-25s : constant Event_Mask := 8#%011lo#;\n", \
948 gen_mouse_events(void)
955 #ifdef BUTTON1_RELEASED
956 GEN_MEVENT(BUTTON1_RELEASED);
957 all1 |= BUTTON1_RELEASED;
959 #ifdef BUTTON1_PRESSED
960 GEN_MEVENT(BUTTON1_PRESSED);
961 all1 |= BUTTON1_PRESSED;
963 #ifdef BUTTON1_CLICKED
964 GEN_MEVENT(BUTTON1_CLICKED);
965 all1 |= BUTTON1_CLICKED;
967 #ifdef BUTTON1_DOUBLE_CLICKED
968 GEN_MEVENT(BUTTON1_DOUBLE_CLICKED);
969 all1 |= BUTTON1_DOUBLE_CLICKED;
971 #ifdef BUTTON1_TRIPLE_CLICKED
972 GEN_MEVENT(BUTTON1_TRIPLE_CLICKED);
973 all1 |= BUTTON1_TRIPLE_CLICKED;
975 #ifdef BUTTON1_RESERVED_EVENT
976 GEN_MEVENT(BUTTON1_RESERVED_EVENT);
977 all1 |= BUTTON1_RESERVED_EVENT;
979 #ifdef BUTTON2_RELEASED
980 GEN_MEVENT(BUTTON2_RELEASED);
981 all2 |= BUTTON2_RELEASED;
983 #ifdef BUTTON2_PRESSED
984 GEN_MEVENT(BUTTON2_PRESSED);
985 all2 |= BUTTON2_PRESSED;
987 #ifdef BUTTON2_CLICKED
988 GEN_MEVENT(BUTTON2_CLICKED);
989 all2 |= BUTTON2_CLICKED;
991 #ifdef BUTTON2_DOUBLE_CLICKED
992 GEN_MEVENT(BUTTON2_DOUBLE_CLICKED);
993 all2 |= BUTTON2_DOUBLE_CLICKED;
995 #ifdef BUTTON2_TRIPLE_CLICKED
996 GEN_MEVENT(BUTTON2_TRIPLE_CLICKED);
997 all2 |= BUTTON2_TRIPLE_CLICKED;
999 #ifdef BUTTON2_RESERVED_EVENT
1000 GEN_MEVENT(BUTTON2_RESERVED_EVENT);
1001 all2 |= BUTTON2_RESERVED_EVENT;
1003 #ifdef BUTTON3_RELEASED
1004 GEN_MEVENT(BUTTON3_RELEASED);
1005 all3 |= BUTTON3_RELEASED;
1007 #ifdef BUTTON3_PRESSED
1008 GEN_MEVENT(BUTTON3_PRESSED);
1009 all3 |= BUTTON3_PRESSED;
1011 #ifdef BUTTON3_CLICKED
1012 GEN_MEVENT(BUTTON3_CLICKED);
1013 all3 |= BUTTON3_CLICKED;
1015 #ifdef BUTTON3_DOUBLE_CLICKED
1016 GEN_MEVENT(BUTTON3_DOUBLE_CLICKED);
1017 all3 |= BUTTON3_DOUBLE_CLICKED;
1019 #ifdef BUTTON3_TRIPLE_CLICKED
1020 GEN_MEVENT(BUTTON3_TRIPLE_CLICKED);
1021 all3 |= BUTTON3_TRIPLE_CLICKED;
1023 #ifdef BUTTON3_RESERVED_EVENT
1024 GEN_MEVENT(BUTTON3_RESERVED_EVENT);
1025 all3 |= BUTTON3_RESERVED_EVENT;
1027 #ifdef BUTTON4_RELEASED
1028 GEN_MEVENT(BUTTON4_RELEASED);
1029 all4 |= BUTTON4_RELEASED;
1031 #ifdef BUTTON4_PRESSED
1032 GEN_MEVENT(BUTTON4_PRESSED);
1033 all4 |= BUTTON4_PRESSED;
1035 #ifdef BUTTON4_CLICKED
1036 GEN_MEVENT(BUTTON4_CLICKED);
1037 all4 |= BUTTON4_CLICKED;
1039 #ifdef BUTTON4_DOUBLE_CLICKED
1040 GEN_MEVENT(BUTTON4_DOUBLE_CLICKED);
1041 all4 |= BUTTON4_DOUBLE_CLICKED;
1043 #ifdef BUTTON4_TRIPLE_CLICKED
1044 GEN_MEVENT(BUTTON4_TRIPLE_CLICKED);
1045 all4 |= BUTTON4_TRIPLE_CLICKED;
1047 #ifdef BUTTON4_RESERVED_EVENT
1048 GEN_MEVENT(BUTTON4_RESERVED_EVENT);
1049 all4 |= BUTTON4_RESERVED_EVENT;
1052 GEN_MEVENT(BUTTON_CTRL);
1055 GEN_MEVENT(BUTTON_SHIFT);
1058 GEN_MEVENT(BUTTON_ALT);
1060 #ifdef REPORT_MOUSE_POSITION
1061 GEN_MEVENT(REPORT_MOUSE_POSITION);
1063 #ifdef ALL_MOUSE_EVENTS
1064 GEN_MEVENT(ALL_MOUSE_EVENTS);
1067 GEN_EVENT(BUTTON1_EVENTS, all1);
1068 GEN_EVENT(BUTTON2_EVENTS, all2);
1069 GEN_EVENT(BUTTON3_EVENTS, all3);
1070 GEN_EVENT(BUTTON4_EVENTS, all4);
1074 wrap_one_var(const char *c_var,
1076 const char *ada_func,
1077 const char *ada_type)
1080 /* must wrap variables */
1082 printf(" function %s return %s\n", ada_func, ada_type);
1084 printf(" function Result return %s;\n", c_type);
1085 printf(" pragma Import (C, Result, \"" NCURSES_WRAP_PREFIX "%s\");\n", c_var);
1087 if (strcmp(c_type, ada_type))
1088 printf(" return %s (Result);\n", ada_type);
1090 printf(" return Result;\n");
1091 printf(" end %s;\n", ada_func);
1093 /* global variables are really global */
1095 printf(" function %s return %s\n", ada_func, ada_type);
1097 printf(" Result : %s;\n", c_type);
1098 printf(" pragma Import (C, Result, \"%s\");\n", c_var);
1100 if (strcmp(c_type, ada_type))
1101 printf(" return %s (Result);\n", ada_type);
1103 printf(" return Result;\n");
1104 printf(" end %s;\n", ada_func);
1108 #define GEN_PUBLIC_VAR(c_var, c_type, ada_func, ada_type) \
1109 wrap_one_var(#c_var, #c_type, #ada_func, #ada_type)
1112 gen_public_vars(void)
1114 GEN_PUBLIC_VAR(stdscr, Window, Standard_Window, Window);
1115 GEN_PUBLIC_VAR(curscr, Window, Current_Window, Window);
1116 GEN_PUBLIC_VAR(LINES, C_Int, Lines, Line_Count);
1117 GEN_PUBLIC_VAR(COLS, C_Int, Columns, Column_Count);
1118 GEN_PUBLIC_VAR(TABSIZE, C_Int, Tab_Size, Natural);
1119 GEN_PUBLIC_VAR(COLORS, C_Int, Number_Of_Colors, Natural);
1120 GEN_PUBLIC_VAR(COLOR_PAIRS, C_Int, Number_Of_Color_Pairs, Natural);
1124 * Output some comment lines indicating that the file is generated.
1125 * The name parameter is the name of the facility to be used in
1129 prologue(const char *name)
1131 printf("-- %s binding.\n", name);
1132 printf("-- This module is generated. Please don't change it manually!\n");
1133 printf("-- Run the generator instead.\n-- |");
1135 printf("define(`M4_BIT_ORDER',`%s_Order_First')",
1136 little_endian ? "Low" : "High");
1140 * Write the prologue for the curses facility and make sure that
1141 * KEY_MIN and KEY_MAX are defined for the rest of this source.
1148 # define KEY_MAX 0777
1150 printf("define(`M4_KEY_MAX',`8#%o#')", KEY_MAX);
1152 # define KEY_MIN 0401
1156 fprintf(stderr, "Unexpected value for KEY_MIN: %d\n", KEY_MIN);
1159 printf("define(`M4_SPECIAL_FIRST',`8#%o#')", KEY_MIN - 1);
1163 * Write out the comment lines for the menu facility
1172 * Write out the comment lines for the form facility
1181 * Write out the comment lines for the mouse facility
1184 mouse_basedefs(void)
1190 * Write the definition of a single color
1193 color_def(const char *name, int value)
1195 printf(" %-16s : constant Color_Number := %d;\n", name, value);
1199 * Generate all color definitions
1204 #if HAVE_USE_DEFAULT_COLORS
1205 color_def("Default_Color", -1);
1208 color_def("Black", COLOR_BLACK);
1211 color_def("Red", COLOR_RED);
1214 color_def("Green", COLOR_GREEN);
1217 color_def("Yellow", COLOR_YELLOW);
1220 color_def("Blue", COLOR_BLUE);
1222 #ifdef COLOR_MAGENTA
1223 color_def("Magenta", COLOR_MAGENTA);
1226 color_def("Cyan", COLOR_CYAN);
1229 color_def("White", COLOR_WHITE);
1234 * Generate the linker options for the base facility
1239 printf(" pragma Linker_Options (\"-lncurses%s\");\n", model);
1243 * Generate the linker options for the menu facility
1246 gen_menu_linkopts(void)
1248 printf(" pragma Linker_Options (\"-lmenu%s\");\n", model);
1252 * Generate the linker options for the form facility
1255 gen_form_linkopts(void)
1257 printf(" pragma Linker_Options (\"-lform%s\");\n", model);
1261 * Generate the linker options for the panel facility
1264 gen_panel_linkopts(void)
1266 printf(" pragma Linker_Options (\"-lpanel%s\");\n", model);
1270 gen_version_info(void)
1272 static const char *v1 =
1273 " NC_Major_Version : constant := %d; -- Major version of the library\n";
1274 static const char *v2 =
1275 " NC_Minor_Version : constant := %d; -- Minor version of the library\n";
1276 static const char *v3 =
1277 " NC_Version : constant String := %c%d.%d%c; -- Version of library\n";
1279 printf(v1, NCURSES_VERSION_MAJOR);
1280 printf(v2, NCURSES_VERSION_MINOR);
1281 printf(v3, '"', NCURSES_VERSION_MAJOR, NCURSES_VERSION_MINOR, '"');
1285 eti_gen(char *buf, int code, const char *name, int *etimin, int *etimax)
1287 sprintf(buf, " E_%-16s : constant Eti_Error := %d;\n", name, code);
1292 return (int)strlen(buf);
1298 const char *s_bool = "";
1300 if (sizeof(bool) == sizeof(char))
1304 else if (sizeof(bool) == sizeof(short))
1308 else if (sizeof(bool) == sizeof(int))
1312 printf(" Sizeof%-*s : constant Natural := %2ld; -- %s\n",
1313 12, "_bool", (long)sizeof(bool), "bool");
1315 printf(" type Curses_Bool is mod 2 ** Interfaces.C.%s'Size;\n", s_bool);
1319 * main() expects two arguments on the commandline, both single characters.
1320 * The first character denotes the facility for which we generate output.
1321 * Possible values are
1325 * P - Pointer Device (Mouse)
1326 * E - ETI base definitions
1328 * The second character then denotes the specific output that should be
1329 * generated for the selected facility.
1332 main(int argc, char *argv[])
1335 char *s = (char *)&x;
1346 /* --------------------------------------------------------------- */
1347 case 'B': /* The Base facility */
1350 case 'A': /* chtype translation into Ada95 record type */
1351 gen_attr_set("Character_Attribute_Set");
1353 case 'B': /* write some initial comment lines */
1356 case 'C': /* generate color constants */
1359 case 'D': /* generate displacements of fields in WINDOW struct. */
1362 case 'E': /* generate Mouse Event codes */
1365 case 'K': /* translation of keycodes */
1368 case 'L': /* generate the Linker_Options pragma */
1371 case 'M': /* generate constants for the ACS characters */
1374 case 'O': /* generate definitions of the old key code names */
1377 case 'P': /* generate definitions of the public variables */
1380 case 'R': /* generate representation clause for Attributed character */
1381 gen_chtype_rep("Attributed_Character");
1383 case 'T': /* generate the Trace info */
1384 gen_trace("Trace_Attribute_Set");
1386 case 'V': /* generate version info */
1393 /* --------------------------------------------------------------- */
1394 case 'M': /* The Menu facility */
1397 case 'R': /* generate representation clause for Menu_Option_Set */
1398 gen_menu_opt_rep("Menu_Option_Set");
1400 case 'B': /* write some initial comment lines */
1403 case 'L': /* generate the Linker_Options pragma */
1404 gen_menu_linkopts();
1406 case 'I': /* generate representation clause for Item_Option_Set */
1407 gen_item_opt_rep("Item_Option_Set");
1413 /* --------------------------------------------------------------- */
1414 case 'F': /* The Form facility */
1417 case 'R': /* generate representation clause for Form_Option_Set */
1418 gen_form_opt_rep("Form_Option_Set");
1420 case 'B': /* write some initial comment lines */
1423 case 'L': /* generate the Linker_Options pragma */
1424 gen_form_linkopts();
1426 case 'I': /* generate representation clause for Field_Option_Set */
1427 gen_field_opt_rep("Field_Option_Set");
1433 /* --------------------------------------------------------------- */
1434 case 'P': /* The Pointer(=Mouse) facility */
1437 case 'B': /* write some initial comment lines */
1440 case 'M': /* generate representation clause for Mouse_Event */
1441 gen_mrep_rep("Mouse_Event");
1443 case 'L': /* generate the Linker_Options pragma */
1444 gen_panel_linkopts();
1450 /* --------------------------------------------------------------- */
1451 case 'E': /* chtype size detection */
1456 const char *fmt = " type C_Chtype is new %s;\n";
1457 const char *afmt = " type C_AttrType is new %s;\n";
1459 if (sizeof(chtype) == sizeof(int))
1461 if (sizeof(int) == sizeof(long))
1462 printf(fmt, "C_ULong");
1465 printf(fmt, "C_UInt");
1467 else if (sizeof(chtype) == sizeof(long))
1469 printf(fmt, "C_ULong");
1474 if (sizeof(attr_t) == sizeof(int))
1476 if (sizeof(int) == sizeof(long))
1477 printf(afmt, "C_ULong");
1480 printf(afmt, "C_UInt");
1482 else if (sizeof(attr_t) == sizeof(long))
1484 printf(afmt, "C_ULong");
1489 printf("define(`CF_CURSES_OK',`%d')", OK);
1490 printf("define(`CF_CURSES_ERR',`%d')", ERR);
1491 printf("define(`CF_CURSES_TRUE',`%d')", TRUE);
1492 printf("define(`CF_CURSES_FALSE',`%d')", FALSE);
1497 char *buf = (char *)malloc(2048);
1504 p += eti_gen(p, E_OK, "Ok", &etimin, &etimax);
1505 p += eti_gen(p, E_SYSTEM_ERROR, "System_Error", &etimin, &etimax);
1506 p += eti_gen(p, E_BAD_ARGUMENT, "Bad_Argument", &etimin, &etimax);
1507 p += eti_gen(p, E_POSTED, "Posted", &etimin, &etimax);
1508 p += eti_gen(p, E_CONNECTED, "Connected", &etimin, &etimax);
1509 p += eti_gen(p, E_BAD_STATE, "Bad_State", &etimin, &etimax);
1510 p += eti_gen(p, E_NO_ROOM, "No_Room", &etimin, &etimax);
1511 p += eti_gen(p, E_NOT_POSTED, "Not_Posted", &etimin, &etimax);
1512 p += eti_gen(p, E_UNKNOWN_COMMAND,
1513 "Unknown_Command", &etimin, &etimax);
1514 p += eti_gen(p, E_NO_MATCH, "No_Match", &etimin, &etimax);
1515 p += eti_gen(p, E_NOT_SELECTABLE,
1516 "Not_Selectable", &etimin, &etimax);
1517 p += eti_gen(p, E_NOT_CONNECTED,
1518 "Not_Connected", &etimin, &etimax);
1519 p += eti_gen(p, E_REQUEST_DENIED,
1520 "Request_Denied", &etimin, &etimax);
1521 p += eti_gen(p, E_INVALID_FIELD,
1522 "Invalid_Field", &etimin, &etimax);
1523 p += eti_gen(p, E_CURRENT,
1524 "Current", &etimin, &etimax);
1526 printf(" subtype Eti_Error is C_Int range %d .. %d;\n\n",
1535 /* --------------------------------------------------------------- */
1536 case 'V': /* plain version dump */
1540 case '1': /* major version */
1541 #ifdef NCURSES_VERSION_MAJOR
1542 printf("%d", NCURSES_VERSION_MAJOR);
1545 case '2': /* minor version */
1546 #ifdef NCURSES_VERSION_MINOR
1547 printf("%d", NCURSES_VERSION_MINOR);
1550 case '3': /* patch level */
1551 #ifdef NCURSES_VERSION_PATCH
1552 printf("%d", NCURSES_VERSION_PATCH);
1560 /* --------------------------------------------------------------- */