/****************************************************************************
* Author: Juergen Pfeifer, 1996 *
+ * and: Thomas E. Dickey, 1998 *
+ * and: Nicolas Boulenguez, 2011 *
****************************************************************************/
/*
Version Control
- $Id: gen.c,v 1.72 2020/02/22 21:01:00 tom Exp $
+ $Id: gen.c,v 1.76 2020/08/09 00:57:30 tom Exp $
--------------------------------------------------------------------------*/
/*
This program prints on its standard output the source for the
#undef UCHAR
#undef UINT
+#undef ULONG
typedef unsigned char UCHAR;
typedef unsigned int UINT;
+typedef unsigned long ULONG;
/* These global variables will be set by main () */
static int little_endian;
}
static void
-print_constant(const char *name,
+print_constant(FILE * fp,
+ const char *name,
+ UINT value)
+{
+ fprintf(fp, " %-28s : constant := %u;\n", name, value);
+}
+
+static void
+print_long_val(FILE * fp,
+ const char *name,
long value)
{
- printf(" %-28s : constant := %ld;\n", name, value);
+ fprintf(fp, " %-28s : constant := %ld;\n", name, value);
+}
+
+static void
+print_size_of(FILE * fp,
+ const char *name,
+ size_t value)
+{
+ fprintf(fp, " %-28s : constant := %lu;\n", name, value);
}
#define PRINT_NAMED_CONSTANT(name) \
- print_constant (#name, name)
+ print_long_val (fp, #name, name)
static void
-print_comment(const char *message)
+print_comment(FILE * fp, const char *message)
{
- printf("\n -- %s\n\n", message);
+ fprintf(fp, "\n -- %s\n\n", message);
}
/*
c_type mask = (mask_macro); \
if (!find_pos ((UCHAR *)&mask, sizeof (mask), &first, &last)) \
my_error ("failed to locate " ada_name); \
- print_constant (ada_name "_First", first); \
- print_constant (ada_name "_Last", last); \
+ print_constant (fp, ada_name "_First", first); \
+ print_constant (fp, ada_name "_Last", last); \
}
#define PRINT_NAMED_BITMASK(c_type, mask_macro) \
memset (&mask.field, 0xff, sizeof(mask.field)); \
if (!find_pos ((UCHAR *)&mask, sizeof (mask), &first, &last)) \
my_error ("failed to locate" #record "_" #field); \
- print_constant (#record "_" #field "_First", first); \
- print_constant (#record "_" #field "_Last", last); \
+ print_constant (fp, #record "_" #field "_First", first); \
+ print_constant (fp, #record "_" #field "_Last", last); \
}
/*--------------------*/
int
main(int argc, const char *argv[])
{
+ FILE *fp = 0;
const int x = 0x12345678;
little_endian = (*((const char *)&x) == 0x78);
if (KEY_MIN == 256)
my_error("unexpected value for KEY_MIN: 256");
- if (argc != 2)
- my_error("Only one argument expected (DFT_ARG_SUFFIX)");
+ if (argc == 3)
+ {
+ fp = fopen(argv[2], "wb");
+ }
+ else if (argc == 2)
+ {
+ fp = stdout;
+ }
+ else
+ {
+ my_error("Only one or two arguments expected (DFT_ARG_SUFFIX)");
+ }
if ((strlen(argv[0]) + strlen(__FILE__)) > 25)
{
- printf("-- Generated by the C program %.40s.\n",
- my_program_invocation_name);
+ fprintf(fp, "-- Generated by the C program %.40s.\n",
+ my_program_invocation_name);
}
else
{
- printf("-- Generated by the C program %s (source %s).\n",
- my_program_invocation_name,
- __FILE__);
+ fprintf(fp, "-- Generated by the C program %s (source %s).\n",
+ my_program_invocation_name,
+ __FILE__);
}
- printf("-- Do not edit this file directly.\n");
- printf("-- The values provided here may vary on your system.\n");
- printf("\n");
- printf("with System;\n");
- printf("package Terminal_Interface.Curses_Constants is\n");
- printf(" pragma Pure;\n");
- printf("\n");
-
- printf(" DFT_ARG_SUFFIX : constant String := \"%s\";\n", argv[1]);
- printf(" Bit_Order : constant System.Bit_Order := System.%s_Order_First;\n",
- little_endian ? "Low" : "High");
- print_constant("Sizeof_Bool", 8 * sizeof(bool));
+ fprintf(fp, "-- Do not edit this file directly.\n");
+ fprintf(fp, "-- The values provided here may vary on your system.\n");
+ fprintf(fp, "\n");
+ fprintf(fp, "with System;\n");
+ fprintf(fp, "package Terminal_Interface.Curses_Constants is\n");
+ fprintf(fp, " pragma Pure;\n");
+ fprintf(fp, "\n");
+
+ fprintf(fp, " DFT_ARG_SUFFIX : constant String := \"%s\";\n", argv[1]);
+ fprintf(fp,
+ " Bit_Order : constant System.Bit_Order := System.%s_Order_First;\n",
+ little_endian ? "Low" : "High");
+ print_size_of(fp, "Sizeof_Bool", 8 * sizeof(bool));
PRINT_NAMED_CONSTANT(OK);
PRINT_NAMED_CONSTANT(ERR);
- printf(" pragma Warnings (Off); -- redefinition of Standard.True and False\n");
+ fprintf(fp,
+ " pragma Warnings (Off); -- redefinition of Standard.True and False\n");
PRINT_NAMED_CONSTANT(TRUE);
PRINT_NAMED_CONSTANT(FALSE);
- printf(" pragma Warnings (On);\n");
+ fprintf(fp, " pragma Warnings (On);\n");
- print_comment("Version of the ncurses library from extensions(3NCURSES)");
+ print_comment(fp, "Version of the ncurses library from extensions(3NCURSES)");
PRINT_NAMED_CONSTANT(NCURSES_VERSION_MAJOR);
PRINT_NAMED_CONSTANT(NCURSES_VERSION_MINOR);
- printf(" Version : constant String := \"%d.%d\";\n",
- NCURSES_VERSION_MAJOR, NCURSES_VERSION_MINOR);
+ fprintf(fp, " Version : constant String := \"%d.%d\";\n",
+ NCURSES_VERSION_MAJOR, NCURSES_VERSION_MINOR);
- print_comment("Character non-color attributes from attr(3NCURSES)");
- printf(" -- attr_t and chtype may be signed in C.\n");
- printf(" type attr_t is mod 2 ** %lu;\n", (long unsigned)(8 * sizeof(attr_t)));
+ print_comment(fp, "Character non-color attributes from attr(3NCURSES)");
+ fprintf(fp, " -- attr_t and chtype may be signed in C.\n");
+ fprintf(fp, " type attr_t is mod 2 ** %lu;\n", (long unsigned)(8 * sizeof(attr_t)));
PRINT_NAMED_BITMASK(attr_t, A_CHARTEXT);
PRINT_NAMED_BITMASK(attr_t, A_COLOR);
PRINT_BITMASK(attr_t, "Attr", A_ATTRIBUTES & ~A_COLOR);
PRINT_NAMED_BITMASK(attr_t, A_RIGHT);
PRINT_NAMED_BITMASK(attr_t, A_TOP);
PRINT_NAMED_BITMASK(attr_t, A_VERTICAL);
- print_constant("chtype_Size", 8 * sizeof(chtype));
+ print_size_of(fp, "chtype_Size", 8 * sizeof(chtype));
- print_comment("predefined color numbers from color(3NCURSES)");
+ print_comment(fp, "predefined color numbers from color(3NCURSES)");
PRINT_NAMED_CONSTANT(COLOR_BLACK);
PRINT_NAMED_CONSTANT(COLOR_RED);
PRINT_NAMED_CONSTANT(COLOR_GREEN);
PRINT_NAMED_CONSTANT(COLOR_CYAN);
PRINT_NAMED_CONSTANT(COLOR_WHITE);
- print_comment("ETI return codes from ncurses.h");
+ print_comment(fp, "ETI return codes from ncurses.h");
PRINT_NAMED_CONSTANT(E_OK);
PRINT_NAMED_CONSTANT(E_SYSTEM_ERROR);
PRINT_NAMED_CONSTANT(E_BAD_ARGUMENT);
PRINT_NAMED_CONSTANT(E_INVALID_FIELD);
PRINT_NAMED_CONSTANT(E_CURRENT);
- print_comment("Input key codes not defined in any ncurses manpage");
+ print_comment(fp, "Input key codes not defined in any ncurses manpage");
PRINT_NAMED_CONSTANT(KEY_MIN);
PRINT_NAMED_CONSTANT(KEY_MAX);
#ifdef KEY_CODE_YES
PRINT_NAMED_CONSTANT(KEY_CODE_YES);
#endif
- print_comment("Input key codes from getch(3NCURSES)");
+ print_comment(fp, "Input key codes from getch(3NCURSES)");
PRINT_NAMED_CONSTANT(KEY_BREAK);
PRINT_NAMED_CONSTANT(KEY_DOWN);
PRINT_NAMED_CONSTANT(KEY_UP);
PRINT_NAMED_CONSTANT(KEY_HOME);
PRINT_NAMED_CONSTANT(KEY_BACKSPACE);
PRINT_NAMED_CONSTANT(KEY_F0);
- print_constant("KEY_F1", KEY_F(1));
- print_constant("KEY_F2", KEY_F(2));
- print_constant("KEY_F3", KEY_F(3));
- print_constant("KEY_F4", KEY_F(4));
- print_constant("KEY_F5", KEY_F(5));
- print_constant("KEY_F6", KEY_F(6));
- print_constant("KEY_F7", KEY_F(7));
- print_constant("KEY_F8", KEY_F(8));
- print_constant("KEY_F9", KEY_F(9));
- print_constant("KEY_F10", KEY_F(10));
- print_constant("KEY_F11", KEY_F(11));
- print_constant("KEY_F12", KEY_F(12));
- print_constant("KEY_F13", KEY_F(13));
- print_constant("KEY_F14", KEY_F(14));
- print_constant("KEY_F15", KEY_F(15));
- print_constant("KEY_F16", KEY_F(16));
- print_constant("KEY_F17", KEY_F(17));
- print_constant("KEY_F18", KEY_F(18));
- print_constant("KEY_F19", KEY_F(19));
- print_constant("KEY_F20", KEY_F(20));
- print_constant("KEY_F21", KEY_F(21));
- print_constant("KEY_F22", KEY_F(22));
- print_constant("KEY_F23", KEY_F(23));
- print_constant("KEY_F24", KEY_F(24));
+#define PRINT_NAMED_FUNC_KEY(name) print_constant(fp, "KEY_F"#name, KEY_F(name))
+ PRINT_NAMED_FUNC_KEY(1);
+ PRINT_NAMED_FUNC_KEY(2);
+ PRINT_NAMED_FUNC_KEY(3);
+ PRINT_NAMED_FUNC_KEY(4);
+ PRINT_NAMED_FUNC_KEY(5);
+ PRINT_NAMED_FUNC_KEY(6);
+ PRINT_NAMED_FUNC_KEY(7);
+ PRINT_NAMED_FUNC_KEY(8);
+ PRINT_NAMED_FUNC_KEY(9);
+ PRINT_NAMED_FUNC_KEY(10);
+ PRINT_NAMED_FUNC_KEY(11);
+ PRINT_NAMED_FUNC_KEY(12);
+ PRINT_NAMED_FUNC_KEY(13);
+ PRINT_NAMED_FUNC_KEY(14);
+ PRINT_NAMED_FUNC_KEY(15);
+ PRINT_NAMED_FUNC_KEY(16);
+ PRINT_NAMED_FUNC_KEY(17);
+ PRINT_NAMED_FUNC_KEY(18);
+ PRINT_NAMED_FUNC_KEY(19);
+ PRINT_NAMED_FUNC_KEY(20);
+ PRINT_NAMED_FUNC_KEY(21);
+ PRINT_NAMED_FUNC_KEY(22);
+ PRINT_NAMED_FUNC_KEY(23);
+ PRINT_NAMED_FUNC_KEY(24);
PRINT_NAMED_CONSTANT(KEY_DL);
PRINT_NAMED_CONSTANT(KEY_IL);
PRINT_NAMED_CONSTANT(KEY_DC);
PRINT_NAMED_CONSTANT(KEY_MOUSE);
PRINT_NAMED_CONSTANT(KEY_RESIZE);
- print_comment("alternate character codes (ACS) from addch(3NCURSES)");
-#define PRINT_ACS(name) print_constant (#name, &name - &acs_map[0])
+ print_comment(fp, "alternate character codes (ACS) from addch(3NCURSES)");
+#define PRINT_ACS(name) print_size_of (fp, #name, (size_t)(&name - &acs_map[0]))
PRINT_ACS(ACS_ULCORNER);
PRINT_ACS(ACS_LLCORNER);
PRINT_ACS(ACS_URCORNER);
PRINT_ACS(ACS_NEQUAL);
PRINT_ACS(ACS_STERLING);
- print_comment("Menu_Options from opts(3MENU)");
+ print_comment(fp, "Menu_Options from opts(3MENU)");
PRINT_NAMED_BITMASK(Menu_Options, O_ONEVALUE);
PRINT_NAMED_BITMASK(Menu_Options, O_SHOWDESC);
PRINT_NAMED_BITMASK(Menu_Options, O_ROWMAJOR);
PRINT_NAMED_BITMASK(Menu_Options, O_IGNORECASE);
PRINT_NAMED_BITMASK(Menu_Options, O_SHOWMATCH);
PRINT_NAMED_BITMASK(Menu_Options, O_NONCYCLIC);
- print_constant("Menu_Options_Size", 8 * sizeof(Menu_Options));
+ print_size_of(fp, "Menu_Options_Size", 8 * sizeof(Menu_Options));
- print_comment("Item_Options from menu_opts(3MENU)");
+ print_comment(fp, "Item_Options from menu_opts(3MENU)");
PRINT_NAMED_BITMASK(Item_Options, O_SELECTABLE);
- print_constant("Item_Options_Size", 8 * sizeof(Item_Options));
+ print_size_of(fp, "Item_Options_Size", 8 * sizeof(Item_Options));
- print_comment("Field_Options from field_opts(3FORM)");
+ print_comment(fp, "Field_Options from field_opts(3FORM)");
PRINT_NAMED_BITMASK(Field_Options, O_VISIBLE);
PRINT_NAMED_BITMASK(Field_Options, O_ACTIVE);
PRINT_NAMED_BITMASK(Field_Options, O_PUBLIC);
PRINT_NAMED_BITMASK(Field_Options, O_NULLOK);
PRINT_NAMED_BITMASK(Field_Options, O_PASSOK);
PRINT_NAMED_BITMASK(Field_Options, O_STATIC);
- print_constant("Field_Options_Size", 8 * sizeof(Field_Options));
+ print_size_of(fp, "Field_Options_Size", 8 * sizeof(Field_Options));
- print_comment("Field_Options from opts(3FORM)");
+ print_comment(fp, "Field_Options from opts(3FORM)");
PRINT_NAMED_BITMASK(Field_Options, O_NL_OVERLOAD);
PRINT_NAMED_BITMASK(Field_Options, O_BS_OVERLOAD);
/* Field_Options_Size is defined below */
- print_comment("MEVENT structure from mouse(3NCURSES)");
+ print_comment(fp, "MEVENT structure from mouse(3NCURSES)");
STRUCT_OFFSET(MEVENT, id);
STRUCT_OFFSET(MEVENT, x);
STRUCT_OFFSET(MEVENT, y);
STRUCT_OFFSET(MEVENT, z);
STRUCT_OFFSET(MEVENT, bstate);
- print_constant("MEVENT_Size", 8 * sizeof(MEVENT));
+ print_size_of(fp, "MEVENT_Size", 8 * sizeof(MEVENT));
- print_comment("mouse events from mouse(3NCURSES)");
+ print_comment(fp, "mouse events from mouse(3NCURSES)");
{
mmask_t all_events;
#define PRINT_MOUSE_EVENT(event) \
- print_constant (#event, event); \
+ print_constant (fp, #event, event); \
all_events |= event
all_events = 0;
#ifdef BUTTON1_RESERVED_EVENT
PRINT_MOUSE_EVENT(BUTTON1_RESERVED_EVENT);
#endif
- print_constant("all_events_button_1", (long)all_events);
+ print_constant(fp, "all_events_button_1", all_events);
all_events = 0;
PRINT_MOUSE_EVENT(BUTTON2_RELEASED);
#ifdef BUTTON2_RESERVED_EVENT
PRINT_MOUSE_EVENT(BUTTON2_RESERVED_EVENT);
#endif
- print_constant("all_events_button_2", (long)all_events);
+ print_constant(fp, "all_events_button_2", all_events);
all_events = 0;
PRINT_MOUSE_EVENT(BUTTON3_RELEASED);
#ifdef BUTTON3_RESERVED_EVENT
PRINT_MOUSE_EVENT(BUTTON3_RESERVED_EVENT);
#endif
- print_constant("all_events_button_3", (long)all_events);
+ print_constant(fp, "all_events_button_3", all_events);
all_events = 0;
PRINT_MOUSE_EVENT(BUTTON4_RELEASED);
#ifdef BUTTON4_RESERVED_EVENT
PRINT_MOUSE_EVENT(BUTTON4_RESERVED_EVENT);
#endif
- print_constant("all_events_button_4", (long)all_events);
+ print_constant(fp, "all_events_button_4", all_events);
}
PRINT_NAMED_CONSTANT(BUTTON_CTRL);
PRINT_NAMED_CONSTANT(BUTTON_SHIFT);
PRINT_NAMED_CONSTANT(REPORT_MOUSE_POSITION);
PRINT_NAMED_CONSTANT(ALL_MOUSE_EVENTS);
- print_comment("trace selection from trace(3NCURSES)");
+ print_comment(fp, "trace selection from trace(3NCURSES)");
PRINT_NAMED_BITMASK(UINT, TRACE_TIMES);
PRINT_NAMED_BITMASK(UINT, TRACE_TPUTS);
PRINT_NAMED_BITMASK(UINT, TRACE_UPDATE);
PRINT_NAMED_BITMASK(UINT, TRACE_CCALLS);
PRINT_NAMED_BITMASK(UINT, TRACE_DATABASE);
PRINT_NAMED_BITMASK(UINT, TRACE_ATTRS);
- print_constant("Trace_Size", 8 * sizeof(UINT));
+ print_size_of(fp, "Trace_Size", 8 * sizeof(UINT));
- printf("end Terminal_Interface.Curses_Constants;\n");
+ fprintf(fp, "end Terminal_Interface.Curses_Constants;\n");
exit(EXIT_SUCCESS);
}