]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - Ada95/gen/gen.c
ncurses 5.6 - patch 20070714
[ncurses.git] / Ada95 / gen / gen.c
index b7842a64a862d45e193f299070a5304f26f2c385..3394aa4c0c622f119c7097175d030055dad38fe5 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2004,2005 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998,2005,2007 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            *
@@ -32,7 +32,7 @@
 
 /*
     Version Control
-    $Id: gen.c,v 1.40 2005/01/22 17:03:48 tom Exp $
+    $Id: gen.c,v 1.48 2007/05/05 17:24:36 tom Exp $
   --------------------------------------------------------------------------*/
 /*
   This program generates various record structures and constants from the
@@ -41,6 +41,8 @@
   to produce the real source.
   */
 
+#include <ncurses_cfg.h>
+
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
@@ -771,6 +773,23 @@ acs_def(const char *name, chtype *a)
 static void
 gen_acs(void)
 {
+  printf("   type C_ACS_Map is array (Character'Val (0) .. Character'Val (127))\n");
+  printf("        of Attributed_Character;\n");
+#if USE_REENTRANT || BROKEN_LINKER
+  printf("   type C_ACS_Ptr is access C_ACS_Map;\n");
+  printf("   function ACS_Map return C_ACS_Ptr;\n");
+  printf("   pragma Import (C, ACS_Map, \"_nc_acs_map\");\n");
+#else
+  printf("   ACS_Map : C_ACS_Map;\n");
+  printf("   pragma Import (C, ACS_Map, \"acs_map\");\n");
+#endif
+  printf("   --\n");
+  printf("   --\n");
+  printf("   --  Constants for several characters from the Alternate Character Set\n");
+  printf("   --  You must use these constants as indices into the ACS_Map array\n");
+  printf("   --  to get the corresponding attributed character at runtime.\n");
+  printf("   --\n");
+
 #ifdef ACS_ULCORNER
   acs_def("ACS_Upper_Left_Corner", &ACS_ULCORNER);
 #endif
@@ -877,8 +896,7 @@ gen_acs(void)
    printf("   %-25s : constant Event_Mask := 8#%011lo#;\n", \
           #name, name)
 
-static
-void
+static void
 gen_mouse_events(void)
 {
   mmask_t all1 = 0;
@@ -1004,6 +1022,56 @@ gen_mouse_events(void)
   GEN_EVENT(BUTTON4_EVENTS, all4);
 }
 
+static void
+wrap_one_var(const char *c_var,
+            const char *c_type,
+            const char *ada_func,
+            const char *ada_type)
+{
+#if USE_REENTRANT
+  /* must wrap variables */
+  printf("\n");
+  printf("   function %s return %s\n", ada_func, ada_type);
+  printf("   is\n");
+  printf("      function Result return %s;\n", c_type);
+  printf("      pragma Import (C, Result, \"_nc_%s\");\n", c_var);
+  printf("   begin\n");
+  if (strcmp(c_type, ada_type))
+    printf("      return %s (Result);\n", ada_type);
+  else
+    printf("      return Result;\n");
+  printf("   end %s;\n", ada_func);
+#else
+  /* global variables are really global */
+  printf("\n");
+  printf("   function %s return %s\n", ada_func, ada_type);
+  printf("   is\n");
+  printf("      Result : %s;\n", c_type);
+  printf("      pragma Import (C, Result, \"%s\");\n", c_var);
+  printf("   begin\n");
+  if (strcmp(c_type, ada_type))
+    printf("      return %s (Result);\n", ada_type);
+  else
+    printf("      return Result;\n");
+  printf("   end %s;\n", ada_func);
+#endif
+}
+
+#define GEN_PUBLIC_VAR(c_var, c_type, ada_func, ada_type) \
+       wrap_one_var(#c_var, #c_type, #ada_func, #ada_type)
+
+static void
+gen_public_vars(void)
+{
+  GEN_PUBLIC_VAR(stdscr, Window, Standard_Window, Window);
+  GEN_PUBLIC_VAR(curscr, Window, Current_Window, Window);
+  GEN_PUBLIC_VAR(LINES, C_Int, Lines, Line_Count);
+  GEN_PUBLIC_VAR(COLS, C_Int, Columns, Column_Count);
+  GEN_PUBLIC_VAR(TABSIZE, C_Int, Tab_Size, Natural);
+  GEN_PUBLIC_VAR(COLORS, C_Int, Number_Of_Colors, Natural);
+  GEN_PUBLIC_VAR(COLOR_PAIRS, C_Int, Number_Of_Color_Pairs, Natural);
+}
+
 /*
  * Output some comment lines indicating that the file is generated.
  * The name parameter is the name of the facility to be used in
@@ -1178,70 +1246,21 @@ eti_gen(char *buf, int code, const char *name, int *etimin, int *etimax)
   return strlen(buf);
 }
 
-#define GEN_OFFSET(member,itype)                                    \
-  if (sizeof(((WINDOW*)0)->member)==sizeof(itype)) {                \
-    o = offsetof(WINDOW, member);                                   \
-    if ((o%sizeof(itype) == 0)) {                                   \
-       printf("   Offset%-*s : constant Natural := %2ld; --  %s\n", \
-              12, #member, (long)(o/sizeof(itype)),#itype);         \
-    }                                                               \
-  }
-
 static void
 gen_offsets(void)
 {
-  long o;
   const char *s_bool = "";
 
-  GEN_OFFSET(_maxy, short);
-  GEN_OFFSET(_maxx, short);
-  GEN_OFFSET(_begy, short);
-  GEN_OFFSET(_begx, short);
-  GEN_OFFSET(_cury, short);
-  GEN_OFFSET(_curx, short);
-  GEN_OFFSET(_yoffset, short);
-  GEN_OFFSET(_pary, int);
-  GEN_OFFSET(_parx, int);
   if (sizeof(bool) == sizeof(char))
     {
-      GEN_OFFSET(_notimeout, char);
-      GEN_OFFSET(_clear, char);
-      GEN_OFFSET(_leaveok, char);
-      GEN_OFFSET(_scroll, char);
-      GEN_OFFSET(_idlok, char);
-      GEN_OFFSET(_idcok, char);
-      GEN_OFFSET(_immed, char);
-      GEN_OFFSET(_sync, char);
-      GEN_OFFSET(_use_keypad, char);
-
       s_bool = "char";
     }
   else if (sizeof(bool) == sizeof(short))
     {
-      GEN_OFFSET(_notimeout, short);
-      GEN_OFFSET(_clear, short);
-      GEN_OFFSET(_leaveok, short);
-      GEN_OFFSET(_scroll, short);
-      GEN_OFFSET(_idlok, short);
-      GEN_OFFSET(_idcok, short);
-      GEN_OFFSET(_immed, short);
-      GEN_OFFSET(_sync, short);
-      GEN_OFFSET(_use_keypad, short);
-
       s_bool = "short";
     }
   else if (sizeof(bool) == sizeof(int))
     {
-      GEN_OFFSET(_notimeout, int);
-      GEN_OFFSET(_clear, int);
-      GEN_OFFSET(_leaveok, int);
-      GEN_OFFSET(_scroll, int);
-      GEN_OFFSET(_idlok, int);
-      GEN_OFFSET(_idcok, int);
-      GEN_OFFSET(_immed, int);
-      GEN_OFFSET(_sync, int);
-      GEN_OFFSET(_use_keypad, int);
-
       s_bool = "int";
     }
   printf("   Sizeof%-*s : constant Natural := %2ld; --  %s\n",
@@ -1291,9 +1310,6 @@ main(int argc, char *argv[])
        case 'A':               /* chtype translation into Ada95 record type */
          gen_attr_set("Character_Attribute_Set");
          break;
-       case 'K':               /* translation of keycodes */
-         gen_keydefs(0);
-         break;
        case 'B':               /* write some initial comment lines */
          basedefs();
          break;
@@ -1306,24 +1322,30 @@ main(int argc, char *argv[])
        case 'E':               /* generate Mouse Event codes */
          gen_mouse_events();
          break;
-       case 'M':               /* generate constants for the ACS characters */
-         gen_acs();
+       case 'K':               /* translation of keycodes */
+         gen_keydefs(0);
          break;
        case 'L':               /* generate the Linker_Options pragma */
          gen_linkopts();
          break;
+       case 'M':               /* generate constants for the ACS characters */
+         gen_acs();
+         break;
        case 'O':               /* generate definitions of the old key code names */
          gen_keydefs(1);
          break;
+       case 'P':               /* generate definitions of the public variables */
+         gen_public_vars();
+         break;
        case 'R':               /* generate representation clause for Attributed character */
          gen_chtype_rep("Attributed_Character");
          break;
-       case 'V':               /* generate version info */
-         gen_version_info();
-         break;
        case 'T':               /* generate the Trace info */
          gen_trace("Trace_Attribute_Set");
          break;
+       case 'V':               /* generate version info */
+         gen_version_info();
+         break;
        default:
          break;
        }