]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - Ada95/gen/gen.c
ncurses 5.8 - patch 20110319
[ncurses.git] / Ada95 / gen / gen.c
index ba180452a2d08212d37928ebab0b71116e8a131c..fad98a1aba31444d9756420bb125561a89a34e34 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2008,2009 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998,2010,2011 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.50 2009/03/21 21:34:20 tom Exp $
+    $Id: gen.c,v 1.57 2011/03/19 19:09:38 Nicolas.Boulenguez Exp $
   --------------------------------------------------------------------------*/
 /*
   This program generates various record structures and constants from the
   to produce the real source.
   */
 
+#ifdef HAVE_CONFIG_H
 #include <ncurses_cfg.h>
+#else
+#include <ncurses.h>
+#define HAVE_USE_DEFAULT_COLORS 1
+#endif
 
 #include <stdlib.h>
 #include <stddef.h>
@@ -52,6 +57,7 @@
 #include <menu.h>
 #include <form.h>
 
+#define UChar(c)       ((unsigned char)(c))
 #define RES_NAME "Reserved"
 
 static const char *model = "";
@@ -71,7 +77,7 @@ find_pos(char *s, unsigned len, int *low, int *high)
   int l = 0;
 
   *high = -1;
-  *low = 8 * len;
+  *low = (int)(8 * len);
 
   for (i = 0; i < len; i++, s++)
     {
@@ -90,9 +96,13 @@ find_pos(char *s, unsigned len, int *low, int *high)
                }
              l++;
              if (little_endian)
-               *s >>= 1;
+               {
+                 *s >>= 1;
+               }
              else
-               *s <<= 1;
+               {
+                 *s = (char)(*s << 1);
+               }
            }
        }
       else
@@ -108,13 +118,16 @@ find_pos(char *s, unsigned len, int *low, int *high)
  * bit size, i.e. they fit into an (u)int or a (u)short.
  */
 static void
-  gen_reps
-  (const name_attribute_pair * nap,    /* array of name_attribute_pair records */
-   const char *name,           /* name of the represented record type  */
-   int len,                    /* size of the record in bytes          */
-   int bias)
+gen_reps(
+         const name_attribute_pair * nap,      /* array of name_attribute_pair records */
+         const char *name,     /* name of the represented record type  */
+         int len,              /* size of the record in bytes          */
+         int bias)
 {
-  int i, n, l, cnt = 0, low, high;
+  const char *unused_name = "Unused";
+  int long_bits = (8 * (int)sizeof(unsigned long));
+  int len_bits = (8 * len);
+  int i, j, n, l, cnt = 0, low, high;
   int width = strlen(RES_NAME) + 3;
   unsigned long a;
   unsigned long mask = 0;
@@ -124,7 +137,7 @@ static void
   for (i = 0; nap[i].name != (char *)0; i++)
     {
       cnt++;
-      l = strlen(nap[i].name);
+      l = (int)strlen(nap[i].name);
       if (l > width)
        width = l;
     }
@@ -134,8 +147,32 @@ static void
   printf("      record\n");
   for (i = 0; nap[i].name != (char *)0; i++)
     {
+      mask |= nap[i].attr;
       printf("         %-*s : Boolean;\n", width, nap[i].name);
     }
+
+  /*
+   * Compute a mask for the unused bits in this target.
+   */
+  mask = ~mask;
+  /*
+   * Bits in the biased area are unused by the target.
+   */
+  for (j = 0; j < bias; ++j)
+    {
+      mask &= (unsigned long)(~(1L << j));
+    }
+  /*
+   * Bits past the target's size are really unused.
+   */
+  for (j = len_bits + bias; j < long_bits; ++j)
+    {
+      mask &= (unsigned long)(~(1L << j));
+    }
+  if (mask != 0)
+    {
+      printf("         %-*s : Boolean;\n", width, unused_name);
+    }
   printf("      end record;\n");
   printf("   pragma Convention (C, %s);\n\n", name);
 
@@ -145,16 +182,22 @@ static void
   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 (mask != 0)
+    {
+      l = find_pos((char *)&mask, sizeof(mask), &low, &high);
+      if (l >= 0)
+       printf("         %-*s at 0 range %2d .. %2d;\n", width, unused_name,
+              low - bias, high - bias);
+    }
   i = 1;
   n = cnt;
   printf("      end record;\n");
-  printf("   for %s'Size use %d;\n", name, 8 * len);
+  printf("   for %s'Size use %d;\n", name, len_bits);
   printf("   --  Please note: this rep. clause is generated and may be\n");
   printf("   --               different on your system.");
 }
@@ -162,7 +205,7 @@ static void
 static void
 chtype_rep(const char *name, attr_t mask)
 {
-  attr_t x = -1;
+  attr_t x = (attr_t)-1;
   attr_t t = x & mask;
   int low, high;
   int l = find_pos((char *)&t, sizeof(t), &low, &high);
@@ -219,7 +262,7 @@ gen_mrep_rep(const char *name)
   mrep_rep("Z", &x);
 
   memset(&x, 0, sizeof(x));
-  x.bstate = -1;
+  x.bstate = (mmask_t) - 1;
   mrep_rep("Bstate", &x);
 
   printf("      end record;\n");
@@ -285,11 +328,12 @@ gen_attr_set(const char *name)
   chtype attr = A_ATTRIBUTES & ~A_COLOR;
   int start = -1;
   int len = 0;
-  int i, set;
+  int i;
+  chtype set;
   for (i = 0; i < (int)(8 * sizeof(chtype)); i++)
 
     {
-      set = attr & 1;
+      set = (attr & 1);
       if (set)
        {
          if (start < 0)
@@ -321,6 +365,7 @@ gen_trace(const char *name)
     {"Internal_Calls", TRACE_ICALLS},
     {"Character_Calls", TRACE_CCALLS},
     {"Termcap_TermInfo", TRACE_DATABASE},
+    {"Attributes_And_Colors", TRACE_ATTRS},
     {(char *)0, 0}
   };
   gen_reps(nap, name, sizeof(int), 0);
@@ -435,13 +480,14 @@ keydef(const char *name, const char *old_name, int value, int mode)
   if (mode == 0)               /* Generate the new name */
     printf("   %-30s : constant Special_Key_Code := 8#%3o#;\n", name, value);
   else
-    {                          /* generate the old name, but only if it doesn't conflict with the old
-                                * name (Ada95 isn't case sensitive!)
-                                */
+    {
       const char *s = old_name;
       const char *t = name;
 
-      while (*s && *t && (toupper(*s++) == toupper(*t++)));
+      /* generate the old name, but only if it doesn't conflict with the old
+       * name (Ada95 isn't case sensitive!)
+       */
+      while (*s && *t && (toupper(UChar(*s++)) == toupper(UChar(*t++))));
       if (*s || *t)
        printf("   %-16s : Special_Key_Code renames %s;\n", old_name, name);
     }
@@ -761,7 +807,7 @@ acs_def(const char *name, chtype *a)
   int c = a - &acs_map[0];
 
   printf("   %-24s : constant Character := ", name);
-  if (isprint(c) && (c != '`'))
+  if (isprint(UChar(c)) && (c != '`'))
     printf("'%c';\n", c);
   else
     printf("Character'Val (%d);\n", c);
@@ -1243,7 +1289,7 @@ eti_gen(char *buf, int code, const char *name, int *etimin, int *etimax)
     *etimin = code;
   if (code > *etimax)
     *etimax = code;
-  return strlen(buf);
+  return (int)strlen(buf);
 }
 
 static void
@@ -1266,12 +1312,6 @@ gen_offsets(void)
   printf("   Sizeof%-*s : constant Natural := %2ld; --  %s\n",
         12, "_bool", (long)sizeof(bool), "bool");
 
-  /* In ncurses _maxy and _maxx needs an offset for the "public"
-   * value
-   */
-  printf("   Offset%-*s : constant Natural := %2d; --  %s\n",
-        12, "_XY", 1, "int");
-  printf("\n");
   printf("   type Curses_Bool is mod 2 ** Interfaces.C.%s'Size;\n", s_bool);
 }
 
@@ -1485,7 +1525,7 @@ main(int argc, char *argv[])
              }
            printf("   subtype Eti_Error is C_Int range %d .. %d;\n\n",
                   etimin, etimax);
-           printf(buf);
+           printf("%s", buf);
          }
          break;
        default: