From 0ded667f30066256e1054da1c2bdaaa4e236dc1f Mon Sep 17 00:00:00 2001 From: Mike Gorse Date: Mon, 28 Jul 2008 17:59:18 -0500 Subject: [PATCH] Moved bitarray to spi-common from atk-adapter --- atk-adaptor/Makefile.am | 1 - atk-adaptor/collection.c | 2 +- spi-common/Makefile.am | 3 ++ spi-common/bitarray.c | 82 ++++++++++++++++++++++++++++++++++ {atk-adaptor => spi-common}/bitarray.h | 0 5 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 spi-common/bitarray.c rename {atk-adaptor => spi-common}/bitarray.h (100%) diff --git a/atk-adaptor/Makefile.am b/atk-adaptor/Makefile.am index 22d6d41..f4c92fb 100644 --- a/atk-adaptor/Makefile.am +++ b/atk-adaptor/Makefile.am @@ -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 \ diff --git a/atk-adaptor/collection.c b/atk-adaptor/collection.c index a687deb..4cfe6d3 100644 --- a/atk-adaptor/collection.c +++ b/atk-adaptor/collection.c @@ -23,7 +23,7 @@ /* collection.c: implements the Collection interface */ #include "accessible.h" -#include "bitarray.h" +#include "spi-common/bitarray.h" #include #define get_object(message) spi_dbus_get_object(dbus_message_get_path(message)) diff --git a/spi-common/Makefile.am b/spi-common/Makefile.am index 13c67bf..26f3c00 100644 --- a/spi-common/Makefile.am +++ b/spi-common/Makefile.am @@ -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 index 0000000..da13174 --- /dev/null +++ b/spi-common/bitarray.c @@ -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; +} diff --git a/atk-adaptor/bitarray.h b/spi-common/bitarray.h similarity index 100% rename from atk-adaptor/bitarray.h rename to spi-common/bitarray.h -- 2.7.4