Moved bitarray to spi-common from atk-adapter
authorMike Gorse <mgorse@boston.site>
Mon, 28 Jul 2008 22:59:18 +0000 (17:59 -0500)
committerMike Gorse <mgorse@boston.site>
Mon, 28 Jul 2008 22:59:18 +0000 (17:59 -0500)
atk-adaptor/Makefile.am
atk-adaptor/collection.c
spi-common/Makefile.am
spi-common/bitarray.c [new file with mode: 0644]
spi-common/bitarray.h [moved from atk-adaptor/bitarray.h with 100% similarity]

index 22d6d41..f4c92fb 100644 (file)
@@ -16,7 +16,6 @@ libspiatk_la_LIBADD = $(DBUS_GLIB_LIBS)                       \
 libspiatk_la_SOURCES =         \
        accessible.h            \
        accessible.c            \
-       bitarray.h              \
        action.c                \
        application.c           \
        bridge.c                \
index a687deb..4cfe6d3 100644 (file)
@@ -23,7 +23,7 @@
 /* collection.c: implements the Collection interface */
 
 #include "accessible.h"
-#include "bitarray.h"
+#include "spi-common/bitarray.h"
 #include <string.h>
 
 #define get_object(message) spi_dbus_get_object(dbus_message_get_path(message))
index 13c67bf..26f3c00 100644 (file)
@@ -11,6 +11,7 @@ libspicommon_la_LIBADD = $(DBUS_GLIB_LIBS)
 spicommonincludedir = $(includedir)/at-spi-1.0/libspi
 
 spicommoninclude_HEADERS =             \
+       bitarray.h \
        event-types.h \
        generated-types.h \
        keymasks.h \
@@ -24,6 +25,8 @@ CLEANFILES = generated-types.h
 nodist_libspicommon_la_SOURCES = generated-types.h
 
 libspicommon_la_SOURCES =      \
+       bitarray.h \
+       bitarray.c \
        event-types.h           \
        spi-types.h             \
        spi-dbus.h              \
diff --git a/spi-common/bitarray.c b/spi-common/bitarray.c
new file mode 100644 (file)
index 0000000..da13174
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2008 Novell, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "bitarray.h"
+
+gint bitarray_to_seq(dbus_uint32_t *array, gint array_size, gint **out)
+{
+  gint *seq = NULL;
+  gint seq_size = 0;
+  int i, j;
+
+  for (i = 0; i < array_size; i++)
+  {
+    for (j = 0; j < 32; j++)
+    {
+      if (array[i] & (1 << j))
+      {
+       if (!(seq_size % 4))
+       {
+         gint *new_seq = (gint *)realloc(seq, (seq_size + 4) * sizeof(gint));
+         if (!new_seq)
+         {
+           *out = seq;
+           return seq_size;
+         }
+         seq = new_seq;
+       }
+       seq[++seq_size] = i * 32 + j;
+      }
+    }
+  }
+  *out = seq;
+  return seq_size;
+}
+
+dbus_uint32_t bitarray_from_seq(gint *seq, dbus_uint32_t **out)
+{
+  dbus_uint32_t *array = NULL;
+  dbus_uint32_t array_size = 0;
+  dbus_uint32_t array_max_size = 0;
+  int i;
+
+  for (i = 0; seq[i] != BITARRAY_SEQ_TERM; i++)
+  {
+    gint pos = seq[i] / 32, val = seq[i] % 32;
+    if (pos >= array_max_size)
+    {
+      gint *new_array;
+      while (array_max_size <= pos) array_max_size += 4;
+      new_array = (dbus_uint32_t *)realloc(array, array_max_size * sizeof(dbus_uint32_t));
+      if (!new_array)
+      {
+       *out = array;
+       return array_size;
+      }
+      array = new_array;
+    }
+    array[pos] &= (1 << val);
+    if (pos > array_size) array_size = pos;
+  }
+  *out = array;
+  return array_size;
+}
similarity index 100%
rename from atk-adaptor/bitarray.h
rename to spi-common/bitarray.h