ncurses 6.2 - patch 20200816
[ncurses.git] / Ada95 / gen / gen.c
index 3a1426f4705d81879ec19dc076305db3989c1d44..51bc161a4685c0f6ab2843ab00e0fff31f11755c 100644 (file)
-/*----------------------------------------------------------------------------
-//                                                                          --
-//                           GNAT ncurses Binding                           --
-//                                                                          --
-//                                  gen.c                                   --
-//                                                                          --
-//                                 B O D Y                                  --
-//                                                                          --
-//  Version 00.92                                                           --
-//                                                                          --
-//  The ncurses Ada95 binding is copyrighted 1996 by                        --
-//  Juergen Pfeifer, Email: Juergen.Pfeifer@T-Online.de                     --
-//                                                                          --
-//  Permission is hereby granted to reproduce and distribute this           --
-//  binding by any means and for any fee, whether alone or as part          --
-//  of a larger distribution, in source or in binary form, PROVIDED         --
-//  this notice is included with any such distribution, and is not          --
-//  removed from any of its header files. Mention of ncurses and the        --
-//  author of this binding in any applications linked with it is            --
-//  highly appreciated.                                                     --
-//                                                                          --
-//  This binding comes AS IS with no warranty, implied or expressed.        --
-//----------------------------------------------------------------------------
+/****************************************************************************
+ * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 1998-2014,2016 Free Software Foundation, Inc.                  *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "Software"), to deal in the Software without restriction, including      *
+ * without limitation the rights to use, copy, modify, merge, publish,      *
+ * distribute, distribute with modifications, sublicense, and/or sell       *
+ * copies of the Software, and to permit persons to whom the Software is    *
+ * furnished to do so, subject to the following conditions:                 *
+ *                                                                          *
+ * The above copyright notice and this permission notice shall be included  *
+ * in all copies or substantial portions of the Software.                   *
+ *                                                                          *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
+ *                                                                          *
+ * Except as contained in this notice, the name(s) of the above copyright   *
+ * holders shall not be used in advertising or otherwise to promote the     *
+ * sale, use or other dealings in this Software without prior written       *
+ * authorization.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *   Author:  Juergen Pfeifer, 1996                                         *
+ *      and:  Thomas E. Dickey, 1998                                        *
+ *      and:  Nicolas Boulenguez, 2011                                      *
+ ****************************************************************************/
+
+/*
     Version Control
-    $Revision: 1.8 $
+    $Id: gen.c,v 1.77 2020/08/16 18:05:05 tom Exp $
   --------------------------------------------------------------------------*/
 /*
-  This program generates various record structures and constants from the
-  ncurses header file for the Ada95 packages. Essentially it produces
-  Ada95 source on stdout, which is then merged using m4 into a template
-  to produce the real source.
-  */
+  This program prints on its standard output the source for the
+  Terminal_Interface.Curses_Constants Ada package specification. This pure
+  package only exports C constants to the Ada compiler.
+ */
 
+#ifdef HAVE_CONFIG_H
+#include <ncurses_cfg.h>
+#else
+#include <ncurses.h>
+#endif
+
+#include <stdlib.h>
 #include <string.h>
-#include <assert.h>
-#include <ctype.h>
-#include <time.h>
 
 #include <menu.h>
 #include <form.h>
 
-#define RES_NAME "Reserved"
-
-static int little_endian = 0;
-
-typedef struct {
-  const char *name;
-  unsigned int attr;
-} name_attribute_pair;
-
-static int find_pos (char *s, unsigned len, int *low, int *high)
-{
-  unsigned int i,j; 
-  int l = 0;
-
-  *high = -1;
-  *low  = 8*len;
-
-  for(i=0; i < len; i++,s++)
-    {
-      if (*s)
-       {
-         for(j=0;j<8*sizeof(char);j++)
-           {
-             if ((( little_endian && ((*s)&0x01)) ||
-                  (!little_endian && ((*s)&0x80))) )
-               {
-                 if (l > *high)
-                   *high = l;
-                 if (l < *low)
-                   *low = l;
-               }
-             l++;
-             if (little_endian)
-               *s >>= 1;
-             else
-               *s <<= 1;
-           }
-       }
-      else
-       l += 8;
-    }
-  return (*high >= 0 && (*low <= *high)) ? *low : -1;
-}
-
-static void gen_reps ( const name_attribute_pair *nap,
-                      const char *name,
-                      int len)
-{
-  int i,l,cnt = 0,low,high;
-  int width = strlen(RES_NAME);
-  int bias = 0;
-  unsigned int a;
-  unsigned int mask = 0;
-  char *suffix;
-
-  assert (nap);
-
-  if (len == sizeof(int)/2)
-    {
-      bias = little_endian ? 8 * len : 0;
-      suffix = " / 2";
-    }
-  else
-    {
-      assert(len==sizeof(int));
-      suffix = "";
-    }
-
-  for (i=0; nap[i].name != (char *)0; i++)
-    {
-      cnt++;
-      l = strlen(nap[i].name);
-      if (l>width)
-       width = l;
-    }
-  assert (width > 0);
-
-  printf("   type %s is\n",name);
-  printf("      record\n");
-  for (i=0; nap[i].name != (char *)0; i++)
-    {
-      printf("         %-*s : Boolean;\n",width,nap[i].name);
-    }  
-  if (cnt != 8*len)
-    {
-      printf("         %-*s : Boolean;\n",width,RES_NAME);
-    }
-  printf("      end record;\n");
-  printf("   pragma Pack (%s);\n",name);
-  printf("   pragma Convention (C, %s);\n\n",name);
-
-  printf("   for %s use\n",name);
-  printf("      record\n");
-
-  for (i=0; nap[i].name != (char *)0; i++)
-    {
-      a = nap[i].attr;
-      mask |= a;
-      l = find_pos( (char *)&a,sizeof(a),&low,&high );
-      if (l>=0)
-       printf("         %-*s at 0 range %2d .. %2d;\n",width,nap[i].name,low-bias,high-bias);
-    }  
-  if (cnt != 8*len)
-    {
-      mask = ~mask;
-      assert(mask);
-      if (little_endian)
-       l = 8*len - 1;
-      else
-       l = 0;
-      printf("         %-*s at 0 range %2d .. %2d;\n",width,RES_NAME,l,l);
-    }
-  printf("      end record;\n");
-  printf("   for %s'Size use Interfaces.C.int'Size%s;\n", name, suffix);
-  printf("   --  Please note: this rep. clause is generated and may be\n");
-  printf("   --               different on your system.");
-}
-
+#undef UCHAR
+#undef UINT
+#undef ULONG
 
-static void chtype_rep (const char *name, int mask)
-{
-  int x = -1;
-  int t = x & mask;
-  int low, high;
-  int l = find_pos ((char *)&t, sizeof(t), &low, &high);
-  if (l>=0)
-    printf("         %-5s at 0 range %2d .. %2d;\n",name,low,high); 
-}
-
-static void gen_chtype_rep(const char *name)
-{
-  printf("   for %s use\n      record\n",name);
-  chtype_rep("Ch",A_CHARTEXT);
-  chtype_rep("Color",A_COLOR);
-  chtype_rep("Attr",(A_ATTRIBUTES&~A_COLOR));
-  printf("      end record;\n   for %s'Size use Interfaces.C.int'Size;\n",name);
-  printf("      --  Please note: this rep. clause is generated and may be\n");
-  printf("      --               different on your system.\n");
-}
-
-
-static void mrep_rep (const char *name, void *rec)
-{
-  int low, high;
-  int l = find_pos((char *)rec, sizeof(MEVENT), &low, &high);
-  if (l>=0)
-    printf("         %-7s at 0 range %3d .. %3d;\n",name,low,high); 
-}
+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 const char *my_program_invocation_name = NULL;
 
-static void gen_mrep_rep(const char *name)
+static void
+my_error(const char *message)
 {
-  MEVENT x;
-
-  printf("   for %s use\n      record\n",name);
-
-  memset(&x,0,sizeof(x));
-  x.id = -1;
-  mrep_rep("Id",&x);
-
-  memset(&x,0,sizeof(x));
-  x.x = -1;
-  mrep_rep("X",&x);
-
-  memset(&x,0,sizeof(x));
-  x.y = -1;
-  mrep_rep("Y",&x);
-
-  memset(&x,0,sizeof(x));
-  x.z = -1;
-  mrep_rep("Z",&x);
-
-  memset(&x,0,sizeof(x));
-  x.bstate = -1;
-  mrep_rep("Bstate",&x);
-
-  printf("      end record;\n");
-  printf("      --  Please note: this rep. clause is generated and may be\n");
-  printf("      --               different on your system.\n");
-}
-
-static void gen_attr_set( const char *name )
-{
-  static const name_attribute_pair nap[] = {
-#ifdef A_STANDOUT
-    {"Stand_Out",               A_STANDOUT},
-#endif
-#ifdef A_UNDERLINE
-    {"Under_Line",              A_UNDERLINE},
-#endif
-#ifdef A_REVERSE
-    {"Reverse_Video",           A_REVERSE},
-#endif
-#ifdef A_BLINK
-    {"Blink",                   A_BLINK},
-#endif
-#ifdef A_DIM
-    {"Dim_Character",           A_DIM},
-#endif
-#ifdef A_BOLD
-    {"Bold_Character",          A_BOLD},
-#endif
-#ifdef A_ALTCHARSET
-    {"Alternate_Character_Set", A_ALTCHARSET},
-#endif
-#ifdef A_INVIS
-    {"Invisible_Character",     A_INVIS},
-#endif
-#ifdef A_PROTECT
-    {"Protected_Character",     A_PROTECT},
-#endif
-#ifdef A_HORIZONTAL
-    {"Horizontal",              A_HORIZONTAL},
-#endif
-#ifdef A_LEFT
-    {"Left",                    A_LEFT},
-#endif
-#ifdef A_LOW
-    {"Low",                     A_LOW},
-#endif
-#ifdef A_RIGHT
-    {"Right",                   A_RIGHT},
-#endif
-#ifdef A_TOP
-    {"Top",                     A_TOP},
-#endif
-#ifdef A_VERTICAL
-    {"Vertical",                A_VERTICAL},
-#endif
-    {(char *)0,                 0}
-  };
-  gen_reps (nap, name, sizeof(int)/2);
+  fprintf(stderr, "%s: %s\n", my_program_invocation_name, message);
+  exit(EXIT_FAILURE);
 }
 
-static void gen_menu_opt_rep(const char *name)
+static void
+print_constant(FILE * fp,
+              const char *name,
+              UINT value)
 {
-  static const name_attribute_pair nap[] = {
-#ifdef O_ONEVALUE
-    {"One_Valued", O_ONEVALUE},
-#endif
-#ifdef O_SHOWDESC
-    {"Show_Descriptions", O_SHOWDESC},
-#endif
-#ifdef O_ROWMAJOR
-    {"Row_Major_Order", O_ROWMAJOR},
-#endif
-#ifdef O_IGNORECASE
-    {"Ignore_Case", O_IGNORECASE},
-#endif
-#ifdef O_SHOWMATCH
-    {"Show_Matches", O_SHOWMATCH},
-#endif
-#ifdef O_NONCYCLIC
-    {"Non_Cyclic", O_NONCYCLIC},
-#endif
-    {(char *)0, 0}
-  };
-  gen_reps (nap, name, sizeof(int));
+  fprintf(fp, "   %-28s : constant := %u;\n", name, value);
 }
 
-static void gen_item_opt_rep(const char *name)
+static void
+print_long_val(FILE * fp,
+              const char *name,
+              long value)
 {
-  static const name_attribute_pair nap[] = {
-#ifdef O_SELECTABLE
-    {"Selectable", O_SELECTABLE},
-#endif
-    {(char *)0   , 0}
-  };  
-  gen_reps (nap, name, sizeof(int));
+  fprintf(fp, "   %-28s : constant := %ld;\n", name, value);
 }
 
-static void gen_form_opt_rep(const char *name)
+static void
+print_size_of(FILE * fp,
+             const char *name,
+             size_t value)
 {
-  static const name_attribute_pair nap[] = {
-#ifdef O_NL_OVERLOAD
-    {"NL_Overload", O_NL_OVERLOAD},
-#endif
-#ifdef O_BS_OVERLOAD
-    {"BS_Overload", O_BS_OVERLOAD},
-#endif
-    {(char *)0    , 0}
-  };
-  gen_reps (nap, name, sizeof(int));
+  fprintf(fp, "   %-28s : constant := %lu;\n", name, value);
 }
 
-static void gen_field_opt_rep(const char *name)
-{
-  static const name_attribute_pair nap[] = {
-#ifdef O_VISIBLE
-    {"Visible",O_VISIBLE},
-#endif
-#ifdef O_ACTIVE
-    {"Active",O_ACTIVE},
-#endif
-#ifdef O_PUBLIC
-    {"Public",O_PUBLIC},
-#endif
-#ifdef O_EDIT
-    {"Edit",O_EDIT},
-#endif
-#ifdef O_WRAP
-    {"Wrap",O_WRAP},
-#endif
-#ifdef O_BLANK
-    {"Blank",O_BLANK},
-#endif
-#ifdef O_AUTOSKIP
-    {"Auto_Skip",O_AUTOSKIP},
-#endif
-#ifdef O_NULLOK
-    {"Null_Ok",O_NULLOK},
-#endif
-#ifdef O_PASSOK
-    {"Pass_Ok",O_PASSOK},
-#endif
-#ifdef O_STATIC
-    {"Static",O_STATIC},
-#endif
-    {(char *)0, 0}
-  };
-  gen_reps (nap, name, sizeof(int));
-}
+#define PRINT_NAMED_CONSTANT(name) \
+  print_long_val (fp, #name, name)
 
-static void keydef(const char *name, const char *old_name, int value, int mode)
+static void
+print_comment(FILE * fp, const char *message)
 {
-  if (mode==0)
-    printf("   %-30s : constant Special_Key_Code := 8#%3o#;\n",name,value);
-  else
-    {
-      const char *s = old_name; const char *t = name;
-      while ( *s && *t && (toupper(*s++) == toupper(*t++)));
-      if (*s || *t)
-       printf("   %-16s : Special_Key_Code renames %s;\n",old_name,name);
-    }
+  fprintf(fp, "\n   --  %s\n\n", message);
 }
-  
-static void gen_keydefs (int mode)
-{
-  char buf[16];
-  char obuf[16];
-  int i;
 
-#ifdef KEY_CODE_YES
-  keydef("Key_Code_Yes","KEY_CODE_YES",KEY_CODE_YES,mode);
-#endif
-#ifdef KEY_MIN
-  keydef("Key_Min","KEY_MIN",KEY_MIN,mode);
-#endif
-#ifdef KEY_BREAK
-  keydef("Key_Break","KEY_BREAK",KEY_BREAK,mode);
-#endif
-#ifdef KEY_DOWN
-  keydef("Key_Cursor_Down","KEY_DOWN",KEY_DOWN,mode);
-#endif
-#ifdef KEY_UP
-  keydef("Key_Cursor_Up","KEY_UP",KEY_UP,mode);
-#endif
-#ifdef KEY_LEFT
-  keydef("Key_Cursor_Left","KEY_LEFT",KEY_LEFT,mode);
-#endif
-#ifdef KEY_RIGHT
-  keydef("Key_Cursor_Right","KEY_RIGHT",KEY_RIGHT,mode);
-#endif
-#ifdef KEY_HOME
-  keydef("Key_Home","KEY_HOME",KEY_HOME,mode);
-#endif
-#ifdef KEY_BACKSPACE
-  keydef("Key_Backspace","KEY_BACKSPACE",KEY_BACKSPACE,mode);
-#endif
-#ifdef KEY_F0
-  keydef("Key_F0","KEY_F0",KEY_F0,mode);
-#endif
-#ifdef KEY_F
-  for(i=1;i<=24;i++)
-    {
-      sprintf(buf ,"Key_F%d",i);
-      sprintf(obuf,"KEY_F%d",i);
-      keydef(buf,obuf,KEY_F(i),mode);
-    }
-#endif
-#ifdef KEY_DL
-  keydef("Key_Delete_Line","KEY_DL",KEY_DL,mode);
-#endif
-#ifdef KEY_IL
-  keydef("Key_Insert_Line","KEY_IL",KEY_IL,mode);
-#endif
-#ifdef KEY_DC
-  keydef("Key_Delete_Char","KEY_DC",KEY_DC,mode);
-#endif
-#ifdef KEY_IC
-  keydef("Key_Insert_Char","KEY_IC",KEY_IC,mode);
-#endif
-#ifdef KEY_EIC
-  keydef("Key_Exit_Insert_Mode","KEY_EIC",KEY_EIC,mode);
-#endif
-#ifdef KEY_CLEAR
-  keydef("Key_Clear_Screen","KEY_CLEAR",KEY_CLEAR,mode);
-#endif
-#ifdef KEY_EOS
-  keydef("Key_Clear_End_Of_Screen","KEY_EOS",KEY_EOS,mode);
-#endif
-#ifdef KEY_EOL
-  keydef("Key_Clear_End_Of_Line","KEY_EOL",KEY_EOL,mode);
-#endif
-#ifdef KEY_SF
-  keydef("Key_Scroll_1_Forward","KEY_SF",KEY_SF,mode);
-#endif
-#ifdef KEY_SR
-  keydef("Key_Scroll_1_Backward","KEY_SR",KEY_SR,mode);
-#endif
-#ifdef KEY_NPAGE
-  keydef("Key_Next_Page","KEY_NPAGE",KEY_NPAGE,mode);
-#endif
-#ifdef KEY_PPAGE
-  keydef("Key_Previous_Page","KEY_PPAGE",KEY_PPAGE,mode);
-#endif
-#ifdef KEY_STAB
-  keydef("Key_Set_Tab","KEY_STAB",KEY_STAB,mode);
-#endif
-#ifdef KEY_CTAB
-  keydef("Key_Clear_Tab","KEY_CTAB",KEY_CTAB,mode);
-#endif
-#ifdef KEY_CATAB
-  keydef("Key_Clear_All_Tabs","KEY_CATAB",KEY_CATAB,mode);
-#endif
-#ifdef KEY_ENTER
-  keydef("Key_Enter_Or_Send","KEY_ENTER",KEY_ENTER,mode);
-#endif
-#ifdef KEY_SRESET
-  keydef("Key_Soft_Reset","KEY_SRESET",KEY_SRESET,mode);
-#endif
-#ifdef KEY_RESET
-  keydef("Key_Reset","KEY_RESET",KEY_RESET,mode);
-#endif
-#ifdef KEY_PRINT
-  keydef("Key_Print","KEY_PRINT",KEY_PRINT,mode);
-#endif
-#ifdef KEY_LL
-  keydef("Key_Bottom","KEY_LL",KEY_LL,mode);
-#endif
-#ifdef KEY_A1
-  keydef("Key_Upper_Left_Of_Keypad","KEY_A1",KEY_A1,mode);
-#endif
-#ifdef KEY_A3
-  keydef("Key_Upper_Right_Of_Keypad","KEY_A3",KEY_A3,mode);
-#endif
-#ifdef KEY_B2
-  keydef("Key_Center_Of_Keypad","KEY_B2",KEY_B2,mode);
-#endif
-#ifdef KEY_C1
-  keydef("Key_Lower_Left_Of_Keypad","KEY_C1",KEY_C1,mode);
-#endif
-#ifdef KEY_C3
-  keydef("Key_Lower_Right_Of_Keypad","KEY_C3",KEY_C3,mode);
-#endif
-#ifdef KEY_BTAB
-  keydef("Key_Back_Tab","KEY_BTAB",KEY_BTAB,mode);
-#endif
-#ifdef KEY_BEG
-  keydef("Key_Beginning","KEY_BEG",KEY_BEG,mode);
-#endif
-#ifdef KEY_CANCEL
-  keydef("Key_Cancel","KEY_CANCEL",KEY_CANCEL,mode);
-#endif
-#ifdef KEY_CLOSE
-  keydef("Key_Close","KEY_CLOSE",KEY_CLOSE,mode);
-#endif
-#ifdef KEY_COMMAND
-  keydef("Key_Command","KEY_COMMAND",KEY_COMMAND,mode);
-#endif
-#ifdef KEY_COPY
-  keydef("Key_Copy","KEY_COPY",KEY_COPY,mode);
-#endif
-#ifdef KEY_CREATE
-  keydef("Key_Create","KEY_CREATE",KEY_CREATE,mode);
-#endif
-#ifdef KEY_END
-  keydef("Key_End","KEY_END",KEY_END,mode);
-#endif
-#ifdef KEY_EXIT
-  keydef("Key_Exit","KEY_EXIT",KEY_EXIT,mode);
-#endif
-#ifdef KEY_FIND
-  keydef("Key_Find","KEY_FIND",KEY_FIND,mode);
-#endif
-#ifdef KEY_HELP
-  keydef("Key_Help","KEY_HELP",KEY_HELP,mode);
-#endif
-#ifdef KEY_MARK
-  keydef("Key_Mark","KEY_MARK",KEY_MARK,mode);
-#endif
-#ifdef KEY_MESSAGE
-  keydef("Key_Message","KEY_MESSAGE",KEY_MESSAGE,mode);
-#endif
-#ifdef KEY_MOVE
-  keydef("Key_Move","KEY_MOVE",KEY_MOVE,mode);
-#endif
-#ifdef KEY_NEXT
-  keydef("Key_Next","KEY_NEXT",KEY_NEXT,mode);
-#endif
-#ifdef KEY_OPEN
-  keydef("Key_Open","KEY_OPEN",KEY_OPEN,mode);
-#endif
-#ifdef KEY_OPTIONS
-  keydef("Key_Options","KEY_OPTIONS",KEY_OPTIONS,mode);
-#endif
-#ifdef KEY_PREVIOUS
-  keydef("Key_Previous","KEY_PREVIOUS",KEY_PREVIOUS,mode);
-#endif
-#ifdef KEY_REDO
-  keydef("Key_Redo","KEY_REDO",KEY_REDO,mode);
-#endif
-#ifdef KEY_REFERENCE
-  keydef("Key_Reference","KEY_REFERENCE",KEY_REFERENCE,mode);
-#endif
-#ifdef KEY_REFRESH
-  keydef("Key_Refresh","KEY_REFRESH",KEY_REFRESH,mode);
-#endif
-#ifdef KEY_REPLACE
-  keydef("Key_Replace","KEY_REPLACE",KEY_REPLACE,mode);
-#endif
-#ifdef KEY_RESTART
-  keydef("Key_Restart","KEY_RESTART",KEY_RESTART,mode);
-#endif
-#ifdef KEY_RESUME
-  keydef("Key_Resume","KEY_RESUME",KEY_RESUME,mode);
-#endif
-#ifdef KEY_SAVE
-  keydef("Key_Save","KEY_SAVE",KEY_SAVE,mode);
-#endif
-#ifdef KEY_SBEG
-  keydef("Key_Shift_Begin","KEY_SBEG",KEY_SBEG,mode);
-#endif
-#ifdef KEY_SCANCEL
-  keydef("Key_Shift_Cancel","KEY_SCANCEL",KEY_SCANCEL,mode);
-#endif
-#ifdef KEY_SCOMMAND
-  keydef("Key_Shift_Command","KEY_SCOMMAND",KEY_SCOMMAND,mode);
-#endif
-#ifdef KEY_SCOPY
-  keydef("Key_Shift_Copy","KEY_SCOPY",KEY_SCOPY,mode);
-#endif
-#ifdef KEY_SCREATE
-  keydef("Key_Shift_Create","KEY_SCREATE",KEY_SCREATE,mode);
-#endif
-#ifdef KEY_SDC
-  keydef("Key_Shift_Delete_Char","KEY_SDC",KEY_SDC,mode);
-#endif
-#ifdef KEY_SDL
-  keydef("Key_Shift_Delete_Line","KEY_SDL",KEY_SDL,mode);
-#endif
-#ifdef KEY_SELECT
-  keydef("Key_Select","KEY_SELECT",KEY_SELECT,mode);
-#endif
-#ifdef KEY_SEND
-  keydef("Key_Shift_End","KEY_SEND",KEY_SEND,mode);
-#endif
-#ifdef KEY_SEOL
-  keydef("Key_Shift_Clear_End_Of_Line","KEY_SEOL",KEY_SEOL,mode);
-#endif
-#ifdef KEY_SEXIT
-  keydef("Key_Shift_Exit","KEY_SEXIT",KEY_SEXIT,mode);
-#endif
-#ifdef KEY_SFIND
-  keydef("Key_Shift_Find","KEY_SFIND",KEY_SFIND,mode);
-#endif
-#ifdef KEY_SHELP
-  keydef("Key_Shift_Help","KEY_SHELP",KEY_SHELP,mode);
-#endif
-#ifdef KEY_SHOME
-  keydef("Key_Shift_Home","KEY_SHOME",KEY_SHOME,mode);
-#endif
-#ifdef KEY_SIC
-  keydef("Key_Shift_Insert_Char","KEY_SIC",KEY_SIC,mode);
-#endif
-#ifdef KEY_SLEFT
-  keydef("Key_Shift_Cursor_Left","KEY_SLEFT",KEY_SLEFT,mode);
-#endif
-#ifdef KEY_SMESSAGE
-  keydef("Key_Shift_Message","KEY_SMESSAGE",KEY_SMESSAGE,mode);
-#endif
-#ifdef KEY_SMOVE
-  keydef("Key_Shift_Move","KEY_SMOVE",KEY_SMOVE,mode);
-#endif
-#ifdef KEY_SNEXT
-  keydef("Key_Shift_Next_Page","KEY_SNEXT",KEY_SNEXT,mode);
-#endif
-#ifdef KEY_SOPTIONS
-  keydef("Key_Shift_Options","KEY_SOPTIONS",KEY_SOPTIONS,mode);
-#endif
-#ifdef KEY_SPREVIOUS
-  keydef("Key_Shift_Previous_Page","KEY_SPREVIOUS",KEY_SPREVIOUS,mode);
-#endif
-#ifdef KEY_SPRINT
-  keydef("Key_Shift_Print","KEY_SPRINT",KEY_SPRINT,mode);
-#endif
-#ifdef KEY_SREDO
-  keydef("Key_Shift_Redo","KEY_SREDO",KEY_SREDO,mode);
-#endif
-#ifdef KEY_SREPLACE
-  keydef("Key_Shift_Replace","KEY_SREPLACE",KEY_SREPLACE,mode);
-#endif
-#ifdef KEY_SRIGHT
-  keydef("Key_Shift_Cursor_Right","KEY_SRIGHT",KEY_SRIGHT,mode);
-#endif
-#ifdef KEY_SRSUME
-  keydef("Key_Shift_Resume","KEY_SRSUME",KEY_SRSUME,mode);
-#endif
-#ifdef KEY_SSAVE
-  keydef("Key_Shift_Save","KEY_SSAVE",KEY_SSAVE,mode);
-#endif
-#ifdef KEY_SSUSPEND
-  keydef("Key_Shift_Suspend","KEY_SSUSPEND",KEY_SSUSPEND,mode);
-#endif
-#ifdef KEY_SUNDO
-  keydef("Key_Shift_Undo","KEY_SUNDO",KEY_SUNDO,mode);
-#endif
-#ifdef KEY_SUSPEND
-  keydef("Key_Suspend","KEY_SUSPEND",KEY_SUSPEND,mode);
-#endif
-#ifdef KEY_UNDO
-  keydef("Key_Undo","KEY_UNDO",KEY_UNDO,mode);
-#endif
-#ifdef KEY_MOUSE
-  keydef("Key_Mouse","KEY_MOUSE",KEY_MOUSE,mode);
-#endif  
-}
-
-static void acs_def (const char *name, chtype *a)
-{
-  int c = a - &acs_map[0];
-  printf("   %-24s : constant Character := ",name);
-  if (isprint(c) && (c!='`'))
-    printf("'%c';\n",c);
-  else
-    printf("Character'Val (%d);\n",c);
-}
-
-
-static void gen_acs (void)
-{
-#ifdef ACS_ULCORNER
-  acs_def("ACS_Upper_Left_Corner",&ACS_ULCORNER);
-#endif
-#ifdef ACS_LLCORNER
-  acs_def("ACS_Lower_Left_Corner",&ACS_LLCORNER);
-#endif
-#ifdef ACS_URCORNER
-  acs_def("ACS_Upper_Right_Corner",&ACS_URCORNER);
-#endif
-#ifdef ACS_LRCORNER
-  acs_def("ACS_Lower_Right_Corner",&ACS_LRCORNER);
-#endif
-#ifdef ACS_LTEE
-  acs_def("ACS_Left_Tee",&ACS_LTEE);
-#endif
-#ifdef ACS_RTEE
-  acs_def("ACS_Right_Tee",&ACS_RTEE);
-#endif
-#ifdef ACS_BTEE
-  acs_def("ACS_Bottom_Tee",&ACS_BTEE);
-#endif
-#ifdef ACS_TTEE
-  acs_def("ACS_Top_Tee",&ACS_TTEE);
-#endif
-#ifdef ACS_HLINE
-  acs_def("ACS_Horizontal_Line",&ACS_HLINE);
-#endif
-#ifdef ACS_VLINE
-  acs_def("ACS_Vertical_Line",&ACS_VLINE);
-#endif
-#ifdef ACS_PLUS
-  acs_def("ACS_Plus_Symbol",&ACS_PLUS);
-#endif
-#ifdef ACS_S1
-  acs_def("ACS_Scan_Line_1",&ACS_S1);
-#endif
-#ifdef ACS_S9
-  acs_def("ACS_Scan_Line_9",&ACS_S9);
-#endif
-#ifdef ACS_DIAMOND
-  acs_def("ACS_Diamond",&ACS_DIAMOND);
-#endif
-#ifdef ACS_CKBOARD
-  acs_def("ACS_Checker_Board",&ACS_CKBOARD);
-#endif
-#ifdef ACS_DEGREE
-  acs_def("ACS_Degree",&ACS_DEGREE);
-#endif
-#ifdef ACS_PLMINUS
-  acs_def("ACS_Plus_Minus",&ACS_PLMINUS);
-#endif
-#ifdef ACS_BULLET
-  acs_def("ACS_Bullet",&ACS_BULLET);
-#endif
-#ifdef ACS_LARROW
-  acs_def("ACS_Left_Arrow",&ACS_LARROW);
-#endif
-#ifdef ACS_RARROW
-  acs_def("ACS_Right_Arrow",&ACS_RARROW);
-#endif
-#ifdef ACS_DARROW
-  acs_def("ACS_Down_Arrow",&ACS_DARROW);
-#endif
-#ifdef ACS_UARROW
-  acs_def("ACS_Up_Arrow",&ACS_UARROW);
-#endif
-#ifdef ACS_BOARD
-  acs_def("ACS_Board_Of_Squares",&ACS_BOARD);
-#endif
-#ifdef ACS_LANTERN
-  acs_def("ACS_Lantern",&ACS_LANTERN);
-#endif
-#ifdef ACS_BLOCK
-  acs_def("ACS_Solid_Block",&ACS_BLOCK);
-#endif
-#ifdef ACS_S3
-  acs_def("ACS_Scan_Line_3",&ACS_S3);
-#endif
-#ifdef ACS_S7
-  acs_def("ACS_Scan_Line_7",&ACS_S7);
-#endif
-#ifdef ACS_LEQUAL
-  acs_def("ACS_Less_Or_Equal",&ACS_LEQUAL);
-#endif
-#ifdef ACS_GEQUAL
-  acs_def("ACS_Greater_Or_Equal",&ACS_GEQUAL);
-#endif
-#ifdef ACS_PI
-  acs_def("ACS_PI",&ACS_PI);
-#endif
-#ifdef ACS_NEQUAL
-  acs_def("ACS_Not_Equal",&ACS_NEQUAL);
-#endif
-#ifdef ACS_STERLING
-  acs_def("ACS_Sterling",&ACS_STERLING);
-#endif
-}
-
-static void prologue(const char *name)
-{
-  time_t t = time(NULL);
-  printf("--  %s binding, generated at %s",name,ctime(&t));
-  printf("--  This module is generated. Please don't change it manually!\n");
-  printf("--  Run the generator instead.\n--  |");
-
-  printf("define(`M4_BIT_ORDER',`%s_Order_First')",little_endian ? "Low":"High");
-}
-
-static void basedefs (void)
-{
-  prologue("curses");
+/*
+ * Make sure that KEY_MIN and KEY_MAX are defined.
+ * main () will protest if KEY_MIN == 256
+ */
 #ifndef KEY_MAX
 #  define KEY_MAX 0777
 #endif
-  printf("define(`M4_KEY_MAX',`8#%o#')",KEY_MAX);
 #ifndef KEY_MIN
 #  define KEY_MIN 0401
 #endif
-  if (KEY_MIN == 256)
-    abort();
-  printf("define(`M4_SPECIAL_FIRST',`8#%o#')",KEY_MIN - 1);
-}
 
-static void menu_basedefs (void)
+static UCHAR
+bit_is_set(const UCHAR * const data,
+          const UINT offset)
 {
-  prologue("menu");
+  const UCHAR byte = data[offset >> 3];
+  UINT bit;
+
+  if (little_endian)
+    bit = offset;              /* offset */
+  else                         /* or */
+    bit = ~offset;             /* 7 - offset */
+  bit &= 7;                    /* modulo 8 */
+  return (UCHAR) (byte & (1 << bit));
 }
 
-static void form_basedefs (void)
+/* Find lowest and highest used offset in a byte array. */
+/* Returns 0 if and only if all bits are unset. */
+static int
+find_pos(const UCHAR * const data,
+        const UINT sizeof_data,
+        UINT * const low,
+        UINT * const high)
 {
-  prologue("form");
-}
+  const UINT last = (sizeof_data << 3) - 1;
+  UINT offset;
 
-static void mouse_basedefs(void)
-{
-  prologue("mouse");
-}
+  for (offset = last; !bit_is_set(data, offset); offset--)
+    if (!offset)               /* All bits are 0. */
+      return 0;
+  *high = offset;
 
-static void color_def (const char *name, int value)
-{
-  printf("   %-8s : constant Color_Number := %d;\n",name,value);
-}
-
-static void gen_color (void)
-{
-#ifdef COLOR_BLACK
-  color_def ("Black",COLOR_BLACK);
-#endif
-#ifdef COLOR_RED
-  color_def ("Red",COLOR_RED);
-#endif
-#ifdef COLOR_GREEN
-  color_def ("Green",COLOR_GREEN);
-#endif
-#ifdef COLOR_YELLOW
-  color_def ("Yellow",COLOR_YELLOW);
-#endif
-#ifdef COLOR_BLUE
-  color_def ("Blue",COLOR_BLUE);
-#endif
-#ifdef COLOR_MAGENTA
-  color_def ("Magenta",COLOR_MAGENTA);
-#endif
-#ifdef COLOR_CYAN
-  color_def ("Cyan",COLOR_CYAN);
-#endif
-#ifdef COLOR_WHITE
-  color_def ("White",COLOR_WHITE);
-#endif
-}
-
-static void gen_linkopts (void)
-{
-   printf("   pragma Linker_Options (\"-lncurses\");\n");
-}
-
-static void gen_menu_linkopts (void)
-{
-   printf("   pragma Linker_Options (\"-lmenu\");\n");
-}
+  for (offset = 0; !bit_is_set(data, offset); offset++)
+    {
+    }
+  *low = offset;
 
-static void gen_form_linkopts (void)
-{
-   printf("   pragma Linker_Options (\"-lform\");\n");
+  return -1;
 }
 
-static void gen_panel_linkopts (void)
+#define PRINT_BITMASK(c_type, ada_name, mask_macro)                     \
+  {                                                                     \
+    UINT first, last;                                                   \
+    c_type mask = (mask_macro);                                         \
+    if (!find_pos ((UCHAR *)&mask, sizeof (mask), &first, &last))       \
+      my_error ("failed to locate " ada_name);                          \
+    print_constant (fp, ada_name "_First", first);                      \
+    print_constant (fp, ada_name "_Last", last);                        \
+  }
+
+#define PRINT_NAMED_BITMASK(c_type, mask_macro)         \
+  PRINT_BITMASK (c_type, #mask_macro, mask_macro)
+
+#define STRUCT_OFFSET(record, field)                                    \
+  {                                                                     \
+    UINT first, last;                                                   \
+    record mask;                                                        \
+    memset (&mask, 0, sizeof (mask));                                   \
+    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 (fp, #record "_" #field "_First", first);            \
+    print_constant (fp, #record "_" #field "_Last", last);              \
+  }
+
+/*--------------------*/
+/*  Start of main (). */
+/*--------------------*/
+
+int
+main(int argc, const char *argv[])
 {
-   printf("   pragma Linker_Options (\"-lpanel\");\n");
-}
+  FILE *fp = 0;
+  const int x = 0x12345678;
 
+  little_endian = (*((const char *)&x) == 0x78);
 
-int main(int argc, char *argv[])
-{
-  int x = 0x12345678;
-  char *s = (char *)&x;
+  my_program_invocation_name = argv[0];
 
-  if (*s == 0x78)
-    little_endian = 1;
+  if (KEY_MIN == 256)
+    my_error("unexpected value for KEY_MIN: 256");
 
-  if (argc!=3)
-    exit(1);
+  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)");
+    }
 
-  switch(argv[1][0])
+  if ((strlen(argv[0]) + strlen(__FILE__)) > 25)
     {
-    case 'B':
-      switch(argv[2][0])
-       {
-       case 'A':
-         gen_attr_set("Character_Attribute_Set");
-         break;
-       case 'K':
-         gen_keydefs(0);
-         break;
-       case 'B':
-         basedefs();
-         break;
-       case 'C':
-         gen_color();
-         break;
-       case 'M':
-         gen_acs();
-         break;
-       case 'L':
-         gen_linkopts();
-         break;
-       case 'O':
-         gen_keydefs(1);
-         break;
-       case 'R':
-         gen_chtype_rep("Attributed_Character");
-         break;
-       default:
-         break;
-       }
-      break;
-    case 'M':
-      switch(argv[2][0])
-       {
-       case 'R':
-         gen_menu_opt_rep("Menu_Option_Set");
-         break;
-       case 'B':
-         menu_basedefs();
-         break;
-       case 'L':
-         gen_menu_linkopts();
-         break;
-       case 'I':
-         gen_item_opt_rep("Item_Option_Set");
-         break;
-       default:
-         break;
-       }
-      break;
-    case 'F':
-      switch(argv[2][0])
-       {
-       case 'R':
-         gen_form_opt_rep("Form_Option_Set");
-         break;
-       case 'B':
-         form_basedefs();
-         break;
-       case 'L':
-         gen_form_linkopts();
-         break;
-       case 'I':
-         gen_field_opt_rep("Field_Option_Set");
-         break;
-       default:
-         break;
-       }
-      break;
-    case 'P':
-      switch(argv[2][0])
-       {
-       case 'B':
-         mouse_basedefs();
-         break;
-       case 'M':
-         gen_mrep_rep("Mouse_Event");
-         break;
-       case 'L':
-         gen_panel_linkopts();
-         break;
-       default:
-         break;
-       }
-       break;
-    default:
-      break;
+      fprintf(fp, "--  Generated by the C program %.40s.\n",
+             my_program_invocation_name);
     }
-  return 0;
+  else
+    {
+      fprintf(fp, "--  Generated by the C program %s (source %s).\n",
+             my_program_invocation_name,
+             __FILE__);
+    }
+  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);
+  fprintf(fp,
+         "   pragma Warnings (Off); -- redefinition of Standard.True and False\n");
+  PRINT_NAMED_CONSTANT(TRUE);
+  PRINT_NAMED_CONSTANT(FALSE);
+  fprintf(fp, "   pragma Warnings (On);\n");
+
+  print_comment(fp, "Version of the ncurses library from extensions(3NCURSES)");
+  PRINT_NAMED_CONSTANT(NCURSES_VERSION_MAJOR);
+  PRINT_NAMED_CONSTANT(NCURSES_VERSION_MINOR);
+  fprintf(fp, "   Version : constant String := \"%d.%d\";\n",
+         NCURSES_VERSION_MAJOR, NCURSES_VERSION_MINOR);
+
+  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_STANDOUT);
+  PRINT_NAMED_BITMASK(attr_t, A_UNDERLINE);
+  PRINT_NAMED_BITMASK(attr_t, A_REVERSE);
+  PRINT_NAMED_BITMASK(attr_t, A_BLINK);
+  PRINT_NAMED_BITMASK(attr_t, A_DIM);
+  PRINT_NAMED_BITMASK(attr_t, A_BOLD);
+  PRINT_NAMED_BITMASK(attr_t, A_PROTECT);
+  PRINT_NAMED_BITMASK(attr_t, A_INVIS);
+  PRINT_NAMED_BITMASK(attr_t, A_ALTCHARSET);
+  PRINT_NAMED_BITMASK(attr_t, A_HORIZONTAL);
+  PRINT_NAMED_BITMASK(attr_t, A_LEFT);
+  PRINT_NAMED_BITMASK(attr_t, A_LOW);
+  PRINT_NAMED_BITMASK(attr_t, A_RIGHT);
+  PRINT_NAMED_BITMASK(attr_t, A_TOP);
+  PRINT_NAMED_BITMASK(attr_t, A_VERTICAL);
+  print_size_of(fp, "chtype_Size", 8 * sizeof(chtype));
+
+  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_YELLOW);
+  PRINT_NAMED_CONSTANT(COLOR_BLUE);
+  PRINT_NAMED_CONSTANT(COLOR_MAGENTA);
+  PRINT_NAMED_CONSTANT(COLOR_CYAN);
+  PRINT_NAMED_CONSTANT(COLOR_WHITE);
+
+  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_POSTED);
+  PRINT_NAMED_CONSTANT(E_CONNECTED);
+  PRINT_NAMED_CONSTANT(E_BAD_STATE);
+  PRINT_NAMED_CONSTANT(E_NO_ROOM);
+  PRINT_NAMED_CONSTANT(E_NOT_POSTED);
+  PRINT_NAMED_CONSTANT(E_UNKNOWN_COMMAND);
+  PRINT_NAMED_CONSTANT(E_NO_MATCH);
+  PRINT_NAMED_CONSTANT(E_NOT_SELECTABLE);
+  PRINT_NAMED_CONSTANT(E_NOT_CONNECTED);
+  PRINT_NAMED_CONSTANT(E_REQUEST_DENIED);
+  PRINT_NAMED_CONSTANT(E_INVALID_FIELD);
+  PRINT_NAMED_CONSTANT(E_CURRENT);
+
+  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(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_LEFT);
+  PRINT_NAMED_CONSTANT(KEY_RIGHT);
+  PRINT_NAMED_CONSTANT(KEY_HOME);
+  PRINT_NAMED_CONSTANT(KEY_BACKSPACE);
+  PRINT_NAMED_CONSTANT(KEY_F0);
+#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_IC);
+  PRINT_NAMED_CONSTANT(KEY_EIC);
+  PRINT_NAMED_CONSTANT(KEY_CLEAR);
+  PRINT_NAMED_CONSTANT(KEY_EOS);
+  PRINT_NAMED_CONSTANT(KEY_EOL);
+  PRINT_NAMED_CONSTANT(KEY_SF);
+  PRINT_NAMED_CONSTANT(KEY_SR);
+  PRINT_NAMED_CONSTANT(KEY_NPAGE);
+  PRINT_NAMED_CONSTANT(KEY_PPAGE);
+  PRINT_NAMED_CONSTANT(KEY_STAB);
+  PRINT_NAMED_CONSTANT(KEY_CTAB);
+  PRINT_NAMED_CONSTANT(KEY_CATAB);
+  PRINT_NAMED_CONSTANT(KEY_ENTER);
+  PRINT_NAMED_CONSTANT(KEY_SRESET);
+  PRINT_NAMED_CONSTANT(KEY_RESET);
+  PRINT_NAMED_CONSTANT(KEY_PRINT);
+  PRINT_NAMED_CONSTANT(KEY_LL);
+  PRINT_NAMED_CONSTANT(KEY_A1);
+  PRINT_NAMED_CONSTANT(KEY_A3);
+  PRINT_NAMED_CONSTANT(KEY_B2);
+  PRINT_NAMED_CONSTANT(KEY_C1);
+  PRINT_NAMED_CONSTANT(KEY_C3);
+  PRINT_NAMED_CONSTANT(KEY_BTAB);
+  PRINT_NAMED_CONSTANT(KEY_BEG);
+  PRINT_NAMED_CONSTANT(KEY_CANCEL);
+  PRINT_NAMED_CONSTANT(KEY_CLOSE);
+  PRINT_NAMED_CONSTANT(KEY_COMMAND);
+  PRINT_NAMED_CONSTANT(KEY_COPY);
+  PRINT_NAMED_CONSTANT(KEY_CREATE);
+  PRINT_NAMED_CONSTANT(KEY_END);
+  PRINT_NAMED_CONSTANT(KEY_EXIT);
+  PRINT_NAMED_CONSTANT(KEY_FIND);
+  PRINT_NAMED_CONSTANT(KEY_HELP);
+  PRINT_NAMED_CONSTANT(KEY_MARK);
+  PRINT_NAMED_CONSTANT(KEY_MESSAGE);
+  PRINT_NAMED_CONSTANT(KEY_MOVE);
+  PRINT_NAMED_CONSTANT(KEY_NEXT);
+  PRINT_NAMED_CONSTANT(KEY_OPEN);
+  PRINT_NAMED_CONSTANT(KEY_OPTIONS);
+  PRINT_NAMED_CONSTANT(KEY_PREVIOUS);
+  PRINT_NAMED_CONSTANT(KEY_REDO);
+  PRINT_NAMED_CONSTANT(KEY_REFERENCE);
+  PRINT_NAMED_CONSTANT(KEY_REFRESH);
+  PRINT_NAMED_CONSTANT(KEY_REPLACE);
+  PRINT_NAMED_CONSTANT(KEY_RESTART);
+  PRINT_NAMED_CONSTANT(KEY_RESUME);
+  PRINT_NAMED_CONSTANT(KEY_SAVE);
+  PRINT_NAMED_CONSTANT(KEY_SBEG);
+  PRINT_NAMED_CONSTANT(KEY_SCANCEL);
+  PRINT_NAMED_CONSTANT(KEY_SCOMMAND);
+  PRINT_NAMED_CONSTANT(KEY_SCOPY);
+  PRINT_NAMED_CONSTANT(KEY_SCREATE);
+  PRINT_NAMED_CONSTANT(KEY_SDC);
+  PRINT_NAMED_CONSTANT(KEY_SDL);
+  PRINT_NAMED_CONSTANT(KEY_SELECT);
+  PRINT_NAMED_CONSTANT(KEY_SEND);
+  PRINT_NAMED_CONSTANT(KEY_SEOL);
+  PRINT_NAMED_CONSTANT(KEY_SEXIT);
+  PRINT_NAMED_CONSTANT(KEY_SFIND);
+  PRINT_NAMED_CONSTANT(KEY_SHELP);
+  PRINT_NAMED_CONSTANT(KEY_SHOME);
+  PRINT_NAMED_CONSTANT(KEY_SIC);
+  PRINT_NAMED_CONSTANT(KEY_SLEFT);
+  PRINT_NAMED_CONSTANT(KEY_SMESSAGE);
+  PRINT_NAMED_CONSTANT(KEY_SMOVE);
+  PRINT_NAMED_CONSTANT(KEY_SNEXT);
+  PRINT_NAMED_CONSTANT(KEY_SOPTIONS);
+  PRINT_NAMED_CONSTANT(KEY_SPREVIOUS);
+  PRINT_NAMED_CONSTANT(KEY_SPRINT);
+  PRINT_NAMED_CONSTANT(KEY_SREDO);
+  PRINT_NAMED_CONSTANT(KEY_SREPLACE);
+  PRINT_NAMED_CONSTANT(KEY_SRIGHT);
+  PRINT_NAMED_CONSTANT(KEY_SRSUME);
+  PRINT_NAMED_CONSTANT(KEY_SSAVE);
+  PRINT_NAMED_CONSTANT(KEY_SSUSPEND);
+  PRINT_NAMED_CONSTANT(KEY_SUNDO);
+  PRINT_NAMED_CONSTANT(KEY_SUSPEND);
+  PRINT_NAMED_CONSTANT(KEY_UNDO);
+  PRINT_NAMED_CONSTANT(KEY_MOUSE);
+  PRINT_NAMED_CONSTANT(KEY_RESIZE);
+
+  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_LRCORNER);
+  PRINT_ACS(ACS_LTEE);
+  PRINT_ACS(ACS_RTEE);
+  PRINT_ACS(ACS_BTEE);
+  PRINT_ACS(ACS_TTEE);
+  PRINT_ACS(ACS_HLINE);
+  PRINT_ACS(ACS_VLINE);
+  PRINT_ACS(ACS_PLUS);
+  PRINT_ACS(ACS_S1);
+  PRINT_ACS(ACS_S9);
+  PRINT_ACS(ACS_DIAMOND);
+  PRINT_ACS(ACS_CKBOARD);
+  PRINT_ACS(ACS_DEGREE);
+  PRINT_ACS(ACS_PLMINUS);
+  PRINT_ACS(ACS_BULLET);
+  PRINT_ACS(ACS_LARROW);
+  PRINT_ACS(ACS_RARROW);
+  PRINT_ACS(ACS_DARROW);
+  PRINT_ACS(ACS_UARROW);
+  PRINT_ACS(ACS_BOARD);
+  PRINT_ACS(ACS_LANTERN);
+  PRINT_ACS(ACS_BLOCK);
+  PRINT_ACS(ACS_S3);
+  PRINT_ACS(ACS_S7);
+  PRINT_ACS(ACS_LEQUAL);
+  PRINT_ACS(ACS_GEQUAL);
+  PRINT_ACS(ACS_PI);
+  PRINT_ACS(ACS_NEQUAL);
+  PRINT_ACS(ACS_STERLING);
+
+  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_size_of(fp, "Menu_Options_Size", 8 * sizeof(Menu_Options));
+
+  print_comment(fp, "Item_Options from menu_opts(3MENU)");
+  PRINT_NAMED_BITMASK(Item_Options, O_SELECTABLE);
+  print_size_of(fp, "Item_Options_Size", 8 * sizeof(Item_Options));
+
+  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_EDIT);
+  PRINT_NAMED_BITMASK(Field_Options, O_WRAP);
+  PRINT_NAMED_BITMASK(Field_Options, O_BLANK);
+  PRINT_NAMED_BITMASK(Field_Options, O_AUTOSKIP);
+  PRINT_NAMED_BITMASK(Field_Options, O_NULLOK);
+  PRINT_NAMED_BITMASK(Field_Options, O_PASSOK);
+  PRINT_NAMED_BITMASK(Field_Options, O_STATIC);
+  print_size_of(fp, "Field_Options_Size", 8 * sizeof(Field_Options));
+
+  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(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_size_of(fp, "MEVENT_Size", 8 * sizeof(MEVENT));
+
+  print_comment(fp, "mouse events from mouse(3NCURSES)");
+  {
+    mmask_t all_events;
+
+#define PRINT_MOUSE_EVENT(event)                \
+    print_constant (fp, #event, event);         \
+    all_events |= event
+
+    all_events = 0;
+    PRINT_MOUSE_EVENT(BUTTON1_RELEASED);
+    PRINT_MOUSE_EVENT(BUTTON1_PRESSED);
+    PRINT_MOUSE_EVENT(BUTTON1_CLICKED);
+    PRINT_MOUSE_EVENT(BUTTON1_DOUBLE_CLICKED);
+    PRINT_MOUSE_EVENT(BUTTON1_TRIPLE_CLICKED);
+#ifdef BUTTON1_RESERVED_EVENT
+    PRINT_MOUSE_EVENT(BUTTON1_RESERVED_EVENT);
+#endif
+    print_constant(fp, "all_events_button_1", (UINT) all_events);
+
+    all_events = 0;
+    PRINT_MOUSE_EVENT(BUTTON2_RELEASED);
+    PRINT_MOUSE_EVENT(BUTTON2_PRESSED);
+    PRINT_MOUSE_EVENT(BUTTON2_CLICKED);
+    PRINT_MOUSE_EVENT(BUTTON2_DOUBLE_CLICKED);
+    PRINT_MOUSE_EVENT(BUTTON2_TRIPLE_CLICKED);
+#ifdef BUTTON2_RESERVED_EVENT
+    PRINT_MOUSE_EVENT(BUTTON2_RESERVED_EVENT);
+#endif
+    print_constant(fp, "all_events_button_2", (UINT) all_events);
+
+    all_events = 0;
+    PRINT_MOUSE_EVENT(BUTTON3_RELEASED);
+    PRINT_MOUSE_EVENT(BUTTON3_PRESSED);
+    PRINT_MOUSE_EVENT(BUTTON3_CLICKED);
+    PRINT_MOUSE_EVENT(BUTTON3_DOUBLE_CLICKED);
+    PRINT_MOUSE_EVENT(BUTTON3_TRIPLE_CLICKED);
+#ifdef BUTTON3_RESERVED_EVENT
+    PRINT_MOUSE_EVENT(BUTTON3_RESERVED_EVENT);
+#endif
+    print_constant(fp, "all_events_button_3", (UINT) all_events);
+
+    all_events = 0;
+    PRINT_MOUSE_EVENT(BUTTON4_RELEASED);
+    PRINT_MOUSE_EVENT(BUTTON4_PRESSED);
+    PRINT_MOUSE_EVENT(BUTTON4_CLICKED);
+    PRINT_MOUSE_EVENT(BUTTON4_DOUBLE_CLICKED);
+    PRINT_MOUSE_EVENT(BUTTON4_TRIPLE_CLICKED);
+#ifdef BUTTON4_RESERVED_EVENT
+    PRINT_MOUSE_EVENT(BUTTON4_RESERVED_EVENT);
+#endif
+    print_constant(fp, "all_events_button_4", (UINT) all_events);
+  }
+  PRINT_NAMED_CONSTANT(BUTTON_CTRL);
+  PRINT_NAMED_CONSTANT(BUTTON_SHIFT);
+  PRINT_NAMED_CONSTANT(BUTTON_ALT);
+  PRINT_NAMED_CONSTANT(REPORT_MOUSE_POSITION);
+  PRINT_NAMED_CONSTANT(ALL_MOUSE_EVENTS);
+
+  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_MOVE);
+  PRINT_NAMED_BITMASK(UINT, TRACE_CHARPUT);
+  PRINT_NAMED_BITMASK(UINT, TRACE_CALLS);
+  PRINT_NAMED_BITMASK(UINT, TRACE_VIRTPUT);
+  PRINT_NAMED_BITMASK(UINT, TRACE_IEVENT);
+  PRINT_NAMED_BITMASK(UINT, TRACE_BITS);
+  PRINT_NAMED_BITMASK(UINT, TRACE_ICALLS);
+  PRINT_NAMED_BITMASK(UINT, TRACE_CCALLS);
+  PRINT_NAMED_BITMASK(UINT, TRACE_DATABASE);
+  PRINT_NAMED_BITMASK(UINT, TRACE_ATTRS);
+  print_size_of(fp, "Trace_Size", 8 * sizeof(UINT));
+
+  fprintf(fp, "end Terminal_Interface.Curses_Constants;\n");
+  exit(EXIT_SUCCESS);
 }