summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2001-06-29 23:42:42 +0000
committerOwen Taylor <otaylor@src.gnome.org>2001-06-29 23:42:42 +0000
commit1f2b1ef1092410f2b8ef0b446180ee26b8e6cd1c (patch)
treebfba094f93dca7a93d33c07dd1aef627f20171cc
parent05693cc3889ad2f9ec84bc7853d2e6e255518a7f (diff)
downloadglib-1f2b1ef1092410f2b8ef0b446180ee26b8e6cd1c.tar.gz
[ Very late checkin ]GLIB_1_2_10
Thu Mar 15 10:37:49 2001 Owen Taylor <otaylor@redhat.com> * Released 1.2.10 * NEWS: Update * configure.in: Up micro/interface-age/binary-age to 10.
-rw-r--r--ChangeLog8
-rw-r--r--ChangeLog.pre-2-08
-rw-r--r--ChangeLog.pre-2-108
-rw-r--r--ChangeLog.pre-2-128
-rw-r--r--ChangeLog.pre-2-28
-rw-r--r--ChangeLog.pre-2-48
-rw-r--r--ChangeLog.pre-2-68
-rw-r--r--ChangeLog.pre-2-88
-rw-r--r--HACKING2
-rw-r--r--INSTALL4
-rw-r--r--NEWS5
-rw-r--r--README2
-rw-r--r--configure.in6
-rw-r--r--glib/Makefile.am130
-rw-r--r--glib/garray.c490
-rw-r--r--glib/gcache.c230
-rw-r--r--glib/gcompletion.c288
-rw-r--r--glib/gdataset.c611
-rw-r--r--glib/gdate.c1294
-rw-r--r--glib/gerror.c293
-rw-r--r--glib/ghash.c404
-rw-r--r--glib/ghook.c633
-rw-r--r--glib/giochannel.c128
-rw-r--r--glib/giounix.c313
-rw-r--r--glib/giowin32.c1035
-rw-r--r--glib/glib.h2827
-rw-r--r--glib/glist.c670
-rw-r--r--glib/gmain.c1392
-rw-r--r--glib/gmem.c1008
-rw-r--r--glib/gmessages.c756
-rw-r--r--glib/gnode.c965
-rw-r--r--glib/gprimes.c83
-rw-r--r--glib/grel.c459
-rw-r--r--glib/gscanner.c1752
-rw-r--r--glib/gslist.c595
-rw-r--r--glib/gstrfuncs.c1496
-rw-r--r--glib/gstring.c512
-rw-r--r--glib/gtimer.c201
-rw-r--r--glib/gtree.c744
-rw-r--r--glib/gutils.c927
-rw-r--r--tests/testgdate.c486
-rw-r--r--tests/testgdateparser.c109
-rw-r--r--tests/testglib.c921
43 files changed, 75 insertions, 21760 deletions
diff --git a/ChangeLog b/ChangeLog
index f705a3b4b..12b344e3e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu Mar 15 10:37:49 2001 Owen Taylor <otaylor@redhat.com>
+
+ * Released 1.2.10
+
+ * NEWS: Update
+
+ * configure.in: Up micro/interface-age/binary-age to 10.
+
2001-03-08 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in (FLAG_DOES_NOT_WORK): Fix typo and thus bug #51862.
diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0
index f705a3b4b..12b344e3e 100644
--- a/ChangeLog.pre-2-0
+++ b/ChangeLog.pre-2-0
@@ -1,3 +1,11 @@
+Thu Mar 15 10:37:49 2001 Owen Taylor <otaylor@redhat.com>
+
+ * Released 1.2.10
+
+ * NEWS: Update
+
+ * configure.in: Up micro/interface-age/binary-age to 10.
+
2001-03-08 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in (FLAG_DOES_NOT_WORK): Fix typo and thus bug #51862.
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index f705a3b4b..12b344e3e 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,11 @@
+Thu Mar 15 10:37:49 2001 Owen Taylor <otaylor@redhat.com>
+
+ * Released 1.2.10
+
+ * NEWS: Update
+
+ * configure.in: Up micro/interface-age/binary-age to 10.
+
2001-03-08 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in (FLAG_DOES_NOT_WORK): Fix typo and thus bug #51862.
diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12
index f705a3b4b..12b344e3e 100644
--- a/ChangeLog.pre-2-12
+++ b/ChangeLog.pre-2-12
@@ -1,3 +1,11 @@
+Thu Mar 15 10:37:49 2001 Owen Taylor <otaylor@redhat.com>
+
+ * Released 1.2.10
+
+ * NEWS: Update
+
+ * configure.in: Up micro/interface-age/binary-age to 10.
+
2001-03-08 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in (FLAG_DOES_NOT_WORK): Fix typo and thus bug #51862.
diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2
index f705a3b4b..12b344e3e 100644
--- a/ChangeLog.pre-2-2
+++ b/ChangeLog.pre-2-2
@@ -1,3 +1,11 @@
+Thu Mar 15 10:37:49 2001 Owen Taylor <otaylor@redhat.com>
+
+ * Released 1.2.10
+
+ * NEWS: Update
+
+ * configure.in: Up micro/interface-age/binary-age to 10.
+
2001-03-08 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in (FLAG_DOES_NOT_WORK): Fix typo and thus bug #51862.
diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4
index f705a3b4b..12b344e3e 100644
--- a/ChangeLog.pre-2-4
+++ b/ChangeLog.pre-2-4
@@ -1,3 +1,11 @@
+Thu Mar 15 10:37:49 2001 Owen Taylor <otaylor@redhat.com>
+
+ * Released 1.2.10
+
+ * NEWS: Update
+
+ * configure.in: Up micro/interface-age/binary-age to 10.
+
2001-03-08 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in (FLAG_DOES_NOT_WORK): Fix typo and thus bug #51862.
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index f705a3b4b..12b344e3e 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,3 +1,11 @@
+Thu Mar 15 10:37:49 2001 Owen Taylor <otaylor@redhat.com>
+
+ * Released 1.2.10
+
+ * NEWS: Update
+
+ * configure.in: Up micro/interface-age/binary-age to 10.
+
2001-03-08 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in (FLAG_DOES_NOT_WORK): Fix typo and thus bug #51862.
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index f705a3b4b..12b344e3e 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,3 +1,11 @@
+Thu Mar 15 10:37:49 2001 Owen Taylor <otaylor@redhat.com>
+
+ * Released 1.2.10
+
+ * NEWS: Update
+
+ * configure.in: Up micro/interface-age/binary-age to 10.
+
2001-03-08 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in (FLAG_DOES_NOT_WORK): Fix typo and thus bug #51862.
diff --git a/HACKING b/HACKING
index 0506b84e7..2a6825267 100644
--- a/HACKING
+++ b/HACKING
@@ -31,5 +31,3 @@ options like --prefix=/usr to configure you can give those options
to autogen.sh and they will be passed on to configure.
For information about submitting patches see the README file.
-
-
diff --git a/INSTALL b/INSTALL
index 884b26b4a..c396d40bb 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,8 +1,8 @@
Simple install procedure
========================
- % gzip -cd glib-1.2.9.tar.gz | tar xvf - # unpack the sources
- % cd glib-1.2.9 # change to the toplevel directory
+ % gzip -cd glib-1.2.10.tar.gz | tar xvf - # unpack the sources
+ % cd glib-1.2.10 # change to the toplevel directory
% ./configure # run the `configure' script
% make # build GLIB
diff --git a/NEWS b/NEWS
index ccb147018..0ab35d5ed 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+Overview of Changes in GLib 1.2.10:
+
+* Fix compilation problem on some compilers where
+ g_log_domain_gmodule was not being declared properly.
+
Overview of Changes in GLib 1.2.9:
* Move include files into a glib-1-2/ subdir to support parallel
diff --git a/README b/README
index 911623c11..39024d919 100644
--- a/README
+++ b/README
@@ -1,7 +1,7 @@
General Information
===================
-This is GLib version 1.2.9. GLib is a library which includes support
+This is GLib version 1.2.10. GLib is a library which includes support
routines for C such as lists, trees, hashes, memory allocation, and
many other things.
diff --git a/configure.in b/configure.in
index afe469a97..8ee9339dd 100644
--- a/configure.in
+++ b/configure.in
@@ -33,9 +33,9 @@ AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)dnl
#
GLIB_MAJOR_VERSION=1
GLIB_MINOR_VERSION=2
-GLIB_MICRO_VERSION=9
-GLIB_INTERFACE_AGE=9
-GLIB_BINARY_AGE=9
+GLIB_MICRO_VERSION=10
+GLIB_INTERFACE_AGE=10
+GLIB_BINARY_AGE=10
GLIB_VERSION=$GLIB_MAJOR_VERSION.$GLIB_MINOR_VERSION.$GLIB_MICRO_VERSION
dnl
AC_DIVERT_POP()dnl
diff --git a/glib/Makefile.am b/glib/Makefile.am
deleted file mode 100644
index 3a6e201f7..000000000
--- a/glib/Makefile.am
+++ /dev/null
@@ -1,130 +0,0 @@
-## Process this file with automake to produce Makefile.in
-
-# require automake 1.4
-AUTOMAKE_OPTIONS = 1.4
-
-SUBDIRS = . gmodule gthread docs tests
-
-configincludedir = $(pkglibdir)/include
-
-bin_SCRIPTS=glib-config
-BUILT_SOURCES=glib-config
-glib-config: glib-config.in
-
-INCLUDES = -DG_LOG_DOMAIN=g_log_domain_glib @GLIB_DEBUG_FLAGS@
-
-EXTRA_DIST = \
- glib.m4 \
- glib.spec.in \
- acglib.m4 \
- sanity_check \
- README.win32 \
- glib.def \
- makefile.msc.in \
- makefile.msc \
- giowin32.c \
- glibconfig.h.win32 \
- glibconfig.h.win32.in \
- config.h.win32 \
- config.h.win32.in \
- glib.pc.in \
- gmodule.pc.in \
- gthread.pc.in
-
-
-lib_LTLIBRARIES = libglib.la
-
-libglib_la_SOURCES = \
- garray.c \
- gcache.c \
- gcompletion.c \
- gdataset.c \
- gdate.c \
- gerror.c \
- ghash.c \
- ghook.c \
- giochannel.c \
- giounix.c \
- glist.c \
- gmain.c \
- gmem.c \
- gmessages.c \
- gmutex.c \
- gnode.c \
- gprimes.c \
- grel.c \
- gscanner.c \
- gslist.c \
- gstrfuncs.c \
- gstring.c \
- gtimer.c \
- gtree.c \
- gutils.c
-
-glibincludedir=$(includedir)/glib-1.2
-glibinclude_HEADERS = \
- glib.h
-
-configinclude_DATA = \
- glibconfig.h
-
-CONFIGURE_DEPENDENCIES = acglib.m4
-
-BUILT_SOURCES = stamp-gc-h #note: not glibconfig.h
-glibconfig.h: stamp-gc-h
- @:
-stamp-gc-h: config.status
- CONFIG_FILES= CONFIG_HEADERS= CONFIG_OTHER=glibconfig.h ./config.status
- echo timestamp > stamp-gc-h
-
-libglib_la_LDFLAGS = \
- -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
- -release $(LT_RELEASE) \
- -export-dynamic
-
-noinst_PROGRAMS = testglib testgdate testgdateparser
-testglib_LDADD = libglib.la
-testgdate_LDADD = libglib.la
-testgdateparser_LDADD = libglib.la
-
-m4datadir = $(datadir)/aclocal
-m4data_DATA = glib.m4
-
-pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = glib.pc gmodule.pc gthread.pc
-
-glibconfig.h.win32: $(top_builddir)/config.status $(top_srcdir)/glibconfig.h.win32.in
- cd $(top_builddir) && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status
-
-config.h.win32: $(top_builddir)/config.status $(top_srcdir)/config.h.win32.in
- cd $(top_builddir) && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status
-
-makefile.msc: $(top_builddir)/config.status $(top_srcdir)/makefile.msc.in
- cd $(top_builddir) && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status
-
-.PHONY: files release sanity snapshot
-
-files:
- @files=`ls $(DISTFILES) 2> /dev/null `; for p in $$files; do \
- echo $$p; \
- done
-
-release:
- rm -rf .deps */.deps
- cd docs && make glib.html
- $(MAKE) distcheck
-
-sanity:
- ./sanity_check $(VERSION)
-
-snapshot:
- $(MAKE) dist distdir=$(PACKAGE)`date +"%y%m%d"`
-
-dist-hook: glib.spec
- if test -e $(srcdir)/INSTALL.in && test -e $(srcdir)/README.in ; then \
- CONFIG_FILES="INSTALL:$(srcdir)/INSTALL.in README:$(srcdir)/README.in" \
- CONFIG_HEADERS= \
- $(SHELL) config.status \
- && cp INSTALL README $(distdir) ; \
- fi \
- && cp glib.spec $(distdir)
diff --git a/glib/garray.c b/glib/garray.c
deleted file mode 100644
index d018ec7c1..000000000
--- a/glib/garray.c
+++ /dev/null
@@ -1,490 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include <string.h>
-#include "glib.h"
-
-
-#define MIN_ARRAY_SIZE 16
-
-
-typedef struct _GRealArray GRealArray;
-
-struct _GRealArray
-{
- guint8 *data;
- guint len;
- guint alloc;
- guint elt_size;
- guint zero_terminated : 1;
- guint clear : 1;
-};
-
-
-static gint g_nearest_pow (gint num);
-static void g_array_maybe_expand (GRealArray *array,
- gint len);
-
-static GMemChunk *array_mem_chunk = NULL;
-G_LOCK_DEFINE_STATIC (array_mem_chunk);
-
-GArray*
-g_array_new (gboolean zero_terminated,
- gboolean clear,
- guint elt_size)
-{
- GRealArray *array;
-
- G_LOCK (array_mem_chunk);
- if (!array_mem_chunk)
- array_mem_chunk = g_mem_chunk_new ("array mem chunk",
- sizeof (GRealArray),
- 1024, G_ALLOC_AND_FREE);
-
- array = g_chunk_new (GRealArray, array_mem_chunk);
- G_UNLOCK (array_mem_chunk);
-
- array->data = NULL;
- array->len = 0;
- array->alloc = 0;
- array->zero_terminated = (zero_terminated ? 1 : 0);
- array->clear = (clear ? 1 : 0);
- array->elt_size = elt_size;
-
- return (GArray*) array;
-}
-
-void
-g_array_free (GArray *array,
- gboolean free_segment)
-{
- if (free_segment)
- g_free (array->data);
-
- G_LOCK (array_mem_chunk);
- g_mem_chunk_free (array_mem_chunk, array);
- G_UNLOCK (array_mem_chunk);
-}
-
-GArray*
-g_array_append_vals (GArray *farray,
- gconstpointer data,
- guint len)
-{
- GRealArray *array = (GRealArray*) farray;
-
- g_array_maybe_expand (array, len);
-
- memcpy (array->data + array->elt_size * array->len, data, array->elt_size * len);
-
- array->len += len;
-
- return farray;
-}
-
-GArray*
-g_array_prepend_vals (GArray *farray,
- gconstpointer data,
- guint len)
-{
- GRealArray *array = (GRealArray*) farray;
-
- g_array_maybe_expand (array, len);
-
- g_memmove (array->data + array->elt_size * len, array->data, array->elt_size * array->len);
-
- memcpy (array->data, data, len * array->elt_size);
-
- array->len += len;
-
- return farray;
-}
-
-GArray*
-g_array_insert_vals (GArray *farray,
- guint index,
- gconstpointer data,
- guint len)
-{
- GRealArray *array = (GRealArray*) farray;
-
- g_array_maybe_expand (array, len);
-
- g_memmove (array->data + array->elt_size * (len + index),
- array->data + array->elt_size * index,
- array->elt_size * (array->len - index));
-
- memcpy (array->data + array->elt_size * index, data, len * array->elt_size);
-
- array->len += len;
-
- return farray;
-}
-
-GArray*
-g_array_set_size (GArray *farray,
- guint length)
-{
- GRealArray *array = (GRealArray*) farray;
-
- if (array->len < length)
- g_array_maybe_expand (array, length - array->len);
-
- array->len = length;
-
- return farray;
-}
-
-GArray*
-g_array_remove_index (GArray* farray,
- guint index)
-{
- GRealArray* array = (GRealArray*) farray;
-
- g_return_val_if_fail (array, NULL);
-
- g_return_val_if_fail (index < array->len, NULL);
-
- if (index != array->len - 1)
- g_memmove (array->data + array->elt_size * index,
- array->data + array->elt_size * (index + 1),
- array->elt_size * (array->len - index - 1));
-
- if (array->zero_terminated)
- memset (array->data + array->elt_size * (array->len - 1), 0,
- array->elt_size);
-
- array->len -= 1;
-
- return farray;
-}
-
-GArray*
-g_array_remove_index_fast (GArray* farray,
- guint index)
-{
- GRealArray* array = (GRealArray*) farray;
-
- g_return_val_if_fail (array, NULL);
-
- g_return_val_if_fail (index < array->len, NULL);
-
- if (index != array->len - 1)
- g_memmove (array->data + array->elt_size * index,
- array->data + array->elt_size * (array->len - 1),
- array->elt_size);
-
- if (array->zero_terminated)
- memset (array->data + array->elt_size * (array->len - 1), 0,
- array->elt_size);
-
- array->len -= 1;
-
- return farray;
-}
-
-static gint
-g_nearest_pow (gint num)
-{
- gint n = 1;
-
- while (n < num)
- n <<= 1;
-
- return n;
-}
-
-static void
-g_array_maybe_expand (GRealArray *array,
- gint len)
-{
- guint want_alloc = (array->len + len + array->zero_terminated) * array->elt_size;
-
- if (want_alloc > array->alloc)
- {
- guint old_alloc = array->alloc;
-
- array->alloc = g_nearest_pow (want_alloc);
- array->alloc = MAX (array->alloc, MIN_ARRAY_SIZE);
-
- array->data = g_realloc (array->data, array->alloc);
-
- if (array->clear || array->zero_terminated)
- memset (array->data + old_alloc, 0, array->alloc - old_alloc);
- }
-}
-
-/* Pointer Array
- */
-
-typedef struct _GRealPtrArray GRealPtrArray;
-
-struct _GRealPtrArray
-{
- gpointer *pdata;
- guint len;
- guint alloc;
-};
-
-static void g_ptr_array_maybe_expand (GRealPtrArray *array,
- gint len);
-
-static GMemChunk *ptr_array_mem_chunk = NULL;
-G_LOCK_DEFINE_STATIC (ptr_array_mem_chunk);
-
-
-GPtrArray*
-g_ptr_array_new (void)
-{
- GRealPtrArray *array;
-
- G_LOCK (ptr_array_mem_chunk);
- if (!ptr_array_mem_chunk)
- ptr_array_mem_chunk = g_mem_chunk_new ("array mem chunk",
- sizeof (GRealPtrArray),
- 1024, G_ALLOC_AND_FREE);
-
- array = g_chunk_new (GRealPtrArray, ptr_array_mem_chunk);
- G_UNLOCK (ptr_array_mem_chunk);
-
- array->pdata = NULL;
- array->len = 0;
- array->alloc = 0;
-
- return (GPtrArray*) array;
-}
-
-void
-g_ptr_array_free (GPtrArray *array,
- gboolean free_segment)
-{
- g_return_if_fail (array);
-
- if (free_segment)
- g_free (array->pdata);
-
- G_LOCK (ptr_array_mem_chunk);
- g_mem_chunk_free (ptr_array_mem_chunk, array);
- G_UNLOCK (ptr_array_mem_chunk);
-}
-
-static void
-g_ptr_array_maybe_expand (GRealPtrArray *array,
- gint len)
-{
- guint old_alloc;
-
- if ((array->len + len) > array->alloc)
- {
- old_alloc = array->alloc;
-
- array->alloc = g_nearest_pow (array->len + len);
- array->alloc = MAX (array->alloc, MIN_ARRAY_SIZE);
- if (array->pdata)
- array->pdata = g_realloc (array->pdata, sizeof(gpointer) * array->alloc);
- else
- array->pdata = g_new0 (gpointer, array->alloc);
-
- memset (array->pdata + old_alloc, 0,
- sizeof (gpointer) * (array->alloc - old_alloc));
- }
-}
-
-void
-g_ptr_array_set_size (GPtrArray *farray,
- gint length)
-{
- GRealPtrArray* array = (GRealPtrArray*) farray;
-
- g_return_if_fail (array);
-
- if (length > array->len)
- g_ptr_array_maybe_expand (array, (length - array->len));
-
- array->len = length;
-}
-
-gpointer
-g_ptr_array_remove_index (GPtrArray* farray,
- guint index)
-{
- GRealPtrArray* array = (GRealPtrArray*) farray;
- gpointer result;
-
- g_return_val_if_fail (array, NULL);
-
- g_return_val_if_fail (index < array->len, NULL);
-
- result = array->pdata[index];
-
- if (index != array->len - 1)
- g_memmove (array->pdata + index, array->pdata + index + 1,
- sizeof (gpointer) * (array->len - index - 1));
-
- array->pdata[array->len - 1] = NULL;
-
- array->len -= 1;
-
- return result;
-}
-
-gpointer
-g_ptr_array_remove_index_fast (GPtrArray* farray,
- guint index)
-{
- GRealPtrArray* array = (GRealPtrArray*) farray;
- gpointer result;
-
- g_return_val_if_fail (array, NULL);
-
- g_return_val_if_fail (index < array->len, NULL);
-
- result = array->pdata[index];
-
- if (index != array->len - 1)
- array->pdata[index] = array->pdata[array->len - 1];
-
- array->pdata[array->len - 1] = NULL;
-
- array->len -= 1;
-
- return result;
-}
-
-gboolean
-g_ptr_array_remove (GPtrArray* farray,
- gpointer data)
-{
- GRealPtrArray* array = (GRealPtrArray*) farray;
- int i;
-
- g_return_val_if_fail (array, FALSE);
-
- for (i = 0; i < array->len; i += 1)
- {
- if (array->pdata[i] == data)
- {
- g_ptr_array_remove_index (farray, i);
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-gboolean
-g_ptr_array_remove_fast (GPtrArray* farray,
- gpointer data)
-{
- GRealPtrArray* array = (GRealPtrArray*) farray;
- int i;
-
- g_return_val_if_fail (array, FALSE);
-
- for (i = 0; i < array->len; i += 1)
- {
- if (array->pdata[i] == data)
- {
- g_ptr_array_remove_index_fast (farray, i);
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-void
-g_ptr_array_add (GPtrArray* farray,
- gpointer data)
-{
- GRealPtrArray* array = (GRealPtrArray*) farray;
-
- g_return_if_fail (array);
-
- g_ptr_array_maybe_expand (array, 1);
-
- array->pdata[array->len++] = data;
-}
-
-/* Byte arrays
- */
-
-GByteArray* g_byte_array_new (void)
-{
- return (GByteArray*) g_array_new (FALSE, FALSE, 1);
-}
-
-void g_byte_array_free (GByteArray *array,
- gboolean free_segment)
-{
- g_array_free ((GArray*) array, free_segment);
-}
-
-GByteArray* g_byte_array_append (GByteArray *array,
- const guint8 *data,
- guint len)
-{
- g_array_append_vals ((GArray*) array, (guint8*)data, len);
-
- return array;
-}
-
-GByteArray* g_byte_array_prepend (GByteArray *array,
- const guint8 *data,
- guint len)
-{
- g_array_prepend_vals ((GArray*) array, (guint8*)data, len);
-
- return array;
-}
-
-GByteArray* g_byte_array_set_size (GByteArray *array,
- guint length)
-{
- g_array_set_size ((GArray*) array, length);
-
- return array;
-}
-
-GByteArray* g_byte_array_remove_index (GByteArray *array,
- guint index)
-{
- g_array_remove_index((GArray*) array, index);
-
- return array;
-}
-
-GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
- guint index)
-{
- g_array_remove_index_fast((GArray*) array, index);
-
- return array;
-}
diff --git a/glib/gcache.c b/glib/gcache.c
deleted file mode 100644
index bba791024..000000000
--- a/glib/gcache.c
+++ /dev/null
@@ -1,230 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "glib.h"
-
-
-typedef struct _GCacheNode GCacheNode;
-typedef struct _GRealCache GRealCache;
-
-struct _GCacheNode
-{
- /* A reference counted node */
- gpointer value;
- gint ref_count;
-};
-
-struct _GRealCache
-{
- /* Called to create a value from a key */
- GCacheNewFunc value_new_func;
-
- /* Called to destroy a value */
- GCacheDestroyFunc value_destroy_func;
-
- /* Called to duplicate a key */
- GCacheDupFunc key_dup_func;
-
- /* Called to destroy a key */
- GCacheDestroyFunc key_destroy_func;
-
- /* Associates keys with nodes */
- GHashTable *key_table;
-
- /* Associates nodes with keys */
- GHashTable *value_table;
-};
-
-
-static GCacheNode* g_cache_node_new (gpointer value);
-static void g_cache_node_destroy (GCacheNode *node);
-
-
-static GMemChunk *node_mem_chunk = NULL;
-G_LOCK_DEFINE_STATIC (node_mem_chunk);
-
-GCache*
-g_cache_new (GCacheNewFunc value_new_func,
- GCacheDestroyFunc value_destroy_func,
- GCacheDupFunc key_dup_func,
- GCacheDestroyFunc key_destroy_func,
- GHashFunc hash_key_func,
- GHashFunc hash_value_func,
- GCompareFunc key_compare_func)
-{
- GRealCache *cache;
-
- g_return_val_if_fail (value_new_func != NULL, NULL);
- g_return_val_if_fail (value_destroy_func != NULL, NULL);
- g_return_val_if_fail (key_dup_func != NULL, NULL);
- g_return_val_if_fail (key_destroy_func != NULL, NULL);
- g_return_val_if_fail (hash_key_func != NULL, NULL);
- g_return_val_if_fail (hash_value_func != NULL, NULL);
- g_return_val_if_fail (key_compare_func != NULL, NULL);
-
- cache = g_new (GRealCache, 1);
- cache->value_new_func = value_new_func;
- cache->value_destroy_func = value_destroy_func;
- cache->key_dup_func = key_dup_func;
- cache->key_destroy_func = key_destroy_func;
- cache->key_table = g_hash_table_new (hash_key_func, key_compare_func);
- cache->value_table = g_hash_table_new (hash_value_func, NULL);
-
- return (GCache*) cache;
-}
-
-void
-g_cache_destroy (GCache *cache)
-{
- GRealCache *rcache;
-
- g_return_if_fail (cache != NULL);
-
- rcache = (GRealCache*) cache;
- g_hash_table_destroy (rcache->key_table);
- g_hash_table_destroy (rcache->value_table);
- g_free (rcache);
-}
-
-gpointer
-g_cache_insert (GCache *cache,
- gpointer key)
-{
- GRealCache *rcache;
- GCacheNode *node;
- gpointer value;
-
- g_return_val_if_fail (cache != NULL, NULL);
-
- rcache = (GRealCache*) cache;
-
- node = g_hash_table_lookup (rcache->key_table, key);
- if (node)
- {
- node->ref_count += 1;
- return node->value;
- }
-
- key = (* rcache->key_dup_func) (key);
- value = (* rcache->value_new_func) (key);
- node = g_cache_node_new (value);
-
- g_hash_table_insert (rcache->key_table, key, node);
- g_hash_table_insert (rcache->value_table, value, key);
-
- return node->value;
-}
-
-void
-g_cache_remove (GCache *cache,
- gpointer value)
-{
- GRealCache *rcache;
- GCacheNode *node;
- gpointer key;
-
- g_return_if_fail (cache != NULL);
-
- rcache = (GRealCache*) cache;
-
- key = g_hash_table_lookup (rcache->value_table, value);
- node = g_hash_table_lookup (rcache->key_table, key);
-
- g_return_if_fail (node != NULL);
-
- node->ref_count -= 1;
- if (node->ref_count == 0)
- {
- g_hash_table_remove (rcache->value_table, value);
- g_hash_table_remove (rcache->key_table, key);
-
- (* rcache->key_destroy_func) (key);
- (* rcache->value_destroy_func) (node->value);
- g_cache_node_destroy (node);
- }
-}
-
-void
-g_cache_key_foreach (GCache *cache,
- GHFunc func,
- gpointer user_data)
-{
- GRealCache *rcache;
-
- g_return_if_fail (cache != NULL);
- g_return_if_fail (func != NULL);
-
- rcache = (GRealCache*) cache;
-
- g_hash_table_foreach (rcache->value_table, func, user_data);
-}
-
-void
-g_cache_value_foreach (GCache *cache,
- GHFunc func,
- gpointer user_data)
-{
- GRealCache *rcache;
-
- g_return_if_fail (cache != NULL);
- g_return_if_fail (func != NULL);
-
- rcache = (GRealCache*) cache;
-
- g_hash_table_foreach (rcache->key_table, func, user_data);
-}
-
-
-static GCacheNode*
-g_cache_node_new (gpointer value)
-{
- GCacheNode *node;
-
- G_LOCK (node_mem_chunk);
- if (!node_mem_chunk)
- node_mem_chunk = g_mem_chunk_new ("cache node mem chunk", sizeof (GCacheNode),
- 1024, G_ALLOC_AND_FREE);
-
- node = g_chunk_new (GCacheNode, node_mem_chunk);
- G_UNLOCK (node_mem_chunk);
-
- node->value = value;
- node->ref_count = 1;
-
- return node;
-}
-
-static void
-g_cache_node_destroy (GCacheNode *node)
-{
- G_LOCK (node_mem_chunk);
- g_mem_chunk_free (node_mem_chunk, node);
- G_UNLOCK (node_mem_chunk);
-}
diff --git a/glib/gcompletion.c b/glib/gcompletion.c
deleted file mode 100644
index 9bc4c9b50..000000000
--- a/glib/gcompletion.c
+++ /dev/null
@@ -1,288 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "glib.h"
-#include <string.h>
-
-static void completion_check_cache (GCompletion* cmp,
- gchar** new_prefix);
-
-GCompletion*
-g_completion_new (GCompletionFunc func)
-{
- GCompletion* gcomp;
-
- gcomp = g_new (GCompletion, 1);
- gcomp->items = NULL;
- gcomp->cache = NULL;
- gcomp->prefix = NULL;
- gcomp->func = func;
-
- return gcomp;
-}
-
-void
-g_completion_add_items (GCompletion* cmp,
- GList* items)
-{
- GList* it;
-
- g_return_if_fail (cmp != NULL);
- g_return_if_fail (items != NULL);
-
- /* optimize adding to cache? */
- if (cmp->cache)
- {
- g_list_free (cmp->cache);
- cmp->cache = NULL;
- }
-
- if (cmp->prefix)
- {
- g_free (cmp->prefix);
- cmp->prefix = NULL;
- }
-
- it = items;
- while (it)
- {
- cmp->items = g_list_prepend (cmp->items, it->data);
- it = it->next;
- }
-}
-
-void
-g_completion_remove_items (GCompletion* cmp,
- GList* items)
-{
- GList* it;
-
- g_return_if_fail (cmp != NULL);
- g_return_if_fail (items != NULL);
-
- it = items;
- while (cmp->items && it)
- {
- cmp->items = g_list_remove (cmp->items, it->data);
- it = it->next;
- }
-
- it = items;
- while (cmp->cache && it)
- {
- cmp->cache = g_list_remove(cmp->cache, it->data);
- it = it->next;
- }
-}
-
-void
-g_completion_clear_items (GCompletion* cmp)
-{
- g_return_if_fail (cmp != NULL);
-
- g_list_free (cmp->items);
- cmp->items = NULL;
- g_list_free (cmp->cache);
- cmp->cache = NULL;
- g_free (cmp->prefix);
- cmp->prefix = NULL;
-}
-
-static void
-completion_check_cache (GCompletion* cmp,
- gchar** new_prefix)
-{
- register GList* list;
- register gint len;
- register gint i;
- register gint plen;
- gchar* postfix;
- gchar* s;
-
- if (!new_prefix)
- return;
- if (!cmp->cache)
- {
- *new_prefix = NULL;
- return;
- }
-
- len = strlen(cmp->prefix);
- list = cmp->cache;
- s = cmp->func ? cmp->func (list->data) : (gchar*) list->data;
- postfix = s + len;
- plen = strlen (postfix);
- list = list->next;
-
- while (list && plen)
- {
- s = cmp->func ? cmp->func (list->data) : (gchar*) list->data;
- s += len;
- for (i = 0; i < plen; ++i)
- {
- if (postfix[i] != s[i])
- break;
- }
- plen = i;
- list = list->next;
- }
-
- *new_prefix = g_new0 (gchar, len + plen + 1);
- strncpy (*new_prefix, cmp->prefix, len);
- strncpy (*new_prefix + len, postfix, plen);
-}
-
-GList*
-g_completion_complete (GCompletion* cmp,
- gchar* prefix,
- gchar** new_prefix)
-{
- gint plen, len;
- gint done = 0;
- GList* list;
-
- g_return_val_if_fail (cmp != NULL, NULL);
- g_return_val_if_fail (prefix != NULL, NULL);
-
- len = strlen (prefix);
- if (cmp->prefix && cmp->cache)
- {
- plen = strlen (cmp->prefix);
- if (plen <= len && !strncmp (prefix, cmp->prefix, plen))
- {
- /* use the cache */
- list = cmp->cache;
- while (list)
- {
- if (strncmp (prefix,
- cmp->func ? cmp->func (list->data) : (gchar*) list->data,
- len))
- {
- list = g_list_remove_link (cmp->cache, list);
- if (list != cmp->cache)
- cmp->cache = list;
- }
- else
- list = list->next;
- }
- done = 1;
- }
- }
-
- if (!done)
- {
- /* normal code */
- g_list_free (cmp->cache);
- cmp->cache = NULL;
- list = cmp->items;
- while (*prefix && list)
- {
- if (!strncmp (prefix,
- cmp->func ? cmp->func (list->data) : (gchar*) list->data,
- len))
- cmp->cache = g_list_prepend (cmp->cache, list->data);
- list = list->next;
- }
- }
- if (cmp->prefix)
- {
- g_free (cmp->prefix);
- cmp->prefix = NULL;
- }
- if (cmp->cache)
- cmp->prefix = g_strdup (prefix);
- completion_check_cache (cmp, new_prefix);
-
- return *prefix ? cmp->cache : cmp->items;
-}
-
-void
-g_completion_free (GCompletion* cmp)
-{
- g_return_if_fail (cmp != NULL);
-
- g_completion_clear_items (cmp);
- g_free (cmp);
-}
-
-#ifdef TEST_COMPLETION
-#include <stdio.h>
-int
-main (int argc,
- char* argv[])
-{
- FILE *file;
- gchar buf[1024];
- GList *list;
- GList *result;
- GList *tmp;
- GCompletion *cmp;
- gint i;
- gchar *longp = NULL;
-
- if (argc < 3)
- {
- g_warning ("Usage: %s filename prefix1 [prefix2 ...]\n", argv[0]);
- return 1;
- }
-
- file = fopen (argv[1], "r");
- if (!file)
- {
- g_warning ("Cannot open %s\n", argv[1]);
- return 1;
- }
-
- cmp = g_completion_new (NULL);
- list = g_list_alloc ();
- while (fgets (buf, 1024, file))
- {
- list->data = g_strdup (buf);
- g_completion_add_items (cmp, list);
- }
- fclose (file);
-
- for (i = 2; i < argc; ++i)
- {
- printf ("COMPLETING: %s\n", argv[i]);
- result = g_completion_complete (cmp, argv[i], &longp);
- g_list_foreach (result, (GFunc) printf, NULL);
- printf ("LONG MATCH: %s\n", longp);
- g_free (longp);
- longp = NULL;
- }
-
- g_list_foreach (cmp->items, (GFunc) g_free, NULL);
- g_completion_free (cmp);
- g_list_free (list);
-
- return 0;
-}
-#endif
diff --git a/glib/gdataset.c b/glib/gdataset.c
deleted file mode 100644
index 2aa4032ab..000000000
--- a/glib/gdataset.c
+++ /dev/null
@@ -1,611 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * gdataset.c: Generic dataset mechanism, similar to GtkObject data.
- * Copyright (C) 1998 Tim Janik
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe ; FIXME: might still freeze, watch out, not thoroughly
- * looked at yet.
- */
-
-#include <string.h>
-#include "glib.h"
-
-
-
-/* --- defines --- */
-#define G_QUARK_BLOCK_SIZE (512)
-#define G_DATA_MEM_CHUNK_PREALLOC (128)
-#define G_DATA_CACHE_MAX (512)
-#define G_DATASET_MEM_CHUNK_PREALLOC (32)
-
-
-/* --- structures --- */
-typedef struct _GDataset GDataset;
-struct _GData
-{
- GData *next;
- GQuark id;
- gpointer data;
- GDestroyNotify destroy_func;
-};
-
-struct _GDataset
-{
- gconstpointer location;
- GData *datalist;
-};
-
-
-/* --- prototypes --- */
-static inline GDataset* g_dataset_lookup (gconstpointer dataset_location);
-static inline void g_datalist_clear_i (GData **datalist);
-static void g_dataset_destroy_internal (GDataset *dataset);
-static inline void g_data_set_internal (GData **datalist,
- GQuark key_id,
- gpointer data,
- GDestroyNotify destroy_func,
- GDataset *dataset);
-static void g_data_initialize (void);
-static inline GQuark g_quark_new (gchar *string);
-
-
-/* --- variables --- */
-G_LOCK_DEFINE_STATIC (g_dataset_global);
-static GHashTable *g_dataset_location_ht = NULL;
-static GDataset *g_dataset_cached = NULL; /* should this be
- threadspecific? */
-static GMemChunk *g_dataset_mem_chunk = NULL;
-static GMemChunk *g_data_mem_chunk = NULL;
-static GData *g_data_cache = NULL;
-static guint g_data_cache_length = 0;
-
-G_LOCK_DEFINE_STATIC (g_quark_global);
-static GHashTable *g_quark_ht = NULL;
-static gchar **g_quarks = NULL;
-static GQuark g_quark_seq_id = 0;
-
-
-/* --- functions --- */
-
-/* HOLDS: g_dataset_global_lock */
-static inline void
-g_datalist_clear_i (GData **datalist)
-{
- register GData *list;
-
- /* unlink *all* items before walking their destructors
- */
- list = *datalist;
- *datalist = NULL;
-
- while (list)
- {
- register GData *prev;
-
- prev = list;
- list = prev->next;
-
- if (prev->destroy_func)
- {
- G_UNLOCK (g_dataset_global);
- prev->destroy_func (prev->data);
- G_LOCK (g_dataset_global);
- }
-
- if (g_data_cache_length < G_DATA_CACHE_MAX)
- {
- prev->next = g_data_cache;
- g_data_cache = prev;
- g_data_cache_length++;
- }
- else
- g_mem_chunk_free (g_data_mem_chunk, prev);
- }
-}
-
-void
-g_datalist_clear (GData **datalist)
-{
- g_return_if_fail (datalist != NULL);
-
- G_LOCK (g_dataset_global);
- if (!g_dataset_location_ht)
- g_data_initialize ();
-
- while (*datalist)
- g_datalist_clear_i (datalist);
- G_UNLOCK (g_dataset_global);
-}
-
-/* HOLDS: g_dataset_global_lock */
-static inline GDataset*
-g_dataset_lookup (gconstpointer dataset_location)
-{
- register GDataset *dataset;
-
- if (g_dataset_cached && g_dataset_cached->location == dataset_location)
- return g_dataset_cached;
-
- dataset = g_hash_table_lookup (g_dataset_location_ht, dataset_location);
- if (dataset)
- g_dataset_cached = dataset;
-
- return dataset;
-}
-
-/* HOLDS: g_dataset_global_lock */
-static void
-g_dataset_destroy_internal (GDataset *dataset)
-{
- register gconstpointer dataset_location;
-
- dataset_location = dataset->location;
- while (dataset)
- {
- if (!dataset->datalist)
- {
- if (dataset == g_dataset_cached)
- g_dataset_cached = NULL;
- g_hash_table_remove (g_dataset_location_ht, dataset_location);
- g_mem_chunk_free (g_dataset_mem_chunk, dataset);
- break;
- }
-
- g_datalist_clear_i (&dataset->datalist);
- dataset = g_dataset_lookup (dataset_location);
- }
-}
-
-void
-g_dataset_destroy (gconstpointer dataset_location)
-{
- g_return_if_fail (dataset_location != NULL);
-
- G_LOCK (g_dataset_global);
- if (g_dataset_location_ht)
- {
- register GDataset *dataset;
-
- dataset = g_dataset_lookup (dataset_location);
- if (dataset)
- g_dataset_destroy_internal (dataset);
- }
- G_UNLOCK (g_dataset_global);
-}
-
-/* HOLDS: g_dataset_global_lock */
-static inline void
-g_data_set_internal (GData **datalist,
- GQuark key_id,
- gpointer data,
- GDestroyNotify destroy_func,
- GDataset *dataset)
-{
- register GData *list;
-
- list = *datalist;
- if (!data)
- {
- register GData *prev;
-
- prev = NULL;
- while (list)
- {
- if (list->id == key_id)
- {
- if (prev)
- prev->next = list->next;
- else
- {
- *datalist = list->next;
-
- /* the dataset destruction *must* be done
- * prior to invokation of the data destroy function
- */
- if (!*datalist && dataset)
- g_dataset_destroy_internal (dataset);
- }
-
- /* the GData struct *must* already be unlinked
- * when invoking the destroy function.
- * we use (data==NULL && destroy_func!=NULL) as
- * a special hint combination to "steal"
- * data without destroy notification
- */
- if (list->destroy_func && !destroy_func)
- {
- G_UNLOCK (g_dataset_global);
- list->destroy_func (list->data);
- G_LOCK (g_dataset_global);
- }
-
- if (g_data_cache_length < G_DATA_CACHE_MAX)
- {
- list->next = g_data_cache;
- g_data_cache = list;
- g_data_cache_length++;
- }
- else
- g_mem_chunk_free (g_data_mem_chunk, list);
-
- return;
- }
-
- prev = list;
- list = list->next;
- }
- }
- else
- {
- while (list)
- {
- if (list->id == key_id)
- {
- if (!list->destroy_func)
- {
- list->data = data;
- list->destroy_func = destroy_func;
- }
- else
- {
- register GDestroyNotify dfunc;
- register gpointer ddata;
-
- dfunc = list->destroy_func;
- ddata = list->data;
- list->data = data;
- list->destroy_func = destroy_func;
-
- /* we need to have updated all structures prior to
- * invokation of the destroy function
- */
- G_UNLOCK (g_dataset_global);
- dfunc (ddata);
- G_LOCK (g_dataset_global);
- }
-
- return;
- }
-
- list = list->next;
- }
-
- if (g_data_cache)
- {
- list = g_data_cache;
- g_data_cache = list->next;
- g_data_cache_length--;
- }
- else
- list = g_chunk_new (GData, g_data_mem_chunk);
- list->next = *datalist;
- list->id = key_id;
- list->data = data;
- list->destroy_func = destroy_func;
- *datalist = list;
- }
-}
-
-void
-g_dataset_id_set_data_full (gconstpointer dataset_location,
- GQuark key_id,
- gpointer data,
- GDestroyNotify destroy_func)
-{
- register GDataset *dataset;
-
- g_return_if_fail (dataset_location != NULL);
- if (!data)
- g_return_if_fail (destroy_func == NULL);
- if (!key_id)
- {
- if (data)
- g_return_if_fail (key_id > 0);
- else
- return;
- }
-
- G_LOCK (g_dataset_global);
- if (!g_dataset_location_ht)
- g_data_initialize ();
-
- dataset = g_dataset_lookup (dataset_location);
- if (!dataset)
- {
- dataset = g_chunk_new (GDataset, g_dataset_mem_chunk);
- dataset->location = dataset_location;
- g_datalist_init (&dataset->datalist);
- g_hash_table_insert (g_dataset_location_ht,
- (gpointer) dataset->location,
- dataset);
- }
-
- g_data_set_internal (&dataset->datalist, key_id, data, destroy_func, dataset);
- G_UNLOCK (g_dataset_global);
-}
-
-void
-g_datalist_id_set_data_full (GData **datalist,
- GQuark key_id,
- gpointer data,
- GDestroyNotify destroy_func)
-{
- g_return_if_fail (datalist != NULL);
- if (!data)
- g_return_if_fail (destroy_func == NULL);
- if (!key_id)
- {
- if (data)
- g_return_if_fail (key_id > 0);
- else
- return;
- }
-
- G_LOCK (g_dataset_global);
- if (!g_dataset_location_ht)
- g_data_initialize ();
-
- g_data_set_internal (datalist, key_id, data, destroy_func, NULL);
- G_UNLOCK (g_dataset_global);
-}
-
-void
-g_dataset_id_remove_no_notify (gconstpointer dataset_location,
- GQuark key_id)
-{
- g_return_if_fail (dataset_location != NULL);
-
- G_LOCK (g_dataset_global);
- if (key_id && g_dataset_location_ht)
- {
- GDataset *dataset;
-
- dataset = g_dataset_lookup (dataset_location);
- if (dataset)
- g_data_set_internal (&dataset->datalist, key_id, NULL, (GDestroyNotify) 42, dataset);
- }
- G_UNLOCK (g_dataset_global);
-}
-
-void
-g_datalist_id_remove_no_notify (GData **datalist,
- GQuark key_id)
-{
- g_return_if_fail (datalist != NULL);
-
- G_LOCK (g_dataset_global);
- if (key_id && g_dataset_location_ht)
- g_data_set_internal (datalist, key_id, NULL, (GDestroyNotify) 42, NULL);
- G_UNLOCK (g_dataset_global);
-}
-
-gpointer
-g_dataset_id_get_data (gconstpointer dataset_location,
- GQuark key_id)
-{
- g_return_val_if_fail (dataset_location != NULL, NULL);
-
- G_LOCK (g_dataset_global);
- if (key_id && g_dataset_location_ht)
- {
- register GDataset *dataset;
-
- dataset = g_dataset_lookup (dataset_location);
- if (dataset)
- {
- register GData *list;
-
- for (list = dataset->datalist; list; list = list->next)
- if (list->id == key_id)
- {
- G_UNLOCK (g_dataset_global);
- return list->data;
- }
- }
- }
- G_UNLOCK (g_dataset_global);
-
- return NULL;
-}
-
-gpointer
-g_datalist_id_get_data (GData **datalist,
- GQuark key_id)
-{
- g_return_val_if_fail (datalist != NULL, NULL);
-
- if (key_id)
- {
- register GData *list;
-
- for (list = *datalist; list; list = list->next)
- if (list->id == key_id)
- return list->data;
- }
-
- return NULL;
-}
-
-void
-g_dataset_foreach (gconstpointer dataset_location,
- GDataForeachFunc func,
- gpointer user_data)
-{
- register GDataset *dataset;
-
- g_return_if_fail (dataset_location != NULL);
- g_return_if_fail (func != NULL);
-
- G_LOCK (g_dataset_global);
- if (g_dataset_location_ht)
- {
- dataset = g_dataset_lookup (dataset_location);
- G_UNLOCK (g_dataset_global);
- if (dataset)
- {
- register GData *list;
-
- for (list = dataset->datalist; list; list = list->next)
- func (list->id, list->data, user_data);
- }
- }
- else
- {
- G_UNLOCK (g_dataset_global);
- }
-}
-
-void
-g_datalist_foreach (GData **datalist,
- GDataForeachFunc func,
- gpointer user_data)
-{
- register GData *list;
-
- g_return_if_fail (datalist != NULL);
- g_return_if_fail (func != NULL);
-
- for (list = *datalist; list; list = list->next)
- func (list->id, list->data, user_data);
-}
-
-void
-g_datalist_init (GData **datalist)
-{
- g_return_if_fail (datalist != NULL);
-
- *datalist = NULL;
-}
-
-/* HOLDS: g_dataset_global_lock */
-static void
-g_data_initialize (void)
-{
- g_return_if_fail (g_dataset_location_ht == NULL);
-
- g_dataset_location_ht = g_hash_table_new (g_direct_hash, NULL);
- g_dataset_cached = NULL;
- g_dataset_mem_chunk =
- g_mem_chunk_new ("GDataset MemChunk",
- sizeof (GDataset),
- sizeof (GDataset) * G_DATASET_MEM_CHUNK_PREALLOC,
- G_ALLOC_AND_FREE);
- g_data_mem_chunk =
- g_mem_chunk_new ("GData MemChunk",
- sizeof (GData),
- sizeof (GData) * G_DATA_MEM_CHUNK_PREALLOC,
- G_ALLOC_AND_FREE);
-}
-
-GQuark
-g_quark_try_string (const gchar *string)
-{
- GQuark quark = 0;
- g_return_val_if_fail (string != NULL, 0);
-
- G_LOCK (g_quark_global);
- if (g_quark_ht)
- quark = GPOINTER_TO_UINT (g_hash_table_lookup (g_quark_ht, string));
- G_UNLOCK (g_quark_global);
-
- return quark;
-}
-
-GQuark
-g_quark_from_string (const gchar *string)
-{
- GQuark quark;
-
- g_return_val_if_fail (string != NULL, 0);
-
- G_LOCK (g_quark_global);
- if (g_quark_ht)
- quark = (gulong) g_hash_table_lookup (g_quark_ht, string);
- else
- {
- g_quark_ht = g_hash_table_new (g_str_hash, g_str_equal);
- quark = 0;
- }
-
- if (!quark)
- quark = g_quark_new (g_strdup (string));
- G_UNLOCK (g_quark_global);
-
- return quark;
-}
-
-GQuark
-g_quark_from_static_string (const gchar *string)
-{
- GQuark quark;
-
- g_return_val_if_fail (string != NULL, 0);
-
- G_LOCK (g_quark_global);
- if (g_quark_ht)
- quark = (gulong) g_hash_table_lookup (g_quark_ht, string);
- else
- {
- g_quark_ht = g_hash_table_new (g_str_hash, g_str_equal);
- quark = 0;
- }
-
- if (!quark)
- quark = g_quark_new ((gchar*) string);
- G_UNLOCK (g_quark_global);
-
- return quark;
-}
-
-gchar*
-g_quark_to_string (GQuark quark)
-{
- gchar* result = NULL;
- G_LOCK (g_quark_global);
- if (quark > 0 && quark <= g_quark_seq_id)
- result = g_quarks[quark - 1];
- G_UNLOCK (g_quark_global);
-
- return result;
-}
-
-/* HOLDS: g_quark_global_lock */
-static inline GQuark
-g_quark_new (gchar *string)
-{
- GQuark quark;
-
- if (g_quark_seq_id % G_QUARK_BLOCK_SIZE == 0)
- g_quarks = g_renew (gchar*, g_quarks, g_quark_seq_id + G_QUARK_BLOCK_SIZE);
-
- g_quarks[g_quark_seq_id] = string;
- g_quark_seq_id++;
- quark = g_quark_seq_id;
- g_hash_table_insert (g_quark_ht, string, GUINT_TO_POINTER (quark));
-
- return quark;
-}
diff --git a/glib/gdate.c b/glib/gdate.c
deleted file mode 100644
index b278a5a4e..000000000
--- a/glib/gdate.c
+++ /dev/null
@@ -1,1294 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "glib.h"
-
-#include <time.h>
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <locale.h>
-
-GDate*
-g_date_new ()
-{
- GDate *d = g_new0 (GDate, 1); /* happily, 0 is the invalid flag for everything. */
-
- return d;
-}
-
-GDate*
-g_date_new_dmy (GDateDay day, GDateMonth m, GDateYear y)
-{
- GDate *d;
- g_return_val_if_fail (g_date_valid_dmy (day, m, y), NULL);
-
- d = g_new (GDate, 1);
-
- d->julian = FALSE;
- d->dmy = TRUE;
-
- d->month = m;
- d->day = day;
- d->year = y;
-
- g_assert (g_date_valid (d));
-
- return d;
-}
-
-GDate*
-g_date_new_julian (guint32 j)
-{
- GDate *d;
- g_return_val_if_fail (g_date_valid_julian (j), NULL);
-
- d = g_new (GDate, 1);
-
- d->julian = TRUE;
- d->dmy = FALSE;
-
- d->julian_days = j;
-
- g_assert (g_date_valid (d));
-
- return d;
-}
-
-void
-g_date_free (GDate *d)
-{
- g_return_if_fail (d != NULL);
-
- g_free (d);
-}
-
-gboolean
-g_date_valid (GDate *d)
-{
- g_return_val_if_fail (d != NULL, FALSE);
-
- return (d->julian || d->dmy);
-}
-
-static const guint8 days_in_months[2][13] =
-{ /* error, jan feb mar apr may jun jul aug sep oct nov dec */
- { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
- { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } /* leap year */
-};
-
-static const guint16 days_in_year[2][14] =
-{ /* 0, jan feb mar apr may jun jul aug sep oct nov dec */
- { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
- { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
-};
-
-gboolean
-g_date_valid_month (GDateMonth m)
-{
- return ( (m > G_DATE_BAD_MONTH) && (m < 13) );
-}
-
-gboolean
-g_date_valid_year (GDateYear y)
-{
- return ( y > G_DATE_BAD_YEAR );
-}
-
-gboolean
-g_date_valid_day (GDateDay d)
-{
- return ( (d > G_DATE_BAD_DAY) && (d < 32) );
-}
-
-gboolean
-g_date_valid_weekday (GDateWeekday w)
-{
- return ( (w > G_DATE_BAD_WEEKDAY) && (w < 8) );
-}
-
-gboolean
-g_date_valid_julian (guint32 j)
-{
- return (j > G_DATE_BAD_JULIAN);
-}
-
-gboolean
-g_date_valid_dmy (GDateDay d,
- GDateMonth m,
- GDateYear y)
-{
- return ( (m > G_DATE_BAD_MONTH) &&
- (m < 13) &&
- (d > G_DATE_BAD_DAY) &&
- (y > G_DATE_BAD_YEAR) && /* must check before using g_date_is_leap_year */
- (d <= (g_date_is_leap_year (y) ?
- days_in_months[1][m] : days_in_months[0][m])) );
-}
-
-
-/* "Julian days" just means an absolute number of days, where Day 1 ==
- * Jan 1, Year 1
- */
-static void
-g_date_update_julian (GDate *d)
-{
- GDateYear year;
- gint index;
-
- g_return_if_fail (d != NULL);
- g_return_if_fail (d->dmy);
- g_return_if_fail (!d->julian);
- g_return_if_fail (g_date_valid_dmy (d->day, d->month, d->year));
-
- /* What we actually do is: multiply years * 365 days in the year,
- * add the number of years divided by 4, subtract the number of
- * years divided by 100 and add the number of years divided by 400,
- * which accounts for leap year stuff. Code from Steffen Beyer's
- * DateCalc.
- */
-
- year = d->year - 1; /* we know d->year > 0 since it's valid */
-
- d->julian_days = year * 365U;
- d->julian_days += (year >>= 2); /* divide by 4 and add */
- d->julian_days -= (year /= 25); /* divides original # years by 100 */
- d->julian_days += year >> 2; /* divides by 4, which divides original by 400 */
-
- index = g_date_is_leap_year (d->year) ? 1 : 0;
-
- d->julian_days += days_in_year[index][d->month] + d->day;
-
- g_return_if_fail (g_date_valid_julian (d->julian_days));
-
- d->julian = TRUE;
-}
-
-static void
-g_date_update_dmy (GDate *d)
-{
- GDateYear y;
- GDateMonth m;
- GDateDay day;
-
- guint32 A, B, C, D, E, M;
-
- g_return_if_fail (d != NULL);
- g_return_if_fail (d->julian);
- g_return_if_fail (!d->dmy);
- g_return_if_fail (g_date_valid_julian (d->julian_days));
-
- /* Formula taken from the Calendar FAQ; the formula was for the
- * Julian Period which starts on 1 January 4713 BC, so we add
- * 1,721,425 to the number of days before doing the formula.
- *
- * I'm sure this can be simplified for our 1 January 1 AD period
- * start, but I can't figure out how to unpack the formula.
- */
-
- A = d->julian_days + 1721425 + 32045;
- B = ( 4 *(A + 36524) )/ 146097 - 1;
- C = A - (146097 * B)/4;
- D = ( 4 * (C + 365) ) / 1461 - 1;
- E = C - ((1461*D) / 4);
- M = (5 * (E - 1) + 2)/153;
-
- m = M + 3 - (12*(M/10));
- day = E - (153*M + 2)/5;
- y = 100 * B + D - 4800 + (M/10);
-
-#ifdef G_ENABLE_DEBUG
- if (!g_date_valid_dmy (day, m, y))
- {
- g_warning ("\nOOPS julian: %u computed dmy: %u %u %u\n",
- d->julian_days, day, m, y);
- }
-#endif
-
- d->month = m;
- d->day = day;
- d->year = y;
-
- d->dmy = TRUE;
-}
-
-GDateWeekday
-g_date_weekday (GDate *d)
-{
- g_return_val_if_fail (d != NULL, G_DATE_BAD_WEEKDAY);
- g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_WEEKDAY);
-
- if (!d->julian)
- {
- g_date_update_julian (d);
- }
- g_return_val_if_fail (d->julian, G_DATE_BAD_WEEKDAY);
-
- return ((d->julian_days - 1) % 7) + 1;
-}
-
-GDateMonth
-g_date_month (GDate *d)
-{
- g_return_val_if_fail (d != NULL, G_DATE_BAD_MONTH);
- g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_MONTH);
-
- if (!d->dmy)
- {
- g_date_update_dmy (d);
- }
- g_return_val_if_fail (d->dmy, G_DATE_BAD_MONTH);
-
- return d->month;
-}
-
-GDateYear
-g_date_year (GDate *d)
-{
- g_return_val_if_fail (d != NULL, G_DATE_BAD_YEAR);
- g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_YEAR);
-
- if (!d->dmy)
- {
- g_date_update_dmy (d);
- }
- g_return_val_if_fail (d->dmy, G_DATE_BAD_YEAR);
-
- return d->year;
-}
-
-GDateDay
-g_date_day (GDate *d)
-{
- g_return_val_if_fail (d != NULL, G_DATE_BAD_DAY);
- g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_DAY);
-
- if (!d->dmy)
- {
- g_date_update_dmy (d);
- }
- g_return_val_if_fail (d->dmy, G_DATE_BAD_DAY);
-
- return d->day;
-}
-
-guint32
-g_date_julian (GDate *d)
-{
- g_return_val_if_fail (d != NULL, G_DATE_BAD_JULIAN);
- g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_JULIAN);
-
- if (!d->julian)
- {
- g_date_update_julian (d);
- }
- g_return_val_if_fail (d->julian, G_DATE_BAD_JULIAN);
-
- return d->julian_days;
-}
-
-guint
-g_date_day_of_year (GDate *d)
-{
- gint index;
-
- g_return_val_if_fail (d != NULL, 0);
- g_return_val_if_fail (g_date_valid (d), 0);
-
- if (!d->dmy)
- {
- g_date_update_dmy (d);
- }
- g_return_val_if_fail (d->dmy, 0);
-
- index = g_date_is_leap_year (d->year) ? 1 : 0;
-
- return (days_in_year[index][d->month] + d->day);
-}
-
-guint
-g_date_monday_week_of_year (GDate *d)
-{
- GDateWeekday wd;
- guint day;
- GDate first;
-
- g_return_val_if_fail (d != NULL, 0);
- g_return_val_if_fail (g_date_valid (d), 0);
-
- if (!d->dmy)
- {
- g_date_update_dmy (d);
- }
- g_return_val_if_fail (d->dmy, 0);
-
- g_date_clear (&first, 1);
-
- g_date_set_dmy (&first, 1, 1, d->year);
-
- wd = g_date_weekday (&first) - 1; /* make Monday day 0 */
- day = g_date_day_of_year (d) - 1;
-
- return ((day + wd)/7U + (wd == 0 ? 1 : 0));
-}
-
-guint
-g_date_sunday_week_of_year (GDate *d)
-{
- GDateWeekday wd;
- guint day;
- GDate first;
-
- g_return_val_if_fail (d != NULL, 0);
- g_return_val_if_fail (g_date_valid (d), 0);
-
- if (!d->dmy)
- {
- g_date_update_dmy (d);
- }
- g_return_val_if_fail (d->dmy, 0);
-
- g_date_clear (&first, 1);
-
- g_date_set_dmy (&first, 1, 1, d->year);
-
- wd = g_date_weekday (&first);
- if (wd == 7) wd = 0; /* make Sunday day 0 */
- day = g_date_day_of_year (d) - 1;
-
- return ((day + wd)/7U + (wd == 0 ? 1 : 0));
-}
-
-void
-g_date_clear (GDate *d, guint ndates)
-{
- g_return_if_fail (d != NULL);
- g_return_if_fail (ndates != 0);
-
- memset (d, 0x0, ndates*sizeof (GDate));
-}
-
-G_LOCK_DEFINE_STATIC (g_date_global);
-
-/* These are for the parser, output to the user should use *
- * g_date_strftime () - this creates more never-freed memory to annoy
- * all those memory debugger users. :-)
- */
-
-static gchar *long_month_names[13] =
-{
- "Error", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
-};
-
-static gchar *short_month_names[13] =
-{
- "Error", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
-};
-
-/* This tells us if we need to update the parse info */
-static gchar *current_locale = NULL;
-
-/* order of these in the current locale */
-static GDateDMY dmy_order[3] =
-{
- G_DATE_DAY, G_DATE_MONTH, G_DATE_YEAR
-};
-
-/* Where to chop two-digit years: i.e., for the 1930 default, numbers
- * 29 and below are counted as in the year 2000, numbers 30 and above
- * are counted as in the year 1900.
- */
-
-static GDateYear twodigit_start_year = 1930;
-
-/* It is impossible to enter a year between 1 AD and 99 AD with this
- * in effect.
- */
-static gboolean using_twodigit_years = FALSE;
-
-struct _GDateParseTokens {
- gint num_ints;
- gint n[3];
- guint month;
-};
-
-typedef struct _GDateParseTokens GDateParseTokens;
-
-#define NUM_LEN 10
-
-/* HOLDS: g_date_global_lock */
-static void
-g_date_fill_parse_tokens (const gchar *str, GDateParseTokens *pt)
-{
- gchar num[4][NUM_LEN+1];
- gint i;
- const guchar *s;
-
- /* We count 4, but store 3; so we can give an error
- * if there are 4.
- */
- num[0][0] = num[1][0] = num[2][0] = num[3][0] = '\0';
-
- s = str;
- pt->num_ints = 0;
- while (*s && pt->num_ints < 4)
- {
-
- i = 0;
- while (*s && isdigit (*s) && i <= NUM_LEN)
- {
- num[pt->num_ints][i] = *s;
- ++s;
- ++i;
- }
-
- if (i > 0)
- {
- num[pt->num_ints][i] = '\0';
- ++(pt->num_ints);
- }
-
- if (*s == '\0') break;
-
- ++s;
- }
-
- pt->n[0] = pt->num_ints > 0 ? atoi (num[0]) : 0;
- pt->n[1] = pt->num_ints > 1 ? atoi (num[1]) : 0;
- pt->n[2] = pt->num_ints > 2 ? atoi (num[2]) : 0;
-
- pt->month = G_DATE_BAD_MONTH;
-
- if (pt->num_ints < 3)
- {
- gchar lcstr[128];
- int i = 1;
-
- strncpy (lcstr, str, 127);
- g_strdown (lcstr);
-
- while (i < 13)
- {
- if (long_month_names[i] != NULL)
- {
- const gchar *found = strstr (lcstr, long_month_names[i]);
-
- if (found != NULL)
- {
- pt->month = i;
- return;
- }
- }
-
- if (short_month_names[i] != NULL)
- {
- const gchar *found = strstr (lcstr, short_month_names[i]);
-
- if (found != NULL)
- {
- pt->month = i;
- return;
- }
- }
-
- ++i;
- }
- }
-}
-
-/* HOLDS: g_date_global_lock */
-static void
-g_date_prepare_to_parse (const gchar *str, GDateParseTokens *pt)
-{
- const gchar *locale = setlocale (LC_TIME, NULL);
- gboolean recompute_localeinfo = FALSE;
- GDate d;
-
- g_return_if_fail (locale != NULL); /* should not happen */
-
- g_date_clear (&d, 1); /* clear for scratch use */
-
- if ( (current_locale == NULL) || (strcmp (locale, current_locale) != 0) )
- {
- recompute_localeinfo = TRUE; /* Uh, there used to be a reason for the temporary */
- }
-
- if (recompute_localeinfo)
- {
- int i = 1;
- GDateParseTokens testpt;
- gchar buf[128];
-
- g_free (current_locale); /* still works if current_locale == NULL */
-
- current_locale = g_strdup (locale);
-
- while (i < 13)
- {
- g_date_set_dmy (&d, 1, i, 1);
-
- g_return_if_fail (g_date_valid (&d));
-
- g_date_strftime (buf, 127, "%b", &d);
- g_free (short_month_names[i]);
- g_strdown (buf);
- short_month_names[i] = g_strdup (buf);
-
-
-
- g_date_strftime (buf, 127, "%B", &d);
- g_free (long_month_names[i]);
- g_strdown (buf);
- long_month_names[i] = g_strdup (buf);
-
- ++i;
- }
-
- /* Determine DMY order */
-
- /* had to pick a random day - don't change this, some strftimes
- * are broken on some days, and this one is good so far. */
- g_date_set_dmy (&d, 4, 7, 1976);
-
- g_date_strftime (buf, 127, "%x", &d);
-
- g_date_fill_parse_tokens (buf, &testpt);
-
- i = 0;
- while (i < testpt.num_ints)
- {
- switch (testpt.n[i])
- {
- case 7:
- dmy_order[i] = G_DATE_MONTH;
- break;
- case 4:
- dmy_order[i] = G_DATE_DAY;
- break;
- case 76:
- using_twodigit_years = TRUE; /* FALL THRU */
- case 1976:
- dmy_order[i] = G_DATE_YEAR;
- break;
- default:
- /* leave it unchanged */
- break;
- }
- ++i;
- }
-
-#ifdef G_ENABLE_DEBUG
- g_message ("**GDate prepared a new set of locale-specific parse rules.");
- i = 1;
- while (i < 13)
- {
- g_message (" %s %s", long_month_names[i], short_month_names[i]);
- ++i;
- }
- if (using_twodigit_years)
- {
- g_message ("**Using twodigit years with cutoff year: %u", twodigit_start_year);
- }
- {
- gchar *strings[3];
- i = 0;
- while (i < 3)
- {
- switch (dmy_order[i])
- {
- case G_DATE_MONTH:
- strings[i] = "Month";
- break;
- case G_DATE_YEAR:
- strings[i] = "Year";
- break;
- case G_DATE_DAY:
- strings[i] = "Day";
- break;
- default:
- strings[i] = NULL;
- break;
- }
- ++i;
- }
- g_message ("**Order: %s, %s, %s", strings[0], strings[1], strings[2]);
- g_message ("**Sample date in this locale: `%s'", buf);
- }
-#endif
- }
-
- g_date_fill_parse_tokens (str, pt);
-}
-
-void
-g_date_set_parse (GDate *d,
- const gchar *str)
-{
- GDateParseTokens pt;
- guint m = G_DATE_BAD_MONTH, day = G_DATE_BAD_DAY, y = G_DATE_BAD_YEAR;
-
- g_return_if_fail (d != NULL);
-
- /* set invalid */
- g_date_clear (d, 1);
-
- G_LOCK (g_date_global);
-
- g_date_prepare_to_parse (str, &pt);
-
-#ifdef G_ENABLE_DEBUG
- g_message ("Found %d ints, `%d' `%d' `%d' and written out month %d",
- pt.num_ints, pt.n[0], pt.n[1], pt.n[2], pt.month);
-#endif
-
-
- if (pt.num_ints == 4)
- {
- G_UNLOCK (g_date_global);
- return; /* presumably a typo; bail out. */
- }
-
- if (pt.num_ints > 1)
- {
- int i = 0;
- int j = 0;
-
- g_assert (pt.num_ints < 4); /* i.e., it is 2 or 3 */
-
- while (i < pt.num_ints && j < 3)
- {
- switch (dmy_order[j])
- {
- case G_DATE_MONTH:
- {
- if (pt.num_ints == 2 && pt.month != G_DATE_BAD_MONTH)
- {
- m = pt.month;
- ++j; /* skip months, but don't skip this number */
- continue;
- }
- else
- m = pt.n[i];
- }
- break;
- case G_DATE_DAY:
- {
- if (pt.num_ints == 2 && pt.month == G_DATE_BAD_MONTH)
- {
- day = 1;
- ++j; /* skip days, since we may have month/year */
- continue;
- }
- day = pt.n[i];
- }
- break;
- case G_DATE_YEAR:
- {
- y = pt.n[i];
-
- if (using_twodigit_years && y < 100)
- {
- guint two = twodigit_start_year % 100;
- guint century = (twodigit_start_year / 100) * 100;
-
- if (y < two)
- century += 100;
-
- y += century;
- }
- }
- break;
- default:
- break;
- }
-
- ++i;
- ++j;
- }
-
-
- if (pt.num_ints == 3 && !g_date_valid_dmy (day, m, y))
- {
- /* Try YYYY MM DD */
- y = pt.n[0];
- m = pt.n[1];
- day = pt.n[2];
-
- if (using_twodigit_years && y < 100)
- y = G_DATE_BAD_YEAR; /* avoids ambiguity */
- }
- }
- else if (pt.num_ints == 1)
- {
- if (pt.month != G_DATE_BAD_MONTH)
- {
- /* Month name and year? */
- m = pt.month;
- day = 1;
- y = pt.n[0];
- }
- else
- {
- /* Try yyyymmdd and yymmdd */
-
- m = (pt.n[0]/100) % 100;
- day = pt.n[0] % 100;
- y = pt.n[0]/10000;
-
- /* FIXME move this into a separate function */
- if (using_twodigit_years && y < 100)
- {
- guint two = twodigit_start_year % 100;
- guint century = (twodigit_start_year / 100) * 100;
-
- if (y < two)
- century += 100;
-
- y += century;
- }
- }
- }
-
- /* See if we got anything valid out of all this. */
- /* y < 8000 is to catch 19998 style typos; the library is OK up to 65535 or so */
- if (y < 8000 && g_date_valid_dmy (day, m, y))
- {
- d->month = m;
- d->day = day;
- d->year = y;
- d->dmy = TRUE;
- }
-#ifdef G_ENABLE_DEBUG
- else
- g_message ("Rejected DMY %u %u %u", day, m, y);
-#endif
- G_UNLOCK (g_date_global);
-}
-
-void
-g_date_set_time (GDate *d,
- GTime time)
-{
- time_t t = time;
- struct tm tm;
-
- g_return_if_fail (d != NULL);
-
-#ifdef HAVE_LOCALTIME_R
- localtime_r (&t, &tm);
-#else
- {
- struct tm *ptm = localtime (&t);
- g_assert (ptm);
- memcpy ((void *) &tm, (void *) ptm, sizeof(struct tm));
- }
-#endif
-
- d->julian = FALSE;
-
- d->month = tm.tm_mon + 1;
- d->day = tm.tm_mday;
- d->year = tm.tm_year + 1900;
-
- g_return_if_fail (g_date_valid_dmy (d->day, d->month, d->year));
-
- d->dmy = TRUE;
-}
-
-void
-g_date_set_month (GDate *d,
- GDateMonth m)
-{
- g_return_if_fail (d != NULL);
- g_return_if_fail (g_date_valid_month (m));
-
- if (d->julian && !d->dmy) g_date_update_dmy(d);
- d->julian = FALSE;
-
- d->month = m;
-
- if (g_date_valid_dmy (d->day, d->month, d->year))
- d->dmy = TRUE;
- else
- d->dmy = FALSE;
-}
-
-void
-g_date_set_day (GDate *d,
- GDateDay day)
-{
- g_return_if_fail (d != NULL);
- g_return_if_fail (g_date_valid_day (day));
-
- if (d->julian && !d->dmy) g_date_update_dmy(d);
- d->julian = FALSE;
-
- d->day = day;
-
- if (g_date_valid_dmy (d->day, d->month, d->year))
- d->dmy = TRUE;
- else
- d->dmy = FALSE;
-}
-
-void
-g_date_set_year (GDate *d,
- GDateYear y)
-{
- g_return_if_fail (d != NULL);
- g_return_if_fail (g_date_valid_year (y));
-
- if (d->julian && !d->dmy) g_date_update_dmy(d);
- d->julian = FALSE;
-
- d->year = y;
-
- if (g_date_valid_dmy (d->day, d->month, d->year))
- d->dmy = TRUE;
- else
- d->dmy = FALSE;
-}
-
-void
-g_date_set_dmy (GDate *d,
- GDateDay day,
- GDateMonth m,
- GDateYear y)
-{
- g_return_if_fail (d != NULL);
- g_return_if_fail (g_date_valid_dmy (day, m, y));
-
- d->julian = FALSE;
-
- d->month = m;
- d->day = day;
- d->year = y;
-
- d->dmy = TRUE;
-}
-
-void
-g_date_set_julian (GDate *d, guint32 j)
-{
- g_return_if_fail (d != NULL);
- g_return_if_fail (g_date_valid_julian (j));
-
- d->julian_days = j;
- d->julian = TRUE;
- d->dmy = FALSE;
-}
-
-
-gboolean
-g_date_is_first_of_month (GDate *d)
-{
- g_return_val_if_fail (d != NULL, FALSE);
- g_return_val_if_fail (g_date_valid (d), FALSE);
-
- if (!d->dmy)
- {
- g_date_update_dmy (d);
- }
- g_return_val_if_fail (d->dmy, FALSE);
-
- if (d->day == 1) return TRUE;
- else return FALSE;
-}
-
-gboolean
-g_date_is_last_of_month (GDate *d)
-{
- gint index;
-
- g_return_val_if_fail (d != NULL, FALSE);
- g_return_val_if_fail (g_date_valid (d), FALSE);
-
- if (!d->dmy)
- {
- g_date_update_dmy (d);
- }
- g_return_val_if_fail (d->dmy, FALSE);
-
- index = g_date_is_leap_year (d->year) ? 1 : 0;
-
- if (d->day == days_in_months[index][d->month]) return TRUE;
- else return FALSE;
-}
-
-void
-g_date_add_days (GDate *d, guint ndays)
-{
- g_return_if_fail (d != NULL);
- g_return_if_fail (g_date_valid (d));
-
- if (!d->julian)
- {
- g_date_update_julian (d);
- }
- g_return_if_fail (d->julian);
-
- d->julian_days += ndays;
- d->dmy = FALSE;
-}
-
-void
-g_date_subtract_days (GDate *d, guint ndays)
-{
- g_return_if_fail (d != NULL);
- g_return_if_fail (g_date_valid (d));
-
- if (!d->julian)
- {
- g_date_update_julian (d);
- }
- g_return_if_fail (d->julian);
- g_return_if_fail (d->julian_days > ndays);
-
- d->julian_days -= ndays;
- d->dmy = FALSE;
-}
-
-void
-g_date_add_months (GDate *d,
- guint nmonths)
-{
- guint years, months;
- gint index;
-
- g_return_if_fail (d != NULL);
- g_return_if_fail (g_date_valid (d));
-
- if (!d->dmy)
- {
- g_date_update_dmy (d);
- }
- g_return_if_fail (d->dmy);
-
- nmonths += d->month - 1;
-
- years = nmonths/12;
- months = nmonths%12;
-
- d->month = months + 1;
- d->year += years;
-
- index = g_date_is_leap_year (d->year) ? 1 : 0;
-
- if (d->day > days_in_months[index][d->month])
- d->day = days_in_months[index][d->month];
-
- d->julian = FALSE;
-
- g_return_if_fail (g_date_valid (d));
-}
-
-void
-g_date_subtract_months (GDate *d,
- guint nmonths)
-{
- guint years, months;
- gint index;
-
- g_return_if_fail (d != NULL);
- g_return_if_fail (g_date_valid (d));
-
- if (!d->dmy)
- {
- g_date_update_dmy (d);
- }
- g_return_if_fail (d->dmy);
-
- years = nmonths/12;
- months = nmonths%12;
-
- g_return_if_fail (d->year > years);
-
- d->year -= years;
-
- if (d->month > months) d->month -= months;
- else
- {
- months -= d->month;
- d->month = 12 - months;
- d->year -= 1;
- }
-
- index = g_date_is_leap_year (d->year) ? 1 : 0;
-
- if (d->day > days_in_months[index][d->month])
- d->day = days_in_months[index][d->month];
-
- d->julian = FALSE;
-
- g_return_if_fail (g_date_valid (d));
-}
-
-void
-g_date_add_years (GDate *d,
- guint nyears)
-{
- g_return_if_fail (d != NULL);
- g_return_if_fail (g_date_valid (d));
-
- if (!d->dmy)
- {
- g_date_update_dmy (d);
- }
- g_return_if_fail (d->dmy);
-
- d->year += nyears;
-
- if (d->month == 2 && d->day == 29)
- {
- if (!g_date_is_leap_year (d->year))
- {
- d->day = 28;
- }
- }
-
- d->julian = FALSE;
-}
-
-void
-g_date_subtract_years (GDate *d,
- guint nyears)
-{
- g_return_if_fail (d != NULL);
- g_return_if_fail (g_date_valid (d));
-
- if (!d->dmy)
- {
- g_date_update_dmy (d);
- }
- g_return_if_fail (d->dmy);
- g_return_if_fail (d->year > nyears);
-
- d->year -= nyears;
-
- if (d->month == 2 && d->day == 29)
- {
- if (!g_date_is_leap_year (d->year))
- {
- d->day = 28;
- }
- }
-
- d->julian = FALSE;
-}
-
-
-gboolean
-g_date_is_leap_year (GDateYear year)
-{
- g_return_val_if_fail (g_date_valid_year (year), FALSE);
-
- return ( (((year % 4) == 0) && ((year % 100) != 0)) ||
- (year % 400) == 0 );
-}
-
-guint8
-g_date_days_in_month (GDateMonth month,
- GDateYear year)
-{
- gint index;
-
- g_return_val_if_fail (g_date_valid_year (year), 0);
- g_return_val_if_fail (g_date_valid_month (month), 0);
-
- index = g_date_is_leap_year (year) ? 1 : 0;
-
- return days_in_months[index][month];
-}
-
-guint8
-g_date_monday_weeks_in_year (GDateYear year)
-{
- GDate d;
-
- g_return_val_if_fail (g_date_valid_year (year), 0);
-
- g_date_clear (&d, 1);
- g_date_set_dmy (&d, 1, 1, year);
- if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
- g_date_set_dmy (&d, 31, 12, year);
- if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
- if (g_date_is_leap_year (year))
- {
- g_date_set_dmy (&d, 2, 1, year);
- if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
- g_date_set_dmy (&d, 30, 12, year);
- if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
- }
- return 52;
-}
-
-guint8
-g_date_sunday_weeks_in_year (GDateYear year)
-{
- GDate d;
-
- g_return_val_if_fail (g_date_valid_year (year), 0);
-
- g_date_clear (&d, 1);
- g_date_set_dmy (&d, 1, 1, year);
- if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
- g_date_set_dmy (&d, 31, 12, year);
- if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
- if (g_date_is_leap_year (year))
- {
- g_date_set_dmy (&d, 2, 1, year);
- if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
- g_date_set_dmy (&d, 30, 12, year);
- if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
- }
- return 52;
-}
-
-gint
-g_date_compare (GDate *lhs,
- GDate *rhs)
-{
- g_return_val_if_fail (lhs != NULL, 0);
- g_return_val_if_fail (rhs != NULL, 0);
- g_return_val_if_fail (g_date_valid (lhs), 0);
- g_return_val_if_fail (g_date_valid (rhs), 0);
-
- /* Remember the self-comparison case! I think it works right now. */
-
- while (TRUE)
- {
-
- if (lhs->julian && rhs->julian)
- {
- if (lhs->julian_days < rhs->julian_days) return -1;
- else if (lhs->julian_days > rhs->julian_days) return 1;
- else return 0;
- }
- else if (lhs->dmy && rhs->dmy)
- {
- if (lhs->year < rhs->year) return -1;
- else if (lhs->year > rhs->year) return 1;
- else
- {
- if (lhs->month < rhs->month) return -1;
- else if (lhs->month > rhs->month) return 1;
- else
- {
- if (lhs->day < rhs->day) return -1;
- else if (lhs->day > rhs->day) return 1;
- else return 0;
- }
-
- }
-
- }
- else
- {
- if (!lhs->julian) g_date_update_julian (lhs);
- if (!rhs->julian) g_date_update_julian (rhs);
- g_return_val_if_fail (lhs->julian, 0);
- g_return_val_if_fail (rhs->julian, 0);
- }
-
- }
- return 0; /* warnings */
-}
-
-
-void
-g_date_to_struct_tm (GDate *d,
- struct tm *tm)
-{
- GDateWeekday day;
-
- g_return_if_fail (d != NULL);
- g_return_if_fail (g_date_valid (d));
- g_return_if_fail (tm != NULL);
-
- if (!d->dmy)
- {
- g_date_update_dmy (d);
- }
- g_return_if_fail (d->dmy);
-
- /* zero all the irrelevant fields to be sure they're valid */
-
- /* On Linux and maybe other systems, there are weird non-POSIX
- * fields on the end of struct tm that choke strftime if they
- * contain garbage. So we need to 0 the entire struct, not just the
- * fields we know to exist.
- */
-
- memset (tm, 0x0, sizeof (struct tm));
-
- tm->tm_mday = d->day;
- tm->tm_mon = d->month - 1; /* 0-11 goes in tm */
- tm->tm_year = ((int)d->year) - 1900; /* X/Open says tm_year can be negative */
-
- day = g_date_weekday (d);
- if (day == 7) day = 0; /* struct tm wants days since Sunday, so Sunday is 0 */
-
- tm->tm_wday = (int)day;
-
- tm->tm_yday = g_date_day_of_year (d) - 1; /* 0 to 365 */
- tm->tm_isdst = -1; /* -1 means "information not available" */
-}
-
-gsize
-g_date_strftime (gchar *s,
- gsize slen,
- const gchar *format,
- GDate *d)
-{
- struct tm tm;
- gsize retval;
-
- g_return_val_if_fail (d != NULL, 0);
- g_return_val_if_fail (g_date_valid (d), 0);
- g_return_val_if_fail (slen > 0, 0);
- g_return_val_if_fail (format != 0, 0);
- g_return_val_if_fail (s != 0, 0);
-
- g_date_to_struct_tm (d, &tm);
-
- retval = strftime (s, slen, format, &tm);
- if (retval == 0)
- {
- /* If retval == 0, the contents of s are undefined. We define
- * them.
- */
- s[0] = '\0';
- }
- return retval;
-}
diff --git a/glib/gerror.c b/glib/gerror.c
deleted file mode 100644
index ba81b5f63..000000000
--- a/glib/gerror.c
+++ /dev/null
@@ -1,293 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe ; except for g_on_error_stack_trace, but who wants thread safety
- * then
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <signal.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "glib.h"
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#ifdef HAVE_SYS_TIMES_H
-#include <sys/times.h>
-#endif
-#include <sys/types.h>
-
-#include <time.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif /* HAVE_SYS_SELECT_H */
-
-#ifdef STDC_HEADERS
-#include <string.h> /* for bzero on BSD systems */
-#endif
-
-#ifdef _MSC_VER
-#include <process.h> /* For _getpid() */
-#endif
-
-#ifndef NO_FD_SET
-# define SELECT_MASK fd_set
-#else
-# ifndef _AIX
- typedef long fd_mask;
-# endif
-# if defined(_IBMR2)
-# define SELECT_MASK void
-# else
-# define SELECT_MASK int
-# endif
-#endif
-
-
-static void stack_trace (char **args);
-
-extern volatile gboolean glib_on_error_halt;
-volatile gboolean glib_on_error_halt = TRUE;
-
-void
-g_on_error_query (const gchar *prg_name)
-{
- static const gchar *query1 = "[E]xit, [H]alt";
- static const gchar *query2 = ", show [S]tack trace";
- static const gchar *query3 = " or [P]roceed";
- gchar buf[16];
-
- if (!prg_name)
- prg_name = g_get_prgname ();
-
- retry:
-
- if (prg_name)
- fprintf (stdout,
- "%s (pid:%u): %s%s%s: ",
- prg_name,
- (guint) getpid (),
- query1,
- query2,
- query3);
- else
- fprintf (stdout,
- "(process:%u): %s%s: ",
- (guint) getpid (),
- query1,
- query3);
- fflush (stdout);
-
-#ifndef NATIVE_WIN32
- if (isatty(0) && isatty(1))
- fgets (buf, 8, stdin);
- else
- strcpy (buf, "E\n");
-#else
- fgets (buf, 8, stdin);
-#endif
-
- if ((buf[0] == 'E' || buf[0] == 'e')
- && buf[1] == '\n')
- _exit (0);
- else if ((buf[0] == 'P' || buf[0] == 'p')
- && buf[1] == '\n')
- return;
- else if (prg_name
- && (buf[0] == 'S' || buf[0] == 's')
- && buf[1] == '\n')
- {
- g_on_error_stack_trace (prg_name);
- goto retry;
- }
- else if ((buf[0] == 'H' || buf[0] == 'h')
- && buf[1] == '\n')
- {
- while (glib_on_error_halt)
- ;
- glib_on_error_halt = TRUE;
- return;
- }
- else
- goto retry;
-}
-
-void
-g_on_error_stack_trace (const gchar *prg_name)
-{
-#ifndef NATIVE_WIN32
- pid_t pid;
- gchar buf[16];
- gchar *args[4] = { "gdb", NULL, NULL, NULL };
-
- if (!prg_name)
- return;
-
- sprintf (buf, "%u", (guint) getpid ());
-
- args[1] = (gchar*) prg_name;
- args[2] = buf;
-
- pid = fork ();
- if (pid == 0)
- {
- stack_trace (args);
- _exit (0);
- }
- else if (pid == (pid_t) -1)
- {
- perror ("unable to fork gdb");
- return;
- }
-
- while (glib_on_error_halt)
- ;
- glib_on_error_halt = TRUE;
-#else
- abort ();
-#endif
-}
-
-static gboolean stack_trace_done = FALSE;
-
-static void
-stack_trace_sigchld (int signum)
-{
- stack_trace_done = TRUE;
-}
-
-static void
-stack_trace (char **args)
-{
-#ifndef NATIVE_WIN32
- pid_t pid;
- int in_fd[2];
- int out_fd[2];
- SELECT_MASK fdset;
- SELECT_MASK readset;
- struct timeval tv;
- int sel, index, state;
- char buffer[256];
- char c;
-
- stack_trace_done = FALSE;
- signal (SIGCHLD, stack_trace_sigchld);
-
- if ((pipe (in_fd) == -1) || (pipe (out_fd) == -1))
- {
- perror ("unable to open pipe");
- _exit (0);
- }
-
- pid = fork ();
- if (pid == 0)
- {
- close (0); dup (in_fd[0]); /* set the stdin to the in pipe */
- close (1); dup (out_fd[1]); /* set the stdout to the out pipe */
- close (2); dup (out_fd[1]); /* set the stderr to the out pipe */
-
- execvp (args[0], args); /* exec gdb */
- perror ("exec failed");
- _exit (0);
- }
- else if (pid == (pid_t) -1)
- {
- perror ("unable to fork");
- _exit (0);
- }
-
- FD_ZERO (&fdset);
- FD_SET (out_fd[0], &fdset);
-
- write (in_fd[1], "backtrace\n", 10);
- write (in_fd[1], "p x = 0\n", 8);
- write (in_fd[1], "quit\n", 5);
-
- index = 0;
- state = 0;
-
- while (1)
- {
- readset = fdset;
- tv.tv_sec = 1;
- tv.tv_usec = 0;
-
- sel = select (FD_SETSIZE, &readset, NULL, NULL, &tv);
- if (sel == -1)
- break;
-
- if ((sel > 0) && (FD_ISSET (out_fd[0], &readset)))
- {
- if (read (out_fd[0], &c, 1))
- {
- switch (state)
- {
- case 0:
- if (c == '#')
- {
- state = 1;
- index = 0;
- buffer[index++] = c;
- }
- break;
- case 1:
- buffer[index++] = c;
- if ((c == '\n') || (c == '\r'))
- {
- buffer[index] = 0;
- fprintf (stdout, "%s", buffer);
- state = 0;
- index = 0;
- }
- break;
- default:
- break;
- }
- }
- }
- else if (stack_trace_done)
- break;
- }
-
- close (in_fd[0]);
- close (in_fd[1]);
- close (out_fd[0]);
- close (out_fd[1]);
- _exit (0);
-#else
- abort ();
-#endif
-}
diff --git a/glib/ghash.c b/glib/ghash.c
deleted file mode 100644
index 331a1ab2d..000000000
--- a/glib/ghash.c
+++ /dev/null
@@ -1,404 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "glib.h"
-
-
-#define HASH_TABLE_MIN_SIZE 11
-#define HASH_TABLE_MAX_SIZE 13845163
-
-
-typedef struct _GHashNode GHashNode;
-
-struct _GHashNode
-{
- gpointer key;
- gpointer value;
- GHashNode *next;
-};
-
-struct _GHashTable
-{
- gint size;
- gint nnodes;
- guint frozen;
- GHashNode **nodes;
- GHashFunc hash_func;
- GCompareFunc key_compare_func;
-};
-
-
-static void g_hash_table_resize (GHashTable *hash_table);
-static GHashNode** g_hash_table_lookup_node (GHashTable *hash_table,
- gconstpointer key);
-static GHashNode* g_hash_node_new (gpointer key,
- gpointer value);
-static void g_hash_node_destroy (GHashNode *hash_node);
-static void g_hash_nodes_destroy (GHashNode *hash_node);
-
-
-G_LOCK_DEFINE_STATIC (g_hash_global);
-
-static GMemChunk *node_mem_chunk = NULL;
-static GHashNode *node_free_list = NULL;
-
-
-GHashTable*
-g_hash_table_new (GHashFunc hash_func,
- GCompareFunc key_compare_func)
-{
- GHashTable *hash_table;
- guint i;
-
- hash_table = g_new (GHashTable, 1);
- hash_table->size = HASH_TABLE_MIN_SIZE;
- hash_table->nnodes = 0;
- hash_table->frozen = FALSE;
- hash_table->hash_func = hash_func ? hash_func : g_direct_hash;
- hash_table->key_compare_func = key_compare_func;
- hash_table->nodes = g_new (GHashNode*, hash_table->size);
-
- for (i = 0; i < hash_table->size; i++)
- hash_table->nodes[i] = NULL;
-
- return hash_table;
-}
-
-void
-g_hash_table_destroy (GHashTable *hash_table)
-{
- guint i;
-
- g_return_if_fail (hash_table != NULL);
-
- for (i = 0; i < hash_table->size; i++)
- g_hash_nodes_destroy (hash_table->nodes[i]);
-
- g_free (hash_table->nodes);
- g_free (hash_table);
-}
-
-static inline GHashNode**
-g_hash_table_lookup_node (GHashTable *hash_table,
- gconstpointer key)
-{
- GHashNode **node;
-
- node = &hash_table->nodes
- [(* hash_table->hash_func) (key) % hash_table->size];
-
- /* Hash table lookup needs to be fast.
- * We therefore remove the extra conditional of testing
- * whether to call the key_compare_func or not from
- * the inner loop.
- */
- if (hash_table->key_compare_func)
- while (*node && !(*hash_table->key_compare_func) ((*node)->key, key))
- node = &(*node)->next;
- else
- while (*node && (*node)->key != key)
- node = &(*node)->next;
-
- return node;
-}
-
-gpointer
-g_hash_table_lookup (GHashTable *hash_table,
- gconstpointer key)
-{
- GHashNode *node;
-
- g_return_val_if_fail (hash_table != NULL, NULL);
-
- node = *g_hash_table_lookup_node (hash_table, key);
-
- return node ? node->value : NULL;
-}
-
-void
-g_hash_table_insert (GHashTable *hash_table,
- gpointer key,
- gpointer value)
-{
- GHashNode **node;
-
- g_return_if_fail (hash_table != NULL);
-
- node = g_hash_table_lookup_node (hash_table, key);
-
- if (*node)
- {
- /* do not reset node->key in this place, keeping
- * the old key might be intended.
- * a g_hash_table_remove/g_hash_table_insert pair
- * can be used otherwise.
- *
- * node->key = key; */
- (*node)->value = value;
- }
- else
- {
- *node = g_hash_node_new (key, value);
- hash_table->nnodes++;
- if (!hash_table->frozen)
- g_hash_table_resize (hash_table);
- }
-}
-
-void
-g_hash_table_remove (GHashTable *hash_table,
- gconstpointer key)
-{
- GHashNode **node, *dest;
-
- g_return_if_fail (hash_table != NULL);
-
- node = g_hash_table_lookup_node (hash_table, key);
-
- if (*node)
- {
- dest = *node;
- (*node) = dest->next;
- g_hash_node_destroy (dest);
- hash_table->nnodes--;
-
- if (!hash_table->frozen)
- g_hash_table_resize (hash_table);
- }
-}
-
-gboolean
-g_hash_table_lookup_extended (GHashTable *hash_table,
- gconstpointer lookup_key,
- gpointer *orig_key,
- gpointer *value)
-{
- GHashNode *node;
-
- g_return_val_if_fail (hash_table != NULL, FALSE);
-
- node = *g_hash_table_lookup_node (hash_table, lookup_key);
-
- if (node)
- {
- if (orig_key)
- *orig_key = node->key;
- if (value)
- *value = node->value;
- return TRUE;
- }
- else
- return FALSE;
-}
-
-void
-g_hash_table_freeze (GHashTable *hash_table)
-{
- g_return_if_fail (hash_table != NULL);
-
- hash_table->frozen++;
-}
-
-void
-g_hash_table_thaw (GHashTable *hash_table)
-{
- g_return_if_fail (hash_table != NULL);
-
- if (hash_table->frozen)
- if (!(--hash_table->frozen))
- g_hash_table_resize (hash_table);
-}
-
-guint
-g_hash_table_foreach_remove (GHashTable *hash_table,
- GHRFunc func,
- gpointer user_data)
-{
- GHashNode *node, *prev;
- guint i;
- guint deleted = 0;
-
- g_return_val_if_fail (hash_table != NULL, 0);
- g_return_val_if_fail (func != NULL, 0);
-
- for (i = 0; i < hash_table->size; i++)
- {
- restart:
-
- prev = NULL;
-
- for (node = hash_table->nodes[i]; node; prev = node, node = node->next)
- {
- if ((* func) (node->key, node->value, user_data))
- {
- deleted += 1;
-
- hash_table->nnodes -= 1;
-
- if (prev)
- {
- prev->next = node->next;
- g_hash_node_destroy (node);
- node = prev;
- }
- else
- {
- hash_table->nodes[i] = node->next;
- g_hash_node_destroy (node);
- goto restart;
- }
- }
- }
- }
-
- if (!hash_table->frozen)
- g_hash_table_resize (hash_table);
-
- return deleted;
-}
-
-void
-g_hash_table_foreach (GHashTable *hash_table,
- GHFunc func,
- gpointer user_data)
-{
- GHashNode *node;
- gint i;
-
- g_return_if_fail (hash_table != NULL);
- g_return_if_fail (func != NULL);
-
- for (i = 0; i < hash_table->size; i++)
- for (node = hash_table->nodes[i]; node; node = node->next)
- (* func) (node->key, node->value, user_data);
-}
-
-/* Returns the number of elements contained in the hash table. */
-guint
-g_hash_table_size (GHashTable *hash_table)
-{
- g_return_val_if_fail (hash_table != NULL, 0);
-
- return hash_table->nnodes;
-}
-
-static void
-g_hash_table_resize (GHashTable *hash_table)
-{
- GHashNode **new_nodes;
- GHashNode *node;
- GHashNode *next;
- gfloat nodes_per_list;
- guint hash_val;
- gint new_size;
- gint i;
-
- nodes_per_list = (gfloat) hash_table->nnodes / (gfloat) hash_table->size;
-
- if ((nodes_per_list > 0.3 || hash_table->size <= HASH_TABLE_MIN_SIZE) &&
- (nodes_per_list < 3.0 || hash_table->size >= HASH_TABLE_MAX_SIZE))
- return;
-
- new_size = CLAMP(g_spaced_primes_closest (hash_table->nnodes),
- HASH_TABLE_MIN_SIZE,
- HASH_TABLE_MAX_SIZE);
- new_nodes = g_new0 (GHashNode*, new_size);
-
- for (i = 0; i < hash_table->size; i++)
- for (node = hash_table->nodes[i]; node; node = next)
- {
- next = node->next;
-
- hash_val = (* hash_table->hash_func) (node->key) % new_size;
-
- node->next = new_nodes[hash_val];
- new_nodes[hash_val] = node;
- }
-
- g_free (hash_table->nodes);
- hash_table->nodes = new_nodes;
- hash_table->size = new_size;
-}
-
-static GHashNode*
-g_hash_node_new (gpointer key,
- gpointer value)
-{
- GHashNode *hash_node;
-
- G_LOCK (g_hash_global);
- if (node_free_list)
- {
- hash_node = node_free_list;
- node_free_list = node_free_list->next;
- }
- else
- {
- if (!node_mem_chunk)
- node_mem_chunk = g_mem_chunk_new ("hash node mem chunk",
- sizeof (GHashNode),
- 1024, G_ALLOC_ONLY);
-
- hash_node = g_chunk_new (GHashNode, node_mem_chunk);
- }
- G_UNLOCK (g_hash_global);
-
- hash_node->key = key;
- hash_node->value = value;
- hash_node->next = NULL;
-
- return hash_node;
-}
-
-static void
-g_hash_node_destroy (GHashNode *hash_node)
-{
- G_LOCK (g_hash_global);
- hash_node->next = node_free_list;
- node_free_list = hash_node;
- G_UNLOCK (g_hash_global);
-}
-
-static void
-g_hash_nodes_destroy (GHashNode *hash_node)
-{
- if (hash_node)
- {
- GHashNode *node = hash_node;
-
- while (node->next)
- node = node->next;
-
- G_LOCK (g_hash_global);
- node->next = node_free_list;
- node_free_list = hash_node;
- G_UNLOCK (g_hash_global);
- }
-}
diff --git a/glib/ghook.c b/glib/ghook.c
deleted file mode 100644
index 09e888366..000000000
--- a/glib/ghook.c
+++ /dev/null
@@ -1,633 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * GHook: Callback maintenance functions
- * Copyright (C) 1998 Tim Janik
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "glib.h"
-
-
-/* --- defines --- */
-#define G_HOOKS_PREALLOC (16)
-
-
-/* --- functions --- */
-void
-g_hook_list_init (GHookList *hook_list,
- guint hook_size)
-{
- g_return_if_fail (hook_list != NULL);
- g_return_if_fail (hook_size >= sizeof (GHook));
-
- hook_list->seq_id = 1;
- hook_list->hook_size = hook_size;
- hook_list->is_setup = TRUE;
- hook_list->hooks = NULL;
- hook_list->hook_memchunk = g_mem_chunk_new ("GHook Memchunk",
- hook_size,
- hook_size * G_HOOKS_PREALLOC,
- G_ALLOC_AND_FREE);
- hook_list->hook_free = NULL;
- hook_list->hook_destroy = NULL;
-}
-
-void
-g_hook_list_clear (GHookList *hook_list)
-{
- g_return_if_fail (hook_list != NULL);
-
- if (hook_list->is_setup)
- {
- GHook *hook;
-
- hook_list->is_setup = FALSE;
-
- hook = hook_list->hooks;
- if (!hook)
- {
- g_mem_chunk_destroy (hook_list->hook_memchunk);
- hook_list->hook_memchunk = NULL;
- }
- else
- do
- {
- GHook *tmp;
-
- g_hook_ref (hook_list, hook);
- g_hook_destroy_link (hook_list, hook);
- tmp = hook->next;
- g_hook_unref (hook_list, hook);
- hook = tmp;
- }
- while (hook);
- }
-}
-
-GHook*
-g_hook_alloc (GHookList *hook_list)
-{
- GHook *hook;
-
- g_return_val_if_fail (hook_list != NULL, NULL);
- g_return_val_if_fail (hook_list->is_setup, NULL);
-
- hook = g_chunk_new0 (GHook, hook_list->hook_memchunk);
- hook->data = NULL;
- hook->next = NULL;
- hook->prev = NULL;
- hook->flags = G_HOOK_FLAG_ACTIVE;
- hook->ref_count = 0;
- hook->hook_id = 0;
- hook->func = NULL;
- hook->destroy = NULL;
-
- return hook;
-}
-
-void
-g_hook_free (GHookList *hook_list,
- GHook *hook)
-{
- g_return_if_fail (hook_list != NULL);
- g_return_if_fail (hook_list->is_setup);
- g_return_if_fail (hook != NULL);
- g_return_if_fail (G_HOOK_IS_UNLINKED (hook));
-
- if (hook_list->hook_free)
- hook_list->hook_free (hook_list, hook);
-
- g_chunk_free (hook, hook_list->hook_memchunk);
-}
-
-void
-g_hook_destroy_link (GHookList *hook_list,
- GHook *hook)
-{
- g_return_if_fail (hook_list != NULL);
- g_return_if_fail (hook != NULL);
-
- if (hook->hook_id)
- {
- hook->hook_id = 0;
- hook->flags &= ~G_HOOK_FLAG_ACTIVE;
- if (hook_list->hook_destroy)
- {
- if (hook_list->hook_destroy != G_HOOK_DEFERRED_DESTROY)
- hook_list->hook_destroy (hook_list, hook);
- }
- else if (hook->destroy)
- {
- hook->destroy (hook->data);
- hook->data = NULL;
- hook->func = NULL;
- hook->destroy = NULL;
- }
- g_hook_unref (hook_list, hook); /* counterpart to g_hook_insert_before */
- }
-}
-
-gboolean
-g_hook_destroy (GHookList *hook_list,
- guint hook_id)
-{
- GHook *hook;
-
- g_return_val_if_fail (hook_list != NULL, FALSE);
- g_return_val_if_fail (hook_id > 0, FALSE);
-
- hook = g_hook_get (hook_list, hook_id);
- if (hook)
- {
- g_hook_destroy_link (hook_list, hook);
- return TRUE;
- }
-
- return FALSE;
-}
-
-void
-g_hook_unref (GHookList *hook_list,
- GHook *hook)
-{
- g_return_if_fail (hook_list != NULL);
- g_return_if_fail (hook_list->hook_memchunk != NULL);
- g_return_if_fail (hook != NULL);
- g_return_if_fail (hook->ref_count > 0);
-
- hook->ref_count--;
- if (!hook->ref_count)
- {
- g_return_if_fail (hook->hook_id == 0);
- g_return_if_fail (!G_HOOK_IN_CALL (hook));
-
- if (hook->prev)
- hook->prev->next = hook->next;
- else
- hook_list->hooks = hook->next;
- if (hook->next)
- {
- hook->next->prev = hook->prev;
- hook->next = NULL;
- }
- hook->prev = NULL;
-
- if (!hook_list->is_setup)
- {
- hook_list->is_setup = TRUE;
- g_hook_free (hook_list, hook);
- hook_list->is_setup = FALSE;
-
- if (!hook_list->hooks)
- {
- g_mem_chunk_destroy (hook_list->hook_memchunk);
- hook_list->hook_memchunk = NULL;
- }
- }
- else
- g_hook_free (hook_list, hook);
- }
-}
-
-void
-g_hook_ref (GHookList *hook_list,
- GHook *hook)
-{
- g_return_if_fail (hook_list != NULL);
- g_return_if_fail (hook != NULL);
- g_return_if_fail (hook->ref_count > 0);
-
- hook->ref_count++;
-}
-
-void
-g_hook_prepend (GHookList *hook_list,
- GHook *hook)
-{
- g_return_if_fail (hook_list != NULL);
-
- g_hook_insert_before (hook_list, hook_list->hooks, hook);
-}
-
-void
-g_hook_insert_before (GHookList *hook_list,
- GHook *sibling,
- GHook *hook)
-{
- g_return_if_fail (hook_list != NULL);
- g_return_if_fail (hook_list->is_setup);
- g_return_if_fail (hook != NULL);
- g_return_if_fail (G_HOOK_IS_UNLINKED (hook));
- g_return_if_fail (hook->func != NULL);
-
- hook->hook_id = hook_list->seq_id++;
- hook->ref_count = 1; /* counterpart to g_hook_destroy_link */
-
- if (sibling)
- {
- if (sibling->prev)
- {
- hook->prev = sibling->prev;
- hook->prev->next = hook;
- hook->next = sibling;
- sibling->prev = hook;
- }
- else
- {
- hook_list->hooks = hook;
- hook->next = sibling;
- sibling->prev = hook;
- }
- }
- else
- {
- if (hook_list->hooks)
- {
- sibling = hook_list->hooks;
- while (sibling->next)
- sibling = sibling->next;
- hook->prev = sibling;
- sibling->next = hook;
- }
- else
- hook_list->hooks = hook;
- }
-}
-
-void
-g_hook_list_invoke (GHookList *hook_list,
- gboolean may_recurse)
-{
- GHook *hook;
-
- g_return_if_fail (hook_list != NULL);
- g_return_if_fail (hook_list->is_setup);
-
- hook = g_hook_first_valid (hook_list, may_recurse);
- while (hook)
- {
- GHookFunc func;
- gboolean was_in_call;
-
- func = (GHookFunc) hook->func;
-
- was_in_call = G_HOOK_IN_CALL (hook);
- hook->flags |= G_HOOK_FLAG_IN_CALL;
- func (hook->data);
- if (!was_in_call)
- hook->flags &= ~G_HOOK_FLAG_IN_CALL;
-
- hook = g_hook_next_valid (hook_list, hook, may_recurse);
- }
-}
-
-void
-g_hook_list_invoke_check (GHookList *hook_list,
- gboolean may_recurse)
-{
- GHook *hook;
-
- g_return_if_fail (hook_list != NULL);
- g_return_if_fail (hook_list->is_setup);
-
- hook = g_hook_first_valid (hook_list, may_recurse);
- while (hook)
- {
- GHookCheckFunc func;
- gboolean was_in_call;
- gboolean need_destroy;
-
- func = (GHookCheckFunc) hook->func;
-
- was_in_call = G_HOOK_IN_CALL (hook);
- hook->flags |= G_HOOK_FLAG_IN_CALL;
- need_destroy = !func (hook->data);
- if (!was_in_call)
- hook->flags &= ~G_HOOK_FLAG_IN_CALL;
- if (need_destroy)
- g_hook_destroy_link (hook_list, hook);
-
- hook = g_hook_next_valid (hook_list, hook, may_recurse);
- }
-}
-
-void
-g_hook_list_marshal_check (GHookList *hook_list,
- gboolean may_recurse,
- GHookCheckMarshaller marshaller,
- gpointer data)
-{
- GHook *hook;
-
- g_return_if_fail (hook_list != NULL);
- g_return_if_fail (hook_list->is_setup);
- g_return_if_fail (marshaller != NULL);
-
- hook = g_hook_first_valid (hook_list, may_recurse);
- while (hook)
- {
- gboolean was_in_call;
- gboolean need_destroy;
-
- was_in_call = G_HOOK_IN_CALL (hook);
- hook->flags |= G_HOOK_FLAG_IN_CALL;
- need_destroy = !marshaller (hook, data);
- if (!was_in_call)
- hook->flags &= ~G_HOOK_FLAG_IN_CALL;
- if (need_destroy)
- g_hook_destroy_link (hook_list, hook);
-
- hook = g_hook_next_valid (hook_list, hook, may_recurse);
- }
-}
-
-void
-g_hook_list_marshal (GHookList *hook_list,
- gboolean may_recurse,
- GHookMarshaller marshaller,
- gpointer data)
-{
- GHook *hook;
-
- g_return_if_fail (hook_list != NULL);
- g_return_if_fail (hook_list->is_setup);
- g_return_if_fail (marshaller != NULL);
-
- hook = g_hook_first_valid (hook_list, may_recurse);
- while (hook)
- {
- gboolean was_in_call;
-
- was_in_call = G_HOOK_IN_CALL (hook);
- hook->flags |= G_HOOK_FLAG_IN_CALL;
- marshaller (hook, data);
- if (!was_in_call)
- hook->flags &= ~G_HOOK_FLAG_IN_CALL;
-
- hook = g_hook_next_valid (hook_list, hook, may_recurse);
- }
-}
-
-GHook*
-g_hook_first_valid (GHookList *hook_list,
- gboolean may_be_in_call)
-{
- g_return_val_if_fail (hook_list != NULL, NULL);
-
- if (hook_list->is_setup)
- {
- GHook *hook;
-
- hook = hook_list->hooks;
- if (hook)
- {
- g_hook_ref (hook_list, hook);
- if (G_HOOK_IS_VALID (hook) && (may_be_in_call || !G_HOOK_IN_CALL (hook)))
- return hook;
- else
- return g_hook_next_valid (hook_list, hook, may_be_in_call);
- }
- }
-
- return NULL;
-}
-
-GHook*
-g_hook_next_valid (GHookList *hook_list,
- GHook *hook,
- gboolean may_be_in_call)
-{
- GHook *ohook = hook;
-
- g_return_val_if_fail (hook_list != NULL, NULL);
-
- if (!hook)
- return NULL;
-
- hook = hook->next;
- while (hook)
- {
- if (G_HOOK_IS_VALID (hook) && (may_be_in_call || !G_HOOK_IN_CALL (hook)))
- {
- g_hook_ref (hook_list, hook);
- g_hook_unref (hook_list, ohook);
-
- return hook;
- }
- hook = hook->next;
- }
- g_hook_unref (hook_list, ohook);
-
- return NULL;
-}
-
-GHook*
-g_hook_get (GHookList *hook_list,
- guint hook_id)
-{
- GHook *hook;
-
- g_return_val_if_fail (hook_list != NULL, NULL);
- g_return_val_if_fail (hook_id > 0, NULL);
-
- hook = hook_list->hooks;
- while (hook)
- {
- if (hook->hook_id == hook_id)
- return hook;
- hook = hook->next;
- }
-
- return NULL;
-}
-
-GHook*
-g_hook_find (GHookList *hook_list,
- gboolean need_valids,
- GHookFindFunc func,
- gpointer data)
-{
- GHook *hook;
-
- g_return_val_if_fail (hook_list != NULL, NULL);
- g_return_val_if_fail (func != NULL, NULL);
-
- hook = hook_list->hooks;
- while (hook)
- {
- GHook *tmp;
-
- /* test only non-destroyed hooks */
- if (!hook->hook_id)
- {
- hook = hook->next;
- continue;
- }
-
- g_hook_ref (hook_list, hook);
-
- if (func (hook, data) && hook->hook_id && (!need_valids || G_HOOK_ACTIVE (hook)))
- {
- g_hook_unref (hook_list, hook);
-
- return hook;
- }
-
- tmp = hook->next;
- g_hook_unref (hook_list, hook);
- hook = tmp;
- }
-
- return NULL;
-}
-
-GHook*
-g_hook_find_data (GHookList *hook_list,
- gboolean need_valids,
- gpointer data)
-{
- GHook *hook;
-
- g_return_val_if_fail (hook_list != NULL, NULL);
-
- hook = hook_list->hooks;
- while (hook)
- {
- /* test only non-destroyed hooks */
- if (hook->data == data &&
- hook->hook_id &&
- (!need_valids || G_HOOK_ACTIVE (hook)))
- return hook;
-
- hook = hook->next;
- }
-
- return NULL;
-}
-
-GHook*
-g_hook_find_func (GHookList *hook_list,
- gboolean need_valids,
- gpointer func)
-{
- GHook *hook;
-
- g_return_val_if_fail (hook_list != NULL, NULL);
- g_return_val_if_fail (func != NULL, NULL);
-
- hook = hook_list->hooks;
- while (hook)
- {
- /* test only non-destroyed hooks */
- if (hook->func == func &&
- hook->hook_id &&
- (!need_valids || G_HOOK_ACTIVE (hook)))
- return hook;
-
- hook = hook->next;
- }
-
- return NULL;
-}
-
-GHook*
-g_hook_find_func_data (GHookList *hook_list,
- gboolean need_valids,
- gpointer func,
- gpointer data)
-{
- GHook *hook;
-
- g_return_val_if_fail (hook_list != NULL, NULL);
- g_return_val_if_fail (func != NULL, NULL);
-
- hook = hook_list->hooks;
- while (hook)
- {
- /* test only non-destroyed hooks */
- if (hook->data == data &&
- hook->func == func &&
- hook->hook_id &&
- (!need_valids || G_HOOK_ACTIVE (hook)))
- return hook;
-
- hook = hook->next;
- }
-
- return NULL;
-}
-
-void
-g_hook_insert_sorted (GHookList *hook_list,
- GHook *hook,
- GHookCompareFunc func)
-{
- GHook *sibling;
-
- g_return_if_fail (hook_list != NULL);
- g_return_if_fail (hook_list->is_setup);
- g_return_if_fail (hook != NULL);
- g_return_if_fail (G_HOOK_IS_UNLINKED (hook));
- g_return_if_fail (hook->func != NULL);
- g_return_if_fail (func != NULL);
-
- /* first non-destroyed hook */
- sibling = hook_list->hooks;
- while (sibling && !sibling->hook_id)
- sibling = sibling->next;
-
- while (sibling)
- {
- GHook *tmp;
-
- g_hook_ref (hook_list, sibling);
- if (func (hook, sibling) <= 0 && sibling->hook_id)
- {
- g_hook_unref (hook_list, sibling);
- break;
- }
-
- /* next non-destroyed hook */
- tmp = sibling->next;
- while (tmp && !tmp->hook_id)
- tmp = tmp->next;
-
- g_hook_unref (hook_list, sibling);
- sibling = tmp;
- }
-
- g_hook_insert_before (hook_list, sibling, hook);
-}
-
-gint
-g_hook_compare_ids (GHook *new_hook,
- GHook *sibling)
-{
- return ((glong) new_hook->hook_id) - ((glong) sibling->hook_id);
-}
diff --git a/glib/giochannel.c b/glib/giochannel.c
deleted file mode 100644
index 8556f0d80..000000000
--- a/glib/giochannel.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * giochannel.c: IO Channel abstraction
- * Copyright 1998 Owen Taylor
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "config.h"
-
-#include "glib.h"
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-void
-g_io_channel_init (GIOChannel *channel)
-{
- channel->channel_flags = 0;
- channel->ref_count = 1;
-}
-
-
-void
-g_io_channel_ref (GIOChannel *channel)
-{
- g_return_if_fail (channel != NULL);
-
- channel->ref_count++;
-}
-
-void
-g_io_channel_unref (GIOChannel *channel)
-{
- g_return_if_fail (channel != NULL);
-
- channel->ref_count--;
- if (channel->ref_count == 0)
- channel->funcs->io_free (channel);
-}
-
-GIOError
-g_io_channel_read (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_read)
-{
- g_return_val_if_fail (channel != NULL, G_IO_ERROR_UNKNOWN);
-
- return channel->funcs->io_read (channel, buf, count, bytes_read);
-}
-
-GIOError
-g_io_channel_write (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written)
-{
- g_return_val_if_fail (channel != NULL, G_IO_ERROR_UNKNOWN);
-
- return channel->funcs->io_write (channel, buf, count, bytes_written);
-}
-
-GIOError
-g_io_channel_seek (GIOChannel *channel,
- gint offset,
- GSeekType type)
-{
- g_return_val_if_fail (channel != NULL, G_IO_ERROR_UNKNOWN);
-
- return channel->funcs->io_seek (channel, offset, type);
-}
-
-void
-g_io_channel_close (GIOChannel *channel)
-{
- g_return_if_fail (channel != NULL);
-
- channel->funcs->io_close (channel);
-}
-
-guint
-g_io_add_watch_full (GIOChannel *channel,
- gint priority,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data,
- GDestroyNotify notify)
-{
- g_return_val_if_fail (channel != NULL, 0);
-
- return channel->funcs->io_add_watch (channel, priority, condition,
- func, user_data, notify);
-}
-
-guint
-g_io_add_watch (GIOChannel *channel,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data)
-{
- return g_io_add_watch_full (channel, 0, condition, func, user_data, NULL);
-}
diff --git a/glib/giounix.c b/glib/giounix.c
deleted file mode 100644
index 108527516..000000000
--- a/glib/giounix.c
+++ /dev/null
@@ -1,313 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * giounix.c: IO Channels using unix file descriptors
- * Copyright 1998 Owen Taylor
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "glib.h"
-#include <sys/types.h>
-#include <unistd.h>
-#include <errno.h>
-
-/*
- * Unix IO Channels
- */
-
-typedef struct _GIOUnixChannel GIOUnixChannel;
-typedef struct _GIOUnixWatch GIOUnixWatch;
-
-struct _GIOUnixChannel {
- GIOChannel channel;
- gint fd;
-};
-
-struct _GIOUnixWatch {
- GPollFD pollfd;
- GIOChannel *channel;
- GIOCondition condition;
- GIOFunc callback;
-};
-
-
-static GIOError g_io_unix_read (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written);
-
-static GIOError g_io_unix_write(GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written);
-static GIOError g_io_unix_seek (GIOChannel *channel,
- gint offset,
- GSeekType type);
-static void g_io_unix_close (GIOChannel *channel);
-static void g_io_unix_free (GIOChannel *channel);
-static guint g_io_unix_add_watch (GIOChannel *channel,
- gint priority,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data,
- GDestroyNotify notify);
-static gboolean g_io_unix_prepare (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout,
- gpointer user_data);
-static gboolean g_io_unix_check (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data);
-static gboolean g_io_unix_dispatch (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data);
-static void g_io_unix_destroy (gpointer source_data);
-
-GSourceFuncs unix_watch_funcs = {
- g_io_unix_prepare,
- g_io_unix_check,
- g_io_unix_dispatch,
- g_io_unix_destroy
-};
-
-GIOFuncs unix_channel_funcs = {
- g_io_unix_read,
- g_io_unix_write,
- g_io_unix_seek,
- g_io_unix_close,
- g_io_unix_add_watch,
- g_io_unix_free,
-};
-
-static gboolean
-g_io_unix_prepare (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout,
- gpointer user_data)
-{
- *timeout = -1;
- return FALSE;
-}
-
-static gboolean
-g_io_unix_check (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data)
-{
- GIOUnixWatch *data = source_data;
-
- return (data->pollfd.revents & data->condition);
-}
-
-static gboolean
-g_io_unix_dispatch (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data)
-
-{
- GIOUnixWatch *data = source_data;
-
- return (*data->callback)(data->channel,
- data->pollfd.revents & data->condition,
- user_data);
-}
-
-static void
-g_io_unix_destroy (gpointer source_data)
-{
- GIOUnixWatch *data = source_data;
-
- g_main_remove_poll (&data->pollfd);
- g_io_channel_unref (data->channel);
- g_free (data);
-}
-
-static GIOError
-g_io_unix_read (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_read)
-{
- GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
- gint result;
-
- result = read (unix_channel->fd, buf, count);
-
- if (result < 0)
- {
- *bytes_read = 0;
- switch (errno)
- {
- case EINVAL:
- return G_IO_ERROR_INVAL;
- case EAGAIN:
- return G_IO_ERROR_AGAIN;
- default:
- return G_IO_ERROR_UNKNOWN;
- }
- }
- else
- {
- *bytes_read = result;
- return G_IO_ERROR_NONE;
- }
-}
-
-static GIOError
-g_io_unix_write(GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written)
-{
- GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
- gint result;
-
- result = write (unix_channel->fd, buf, count);
-
- if (result < 0)
- {
- *bytes_written = 0;
- switch (errno)
- {
- case EINVAL:
- return G_IO_ERROR_INVAL;
- case EAGAIN:
- return G_IO_ERROR_AGAIN;
- default:
- return G_IO_ERROR_UNKNOWN;
- }
- }
- else
- {
- *bytes_written = result;
- return G_IO_ERROR_NONE;
- }
-}
-
-static GIOError
-g_io_unix_seek (GIOChannel *channel,
- gint offset,
- GSeekType type)
-{
- GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
- int whence;
- off_t result;
-
- switch (type)
- {
- case G_SEEK_SET:
- whence = SEEK_SET;
- break;
- case G_SEEK_CUR:
- whence = SEEK_CUR;
- break;
- case G_SEEK_END:
- whence = SEEK_END;
- break;
- default:
- g_warning ("g_io_unix_seek: unknown seek type");
- return G_IO_ERROR_UNKNOWN;
- }
-
- result = lseek (unix_channel->fd, offset, whence);
-
- if (result < 0)
- {
- switch (errno)
- {
- case EINVAL:
- return G_IO_ERROR_INVAL;
- default:
- return G_IO_ERROR_UNKNOWN;
- }
- }
- else
- return G_IO_ERROR_NONE;
-}
-
-
-static void
-g_io_unix_close (GIOChannel *channel)
-{
- GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
-
- close (unix_channel->fd);
-}
-
-static void
-g_io_unix_free (GIOChannel *channel)
-{
- GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
-
- g_free (unix_channel);
-}
-
-static guint
-g_io_unix_add_watch (GIOChannel *channel,
- gint priority,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data,
- GDestroyNotify notify)
-{
- GIOUnixWatch *watch = g_new (GIOUnixWatch, 1);
- GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
-
- watch->channel = channel;
- g_io_channel_ref (channel);
-
- watch->callback = func;
- watch->condition = condition;
-
- watch->pollfd.fd = unix_channel->fd;
- watch->pollfd.events = condition;
-
- g_main_add_poll (&watch->pollfd, priority);
-
- return g_source_add (priority, TRUE, &unix_watch_funcs, watch, user_data, notify);
-}
-
-GIOChannel *
-g_io_channel_unix_new (gint fd)
-{
- GIOUnixChannel *unix_channel = g_new (GIOUnixChannel, 1);
- GIOChannel *channel = (GIOChannel *)unix_channel;
-
- g_io_channel_init (channel);
- channel->funcs = &unix_channel_funcs;
-
- unix_channel->fd = fd;
- return channel;
-}
-
-gint
-g_io_channel_unix_get_fd (GIOChannel *channel)
-{
- GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
- return unix_channel->fd;
-}
diff --git a/glib/giowin32.c b/glib/giowin32.c
deleted file mode 100644
index d5e467e3d..000000000
--- a/glib/giowin32.c
+++ /dev/null
@@ -1,1035 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * giowin32.c: IO Channels for Win32.
- * Copyright 1998 Owen Taylor and Tor Lillqvist
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-
-#include "config.h"
-#include "glib.h"
-#include <windows.h>
-#include <winsock.h> /* Not everybody has winsock2 */
-#include <fcntl.h>
-#include <io.h>
-#include <errno.h>
-#include <sys/types.h>
-
-#include <stdio.h>
-
-typedef struct _GIOWin32Channel GIOWin32Channel;
-typedef struct _GIOWin32Watch GIOWin32Watch;
-
-guint g_pipe_readable_msg;
-
-typedef enum {
- G_IO_WINDOWS_MESSAGES, /* Windows messages */
- G_IO_FILE_DESC, /* Unix-like file descriptors from _open*/
- G_IO_PIPE, /* pipe, with windows messages for signalling */
- G_IO_STREAM_SOCKET /* Stream sockets */
-} GIOWin32ChannelType;
-
-struct _GIOWin32Channel {
- GIOChannel channel;
- gint fd; /* Either a Unix-like file handle as provided
- * by the Microsoft C runtime, or a SOCKET
- * as provided by WinSock.
- */
- GIOWin32ChannelType type;
-
- /* This is used by G_IO_WINDOWS_MESSAGES channels */
- HWND hwnd; /* handle of window, or NULL */
-
- /* This is used by G_IO_PIPE channels */
- guint peer; /* thread id of reader */
- guint peer_fd; /* fd in the reader */
- guint offset; /* counter of accumulated bytes */
- guint need_wakeups; /* in output channels whether the
- * reader needs wakeups
- */
-};
-
-struct _GIOWin32Watch {
- GPollFD pollfd;
- GIOChannel *channel;
- GIOCondition condition;
- GIOFunc callback;
-};
-
-static gboolean g_io_win32_msg_prepare (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout);
-static gboolean g_io_win32_msg_check (gpointer source_data,
- GTimeVal *current_time);
-static gboolean g_io_win32_msg_dispatch (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data);
-
-static gboolean g_io_win32_fd_prepare (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout);
-static gboolean g_io_win32_fd_check (gpointer source_data,
- GTimeVal *current_time);
-static gboolean g_io_win32_fd_dispatch (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data);
-
-static gboolean g_io_win32_pipe_prepare (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout);
-static gboolean g_io_win32_pipe_check (gpointer source_data,
- GTimeVal *current_time);
-static gboolean g_io_win32_pipe_dispatch (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data);
-static void g_io_win32_pipe_destroy (gpointer source_data);
-
-static gboolean g_io_win32_sock_prepare (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout);
-static gboolean g_io_win32_sock_check (gpointer source_data,
- GTimeVal *current_time);
-static gboolean g_io_win32_sock_dispatch (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data);
-
-static void g_io_win32_destroy (gpointer source_data);
-
-static GIOError g_io_win32_msg_read (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written);
-
-static GIOError g_io_win32_msg_write(GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written);
-static GIOError g_io_win32_msg_seek (GIOChannel *channel,
- gint offset,
- GSeekType type);
-static void g_io_win32_msg_close (GIOChannel *channel);
-static guint g_io_win32_msg_add_watch (GIOChannel *channel,
- gint priority,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data,
- GDestroyNotify notify);
-
-static GIOError g_io_win32_fd_read (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written);
-static GIOError g_io_win32_fd_write(GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written);
-static GIOError g_io_win32_fd_seek (GIOChannel *channel,
- gint offset,
- GSeekType type);
-static void g_io_win32_fd_close (GIOChannel *channel);
-
-static void g_io_win32_free (GIOChannel *channel);
-
-static guint g_io_win32_fd_add_watch (GIOChannel *channel,
- gint priority,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data,
- GDestroyNotify notify);
-
-static GIOError g_io_win32_no_seek (GIOChannel *channel,
- gint offset,
- GSeekType type);
-
-static GIOError g_io_win32_pipe_read (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written);
-static GIOError g_io_win32_pipe_write (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written);
-static void g_io_win32_pipe_close (GIOChannel *channel);
-static guint g_io_win32_pipe_add_watch (GIOChannel *channel,
- gint priority,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data,
- GDestroyNotify notify);
-static void g_io_win32_pipe_free (GIOChannel *channel);
-
-static GIOError g_io_win32_sock_read (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written);
-static GIOError g_io_win32_sock_write(GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written);
-static void g_io_win32_sock_close (GIOChannel *channel);
-static guint g_io_win32_sock_add_watch (GIOChannel *channel,
- gint priority,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data,
- GDestroyNotify notify);
-
-GSourceFuncs win32_watch_msg_funcs = {
- g_io_win32_msg_prepare,
- g_io_win32_msg_check,
- g_io_win32_msg_dispatch,
- g_io_win32_destroy
-};
-
-GSourceFuncs win32_watch_fd_funcs = {
- g_io_win32_fd_prepare,
- g_io_win32_fd_check,
- g_io_win32_fd_dispatch,
- g_io_win32_destroy
-};
-
-GSourceFuncs win32_watch_pipe_funcs = {
- g_io_win32_pipe_prepare,
- g_io_win32_pipe_check,
- g_io_win32_pipe_dispatch,
- g_io_win32_pipe_destroy
-};
-
-GSourceFuncs win32_watch_sock_funcs = {
- g_io_win32_sock_prepare,
- g_io_win32_sock_check,
- g_io_win32_sock_dispatch,
- g_io_win32_destroy
-};
-
-GIOFuncs win32_channel_msg_funcs = {
- g_io_win32_msg_read,
- g_io_win32_msg_write,
- g_io_win32_no_seek,
- g_io_win32_msg_close,
- g_io_win32_msg_add_watch,
- g_io_win32_free
-};
-
-GIOFuncs win32_channel_fd_funcs = {
- g_io_win32_fd_read,
- g_io_win32_fd_write,
- g_io_win32_fd_seek,
- g_io_win32_fd_close,
- g_io_win32_fd_add_watch,
- g_io_win32_free
-};
-
-GIOFuncs win32_channel_pipe_funcs = {
- g_io_win32_pipe_read,
- g_io_win32_pipe_write,
- g_io_win32_no_seek,
- g_io_win32_pipe_close,
- g_io_win32_pipe_add_watch,
- g_io_win32_pipe_free
-};
-
-GIOFuncs win32_channel_sock_funcs = {
- g_io_win32_sock_read,
- g_io_win32_sock_write,
- g_io_win32_no_seek,
- g_io_win32_sock_close,
- g_io_win32_sock_add_watch,
- g_io_win32_free
-};
-
-#define N_WATCHED_PIPES 4
-
-static struct {
- gint fd;
- GIOWin32Watch *watch;
- GIOWin32Channel *channel;
- gpointer user_data;
-} watched_pipes[N_WATCHED_PIPES];
-
-static gint n_watched_pipes = 0;
-
-static gboolean
-g_io_win32_msg_prepare (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout)
-{
- GIOWin32Watch *data = source_data;
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) data->channel;
- MSG msg;
-
- *timeout = -1;
-
- return PeekMessage (&msg, win32_channel->hwnd, 0, 0, PM_NOREMOVE) == TRUE;
-}
-
-static gboolean
-g_io_win32_msg_check (gpointer source_data,
- GTimeVal *current_time)
-{
- GIOWin32Watch *data = source_data;
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) data->channel;
- MSG msg;
-
- return PeekMessage (&msg, win32_channel->hwnd, 0, 0, PM_NOREMOVE) == TRUE;
-}
-
-static gboolean
-g_io_win32_msg_dispatch (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data)
-
-{
- GIOWin32Watch *data = source_data;
-
- return (*data->callback)(data->channel,
- data->pollfd.revents & data->condition,
- user_data);
-}
-
-static void
-g_io_win32_destroy (gpointer source_data)
-{
- GIOWin32Watch *data = source_data;
-
- g_main_remove_poll (&data->pollfd);
- g_io_channel_unref (data->channel);
- g_free (data);
-}
-
-static gboolean
-g_io_win32_fd_prepare (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout)
-{
- *timeout = -1;
-
- return FALSE;
-}
-
-static gboolean
-g_io_win32_fd_check (gpointer source_data,
- GTimeVal *current_time)
-{
- GIOWin32Watch *data = source_data;
-
- return (data->pollfd.revents & data->condition);
-}
-
-static gboolean
-g_io_win32_fd_dispatch (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data)
-
-{
- GIOWin32Watch *data = source_data;
-
- return (*data->callback)(data->channel,
- data->pollfd.revents & data->condition,
- user_data);
-}
-
-static GIOError
-g_io_win32_msg_read (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_read)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
- MSG msg; /* In case of alignment problems */
-
- if (count < sizeof (MSG))
- return G_IO_ERROR_INVAL;
-
- if (!PeekMessage (&msg, win32_channel->hwnd, 0, 0, PM_REMOVE))
- return G_IO_ERROR_AGAIN;
-
- memmove (buf, &msg, sizeof (MSG));
- *bytes_read = sizeof (MSG);
- return G_IO_ERROR_NONE;
-}
-
-static GIOError
-g_io_win32_msg_write(GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
- MSG msg;
- gint result;
-
- if (count != sizeof (MSG))
- return G_IO_ERROR_INVAL;
-
- /* In case of alignment problems */
- memmove (&msg, buf, sizeof (MSG));
- if (!PostMessage (win32_channel->hwnd, msg.message, msg.wParam, msg.lParam))
- return G_IO_ERROR_UNKNOWN;
-
- *bytes_written = sizeof (MSG);
- return G_IO_ERROR_NONE;
-}
-
-static GIOError
-g_io_win32_no_seek (GIOChannel *channel,
- gint offset,
- GSeekType type)
-{
- g_warning ("g_io_win32_no_seek: unseekable IO channel type");
- return G_IO_ERROR_UNKNOWN;
-}
-
-
-static void
-g_io_win32_msg_close (GIOChannel *channel)
-{
- /* Nothing to be done. Or should we set hwnd to some invalid value? */
-}
-
-static void
-g_io_win32_free (GIOChannel *channel)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
-
- g_free (win32_channel);
-}
-
-static guint
-g_io_win32_msg_add_watch (GIOChannel *channel,
- gint priority,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data,
- GDestroyNotify notify)
-{
- GIOWin32Watch *watch = g_new (GIOWin32Watch, 1);
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
-
- watch->channel = channel;
- g_io_channel_ref (channel);
-
- watch->callback = func;
- watch->condition = condition;
-
- watch->pollfd.fd = G_WIN32_MSG_HANDLE;
- watch->pollfd.events = condition;
-
- g_main_add_poll (&watch->pollfd, priority);
-
- return g_source_add (priority, TRUE, &win32_watch_msg_funcs,
- watch, user_data, notify);
-}
-
-static gboolean
-g_io_win32_pipe_prepare (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout)
-{
- *timeout = -1;
-
- return FALSE;
-}
-
-static gboolean
-g_io_win32_pipe_check (gpointer source_data,
- GTimeVal *current_time)
-{
- GIOWin32Watch *data = source_data;
- return FALSE;
-}
-
-static gboolean
-g_io_win32_pipe_dispatch (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data)
-
-{
- GIOWin32Watch *data = source_data;
-
- return (*data->callback)(data->channel,
- data->pollfd.revents & data->condition,
- user_data);
-}
-
-static void
-g_io_win32_pipe_destroy (gpointer source_data)
-{
- GIOWin32Watch *data = source_data;
-
- g_io_channel_unref (data->channel);
- g_free (data);
-}
-
-static gboolean
-g_io_win32_sock_prepare (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout)
-{
- *timeout = -1;
-
- return FALSE;
-}
-
-static gboolean
-g_io_win32_sock_check (gpointer source_data,
- GTimeVal *current_time)
-{
- GIOWin32Watch *data = source_data;
-
- return (data->pollfd.revents & data->condition);
-}
-
-static gboolean
-g_io_win32_sock_dispatch (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data)
-
-{
- GIOWin32Watch *data = source_data;
-
- return (*data->callback)(data->channel,
- data->pollfd.revents & data->condition,
- user_data);
-}
-
-static GIOError
-g_io_win32_fd_read (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_read)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
- gint result;
-
- result = read (win32_channel->fd, buf, count);
- if (result < 0)
- {
- *bytes_read = 0;
- switch (errno)
- {
- case EINVAL:
- return G_IO_ERROR_INVAL;
- case EAGAIN:
- return G_IO_ERROR_AGAIN;
- default:
- return G_IO_ERROR_UNKNOWN;
- }
- }
- else
- {
- *bytes_read = result;
- return G_IO_ERROR_NONE;
- }
-}
-
-static GIOError
-g_io_win32_fd_write(GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
- gint result;
-
- result = write (win32_channel->fd, buf, count);
-
- if (result < 0)
- {
- *bytes_written = 0;
- switch (errno)
- {
- case EINVAL:
- return G_IO_ERROR_INVAL;
- case EAGAIN:
- return G_IO_ERROR_AGAIN;
- default:
- return G_IO_ERROR_UNKNOWN;
- }
- }
- else
- {
- *bytes_written = result;
- return G_IO_ERROR_NONE;
- }
-}
-
-static GIOError
-g_io_win32_fd_seek (GIOChannel *channel,
- gint offset,
- GSeekType type)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
- int whence;
- off_t result;
-
- switch (type)
- {
- case G_SEEK_SET:
- whence = SEEK_SET;
- break;
- case G_SEEK_CUR:
- whence = SEEK_CUR;
- break;
- case G_SEEK_END:
- whence = SEEK_END;
- break;
- default:
- g_warning ("g_io_win32_fd_seek: unknown seek type");
- return G_IO_ERROR_UNKNOWN;
- }
-
- result = lseek (win32_channel->fd, offset, whence);
-
- if (result < 0)
- {
- switch (errno)
- {
- case EINVAL:
- return G_IO_ERROR_INVAL;
- default:
- return G_IO_ERROR_UNKNOWN;
- }
- }
- else
- return G_IO_ERROR_NONE;
-}
-
-static void
-g_io_win32_fd_close (GIOChannel *channel)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
-
- close (win32_channel->fd);
- return;
-}
-
-static guint
-g_io_win32_fd_add_watch (GIOChannel *channel,
- gint priority,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data,
- GDestroyNotify notify)
-{
- GIOWin32Watch *watch = g_new (GIOWin32Watch, 1);
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
-
- watch->channel = channel;
- g_io_channel_ref (channel);
-
- watch->callback = func;
- watch->condition = condition;
-
- /* This probably does not work, except for CONIN$. */
- watch->pollfd.fd = _get_osfhandle (win32_channel->fd);
- watch->pollfd.events = condition;
-
- g_main_add_poll (&watch->pollfd, priority);
-
- return g_source_add (priority, TRUE, &win32_watch_fd_funcs,
- watch, user_data, notify);
-}
-
-static GIOError
-g_io_win32_pipe_read (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_read)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
- HANDLE handle;
- DWORD avail;
- gint result;
-
- handle = (HANDLE) _get_osfhandle (win32_channel->fd);
- if (!PeekNamedPipe (handle, NULL, 0, NULL, &avail, NULL))
- {
- return G_IO_ERROR_UNKNOWN;
- }
-
- count = MIN (count, avail);
-
- count = MAX (count, 1); /* Must read at least one byte, or
- * caller will think it's EOF.
- */
- /* g_print ("g_io_win32_pipe_read: %d %d\n", win32_channel->fd, count); */
- if (count == 0)
- result = 0;
- else
- result = read (win32_channel->fd, buf, count);
- if (result < 0)
- {
- *bytes_read = 0;
- switch (errno)
- {
- case EINVAL:
- return G_IO_ERROR_INVAL;
- case EAGAIN:
- return G_IO_ERROR_AGAIN;
- default:
- return G_IO_ERROR_UNKNOWN;
- }
- }
- else
- {
- *bytes_read = result;
- win32_channel->offset += result;
- /* g_print ("=%d (%d)\n", result, win32_channel->offset); */
- return G_IO_ERROR_NONE;
- }
-}
-
-static GIOError
-g_io_win32_pipe_write(GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
- LONG prevcnt;
- gint result;
-
- /* g_print ("g_io_win32_pipe_write: %d %d\n", win32_channel->fd, count); */
- result = write (win32_channel->fd, buf, count);
- if (result < 0)
- {
- *bytes_written = 0;
- switch (errno)
- {
- case EINVAL:
- return G_IO_ERROR_INVAL;
- case EAGAIN:
- return G_IO_ERROR_AGAIN;
- default:
- return G_IO_ERROR_UNKNOWN;
- }
- }
- else
- {
- if (g_pipe_readable_msg == 0)
- g_pipe_readable_msg = RegisterWindowMessage ("g-pipe-readable");
-
- win32_channel->offset += result;
- /* g_print ("=%d (%d)\n", result, win32_channel->offset); */
- if (win32_channel->need_wakeups)
- {
- PostThreadMessage (win32_channel->peer,
- g_pipe_readable_msg,
- win32_channel->peer_fd,
- win32_channel->offset);
- }
- *bytes_written = result;
- return G_IO_ERROR_NONE;
- }
-}
-
-static void
-g_io_win32_pipe_close (GIOChannel *channel)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
-
- /* g_print ("g_io_win32_pipe_close: %#x %d\n", channel, win32_channel->fd); */
-
- close (win32_channel->fd);
- return;
-}
-
-static guint
-g_io_win32_pipe_add_watch (GIOChannel *channel,
- gint priority,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data,
- GDestroyNotify notify)
-{
- GIOWin32Watch *watch = g_new (GIOWin32Watch, 1);
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
- gint i;
-
- /* g_print ("g_io_win32_pipe_add_watch: %d\n", win32_channel->fd); */
-
- watch->channel = channel;
- g_io_channel_ref (channel);
-
- watch->callback = func;
- watch->condition = condition;
-
- watch->pollfd.fd = win32_channel->fd;
- watch->pollfd.events = condition;
-
- for (i = 0; i < n_watched_pipes; i++)
- if (watched_pipes[i].fd == -1)
- break;
- if (i == N_WATCHED_PIPES)
- g_error ("Too many watched pipes");
- else
- {
- watched_pipes[i].fd = win32_channel->fd;
- watched_pipes[i].watch = watch;
- watched_pipes[i].channel = win32_channel;
- watched_pipes[i].user_data = user_data;
- n_watched_pipes = MAX (i + 1, n_watched_pipes);
- }
- return g_source_add (priority, FALSE, &win32_watch_pipe_funcs, watch, user_data, notify);
-}
-
-static void
-g_io_win32_pipe_free (GIOChannel *channel)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
- gint i;
-
- /* g_print ("g_io_win32_pipe_free: %#x %#x\n", channel, channel->channel_data); */
-
- for (i = 0; i < n_watched_pipes; i++)
- if (watched_pipes[i].fd == win32_channel->fd)
- {
- watched_pipes[i].fd = -1;
- break;
- }
- g_io_win32_free (channel);
-}
-
-static GIOError
-g_io_win32_sock_read (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_read)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
- gint result;
-
- result = recv (win32_channel->fd, buf, count, 0);
- if (result == SOCKET_ERROR)
- {
- *bytes_read = 0;
- switch (WSAGetLastError ())
- {
- case WSAEINVAL:
- return G_IO_ERROR_INVAL;
- case WSAEWOULDBLOCK:
- case WSAEINTR:
- return G_IO_ERROR_AGAIN;
- default:
- return G_IO_ERROR_UNKNOWN;
- }
- }
- else
- {
- *bytes_read = result;
- return G_IO_ERROR_NONE;
- }
-}
-
-static GIOError
-g_io_win32_sock_write(GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
- gint result;
-
- result = send (win32_channel->fd, buf, count, 0);
-
- if (result == SOCKET_ERROR)
- {
- *bytes_written = 0;
- switch (WSAGetLastError ())
- {
- case WSAEINVAL:
- return G_IO_ERROR_INVAL;
- case WSAEWOULDBLOCK:
- case WSAEINTR:
- return G_IO_ERROR_AGAIN;
- default:
- return G_IO_ERROR_UNKNOWN;
- }
- }
- else
- {
- *bytes_written = result;
- return G_IO_ERROR_NONE;
- }
-}
-
-static void
-g_io_win32_sock_close (GIOChannel *channel)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
-
- closesocket (win32_channel->fd);
- return;
-}
-
-static guint
-g_io_win32_sock_add_watch (GIOChannel *channel,
- gint priority,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data,
- GDestroyNotify notify)
-{
- GIOWin32Watch *watch = g_new (GIOWin32Watch, 1);
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
-
- watch->channel = channel;
- g_io_channel_ref (channel);
-
- watch->callback = func;
- watch->condition = condition;
-
- watch->pollfd.fd = win32_channel->fd;
- watch->pollfd.events = condition;
-
- g_main_add_poll (&watch->pollfd, priority);
-
- return g_source_add (priority, TRUE, &win32_watch_sock_funcs, watch, user_data, notify);
-}
-
-GIOChannel *
-g_io_channel_win32_new_messages (guint hwnd)
-{
- GIOWin32Channel *win32_channel = g_new (GIOWin32Channel, 1);
- GIOChannel *channel = (GIOChannel *) win32_channel;
-
- g_io_channel_init (channel);
- channel->funcs = &win32_channel_msg_funcs;
- win32_channel->fd = -1;
- win32_channel->type = G_IO_WINDOWS_MESSAGES;
- win32_channel->hwnd = (HWND) hwnd;
-
- return channel;
-}
-
-GIOChannel *
-g_io_channel_unix_new (gint fd)
-{
- GIOWin32Channel *win32_channel = g_new (GIOWin32Channel, 1);
- GIOChannel *channel = (GIOChannel *) win32_channel;
-
- g_io_channel_init (channel);
- channel->funcs = &win32_channel_fd_funcs;
- win32_channel->fd = fd;
- win32_channel->type = G_IO_FILE_DESC;
-
- return channel;
-}
-
-gint
-g_io_channel_unix_get_fd (GIOChannel *channel)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
-
- return win32_channel->fd;
-}
-
-GIOChannel *
-g_io_channel_win32_new_pipe_with_wakeups (int fd,
- guint peer,
- int peer_fd)
-{
- GIOWin32Channel *win32_channel = g_new (GIOWin32Channel, 1);
- GIOChannel *channel = (GIOChannel *) win32_channel;
-
- /* g_print ("g_io_channel_win32_new_pipe_with_wakeups %d %#x %d\n", fd, peer, peer_fd); */
-
- g_io_channel_init (channel);
- channel->funcs = &win32_channel_pipe_funcs;
- win32_channel->fd = fd;
- win32_channel->type = G_IO_PIPE;
- win32_channel->peer = peer;
- win32_channel->peer_fd = peer_fd;
- win32_channel->offset = 0;
- win32_channel->need_wakeups = TRUE;
-
- return channel;
-}
-
-GIOChannel *
-g_io_channel_win32_new_pipe (int fd)
-{
- GIOWin32Channel *win32_channel = g_new (GIOWin32Channel, 1);
- GIOChannel *channel = (GIOChannel *) win32_channel;
-
- g_io_channel_init (channel);
- channel->funcs = &win32_channel_pipe_funcs;
- win32_channel->fd = fd;
- win32_channel->type = G_IO_PIPE;
- win32_channel->offset = 0;
- win32_channel->need_wakeups = FALSE;
-
- return channel;
-}
-
-GIOChannel *
-g_io_channel_win32_new_stream_socket (int socket)
-{
- GIOWin32Channel *win32_channel = g_new (GIOWin32Channel, 1);
- GIOChannel *channel = (GIOChannel *) win32_channel;
-
- g_io_channel_init (channel);
- channel->funcs = &win32_channel_sock_funcs;
- win32_channel->fd = socket;
- win32_channel->type = G_IO_STREAM_SOCKET;
-
- return channel;
-}
-
-gint
-g_io_channel_win32_get_fd (GIOChannel *channel)
-{
- return g_io_channel_unix_get_fd (channel);
-}
-
-void
-g_io_channel_win32_pipe_request_wakeups (GIOChannel *channel,
- guint peer,
- int peer_fd)
-{
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
-
- win32_channel->peer = peer;
- win32_channel->peer_fd = peer_fd;
- win32_channel->need_wakeups = TRUE;
-}
-
-void
-g_io_channel_win32_pipe_readable (gint fd,
- guint offset)
-{
- gint i;
-
- for (i = 0; i < n_watched_pipes; i++)
- if (watched_pipes[i].fd == fd)
- {
- if (watched_pipes[i].channel->offset < offset)
- (*watched_pipes[i].watch->callback) (watched_pipes[i].watch->channel,
- G_IO_IN,
- watched_pipes[i].user_data);
- break;
- }
-}
diff --git a/glib/glib.h b/glib/glib.h
deleted file mode 100644
index b83cf5db3..000000000
--- a/glib/glib.h
+++ /dev/null
@@ -1,2827 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#ifndef __G_LIB_H__
-#define __G_LIB_H__
-
-/* system specific config file glibconfig.h provides definitions for
- * the extrema of many of the standard types. These are:
- *
- * G_MINSHORT, G_MAXSHORT
- * G_MININT, G_MAXINT
- * G_MINLONG, G_MAXLONG
- * G_MINFLOAT, G_MAXFLOAT
- * G_MINDOUBLE, G_MAXDOUBLE
- *
- * It also provides the following typedefs:
- *
- * gint8, guint8
- * gint16, guint16
- * gint32, guint32
- * gint64, guint64
- *
- * It defines the G_BYTE_ORDER symbol to one of G_*_ENDIAN (see later in
- * this file).
- *
- * And it provides a way to store and retrieve a `gint' in/from a `gpointer'.
- * This is useful to pass an integer instead of a pointer to a callback.
- *
- * GINT_TO_POINTER(i), GUINT_TO_POINTER(i)
- * GPOINTER_TO_INT(p), GPOINTER_TO_UINT(p)
- *
- * Finally, it provide the following wrappers to STDC functions:
- *
- * g_ATEXIT
- * To register hooks which are executed on exit().
- * Usually a wrapper for STDC atexit.
- *
- * void *g_memmove(void *dest, const void *src, guint count);
- * A wrapper for STDC memmove, or an implementation, if memmove doesn't
- * exist. The prototype looks like the above, give or take a const,
- * or size_t.
- */
-#include <glibconfig.h>
-
-/* include varargs functions for assertment macros
- */
-#include <stdarg.h>
-
-/* optionally feature DMALLOC memory allocation debugger
- */
-#ifdef USE_DMALLOC
-#include "dmalloc.h"
-#endif
-
-
-#ifdef NATIVE_WIN32
-
-/* On native Win32, directory separator is the backslash, and search path
- * separator is the semicolon.
- */
-#define G_DIR_SEPARATOR '\\'
-#define G_DIR_SEPARATOR_S "\\"
-#define G_SEARCHPATH_SEPARATOR ';'
-#define G_SEARCHPATH_SEPARATOR_S ";"
-
-#else /* !NATIVE_WIN32 */
-
-#ifndef __EMX__
-/* Unix */
-
-#define G_DIR_SEPARATOR '/'
-#define G_DIR_SEPARATOR_S "/"
-#define G_SEARCHPATH_SEPARATOR ':'
-#define G_SEARCHPATH_SEPARATOR_S ":"
-
-#else
-/* EMX/OS2 */
-
-#define G_DIR_SEPARATOR '/'
-#define G_DIR_SEPARATOR_S "/"
-#define G_SEARCHPATH_SEPARATOR ';'
-#define G_SEARCHPATH_SEPARATOR_S ";"
-
-#endif
-
-#endif /* !NATIVE_WIN32 */
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-
-/* Provide definitions for some commonly used macros.
- * Some of them are only provided if they haven't already
- * been defined. It is assumed that if they are already
- * defined then the current definition is correct.
- */
-#ifndef NULL
-#define NULL ((void*) 0)
-#endif
-
-#ifndef FALSE
-#define FALSE (0)
-#endif
-
-#ifndef TRUE
-#define TRUE (!FALSE)
-#endif
-
-#undef MAX
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-
-#undef MIN
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-
-#undef ABS
-#define ABS(a) (((a) < 0) ? -(a) : (a))
-
-#undef CLAMP
-#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
-
-
-/* Define G_VA_COPY() to do the right thing for copying va_list variables.
- * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.
- */
-#if !defined (G_VA_COPY)
-# if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
-# define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
-# elif defined (G_VA_COPY_AS_ARRAY)
-# define G_VA_COPY(ap1, ap2) g_memmove ((ap1), (ap2), sizeof (va_list))
-# else /* va_list is a pointer */
-# define G_VA_COPY(ap1, ap2) ((ap1) = (ap2))
-# endif /* va_list is a pointer */
-#endif /* !G_VA_COPY */
-
-
-/* Provide convenience macros for handling structure
- * fields through their offsets.
- */
-#define G_STRUCT_OFFSET(struct_type, member) \
- ((gulong) ((gchar*) &((struct_type*) 0)->member))
-#define G_STRUCT_MEMBER_P(struct_p, struct_offset) \
- ((gpointer) ((gchar*) (struct_p) + (gulong) (struct_offset)))
-#define G_STRUCT_MEMBER(member_type, struct_p, struct_offset) \
- (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
-
-
-/* inlining hassle. for compilers that don't allow the `inline' keyword,
- * mostly because of strict ANSI C compliance or dumbness, we try to fall
- * back to either `__inline__' or `__inline'.
- * we define G_CAN_INLINE, if the compiler seems to be actually
- * *capable* to do function inlining, in which case inline function bodys
- * do make sense. we also define G_INLINE_FUNC to properly export the
- * function prototypes if no inlining can be performed.
- * we special case most of the stuff, so inline functions can have a normal
- * implementation by defining G_INLINE_FUNC to extern and G_CAN_INLINE to 1.
- */
-#ifndef G_INLINE_FUNC
-# define G_CAN_INLINE 1
-#endif
-#ifdef G_HAVE_INLINE
-# if defined (__GNUC__) && defined (__STRICT_ANSI__)
-# undef inline
-# define inline __inline__
-# endif
-#else /* !G_HAVE_INLINE */
-# undef inline
-# if defined (G_HAVE___INLINE__)
-# define inline __inline__
-# else /* !inline && !__inline__ */
-# if defined (G_HAVE___INLINE)
-# define inline __inline
-# else /* !inline && !__inline__ && !__inline */
-# define inline /* don't inline, then */
-# ifndef G_INLINE_FUNC
-# undef G_CAN_INLINE
-# endif
-# endif
-# endif
-#endif
-#ifndef G_INLINE_FUNC
-# ifdef __GNUC__
-# ifdef __OPTIMIZE__
-# define G_INLINE_FUNC extern inline
-# else
-# undef G_CAN_INLINE
-# define G_INLINE_FUNC extern
-# endif
-# else /* !__GNUC__ */
-# ifdef G_CAN_INLINE
-# define G_INLINE_FUNC static inline
-# else
-# define G_INLINE_FUNC extern
-# endif
-# endif /* !__GNUC__ */
-#endif /* !G_INLINE_FUNC */
-
-
-/* Provide simple macro statement wrappers (adapted from Perl):
- * G_STMT_START { statements; } G_STMT_END;
- * can be used as a single statement, as in
- * if (x) G_STMT_START { ... } G_STMT_END; else ...
- *
- * For gcc we will wrap the statements within `({' and `})' braces.
- * For SunOS they will be wrapped within `if (1)' and `else (void) 0',
- * and otherwise within `do' and `while (0)'.
- */
-#if !(defined (G_STMT_START) && defined (G_STMT_END))
-# if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
-# define G_STMT_START (void)(
-# define G_STMT_END )
-# else
-# if (defined (sun) || defined (__sun__))
-# define G_STMT_START if (1)
-# define G_STMT_END else (void)0
-# else
-# define G_STMT_START do
-# define G_STMT_END while (0)
-# endif
-# endif
-#endif
-
-
-/* Provide macros to feature the GCC function attribute.
- */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
-#define G_GNUC_PRINTF( format_idx, arg_idx ) \
- __attribute__((format (printf, format_idx, arg_idx)))
-#define G_GNUC_SCANF( format_idx, arg_idx ) \
- __attribute__((format (scanf, format_idx, arg_idx)))
-#define G_GNUC_FORMAT( arg_idx ) \
- __attribute__((format_arg (arg_idx)))
-#define G_GNUC_NORETURN \
- __attribute__((noreturn))
-#define G_GNUC_CONST \
- __attribute__((const))
-#define G_GNUC_UNUSED \
- __attribute__((unused))
-#else /* !__GNUC__ */
-#define G_GNUC_PRINTF( format_idx, arg_idx )
-#define G_GNUC_SCANF( format_idx, arg_idx )
-#define G_GNUC_FORMAT( arg_idx )
-#define G_GNUC_NORETURN
-#define G_GNUC_CONST
-#define G_GNUC_UNUSED
-#endif /* !__GNUC__ */
-
-
-/* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
- * macros, so we can refer to them as strings unconditionally.
- */
-#ifdef __GNUC__
-#define G_GNUC_FUNCTION __FUNCTION__
-#define G_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__
-#else /* !__GNUC__ */
-#define G_GNUC_FUNCTION ""
-#define G_GNUC_PRETTY_FUNCTION ""
-#endif /* !__GNUC__ */
-
-/* we try to provide a usefull equivalent for ATEXIT if it is
- * not defined, but use is actually abandoned. people should
- * use g_atexit() instead.
- */
-#ifndef ATEXIT
-# define ATEXIT(proc) g_ATEXIT(proc)
-#else
-# define G_NATIVE_ATEXIT
-#endif /* ATEXIT */
-
-/* Hacker macro to place breakpoints for elected machines.
- * Actual use is strongly deprecated of course ;)
- */
-#if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2
-#define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("int $03"); }G_STMT_END
-#elif defined (__alpha__) && defined (__GNUC__) && __GNUC__ >= 2
-#define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("bpt"); }G_STMT_END
-#else /* !__i386__ && !__alpha__ */
-#define G_BREAKPOINT()
-#endif /* __i386__ */
-
-
-/* Provide macros for easily allocating memory. The macros
- * will cast the allocated memory to the specified type
- * in order to avoid compiler warnings. (Makes the code neater).
- */
-
-#ifdef __DMALLOC_H__
-# define g_new(type, count) (ALLOC (type, count))
-# define g_new0(type, count) (CALLOC (type, count))
-# define g_renew(type, mem, count) (REALLOC (mem, type, count))
-#else /* __DMALLOC_H__ */
-# define g_new(type, count) \
- ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
-# define g_new0(type, count) \
- ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
-# define g_renew(type, mem, count) \
- ((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
-#endif /* __DMALLOC_H__ */
-
-#define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
- g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
- sizeof (type), \
- sizeof (type) * (pre_alloc), \
- (alloc_type)) \
-)
-#define g_chunk_new(type, chunk) ( \
- (type *) g_mem_chunk_alloc (chunk) \
-)
-#define g_chunk_new0(type, chunk) ( \
- (type *) g_mem_chunk_alloc0 (chunk) \
-)
-#define g_chunk_free(mem, mem_chunk) G_STMT_START { \
- g_mem_chunk_free ((mem_chunk), (mem)); \
-} G_STMT_END
-
-
-#define g_string(x) #x
-
-
-/* Provide macros for error handling. The "assert" macros will
- * exit on failure. The "return" macros will exit the current
- * function. Two different definitions are given for the macros
- * if G_DISABLE_ASSERT is not defined, in order to support gcc's
- * __PRETTY_FUNCTION__ capability.
- */
-
-#ifdef G_DISABLE_ASSERT
-
-#define g_assert(expr)
-#define g_assert_not_reached()
-
-#else /* !G_DISABLE_ASSERT */
-
-#ifdef __GNUC__
-
-#define g_assert(expr) G_STMT_START{ \
- if (!(expr)) \
- g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_ERROR, \
- "file %s: line %d (%s): assertion failed: (%s)", \
- __FILE__, \
- __LINE__, \
- __PRETTY_FUNCTION__, \
- #expr); }G_STMT_END
-
-#define g_assert_not_reached() G_STMT_START{ \
- g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_ERROR, \
- "file %s: line %d (%s): should not be reached", \
- __FILE__, \
- __LINE__, \
- __PRETTY_FUNCTION__); }G_STMT_END
-
-#else /* !__GNUC__ */
-
-#define g_assert(expr) G_STMT_START{ \
- if (!(expr)) \
- g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_ERROR, \
- "file %s: line %d: assertion failed: (%s)", \
- __FILE__, \
- __LINE__, \
- #expr); }G_STMT_END
-
-#define g_assert_not_reached() G_STMT_START{ \
- g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_ERROR, \
- "file %s: line %d: should not be reached", \
- __FILE__, \
- __LINE__); }G_STMT_END
-
-#endif /* __GNUC__ */
-
-#endif /* !G_DISABLE_ASSERT */
-
-
-#ifdef G_DISABLE_CHECKS
-
-#define g_return_if_fail(expr)
-#define g_return_val_if_fail(expr,val)
-
-#else /* !G_DISABLE_CHECKS */
-
-#ifdef __GNUC__
-
-#define g_return_if_fail(expr) G_STMT_START{ \
- if (!(expr)) \
- { \
- g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_CRITICAL, \
- "file %s: line %d (%s): assertion `%s' failed.", \
- __FILE__, \
- __LINE__, \
- __PRETTY_FUNCTION__, \
- #expr); \
- return; \
- }; }G_STMT_END
-
-#define g_return_val_if_fail(expr,val) G_STMT_START{ \
- if (!(expr)) \
- { \
- g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_CRITICAL, \
- "file %s: line %d (%s): assertion `%s' failed.", \
- __FILE__, \
- __LINE__, \
- __PRETTY_FUNCTION__, \
- #expr); \
- return val; \
- }; }G_STMT_END
-
-#else /* !__GNUC__ */
-
-#define g_return_if_fail(expr) G_STMT_START{ \
- if (!(expr)) \
- { \
- g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_CRITICAL, \
- "file %s: line %d: assertion `%s' failed.", \
- __FILE__, \
- __LINE__, \
- #expr); \
- return; \
- }; }G_STMT_END
-
-#define g_return_val_if_fail(expr, val) G_STMT_START{ \
- if (!(expr)) \
- { \
- g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_CRITICAL, \
- "file %s: line %d: assertion `%s' failed.", \
- __FILE__, \
- __LINE__, \
- #expr); \
- return val; \
- }; }G_STMT_END
-
-#endif /* !__GNUC__ */
-
-#endif /* !G_DISABLE_CHECKS */
-
-
-/* Provide type definitions for commonly used types.
- * These are useful because a "gint8" can be adjusted
- * to be 1 byte (8 bits) on all platforms. Similarly and
- * more importantly, "gint32" can be adjusted to be
- * 4 bytes (32 bits) on all platforms.
- */
-
-typedef char gchar;
-typedef short gshort;
-typedef long glong;
-typedef int gint;
-typedef gint gboolean;
-
-typedef unsigned char guchar;
-typedef unsigned short gushort;
-typedef unsigned long gulong;
-typedef unsigned int guint;
-
-typedef float gfloat;
-typedef double gdouble;
-
-/* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
- * Since gldouble isn't used anywhere, just disable it for now */
-
-#if 0
-#ifdef HAVE_LONG_DOUBLE
-typedef long double gldouble;
-#else /* HAVE_LONG_DOUBLE */
-typedef double gldouble;
-#endif /* HAVE_LONG_DOUBLE */
-#endif /* 0 */
-
-typedef void* gpointer;
-typedef const void *gconstpointer;
-
-
-typedef gint32 gssize;
-typedef guint32 gsize;
-typedef guint32 GQuark;
-typedef gint32 GTime;
-
-
-/* Portable endian checks and conversions
- *
- * glibconfig.h defines G_BYTE_ORDER which expands to one of
- * the below macros.
- */
-#define G_LITTLE_ENDIAN 1234
-#define G_BIG_ENDIAN 4321
-#define G_PDP_ENDIAN 3412 /* unused, need specific PDP check */
-
-
-/* Basic bit swapping functions
- */
-#define GUINT16_SWAP_LE_BE_CONSTANT(val) ((guint16) ( \
- (((guint16) (val) & (guint16) 0x00ffU) << 8) | \
- (((guint16) (val) & (guint16) 0xff00U) >> 8)))
-#define GUINT32_SWAP_LE_BE_CONSTANT(val) ((guint32) ( \
- (((guint32) (val) & (guint32) 0x000000ffU) << 24) | \
- (((guint32) (val) & (guint32) 0x0000ff00U) << 8) | \
- (((guint32) (val) & (guint32) 0x00ff0000U) >> 8) | \
- (((guint32) (val) & (guint32) 0xff000000U) >> 24)))
-
-/* Intel specific stuff for speed
- */
-#if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2
-# define GUINT16_SWAP_LE_BE_X86(val) \
- (__extension__ \
- ({ register guint16 __v; \
- if (__builtin_constant_p (val)) \
- __v = GUINT16_SWAP_LE_BE_CONSTANT (val); \
- else \
- __asm__ __const__ ("rorw $8, %w0" \
- : "=r" (__v) \
- : "0" ((guint16) (val))); \
- __v; }))
-# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_X86 (val))
-# if !defined(__i486__) && !defined(__i586__) \
- && !defined(__pentium__) && !defined(__i686__) && !defined(__pentiumpro__)
-# define GUINT32_SWAP_LE_BE_X86(val) \
- (__extension__ \
- ({ register guint32 __v; \
- if (__builtin_constant_p (val)) \
- __v = GUINT32_SWAP_LE_BE_CONSTANT (val); \
- else \
- __asm__ __const__ ("rorw $8, %w0\n\t" \
- "rorl $16, %0\n\t" \
- "rorw $8, %w0" \
- : "=r" (__v) \
- : "0" ((guint32) (val))); \
- __v; }))
-# else /* 486 and higher has bswap */
-# define GUINT32_SWAP_LE_BE_X86(val) \
- (__extension__ \
- ({ register guint32 __v; \
- if (__builtin_constant_p (val)) \
- __v = GUINT32_SWAP_LE_BE_CONSTANT (val); \
- else \
- __asm__ __const__ ("bswap %0" \
- : "=r" (__v) \
- : "0" ((guint32) (val))); \
- __v; }))
-# endif /* processor specific 32-bit stuff */
-# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_X86 (val))
-#else /* !__i386__ */
-# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
-# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val))
-#endif /* __i386__ */
-
-#ifdef G_HAVE_GINT64
-# define GUINT64_SWAP_LE_BE_CONSTANT(val) ((guint64) ( \
- (((guint64) (val) & \
- (guint64) G_GINT64_CONSTANT(0x00000000000000ffU)) << 56) | \
- (((guint64) (val) & \
- (guint64) G_GINT64_CONSTANT(0x000000000000ff00U)) << 40) | \
- (((guint64) (val) & \
- (guint64) G_GINT64_CONSTANT(0x0000000000ff0000U)) << 24) | \
- (((guint64) (val) & \
- (guint64) G_GINT64_CONSTANT(0x00000000ff000000U)) << 8) | \
- (((guint64) (val) & \
- (guint64) G_GINT64_CONSTANT(0x000000ff00000000U)) >> 8) | \
- (((guint64) (val) & \
- (guint64) G_GINT64_CONSTANT(0x0000ff0000000000U)) >> 24) | \
- (((guint64) (val) & \
- (guint64) G_GINT64_CONSTANT(0x00ff000000000000U)) >> 40) | \
- (((guint64) (val) & \
- (guint64) G_GINT64_CONSTANT(0xff00000000000000U)) >> 56)))
-# if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2
-# define GUINT64_SWAP_LE_BE_X86(val) \
- (__extension__ \
- ({ union { guint64 __ll; \
- guint32 __l[2]; } __r; \
- if (__builtin_constant_p (val)) \
- __r.__ll = GUINT64_SWAP_LE_BE_CONSTANT (val); \
- else \
- { \
- union { guint64 __ll; \
- guint32 __l[2]; } __w; \
- __w.__ll = ((guint64) val); \
- __r.__l[0] = GUINT32_SWAP_LE_BE (__w.__l[1]); \
- __r.__l[1] = GUINT32_SWAP_LE_BE (__w.__l[0]); \
- } \
- __r.__ll; }))
-# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_X86 (val))
-# else /* !__i386__ */
-# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT(val))
-# endif
-#endif
-
-#define GUINT16_SWAP_LE_PDP(val) ((guint16) (val))
-#define GUINT16_SWAP_BE_PDP(val) (GUINT16_SWAP_LE_BE (val))
-#define GUINT32_SWAP_LE_PDP(val) ((guint32) ( \
- (((guint32) (val) & (guint32) 0x0000ffffU) << 16) | \
- (((guint32) (val) & (guint32) 0xffff0000U) >> 16)))
-#define GUINT32_SWAP_BE_PDP(val) ((guint32) ( \
- (((guint32) (val) & (guint32) 0x00ff00ffU) << 8) | \
- (((guint32) (val) & (guint32) 0xff00ff00U) >> 8)))
-
-/* The G*_TO_?E() macros are defined in glibconfig.h.
- * The transformation is symmetric, so the FROM just maps to the TO.
- */
-#define GINT16_FROM_LE(val) (GINT16_TO_LE (val))
-#define GUINT16_FROM_LE(val) (GUINT16_TO_LE (val))
-#define GINT16_FROM_BE(val) (GINT16_TO_BE (val))
-#define GUINT16_FROM_BE(val) (GUINT16_TO_BE (val))
-#define GINT32_FROM_LE(val) (GINT32_TO_LE (val))
-#define GUINT32_FROM_LE(val) (GUINT32_TO_LE (val))
-#define GINT32_FROM_BE(val) (GINT32_TO_BE (val))
-#define GUINT32_FROM_BE(val) (GUINT32_TO_BE (val))
-
-#ifdef G_HAVE_GINT64
-#define GINT64_FROM_LE(val) (GINT64_TO_LE (val))
-#define GUINT64_FROM_LE(val) (GUINT64_TO_LE (val))
-#define GINT64_FROM_BE(val) (GINT64_TO_BE (val))
-#define GUINT64_FROM_BE(val) (GUINT64_TO_BE (val))
-#endif
-
-#define GLONG_FROM_LE(val) (GLONG_TO_LE (val))
-#define GULONG_FROM_LE(val) (GULONG_TO_LE (val))
-#define GLONG_FROM_BE(val) (GLONG_TO_BE (val))
-#define GULONG_FROM_BE(val) (GULONG_TO_BE (val))
-
-#define GINT_FROM_LE(val) (GINT_TO_LE (val))
-#define GUINT_FROM_LE(val) (GUINT_TO_LE (val))
-#define GINT_FROM_BE(val) (GINT_TO_BE (val))
-#define GUINT_FROM_BE(val) (GUINT_TO_BE (val))
-
-
-/* Portable versions of host-network order stuff
- */
-#define g_ntohl(val) (GUINT32_FROM_BE (val))
-#define g_ntohs(val) (GUINT16_FROM_BE (val))
-#define g_htonl(val) (GUINT32_TO_BE (val))
-#define g_htons(val) (GUINT16_TO_BE (val))
-
-
-/* Glib version.
- * we prefix variable declarations so they can
- * properly get exported in windows dlls.
- */
-#ifdef NATIVE_WIN32
-# ifdef GLIB_COMPILATION
-# define GUTILS_C_VAR __declspec(dllexport)
-# else /* !GLIB_COMPILATION */
-# define GUTILS_C_VAR extern __declspec(dllimport)
-# endif /* !GLIB_COMPILATION */
-#else /* !NATIVE_WIN32 */
-# define GUTILS_C_VAR extern
-#endif /* !NATIVE_WIN32 */
-
-GUTILS_C_VAR const guint glib_major_version;
-GUTILS_C_VAR const guint glib_minor_version;
-GUTILS_C_VAR const guint glib_micro_version;
-GUTILS_C_VAR const guint glib_interface_age;
-GUTILS_C_VAR const guint glib_binary_age;
-
-#define GLIB_CHECK_VERSION(major,minor,micro) \
- (GLIB_MAJOR_VERSION > (major) || \
- (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION > (minor)) || \
- (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION == (minor) && \
- GLIB_MICRO_VERSION >= (micro)))
-
-/* Forward declarations of glib types.
- */
-typedef struct _GAllocator GAllocator;
-typedef struct _GArray GArray;
-typedef struct _GByteArray GByteArray;
-typedef struct _GCache GCache;
-typedef struct _GCompletion GCompletion;
-typedef struct _GData GData;
-typedef struct _GDebugKey GDebugKey;
-typedef struct _GHashTable GHashTable;
-typedef struct _GHook GHook;
-typedef struct _GHookList GHookList;
-typedef struct _GList GList;
-typedef struct _GMemChunk GMemChunk;
-typedef struct _GNode GNode;
-typedef struct _GPtrArray GPtrArray;
-typedef struct _GRelation GRelation;
-typedef struct _GScanner GScanner;
-typedef struct _GScannerConfig GScannerConfig;
-typedef struct _GSList GSList;
-typedef struct _GString GString;
-typedef struct _GStringChunk GStringChunk;
-typedef struct _GTimer GTimer;
-typedef struct _GTree GTree;
-typedef struct _GTuples GTuples;
-typedef union _GTokenValue GTokenValue;
-typedef struct _GIOChannel GIOChannel;
-
-/* Tree traverse flags */
-typedef enum
-{
- G_TRAVERSE_LEAFS = 1 << 0,
- G_TRAVERSE_NON_LEAFS = 1 << 1,
- G_TRAVERSE_ALL = G_TRAVERSE_LEAFS | G_TRAVERSE_NON_LEAFS,
- G_TRAVERSE_MASK = 0x03
-} GTraverseFlags;
-
-/* Tree traverse orders */
-typedef enum
-{
- G_IN_ORDER,
- G_PRE_ORDER,
- G_POST_ORDER,
- G_LEVEL_ORDER
-} GTraverseType;
-
-/* Log level shift offset for user defined
- * log levels (0-7 are used by GLib).
- */
-#define G_LOG_LEVEL_USER_SHIFT (8)
-
-/* Glib log levels and flags.
- */
-typedef enum
-{
- /* log flags */
- G_LOG_FLAG_RECURSION = 1 << 0,
- G_LOG_FLAG_FATAL = 1 << 1,
-
- /* GLib log levels */
- G_LOG_LEVEL_ERROR = 1 << 2, /* always fatal */
- G_LOG_LEVEL_CRITICAL = 1 << 3,
- G_LOG_LEVEL_WARNING = 1 << 4,
- G_LOG_LEVEL_MESSAGE = 1 << 5,
- G_LOG_LEVEL_INFO = 1 << 6,
- G_LOG_LEVEL_DEBUG = 1 << 7,
-
- G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
-} GLogLevelFlags;
-
-/* GLib log levels that are considered fatal by default */
-#define G_LOG_FATAL_MASK (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
-
-
-typedef gpointer (*GCacheNewFunc) (gpointer key);
-typedef gpointer (*GCacheDupFunc) (gpointer value);
-typedef void (*GCacheDestroyFunc) (gpointer value);
-typedef gint (*GCompareFunc) (gconstpointer a,
- gconstpointer b);
-typedef gchar* (*GCompletionFunc) (gpointer);
-typedef void (*GDestroyNotify) (gpointer data);
-typedef void (*GDataForeachFunc) (GQuark key_id,
- gpointer data,
- gpointer user_data);
-typedef void (*GFunc) (gpointer data,
- gpointer user_data);
-typedef guint (*GHashFunc) (gconstpointer key);
-typedef void (*GFreeFunc) (gpointer data);
-typedef void (*GHFunc) (gpointer key,
- gpointer value,
- gpointer user_data);
-typedef gboolean (*GHRFunc) (gpointer key,
- gpointer value,
- gpointer user_data);
-typedef gint (*GHookCompareFunc) (GHook *new_hook,
- GHook *sibling);
-typedef gboolean (*GHookFindFunc) (GHook *hook,
- gpointer data);
-typedef void (*GHookMarshaller) (GHook *hook,
- gpointer data);
-typedef gboolean (*GHookCheckMarshaller) (GHook *hook,
- gpointer data);
-typedef void (*GHookFunc) (gpointer data);
-typedef gboolean (*GHookCheckFunc) (gpointer data);
-typedef void (*GHookFreeFunc) (GHookList *hook_list,
- GHook *hook);
-typedef void (*GLogFunc) (const gchar *log_domain,
- GLogLevelFlags log_level,
- const gchar *message,
- gpointer user_data);
-typedef gboolean (*GNodeTraverseFunc) (GNode *node,
- gpointer data);
-typedef void (*GNodeForeachFunc) (GNode *node,
- gpointer data);
-typedef gint (*GSearchFunc) (gpointer key,
- gpointer data);
-typedef void (*GScannerMsgFunc) (GScanner *scanner,
- gchar *message,
- gint error);
-typedef gint (*GTraverseFunc) (gpointer key,
- gpointer value,
- gpointer data);
-typedef void (*GVoidFunc) (void);
-
-
-struct _GList
-{
- gpointer data;
- GList *next;
- GList *prev;
-};
-
-struct _GSList
-{
- gpointer data;
- GSList *next;
-};
-
-struct _GString
-{
- gchar *str;
- gint len;
-};
-
-struct _GArray
-{
- gchar *data;
- guint len;
-};
-
-struct _GByteArray
-{
- guint8 *data;
- guint len;
-};
-
-struct _GPtrArray
-{
- gpointer *pdata;
- guint len;
-};
-
-struct _GTuples
-{
- guint len;
-};
-
-struct _GDebugKey
-{
- gchar *key;
- guint value;
-};
-
-
-/* Doubly linked lists
- */
-void g_list_push_allocator (GAllocator *allocator);
-void g_list_pop_allocator (void);
-GList* g_list_alloc (void);
-void g_list_free (GList *list);
-void g_list_free_1 (GList *list);
-GList* g_list_append (GList *list,
- gpointer data);
-GList* g_list_prepend (GList *list,
- gpointer data);
-GList* g_list_insert (GList *list,
- gpointer data,
- gint position);
-GList* g_list_insert_sorted (GList *list,
- gpointer data,
- GCompareFunc func);
-GList* g_list_concat (GList *list1,
- GList *list2);
-GList* g_list_remove (GList *list,
- gpointer data);
-GList* g_list_remove_link (GList *list,
- GList *llink);
-GList* g_list_reverse (GList *list);
-GList* g_list_copy (GList *list);
-GList* g_list_nth (GList *list,
- guint n);
-GList* g_list_find (GList *list,
- gpointer data);
-GList* g_list_find_custom (GList *list,
- gpointer data,
- GCompareFunc func);
-gint g_list_position (GList *list,
- GList *llink);
-gint g_list_index (GList *list,
- gpointer data);
-GList* g_list_last (GList *list);
-GList* g_list_first (GList *list);
-guint g_list_length (GList *list);
-void g_list_foreach (GList *list,
- GFunc func,
- gpointer user_data);
-GList* g_list_sort (GList *list,
- GCompareFunc compare_func);
-gpointer g_list_nth_data (GList *list,
- guint n);
-#define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL)
-#define g_list_next(list) ((list) ? (((GList *)(list))->next) : NULL)
-
-
-/* Singly linked lists
- */
-void g_slist_push_allocator (GAllocator *allocator);
-void g_slist_pop_allocator (void);
-GSList* g_slist_alloc (void);
-void g_slist_free (GSList *list);
-void g_slist_free_1 (GSList *list);
-GSList* g_slist_append (GSList *list,
- gpointer data);
-GSList* g_slist_prepend (GSList *list,
- gpointer data);
-GSList* g_slist_insert (GSList *list,
- gpointer data,
- gint position);
-GSList* g_slist_insert_sorted (GSList *list,
- gpointer data,
- GCompareFunc func);
-GSList* g_slist_concat (GSList *list1,
- GSList *list2);
-GSList* g_slist_remove (GSList *list,
- gpointer data);
-GSList* g_slist_remove_link (GSList *list,
- GSList *llink);
-GSList* g_slist_reverse (GSList *list);
-GSList* g_slist_copy (GSList *list);
-GSList* g_slist_nth (GSList *list,
- guint n);
-GSList* g_slist_find (GSList *list,
- gpointer data);
-GSList* g_slist_find_custom (GSList *list,
- gpointer data,
- GCompareFunc func);
-gint g_slist_position (GSList *list,
- GSList *llink);
-gint g_slist_index (GSList *list,
- gpointer data);
-GSList* g_slist_last (GSList *list);
-guint g_slist_length (GSList *list);
-void g_slist_foreach (GSList *list,
- GFunc func,
- gpointer user_data);
-GSList* g_slist_sort (GSList *list,
- GCompareFunc compare_func);
-gpointer g_slist_nth_data (GSList *list,
- guint n);
-#define g_slist_next(slist) ((slist) ? (((GSList *)(slist))->next) : NULL)
-
-
-/* Hash tables
- */
-GHashTable* g_hash_table_new (GHashFunc hash_func,
- GCompareFunc key_compare_func);
-void g_hash_table_destroy (GHashTable *hash_table);
-void g_hash_table_insert (GHashTable *hash_table,
- gpointer key,
- gpointer value);
-void g_hash_table_remove (GHashTable *hash_table,
- gconstpointer key);
-gpointer g_hash_table_lookup (GHashTable *hash_table,
- gconstpointer key);
-gboolean g_hash_table_lookup_extended(GHashTable *hash_table,
- gconstpointer lookup_key,
- gpointer *orig_key,
- gpointer *value);
-void g_hash_table_freeze (GHashTable *hash_table);
-void g_hash_table_thaw (GHashTable *hash_table);
-void g_hash_table_foreach (GHashTable *hash_table,
- GHFunc func,
- gpointer user_data);
-guint g_hash_table_foreach_remove (GHashTable *hash_table,
- GHRFunc func,
- gpointer user_data);
-guint g_hash_table_size (GHashTable *hash_table);
-
-
-/* Caches
- */
-GCache* g_cache_new (GCacheNewFunc value_new_func,
- GCacheDestroyFunc value_destroy_func,
- GCacheDupFunc key_dup_func,
- GCacheDestroyFunc key_destroy_func,
- GHashFunc hash_key_func,
- GHashFunc hash_value_func,
- GCompareFunc key_compare_func);
-void g_cache_destroy (GCache *cache);
-gpointer g_cache_insert (GCache *cache,
- gpointer key);
-void g_cache_remove (GCache *cache,
- gpointer value);
-void g_cache_key_foreach (GCache *cache,
- GHFunc func,
- gpointer user_data);
-void g_cache_value_foreach (GCache *cache,
- GHFunc func,
- gpointer user_data);
-
-
-/* Balanced binary trees
- */
-GTree* g_tree_new (GCompareFunc key_compare_func);
-void g_tree_destroy (GTree *tree);
-void g_tree_insert (GTree *tree,
- gpointer key,
- gpointer value);
-void g_tree_remove (GTree *tree,
- gpointer key);
-gpointer g_tree_lookup (GTree *tree,
- gpointer key);
-void g_tree_traverse (GTree *tree,
- GTraverseFunc traverse_func,
- GTraverseType traverse_type,
- gpointer data);
-gpointer g_tree_search (GTree *tree,
- GSearchFunc search_func,
- gpointer data);
-gint g_tree_height (GTree *tree);
-gint g_tree_nnodes (GTree *tree);
-
-
-
-/* N-way tree implementation
- */
-struct _GNode
-{
- gpointer data;
- GNode *next;
- GNode *prev;
- GNode *parent;
- GNode *children;
-};
-
-#define G_NODE_IS_ROOT(node) (((GNode*) (node))->parent == NULL && \
- ((GNode*) (node))->prev == NULL && \
- ((GNode*) (node))->next == NULL)
-#define G_NODE_IS_LEAF(node) (((GNode*) (node))->children == NULL)
-
-void g_node_push_allocator (GAllocator *allocator);
-void g_node_pop_allocator (void);
-GNode* g_node_new (gpointer data);
-void g_node_destroy (GNode *root);
-void g_node_unlink (GNode *node);
-GNode* g_node_insert (GNode *parent,
- gint position,
- GNode *node);
-GNode* g_node_insert_before (GNode *parent,
- GNode *sibling,
- GNode *node);
-GNode* g_node_prepend (GNode *parent,
- GNode *node);
-guint g_node_n_nodes (GNode *root,
- GTraverseFlags flags);
-GNode* g_node_get_root (GNode *node);
-gboolean g_node_is_ancestor (GNode *node,
- GNode *descendant);
-guint g_node_depth (GNode *node);
-GNode* g_node_find (GNode *root,
- GTraverseType order,
- GTraverseFlags flags,
- gpointer data);
-
-/* convenience macros */
-#define g_node_append(parent, node) \
- g_node_insert_before ((parent), NULL, (node))
-#define g_node_insert_data(parent, position, data) \
- g_node_insert ((parent), (position), g_node_new (data))
-#define g_node_insert_data_before(parent, sibling, data) \
- g_node_insert_before ((parent), (sibling), g_node_new (data))
-#define g_node_prepend_data(parent, data) \
- g_node_prepend ((parent), g_node_new (data))
-#define g_node_append_data(parent, data) \
- g_node_insert_before ((parent), NULL, g_node_new (data))
-
-/* traversal function, assumes that `node' is root
- * (only traverses `node' and its subtree).
- * this function is just a high level interface to
- * low level traversal functions, optimized for speed.
- */
-void g_node_traverse (GNode *root,
- GTraverseType order,
- GTraverseFlags flags,
- gint max_depth,
- GNodeTraverseFunc func,
- gpointer data);
-
-/* return the maximum tree height starting with `node', this is an expensive
- * operation, since we need to visit all nodes. this could be shortened by
- * adding `guint height' to struct _GNode, but then again, this is not very
- * often needed, and would make g_node_insert() more time consuming.
- */
-guint g_node_max_height (GNode *root);
-
-void g_node_children_foreach (GNode *node,
- GTraverseFlags flags,
- GNodeForeachFunc func,
- gpointer data);
-void g_node_reverse_children (GNode *node);
-guint g_node_n_children (GNode *node);
-GNode* g_node_nth_child (GNode *node,
- guint n);
-GNode* g_node_last_child (GNode *node);
-GNode* g_node_find_child (GNode *node,
- GTraverseFlags flags,
- gpointer data);
-gint g_node_child_position (GNode *node,
- GNode *child);
-gint g_node_child_index (GNode *node,
- gpointer data);
-
-GNode* g_node_first_sibling (GNode *node);
-GNode* g_node_last_sibling (GNode *node);
-
-#define g_node_prev_sibling(node) ((node) ? \
- ((GNode*) (node))->prev : NULL)
-#define g_node_next_sibling(node) ((node) ? \
- ((GNode*) (node))->next : NULL)
-#define g_node_first_child(node) ((node) ? \
- ((GNode*) (node))->children : NULL)
-
-
-/* Callback maintenance functions
- */
-#define G_HOOK_FLAG_USER_SHIFT (4)
-typedef enum
-{
- G_HOOK_FLAG_ACTIVE = 1 << 0,
- G_HOOK_FLAG_IN_CALL = 1 << 1,
- G_HOOK_FLAG_MASK = 0x0f
-} GHookFlagMask;
-
-#define G_HOOK_DEFERRED_DESTROY ((GHookFreeFunc) 0x01)
-
-struct _GHookList
-{
- guint seq_id;
- guint hook_size;
- guint is_setup : 1;
- GHook *hooks;
- GMemChunk *hook_memchunk;
- GHookFreeFunc hook_free; /* virtual function */
- GHookFreeFunc hook_destroy; /* virtual function */
-};
-
-struct _GHook
-{
- gpointer data;
- GHook *next;
- GHook *prev;
- guint ref_count;
- guint hook_id;
- guint flags;
- gpointer func;
- GDestroyNotify destroy;
-};
-
-#define G_HOOK_ACTIVE(hook) ((((GHook*) hook)->flags & \
- G_HOOK_FLAG_ACTIVE) != 0)
-#define G_HOOK_IN_CALL(hook) ((((GHook*) hook)->flags & \
- G_HOOK_FLAG_IN_CALL) != 0)
-#define G_HOOK_IS_VALID(hook) (((GHook*) hook)->hook_id != 0 && \
- G_HOOK_ACTIVE (hook))
-#define G_HOOK_IS_UNLINKED(hook) (((GHook*) hook)->next == NULL && \
- ((GHook*) hook)->prev == NULL && \
- ((GHook*) hook)->hook_id == 0 && \
- ((GHook*) hook)->ref_count == 0)
-
-void g_hook_list_init (GHookList *hook_list,
- guint hook_size);
-void g_hook_list_clear (GHookList *hook_list);
-GHook* g_hook_alloc (GHookList *hook_list);
-void g_hook_free (GHookList *hook_list,
- GHook *hook);
-void g_hook_ref (GHookList *hook_list,
- GHook *hook);
-void g_hook_unref (GHookList *hook_list,
- GHook *hook);
-gboolean g_hook_destroy (GHookList *hook_list,
- guint hook_id);
-void g_hook_destroy_link (GHookList *hook_list,
- GHook *hook);
-void g_hook_prepend (GHookList *hook_list,
- GHook *hook);
-void g_hook_insert_before (GHookList *hook_list,
- GHook *sibling,
- GHook *hook);
-void g_hook_insert_sorted (GHookList *hook_list,
- GHook *hook,
- GHookCompareFunc func);
-GHook* g_hook_get (GHookList *hook_list,
- guint hook_id);
-GHook* g_hook_find (GHookList *hook_list,
- gboolean need_valids,
- GHookFindFunc func,
- gpointer data);
-GHook* g_hook_find_data (GHookList *hook_list,
- gboolean need_valids,
- gpointer data);
-GHook* g_hook_find_func (GHookList *hook_list,
- gboolean need_valids,
- gpointer func);
-GHook* g_hook_find_func_data (GHookList *hook_list,
- gboolean need_valids,
- gpointer func,
- gpointer data);
-/* return the first valid hook, and increment its reference count */
-GHook* g_hook_first_valid (GHookList *hook_list,
- gboolean may_be_in_call);
-/* return the next valid hook with incremented reference count, and
- * decrement the reference count of the original hook
- */
-GHook* g_hook_next_valid (GHookList *hook_list,
- GHook *hook,
- gboolean may_be_in_call);
-
-/* GHookCompareFunc implementation to insert hooks sorted by their id */
-gint g_hook_compare_ids (GHook *new_hook,
- GHook *sibling);
-
-/* convenience macros */
-#define g_hook_append( hook_list, hook ) \
- g_hook_insert_before ((hook_list), NULL, (hook))
-
-/* invoke all valid hooks with the (*GHookFunc) signature.
- */
-void g_hook_list_invoke (GHookList *hook_list,
- gboolean may_recurse);
-/* invoke all valid hooks with the (*GHookCheckFunc) signature,
- * and destroy the hook if FALSE is returned.
- */
-void g_hook_list_invoke_check (GHookList *hook_list,
- gboolean may_recurse);
-/* invoke a marshaller on all valid hooks.
- */
-void g_hook_list_marshal (GHookList *hook_list,
- gboolean may_recurse,
- GHookMarshaller marshaller,
- gpointer data);
-void g_hook_list_marshal_check (GHookList *hook_list,
- gboolean may_recurse,
- GHookCheckMarshaller marshaller,
- gpointer data);
-
-
-/* Fatal error handlers.
- * g_on_error_query() will prompt the user to either
- * [E]xit, [H]alt, [P]roceed or show [S]tack trace.
- * g_on_error_stack_trace() invokes gdb, which attaches to the current
- * process and shows a stack trace.
- * These function may cause different actions on non-unix platforms.
- * The prg_name arg is required by gdb to find the executable, if it is
- * passed as NULL, g_on_error_query() will try g_get_prgname().
- */
-void g_on_error_query (const gchar *prg_name);
-void g_on_error_stack_trace (const gchar *prg_name);
-
-
-/* Logging mechanism
- */
-extern const gchar *g_log_domain_glib;
-guint g_log_set_handler (const gchar *log_domain,
- GLogLevelFlags log_levels,
- GLogFunc log_func,
- gpointer user_data);
-void g_log_remove_handler (const gchar *log_domain,
- guint handler_id);
-void g_log_default_handler (const gchar *log_domain,
- GLogLevelFlags log_level,
- const gchar *message,
- gpointer unused_data);
-void g_log (const gchar *log_domain,
- GLogLevelFlags log_level,
- const gchar *format,
- ...) G_GNUC_PRINTF (3, 4);
-void g_logv (const gchar *log_domain,
- GLogLevelFlags log_level,
- const gchar *format,
- va_list args);
-GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain,
- GLogLevelFlags fatal_mask);
-GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
-#ifndef G_LOG_DOMAIN
-#define G_LOG_DOMAIN ((gchar*) 0)
-#endif /* G_LOG_DOMAIN */
-#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-#define g_error(...) g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_ERROR, \
- __VA_ARGS__)
-#define g_message(...) g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_MESSAGE, \
- __VA_ARGS__)
-#define g_critical(...) g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_CRITICAL, \
- __VA_ARGS__)
-#define g_warning(...) g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_WARNING, \
- __VA_ARGS__)
-#elif defined (__GNUC__)
-#define g_error(format...) g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_ERROR, \
- format)
-#define g_message(format...) g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_MESSAGE, \
- format)
-#define g_critical(format...) g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_CRITICAL, \
- format)
-#define g_warning(format...) g_log (G_LOG_DOMAIN, \
- G_LOG_LEVEL_WARNING, \
- format)
-#else /* !__GNUC__ */
-static void
-g_error (const gchar *format,
- ...)
-{
- va_list args;
- va_start (args, format);
- g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
- va_end (args);
-}
-static void
-g_message (const gchar *format,
- ...)
-{
- va_list args;
- va_start (args, format);
- g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
- va_end (args);
-}
-static void
-g_warning (const gchar *format,
- ...)
-{
- va_list args;
- va_start (args, format);
- g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
- va_end (args);
-}
-#endif /* !__GNUC__ */
-
-typedef void (*GPrintFunc) (const gchar *string);
-void g_print (const gchar *format,
- ...) G_GNUC_PRINTF (1, 2);
-GPrintFunc g_set_print_handler (GPrintFunc func);
-void g_printerr (const gchar *format,
- ...) G_GNUC_PRINTF (1, 2);
-GPrintFunc g_set_printerr_handler (GPrintFunc func);
-
-/* deprecated compatibility functions, use g_log_set_handler() instead */
-typedef void (*GErrorFunc) (const gchar *str);
-typedef void (*GWarningFunc) (const gchar *str);
-GErrorFunc g_set_error_handler (GErrorFunc func);
-GWarningFunc g_set_warning_handler (GWarningFunc func);
-GPrintFunc g_set_message_handler (GPrintFunc func);
-
-
-/* Memory allocation and debugging
- */
-#ifdef USE_DMALLOC
-
-#define g_malloc(size) ((gpointer) MALLOC (size))
-#define g_malloc0(size) ((gpointer) CALLOC (char, size))
-#define g_realloc(mem,size) ((gpointer) REALLOC (mem, char, size))
-#define g_free(mem) FREE (mem)
-
-#else /* !USE_DMALLOC */
-
-gpointer g_malloc (gulong size);
-gpointer g_malloc0 (gulong size);
-gpointer g_realloc (gpointer mem,
- gulong size);
-void g_free (gpointer mem);
-
-#endif /* !USE_DMALLOC */
-
-void g_mem_profile (void);
-void g_mem_check (gpointer mem);
-
-/* Generic allocators
- */
-GAllocator* g_allocator_new (const gchar *name,
- guint n_preallocs);
-void g_allocator_free (GAllocator *allocator);
-
-#define G_ALLOCATOR_LIST (1)
-#define G_ALLOCATOR_SLIST (2)
-#define G_ALLOCATOR_NODE (3)
-
-
-/* "g_mem_chunk_new" creates a new memory chunk.
- * Memory chunks are used to allocate pieces of memory which are
- * always the same size. Lists are a good example of such a data type.
- * The memory chunk allocates and frees blocks of memory as needed.
- * Just be sure to call "g_mem_chunk_free" and not "g_free" on data
- * allocated in a mem chunk. ("g_free" will most likely cause a seg
- * fault...somewhere).
- *
- * Oh yeah, GMemChunk is an opaque data type. (You don't really
- * want to know what's going on inside do you?)
- */
-
-/* ALLOC_ONLY MemChunk's can only allocate memory. The free operation
- * is interpreted as a no op. ALLOC_ONLY MemChunk's save 4 bytes per
- * atom. (They are also useful for lists which use MemChunk to allocate
- * memory but are also part of the MemChunk implementation).
- * ALLOC_AND_FREE MemChunk's can allocate and free memory.
- */
-
-#define G_ALLOC_ONLY 1
-#define G_ALLOC_AND_FREE 2
-
-GMemChunk* g_mem_chunk_new (gchar *name,
- gint atom_size,
- gulong area_size,
- gint type);
-void g_mem_chunk_destroy (GMemChunk *mem_chunk);
-gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
-gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
-void g_mem_chunk_free (GMemChunk *mem_chunk,
- gpointer mem);
-void g_mem_chunk_clean (GMemChunk *mem_chunk);
-void g_mem_chunk_reset (GMemChunk *mem_chunk);
-void g_mem_chunk_print (GMemChunk *mem_chunk);
-void g_mem_chunk_info (void);
-
-/* Ah yes...we have a "g_blow_chunks" function.
- * "g_blow_chunks" simply compresses all the chunks. This operation
- * consists of freeing every memory area that should be freed (but
- * which we haven't gotten around to doing yet). And, no,
- * "g_blow_chunks" doesn't follow the naming scheme, but it is a
- * much better name than "g_mem_chunk_clean_all" or something
- * similar.
- */
-void g_blow_chunks (void);
-
-
-/* Timer
- */
-GTimer* g_timer_new (void);
-void g_timer_destroy (GTimer *timer);
-void g_timer_start (GTimer *timer);
-void g_timer_stop (GTimer *timer);
-void g_timer_reset (GTimer *timer);
-gdouble g_timer_elapsed (GTimer *timer,
- gulong *microseconds);
-
-
-/* String utility functions that modify a string argument or
- * return a constant string that must not be freed.
- */
-#define G_STR_DELIMITERS "_-|> <."
-gchar* g_strdelimit (gchar *string,
- const gchar *delimiters,
- gchar new_delimiter);
-gdouble g_strtod (const gchar *nptr,
- gchar **endptr);
-gchar* g_strerror (gint errnum);
-gchar* g_strsignal (gint signum);
-gint g_strcasecmp (const gchar *s1,
- const gchar *s2);
-gint g_strncasecmp (const gchar *s1,
- const gchar *s2,
- guint n);
-void g_strdown (gchar *string);
-void g_strup (gchar *string);
-void g_strreverse (gchar *string);
-/* removes leading spaces */
-gchar* g_strchug (gchar *string);
-/* removes trailing spaces */
-gchar* g_strchomp (gchar *string);
-/* removes leading & trailing spaces */
-#define g_strstrip( string ) g_strchomp (g_strchug (string))
-
-/* String utility functions that return a newly allocated string which
- * ought to be freed from the caller at some point.
- */
-gchar* g_strdup (const gchar *str);
-gchar* g_strdup_printf (const gchar *format,
- ...) G_GNUC_PRINTF (1, 2);
-gchar* g_strdup_vprintf (const gchar *format,
- va_list args);
-gchar* g_strndup (const gchar *str,
- guint n);
-gchar* g_strnfill (guint length,
- gchar fill_char);
-gchar* g_strconcat (const gchar *string1,
- ...); /* NULL terminated */
-gchar* g_strjoin (const gchar *separator,
- ...); /* NULL terminated */
-gchar* g_strescape (gchar *string);
-gpointer g_memdup (gconstpointer mem,
- guint byte_size);
-
-/* NULL terminated string arrays.
- * g_strsplit() splits up string into max_tokens tokens at delim and
- * returns a newly allocated string array.
- * g_strjoinv() concatenates all of str_array's strings, sliding in an
- * optional separator, the returned string is newly allocated.
- * g_strfreev() frees the array itself and all of its strings.
- */
-gchar** g_strsplit (const gchar *string,
- const gchar *delimiter,
- gint max_tokens);
-gchar* g_strjoinv (const gchar *separator,
- gchar **str_array);
-void g_strfreev (gchar **str_array);
-
-
-
-/* calculate a string size, guarranteed to fit format + args.
- */
-guint g_printf_string_upper_bound (const gchar* format,
- va_list args);
-
-
-/* Retrive static string info
- */
-gchar* g_get_user_name (void);
-gchar* g_get_real_name (void);
-gchar* g_get_home_dir (void);
-gchar* g_get_tmp_dir (void);
-gchar* g_get_prgname (void);
-void g_set_prgname (const gchar *prgname);
-
-
-/* Miscellaneous utility functions
- */
-guint g_parse_debug_string (const gchar *string,
- GDebugKey *keys,
- guint nkeys);
-gint g_snprintf (gchar *string,
- gulong n,
- gchar const *format,
- ...) G_GNUC_PRINTF (3, 4);
-gint g_vsnprintf (gchar *string,
- gulong n,
- gchar const *format,
- va_list args);
-gchar* g_basename (const gchar *file_name);
-/* Check if a file name is an absolute path */
-gboolean g_path_is_absolute (const gchar *file_name);
-/* In case of absolute paths, skip the root part */
-gchar* g_path_skip_root (gchar *file_name);
-
-/* strings are newly allocated with g_malloc() */
-gchar* g_dirname (const gchar *file_name);
-gchar* g_get_current_dir (void);
-
-/* return the environment string for the variable. The returned memory
- * must not be freed. */
-gchar* g_getenv (const gchar *variable);
-
-
-/* we use a GLib function as a replacement for ATEXIT, so
- * the programmer is not required to check the return value
- * (if there is any in the implementation) and doesn't encounter
- * missing include files.
- */
-void g_atexit (GVoidFunc func);
-
-
-/* Bit tests
- */
-G_INLINE_FUNC gint g_bit_nth_lsf (guint32 mask,
- gint nth_bit);
-#ifdef G_CAN_INLINE
-G_INLINE_FUNC gint
-g_bit_nth_lsf (guint32 mask,
- gint nth_bit)
-{
- do
- {
- nth_bit++;
- if (mask & (1 << (guint) nth_bit))
- return nth_bit;
- }
- while (nth_bit < 32);
- return -1;
-}
-#endif /* G_CAN_INLINE */
-
-G_INLINE_FUNC gint g_bit_nth_msf (guint32 mask,
- gint nth_bit);
-#ifdef G_CAN_INLINE
-G_INLINE_FUNC gint
-g_bit_nth_msf (guint32 mask,
- gint nth_bit)
-{
- if (nth_bit < 0)
- nth_bit = 32;
- do
- {
- nth_bit--;
- if (mask & (1 << (guint) nth_bit))
- return nth_bit;
- }
- while (nth_bit > 0);
- return -1;
-}
-#endif /* G_CAN_INLINE */
-
-G_INLINE_FUNC guint g_bit_storage (guint number);
-#ifdef G_CAN_INLINE
-G_INLINE_FUNC guint
-g_bit_storage (guint number)
-{
- register guint n_bits = 0;
-
- do
- {
- n_bits++;
- number >>= 1;
- }
- while (number);
- return n_bits;
-}
-#endif /* G_CAN_INLINE */
-
-/* String Chunks
- */
-GStringChunk* g_string_chunk_new (gint size);
-void g_string_chunk_free (GStringChunk *chunk);
-gchar* g_string_chunk_insert (GStringChunk *chunk,
- const gchar *string);
-gchar* g_string_chunk_insert_const (GStringChunk *chunk,
- const gchar *string);
-
-
-/* Strings
- */
-GString* g_string_new (const gchar *init);
-GString* g_string_sized_new (guint dfl_size);
-void g_string_free (GString *string,
- gint free_segment);
-GString* g_string_assign (GString *lval,
- const gchar *rval);
-GString* g_string_truncate (GString *string,
- gint len);
-GString* g_string_append (GString *string,
- const gchar *val);
-GString* g_string_append_c (GString *string,
- gchar c);
-GString* g_string_prepend (GString *string,
- const gchar *val);
-GString* g_string_prepend_c (GString *string,
- gchar c);
-GString* g_string_insert (GString *string,
- gint pos,
- const gchar *val);
-GString* g_string_insert_c (GString *string,
- gint pos,
- gchar c);
-GString* g_string_erase (GString *string,
- gint pos,
- gint len);
-GString* g_string_down (GString *string);
-GString* g_string_up (GString *string);
-void g_string_sprintf (GString *string,
- const gchar *format,
- ...) G_GNUC_PRINTF (2, 3);
-void g_string_sprintfa (GString *string,
- const gchar *format,
- ...) G_GNUC_PRINTF (2, 3);
-
-
-/* Resizable arrays, remove fills any cleared spot and shortens the
- * array, while preserving the order. remove_fast will distort the
- * order by moving the last element to the position of the removed
- */
-
-#define g_array_append_val(a,v) g_array_append_vals (a, &(v), 1)
-#define g_array_prepend_val(a,v) g_array_prepend_vals (a, &(v), 1)
-#define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &(v), 1)
-#define g_array_index(a,t,i) (((t*) (a)->data) [(i)])
-
-GArray* g_array_new (gboolean zero_terminated,
- gboolean clear,
- guint element_size);
-void g_array_free (GArray *array,
- gboolean free_segment);
-GArray* g_array_append_vals (GArray *array,
- gconstpointer data,
- guint len);
-GArray* g_array_prepend_vals (GArray *array,
- gconstpointer data,
- guint len);
-GArray* g_array_insert_vals (GArray *array,
- guint index,
- gconstpointer data,
- guint len);
-GArray* g_array_set_size (GArray *array,
- guint length);
-GArray* g_array_remove_index (GArray *array,
- guint index);
-GArray* g_array_remove_index_fast (GArray *array,
- guint index);
-
-/* Resizable pointer array. This interface is much less complicated
- * than the above. Add appends appends a pointer. Remove fills any
- * cleared spot and shortens the array. remove_fast will again distort
- * order.
- */
-#define g_ptr_array_index(array,index) (array->pdata)[index]
-GPtrArray* g_ptr_array_new (void);
-void g_ptr_array_free (GPtrArray *array,
- gboolean free_seg);
-void g_ptr_array_set_size (GPtrArray *array,
- gint length);
-gpointer g_ptr_array_remove_index (GPtrArray *array,
- guint index);
-gpointer g_ptr_array_remove_index_fast (GPtrArray *array,
- guint index);
-gboolean g_ptr_array_remove (GPtrArray *array,
- gpointer data);
-gboolean g_ptr_array_remove_fast (GPtrArray *array,
- gpointer data);
-void g_ptr_array_add (GPtrArray *array,
- gpointer data);
-
-/* Byte arrays, an array of guint8. Implemented as a GArray,
- * but type-safe.
- */
-
-GByteArray* g_byte_array_new (void);
-void g_byte_array_free (GByteArray *array,
- gboolean free_segment);
-GByteArray* g_byte_array_append (GByteArray *array,
- const guint8 *data,
- guint len);
-GByteArray* g_byte_array_prepend (GByteArray *array,
- const guint8 *data,
- guint len);
-GByteArray* g_byte_array_set_size (GByteArray *array,
- guint length);
-GByteArray* g_byte_array_remove_index (GByteArray *array,
- guint index);
-GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
- guint index);
-
-
-/* Hash Functions
- */
-gint g_str_equal (gconstpointer v,
- gconstpointer v2);
-guint g_str_hash (gconstpointer v);
-
-gint g_int_equal (gconstpointer v,
- gconstpointer v2);
-guint g_int_hash (gconstpointer v);
-
-/* This "hash" function will just return the key's adress as an
- * unsigned integer. Useful for hashing on plain adresses or
- * simple integer values.
- * passing NULL into g_hash_table_new() as GHashFunc has the
- * same effect as passing g_direct_hash().
- */
-guint g_direct_hash (gconstpointer v);
-gint g_direct_equal (gconstpointer v,
- gconstpointer v2);
-
-
-/* Quarks (string<->id association)
- */
-GQuark g_quark_try_string (const gchar *string);
-GQuark g_quark_from_static_string (const gchar *string);
-GQuark g_quark_from_string (const gchar *string);
-gchar* g_quark_to_string (GQuark quark);
-
-
-/* Keyed Data List
- * NOTE: these functions are scheduled for a rename in GLib 1.3
- */
-void g_datalist_init (GData **datalist);
-void g_datalist_clear (GData **datalist);
-gpointer g_datalist_id_get_data (GData **datalist,
- GQuark key_id);
-void g_datalist_id_set_data_full (GData **datalist,
- GQuark key_id,
- gpointer data,
- GDestroyNotify destroy_func);
-void g_datalist_id_remove_no_notify (GData **datalist,
- GQuark key_id);
-void g_datalist_foreach (GData **datalist,
- GDataForeachFunc func,
- gpointer user_data);
-#define g_datalist_id_set_data(dl, q, d) \
- g_datalist_id_set_data_full ((dl), (q), (d), NULL)
-#define g_datalist_id_remove_data(dl, q) \
- g_datalist_id_set_data ((dl), (q), NULL)
-#define g_datalist_get_data(dl, k) \
- (g_datalist_id_get_data ((dl), g_quark_try_string (k)))
-#define g_datalist_set_data_full(dl, k, d, f) \
- g_datalist_id_set_data_full ((dl), g_quark_from_string (k), (d), (f))
-#define g_datalist_remove_no_notify(dl, k) \
- g_datalist_id_remove_no_notify ((dl), g_quark_try_string (k))
-#define g_datalist_set_data(dl, k, d) \
- g_datalist_set_data_full ((dl), (k), (d), NULL)
-#define g_datalist_remove_data(dl, k) \
- g_datalist_id_set_data ((dl), g_quark_try_string (k), NULL)
-
-
-/* Location Associated Keyed Data
- * NOTE: these functions are scheduled for a rename in GLib 1.3
- */
-void g_dataset_destroy (gconstpointer dataset_location);
-gpointer g_dataset_id_get_data (gconstpointer dataset_location,
- GQuark key_id);
-void g_dataset_id_set_data_full (gconstpointer dataset_location,
- GQuark key_id,
- gpointer data,
- GDestroyNotify destroy_func);
-void g_dataset_id_remove_no_notify (gconstpointer dataset_location,
- GQuark key_id);
-void g_dataset_foreach (gconstpointer dataset_location,
- GDataForeachFunc func,
- gpointer user_data);
-#define g_dataset_id_set_data(l, k, d) \
- g_dataset_id_set_data_full ((l), (k), (d), NULL)
-#define g_dataset_id_remove_data(l, k) \
- g_dataset_id_set_data ((l), (k), NULL)
-#define g_dataset_get_data(l, k) \
- (g_dataset_id_get_data ((l), g_quark_try_string (k)))
-#define g_dataset_set_data_full(l, k, d, f) \
- g_dataset_id_set_data_full ((l), g_quark_from_string (k), (d), (f))
-#define g_dataset_remove_no_notify(l, k) \
- g_dataset_id_remove_no_notify ((l), g_quark_try_string (k))
-#define g_dataset_set_data(l, k, d) \
- g_dataset_set_data_full ((l), (k), (d), NULL)
-#define g_dataset_remove_data(l, k) \
- g_dataset_id_set_data ((l), g_quark_try_string (k), NULL)
-
-
-/* GScanner: Flexible lexical scanner for general purpose.
- */
-
-/* Character sets */
-#define G_CSET_A_2_Z "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-#define G_CSET_a_2_z "abcdefghijklmnopqrstuvwxyz"
-#define G_CSET_LATINC "\300\301\302\303\304\305\306"\
- "\307\310\311\312\313\314\315\316\317\320"\
- "\321\322\323\324\325\326"\
- "\330\331\332\333\334\335\336"
-#define G_CSET_LATINS "\337\340\341\342\343\344\345\346"\
- "\347\350\351\352\353\354\355\356\357\360"\
- "\361\362\363\364\365\366"\
- "\370\371\372\373\374\375\376\377"
-
-/* Error types */
-typedef enum
-{
- G_ERR_UNKNOWN,
- G_ERR_UNEXP_EOF,
- G_ERR_UNEXP_EOF_IN_STRING,
- G_ERR_UNEXP_EOF_IN_COMMENT,
- G_ERR_NON_DIGIT_IN_CONST,
- G_ERR_DIGIT_RADIX,
- G_ERR_FLOAT_RADIX,
- G_ERR_FLOAT_MALFORMED
-} GErrorType;
-
-/* Token types */
-typedef enum
-{
- G_TOKEN_EOF = 0,
-
- G_TOKEN_LEFT_PAREN = '(',
- G_TOKEN_RIGHT_PAREN = ')',
- G_TOKEN_LEFT_CURLY = '{',
- G_TOKEN_RIGHT_CURLY = '}',
- G_TOKEN_LEFT_BRACE = '[',
- G_TOKEN_RIGHT_BRACE = ']',
- G_TOKEN_EQUAL_SIGN = '=',
- G_TOKEN_COMMA = ',',
-
- G_TOKEN_NONE = 256,
-
- G_TOKEN_ERROR,
-
- G_TOKEN_CHAR,
- G_TOKEN_BINARY,
- G_TOKEN_OCTAL,
- G_TOKEN_INT,
- G_TOKEN_HEX,
- G_TOKEN_FLOAT,
- G_TOKEN_STRING,
-
- G_TOKEN_SYMBOL,
- G_TOKEN_IDENTIFIER,
- G_TOKEN_IDENTIFIER_NULL,
-
- G_TOKEN_COMMENT_SINGLE,
- G_TOKEN_COMMENT_MULTI,
- G_TOKEN_LAST
-} GTokenType;
-
-union _GTokenValue
-{
- gpointer v_symbol;
- gchar *v_identifier;
- gulong v_binary;
- gulong v_octal;
- gulong v_int;
- gdouble v_float;
- gulong v_hex;
- gchar *v_string;
- gchar *v_comment;
- guchar v_char;
- guint v_error;
-};
-
-struct _GScannerConfig
-{
- /* Character sets
- */
- gchar *cset_skip_characters; /* default: " \t\n" */
- gchar *cset_identifier_first;
- gchar *cset_identifier_nth;
- gchar *cpair_comment_single; /* default: "#\n" */
-
- /* Should symbol lookup work case sensitive?
- */
- guint case_sensitive : 1;
-
- /* Boolean values to be adjusted "on the fly"
- * to configure scanning behaviour.
- */
- guint skip_comment_multi : 1; /* C like comment */
- guint skip_comment_single : 1; /* single line comment */
- guint scan_comment_multi : 1; /* scan multi line comments? */
- guint scan_identifier : 1;
- guint scan_identifier_1char : 1;
- guint scan_identifier_NULL : 1;
- guint scan_symbols : 1;
- guint scan_binary : 1;
- guint scan_octal : 1;
- guint scan_float : 1;
- guint scan_hex : 1; /* `0x0ff0' */
- guint scan_hex_dollar : 1; /* `$0ff0' */
- guint scan_string_sq : 1; /* string: 'anything' */
- guint scan_string_dq : 1; /* string: "\\-escapes!\n" */
- guint numbers_2_int : 1; /* bin, octal, hex => int */
- guint int_2_float : 1; /* int => G_TOKEN_FLOAT? */
- guint identifier_2_string : 1;
- guint char_2_token : 1; /* return G_TOKEN_CHAR? */
- guint symbol_2_token : 1;
- guint scope_0_fallback : 1; /* try scope 0 on lookups? */
-};
-
-struct _GScanner
-{
- /* unused fields */
- gpointer user_data;
- guint max_parse_errors;
-
- /* g_scanner_error() increments this field */
- guint parse_errors;
-
- /* name of input stream, featured by the default message handler */
- const gchar *input_name;
-
- /* data pointer for derived structures */
- gpointer derived_data;
-
- /* link into the scanner configuration */
- GScannerConfig *config;
-
- /* fields filled in after g_scanner_get_next_token() */
- GTokenType token;
- GTokenValue value;
- guint line;
- guint position;
-
- /* fields filled in after g_scanner_peek_next_token() */
- GTokenType next_token;
- GTokenValue next_value;
- guint next_line;
- guint next_position;
-
- /* to be considered private */
- GHashTable *symbol_table;
- gint input_fd;
- const gchar *text;
- const gchar *text_end;
- gchar *buffer;
- guint scope_id;
-
- /* handler function for _warn and _error */
- GScannerMsgFunc msg_handler;
-};
-
-GScanner* g_scanner_new (GScannerConfig *config_templ);
-void g_scanner_destroy (GScanner *scanner);
-void g_scanner_input_file (GScanner *scanner,
- gint input_fd);
-void g_scanner_sync_file_offset (GScanner *scanner);
-void g_scanner_input_text (GScanner *scanner,
- const gchar *text,
- guint text_len);
-GTokenType g_scanner_get_next_token (GScanner *scanner);
-GTokenType g_scanner_peek_next_token (GScanner *scanner);
-GTokenType g_scanner_cur_token (GScanner *scanner);
-GTokenValue g_scanner_cur_value (GScanner *scanner);
-guint g_scanner_cur_line (GScanner *scanner);
-guint g_scanner_cur_position (GScanner *scanner);
-gboolean g_scanner_eof (GScanner *scanner);
-guint g_scanner_set_scope (GScanner *scanner,
- guint scope_id);
-void g_scanner_scope_add_symbol (GScanner *scanner,
- guint scope_id,
- const gchar *symbol,
- gpointer value);
-void g_scanner_scope_remove_symbol (GScanner *scanner,
- guint scope_id,
- const gchar *symbol);
-gpointer g_scanner_scope_lookup_symbol (GScanner *scanner,
- guint scope_id,
- const gchar *symbol);
-void g_scanner_scope_foreach_symbol (GScanner *scanner,
- guint scope_id,
- GHFunc func,
- gpointer user_data);
-gpointer g_scanner_lookup_symbol (GScanner *scanner,
- const gchar *symbol);
-void g_scanner_freeze_symbol_table (GScanner *scanner);
-void g_scanner_thaw_symbol_table (GScanner *scanner);
-void g_scanner_unexp_token (GScanner *scanner,
- GTokenType expected_token,
- const gchar *identifier_spec,
- const gchar *symbol_spec,
- const gchar *symbol_name,
- const gchar *message,
- gint is_error);
-void g_scanner_error (GScanner *scanner,
- const gchar *format,
- ...) G_GNUC_PRINTF (2,3);
-void g_scanner_warn (GScanner *scanner,
- const gchar *format,
- ...) G_GNUC_PRINTF (2,3);
-gint g_scanner_stat_mode (const gchar *filename);
-/* keep downward source compatibility */
-#define g_scanner_add_symbol( scanner, symbol, value ) G_STMT_START { \
- g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
-} G_STMT_END
-#define g_scanner_remove_symbol( scanner, symbol ) G_STMT_START { \
- g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
-} G_STMT_END
-#define g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
- g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
-} G_STMT_END
-
-
-/* GCompletion
- */
-
-struct _GCompletion
-{
- GList* items;
- GCompletionFunc func;
-
- gchar* prefix;
- GList* cache;
-};
-
-GCompletion* g_completion_new (GCompletionFunc func);
-void g_completion_add_items (GCompletion* cmp,
- GList* items);
-void g_completion_remove_items (GCompletion* cmp,
- GList* items);
-void g_completion_clear_items (GCompletion* cmp);
-GList* g_completion_complete (GCompletion* cmp,
- gchar* prefix,
- gchar** new_prefix);
-void g_completion_free (GCompletion* cmp);
-
-
-/* GDate
- *
- * Date calculations (not time for now, to be resolved). These are a
- * mutant combination of Steffen Beyer's DateCalc routines
- * (http://www.perl.com/CPAN/authors/id/STBEY/) and Jon Trowbridge's
- * date routines (written for in-house software). Written by Havoc
- * Pennington <hp@pobox.com>
- */
-
-typedef guint16 GDateYear;
-typedef guint8 GDateDay; /* day of the month */
-typedef struct _GDate GDate;
-/* make struct tm known without having to include time.h */
-struct tm;
-
-/* enum used to specify order of appearance in parsed date strings */
-typedef enum
-{
- G_DATE_DAY = 0,
- G_DATE_MONTH = 1,
- G_DATE_YEAR = 2
-} GDateDMY;
-
-/* actual week and month values */
-typedef enum
-{
- G_DATE_BAD_WEEKDAY = 0,
- G_DATE_MONDAY = 1,
- G_DATE_TUESDAY = 2,
- G_DATE_WEDNESDAY = 3,
- G_DATE_THURSDAY = 4,
- G_DATE_FRIDAY = 5,
- G_DATE_SATURDAY = 6,
- G_DATE_SUNDAY = 7
-} GDateWeekday;
-typedef enum
-{
- G_DATE_BAD_MONTH = 0,
- G_DATE_JANUARY = 1,
- G_DATE_FEBRUARY = 2,
- G_DATE_MARCH = 3,
- G_DATE_APRIL = 4,
- G_DATE_MAY = 5,
- G_DATE_JUNE = 6,
- G_DATE_JULY = 7,
- G_DATE_AUGUST = 8,
- G_DATE_SEPTEMBER = 9,
- G_DATE_OCTOBER = 10,
- G_DATE_NOVEMBER = 11,
- G_DATE_DECEMBER = 12
-} GDateMonth;
-
-#define G_DATE_BAD_JULIAN 0U
-#define G_DATE_BAD_DAY 0U
-#define G_DATE_BAD_YEAR 0U
-
-/* Note: directly manipulating structs is generally a bad idea, but
- * in this case it's an *incredibly* bad idea, because all or part
- * of this struct can be invalid at any given time. Use the functions,
- * or you will get hosed, I promise.
- */
-struct _GDate
-{
- guint julian_days : 32; /* julian days representation - we use a
- * bitfield hoping that 64 bit platforms
- * will pack this whole struct in one big
- * int
- */
-
- guint julian : 1; /* julian is valid */
- guint dmy : 1; /* dmy is valid */
-
- /* DMY representation */
- guint day : 6;
- guint month : 4;
- guint year : 16;
-};
-
-/* g_date_new() returns an invalid date, you then have to _set() stuff
- * to get a usable object. You can also allocate a GDate statically,
- * then call g_date_clear() to initialize.
- */
-GDate* g_date_new (void);
-GDate* g_date_new_dmy (GDateDay day,
- GDateMonth month,
- GDateYear year);
-GDate* g_date_new_julian (guint32 julian_day);
-void g_date_free (GDate *date);
-
-/* check g_date_valid() after doing an operation that might fail, like
- * _parse. Almost all g_date operations are undefined on invalid
- * dates (the exceptions are the mutators, since you need those to
- * return to validity).
- */
-gboolean g_date_valid (GDate *date);
-gboolean g_date_valid_day (GDateDay day);
-gboolean g_date_valid_month (GDateMonth month);
-gboolean g_date_valid_year (GDateYear year);
-gboolean g_date_valid_weekday (GDateWeekday weekday);
-gboolean g_date_valid_julian (guint32 julian_date);
-gboolean g_date_valid_dmy (GDateDay day,
- GDateMonth month,
- GDateYear year);
-
-GDateWeekday g_date_weekday (GDate *date);
-GDateMonth g_date_month (GDate *date);
-GDateYear g_date_year (GDate *date);
-GDateDay g_date_day (GDate *date);
-guint32 g_date_julian (GDate *date);
-guint g_date_day_of_year (GDate *date);
-
-/* First monday/sunday is the start of week 1; if we haven't reached
- * that day, return 0. These are not ISO weeks of the year; that
- * routine needs to be added.
- * these functions return the number of weeks, starting on the
- * corrsponding day
- */
-guint g_date_monday_week_of_year (GDate *date);
-guint g_date_sunday_week_of_year (GDate *date);
-
-/* If you create a static date struct you need to clear it to get it
- * in a sane state before use. You can clear a whole array at
- * once with the ndates argument.
- */
-void g_date_clear (GDate *date,
- guint n_dates);
-
-/* The parse routine is meant for dates typed in by a user, so it
- * permits many formats but tries to catch common typos. If your data
- * needs to be strictly validated, it is not an appropriate function.
- */
-void g_date_set_parse (GDate *date,
- const gchar *str);
-void g_date_set_time (GDate *date,
- GTime time);
-void g_date_set_month (GDate *date,
- GDateMonth month);
-void g_date_set_day (GDate *date,
- GDateDay day);
-void g_date_set_year (GDate *date,
- GDateYear year);
-void g_date_set_dmy (GDate *date,
- GDateDay day,
- GDateMonth month,
- GDateYear y);
-void g_date_set_julian (GDate *date,
- guint32 julian_date);
-gboolean g_date_is_first_of_month (GDate *date);
-gboolean g_date_is_last_of_month (GDate *date);
-
-/* To go forward by some number of weeks just go forward weeks*7 days */
-void g_date_add_days (GDate *date,
- guint n_days);
-void g_date_subtract_days (GDate *date,
- guint n_days);
-
-/* If you add/sub months while day > 28, the day might change */
-void g_date_add_months (GDate *date,
- guint n_months);
-void g_date_subtract_months (GDate *date,
- guint n_months);
-
-/* If it's feb 29, changing years can move you to the 28th */
-void g_date_add_years (GDate *date,
- guint n_years);
-void g_date_subtract_years (GDate *date,
- guint n_years);
-gboolean g_date_is_leap_year (GDateYear year);
-guint8 g_date_days_in_month (GDateMonth month,
- GDateYear year);
-guint8 g_date_monday_weeks_in_year (GDateYear year);
-guint8 g_date_sunday_weeks_in_year (GDateYear year);
-
-/* qsort-friendly (with a cast...) */
-gint g_date_compare (GDate *lhs,
- GDate *rhs);
-void g_date_to_struct_tm (GDate *date,
- struct tm *tm);
-
-/* Just like strftime() except you can only use date-related formats.
- * Using a time format is undefined.
- */
-gsize g_date_strftime (gchar *s,
- gsize slen,
- const gchar *format,
- GDate *date);
-
-
-/* GRelation
- *
- * Indexed Relations. Imagine a really simple table in a
- * database. Relations are not ordered. This data type is meant for
- * maintaining a N-way mapping.
- *
- * g_relation_new() creates a relation with FIELDS fields
- *
- * g_relation_destroy() frees all resources
- * g_tuples_destroy() frees the result of g_relation_select()
- *
- * g_relation_index() indexes relation FIELD with the provided
- * equality and hash functions. this must be done before any
- * calls to insert are made.
- *
- * g_relation_insert() inserts a new tuple. you are expected to
- * provide the right number of fields.
- *
- * g_relation_delete() deletes all relations with KEY in FIELD
- * g_relation_select() returns ...
- * g_relation_count() counts ...
- */
-
-GRelation* g_relation_new (gint fields);
-void g_relation_destroy (GRelation *relation);
-void g_relation_index (GRelation *relation,
- gint field,
- GHashFunc hash_func,
- GCompareFunc key_compare_func);
-void g_relation_insert (GRelation *relation,
- ...);
-gint g_relation_delete (GRelation *relation,
- gconstpointer key,
- gint field);
-GTuples* g_relation_select (GRelation *relation,
- gconstpointer key,
- gint field);
-gint g_relation_count (GRelation *relation,
- gconstpointer key,
- gint field);
-gboolean g_relation_exists (GRelation *relation,
- ...);
-void g_relation_print (GRelation *relation);
-
-void g_tuples_destroy (GTuples *tuples);
-gpointer g_tuples_index (GTuples *tuples,
- gint index,
- gint field);
-
-
-/* Prime numbers.
- */
-
-/* This function returns prime numbers spaced by approximately 1.5-2.0
- * and is for use in resizing data structures which prefer
- * prime-valued sizes. The closest spaced prime function returns the
- * next largest prime, or the highest it knows about which is about
- * MAXINT/4.
- */
-guint g_spaced_primes_closest (guint num);
-
-
-/* GIOChannel
- */
-
-typedef struct _GIOFuncs GIOFuncs;
-typedef enum
-{
- G_IO_ERROR_NONE,
- G_IO_ERROR_AGAIN,
- G_IO_ERROR_INVAL,
- G_IO_ERROR_UNKNOWN
-} GIOError;
-typedef enum
-{
- G_SEEK_CUR,
- G_SEEK_SET,
- G_SEEK_END
-} GSeekType;
-typedef enum
-{
- G_IO_IN GLIB_SYSDEF_POLLIN,
- G_IO_OUT GLIB_SYSDEF_POLLOUT,
- G_IO_PRI GLIB_SYSDEF_POLLPRI,
- G_IO_ERR GLIB_SYSDEF_POLLERR,
- G_IO_HUP GLIB_SYSDEF_POLLHUP,
- G_IO_NVAL GLIB_SYSDEF_POLLNVAL
-} GIOCondition;
-
-struct _GIOChannel
-{
- guint channel_flags;
- guint ref_count;
- GIOFuncs *funcs;
-};
-
-typedef gboolean (*GIOFunc) (GIOChannel *source,
- GIOCondition condition,
- gpointer data);
-struct _GIOFuncs
-{
- GIOError (*io_read) (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_read);
- GIOError (*io_write) (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written);
- GIOError (*io_seek) (GIOChannel *channel,
- gint offset,
- GSeekType type);
- void (*io_close) (GIOChannel *channel);
- guint (*io_add_watch) (GIOChannel *channel,
- gint priority,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data,
- GDestroyNotify notify);
- void (*io_free) (GIOChannel *channel);
-};
-
-void g_io_channel_init (GIOChannel *channel);
-void g_io_channel_ref (GIOChannel *channel);
-void g_io_channel_unref (GIOChannel *channel);
-GIOError g_io_channel_read (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_read);
-GIOError g_io_channel_write (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written);
-GIOError g_io_channel_seek (GIOChannel *channel,
- gint offset,
- GSeekType type);
-void g_io_channel_close (GIOChannel *channel);
-guint g_io_add_watch_full (GIOChannel *channel,
- gint priority,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data,
- GDestroyNotify notify);
-guint g_io_add_watch (GIOChannel *channel,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data);
-
-
-/* Main loop
- */
-typedef struct _GTimeVal GTimeVal;
-typedef struct _GSourceFuncs GSourceFuncs;
-typedef struct _GMainLoop GMainLoop; /* Opaque */
-
-struct _GTimeVal
-{
- glong tv_sec;
- glong tv_usec;
-};
-struct _GSourceFuncs
-{
- gboolean (*prepare) (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout,
- gpointer user_data);
- gboolean (*check) (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data);
- gboolean (*dispatch) (gpointer source_data,
- GTimeVal *dispatch_time,
- gpointer user_data);
- GDestroyNotify destroy;
-};
-
-/* Standard priorities */
-
-#define G_PRIORITY_HIGH -100
-#define G_PRIORITY_DEFAULT 0
-#define G_PRIORITY_HIGH_IDLE 100
-#define G_PRIORITY_DEFAULT_IDLE 200
-#define G_PRIORITY_LOW 300
-
-typedef gboolean (*GSourceFunc) (gpointer data);
-
-/* Hooks for adding to the main loop */
-guint g_source_add (gint priority,
- gboolean can_recurse,
- GSourceFuncs *funcs,
- gpointer source_data,
- gpointer user_data,
- GDestroyNotify notify);
-gboolean g_source_remove (guint tag);
-gboolean g_source_remove_by_user_data (gpointer user_data);
-gboolean g_source_remove_by_source_data (gpointer source_data);
-gboolean g_source_remove_by_funcs_user_data (GSourceFuncs *funcs,
- gpointer user_data);
-
-void g_get_current_time (GTimeVal *result);
-
-/* Running the main loop */
-GMainLoop* g_main_new (gboolean is_running);
-void g_main_run (GMainLoop *loop);
-void g_main_quit (GMainLoop *loop);
-void g_main_destroy (GMainLoop *loop);
-gboolean g_main_is_running (GMainLoop *loop);
-
-/* Run a single iteration of the mainloop. If block is FALSE,
- * will never block
- */
-gboolean g_main_iteration (gboolean may_block);
-
-/* See if any events are pending */
-gboolean g_main_pending (void);
-
-/* Idles and timeouts */
-guint g_timeout_add_full (gint priority,
- guint interval,
- GSourceFunc function,
- gpointer data,
- GDestroyNotify notify);
-guint g_timeout_add (guint interval,
- GSourceFunc function,
- gpointer data);
-guint g_idle_add (GSourceFunc function,
- gpointer data);
-guint g_idle_add_full (gint priority,
- GSourceFunc function,
- gpointer data,
- GDestroyNotify destroy);
-gboolean g_idle_remove_by_data (gpointer data);
-
-/* GPollFD
- *
- * System-specific IO and main loop calls
- *
- * On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file
- * descriptor as provided by the C runtime) that can be used by
- * MsgWaitForMultipleObjects. This does *not* include file handles
- * from CreateFile, SOCKETs, nor pipe handles. (But you can use
- * WSAEventSelect to signal events when a SOCKET is readable).
- *
- * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
- * indicate polling for messages. These message queue GPollFDs should
- * be added with the g_main_poll_win32_msg_add function.
- *
- * But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
- * (GTK) programs, as GDK itself wants to read messages and convert them
- * to GDK events.
- *
- * So, unless you really know what you are doing, it's best not to try
- * to use the main loop polling stuff for your own needs on
- * Win32. It's really only written for the GIMP's needs so
- * far.
- */
-
-typedef struct _GPollFD GPollFD;
-typedef gint (*GPollFunc) (GPollFD *ufds,
- guint nfsd,
- gint timeout);
-struct _GPollFD
-{
- gint fd;
- gushort events;
- gushort revents;
-};
-
-void g_main_add_poll (GPollFD *fd,
- gint priority);
-void g_main_remove_poll (GPollFD *fd);
-void g_main_set_poll_func (GPollFunc func);
-
-/* On Unix, IO channels created with this function for any file
- * descriptor or socket.
- *
- * On Win32, use this only for plain files opened with the MSVCRT (the
- * Microsoft run-time C library) _open(), including file descriptors
- * 0, 1 and 2 (corresponding to stdin, stdout and stderr).
- * Actually, don't do even that, this code isn't done yet.
- *
- * The term file descriptor as used in the context of Win32 refers to
- * the emulated Unix-like file descriptors MSVCRT provides.
- */
-GIOChannel* g_io_channel_unix_new (int fd);
-gint g_io_channel_unix_get_fd (GIOChannel *channel);
-
-#ifdef NATIVE_WIN32
-
-GUTILS_C_VAR guint g_pipe_readable_msg;
-
-#define G_WIN32_MSG_HANDLE 19981206
-
-/* This is used to add polling for Windows messages. GDK (GTk+) programs
- * should *not* use this. (In fact, I can't think of any program that
- * would want to use this, but it's here just for completeness's sake.
- */
-void g_main_poll_win32_msg_add(gint priority,
- GPollFD *fd,
- guint hwnd);
-
-/* An IO channel for Windows messages for window handle hwnd. */
-GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
-
-/* An IO channel for an anonymous pipe as returned from the MSVCRT
- * _pipe(), with no mechanism for the writer to tell the reader when
- * there is data in the pipe.
- *
- * This is not really implemented yet.
- */
-GIOChannel *g_io_channel_win32_new_pipe (int fd);
-
-/* An IO channel for a pipe as returned from the MSVCRT _pipe(), with
- * Windows user messages used to signal data in the pipe for the
- * reader.
- *
- * fd is the file descriptor. For the write end, peer is the thread id
- * of the reader, and peer_fd is his file descriptor for the read end
- * of the pipe.
- *
- * This is used by the GIMP, and works.
- */
-GIOChannel *g_io_channel_win32_new_pipe_with_wakeups (int fd,
- guint peer,
- int peer_fd);
-
-void g_io_channel_win32_pipe_request_wakeups (GIOChannel *channel,
- guint peer,
- int peer_fd);
-
-void g_io_channel_win32_pipe_readable (int fd,
- guint offset);
-
-/* Get the C runtime file descriptor of a channel. */
-gint g_io_channel_win32_get_fd (GIOChannel *channel);
-
-/* An IO channel for a SOCK_STREAM winsock socket. The parameter is
- * actually a SOCKET.
- */
-GIOChannel *g_io_channel_win32_new_stream_socket (int socket);
-
-#endif
-
-/* Windows emulation stubs for common Unix functions
- */
-#ifdef NATIVE_WIN32
-# define MAXPATHLEN 1024
-# ifdef _MSC_VER
-typedef int pid_t;
-
-/* These POSIXish functions are available in the Microsoft C library
- * prefixed with underscore (which of course technically speaking is
- * the Right Thing, as they are non-ANSI. Not that being non-ANSI
- * prevents Microsoft from practically requiring you to include
- * <windows.h> every now and then...).
- *
- * You still need to include the appropriate headers to get the
- * prototypes, <io.h> or <direct.h>.
- *
- * For some functions, we provide emulators in glib, which are prefixed
- * with gwin_.
- */
-# define getcwd _getcwd
-# define getpid _getpid
-# define access _access
-# define open _open
-# define read _read
-# define write _write
-# define lseek _lseek
-# define close _close
-# define pipe(phandles) _pipe (phandles, 4096, _O_BINARY)
-# define popen _popen
-# define pclose _pclose
-# define fdopen _fdopen
-# define ftruncate(fd, size) gwin_ftruncate (fd, size)
-# define opendir gwin_opendir
-# define readdir gwin_readdir
-# define rewinddir gwin_rewinddir
-# define closedir gwin_closedir
-# define NAME_MAX 255
-struct DIR
-{
- gchar *dir_name;
- gboolean just_opened;
- guint find_file_handle;
- gpointer find_file_data;
-};
-typedef struct DIR DIR;
-struct dirent
-{
- gchar d_name[NAME_MAX + 1];
-};
-/* emulation functions */
-extern int gwin_ftruncate (gint f,
- guint size);
-DIR* gwin_opendir (const gchar *dirname);
-struct dirent* gwin_readdir (DIR *dir);
-void gwin_rewinddir (DIR *dir);
-gint gwin_closedir (DIR *dir);
-# endif /* _MSC_VER */
-#endif /* NATIVE_WIN32 */
-
-
-/* GLib Thread support
- */
-typedef struct _GMutex GMutex;
-typedef struct _GCond GCond;
-typedef struct _GPrivate GPrivate;
-typedef struct _GStaticPrivate GStaticPrivate;
-typedef struct _GThreadFunctions GThreadFunctions;
-struct _GThreadFunctions
-{
- GMutex* (*mutex_new) (void);
- void (*mutex_lock) (GMutex *mutex);
- gboolean (*mutex_trylock) (GMutex *mutex);
- void (*mutex_unlock) (GMutex *mutex);
- void (*mutex_free) (GMutex *mutex);
- GCond* (*cond_new) (void);
- void (*cond_signal) (GCond *cond);
- void (*cond_broadcast) (GCond *cond);
- void (*cond_wait) (GCond *cond,
- GMutex *mutex);
- gboolean (*cond_timed_wait) (GCond *cond,
- GMutex *mutex,
- GTimeVal *end_time);
- void (*cond_free) (GCond *cond);
- GPrivate* (*private_new) (GDestroyNotify destructor);
- gpointer (*private_get) (GPrivate *private_key);
- void (*private_set) (GPrivate *private_key,
- gpointer data);
-};
-
-GUTILS_C_VAR GThreadFunctions g_thread_functions_for_glib_use;
-GUTILS_C_VAR gboolean g_thread_use_default_impl;
-GUTILS_C_VAR gboolean g_threads_got_initialized;
-
-/* initializes the mutex/cond/private implementation for glib, might
- * only be called once, and must not be called directly or indirectly
- * from another glib-function, e.g. as a callback.
- */
-void g_thread_init (GThreadFunctions *vtable);
-
-/* internal function for fallback static mutex implementation */
-GMutex* g_static_mutex_get_mutex_impl (GMutex **mutex);
-
-/* shorthands for conditional and unconditional function calls */
-#define G_THREAD_UF(name, arglist) \
- (*g_thread_functions_for_glib_use . name) arglist
-#define G_THREAD_CF(name, fail, arg) \
- (g_thread_supported () ? G_THREAD_UF (name, arg) : (fail))
-/* keep in mind, all those mutexes and static mutexes are not
- * recursive in general, don't rely on that
- */
-#define g_thread_supported() (g_threads_got_initialized)
-#define g_mutex_new() G_THREAD_UF (mutex_new, ())
-#define g_mutex_lock(mutex) G_THREAD_CF (mutex_lock, (void)0, (mutex))
-#define g_mutex_trylock(mutex) G_THREAD_CF (mutex_trylock, TRUE, (mutex))
-#define g_mutex_unlock(mutex) G_THREAD_CF (mutex_unlock, (void)0, (mutex))
-#define g_mutex_free(mutex) G_THREAD_CF (mutex_free, (void)0, (mutex))
-#define g_cond_new() G_THREAD_UF (cond_new, ())
-#define g_cond_signal(cond) G_THREAD_CF (cond_signal, (void)0, (cond))
-#define g_cond_broadcast(cond) G_THREAD_CF (cond_broadcast, (void)0, (cond))
-#define g_cond_wait(cond, mutex) G_THREAD_CF (cond_wait, (void)0, (cond, \
- mutex))
-#define g_cond_free(cond) G_THREAD_CF (cond_free, (void)0, (cond))
-#define g_cond_timed_wait(cond, mutex, abs_time) G_THREAD_CF (cond_timed_wait, \
- TRUE, \
- (cond, mutex, \
- abs_time))
-#define g_private_new(destructor) G_THREAD_UF (private_new, (destructor))
-#define g_private_get(private_key) G_THREAD_CF (private_get, \
- ((gpointer)private_key), \
- (private_key))
-#define g_private_set(private_key, value) G_THREAD_CF (private_set, \
- (void) (private_key = \
- (GPrivate*) (value)), \
- (private_key, value))
-/* GStaticMutexes can be statically initialized with the value
- * G_STATIC_MUTEX_INIT, and then they can directly be used, that is
- * much easier, than having to explicitly allocate the mutex before
- * use
- */
-#define g_static_mutex_lock(mutex) \
- g_mutex_lock (g_static_mutex_get_mutex (mutex))
-#define g_static_mutex_trylock(mutex) \
- g_mutex_trylock (g_static_mutex_get_mutex (mutex))
-#define g_static_mutex_unlock(mutex) \
- g_mutex_unlock (g_static_mutex_get_mutex (mutex))
-struct _GStaticPrivate
-{
- guint index;
-};
-#define G_STATIC_PRIVATE_INIT { 0 }
-gpointer g_static_private_get (GStaticPrivate *private_key);
-void g_static_private_set (GStaticPrivate *private_key,
- gpointer data,
- GDestroyNotify notify);
-
-/* these are some convenience macros that expand to nothing if GLib
- * was configured with --disable-threads. for using StaticMutexes,
- * you define them with G_LOCK_DEFINE_STATIC (name) or G_LOCK_DEFINE (name)
- * if you need to export the mutex. With G_LOCK_EXTERN (name) you can
- * declare such an globally defined lock. name is a unique identifier
- * for the protected varibale or code portion. locking, testing and
- * unlocking of such mutexes can be done with G_LOCK(), G_UNLOCK() and
- * G_TRYLOCK() respectively.
- */
-extern void glib_dummy_decl (void);
-#define G_LOCK_NAME(name) (g__ ## name ## _lock)
-#ifdef G_THREADS_ENABLED
-# define G_LOCK_DEFINE_STATIC(name) static G_LOCK_DEFINE (name)
-# define G_LOCK_DEFINE(name) \
- GStaticMutex G_LOCK_NAME (name) = G_STATIC_MUTEX_INIT
-# define G_LOCK_EXTERN(name) extern GStaticMutex G_LOCK_NAME (name)
-
-# ifdef G_DEBUG_LOCKS
-# define G_LOCK(name) G_STMT_START{ \
- g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
- "file %s: line %d (%s): locking: %s ", \
- __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
- #name); \
- g_static_mutex_lock (&G_LOCK_NAME (name)); \
- }G_STMT_END
-# define G_UNLOCK(name) G_STMT_START{ \
- g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
- "file %s: line %d (%s): unlocking: %s ", \
- __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
- #name); \
- g_static_mutex_unlock (&G_LOCK_NAME (name)); \
- }G_STMT_END
-# define G_TRYLOCK(name) G_STMT_START{ \
- g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
- "file %s: line %d (%s): try locking: %s ", \
- __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
- #name); \
- }G_STMT_END, g_static_mutex_trylock (&G_LOCK_NAME (name))
-# else /* !G_DEBUG_LOCKS */
-# define G_LOCK(name) g_static_mutex_lock (&G_LOCK_NAME (name))
-# define G_UNLOCK(name) g_static_mutex_unlock (&G_LOCK_NAME (name))
-# define G_TRYLOCK(name) g_static_mutex_trylock (&G_LOCK_NAME (name))
-# endif /* !G_DEBUG_LOCKS */
-#else /* !G_THREADS_ENABLED */
-# define G_LOCK_DEFINE_STATIC(name) extern void glib_dummy_decl (void)
-# define G_LOCK_DEFINE(name) extern void glib_dummy_decl (void)
-# define G_LOCK_EXTERN(name) extern void glib_dummy_decl (void)
-# define G_LOCK(name)
-# define G_UNLOCK(name)
-# define G_TRYLOCK(name) (FALSE)
-#endif /* !G_THREADS_ENABLED */
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-
-#endif /* __G_LIB_H__ */
diff --git a/glib/glist.c b/glib/glist.c
deleted file mode 100644
index ca37b8da9..000000000
--- a/glib/glist.c
+++ /dev/null
@@ -1,670 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "glib.h"
-
-
-struct _GAllocator /* from gmem.c */
-{
- gchar *name;
- guint16 n_preallocs;
- guint is_unused : 1;
- guint type : 4;
- GAllocator *last;
- GMemChunk *mem_chunk;
- GList *free_lists; /* implementation specific */
-};
-
-static GAllocator *current_allocator = NULL;
-G_LOCK_DEFINE_STATIC (current_allocator);
-
-/* HOLDS: current_allocator_lock */
-static void
-g_list_validate_allocator (GAllocator *allocator)
-{
- g_return_if_fail (allocator != NULL);
- g_return_if_fail (allocator->is_unused == TRUE);
-
- if (allocator->type != G_ALLOCATOR_LIST)
- {
- allocator->type = G_ALLOCATOR_LIST;
- if (allocator->mem_chunk)
- {
- g_mem_chunk_destroy (allocator->mem_chunk);
- allocator->mem_chunk = NULL;
- }
- }
-
- if (!allocator->mem_chunk)
- {
- allocator->mem_chunk = g_mem_chunk_new (allocator->name,
- sizeof (GList),
- sizeof (GList) * allocator->n_preallocs,
- G_ALLOC_ONLY);
- allocator->free_lists = NULL;
- }
-
- allocator->is_unused = FALSE;
-}
-
-void
-g_list_push_allocator(GAllocator *allocator)
-{
- G_LOCK (current_allocator);
- g_list_validate_allocator ( allocator );
- allocator->last = current_allocator;
- current_allocator = allocator;
- G_UNLOCK (current_allocator);
-}
-
-void
-g_list_pop_allocator (void)
-{
- G_LOCK (current_allocator);
- if (current_allocator)
- {
- GAllocator *allocator;
-
- allocator = current_allocator;
- current_allocator = allocator->last;
- allocator->last = NULL;
- allocator->is_unused = TRUE;
- }
- G_UNLOCK (current_allocator);
-}
-
-GList*
-g_list_alloc (void)
-{
- GList *list;
-
- G_LOCK (current_allocator);
- if (!current_allocator)
- {
- GAllocator *allocator = g_allocator_new ("GLib default GList allocator",
- 128);
- g_list_validate_allocator (allocator);
- allocator->last = NULL;
- current_allocator = allocator;
- }
- if (!current_allocator->free_lists)
- {
- list = g_chunk_new (GList, current_allocator->mem_chunk);
- list->data = NULL;
- }
- else
- {
- if (current_allocator->free_lists->data)
- {
- list = current_allocator->free_lists->data;
- current_allocator->free_lists->data = list->next;
- list->data = NULL;
- }
- else
- {
- list = current_allocator->free_lists;
- current_allocator->free_lists = list->next;
- }
- }
- G_UNLOCK (current_allocator);
- list->next = NULL;
- list->prev = NULL;
-
- return list;
-}
-
-void
-g_list_free (GList *list)
-{
- if (list)
- {
- list->data = list->next;
- G_LOCK (current_allocator);
- list->next = current_allocator->free_lists;
- current_allocator->free_lists = list;
- G_UNLOCK (current_allocator);
- }
-}
-
-void
-g_list_free_1 (GList *list)
-{
- if (list)
- {
- list->data = NULL;
- G_LOCK (current_allocator);
- list->next = current_allocator->free_lists;
- current_allocator->free_lists = list;
- G_UNLOCK (current_allocator);
- }
-}
-
-GList*
-g_list_append (GList *list,
- gpointer data)
-{
- GList *new_list;
- GList *last;
-
- new_list = g_list_alloc ();
- new_list->data = data;
-
- if (list)
- {
- last = g_list_last (list);
- /* g_assert (last != NULL); */
- last->next = new_list;
- new_list->prev = last;
-
- return list;
- }
- else
- return new_list;
-}
-
-GList*
-g_list_prepend (GList *list,
- gpointer data)
-{
- GList *new_list;
-
- new_list = g_list_alloc ();
- new_list->data = data;
-
- if (list)
- {
- if (list->prev)
- {
- list->prev->next = new_list;
- new_list->prev = list->prev;
- }
- list->prev = new_list;
- new_list->next = list;
- }
-
- return new_list;
-}
-
-GList*
-g_list_insert (GList *list,
- gpointer data,
- gint position)
-{
- GList *new_list;
- GList *tmp_list;
-
- if (position < 0)
- return g_list_append (list, data);
- else if (position == 0)
- return g_list_prepend (list, data);
-
- tmp_list = g_list_nth (list, position);
- if (!tmp_list)
- return g_list_append (list, data);
-
- new_list = g_list_alloc ();
- new_list->data = data;
-
- if (tmp_list->prev)
- {
- tmp_list->prev->next = new_list;
- new_list->prev = tmp_list->prev;
- }
- new_list->next = tmp_list;
- tmp_list->prev = new_list;
-
- if (tmp_list == list)
- return new_list;
- else
- return list;
-}
-
-GList *
-g_list_concat (GList *list1, GList *list2)
-{
- GList *tmp_list;
-
- if (list2)
- {
- tmp_list = g_list_last (list1);
- if (tmp_list)
- tmp_list->next = list2;
- else
- list1 = list2;
- list2->prev = tmp_list;
- }
-
- return list1;
-}
-
-GList*
-g_list_remove (GList *list,
- gpointer data)
-{
- GList *tmp;
-
- tmp = list;
- while (tmp)
- {
- if (tmp->data != data)
- tmp = tmp->next;
- else
- {
- if (tmp->prev)
- tmp->prev->next = tmp->next;
- if (tmp->next)
- tmp->next->prev = tmp->prev;
-
- if (list == tmp)
- list = list->next;
-
- g_list_free_1 (tmp);
-
- break;
- }
- }
- return list;
-}
-
-GList*
-g_list_remove_link (GList *list,
- GList *link)
-{
- if (link)
- {
- if (link->prev)
- link->prev->next = link->next;
- if (link->next)
- link->next->prev = link->prev;
-
- if (link == list)
- list = list->next;
-
- link->next = NULL;
- link->prev = NULL;
- }
-
- return list;
-}
-
-GList*
-g_list_copy (GList *list)
-{
- GList *new_list = NULL;
-
- if (list)
- {
- GList *last;
-
- new_list = g_list_alloc ();
- new_list->data = list->data;
- last = new_list;
- list = list->next;
- while (list)
- {
- last->next = g_list_alloc ();
- last->next->prev = last;
- last = last->next;
- last->data = list->data;
- list = list->next;
- }
- }
-
- return new_list;
-}
-
-GList*
-g_list_reverse (GList *list)
-{
- GList *last;
-
- last = NULL;
- while (list)
- {
- last = list;
- list = last->next;
- last->next = last->prev;
- last->prev = list;
- }
-
- return last;
-}
-
-GList*
-g_list_nth (GList *list,
- guint n)
-{
- while ((n-- > 0) && list)
- list = list->next;
-
- return list;
-}
-
-gpointer
-g_list_nth_data (GList *list,
- guint n)
-{
- while ((n-- > 0) && list)
- list = list->next;
-
- return list ? list->data : NULL;
-}
-
-GList*
-g_list_find (GList *list,
- gpointer data)
-{
- while (list)
- {
- if (list->data == data)
- break;
- list = list->next;
- }
-
- return list;
-}
-
-GList*
-g_list_find_custom (GList *list,
- gpointer data,
- GCompareFunc func)
-{
- g_return_val_if_fail (func != NULL, list);
-
- while (list)
- {
- if (! func (list->data, data))
- return list;
- list = list->next;
- }
-
- return NULL;
-}
-
-
-gint
-g_list_position (GList *list,
- GList *link)
-{
- gint i;
-
- i = 0;
- while (list)
- {
- if (list == link)
- return i;
- i++;
- list = list->next;
- }
-
- return -1;
-}
-
-gint
-g_list_index (GList *list,
- gpointer data)
-{
- gint i;
-
- i = 0;
- while (list)
- {
- if (list->data == data)
- return i;
- i++;
- list = list->next;
- }
-
- return -1;
-}
-
-GList*
-g_list_last (GList *list)
-{
- if (list)
- {
- while (list->next)
- list = list->next;
- }
-
- return list;
-}
-
-GList*
-g_list_first (GList *list)
-{
- if (list)
- {
- while (list->prev)
- list = list->prev;
- }
-
- return list;
-}
-
-guint
-g_list_length (GList *list)
-{
- guint length;
-
- length = 0;
- while (list)
- {
- length++;
- list = list->next;
- }
-
- return length;
-}
-
-void
-g_list_foreach (GList *list,
- GFunc func,
- gpointer user_data)
-{
- while (list)
- {
- (*func) (list->data, user_data);
- list = list->next;
- }
-}
-
-
-GList*
-g_list_insert_sorted (GList *list,
- gpointer data,
- GCompareFunc func)
-{
- GList *tmp_list = list;
- GList *new_list;
- gint cmp;
-
- g_return_val_if_fail (func != NULL, list);
-
- if (!list)
- {
- new_list = g_list_alloc();
- new_list->data = data;
- return new_list;
- }
-
- cmp = (*func) (data, tmp_list->data);
-
- while ((tmp_list->next) && (cmp > 0))
- {
- tmp_list = tmp_list->next;
- cmp = (*func) (data, tmp_list->data);
- }
-
- new_list = g_list_alloc();
- new_list->data = data;
-
- if ((!tmp_list->next) && (cmp > 0))
- {
- tmp_list->next = new_list;
- new_list->prev = tmp_list;
- return list;
- }
-
- if (tmp_list->prev)
- {
- tmp_list->prev->next = new_list;
- new_list->prev = tmp_list->prev;
- }
- new_list->next = tmp_list;
- tmp_list->prev = new_list;
-
- if (tmp_list == list)
- return new_list;
- else
- return list;
-}
-
-static GList *
-g_list_sort_merge (GList *l1,
- GList *l2,
- GCompareFunc compare_func)
-{
- GList list, *l, *lprev;
-
- l = &list;
- lprev = NULL;
-
- while (l1 && l2)
- {
- if (compare_func (l1->data, l2->data) < 0)
- {
- l->next = l1;
- l = l->next;
- l->prev = lprev;
- lprev = l;
- l1 = l1->next;
- }
- else
- {
- l->next = l2;
- l = l->next;
- l->prev = lprev;
- lprev = l;
- l2 = l2->next;
- }
- }
- l->next = l1 ? l1 : l2;
- l->next->prev = l;
-
- return list.next;
-}
-
-GList*
-g_list_sort (GList *list,
- GCompareFunc compare_func)
-{
- GList *l1, *l2;
-
- if (!list)
- return NULL;
- if (!list->next)
- return list;
-
- l1 = list;
- l2 = list->next;
-
- while ((l2 = l2->next) != NULL)
- {
- if ((l2 = l2->next) == NULL)
- break;
- l1 = l1->next;
- }
- l2 = l1->next;
- l1->next = NULL;
-
- return g_list_sort_merge (g_list_sort (list, compare_func),
- g_list_sort (l2, compare_func),
- compare_func);
-}
-
-GList*
-g_list_sort2 (GList *list,
- GCompareFunc compare_func)
-{
- GSList *runs = NULL;
- GList *tmp;
-
- /* Degenerate case. */
- if (!list) return NULL;
-
- /* Assume: list = [12,2,4,11,2,4,6,1,1,12]. */
- for (tmp = list; tmp; )
- {
- GList *tmp2;
- for (tmp2 = tmp;
- tmp2->next && compare_func (tmp2->data, tmp2->next->data) <= 0;
- tmp2 = tmp2->next)
- /* Nothing */;
- runs = g_slist_append (runs, tmp);
- tmp = tmp2->next;
- tmp2->next = NULL;
- }
- /* Now: runs = [[12],[2,4,11],[2,4,6],[1,1,12]]. */
-
- while (runs->next)
- {
- /* We have more than one run. Merge pairwise. */
- GSList *dst, *src, *dstprev = NULL;
- dst = src = runs;
- while (src && src->next)
- {
- dst->data = g_list_sort_merge (src->data,
- src->next->data,
- compare_func);
- dstprev = dst;
- dst = dst->next;
- src = src->next->next;
- }
-
- /* If number of runs was odd, just keep the last. */
- if (src)
- {
- dst->data = src->data;
- dstprev = dst;
- dst = dst->next;
- }
-
- dstprev->next = NULL;
- g_slist_free (dst);
- }
-
- /* After 1st loop: runs = [[2,4,11,12],[1,1,2,4,6,12]]. */
- /* After 2nd loop: runs = [[1,1,2,2,4,4,6,11,12,12]]. */
-
- list = runs->data;
- g_slist_free (runs);
- return list;
-}
diff --git a/glib/gmain.c b/glib/gmain.c
deleted file mode 100644
index 8ead8a017..000000000
--- a/glib/gmain.c
+++ /dev/null
@@ -1,1392 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * gmain.c: Main loop abstraction, timeouts, and idle functions
- * Copyright 1998 Owen Taylor
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "config.h"
-
-/* uncomment the next line to get poll() debugging info */
-/* #define G_MAIN_POLL_DEBUG */
-
-
-
-#include "glib.h"
-#include <sys/types.h>
-#include <time.h>
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif /* HAVE_SYS_TIME_H */
-#ifdef GLIB_HAVE_SYS_POLL_H
-# include <sys/poll.h>
-# undef events /* AIX 4.1.5 & 4.3.2 define this for SVR3,4 compatibility */
-# undef revents /* AIX 4.1.5 & 4.3.2 define this for SVR3,4 compatibility */
-#endif /* GLIB_HAVE_SYS_POLL_H */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#include <errno.h>
-
-#ifdef NATIVE_WIN32
-#define STRICT
-#include <windows.h>
-#endif /* NATIVE_WIN32 */
-
-#ifdef _MSC_VER
-#include <fcntl.h>
-#include <io.h>
-#endif /* _MSC_VER */
-
-/* Types */
-
-typedef struct _GTimeoutData GTimeoutData;
-typedef struct _GSource GSource;
-typedef struct _GPollRec GPollRec;
-
-typedef enum
-{
- G_SOURCE_READY = 1 << G_HOOK_FLAG_USER_SHIFT,
- G_SOURCE_CAN_RECURSE = 1 << (G_HOOK_FLAG_USER_SHIFT + 1)
-} GSourceFlags;
-
-struct _GSource
-{
- GHook hook;
- gint priority;
- gpointer source_data;
-};
-
-struct _GMainLoop
-{
- gboolean is_running;
-};
-
-struct _GTimeoutData
-{
- GTimeVal expiration;
- gint interval;
- GSourceFunc callback;
-};
-
-struct _GPollRec
-{
- gint priority;
- GPollFD *fd;
- GPollRec *next;
-};
-
-/* Forward declarations */
-
-static gint g_source_compare (GHook *a,
- GHook *b);
-static void g_source_destroy_func (GHookList *hook_list,
- GHook *hook);
-static void g_main_poll (gint timeout,
- gboolean use_priority,
- gint priority);
-static void g_main_add_poll_unlocked (gint priority,
- GPollFD *fd);
-static void g_main_wakeup (void);
-
-static gboolean g_timeout_prepare (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout,
- gpointer user_data);
-static gboolean g_timeout_check (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data);
-static gboolean g_timeout_dispatch (gpointer source_data,
- GTimeVal *dispatch_time,
- gpointer user_data);
-static gboolean g_idle_prepare (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout,
- gpointer user_data);
-static gboolean g_idle_check (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data);
-static gboolean g_idle_dispatch (gpointer source_data,
- GTimeVal *dispatch_time,
- gpointer user_data);
-
-/* Data */
-
-static GSList *pending_dispatches = NULL;
-static GHookList source_list = { 0 };
-static gint in_check_or_prepare = 0;
-
-/* The following lock is used for both the list of sources
- * and the list of poll records
- */
-G_LOCK_DEFINE_STATIC (main_loop);
-
-static GSourceFuncs timeout_funcs =
-{
- g_timeout_prepare,
- g_timeout_check,
- g_timeout_dispatch,
- g_free,
-};
-
-static GSourceFuncs idle_funcs =
-{
- g_idle_prepare,
- g_idle_check,
- g_idle_dispatch,
- NULL,
-};
-
-static GPollRec *poll_records = NULL;
-static GPollRec *poll_free_list = NULL;
-static GMemChunk *poll_chunk;
-static guint n_poll_records = 0;
-
-#ifdef G_THREADS_ENABLED
-#ifndef NATIVE_WIN32
-/* this pipe is used to wake up the main loop when a source is added.
- */
-static gint wake_up_pipe[2] = { -1, -1 };
-#else /* NATIVE_WIN32 */
-static HANDLE wake_up_semaphore = NULL;
-#endif /* NATIVE_WIN32 */
-static GPollFD wake_up_rec;
-static gboolean poll_waiting = FALSE;
-
-/* Flag indicating whether the set of fd's changed during a poll */
-static gboolean poll_changed = FALSE;
-#endif /* G_THREADS_ENABLED */
-
-#ifdef HAVE_POLL
-/* SunOS has poll, but doesn't provide a prototype. */
-# if defined (sun) && !defined (__SVR4)
-extern gint poll (GPollFD *ufds, guint nfsd, gint timeout);
-# endif /* !sun */
-static GPollFunc poll_func = (GPollFunc) poll;
-#else /* !HAVE_POLL */
-#ifdef NATIVE_WIN32
-
-static gint
-g_poll (GPollFD *fds, guint nfds, gint timeout)
-{
- HANDLE handles[MAXIMUM_WAIT_OBJECTS];
- GPollFD *f;
- DWORD ready;
- MSG msg;
- UINT timer;
- LONG prevcnt;
- gint poll_msgs = -1;
- gint nhandles = 0;
-
- for (f = fds; f < &fds[nfds]; ++f)
- if (f->fd >= 0)
- {
- if (f->events & G_IO_IN)
- if (f->fd == G_WIN32_MSG_HANDLE)
- poll_msgs = f - fds;
- else
- {
- /* g_print ("g_poll: waiting for handle %#x\n", f->fd); */
- handles[nhandles++] = (HANDLE) f->fd;
- }
- }
-
- if (timeout == -1)
- timeout = INFINITE;
-
- if (poll_msgs >= 0)
- {
- /* Waiting for messages, and maybe events */
- if (nhandles == 0)
- {
- if (timeout == INFINITE)
- {
- /* Waiting just for messages, infinite timeout
- * -> Use PeekMessage, then WaitMessage
- */
- /* g_print ("WaitMessage, PeekMessage\n"); */
- if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
- ready = WAIT_OBJECT_0;
- else if (!WaitMessage ())
- g_warning ("g_poll: WaitMessage failed");
- ready = WAIT_OBJECT_0;
- }
- else if (timeout == 0)
- {
- /* Waiting just for messages, zero timeout
- * -> Use PeekMessage
- */
- /* g_print ("PeekMessage\n"); */
- if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
- ready = WAIT_OBJECT_0;
- else
- ready = WAIT_TIMEOUT;
- }
- else
- {
- /* Waiting just for messages, some timeout
- * -> First try PeekMessage, then set a timer, wait for message,
- * kill timer, use PeekMessage
- */
- /* g_print ("PeekMessage\n"); */
- if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
- ready = WAIT_OBJECT_0;
- else if ((timer = SetTimer (NULL, 0, timeout, NULL)) == 0)
- g_warning ("g_poll: SetTimer failed");
- else
- {
- /* g_print ("WaitMessage\n"); */
- WaitMessage ();
- KillTimer (NULL, timer);
- if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
- ready = WAIT_OBJECT_0;
- else
- ready = WAIT_TIMEOUT;
- }
- }
- }
- else
- {
- /* Wait for either message or event
- * -> Use MsgWaitForMultipleObjects
- */
- /* g_print ("MsgWaitForMultipleObjects(%d, %d)\n", nhandles, timeout); */
- ready = MsgWaitForMultipleObjects (nhandles, handles, FALSE,
- timeout, QS_ALLINPUT);
- /* g_print("=%d\n", ready); */
- if (ready == WAIT_FAILED)
- g_warning ("g_poll: MsgWaitForMultipleObjects failed");
- }
- }
- else if (nhandles == 0)
- {
- /* Wait for nothing (huh?) */
- return 0;
- }
- else
- {
- /* Wait for just events
- * -> Use WaitForMultipleObjects
- */
- /* g_print ("WaitForMultipleObjects(%d, %d)\n", nhandles, timeout); */
- ready = WaitForMultipleObjects (nhandles, handles, FALSE, timeout);
- /* g_print("=%d\n", ready); */
- if (ready == WAIT_FAILED)
- g_warning ("g_poll: WaitForMultipleObjects failed");
- }
-
- for (f = fds; f < &fds[nfds]; ++f)
- f->revents = 0;
-
- if (ready == WAIT_FAILED)
- return -1;
- else if (poll_msgs >= 0 && ready == WAIT_OBJECT_0 + nhandles)
- {
- fds[poll_msgs].revents |= G_IO_IN;
- }
- else if (ready >= WAIT_OBJECT_0 && ready < WAIT_OBJECT_0 + nhandles)
- for (f = fds; f < &fds[nfds]; ++f)
- {
- if ((f->events & G_IO_IN)
- && f->fd == (gint) handles[ready - WAIT_OBJECT_0])
- {
- f->revents |= G_IO_IN;
- /* g_print ("event %#x\n", f->fd); */
- ResetEvent ((HANDLE) f->fd);
- }
- }
-
- if (ready == WAIT_TIMEOUT)
- return 0;
- else
- return 1;
-}
-
-#else /* !NATIVE_WIN32 */
-
-/* The following implementation of poll() comes from the GNU C Library.
- * Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
- */
-
-#include <string.h> /* for bzero on BSD systems */
-
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif /* HAVE_SYS_SELECT_H_ */
-
-#ifndef NO_FD_SET
-# define SELECT_MASK fd_set
-#else /* !NO_FD_SET */
-# ifndef _AIX
-typedef long fd_mask;
-# endif /* _AIX */
-# ifdef _IBMR2
-# define SELECT_MASK void
-# else /* !_IBMR2 */
-# define SELECT_MASK int
-# endif /* !_IBMR2 */
-#endif /* !NO_FD_SET */
-
-static gint
-g_poll (GPollFD *fds,
- guint nfds,
- gint timeout)
-{
- struct timeval tv;
- SELECT_MASK rset, wset, xset;
- GPollFD *f;
- int ready;
- int maxfd = 0;
-
- FD_ZERO (&rset);
- FD_ZERO (&wset);
- FD_ZERO (&xset);
-
- for (f = fds; f < &fds[nfds]; ++f)
- if (f->fd >= 0)
- {
- if (f->events & G_IO_IN)
- FD_SET (f->fd, &rset);
- if (f->events & G_IO_OUT)
- FD_SET (f->fd, &wset);
- if (f->events & G_IO_PRI)
- FD_SET (f->fd, &xset);
- if (f->fd > maxfd && (f->events & (G_IO_IN|G_IO_OUT|G_IO_PRI)))
- maxfd = f->fd;
- }
-
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = (timeout % 1000) * 1000;
-
- ready = select (maxfd + 1, &rset, &wset, &xset,
- timeout == -1 ? NULL : &tv);
- if (ready > 0)
- for (f = fds; f < &fds[nfds]; ++f)
- {
- f->revents = 0;
- if (f->fd >= 0)
- {
- if (FD_ISSET (f->fd, &rset))
- f->revents |= G_IO_IN;
- if (FD_ISSET (f->fd, &wset))
- f->revents |= G_IO_OUT;
- if (FD_ISSET (f->fd, &xset))
- f->revents |= G_IO_PRI;
- }
- }
-
- return ready;
-}
-
-#endif /* !NATIVE_WIN32 */
-
-static GPollFunc poll_func = g_poll;
-#endif /* !HAVE_POLL */
-
-/* Hooks for adding to the main loop */
-
-/* Use knowledge of insert_sorted algorithm here to make
- * sure we insert at the end of equal priority items
- */
-static gint
-g_source_compare (GHook *a,
- GHook *b)
-{
- GSource *source_a = (GSource *)a;
- GSource *source_b = (GSource *)b;
-
- return (source_a->priority < source_b->priority) ? -1 : 1;
-}
-
-/* HOLDS: main_loop lock */
-static void
-g_source_destroy_func (GHookList *hook_list,
- GHook *hook)
-{
- GSource *source = (GSource*) hook;
- GDestroyNotify destroy;
-
- G_UNLOCK (main_loop);
-
- destroy = hook->destroy;
- if (destroy)
- destroy (hook->data);
-
- destroy = ((GSourceFuncs*) hook->func)->destroy;
- if (destroy)
- destroy (source->source_data);
-
- G_LOCK (main_loop);
-}
-
-guint
-g_source_add (gint priority,
- gboolean can_recurse,
- GSourceFuncs *funcs,
- gpointer source_data,
- gpointer user_data,
- GDestroyNotify notify)
-{
- guint return_val;
- GSource *source;
-
- G_LOCK (main_loop);
-
- if (!source_list.is_setup)
- {
- g_hook_list_init (&source_list, sizeof (GSource));
-
- source_list.hook_destroy = G_HOOK_DEFERRED_DESTROY;
- source_list.hook_free = g_source_destroy_func;
- }
-
- source = (GSource*) g_hook_alloc (&source_list);
- source->priority = priority;
- source->source_data = source_data;
- source->hook.func = funcs;
- source->hook.data = user_data;
- source->hook.destroy = notify;
-
- g_hook_insert_sorted (&source_list,
- (GHook *)source,
- g_source_compare);
-
- if (can_recurse)
- source->hook.flags |= G_SOURCE_CAN_RECURSE;
-
- return_val = source->hook.hook_id;
-
-#ifdef G_THREADS_ENABLED
- /* Now wake up the main loop if it is waiting in the poll() */
- g_main_wakeup ();
-#endif
-
- G_UNLOCK (main_loop);
-
- return return_val;
-}
-
-gboolean
-g_source_remove (guint tag)
-{
- GHook *hook;
-
- g_return_val_if_fail (tag > 0, FALSE);
-
- G_LOCK (main_loop);
-
- hook = g_hook_get (&source_list, tag);
- if (hook)
- g_hook_destroy_link (&source_list, hook);
-
- G_UNLOCK (main_loop);
-
- return hook != NULL;
-}
-
-gboolean
-g_source_remove_by_user_data (gpointer user_data)
-{
- GHook *hook;
-
- G_LOCK (main_loop);
-
- hook = g_hook_find_data (&source_list, TRUE, user_data);
- if (hook)
- g_hook_destroy_link (&source_list, hook);
-
- G_UNLOCK (main_loop);
-
- return hook != NULL;
-}
-
-static gboolean
-g_source_find_source_data (GHook *hook,
- gpointer data)
-{
- GSource *source = (GSource *)hook;
-
- return (source->source_data == data);
-}
-
-gboolean
-g_source_remove_by_source_data (gpointer source_data)
-{
- GHook *hook;
-
- G_LOCK (main_loop);
-
- hook = g_hook_find (&source_list, TRUE,
- g_source_find_source_data, source_data);
- if (hook)
- g_hook_destroy_link (&source_list, hook);
-
- G_UNLOCK (main_loop);
-
- return hook != NULL;
-}
-
-static gboolean
-g_source_find_funcs_user_data (GHook *hook,
- gpointer data)
-{
- gpointer *d = data;
-
- return hook->func == d[0] && hook->data == d[1];
-}
-
-gboolean
-g_source_remove_by_funcs_user_data (GSourceFuncs *funcs,
- gpointer user_data)
-{
- gpointer d[2];
- GHook *hook;
-
- g_return_val_if_fail (funcs != NULL, FALSE);
-
- G_LOCK (main_loop);
-
- d[0] = funcs;
- d[1] = user_data;
-
- hook = g_hook_find (&source_list, TRUE,
- g_source_find_funcs_user_data, d);
- if (hook)
- g_hook_destroy_link (&source_list, hook);
-
- G_UNLOCK (main_loop);
-
- return hook != NULL;
-}
-
-void
-g_get_current_time (GTimeVal *result)
-{
-#ifndef _MSC_VER
- struct timeval r;
- g_return_if_fail (result != NULL);
-
- /*this is required on alpha, there the timeval structs are int's
- not longs and a cast only would fail horribly*/
- gettimeofday (&r, NULL);
- result->tv_sec = r.tv_sec;
- result->tv_usec = r.tv_usec;
-#else
- /* Avoid calling time() except for the first time.
- * GetTickCount() should be pretty fast and low-level?
- * I could also use ftime() but it seems unnecessarily overheady.
- */
- static DWORD start_tick = 0;
- static time_t start_time;
- DWORD tick;
- time_t t;
-
- g_return_if_fail (result != NULL);
-
- if (start_tick == 0)
- {
- start_tick = GetTickCount ();
- time (&start_time);
- }
-
- tick = GetTickCount ();
-
- result->tv_sec = (tick - start_tick) / 1000 + start_time;
- result->tv_usec = ((tick - start_tick) % 1000) * 1000;
-#endif
-}
-
-/* Running the main loop */
-
-/* HOLDS: main_loop_lock */
-static void
-g_main_dispatch (GTimeVal *dispatch_time)
-{
- while (pending_dispatches != NULL)
- {
- gboolean need_destroy;
- GSource *source = pending_dispatches->data;
- GSList *tmp_list;
-
- tmp_list = pending_dispatches;
- pending_dispatches = g_slist_remove_link (pending_dispatches, pending_dispatches);
- g_slist_free_1 (tmp_list);
-
- if (G_HOOK_IS_VALID (source))
- {
- gboolean was_in_call;
- gpointer hook_data = source->hook.data;
- gpointer source_data = source->source_data;
- gboolean (*dispatch) (gpointer,
- GTimeVal *,
- gpointer);
-
- dispatch = ((GSourceFuncs *) source->hook.func)->dispatch;
-
- was_in_call = G_HOOK_IN_CALL (source);
- source->hook.flags |= G_HOOK_FLAG_IN_CALL;
-
- G_UNLOCK (main_loop);
- need_destroy = ! dispatch (source_data,
- dispatch_time,
- hook_data);
- G_LOCK (main_loop);
-
- if (!was_in_call)
- source->hook.flags &= ~G_HOOK_FLAG_IN_CALL;
-
- if (need_destroy && G_HOOK_IS_VALID (source))
- g_hook_destroy_link (&source_list, (GHook *) source);
- }
-
- g_hook_unref (&source_list, (GHook*) source);
- }
-}
-
-/* g_main_iterate () runs a single iteration of the mainloop, or,
- * if !dispatch checks to see if any sources need dispatching.
- * basic algorithm for dispatch=TRUE:
- *
- * 1) while the list of currently pending sources is non-empty,
- * we call (*dispatch) on those that are !IN_CALL or can_recurse,
- * removing sources from the list after each returns.
- * the return value of (*dispatch) determines whether the source
- * itself is kept alive.
- *
- * 2) call (*prepare) for sources that are not yet SOURCE_READY and
- * are !IN_CALL or can_recurse. a return value of TRUE determines
- * that the source would like to be dispatched immediatedly, it
- * is then flagged as SOURCE_READY.
- *
- * 3) poll with the pollfds from all sources at the priority of the
- * first source flagged as SOURCE_READY. if there are any sources
- * flagged as SOURCE_READY, we use a timeout of 0 or the minimum
- * of all timouts otherwise.
- *
- * 4) for each source !IN_CALL or can_recurse, if SOURCE_READY or
- * (*check) returns true, add the source to the pending list.
- * once one source returns true, stop after checking all sources
- * at that priority.
- *
- * 5) while the list of currently pending sources is non-empty,
- * call (*dispatch) on each source, removing the source
- * after the call.
- *
- */
-static gboolean
-g_main_iterate (gboolean block,
- gboolean dispatch)
-{
- GHook *hook;
- GTimeVal current_time = { 0, 0 };
- gint n_ready = 0;
- gint current_priority = 0;
- gint timeout;
- gboolean retval = FALSE;
-
- g_return_val_if_fail (!block || dispatch, FALSE);
-
- g_get_current_time (&current_time);
-
- G_LOCK (main_loop);
-
-#ifdef G_THREADS_ENABLED
- if (poll_waiting)
- {
- g_warning("g_main_iterate(): main loop already active in another thread");
- G_UNLOCK (main_loop);
- return FALSE;
- }
-#endif
-
- /* If recursing, finish up current dispatch, before starting over */
- if (pending_dispatches)
- {
- if (dispatch)
- g_main_dispatch (&current_time);
-
- G_UNLOCK (main_loop);
-
- return TRUE;
- }
-
- /* Prepare all sources */
-
- timeout = block ? -1 : 0;
-
- hook = g_hook_first_valid (&source_list, TRUE);
- while (hook)
- {
- GSource *source = (GSource*) hook;
- gint source_timeout = -1;
-
- if ((n_ready > 0) && (source->priority > current_priority))
- {
- g_hook_unref (&source_list, hook);
- break;
- }
- if (G_HOOK_IN_CALL (hook) && !(hook->flags & G_SOURCE_CAN_RECURSE))
- {
- hook = g_hook_next_valid (&source_list, hook, TRUE);
- continue;
- }
-
- if (!(hook->flags & G_SOURCE_READY))
- {
- gboolean (*prepare) (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout,
- gpointer user_data);
-
- prepare = ((GSourceFuncs *) hook->func)->prepare;
- in_check_or_prepare++;
- G_UNLOCK (main_loop);
-
- if ((*prepare) (source->source_data, &current_time, &source_timeout, source->hook.data))
- hook->flags |= G_SOURCE_READY;
-
- G_LOCK (main_loop);
- in_check_or_prepare--;
- }
-
- if (hook->flags & G_SOURCE_READY)
- {
- if (!dispatch)
- {
- g_hook_unref (&source_list, hook);
- G_UNLOCK (main_loop);
-
- return TRUE;
- }
- else
- {
- n_ready++;
- current_priority = source->priority;
- timeout = 0;
- }
- }
-
- if (source_timeout >= 0)
- {
- if (timeout < 0)
- timeout = source_timeout;
- else
- timeout = MIN (timeout, source_timeout);
- }
-
- hook = g_hook_next_valid (&source_list, hook, TRUE);
- }
-
- /* poll(), if necessary */
-
- g_main_poll (timeout, n_ready > 0, current_priority);
-
- if (timeout != 0)
- g_get_current_time (&current_time);
-
- /* Check to see what sources need to be dispatched */
-
- n_ready = 0;
-
- hook = g_hook_first_valid (&source_list, TRUE);
- while (hook)
- {
- GSource *source = (GSource *)hook;
-
- if ((n_ready > 0) && (source->priority > current_priority))
- {
- g_hook_unref (&source_list, hook);
- break;
- }
- if (G_HOOK_IN_CALL (hook) && !(hook->flags & G_SOURCE_CAN_RECURSE))
- {
- hook = g_hook_next_valid (&source_list, hook, TRUE);
- continue;
- }
-
- if (!(hook->flags & G_SOURCE_READY))
- {
- gboolean (*check) (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data);
-
- check = ((GSourceFuncs *) hook->func)->check;
- in_check_or_prepare++;
- G_UNLOCK (main_loop);
-
- if ((*check) (source->source_data, &current_time, source->hook.data))
- hook->flags |= G_SOURCE_READY;
-
- G_LOCK (main_loop);
- in_check_or_prepare--;
- }
-
- if (hook->flags & G_SOURCE_READY)
- {
- if (dispatch)
- {
- hook->flags &= ~G_SOURCE_READY;
- g_hook_ref (&source_list, hook);
- pending_dispatches = g_slist_prepend (pending_dispatches, source);
- current_priority = source->priority;
- n_ready++;
- }
- else
- {
- g_hook_unref (&source_list, hook);
- G_UNLOCK (main_loop);
-
- return TRUE;
- }
- }
-
- hook = g_hook_next_valid (&source_list, hook, TRUE);
- }
-
- /* Now invoke the callbacks */
-
- if (pending_dispatches)
- {
- pending_dispatches = g_slist_reverse (pending_dispatches);
- g_main_dispatch (&current_time);
- retval = TRUE;
- }
-
- G_UNLOCK (main_loop);
-
- return retval;
-}
-
-/* See if any events are pending
- */
-gboolean
-g_main_pending (void)
-{
- return in_check_or_prepare ? FALSE : g_main_iterate (FALSE, FALSE);
-}
-
-/* Run a single iteration of the mainloop. If block is FALSE,
- * will never block
- */
-gboolean
-g_main_iteration (gboolean block)
-{
- if (in_check_or_prepare)
- {
- g_warning ("g_main_iteration(): called recursively from within a source's check() or "
- "prepare() member or from a second thread, iteration not possible");
- return FALSE;
- }
- else
- return g_main_iterate (block, TRUE);
-}
-
-GMainLoop*
-g_main_new (gboolean is_running)
-{
- GMainLoop *loop;
-
- loop = g_new0 (GMainLoop, 1);
- loop->is_running = is_running != FALSE;
-
- return loop;
-}
-
-void
-g_main_run (GMainLoop *loop)
-{
- g_return_if_fail (loop != NULL);
-
- if (in_check_or_prepare)
- {
- g_warning ("g_main_run(): called recursively from within a source's check() or "
- "prepare() member or from a second thread, iteration not possible");
- return;
- }
-
- loop->is_running = TRUE;
- while (loop->is_running)
- g_main_iterate (TRUE, TRUE);
-}
-
-void
-g_main_quit (GMainLoop *loop)
-{
- g_return_if_fail (loop != NULL);
-
- loop->is_running = FALSE;
-}
-
-void
-g_main_destroy (GMainLoop *loop)
-{
- g_return_if_fail (loop != NULL);
-
- g_free (loop);
-}
-
-gboolean
-g_main_is_running (GMainLoop *loop)
-{
- g_return_val_if_fail (loop != NULL, FALSE);
-
- return loop->is_running;
-}
-
-/* HOLDS: main_loop_lock */
-static void
-g_main_poll (gint timeout,
- gboolean use_priority,
- gint priority)
-{
-#ifdef G_MAIN_POLL_DEBUG
- GTimer *poll_timer;
-#endif
- GPollFD *fd_array;
- GPollRec *pollrec;
- gint i;
- gint npoll;
-
-#ifdef G_THREADS_ENABLED
-#ifndef NATIVE_WIN32
- if (wake_up_pipe[0] < 0)
- {
- if (pipe (wake_up_pipe) < 0)
- g_error ("Cannot create pipe main loop wake-up: %s\n",
- g_strerror (errno));
-
- wake_up_rec.fd = wake_up_pipe[0];
- wake_up_rec.events = G_IO_IN;
- g_main_add_poll_unlocked (0, &wake_up_rec);
- }
-#else
- if (wake_up_semaphore == NULL)
- {
- if ((wake_up_semaphore = CreateSemaphore (NULL, 0, 100, NULL)) == NULL)
- g_error ("Cannot create wake-up semaphore: %d", GetLastError ());
- wake_up_rec.fd = (gint) wake_up_semaphore;
- wake_up_rec.events = G_IO_IN;
- g_main_add_poll_unlocked (0, &wake_up_rec);
- }
-#endif
-#endif
- fd_array = g_new (GPollFD, n_poll_records);
-
- pollrec = poll_records;
- i = 0;
- while (pollrec && (!use_priority || priority >= pollrec->priority))
- {
- if (pollrec->fd->events)
- {
- fd_array[i].fd = pollrec->fd->fd;
- /* In direct contradiction to the Unix98 spec, IRIX runs into
- * difficulty if you pass in POLLERR, POLLHUP or POLLNVAL
- * flags in the events field of the pollfd while it should
- * just ignoring them. So we mask them out here.
- */
- fd_array[i].events = pollrec->fd->events & ~(G_IO_ERR|G_IO_HUP|G_IO_NVAL);
- fd_array[i].revents = 0;
- i++;
- }
-
- pollrec = pollrec->next;
- }
-#ifdef G_THREADS_ENABLED
- poll_waiting = TRUE;
- poll_changed = FALSE;
-#endif
-
- npoll = i;
- if (npoll || timeout != 0)
- {
-#ifdef G_MAIN_POLL_DEBUG
- g_print ("g_main_poll(%d) timeout: %d\r", npoll, timeout);
- poll_timer = g_timer_new ();
-#endif
-
- G_UNLOCK (main_loop);
- (*poll_func) (fd_array, npoll, timeout);
- G_LOCK (main_loop);
-
-#ifdef G_MAIN_POLL_DEBUG
- g_print ("g_main_poll(%d) timeout: %d - elapsed %12.10f seconds",
- npoll,
- timeout,
- g_timer_elapsed (poll_timer, NULL));
- g_timer_destroy (poll_timer);
- pollrec = poll_records;
- i = 0;
- while (i < npoll)
- {
- if (pollrec->fd->events)
- {
- if (fd_array[i].revents)
- {
- g_print (" [%d:", fd_array[i].fd);
- if (fd_array[i].revents & G_IO_IN)
- g_print ("i");
- if (fd_array[i].revents & G_IO_OUT)
- g_print ("o");
- if (fd_array[i].revents & G_IO_PRI)
- g_print ("p");
- if (fd_array[i].revents & G_IO_ERR)
- g_print ("e");
- if (fd_array[i].revents & G_IO_HUP)
- g_print ("h");
- if (fd_array[i].revents & G_IO_NVAL)
- g_print ("n");
- g_print ("]");
- }
- i++;
- }
- pollrec = pollrec->next;
- }
- g_print ("\n");
-#endif
- } /* if (npoll || timeout != 0) */
-
-#ifdef G_THREADS_ENABLED
- if (!poll_waiting)
- {
-#ifndef NATIVE_WIN32
- gchar c;
- read (wake_up_pipe[0], &c, 1);
-#endif
- }
- else
- poll_waiting = FALSE;
-
- /* If the set of poll file descriptors changed, bail out
- * and let the main loop rerun
- */
- if (poll_changed)
- {
- g_free (fd_array);
- return;
- }
-#endif
-
- pollrec = poll_records;
- i = 0;
- while (i < npoll)
- {
- if (pollrec->fd->events)
- {
- pollrec->fd->revents = fd_array[i].revents;
- i++;
- }
- pollrec = pollrec->next;
- }
-
- g_free (fd_array);
-}
-
-void
-g_main_add_poll (GPollFD *fd,
- gint priority)
-{
- G_LOCK (main_loop);
- g_main_add_poll_unlocked (priority, fd);
- G_UNLOCK (main_loop);
-}
-
-/* HOLDS: main_loop_lock */
-static void
-g_main_add_poll_unlocked (gint priority,
- GPollFD *fd)
-{
- GPollRec *lastrec, *pollrec, *newrec;
-
- if (!poll_chunk)
- poll_chunk = g_mem_chunk_create (GPollRec, 32, G_ALLOC_ONLY);
-
- if (poll_free_list)
- {
- newrec = poll_free_list;
- poll_free_list = newrec->next;
- }
- else
- newrec = g_chunk_new (GPollRec, poll_chunk);
-
- /* This file descriptor may be checked before we ever poll */
- fd->revents = 0;
- newrec->fd = fd;
- newrec->priority = priority;
-
- lastrec = NULL;
- pollrec = poll_records;
- while (pollrec && priority >= pollrec->priority)
- {
- lastrec = pollrec;
- pollrec = pollrec->next;
- }
-
- if (lastrec)
- lastrec->next = newrec;
- else
- poll_records = newrec;
-
- newrec->next = pollrec;
-
- n_poll_records++;
-
-#ifdef G_THREADS_ENABLED
- poll_changed = TRUE;
-
- /* Now wake up the main loop if it is waiting in the poll() */
- g_main_wakeup ();
-#endif
-}
-
-void
-g_main_remove_poll (GPollFD *fd)
-{
- GPollRec *pollrec, *lastrec;
-
- G_LOCK (main_loop);
-
- lastrec = NULL;
- pollrec = poll_records;
-
- while (pollrec)
- {
- if (pollrec->fd == fd)
- {
- if (lastrec != NULL)
- lastrec->next = pollrec->next;
- else
- poll_records = pollrec->next;
-
- pollrec->next = poll_free_list;
- poll_free_list = pollrec;
-
- n_poll_records--;
- break;
- }
- lastrec = pollrec;
- pollrec = pollrec->next;
- }
-
-#ifdef G_THREADS_ENABLED
- poll_changed = TRUE;
-
- /* Now wake up the main loop if it is waiting in the poll() */
- g_main_wakeup ();
-#endif
-
- G_UNLOCK (main_loop);
-}
-
-void
-g_main_set_poll_func (GPollFunc func)
-{
- if (func)
- poll_func = func;
- else
-#ifdef HAVE_POLL
- poll_func = (GPollFunc) poll;
-#else
- poll_func = (GPollFunc) g_poll;
-#endif
-}
-
-/* Wake the main loop up from a poll() */
-static void
-g_main_wakeup (void)
-{
-#ifdef G_THREADS_ENABLED
- if (poll_waiting)
- {
- poll_waiting = FALSE;
-#ifndef NATIVE_WIN32
- write (wake_up_pipe[1], "A", 1);
-#else
- ReleaseSemaphore (wake_up_semaphore, 1, NULL);
-#endif
- }
-#endif
-}
-
-/* Timeouts */
-
-static void
-g_timeout_set_expiration (GTimeoutData *data,
- GTimeVal *current_time)
-{
- guint seconds = data->interval / 1000;
- guint msecs = data->interval - seconds * 1000;
-
- data->expiration.tv_sec = current_time->tv_sec + seconds;
- data->expiration.tv_usec = current_time->tv_usec + msecs * 1000;
- if (data->expiration.tv_usec >= 1000000)
- {
- data->expiration.tv_usec -= 1000000;
- data->expiration.tv_sec++;
- }
-}
-
-static gboolean
-g_timeout_prepare (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout,
- gpointer user_data)
-{
- glong msec;
- GTimeoutData *data = source_data;
-
- msec = (data->expiration.tv_sec - current_time->tv_sec) * 1000 +
- (data->expiration.tv_usec - current_time->tv_usec) / 1000;
-
- if (msec < 0)
- msec = 0;
- else if (msec > data->interval)
- {
- /* The system time has been set backwards, so we
- * reset the expiration time to now + data->interval;
- * this at least avoids hanging for long periods of time.
- */
- g_timeout_set_expiration (data, current_time);
- msec = data->interval;
- }
-
- *timeout = msec;
-
- return (msec == 0);
-}
-
-static gboolean
-g_timeout_check (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data)
-{
- GTimeoutData *data = source_data;
-
- return (data->expiration.tv_sec < current_time->tv_sec) ||
- ((data->expiration.tv_sec == current_time->tv_sec) &&
- (data->expiration.tv_usec <= current_time->tv_usec));
-}
-
-static gboolean
-g_timeout_dispatch (gpointer source_data,
- GTimeVal *dispatch_time,
- gpointer user_data)
-{
- GTimeoutData *data = source_data;
-
- if (data->callback (user_data))
- {
- g_timeout_set_expiration (data, dispatch_time);
- return TRUE;
- }
- else
- return FALSE;
-}
-
-guint
-g_timeout_add_full (gint priority,
- guint interval,
- GSourceFunc function,
- gpointer data,
- GDestroyNotify notify)
-{
- GTimeoutData *timeout_data = g_new (GTimeoutData, 1);
- GTimeVal current_time;
-
- timeout_data->interval = interval;
- timeout_data->callback = function;
- g_get_current_time (&current_time);
-
- g_timeout_set_expiration (timeout_data, &current_time);
-
- return g_source_add (priority, FALSE, &timeout_funcs, timeout_data, data, notify);
-}
-
-guint
-g_timeout_add (guint32 interval,
- GSourceFunc function,
- gpointer data)
-{
- return g_timeout_add_full (G_PRIORITY_DEFAULT,
- interval, function, data, NULL);
-}
-
-/* Idle functions */
-
-static gboolean
-g_idle_prepare (gpointer source_data,
- GTimeVal *current_time,
- gint *timeout,
- gpointer user_data)
-{
- *timeout = 0;
-
- return TRUE;
-}
-
-static gboolean
-g_idle_check (gpointer source_data,
- GTimeVal *current_time,
- gpointer user_data)
-{
- return TRUE;
-}
-
-static gboolean
-g_idle_dispatch (gpointer source_data,
- GTimeVal *dispatch_time,
- gpointer user_data)
-{
- GSourceFunc func = (GSourceFunc) source_data;
-
- return func (user_data);
-}
-
-guint
-g_idle_add_full (gint priority,
- GSourceFunc function,
- gpointer data,
- GDestroyNotify notify)
-{
- g_return_val_if_fail (function != NULL, 0);
-
- return g_source_add (priority, FALSE, &idle_funcs, (gpointer) function, data, notify);
-}
-
-guint
-g_idle_add (GSourceFunc function,
- gpointer data)
-{
- return g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, function, data, NULL);
-}
-
-gboolean
-g_idle_remove_by_data (gpointer data)
-{
- return g_source_remove_by_funcs_user_data (&idle_funcs, data);
-}
diff --git a/glib/gmem.c b/glib/gmem.c
deleted file mode 100644
index 08f87b157..000000000
--- a/glib/gmem.c
+++ /dev/null
@@ -1,1008 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include "glib.h"
-
-/* #define ENABLE_MEM_PROFILE */
-/* #define ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS */
-/* #define ENABLE_MEM_CHECK */
-#define MEM_PROFILE_TABLE_SIZE 8192
-
-/*
- * This library can check for some attempts to do illegal things to
- * memory (ENABLE_MEM_CHECK), and can do profiling
- * (ENABLE_MEM_PROFILE). Both features are implemented by storing
- * words before the start of the memory chunk.
- *
- * The first, at offset -2*SIZEOF_LONG, is used only if
- * ENABLE_MEM_CHECK is set, and stores 0 after the memory has been
- * allocated and 1 when it has been freed. The second, at offset
- * -SIZEOF_LONG, is used if either flag is set and stores the size of
- * the block.
- *
- * The MEM_CHECK flag is checked when memory is realloc'd and free'd,
- * and it can be explicitly checked before using a block by calling
- * g_mem_check().
- */
-
-#if defined(ENABLE_MEM_PROFILE) && defined(ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS)
-#define ENTER_MEM_CHUNK_ROUTINE() \
- g_private_set (allocating_for_mem_chunk, \
- g_private_get (allocating_for_mem_chunk) + 1)
-#define LEAVE_MEM_CHUNK_ROUTINE() \
- g_private_set (allocating_for_mem_chunk, \
- g_private_get (allocating_for_mem_chunk) - 1)
-#else
-#define ENTER_MEM_CHUNK_ROUTINE()
-#define LEAVE_MEM_CHUNK_ROUTINE()
-#endif
-
-
-#define MEM_AREA_SIZE 4L
-
-#if SIZEOF_VOID_P > SIZEOF_LONG
-#define MEM_ALIGN SIZEOF_VOID_P
-#else
-#define MEM_ALIGN SIZEOF_LONG
-#endif
-
-
-typedef struct _GFreeAtom GFreeAtom;
-typedef struct _GMemArea GMemArea;
-typedef struct _GRealMemChunk GRealMemChunk;
-
-struct _GFreeAtom
-{
- GFreeAtom *next;
-};
-
-struct _GMemArea
-{
- GMemArea *next; /* the next mem area */
- GMemArea *prev; /* the previous mem area */
- gulong index; /* the current index into the "mem" array */
- gulong free; /* the number of free bytes in this mem area */
- gulong allocated; /* the number of atoms allocated from this area */
- gulong mark; /* is this mem area marked for deletion */
- gchar mem[MEM_AREA_SIZE]; /* the mem array from which atoms get allocated
- * the actual size of this array is determined by
- * the mem chunk "area_size". ANSI says that it
- * must be declared to be the maximum size it
- * can possibly be (even though the actual size
- * may be less).
- */
-};
-
-struct _GRealMemChunk
-{
- gchar *name; /* name of this MemChunk...used for debugging output */
- gint type; /* the type of MemChunk: ALLOC_ONLY or ALLOC_AND_FREE */
- gint num_mem_areas; /* the number of memory areas */
- gint num_marked_areas; /* the number of areas marked for deletion */
- guint atom_size; /* the size of an atom */
- gulong area_size; /* the size of a memory area */
- GMemArea *mem_area; /* the current memory area */
- GMemArea *mem_areas; /* a list of all the mem areas owned by this chunk */
- GMemArea *free_mem_area; /* the free area...which is about to be destroyed */
- GFreeAtom *free_atoms; /* the free atoms list */
- GTree *mem_tree; /* tree of mem areas sorted by memory address */
- GRealMemChunk *next; /* pointer to the next chunk */
- GRealMemChunk *prev; /* pointer to the previous chunk */
-};
-
-
-static gulong g_mem_chunk_compute_size (gulong size,
- gulong min_size);
-static gint g_mem_chunk_area_compare (GMemArea *a,
- GMemArea *b);
-static gint g_mem_chunk_area_search (GMemArea *a,
- gchar *addr);
-
-
-/* here we can't use StaticMutexes, as they depend upon a working
- * g_malloc, the same holds true for StaticPrivate */
-static GMutex* mem_chunks_lock = NULL;
-static GRealMemChunk *mem_chunks = NULL;
-
-#ifdef ENABLE_MEM_PROFILE
-static GMutex* mem_profile_lock;
-static gulong allocations[MEM_PROFILE_TABLE_SIZE] = { 0 };
-static gulong allocated_mem = 0;
-static gulong freed_mem = 0;
-static GPrivate* allocating_for_mem_chunk = NULL;
-#define IS_IN_MEM_CHUNK_ROUTINE() \
- GPOINTER_TO_UINT (g_private_get (allocating_for_mem_chunk))
-#endif /* ENABLE_MEM_PROFILE */
-
-
-#ifndef USE_DMALLOC
-
-gpointer
-g_malloc (gulong size)
-{
- gpointer p;
-
-
-#if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
- gulong *t;
-#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
-
-
- if (size == 0)
- return NULL;
-
-
-#if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
- size += SIZEOF_LONG;
-#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
-
-#ifdef ENABLE_MEM_CHECK
- size += SIZEOF_LONG;
-#endif /* ENABLE_MEM_CHECK */
-
-
- p = (gpointer) malloc (size);
- if (!p)
- g_error ("could not allocate %ld bytes", size);
-
-
-#ifdef ENABLE_MEM_CHECK
- size -= SIZEOF_LONG;
-
- t = p;
- p = ((guchar*) p + SIZEOF_LONG);
- *t = 0;
-#endif /* ENABLE_MEM_CHECK */
-
-#if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
- size -= SIZEOF_LONG;
-
- t = p;
- p = ((guchar*) p + SIZEOF_LONG);
- *t = size;
-
-#ifdef ENABLE_MEM_PROFILE
- g_mutex_lock (mem_profile_lock);
-# ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
- if(!IS_IN_MEM_CHUNK_ROUTINE()) {
-# endif
- if (size <= MEM_PROFILE_TABLE_SIZE - 1)
- allocations[size-1] += 1;
- else
- allocations[MEM_PROFILE_TABLE_SIZE - 1] += 1;
- allocated_mem += size;
-# ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
- }
-# endif
- g_mutex_unlock (mem_profile_lock);
-#endif /* ENABLE_MEM_PROFILE */
-#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
-
-
- return p;
-}
-
-gpointer
-g_malloc0 (gulong size)
-{
- gpointer p;
-
-
-#if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
- gulong *t;
-#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
-
-
- if (size == 0)
- return NULL;
-
-
-#if defined (ENABLE_MEM_PROFILE) || defined (ENABLE_MEM_CHECK)
- size += SIZEOF_LONG;
-#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
-
-#ifdef ENABLE_MEM_CHECK
- size += SIZEOF_LONG;
-#endif /* ENABLE_MEM_CHECK */
-
-
- p = (gpointer) calloc (size, 1);
- if (!p)
- g_error ("could not allocate %ld bytes", size);
-
-
-#ifdef ENABLE_MEM_CHECK
- size -= SIZEOF_LONG;
-
- t = p;
- p = ((guchar*) p + SIZEOF_LONG);
- *t = 0;
-#endif /* ENABLE_MEM_CHECK */
-
-#if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
- size -= SIZEOF_LONG;
-
- t = p;
- p = ((guchar*) p + SIZEOF_LONG);
- *t = size;
-
-# ifdef ENABLE_MEM_PROFILE
- g_mutex_lock (mem_profile_lock);
-# ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
- if(!IS_IN_MEM_CHUNK_ROUTINE()) {
-# endif
- if (size <= (MEM_PROFILE_TABLE_SIZE - 1))
- allocations[size-1] += 1;
- else
- allocations[MEM_PROFILE_TABLE_SIZE - 1] += 1;
- allocated_mem += size;
-# ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
- }
-# endif
- g_mutex_unlock (mem_profile_lock);
-# endif /* ENABLE_MEM_PROFILE */
-#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
-
-
- return p;
-}
-
-gpointer
-g_realloc (gpointer mem,
- gulong size)
-{
- gpointer p;
-
-#if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
- gulong *t;
-#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
-
-
- if (size == 0)
- {
- g_free (mem);
-
- return NULL;
- }
-
-
-#if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
- size += SIZEOF_LONG;
-#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
-
-#ifdef ENABLE_MEM_CHECK
- size += SIZEOF_LONG;
-#endif /* ENABLE_MEM_CHECK */
-
-
- if (!mem)
- {
-#ifdef REALLOC_0_WORKS
- p = (gpointer) realloc (NULL, size);
-#else /* !REALLOC_0_WORKS */
- p = (gpointer) malloc (size);
-#endif /* !REALLOC_0_WORKS */
- }
- else
- {
-#if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
- t = (gulong*) ((guchar*) mem - SIZEOF_LONG);
-#ifdef ENABLE_MEM_PROFILE
- g_mutex_lock (mem_profile_lock);
- freed_mem += *t;
- g_mutex_unlock (mem_profile_lock);
-#endif /* ENABLE_MEM_PROFILE */
- mem = t;
-#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
-
-#ifdef ENABLE_MEM_CHECK
- t = (gulong*) ((guchar*) mem - SIZEOF_LONG);
- if (*t >= 1)
- g_warning ("trying to realloc freed memory\n");
- mem = t;
-#endif /* ENABLE_MEM_CHECK */
-
- p = (gpointer) realloc (mem, size);
- }
-
- if (!p)
- g_error ("could not reallocate %lu bytes", (gulong) size);
-
-
-#ifdef ENABLE_MEM_CHECK
- size -= SIZEOF_LONG;
-
- t = p;
- p = ((guchar*) p + SIZEOF_LONG);
- *t = 0;
-#endif /* ENABLE_MEM_CHECK */
-
-#if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
- size -= SIZEOF_LONG;
-
- t = p;
- p = ((guchar*) p + SIZEOF_LONG);
- *t = size;
-
-#ifdef ENABLE_MEM_PROFILE
- g_mutex_lock (mem_profile_lock);
-#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
- if(!IS_IN_MEM_CHUNK_ROUTINE()) {
-#endif
- if (size <= (MEM_PROFILE_TABLE_SIZE - 1))
- allocations[size-1] += 1;
- else
- allocations[MEM_PROFILE_TABLE_SIZE - 1] += 1;
- allocated_mem += size;
-#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
- }
-#endif
- g_mutex_unlock (mem_profile_lock);
-#endif /* ENABLE_MEM_PROFILE */
-#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
-
-
- return p;
-}
-
-void
-g_free (gpointer mem)
-{
- if (mem)
- {
-#if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
- gulong *t;
- gulong size;
-#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
-
-#if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
- t = (gulong*) ((guchar*) mem - SIZEOF_LONG);
- size = *t;
-#ifdef ENABLE_MEM_PROFILE
- g_mutex_lock (mem_profile_lock);
- freed_mem += size;
- g_mutex_unlock (mem_profile_lock);
-#endif /* ENABLE_MEM_PROFILE */
- mem = t;
-#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
-
-#ifdef ENABLE_MEM_CHECK
- t = (gulong*) ((guchar*) mem - SIZEOF_LONG);
- if (*t >= 1)
- g_warning ("freeing previously freed (%lu times) memory\n", *t);
- *t += 1;
- mem = t;
-
- memset ((guchar*) mem + 2 * SIZEOF_LONG, 0, size);
-#else /* ENABLE_MEM_CHECK */
- free (mem);
-#endif /* ENABLE_MEM_CHECK */
- }
-}
-
-#endif /* ! USE_DMALLOC */
-
-
-void
-g_mem_profile (void)
-{
-#ifdef ENABLE_MEM_PROFILE
- gint i;
- gulong local_allocations[MEM_PROFILE_TABLE_SIZE];
- gulong local_allocated_mem;
- gulong local_freed_mem;
-
- g_mutex_lock (mem_profile_lock);
- for (i = 0; i < MEM_PROFILE_TABLE_SIZE; i++)
- local_allocations[i] = allocations[i];
- local_allocated_mem = allocated_mem;
- local_freed_mem = freed_mem;
- g_mutex_unlock (mem_profile_lock);
-
- for (i = 0; i < (MEM_PROFILE_TABLE_SIZE - 1); i++)
- if (local_allocations[i] > 0)
- g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,
- "%lu allocations of %d bytes", local_allocations[i], i + 1);
-
- if (local_allocations[MEM_PROFILE_TABLE_SIZE - 1] > 0)
- g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,
- "%lu allocations of greater than %d bytes",
- local_allocations[MEM_PROFILE_TABLE_SIZE - 1], MEM_PROFILE_TABLE_SIZE - 1);
- g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes allocated", local_allocated_mem);
- g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes freed", local_freed_mem);
- g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes in use", local_allocated_mem - local_freed_mem);
-#endif /* ENABLE_MEM_PROFILE */
-}
-
-void
-g_mem_check (gpointer mem)
-{
-#ifdef ENABLE_MEM_CHECK
- gulong *t;
-
- t = (gulong*) ((guchar*) mem - SIZEOF_LONG - SIZEOF_LONG);
-
- if (*t >= 1)
- g_warning ("mem: 0x%08lx has been freed %lu times\n", (gulong) mem, *t);
-#endif /* ENABLE_MEM_CHECK */
-}
-
-GMemChunk*
-g_mem_chunk_new (gchar *name,
- gint atom_size,
- gulong area_size,
- gint type)
-{
- GRealMemChunk *mem_chunk;
- gulong rarea_size;
-
- g_return_val_if_fail (atom_size > 0, NULL);
- g_return_val_if_fail (area_size >= atom_size, NULL);
-
- ENTER_MEM_CHUNK_ROUTINE();
-
- area_size = (area_size + atom_size - 1) / atom_size;
- area_size *= atom_size;
-
- mem_chunk = g_new (struct _GRealMemChunk, 1);
- mem_chunk->name = name;
- mem_chunk->type = type;
- mem_chunk->num_mem_areas = 0;
- mem_chunk->num_marked_areas = 0;
- mem_chunk->mem_area = NULL;
- mem_chunk->free_mem_area = NULL;
- mem_chunk->free_atoms = NULL;
- mem_chunk->mem_tree = NULL;
- mem_chunk->mem_areas = NULL;
- mem_chunk->atom_size = atom_size;
-
- if (mem_chunk->type == G_ALLOC_AND_FREE)
- mem_chunk->mem_tree = g_tree_new ((GCompareFunc) g_mem_chunk_area_compare);
-
- if (mem_chunk->atom_size % MEM_ALIGN)
- mem_chunk->atom_size += MEM_ALIGN - (mem_chunk->atom_size % MEM_ALIGN);
-
- rarea_size = area_size + sizeof (GMemArea) - MEM_AREA_SIZE;
- rarea_size = g_mem_chunk_compute_size (rarea_size, atom_size + sizeof (GMemArea) - MEM_AREA_SIZE);
- mem_chunk->area_size = rarea_size - (sizeof (GMemArea) - MEM_AREA_SIZE);
-
- g_mutex_lock (mem_chunks_lock);
- mem_chunk->next = mem_chunks;
- mem_chunk->prev = NULL;
- if (mem_chunks)
- mem_chunks->prev = mem_chunk;
- mem_chunks = mem_chunk;
- g_mutex_unlock (mem_chunks_lock);
-
- LEAVE_MEM_CHUNK_ROUTINE();
-
- return ((GMemChunk*) mem_chunk);
-}
-
-void
-g_mem_chunk_destroy (GMemChunk *mem_chunk)
-{
- GRealMemChunk *rmem_chunk;
- GMemArea *mem_areas;
- GMemArea *temp_area;
-
- g_return_if_fail (mem_chunk != NULL);
-
- ENTER_MEM_CHUNK_ROUTINE();
-
- rmem_chunk = (GRealMemChunk*) mem_chunk;
-
- mem_areas = rmem_chunk->mem_areas;
- while (mem_areas)
- {
- temp_area = mem_areas;
- mem_areas = mem_areas->next;
- g_free (temp_area);
- }
-
- if (rmem_chunk->next)
- rmem_chunk->next->prev = rmem_chunk->prev;
- if (rmem_chunk->prev)
- rmem_chunk->prev->next = rmem_chunk->next;
-
- g_mutex_lock (mem_chunks_lock);
- if (rmem_chunk == mem_chunks)
- mem_chunks = mem_chunks->next;
- g_mutex_unlock (mem_chunks_lock);
-
- if (rmem_chunk->type == G_ALLOC_AND_FREE)
- g_tree_destroy (rmem_chunk->mem_tree);
-
- g_free (rmem_chunk);
-
- LEAVE_MEM_CHUNK_ROUTINE();
-}
-
-gpointer
-g_mem_chunk_alloc (GMemChunk *mem_chunk)
-{
- GRealMemChunk *rmem_chunk;
- GMemArea *temp_area;
- gpointer mem;
-
- ENTER_MEM_CHUNK_ROUTINE();
-
- g_return_val_if_fail (mem_chunk != NULL, NULL);
-
- rmem_chunk = (GRealMemChunk*) mem_chunk;
-
- while (rmem_chunk->free_atoms)
- {
- /* Get the first piece of memory on the "free_atoms" list.
- * We can go ahead and destroy the list node we used to keep
- * track of it with and to update the "free_atoms" list to
- * point to its next element.
- */
- mem = rmem_chunk->free_atoms;
- rmem_chunk->free_atoms = rmem_chunk->free_atoms->next;
-
- /* Determine which area this piece of memory is allocated from */
- temp_area = g_tree_search (rmem_chunk->mem_tree,
- (GSearchFunc) g_mem_chunk_area_search,
- mem);
-
- /* If the area has been marked, then it is being destroyed.
- * (ie marked to be destroyed).
- * We check to see if all of the segments on the free list that
- * reference this area have been removed. This occurs when
- * the ammount of free memory is less than the allocatable size.
- * If the chunk should be freed, then we place it in the "free_mem_area".
- * This is so we make sure not to free the mem area here and then
- * allocate it again a few lines down.
- * If we don't allocate a chunk a few lines down then the "free_mem_area"
- * will be freed.
- * If there is already a "free_mem_area" then we'll just free this mem area.
- */
- if (temp_area->mark)
- {
- /* Update the "free" memory available in that area */
- temp_area->free += rmem_chunk->atom_size;
-
- if (temp_area->free == rmem_chunk->area_size)
- {
- if (temp_area == rmem_chunk->mem_area)
- rmem_chunk->mem_area = NULL;
-
- if (rmem_chunk->free_mem_area)
- {
- rmem_chunk->num_mem_areas -= 1;
-
- if (temp_area->next)
- temp_area->next->prev = temp_area->prev;
- if (temp_area->prev)
- temp_area->prev->next = temp_area->next;
- if (temp_area == rmem_chunk->mem_areas)
- rmem_chunk->mem_areas = rmem_chunk->mem_areas->next;
-
- if (rmem_chunk->type == G_ALLOC_AND_FREE)
- g_tree_remove (rmem_chunk->mem_tree, temp_area);
- g_free (temp_area);
- }
- else
- rmem_chunk->free_mem_area = temp_area;
-
- rmem_chunk->num_marked_areas -= 1;
- }
- }
- else
- {
- /* Update the number of allocated atoms count.
- */
- temp_area->allocated += 1;
-
- /* The area wasn't marked...return the memory
- */
- goto outa_here;
- }
- }
-
- /* If there isn't a current mem area or the current mem area is out of space
- * then allocate a new mem area. We'll first check and see if we can use
- * the "free_mem_area". Otherwise we'll just malloc the mem area.
- */
- if ((!rmem_chunk->mem_area) ||
- ((rmem_chunk->mem_area->index + rmem_chunk->atom_size) > rmem_chunk->area_size))
- {
- if (rmem_chunk->free_mem_area)
- {
- rmem_chunk->mem_area = rmem_chunk->free_mem_area;
- rmem_chunk->free_mem_area = NULL;
- }
- else
- {
- rmem_chunk->mem_area = (GMemArea*) g_malloc (sizeof (GMemArea) -
- MEM_AREA_SIZE +
- rmem_chunk->area_size);
-
- rmem_chunk->num_mem_areas += 1;
- rmem_chunk->mem_area->next = rmem_chunk->mem_areas;
- rmem_chunk->mem_area->prev = NULL;
-
- if (rmem_chunk->mem_areas)
- rmem_chunk->mem_areas->prev = rmem_chunk->mem_area;
- rmem_chunk->mem_areas = rmem_chunk->mem_area;
-
- if (rmem_chunk->type == G_ALLOC_AND_FREE)
- g_tree_insert (rmem_chunk->mem_tree, rmem_chunk->mem_area, rmem_chunk->mem_area);
- }
-
- rmem_chunk->mem_area->index = 0;
- rmem_chunk->mem_area->free = rmem_chunk->area_size;
- rmem_chunk->mem_area->allocated = 0;
- rmem_chunk->mem_area->mark = 0;
- }
-
- /* Get the memory and modify the state variables appropriately.
- */
- mem = (gpointer) &rmem_chunk->mem_area->mem[rmem_chunk->mem_area->index];
- rmem_chunk->mem_area->index += rmem_chunk->atom_size;
- rmem_chunk->mem_area->free -= rmem_chunk->atom_size;
- rmem_chunk->mem_area->allocated += 1;
-
-outa_here:
-
- LEAVE_MEM_CHUNK_ROUTINE();
-
- return mem;
-}
-
-gpointer
-g_mem_chunk_alloc0 (GMemChunk *mem_chunk)
-{
- gpointer mem;
-
- mem = g_mem_chunk_alloc (mem_chunk);
- if (mem)
- {
- GRealMemChunk *rmem_chunk = (GRealMemChunk*) mem_chunk;
-
- memset (mem, 0, rmem_chunk->atom_size);
- }
-
- return mem;
-}
-
-void
-g_mem_chunk_free (GMemChunk *mem_chunk,
- gpointer mem)
-{
- GRealMemChunk *rmem_chunk;
- GMemArea *temp_area;
- GFreeAtom *free_atom;
-
- g_return_if_fail (mem_chunk != NULL);
- g_return_if_fail (mem != NULL);
-
- ENTER_MEM_CHUNK_ROUTINE();
-
- rmem_chunk = (GRealMemChunk*) mem_chunk;
-
- /* Don't do anything if this is an ALLOC_ONLY chunk
- */
- if (rmem_chunk->type == G_ALLOC_AND_FREE)
- {
- /* Place the memory on the "free_atoms" list
- */
- free_atom = (GFreeAtom*) mem;
- free_atom->next = rmem_chunk->free_atoms;
- rmem_chunk->free_atoms = free_atom;
-
- temp_area = g_tree_search (rmem_chunk->mem_tree,
- (GSearchFunc) g_mem_chunk_area_search,
- mem);
-
- temp_area->allocated -= 1;
-
- if (temp_area->allocated == 0)
- {
- temp_area->mark = 1;
- rmem_chunk->num_marked_areas += 1;
- }
- }
-
- LEAVE_MEM_CHUNK_ROUTINE();
-}
-
-/* This doesn't free the free_area if there is one */
-void
-g_mem_chunk_clean (GMemChunk *mem_chunk)
-{
- GRealMemChunk *rmem_chunk;
- GMemArea *mem_area;
- GFreeAtom *prev_free_atom;
- GFreeAtom *temp_free_atom;
- gpointer mem;
-
- g_return_if_fail (mem_chunk != NULL);
-
- rmem_chunk = (GRealMemChunk*) mem_chunk;
-
- if (rmem_chunk->type == G_ALLOC_AND_FREE)
- {
- prev_free_atom = NULL;
- temp_free_atom = rmem_chunk->free_atoms;
-
- while (temp_free_atom)
- {
- mem = (gpointer) temp_free_atom;
-
- mem_area = g_tree_search (rmem_chunk->mem_tree,
- (GSearchFunc) g_mem_chunk_area_search,
- mem);
-
- /* If this mem area is marked for destruction then delete the
- * area and list node and decrement the free mem.
- */
- if (mem_area->mark)
- {
- if (prev_free_atom)
- prev_free_atom->next = temp_free_atom->next;
- else
- rmem_chunk->free_atoms = temp_free_atom->next;
- temp_free_atom = temp_free_atom->next;
-
- mem_area->free += rmem_chunk->atom_size;
- if (mem_area->free == rmem_chunk->area_size)
- {
- rmem_chunk->num_mem_areas -= 1;
- rmem_chunk->num_marked_areas -= 1;
-
- if (mem_area->next)
- mem_area->next->prev = mem_area->prev;
- if (mem_area->prev)
- mem_area->prev->next = mem_area->next;
- if (mem_area == rmem_chunk->mem_areas)
- rmem_chunk->mem_areas = rmem_chunk->mem_areas->next;
- if (mem_area == rmem_chunk->mem_area)
- rmem_chunk->mem_area = NULL;
-
- if (rmem_chunk->type == G_ALLOC_AND_FREE)
- g_tree_remove (rmem_chunk->mem_tree, mem_area);
- g_free (mem_area);
- }
- }
- else
- {
- prev_free_atom = temp_free_atom;
- temp_free_atom = temp_free_atom->next;
- }
- }
- }
-}
-
-void
-g_mem_chunk_reset (GMemChunk *mem_chunk)
-{
- GRealMemChunk *rmem_chunk;
- GMemArea *mem_areas;
- GMemArea *temp_area;
-
- g_return_if_fail (mem_chunk != NULL);
-
- rmem_chunk = (GRealMemChunk*) mem_chunk;
-
- mem_areas = rmem_chunk->mem_areas;
- rmem_chunk->num_mem_areas = 0;
- rmem_chunk->mem_areas = NULL;
- rmem_chunk->mem_area = NULL;
-
- while (mem_areas)
- {
- temp_area = mem_areas;
- mem_areas = mem_areas->next;
- g_free (temp_area);
- }
-
- rmem_chunk->free_atoms = NULL;
-
- if (rmem_chunk->mem_tree)
- g_tree_destroy (rmem_chunk->mem_tree);
- rmem_chunk->mem_tree = g_tree_new ((GCompareFunc) g_mem_chunk_area_compare);
-}
-
-void
-g_mem_chunk_print (GMemChunk *mem_chunk)
-{
- GRealMemChunk *rmem_chunk;
- GMemArea *mem_areas;
- gulong mem;
-
- g_return_if_fail (mem_chunk != NULL);
-
- rmem_chunk = (GRealMemChunk*) mem_chunk;
- mem_areas = rmem_chunk->mem_areas;
- mem = 0;
-
- while (mem_areas)
- {
- mem += rmem_chunk->area_size - mem_areas->free;
- mem_areas = mem_areas->next;
- }
-
- g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,
- "%s: %ld bytes using %d mem areas",
- rmem_chunk->name, mem, rmem_chunk->num_mem_areas);
-}
-
-void
-g_mem_chunk_info (void)
-{
- GRealMemChunk *mem_chunk;
- gint count;
-
- count = 0;
- g_mutex_lock (mem_chunks_lock);
- mem_chunk = mem_chunks;
- while (mem_chunk)
- {
- count += 1;
- mem_chunk = mem_chunk->next;
- }
- g_mutex_unlock (mem_chunks_lock);
-
- g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%d mem chunks", count);
-
- g_mutex_lock (mem_chunks_lock);
- mem_chunk = mem_chunks;
- g_mutex_unlock (mem_chunks_lock);
-
- while (mem_chunk)
- {
- g_mem_chunk_print ((GMemChunk*) mem_chunk);
- mem_chunk = mem_chunk->next;
- }
-}
-
-void
-g_blow_chunks (void)
-{
- GRealMemChunk *mem_chunk;
-
- g_mutex_lock (mem_chunks_lock);
- mem_chunk = mem_chunks;
- g_mutex_unlock (mem_chunks_lock);
- while (mem_chunk)
- {
- g_mem_chunk_clean ((GMemChunk*) mem_chunk);
- mem_chunk = mem_chunk->next;
- }
-}
-
-
-static gulong
-g_mem_chunk_compute_size (gulong size,
- gulong min_size)
-{
- gulong power_of_2;
- gulong lower, upper;
-
- power_of_2 = 16;
- while (power_of_2 < size)
- power_of_2 <<= 1;
-
- lower = power_of_2 >> 1;
- upper = power_of_2;
-
- if (size - lower < upper - size && lower >= min_size)
- return lower;
- else
- return upper;
-}
-
-static gint
-g_mem_chunk_area_compare (GMemArea *a,
- GMemArea *b)
-{
- if (a->mem > b->mem)
- return 1;
- else if (a->mem < b->mem)
- return -1;
- return 0;
-}
-
-static gint
-g_mem_chunk_area_search (GMemArea *a,
- gchar *addr)
-{
- if (a->mem <= addr)
- {
- if (addr < &a->mem[a->index])
- return 0;
- return 1;
- }
- return -1;
-}
-
-/* generic allocators
- */
-struct _GAllocator /* from gmem.c */
-{
- gchar *name;
- guint16 n_preallocs;
- guint is_unused : 1;
- guint type : 4;
- GAllocator *last;
- GMemChunk *mem_chunk;
- gpointer dummy; /* implementation specific */
-};
-
-GAllocator*
-g_allocator_new (const gchar *name,
- guint n_preallocs)
-{
- GAllocator *allocator;
-
- g_return_val_if_fail (name != NULL, NULL);
-
- allocator = g_new0 (GAllocator, 1);
- allocator->name = g_strdup (name);
- allocator->n_preallocs = CLAMP (n_preallocs, 1, 65535);
- allocator->is_unused = TRUE;
- allocator->type = 0;
- allocator->last = NULL;
- allocator->mem_chunk = NULL;
- allocator->dummy = NULL;
-
- return allocator;
-}
-
-void
-g_allocator_free (GAllocator *allocator)
-{
- g_return_if_fail (allocator != NULL);
- g_return_if_fail (allocator->is_unused == TRUE);
-
- g_free (allocator->name);
- if (allocator->mem_chunk)
- g_mem_chunk_destroy (allocator->mem_chunk);
-
- g_free (allocator);
-}
-
-void
-g_mem_init (void)
-{
- mem_chunks_lock = g_mutex_new();
-#ifdef ENABLE_MEM_PROFILE
- mem_profile_lock = g_mutex_new();
- allocating_for_mem_chunk = g_private_new(NULL);
-#endif
-}
diff --git a/glib/gmessages.c b/glib/gmessages.c
deleted file mode 100644
index 9c75c4de6..000000000
--- a/glib/gmessages.c
+++ /dev/null
@@ -1,756 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-#include "glib.h"
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifdef NATIVE_WIN32
-#define STRICT
-#include <windows.h>
-
-/* Just use stdio. If we're out of memory, we're hosed anyway. */
-#undef write
-
-static inline int
-write (FILE *fd,
- const char *buf,
- int len)
-{
- fwrite (buf, len, 1, fd);
-
- return len;
-}
-
-static void
-ensure_stdout_valid (void)
-{
- HANDLE handle;
-
- handle = GetStdHandle (STD_OUTPUT_HANDLE);
-
- if (handle == INVALID_HANDLE_VALUE)
- {
- AllocConsole ();
- freopen ("CONOUT$", "w", stdout);
- }
-}
-#else
-#define ensure_stdout_valid() /* Define as empty */
-#endif
-
-
-/* --- structures --- */
-typedef struct _GLogDomain GLogDomain;
-typedef struct _GLogHandler GLogHandler;
-struct _GLogDomain
-{
- gchar *log_domain;
- GLogLevelFlags fatal_mask;
- GLogHandler *handlers;
- GLogDomain *next;
-};
-struct _GLogHandler
-{
- guint id;
- GLogLevelFlags log_level;
- GLogFunc log_func;
- gpointer data;
- GLogHandler *next;
-};
-
-
-/* --- variables --- */
-
-static GMutex* g_messages_lock = NULL;
-
-const gchar *g_log_domain_glib = "GLib";
-static GLogDomain *g_log_domains = NULL;
-static GLogLevelFlags g_log_always_fatal = G_LOG_FATAL_MASK;
-static GPrintFunc glib_print_func = NULL;
-static GPrintFunc glib_printerr_func = NULL;
-static GErrorFunc glib_error_func = NULL;
-static GWarningFunc glib_warning_func = NULL;
-static GPrintFunc glib_message_func = NULL;
-
-static GPrivate* g_log_depth = NULL;
-
-
-/* --- functions --- */
-static inline GLogDomain*
-g_log_find_domain (const gchar *log_domain)
-{
- register GLogDomain *domain;
-
- g_mutex_lock (g_messages_lock);
- domain = g_log_domains;
- while (domain)
- {
- if (strcmp (domain->log_domain, log_domain) == 0)
- {
- g_mutex_unlock (g_messages_lock);
- return domain;
- }
- domain = domain->next;
- }
- g_mutex_unlock (g_messages_lock);
- return NULL;
-}
-
-static inline GLogDomain*
-g_log_domain_new (const gchar *log_domain)
-{
- register GLogDomain *domain;
-
- domain = g_new (GLogDomain, 1);
- domain->log_domain = g_strdup (log_domain);
- domain->fatal_mask = G_LOG_FATAL_MASK;
- domain->handlers = NULL;
-
- g_mutex_lock (g_messages_lock);
- domain->next = g_log_domains;
- g_log_domains = domain;
- g_mutex_unlock (g_messages_lock);
-
- return domain;
-}
-
-static inline void
-g_log_domain_check_free (GLogDomain *domain)
-{
- if (domain->fatal_mask == G_LOG_FATAL_MASK &&
- domain->handlers == NULL)
- {
- register GLogDomain *last, *work;
-
- last = NULL;
-
- g_mutex_lock (g_messages_lock);
- work = g_log_domains;
- while (work)
- {
- if (work == domain)
- {
- if (last)
- last->next = domain->next;
- else
- g_log_domains = domain->next;
- g_free (domain->log_domain);
- g_free (domain);
- break;
- }
- last = work;
- work = last->next;
- }
- g_mutex_unlock (g_messages_lock);
- }
-}
-
-static inline GLogFunc
-g_log_domain_get_handler (GLogDomain *domain,
- GLogLevelFlags log_level,
- gpointer *data)
-{
- if (domain && log_level)
- {
- register GLogHandler *handler;
-
- handler = domain->handlers;
- while (handler)
- {
- if ((handler->log_level & log_level) == log_level)
- {
- *data = handler->data;
- return handler->log_func;
- }
- handler = handler->next;
- }
- }
- return g_log_default_handler;
-}
-
-GLogLevelFlags
-g_log_set_always_fatal (GLogLevelFlags fatal_mask)
-{
- GLogLevelFlags old_mask;
-
- /* restrict the global mask to levels that are known to glib */
- fatal_mask &= (1 << G_LOG_LEVEL_USER_SHIFT) - 1;
- /* force errors to be fatal */
- fatal_mask |= G_LOG_LEVEL_ERROR;
- /* remove bogus flag */
- fatal_mask &= ~G_LOG_FLAG_FATAL;
-
- g_mutex_lock (g_messages_lock);
- old_mask = g_log_always_fatal;
- g_log_always_fatal = fatal_mask;
- g_mutex_unlock (g_messages_lock);
-
- return old_mask;
-}
-
-GLogLevelFlags
-g_log_set_fatal_mask (const gchar *log_domain,
- GLogLevelFlags fatal_mask)
-{
- GLogLevelFlags old_flags;
- register GLogDomain *domain;
-
- if (!log_domain)
- log_domain = "";
-
- /* force errors to be fatal */
- fatal_mask |= G_LOG_LEVEL_ERROR;
- /* remove bogus flag */
- fatal_mask &= ~G_LOG_FLAG_FATAL;
-
- domain = g_log_find_domain (log_domain);
- if (!domain)
- domain = g_log_domain_new (log_domain);
- old_flags = domain->fatal_mask;
-
- domain->fatal_mask = fatal_mask;
- g_log_domain_check_free (domain);
-
- return old_flags;
-}
-
-guint
-g_log_set_handler (const gchar *log_domain,
- GLogLevelFlags log_levels,
- GLogFunc log_func,
- gpointer user_data)
-{
- register GLogDomain *domain;
- register GLogHandler *handler;
- static guint handler_id = 0;
-
- g_return_val_if_fail ((log_levels & G_LOG_LEVEL_MASK) != 0, 0);
- g_return_val_if_fail (log_func != NULL, 0);
-
- if (!log_domain)
- log_domain = "";
-
- domain = g_log_find_domain (log_domain);
- if (!domain)
- domain = g_log_domain_new (log_domain);
-
- handler = g_new (GLogHandler, 1);
- g_mutex_lock (g_messages_lock);
- handler->id = ++handler_id;
- g_mutex_unlock (g_messages_lock);
- handler->log_level = log_levels;
- handler->log_func = log_func;
- handler->data = user_data;
- handler->next = domain->handlers;
- domain->handlers = handler;
-
- return handler_id;
-}
-
-void
-g_log_remove_handler (const gchar *log_domain,
- guint handler_id)
-{
- register GLogDomain *domain;
-
- g_return_if_fail (handler_id > 0);
-
- if (!log_domain)
- log_domain = "";
-
- domain = g_log_find_domain (log_domain);
- if (domain)
- {
- register GLogHandler *work, *last;
-
- last = NULL;
- work = domain->handlers;
- while (work)
- {
- if (work->id == handler_id)
- {
- if (last)
- last->next = work->next;
- else
- domain->handlers = work->next;
- g_free (work);
- g_log_domain_check_free (domain);
- return;
- }
- last = work;
- work = last->next;
- }
- }
- g_warning ("g_log_remove_handler(): could not find handler with id `%d' for domain \"%s\"",
- handler_id,
- log_domain);
-}
-
-void
-g_logv (const gchar *log_domain,
- GLogLevelFlags log_level,
- const gchar *format,
- va_list args1)
-{
- va_list args2;
- gchar buffer[1025];
- register gint i;
-
- log_level &= G_LOG_LEVEL_MASK;
- if (!log_level)
- return;
-
- /* we use a stack buffer of fixed size, because we might get called
- * recursively.
- */
- G_VA_COPY (args2, args1);
- if (g_printf_string_upper_bound (format, args1) < 1024)
- vsprintf (buffer, format, args2);
- else
- {
- /* since we might be out of memory, we can't use g_vsnprintf(). */
-#ifdef HAVE_VSNPRINTF
- vsnprintf (buffer, 1024, format, args2);
-#else /* !HAVE_VSNPRINTF */
- /* we are out of luck here */
- strncpy (buffer, format, 1024);
-#endif /* !HAVE_VSNPRINTF */
- buffer[1024] = 0;
- }
- va_end (args2);
-
- for (i = g_bit_nth_msf (log_level, -1); i >= 0; i = g_bit_nth_msf (log_level, i))
- {
- register GLogLevelFlags test_level;
-
- test_level = 1 << i;
- if (log_level & test_level)
- {
- guint depth = GPOINTER_TO_UINT (g_private_get (g_log_depth));
- GLogDomain *domain;
- GLogFunc log_func;
- gpointer data = NULL;
-
- domain = g_log_find_domain (log_domain ? log_domain : "");
-
- if (depth)
- test_level |= G_LOG_FLAG_RECURSION;
-
- depth++;
- g_private_set (g_log_depth, GUINT_TO_POINTER (depth));
-
- g_mutex_lock (g_messages_lock);
- if ((((domain ? domain->fatal_mask : G_LOG_FATAL_MASK) |
- g_log_always_fatal) & test_level) != 0)
- test_level |= G_LOG_FLAG_FATAL;
- g_mutex_unlock (g_messages_lock);
-
- log_func = g_log_domain_get_handler (domain, test_level, &data);
- log_func (log_domain, test_level, buffer, data);
-
- /* *domain can be cluttered now */
-
- if (test_level & G_LOG_FLAG_FATAL)
- abort ();
-
- depth--;
- g_private_set (g_log_depth, GUINT_TO_POINTER (depth));
- }
- }
-}
-
-void
-g_log (const gchar *log_domain,
- GLogLevelFlags log_level,
- const gchar *format,
- ...)
-{
- va_list args;
-
- va_start (args, format);
- g_logv (log_domain, log_level, format, args);
- va_end (args);
-}
-
-void
-g_log_default_handler (const gchar *log_domain,
- GLogLevelFlags log_level,
- const gchar *message,
- gpointer unused_data)
-{
-#ifdef NATIVE_WIN32
- FILE *fd;
-#else
- gint fd;
-#endif
- gboolean in_recursion;
- gboolean is_fatal;
- GErrorFunc local_glib_error_func;
- GWarningFunc local_glib_warning_func;
- GPrintFunc local_glib_message_func;
-
- in_recursion = (log_level & G_LOG_FLAG_RECURSION) != 0;
- is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
- log_level &= G_LOG_LEVEL_MASK;
-
- if (!message)
- message = "g_log_default_handler(): (NULL) message";
-
-#ifdef NATIVE_WIN32
- /* Use just stdout as stderr is hard to get redirected from the
- * DOS prompt.
- */
- fd = stdout;
-#else
- fd = (log_level >= G_LOG_LEVEL_MESSAGE) ? 1 : 2;
-#endif
-
- g_mutex_lock (g_messages_lock);
- local_glib_error_func = glib_error_func;
- local_glib_warning_func = glib_warning_func;
- local_glib_message_func = glib_message_func;
- g_mutex_unlock (g_messages_lock);
-
- switch (log_level)
- {
- case G_LOG_LEVEL_ERROR:
- if (!log_domain && local_glib_error_func)
- {
- /* compatibility code */
- local_glib_error_func (message);
- return;
- }
- /* use write(2) for output, in case we are out of memeory */
- ensure_stdout_valid ();
- if (log_domain)
- {
- write (fd, "\n", 1);
- write (fd, log_domain, strlen (log_domain));
- write (fd, "-", 1);
- }
- else
- write (fd, "\n** ", 4);
- if (in_recursion)
- write (fd, "ERROR (recursed) **: ", 21);
- else
- write (fd, "ERROR **: ", 10);
- write (fd, message, strlen(message));
- if (is_fatal)
- write (fd, "\naborting...\n", 13);
- else
- write (fd, "\n", 1);
- break;
- case G_LOG_LEVEL_CRITICAL:
- ensure_stdout_valid ();
- if (log_domain)
- {
- write (fd, "\n", 1);
- write (fd, log_domain, strlen (log_domain));
- write (fd, "-", 1);
- }
- else
- write (fd, "\n** ", 4);
- if (in_recursion)
- write (fd, "CRITICAL (recursed) **: ", 24);
- else
- write (fd, "CRITICAL **: ", 13);
- write (fd, message, strlen(message));
- if (is_fatal)
- write (fd, "\naborting...\n", 13);
- else
- write (fd, "\n", 1);
- break;
- case G_LOG_LEVEL_WARNING:
- if (!log_domain && local_glib_warning_func)
- {
- /* compatibility code */
- local_glib_warning_func (message);
- return;
- }
- ensure_stdout_valid ();
- if (log_domain)
- {
- write (fd, "\n", 1);
- write (fd, log_domain, strlen (log_domain));
- write (fd, "-", 1);
- }
- else
- write (fd, "\n** ", 4);
- if (in_recursion)
- write (fd, "WARNING (recursed) **: ", 23);
- else
- write (fd, "WARNING **: ", 12);
- write (fd, message, strlen(message));
- if (is_fatal)
- write (fd, "\naborting...\n", 13);
- else
- write (fd, "\n", 1);
- break;
- case G_LOG_LEVEL_MESSAGE:
- if (!log_domain && local_glib_message_func)
- {
- /* compatibility code */
- local_glib_message_func (message);
- return;
- }
- ensure_stdout_valid ();
- if (log_domain)
- {
- write (fd, log_domain, strlen (log_domain));
- write (fd, "-", 1);
- }
- if (in_recursion)
- write (fd, "Message (recursed): ", 20);
- else
- write (fd, "Message: ", 9);
- write (fd, message, strlen(message));
- if (is_fatal)
- write (fd, "\naborting...\n", 13);
- else
- write (fd, "\n", 1);
- break;
- case G_LOG_LEVEL_INFO:
- ensure_stdout_valid ();
- if (log_domain)
- {
- write (fd, log_domain, strlen (log_domain));
- write (fd, "-", 1);
- }
- if (in_recursion)
- write (fd, "INFO (recursed): ", 17);
- else
- write (fd, "INFO: ", 6);
- write (fd, message, strlen(message));
- if (is_fatal)
- write (fd, "\naborting...\n", 13);
- else
- write (fd, "\n", 1);
- break;
- case G_LOG_LEVEL_DEBUG:
- ensure_stdout_valid ();
- if (log_domain)
- {
- write (fd, log_domain, strlen (log_domain));
- write (fd, "-", 1);
- }
- if (in_recursion)
- write (fd, "DEBUG (recursed): ", 18);
- else
- write (fd, "DEBUG: ", 7);
- write (fd, message, strlen(message));
- if (is_fatal)
- write (fd, "\naborting...\n", 13);
- else
- write (fd, "\n", 1);
- break;
- default:
- /* we are used for a log level that is not defined by GLib itself,
- * try to make the best out of it.
- */
- ensure_stdout_valid ();
- if (log_domain)
- {
- write (fd, log_domain, strlen (log_domain));
- if (in_recursion)
- write (fd, "-LOG (recursed:", 15);
- else
- write (fd, "-LOG (", 6);
- }
- else if (in_recursion)
- write (fd, "LOG (recursed:", 14);
- else
- write (fd, "LOG (", 5);
- if (log_level)
- {
- gchar string[] = "0x00): ";
- gchar *p = string + 2;
- guint i;
-
- i = g_bit_nth_msf (log_level, -1);
- *p = i >> 4;
- p++;
- *p = '0' + (i & 0xf);
- if (*p > '9')
- *p += 'A' - '9' - 1;
-
- write (fd, string, 7);
- }
- else
- write (fd, "): ", 3);
- write (fd, message, strlen(message));
- if (is_fatal)
- write (fd, "\naborting...\n", 13);
- else
- write (fd, "\n", 1);
- break;
- }
-}
-
-GPrintFunc
-g_set_print_handler (GPrintFunc func)
-{
- GPrintFunc old_print_func;
-
- g_mutex_lock (g_messages_lock);
- old_print_func = glib_print_func;
- glib_print_func = func;
- g_mutex_unlock (g_messages_lock);
-
- return old_print_func;
-}
-
-void
-g_print (const gchar *format,
- ...)
-{
- va_list args;
- gchar *string;
- GPrintFunc local_glib_print_func;
-
- g_return_if_fail (format != NULL);
-
- va_start (args, format);
- string = g_strdup_vprintf (format, args);
- va_end (args);
-
- g_mutex_lock (g_messages_lock);
- local_glib_print_func = glib_print_func;
- g_mutex_unlock (g_messages_lock);
-
- if (local_glib_print_func)
- local_glib_print_func (string);
- else
- {
- ensure_stdout_valid ();
- fputs (string, stdout);
- fflush (stdout);
- }
- g_free (string);
-}
-
-GPrintFunc
-g_set_printerr_handler (GPrintFunc func)
-{
- GPrintFunc old_printerr_func;
-
- g_mutex_lock (g_messages_lock);
- old_printerr_func = glib_printerr_func;
- glib_printerr_func = func;
- g_mutex_unlock (g_messages_lock);
-
- return old_printerr_func;
-}
-
-void
-g_printerr (const gchar *format,
- ...)
-{
- va_list args;
- gchar *string;
- GPrintFunc local_glib_printerr_func;
-
- g_return_if_fail (format != NULL);
-
- va_start (args, format);
- string = g_strdup_vprintf (format, args);
- va_end (args);
-
- g_mutex_lock (g_messages_lock);
- local_glib_printerr_func = glib_printerr_func;
- g_mutex_unlock (g_messages_lock);
-
- if (local_glib_printerr_func)
- local_glib_printerr_func (string);
- else
- {
- fputs (string, stderr);
- fflush (stderr);
- }
- g_free (string);
-}
-
-/* compatibility code */
-GErrorFunc
-g_set_error_handler (GErrorFunc func)
-{
- GErrorFunc old_error_func;
-
- g_mutex_lock (g_messages_lock);
- old_error_func = glib_error_func;
- glib_error_func = func;
- g_mutex_unlock (g_messages_lock);
-
- return old_error_func;
-}
-
-/* compatibility code */
-GWarningFunc
-g_set_warning_handler (GWarningFunc func)
-{
- GWarningFunc old_warning_func;
-
- g_mutex_lock (g_messages_lock);
- old_warning_func = glib_warning_func;
- glib_warning_func = func;
- g_mutex_unlock (g_messages_lock);
-
- return old_warning_func;
-}
-
-/* compatibility code */
-GPrintFunc
-g_set_message_handler (GPrintFunc func)
-{
- GPrintFunc old_message_func;
-
- g_mutex_lock (g_messages_lock);
- old_message_func = glib_message_func;
- glib_message_func = func;
- g_mutex_unlock (g_messages_lock);
-
- return old_message_func;
-}
-
-void
-g_messages_init (void)
-{
- g_messages_lock = g_mutex_new();
- g_log_depth = g_private_new(NULL);
-}
diff --git a/glib/gnode.c b/glib/gnode.c
deleted file mode 100644
index 5145c6bd6..000000000
--- a/glib/gnode.c
+++ /dev/null
@@ -1,965 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * GNode: N-way tree implementation.
- * Copyright (C) 1998 Tim Janik
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "glib.h"
-
-/* node allocation
- */
-struct _GAllocator /* from gmem.c */
-{
- gchar *name;
- guint16 n_preallocs;
- guint is_unused : 1;
- guint type : 4;
- GAllocator *last;
- GMemChunk *mem_chunk;
- GNode *free_nodes; /* implementation specific */
-};
-
-G_LOCK_DEFINE_STATIC (current_allocator);
-static GAllocator *current_allocator = NULL;
-
-/* HOLDS: current_allocator_lock */
-static void
-g_node_validate_allocator (GAllocator *allocator)
-{
- g_return_if_fail (allocator != NULL);
- g_return_if_fail (allocator->is_unused == TRUE);
-
- if (allocator->type != G_ALLOCATOR_NODE)
- {
- allocator->type = G_ALLOCATOR_NODE;
- if (allocator->mem_chunk)
- {
- g_mem_chunk_destroy (allocator->mem_chunk);
- allocator->mem_chunk = NULL;
- }
- }
-
- if (!allocator->mem_chunk)
- {
- allocator->mem_chunk = g_mem_chunk_new (allocator->name,
- sizeof (GNode),
- sizeof (GNode) * allocator->n_preallocs,
- G_ALLOC_ONLY);
- allocator->free_nodes = NULL;
- }
-
- allocator->is_unused = FALSE;
-}
-
-void
-g_node_push_allocator (GAllocator *allocator)
-{
- G_LOCK (current_allocator);
- g_node_validate_allocator ( allocator );
- allocator->last = current_allocator;
- current_allocator = allocator;
- G_UNLOCK (current_allocator);
-}
-
-void
-g_node_pop_allocator (void)
-{
- G_LOCK (current_allocator);
- if (current_allocator)
- {
- GAllocator *allocator;
-
- allocator = current_allocator;
- current_allocator = allocator->last;
- allocator->last = NULL;
- allocator->is_unused = TRUE;
- }
- G_UNLOCK (current_allocator);
-}
-
-
-/* --- functions --- */
-GNode*
-g_node_new (gpointer data)
-{
- GNode *node;
-
- G_LOCK (current_allocator);
- if (!current_allocator)
- {
- GAllocator *allocator = g_allocator_new ("GLib default GNode allocator",
- 128);
- g_node_validate_allocator (allocator);
- allocator->last = NULL;
- current_allocator = allocator;
- }
- if (!current_allocator->free_nodes)
- node = g_chunk_new (GNode, current_allocator->mem_chunk);
- else
- {
- node = current_allocator->free_nodes;
- current_allocator->free_nodes = node->next;
- }
- G_UNLOCK (current_allocator);
-
- node->data = data;
- node->next = NULL;
- node->prev = NULL;
- node->parent = NULL;
- node->children = NULL;
-
- return node;
-}
-
-static void
-g_nodes_free (GNode *node)
-{
- GNode *parent;
-
- parent = node;
- while (1)
- {
- if (parent->children)
- g_nodes_free (parent->children);
- if (parent->next)
- parent = parent->next;
- else
- break;
- }
-
- G_LOCK (current_allocator);
- parent->next = current_allocator->free_nodes;
- current_allocator->free_nodes = node;
- G_UNLOCK (current_allocator);
-}
-
-void
-g_node_destroy (GNode *root)
-{
- g_return_if_fail (root != NULL);
-
- if (!G_NODE_IS_ROOT (root))
- g_node_unlink (root);
-
- g_nodes_free (root);
-}
-
-void
-g_node_unlink (GNode *node)
-{
- g_return_if_fail (node != NULL);
-
- if (node->prev)
- node->prev->next = node->next;
- else if (node->parent)
- node->parent->children = node->next;
- node->parent = NULL;
- if (node->next)
- {
- node->next->prev = node->prev;
- node->next = NULL;
- }
- node->prev = NULL;
-}
-
-GNode*
-g_node_insert (GNode *parent,
- gint position,
- GNode *node)
-{
- g_return_val_if_fail (parent != NULL, node);
- g_return_val_if_fail (node != NULL, node);
- g_return_val_if_fail (G_NODE_IS_ROOT (node), node);
-
- if (position > 0)
- return g_node_insert_before (parent,
- g_node_nth_child (parent, position),
- node);
- else if (position == 0)
- return g_node_prepend (parent, node);
- else /* if (position < 0) */
- return g_node_append (parent, node);
-}
-
-GNode*
-g_node_insert_before (GNode *parent,
- GNode *sibling,
- GNode *node)
-{
- g_return_val_if_fail (parent != NULL, node);
- g_return_val_if_fail (node != NULL, node);
- g_return_val_if_fail (G_NODE_IS_ROOT (node), node);
- if (sibling)
- g_return_val_if_fail (sibling->parent == parent, node);
-
- node->parent = parent;
-
- if (sibling)
- {
- if (sibling->prev)
- {
- node->prev = sibling->prev;
- node->prev->next = node;
- node->next = sibling;
- sibling->prev = node;
- }
- else
- {
- node->parent->children = node;
- node->next = sibling;
- sibling->prev = node;
- }
- }
- else
- {
- if (parent->children)
- {
- sibling = parent->children;
- while (sibling->next)
- sibling = sibling->next;
- node->prev = sibling;
- sibling->next = node;
- }
- else
- node->parent->children = node;
- }
-
- return node;
-}
-
-GNode*
-g_node_prepend (GNode *parent,
- GNode *node)
-{
- g_return_val_if_fail (parent != NULL, node);
-
- return g_node_insert_before (parent, parent->children, node);
-}
-
-GNode*
-g_node_get_root (GNode *node)
-{
- g_return_val_if_fail (node != NULL, NULL);
-
- while (node->parent)
- node = node->parent;
-
- return node;
-}
-
-gboolean
-g_node_is_ancestor (GNode *node,
- GNode *descendant)
-{
- g_return_val_if_fail (node != NULL, FALSE);
- g_return_val_if_fail (descendant != NULL, FALSE);
-
- while (descendant)
- {
- if (descendant->parent == node)
- return TRUE;
-
- descendant = descendant->parent;
- }
-
- return FALSE;
-}
-
-/* returns 1 for root, 2 for first level children,
- * 3 for children's children...
- */
-guint
-g_node_depth (GNode *node)
-{
- register guint depth = 0;
-
- while (node)
- {
- depth++;
- node = node->parent;
- }
-
- return depth;
-}
-
-void
-g_node_reverse_children (GNode *node)
-{
- GNode *child;
- GNode *last;
-
- g_return_if_fail (node != NULL);
-
- child = node->children;
- last = NULL;
- while (child)
- {
- last = child;
- child = last->next;
- last->next = last->prev;
- last->prev = child;
- }
- node->children = last;
-}
-
-guint
-g_node_max_height (GNode *root)
-{
- register GNode *child;
- register guint max_height = 0;
-
- if (!root)
- return 0;
-
- child = root->children;
- while (child)
- {
- register guint tmp_height;
-
- tmp_height = g_node_max_height (child);
- if (tmp_height > max_height)
- max_height = tmp_height;
- child = child->next;
- }
-
- return max_height + 1;
-}
-
-static gboolean
-g_node_traverse_pre_order (GNode *node,
- GTraverseFlags flags,
- GNodeTraverseFunc func,
- gpointer data)
-{
- if (node->children)
- {
- GNode *child;
-
- if ((flags & G_TRAVERSE_NON_LEAFS) &&
- func (node, data))
- return TRUE;
-
- child = node->children;
- while (child)
- {
- register GNode *current;
-
- current = child;
- child = current->next;
- if (g_node_traverse_pre_order (current, flags, func, data))
- return TRUE;
- }
- }
- else if ((flags & G_TRAVERSE_LEAFS) &&
- func (node, data))
- return TRUE;
-
- return FALSE;
-}
-
-static gboolean
-g_node_depth_traverse_pre_order (GNode *node,
- GTraverseFlags flags,
- guint depth,
- GNodeTraverseFunc func,
- gpointer data)
-{
- if (node->children)
- {
- GNode *child;
-
- if ((flags & G_TRAVERSE_NON_LEAFS) &&
- func (node, data))
- return TRUE;
-
- depth--;
- if (!depth)
- return FALSE;
-
- child = node->children;
- while (child)
- {
- register GNode *current;
-
- current = child;
- child = current->next;
- if (g_node_depth_traverse_pre_order (current, flags, depth, func, data))
- return TRUE;
- }
- }
- else if ((flags & G_TRAVERSE_LEAFS) &&
- func (node, data))
- return TRUE;
-
- return FALSE;
-}
-
-static gboolean
-g_node_traverse_post_order (GNode *node,
- GTraverseFlags flags,
- GNodeTraverseFunc func,
- gpointer data)
-{
- if (node->children)
- {
- GNode *child;
-
- child = node->children;
- while (child)
- {
- register GNode *current;
-
- current = child;
- child = current->next;
- if (g_node_traverse_post_order (current, flags, func, data))
- return TRUE;
- }
-
- if ((flags & G_TRAVERSE_NON_LEAFS) &&
- func (node, data))
- return TRUE;
-
- }
- else if ((flags & G_TRAVERSE_LEAFS) &&
- func (node, data))
- return TRUE;
-
- return FALSE;
-}
-
-static gboolean
-g_node_depth_traverse_post_order (GNode *node,
- GTraverseFlags flags,
- guint depth,
- GNodeTraverseFunc func,
- gpointer data)
-{
- if (node->children)
- {
- depth--;
- if (depth)
- {
- GNode *child;
-
- child = node->children;
- while (child)
- {
- register GNode *current;
-
- current = child;
- child = current->next;
- if (g_node_depth_traverse_post_order (current, flags, depth, func, data))
- return TRUE;
- }
- }
-
- if ((flags & G_TRAVERSE_NON_LEAFS) &&
- func (node, data))
- return TRUE;
-
- }
- else if ((flags & G_TRAVERSE_LEAFS) &&
- func (node, data))
- return TRUE;
-
- return FALSE;
-}
-
-static gboolean
-g_node_traverse_in_order (GNode *node,
- GTraverseFlags flags,
- GNodeTraverseFunc func,
- gpointer data)
-{
- if (node->children)
- {
- GNode *child;
- register GNode *current;
-
- child = node->children;
- current = child;
- child = current->next;
-
- if (g_node_traverse_in_order (current, flags, func, data))
- return TRUE;
-
- if ((flags & G_TRAVERSE_NON_LEAFS) &&
- func (node, data))
- return TRUE;
-
- while (child)
- {
- current = child;
- child = current->next;
- if (g_node_traverse_in_order (current, flags, func, data))
- return TRUE;
- }
- }
- else if ((flags & G_TRAVERSE_LEAFS) &&
- func (node, data))
- return TRUE;
-
- return FALSE;
-}
-
-static gboolean
-g_node_depth_traverse_in_order (GNode *node,
- GTraverseFlags flags,
- guint depth,
- GNodeTraverseFunc func,
- gpointer data)
-{
- if (node->children)
- {
- depth--;
- if (depth)
- {
- GNode *child;
- register GNode *current;
-
- child = node->children;
- current = child;
- child = current->next;
-
- if (g_node_depth_traverse_in_order (current, flags, depth, func, data))
- return TRUE;
-
- if ((flags & G_TRAVERSE_NON_LEAFS) &&
- func (node, data))
- return TRUE;
-
- while (child)
- {
- current = child;
- child = current->next;
- if (g_node_depth_traverse_in_order (current, flags, depth, func, data))
- return TRUE;
- }
- }
- else if ((flags & G_TRAVERSE_NON_LEAFS) &&
- func (node, data))
- return TRUE;
- }
- else if ((flags & G_TRAVERSE_LEAFS) &&
- func (node, data))
- return TRUE;
-
- return FALSE;
-}
-
-static gboolean
-g_node_traverse_children (GNode *node,
- GTraverseFlags flags,
- GNodeTraverseFunc func,
- gpointer data)
-{
- GNode *child;
-
- child = node->children;
-
- while (child)
- {
- register GNode *current;
-
- current = child;
- child = current->next;
-
- if (current->children)
- {
- if ((flags & G_TRAVERSE_NON_LEAFS) &&
- func (current, data))
- return TRUE;
- }
- else if ((flags & G_TRAVERSE_LEAFS) &&
- func (current, data))
- return TRUE;
- }
-
- child = node->children;
-
- while (child)
- {
- register GNode *current;
-
- current = child;
- child = current->next;
-
- if (current->children &&
- g_node_traverse_children (current, flags, func, data))
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean
-g_node_depth_traverse_children (GNode *node,
- GTraverseFlags flags,
- guint depth,
- GNodeTraverseFunc func,
- gpointer data)
-{
- GNode *child;
-
- child = node->children;
-
- while (child)
- {
- register GNode *current;
-
- current = child;
- child = current->next;
-
- if (current->children)
- {
- if ((flags & G_TRAVERSE_NON_LEAFS) &&
- func (current, data))
- return TRUE;
- }
- else if ((flags & G_TRAVERSE_LEAFS) &&
- func (current, data))
- return TRUE;
- }
-
- depth--;
- if (!depth)
- return FALSE;
-
- child = node->children;
-
- while (child)
- {
- register GNode *current;
-
- current = child;
- child = current->next;
-
- if (current->children &&
- g_node_depth_traverse_children (current, flags, depth, func, data))
- return TRUE;
- }
-
- return FALSE;
-}
-
-void
-g_node_traverse (GNode *root,
- GTraverseType order,
- GTraverseFlags flags,
- gint depth,
- GNodeTraverseFunc func,
- gpointer data)
-{
- g_return_if_fail (root != NULL);
- g_return_if_fail (func != NULL);
- g_return_if_fail (order <= G_LEVEL_ORDER);
- g_return_if_fail (flags <= G_TRAVERSE_MASK);
- g_return_if_fail (depth == -1 || depth > 0);
-
- switch (order)
- {
- case G_PRE_ORDER:
- if (depth < 0)
- g_node_traverse_pre_order (root, flags, func, data);
- else
- g_node_depth_traverse_pre_order (root, flags, depth, func, data);
- break;
- case G_POST_ORDER:
- if (depth < 0)
- g_node_traverse_post_order (root, flags, func, data);
- else
- g_node_depth_traverse_post_order (root, flags, depth, func, data);
- break;
- case G_IN_ORDER:
- if (depth < 0)
- g_node_traverse_in_order (root, flags, func, data);
- else
- g_node_depth_traverse_in_order (root, flags, depth, func, data);
- break;
- case G_LEVEL_ORDER:
- if (root->children)
- {
- if (!((flags & G_TRAVERSE_NON_LEAFS) &&
- func (root, data)))
- {
- if (depth < 0)
- g_node_traverse_children (root, flags, func, data);
- else
- {
- depth--;
- if (depth)
- g_node_depth_traverse_children (root, flags, depth, func, data);
- }
- }
- }
- else if (flags & G_TRAVERSE_LEAFS)
- func (root, data);
- break;
- }
-}
-
-static gboolean
-g_node_find_func (GNode *node,
- gpointer data)
-{
- register gpointer *d = data;
-
- if (*d != node->data)
- return FALSE;
-
- *(++d) = node;
-
- return TRUE;
-}
-
-GNode*
-g_node_find (GNode *root,
- GTraverseType order,
- GTraverseFlags flags,
- gpointer data)
-{
- gpointer d[2];
-
- g_return_val_if_fail (root != NULL, NULL);
- g_return_val_if_fail (order <= G_LEVEL_ORDER, NULL);
- g_return_val_if_fail (flags <= G_TRAVERSE_MASK, NULL);
-
- d[0] = data;
- d[1] = NULL;
-
- g_node_traverse (root, order, flags, -1, g_node_find_func, d);
-
- return d[1];
-}
-
-static void
-g_node_count_func (GNode *node,
- GTraverseFlags flags,
- guint *n)
-{
- if (node->children)
- {
- GNode *child;
-
- if (flags & G_TRAVERSE_NON_LEAFS)
- (*n)++;
-
- child = node->children;
- while (child)
- {
- g_node_count_func (child, flags, n);
- child = child->next;
- }
- }
- else if (flags & G_TRAVERSE_LEAFS)
- (*n)++;
-}
-
-guint
-g_node_n_nodes (GNode *root,
- GTraverseFlags flags)
-{
- guint n = 0;
-
- g_return_val_if_fail (root != NULL, 0);
- g_return_val_if_fail (flags <= G_TRAVERSE_MASK, 0);
-
- g_node_count_func (root, flags, &n);
-
- return n;
-}
-
-GNode*
-g_node_last_child (GNode *node)
-{
- g_return_val_if_fail (node != NULL, NULL);
-
- node = node->children;
- if (node)
- while (node->next)
- node = node->next;
-
- return node;
-}
-
-GNode*
-g_node_nth_child (GNode *node,
- guint n)
-{
- g_return_val_if_fail (node != NULL, NULL);
-
- node = node->children;
- if (node)
- while ((n-- > 0) && node)
- node = node->next;
-
- return node;
-}
-
-guint
-g_node_n_children (GNode *node)
-{
- guint n = 0;
-
- g_return_val_if_fail (node != NULL, 0);
-
- node = node->children;
- while (node)
- {
- n++;
- node = node->next;
- }
-
- return n;
-}
-
-GNode*
-g_node_find_child (GNode *node,
- GTraverseFlags flags,
- gpointer data)
-{
- g_return_val_if_fail (node != NULL, NULL);
- g_return_val_if_fail (flags <= G_TRAVERSE_MASK, NULL);
-
- node = node->children;
- while (node)
- {
- if (node->data == data)
- {
- if (G_NODE_IS_LEAF (node))
- {
- if (flags & G_TRAVERSE_LEAFS)
- return node;
- }
- else
- {
- if (flags & G_TRAVERSE_NON_LEAFS)
- return node;
- }
- }
- node = node->next;
- }
-
- return NULL;
-}
-
-gint
-g_node_child_position (GNode *node,
- GNode *child)
-{
- register guint n = 0;
-
- g_return_val_if_fail (node != NULL, -1);
- g_return_val_if_fail (child != NULL, -1);
- g_return_val_if_fail (child->parent == node, -1);
-
- node = node->children;
- while (node)
- {
- if (node == child)
- return n;
- n++;
- node = node->next;
- }
-
- return -1;
-}
-
-gint
-g_node_child_index (GNode *node,
- gpointer data)
-{
- register guint n = 0;
-
- g_return_val_if_fail (node != NULL, -1);
-
- node = node->children;
- while (node)
- {
- if (node->data == data)
- return n;
- n++;
- node = node->next;
- }
-
- return -1;
-}
-
-GNode*
-g_node_first_sibling (GNode *node)
-{
- g_return_val_if_fail (node != NULL, NULL);
-
- while (node->prev)
- node = node->prev;
-
- return node;
-}
-
-GNode*
-g_node_last_sibling (GNode *node)
-{
- g_return_val_if_fail (node != NULL, NULL);
-
- while (node->next)
- node = node->next;
-
- return node;
-}
-
-void
-g_node_children_foreach (GNode *node,
- GTraverseFlags flags,
- GNodeForeachFunc func,
- gpointer data)
-{
- g_return_if_fail (node != NULL);
- g_return_if_fail (flags <= G_TRAVERSE_MASK);
- g_return_if_fail (func != NULL);
-
- node = node->children;
- while (node)
- {
- register GNode *current;
-
- current = node;
- node = current->next;
- if (G_NODE_IS_LEAF (current))
- {
- if (flags & G_TRAVERSE_LEAFS)
- func (current, data);
- }
- else
- {
- if (flags & G_TRAVERSE_NON_LEAFS)
- func (current, data);
- }
- }
-}
diff --git a/glib/gprimes.c b/glib/gprimes.c
deleted file mode 100644
index c6109bf95..000000000
--- a/glib/gprimes.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "glib.h"
-
-static const guint g_primes[] =
-{
- 11,
- 19,
- 37,
- 73,
- 109,
- 163,
- 251,
- 367,
- 557,
- 823,
- 1237,
- 1861,
- 2777,
- 4177,
- 6247,
- 9371,
- 14057,
- 21089,
- 31627,
- 47431,
- 71143,
- 106721,
- 160073,
- 240101,
- 360163,
- 540217,
- 810343,
- 1215497,
- 1823231,
- 2734867,
- 4102283,
- 6153409,
- 9230113,
- 13845163,
-};
-
-static const guint g_nprimes = sizeof (g_primes) / sizeof (g_primes[0]);
-
-guint
-g_spaced_primes_closest (guint num)
-{
- gint i;
-
- for (i = 0; i < g_nprimes; i++)
- if (g_primes[i] > num)
- return g_primes[i];
-
- return g_primes[g_nprimes - 1];
-}
diff --git a/glib/grel.c b/glib/grel.c
deleted file mode 100644
index 4358cdceb..000000000
--- a/glib/grel.c
+++ /dev/null
@@ -1,459 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "glib.h"
-#include <stdarg.h>
-#include <string.h>
-
-typedef struct _GRealRelation GRealRelation;
-typedef struct _GRealTuples GRealTuples;
-
-struct _GRealRelation
-{
- gint fields;
- gint current_field;
-
- GHashTable *all_tuples;
- GHashTable **hashed_tuple_tables;
- GMemChunk *tuple_chunk;
-
- gint count;
-};
-
-struct _GRealTuples
-{
- gint len;
- gint width;
- gpointer *data;
-};
-
-static gboolean
-tuple_equal_2 (gconstpointer v_a,
- gconstpointer v_b)
-{
- gpointer* a = (gpointer*) v_a;
- gpointer* b = (gpointer*) v_b;
-
- return a[0] == b[0] && a[1] == b[1];
-}
-
-static guint
-tuple_hash_2 (gconstpointer v_a)
-{
- gpointer* a = (gpointer*) v_a;
-
- return (gulong)a[0] ^ (gulong)a[1];
-}
-
-static GHashFunc
-tuple_hash (gint fields)
-{
- switch (fields)
- {
- case 2:
- return tuple_hash_2;
- default:
- g_error ("no tuple hash for %d", fields);
- }
-
- return NULL;
-}
-
-static GCompareFunc
-tuple_equal (gint fields)
-{
- switch (fields)
- {
- case 2:
- return tuple_equal_2;
- default:
- g_error ("no tuple equal for %d", fields);
- }
-
- return NULL;
-}
-
-GRelation*
-g_relation_new (gint fields)
-{
- GRealRelation* rel = g_new0 (GRealRelation, 1);
-
- rel->fields = fields;
- rel->tuple_chunk = g_mem_chunk_new ("Relation Chunk",
- fields * sizeof (gpointer),
- fields * sizeof (gpointer) * 128,
- G_ALLOC_AND_FREE);
- rel->all_tuples = g_hash_table_new (tuple_hash (fields), tuple_equal (fields));
- rel->hashed_tuple_tables = g_new0 (GHashTable*, fields);
-
- return (GRelation*) rel;
-}
-
-static void
-g_relation_free_array (gpointer key, gpointer value, gpointer user_data)
-{
- g_hash_table_destroy ((GHashTable*) value);
-}
-
-void
-g_relation_destroy (GRelation *relation)
-{
- GRealRelation *rel = (GRealRelation *) relation;
- gint i;
-
- if (rel)
- {
- g_hash_table_destroy (rel->all_tuples);
- g_mem_chunk_destroy (rel->tuple_chunk);
-
- for (i = 0; i < rel->fields; i += 1)
- {
- if (rel->hashed_tuple_tables[i])
- {
- g_hash_table_foreach (rel->hashed_tuple_tables[i], g_relation_free_array, NULL);
- g_hash_table_destroy (rel->hashed_tuple_tables[i]);
- }
- }
-
- g_free (rel->hashed_tuple_tables);
- g_free (rel);
- }
-}
-
-void
-g_relation_index (GRelation *relation,
- gint field,
- GHashFunc hash_func,
- GCompareFunc key_compare_func)
-{
- GRealRelation *rel = (GRealRelation *) relation;
-
- g_return_if_fail (relation != NULL);
-
- g_return_if_fail (rel->count == 0 && rel->hashed_tuple_tables[field] == NULL);
-
- rel->hashed_tuple_tables[field] = g_hash_table_new (hash_func, key_compare_func);
-}
-
-void
-g_relation_insert (GRelation *relation,
- ...)
-{
- GRealRelation *rel = (GRealRelation *) relation;
- gpointer* tuple = g_chunk_new (gpointer, rel->tuple_chunk);
- va_list args;
- gint i;
-
- va_start(args, relation);
-
- for (i = 0; i < rel->fields; i += 1)
- tuple[i] = va_arg(args, gpointer);
-
- va_end(args);
-
- g_hash_table_insert (rel->all_tuples, tuple, tuple);
-
- rel->count += 1;
-
- for (i = 0; i < rel->fields; i += 1)
- {
- GHashTable *table;
- gpointer key;
- GHashTable *per_key_table;
-
- table = rel->hashed_tuple_tables[i];
-
- if (table == NULL)
- continue;
-
- key = tuple[i];
- per_key_table = g_hash_table_lookup (table, key);
-
- if (per_key_table == NULL)
- {
- per_key_table = g_hash_table_new (tuple_hash (rel->fields), tuple_equal (rel->fields));
- g_hash_table_insert (table, key, per_key_table);
- }
-
- g_hash_table_insert (per_key_table, tuple, tuple);
- }
-}
-
-static void
-g_relation_delete_tuple (gpointer tuple_key,
- gpointer tuple_value,
- gpointer user_data)
-{
- gpointer *tuple = (gpointer*) tuple_value;
- GRealRelation *rel = (GRealRelation *) user_data;
- gint j;
-
- g_assert (tuple_key == tuple_value);
-
- for (j = 0; j < rel->fields; j += 1)
- {
- GHashTable *one_table = rel->hashed_tuple_tables[j];
- gpointer one_key;
- GHashTable *per_key_table;
-
- if (one_table == NULL)
- continue;
-
- if (j == rel->current_field)
- /* can't delete from the table we're foreaching in */
- continue;
-
- one_key = tuple[j];
-
- per_key_table = g_hash_table_lookup (one_table, one_key);
-
- g_hash_table_remove (per_key_table, tuple);
- }
-
- g_hash_table_remove (rel->all_tuples, tuple);
-
- rel->count -= 1;
-}
-
-gint
-g_relation_delete (GRelation *relation,
- gconstpointer key,
- gint field)
-{
- GRealRelation *rel = (GRealRelation *) relation;
- GHashTable *table = rel->hashed_tuple_tables[field];
- GHashTable *key_table;
- gint count = rel->count;
-
- g_return_val_if_fail (relation != NULL, 0);
- g_return_val_if_fail (table != NULL, 0);
-
- key_table = g_hash_table_lookup (table, key);
-
- if (!key_table)
- return 0;
-
- rel->current_field = field;
-
- g_hash_table_foreach (key_table, g_relation_delete_tuple, rel);
-
- g_hash_table_remove (table, key);
-
- g_hash_table_destroy (key_table);
-
- /* @@@ FIXME: Remove empty hash tables. */
-
- return count - rel->count;
-}
-
-static void
-g_relation_select_tuple (gpointer tuple_key,
- gpointer tuple_value,
- gpointer user_data)
-{
- gpointer *tuple = (gpointer*) tuple_value;
- GRealTuples *tuples = (GRealTuples*) user_data;
- gint stride = sizeof (gpointer) * tuples->width;
-
- g_assert (tuple_key == tuple_value);
-
- memcpy (tuples->data + (tuples->len * tuples->width),
- tuple,
- stride);
-
- tuples->len += 1;
-}
-
-GTuples*
-g_relation_select (GRelation *relation,
- gconstpointer key,
- gint field)
-{
- GRealRelation *rel = (GRealRelation *) relation;
- GHashTable *table = rel->hashed_tuple_tables[field];
- GHashTable *key_table;
- GRealTuples *tuples = g_new0 (GRealTuples, 1);
- gint count;
-
- g_return_val_if_fail (relation != NULL, NULL);
- g_return_val_if_fail (table != NULL, NULL);
-
- key_table = g_hash_table_lookup (table, key);
-
- if (!key_table)
- return (GTuples*)tuples;
-
- count = g_relation_count (relation, key, field);
-
- tuples->data = g_malloc (sizeof (gpointer) * rel->fields * count);
- tuples->width = rel->fields;
-
- g_hash_table_foreach (key_table, g_relation_select_tuple, tuples);
-
- g_assert (count == tuples->len);
-
- return (GTuples*)tuples;
-}
-
-gint
-g_relation_count (GRelation *relation,
- gconstpointer key,
- gint field)
-{
- GRealRelation *rel = (GRealRelation *) relation;
- GHashTable *table = rel->hashed_tuple_tables[field];
- GHashTable *key_table;
-
- g_return_val_if_fail (relation != NULL, 0);
- g_return_val_if_fail (table != NULL, 0);
-
- key_table = g_hash_table_lookup (table, key);
-
- if (!key_table)
- return 0;
-
- return g_hash_table_size (key_table);
-}
-
-gboolean
-g_relation_exists (GRelation *relation, ...)
-{
- GRealRelation *rel = (GRealRelation *) relation;
- gpointer* tuple = g_chunk_new (gpointer, rel->tuple_chunk);
- va_list args;
- gint i;
- gboolean result;
-
- va_start(args, relation);
-
- for (i = 0; i < rel->fields; i += 1)
- tuple[i] = va_arg(args, gpointer);
-
- va_end(args);
-
- result = g_hash_table_lookup (rel->all_tuples, tuple) != NULL;
-
- g_mem_chunk_free (rel->tuple_chunk, tuple);
-
- return result;
-}
-
-void
-g_tuples_destroy (GTuples *tuples0)
-{
- GRealTuples *tuples = (GRealTuples*) tuples0;
-
- if (tuples)
- {
- g_free (tuples->data);
- g_free (tuples);
- }
-}
-
-gpointer
-g_tuples_index (GTuples *tuples0,
- gint index,
- gint field)
-{
- GRealTuples *tuples = (GRealTuples*) tuples0;
-
- g_return_val_if_fail (tuples0 != NULL, NULL);
- g_return_val_if_fail (field < tuples->width, NULL);
-
- return tuples->data[index * tuples->width + field];
-}
-
-/* Print
- */
-
-static void
-g_relation_print_one (gpointer tuple_key,
- gpointer tuple_value,
- gpointer user_data)
-{
- gint i;
- GString *gstring;
- GRealRelation* rel = (GRealRelation*) user_data;
- gpointer* tuples = (gpointer*) tuple_value;
-
- gstring = g_string_new ("[");
-
- for (i = 0; i < rel->fields; i += 1)
- {
- g_string_sprintfa (gstring, "%p", tuples[i]);
-
- if (i < (rel->fields - 1))
- g_string_append (gstring, ",");
- }
-
- g_string_append (gstring, "]");
- g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, gstring->str);
- g_string_free (gstring, TRUE);
-}
-
-static void
-g_relation_print_index (gpointer tuple_key,
- gpointer tuple_value,
- gpointer user_data)
-{
- GRealRelation* rel = (GRealRelation*) user_data;
- GHashTable* table = (GHashTable*) tuple_value;
-
- g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "*** key %p", tuple_key);
-
- g_hash_table_foreach (table,
- g_relation_print_one,
- rel);
-}
-
-void
-g_relation_print (GRelation *relation)
-{
- gint i;
- GRealRelation* rel = (GRealRelation*) relation;
-
- g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "*** all tuples (%d)", rel->count);
-
- g_hash_table_foreach (rel->all_tuples,
- g_relation_print_one,
- rel);
-
- for (i = 0; i < rel->fields; i += 1)
- {
- if (rel->hashed_tuple_tables[i] == NULL)
- continue;
-
- g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "*** index %d", i);
-
- g_hash_table_foreach (rel->hashed_tuple_tables[i],
- g_relation_print_index,
- rel);
- }
-
-}
diff --git a/glib/gscanner.c b/glib/gscanner.c
deleted file mode 100644
index becead817..000000000
--- a/glib/gscanner.c
+++ /dev/null
@@ -1,1752 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * GScanner: Flexible lexical scanner for general purpose.
- * Copyright (C) 1997, 1998 Tim Janik
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#define __gscanner_c__
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <stdio.h>
-#include "glib.h"
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <errno.h>
-#include <sys/types.h> /* needed for sys/stat.h */
-#include <sys/stat.h>
-#ifdef _MSC_VER
-#include <io.h> /* For _read() */
-#endif
-
-/* --- defines --- */
-#define to_lower(c) ( \
- (guchar) ( \
- ( (((guchar)(c))>='A' && ((guchar)(c))<='Z') * ('a'-'A') ) | \
- ( (((guchar)(c))>=192 && ((guchar)(c))<=214) * (224-192) ) | \
- ( (((guchar)(c))>=216 && ((guchar)(c))<=222) * (248-216) ) | \
- ((guchar)(c)) \
- ) \
-)
-#define READ_BUFFER_SIZE (4000)
-
-
-/* --- typedefs --- */
-typedef struct _GScannerKey GScannerKey;
-
-struct _GScannerKey
-{
- guint scope_id;
- gchar *symbol;
- gpointer value;
-};
-
-
-
-/* --- variables --- */
-static GScannerConfig g_scanner_config_template =
-{
- (
- " \t\r\n"
- ) /* cset_skip_characters */,
- (
- G_CSET_a_2_z
- "_"
- G_CSET_A_2_Z
- ) /* cset_identifier_first */,
- (
- G_CSET_a_2_z
- "_0123456789"
- G_CSET_A_2_Z
- G_CSET_LATINS
- G_CSET_LATINC
- ) /* cset_identifier_nth */,
- ( "#\n" ) /* cpair_comment_single */,
-
- FALSE /* case_sensitive */,
-
- TRUE /* skip_comment_multi */,
- TRUE /* skip_comment_single */,
- TRUE /* scan_comment_multi */,
- TRUE /* scan_identifier */,
- FALSE /* scan_identifier_1char */,
- FALSE /* scan_identifier_NULL */,
- TRUE /* scan_symbols */,
- FALSE /* scan_binary */,
- TRUE /* scan_octal */,
- TRUE /* scan_float */,
- TRUE /* scan_hex */,
- FALSE /* scan_hex_dollar */,
- TRUE /* scan_string_sq */,
- TRUE /* scan_string_dq */,
- TRUE /* numbers_2_int */,
- FALSE /* int_2_float */,
- FALSE /* identifier_2_string */,
- TRUE /* char_2_token */,
- FALSE /* symbol_2_token */,
- FALSE /* scope_0_fallback */,
-};
-
-
-/* --- prototypes --- */
-static inline
-GScannerKey* g_scanner_lookup_internal (GScanner *scanner,
- guint scope_id,
- const gchar *symbol);
-static gint g_scanner_key_equal (gconstpointer v1,
- gconstpointer v2);
-static guint g_scanner_key_hash (gconstpointer v);
-static void g_scanner_get_token_ll (GScanner *scanner,
- GTokenType *token_p,
- GTokenValue *value_p,
- guint *line_p,
- guint *position_p);
-static void g_scanner_get_token_i (GScanner *scanner,
- GTokenType *token_p,
- GTokenValue *value_p,
- guint *line_p,
- guint *position_p);
-
-static guchar g_scanner_peek_next_char (GScanner *scanner);
-static guchar g_scanner_get_char (GScanner *scanner,
- guint *line_p,
- guint *position_p);
-static void g_scanner_msg_handler (GScanner *scanner,
- gchar *message,
- gint is_error);
-
-
-/* --- functions --- */
-static inline gint
-g_scanner_char_2_num (guchar c,
- guchar base)
-{
- if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'A' && c <= 'Z')
- c -= 'A' - 10;
- else if (c >= 'a' && c <= 'z')
- c -= 'a' - 10;
- else
- return -1;
-
- if (c < base)
- return c;
-
- return -1;
-}
-
-GScanner*
-g_scanner_new (GScannerConfig *config_templ)
-{
- GScanner *scanner;
-
- if (!config_templ)
- config_templ = &g_scanner_config_template;
-
- scanner = g_new0 (GScanner, 1);
-
- scanner->user_data = NULL;
- scanner->max_parse_errors = 0;
- scanner->parse_errors = 0;
- scanner->input_name = NULL;
- scanner->derived_data = NULL;
-
- scanner->config = g_new0 (GScannerConfig, 1);
-
- scanner->config->case_sensitive = config_templ->case_sensitive;
- scanner->config->cset_skip_characters = config_templ->cset_skip_characters;
- if (!scanner->config->cset_skip_characters)
- scanner->config->cset_skip_characters = "";
- scanner->config->cset_identifier_first= config_templ->cset_identifier_first;
- scanner->config->cset_identifier_nth = config_templ->cset_identifier_nth;
- scanner->config->cpair_comment_single = config_templ->cpair_comment_single;
- scanner->config->skip_comment_multi = config_templ->skip_comment_multi;
- scanner->config->skip_comment_single = config_templ->skip_comment_single;
- scanner->config->scan_comment_multi = config_templ->scan_comment_multi;
- scanner->config->scan_identifier = config_templ->scan_identifier;
- scanner->config->scan_identifier_1char= config_templ->scan_identifier_1char;
- scanner->config->scan_identifier_NULL = config_templ->scan_identifier_NULL;
- scanner->config->scan_symbols = config_templ->scan_symbols;
- scanner->config->scan_binary = config_templ->scan_binary;
- scanner->config->scan_octal = config_templ->scan_octal;
- scanner->config->scan_float = config_templ->scan_float;
- scanner->config->scan_hex = config_templ->scan_hex;
- scanner->config->scan_hex_dollar = config_templ->scan_hex_dollar;
- scanner->config->scan_string_sq = config_templ->scan_string_sq;
- scanner->config->scan_string_dq = config_templ->scan_string_dq;
- scanner->config->numbers_2_int = config_templ->numbers_2_int;
- scanner->config->int_2_float = config_templ->int_2_float;
- scanner->config->identifier_2_string = config_templ->identifier_2_string;
- scanner->config->char_2_token = config_templ->char_2_token;
- scanner->config->symbol_2_token = config_templ->symbol_2_token;
- scanner->config->scope_0_fallback = config_templ->scope_0_fallback;
-
- scanner->token = G_TOKEN_NONE;
- scanner->value.v_int = 0;
- scanner->line = 1;
- scanner->position = 0;
-
- scanner->next_token = G_TOKEN_NONE;
- scanner->next_value.v_int = 0;
- scanner->next_line = 1;
- scanner->next_position = 0;
-
- scanner->symbol_table = g_hash_table_new (g_scanner_key_hash, g_scanner_key_equal);
- scanner->input_fd = -1;
- scanner->text = NULL;
- scanner->text_end = NULL;
- scanner->buffer = NULL;
- scanner->scope_id = 0;
-
- scanner->msg_handler = g_scanner_msg_handler;
-
- return scanner;
-}
-
-static inline void
-g_scanner_free_value (GTokenType *token_p,
- GTokenValue *value_p)
-{
- switch (*token_p)
- {
- case G_TOKEN_STRING:
- case G_TOKEN_IDENTIFIER:
- case G_TOKEN_IDENTIFIER_NULL:
- case G_TOKEN_COMMENT_SINGLE:
- case G_TOKEN_COMMENT_MULTI:
- g_free (value_p->v_string);
- break;
-
- default:
- break;
- }
-
- *token_p = G_TOKEN_NONE;
-}
-
-static void
-g_scanner_destroy_symbol_table_entry (gpointer _key,
- gpointer _value,
- gpointer _data)
-{
- GScannerKey *key = _key;
-
- g_free (key->symbol);
- g_free (key);
-}
-
-void
-g_scanner_destroy (GScanner *scanner)
-{
- g_return_if_fail (scanner != NULL);
-
- g_hash_table_foreach (scanner->symbol_table,
- g_scanner_destroy_symbol_table_entry, NULL);
- g_hash_table_destroy (scanner->symbol_table);
- g_scanner_free_value (&scanner->token, &scanner->value);
- g_scanner_free_value (&scanner->next_token, &scanner->next_value);
- g_free (scanner->config);
- g_free (scanner->buffer);
- g_free (scanner);
-}
-
-static void
-g_scanner_msg_handler (GScanner *scanner,
- gchar *message,
- gint is_error)
-{
- g_return_if_fail (scanner != NULL);
-
- fprintf (stdout, "%s:%d: ", scanner->input_name, scanner->line);
- if (is_error)
- fprintf (stdout, "error: ");
- fprintf (stdout, "%s\n", message);
-}
-
-void
-g_scanner_error (GScanner *scanner,
- const gchar *format,
- ...)
-{
- g_return_if_fail (scanner != NULL);
- g_return_if_fail (format != NULL);
-
- scanner->parse_errors++;
-
- if (scanner->msg_handler)
- {
- va_list args;
- gchar *string;
-
- va_start (args, format);
- string = g_strdup_vprintf (format, args);
- va_end (args);
-
- scanner->msg_handler (scanner, string, TRUE);
-
- g_free (string);
- }
-}
-
-void
-g_scanner_warn (GScanner *scanner,
- const gchar *format,
- ...)
-{
- g_return_if_fail (scanner != NULL);
- g_return_if_fail (format != NULL);
-
- if (scanner->msg_handler)
- {
- va_list args;
- gchar *string;
-
- va_start (args, format);
- string = g_strdup_vprintf (format, args);
- va_end (args);
-
- scanner->msg_handler (scanner, string, FALSE);
-
- g_free (string);
- }
-}
-
-static gint
-g_scanner_key_equal (gconstpointer v1,
- gconstpointer v2)
-{
- const GScannerKey *key1 = v1;
- const GScannerKey *key2 = v2;
-
- return (key1->scope_id == key2->scope_id) && (strcmp (key1->symbol, key2->symbol) == 0);
-}
-
-static guint
-g_scanner_key_hash (gconstpointer v)
-{
- const GScannerKey *key = v;
- gchar *c;
- guint h;
-
- h = key->scope_id;
- for (c = key->symbol; *c; c++)
- {
- guint g;
-
- h = (h << 4) + *c;
- g = h & 0xf0000000;
- if (g)
- {
- h = h ^ (g >> 24);
- h = h ^ g;
- }
- }
-
- return h;
-}
-
-static inline GScannerKey*
-g_scanner_lookup_internal (GScanner *scanner,
- guint scope_id,
- const gchar *symbol)
-{
- GScannerKey *key_p;
- GScannerKey key;
-
- key.scope_id = scope_id;
-
- if (!scanner->config->case_sensitive)
- {
- gchar *d;
- const gchar *c;
-
- key.symbol = g_new (gchar, strlen (symbol) + 1);
- for (d = key.symbol, c = symbol; *c; c++, d++)
- *d = to_lower (*c);
- *d = 0;
- key_p = g_hash_table_lookup (scanner->symbol_table, &key);
- g_free (key.symbol);
- }
- else
- {
- key.symbol = (gchar*) symbol;
- key_p = g_hash_table_lookup (scanner->symbol_table, &key);
- }
-
- return key_p;
-}
-
-void
-g_scanner_scope_add_symbol (GScanner *scanner,
- guint scope_id,
- const gchar *symbol,
- gpointer value)
-{
- GScannerKey *key;
-
- g_return_if_fail (scanner != NULL);
- g_return_if_fail (symbol != NULL);
-
- key = g_scanner_lookup_internal (scanner, scope_id, symbol);
-
- if (!key)
- {
- key = g_new (GScannerKey, 1);
- key->scope_id = scope_id;
- key->symbol = g_strdup (symbol);
- key->value = value;
- if (!scanner->config->case_sensitive)
- {
- gchar *c;
-
- c = key->symbol;
- while (*c != 0)
- {
- *c = to_lower (*c);
- c++;
- }
- }
- g_hash_table_insert (scanner->symbol_table, key, key);
- }
- else
- key->value = value;
-}
-
-void
-g_scanner_scope_remove_symbol (GScanner *scanner,
- guint scope_id,
- const gchar *symbol)
-{
- GScannerKey *key;
-
- g_return_if_fail (scanner != NULL);
- g_return_if_fail (symbol != NULL);
-
- key = g_scanner_lookup_internal (scanner, scope_id, symbol);
-
- if (key)
- {
- g_hash_table_remove (scanner->symbol_table, key);
- g_free (key->symbol);
- g_free (key);
- }
-}
-
-gpointer
-g_scanner_lookup_symbol (GScanner *scanner,
- const gchar *symbol)
-{
- GScannerKey *key;
- guint scope_id;
-
- g_return_val_if_fail (scanner != NULL, NULL);
-
- if (!symbol)
- return NULL;
-
- scope_id = scanner->scope_id;
- key = g_scanner_lookup_internal (scanner, scope_id, symbol);
- if (!key && scope_id && scanner->config->scope_0_fallback)
- key = g_scanner_lookup_internal (scanner, 0, symbol);
-
- if (key)
- return key->value;
- else
- return NULL;
-}
-
-gpointer
-g_scanner_scope_lookup_symbol (GScanner *scanner,
- guint scope_id,
- const gchar *symbol)
-{
- GScannerKey *key;
-
- g_return_val_if_fail (scanner != NULL, NULL);
-
- if (!symbol)
- return NULL;
-
- key = g_scanner_lookup_internal (scanner, scope_id, symbol);
-
- if (key)
- return key->value;
- else
- return NULL;
-}
-
-guint
-g_scanner_set_scope (GScanner *scanner,
- guint scope_id)
-{
- guint old_scope_id;
-
- g_return_val_if_fail (scanner != NULL, 0);
-
- old_scope_id = scanner->scope_id;
- scanner->scope_id = scope_id;
-
- return old_scope_id;
-}
-
-static void
-g_scanner_foreach_internal (gpointer _key,
- gpointer _value,
- gpointer _user_data)
-{
- GScannerKey *key;
- gpointer *d;
- GHFunc func;
- gpointer user_data;
- guint *scope_id;
-
- d = _user_data;
- func = (GHFunc) d[0];
- user_data = d[1];
- scope_id = d[2];
- key = _value;
-
- if (key->scope_id == *scope_id)
- func (key->symbol, key->value, user_data);
-}
-
-void
-g_scanner_scope_foreach_symbol (GScanner *scanner,
- guint scope_id,
- GHFunc func,
- gpointer user_data)
-{
- gpointer d[3];
-
- g_return_if_fail (scanner != NULL);
-
- d[0] = (gpointer) func;
- d[1] = user_data;
- d[2] = &scope_id;
-
- g_hash_table_foreach (scanner->symbol_table, g_scanner_foreach_internal, d);
-}
-
-void
-g_scanner_freeze_symbol_table (GScanner *scanner)
-{
- g_return_if_fail (scanner != NULL);
-
- g_hash_table_freeze (scanner->symbol_table);
-}
-
-void
-g_scanner_thaw_symbol_table (GScanner *scanner)
-{
- g_return_if_fail (scanner != NULL);
-
- g_hash_table_thaw (scanner->symbol_table);
-}
-
-GTokenType
-g_scanner_peek_next_token (GScanner *scanner)
-{
- g_return_val_if_fail (scanner != NULL, G_TOKEN_EOF);
-
- if (scanner->next_token == G_TOKEN_NONE)
- {
- scanner->next_line = scanner->line;
- scanner->next_position = scanner->position;
- g_scanner_get_token_i (scanner,
- &scanner->next_token,
- &scanner->next_value,
- &scanner->next_line,
- &scanner->next_position);
- }
-
- return scanner->next_token;
-}
-
-GTokenType
-g_scanner_get_next_token (GScanner *scanner)
-{
- g_return_val_if_fail (scanner != NULL, G_TOKEN_EOF);
-
- if (scanner->next_token != G_TOKEN_NONE)
- {
- g_scanner_free_value (&scanner->token, &scanner->value);
-
- scanner->token = scanner->next_token;
- scanner->value = scanner->next_value;
- scanner->line = scanner->next_line;
- scanner->position = scanner->next_position;
- scanner->next_token = G_TOKEN_NONE;
- }
- else
- g_scanner_get_token_i (scanner,
- &scanner->token,
- &scanner->value,
- &scanner->line,
- &scanner->position);
-
- return scanner->token;
-}
-
-GTokenType
-g_scanner_cur_token (GScanner *scanner)
-{
- g_return_val_if_fail (scanner != NULL, G_TOKEN_EOF);
-
- return scanner->token;
-}
-
-GTokenValue
-g_scanner_cur_value (GScanner *scanner)
-{
- GTokenValue v;
-
- v.v_int = 0;
-
- g_return_val_if_fail (scanner != NULL, v);
-
- /* MSC isn't capable of handling return scanner->value; ? */
-
- v = scanner->value;
-
- return v;
-}
-
-guint
-g_scanner_cur_line (GScanner *scanner)
-{
- g_return_val_if_fail (scanner != NULL, 0);
-
- return scanner->line;
-}
-
-guint
-g_scanner_cur_position (GScanner *scanner)
-{
- g_return_val_if_fail (scanner != NULL, 0);
-
- return scanner->position;
-}
-
-gboolean
-g_scanner_eof (GScanner *scanner)
-{
- g_return_val_if_fail (scanner != NULL, TRUE);
-
- return scanner->token == G_TOKEN_EOF;
-}
-
-void
-g_scanner_input_file (GScanner *scanner,
- gint input_fd)
-{
- g_return_if_fail (scanner != NULL);
- g_return_if_fail (input_fd >= 0);
-
- if (scanner->input_fd >= 0)
- g_scanner_sync_file_offset (scanner);
-
- scanner->token = G_TOKEN_NONE;
- scanner->value.v_int = 0;
- scanner->line = 1;
- scanner->position = 0;
- scanner->next_token = G_TOKEN_NONE;
-
- scanner->input_fd = input_fd;
- scanner->text = NULL;
- scanner->text_end = NULL;
-
- if (!scanner->buffer)
- scanner->buffer = g_new (gchar, READ_BUFFER_SIZE + 1);
-}
-
-void
-g_scanner_input_text (GScanner *scanner,
- const gchar *text,
- guint text_len)
-{
- g_return_if_fail (scanner != NULL);
- if (text_len)
- g_return_if_fail (text != NULL);
- else
- text = NULL;
-
- if (scanner->input_fd >= 0)
- g_scanner_sync_file_offset (scanner);
-
- scanner->token = G_TOKEN_NONE;
- scanner->value.v_int = 0;
- scanner->line = 1;
- scanner->position = 0;
- scanner->next_token = G_TOKEN_NONE;
-
- scanner->input_fd = -1;
- scanner->text = text;
- scanner->text_end = text + text_len;
-
- if (scanner->buffer)
- {
- g_free (scanner->buffer);
- scanner->buffer = NULL;
- }
-}
-
-static guchar
-g_scanner_peek_next_char (GScanner *scanner)
-{
- if (scanner->text < scanner->text_end)
- {
- return *scanner->text;
- }
- else if (scanner->input_fd >= 0)
- {
- gint count;
- gchar *buffer;
-
- buffer = scanner->buffer;
- do
- {
- count = read (scanner->input_fd, buffer, READ_BUFFER_SIZE);
- }
- while (count == -1 && (errno == EINTR || errno == EAGAIN));
-
- if (count < 1)
- {
- scanner->input_fd = -1;
-
- return 0;
- }
- else
- {
- scanner->text = buffer;
- scanner->text_end = buffer + count;
-
- return *buffer;
- }
- }
- else
- return 0;
-}
-
-void
-g_scanner_sync_file_offset (GScanner *scanner)
-{
- g_return_if_fail (scanner != NULL);
-
- /* for file input, rewind the filedescriptor to the current
- * buffer position and blow the file read ahead buffer. usefull for
- * third party uses of our filedescriptor, which hooks onto the current
- * scanning position.
- */
-
- if (scanner->input_fd >= 0 && scanner->text_end > scanner->text)
- {
- gint buffered;
-
- buffered = scanner->text_end - scanner->text;
- if (lseek (scanner->input_fd, - buffered, SEEK_CUR) >= 0)
- {
- /* we succeeded, blow our buffer's contents now */
- scanner->text = NULL;
- scanner->text_end = NULL;
- }
- else
- errno = 0;
- }
-}
-
-static guchar
-g_scanner_get_char (GScanner *scanner,
- guint *line_p,
- guint *position_p)
-{
- guchar fchar;
-
- if (scanner->text < scanner->text_end)
- fchar = *(scanner->text++);
- else if (scanner->input_fd >= 0)
- {
- gint count;
- gchar *buffer;
-
- buffer = scanner->buffer;
- do
- {
- count = read (scanner->input_fd, buffer, READ_BUFFER_SIZE);
- }
- while (count == -1 && (errno == EINTR || errno == EAGAIN));
-
- if (count < 1)
- {
- scanner->input_fd = -1;
- fchar = 0;
- }
- else
- {
- scanner->text = buffer + 1;
- scanner->text_end = buffer + count;
- fchar = *buffer;
- if (!fchar)
- {
- g_scanner_sync_file_offset (scanner);
- scanner->text_end = scanner->text;
- scanner->input_fd = -1;
- }
- }
- }
- else
- fchar = 0;
-
- if (fchar == '\n')
- {
- (*position_p) = 0;
- (*line_p)++;
- }
- else if (fchar)
- {
- (*position_p)++;
- }
-
- return fchar;
-}
-
-void
-g_scanner_unexp_token (GScanner *scanner,
- GTokenType expected_token,
- const gchar *identifier_spec,
- const gchar *symbol_spec,
- const gchar *symbol_name,
- const gchar *message,
- gint is_error)
-{
- gchar *token_string;
- guint token_string_len;
- gchar *expected_string;
- guint expected_string_len;
- gchar *message_prefix;
- gboolean print_unexp;
- void (*msg_handler) (GScanner*, const gchar*, ...);
-
- g_return_if_fail (scanner != NULL);
-
- if (is_error)
- msg_handler = g_scanner_error;
- else
- msg_handler = g_scanner_warn;
-
- if (!identifier_spec)
- identifier_spec = "identifier";
- if (!symbol_spec)
- symbol_spec = "symbol";
-
- token_string_len = 56;
- token_string = g_new (gchar, token_string_len + 1);
- expected_string_len = 64;
- expected_string = g_new (gchar, expected_string_len + 1);
- print_unexp = TRUE;
-
- switch (scanner->token)
- {
- case G_TOKEN_EOF:
- g_snprintf (token_string, token_string_len, "end of file");
- break;
-
- default:
- if (scanner->token >= 1 && scanner->token <= 255)
- {
- if ((scanner->token >= ' ' && scanner->token <= '~') ||
- strchr (scanner->config->cset_identifier_first, scanner->token) ||
- strchr (scanner->config->cset_identifier_nth, scanner->token))
- g_snprintf (token_string, expected_string_len, "character `%c'", scanner->token);
- else
- g_snprintf (token_string, expected_string_len, "character `\\%o'", scanner->token);
- break;
- }
- else if (!scanner->config->symbol_2_token)
- {
- g_snprintf (token_string, token_string_len, "(unknown) token <%d>", scanner->token);
- break;
- }
- /* fall through */
- case G_TOKEN_SYMBOL:
- if (expected_token == G_TOKEN_SYMBOL ||
- (scanner->config->symbol_2_token &&
- expected_token > G_TOKEN_LAST))
- print_unexp = FALSE;
- if (symbol_name)
- g_snprintf (token_string,
- token_string_len,
- "%s%s `%s'",
- print_unexp ? "" : "invalid ",
- symbol_spec,
- symbol_name);
- else
- g_snprintf (token_string,
- token_string_len,
- "%s%s",
- print_unexp ? "" : "invalid ",
- symbol_spec);
- break;
-
- case G_TOKEN_ERROR:
- print_unexp = FALSE;
- expected_token = G_TOKEN_NONE;
- switch (scanner->value.v_error)
- {
- case G_ERR_UNEXP_EOF:
- g_snprintf (token_string, token_string_len, "scanner: unexpected end of file");
- break;
-
- case G_ERR_UNEXP_EOF_IN_STRING:
- g_snprintf (token_string, token_string_len, "scanner: unterminated string constant");
- break;
-
- case G_ERR_UNEXP_EOF_IN_COMMENT:
- g_snprintf (token_string, token_string_len, "scanner: unterminated comment");
- break;
-
- case G_ERR_NON_DIGIT_IN_CONST:
- g_snprintf (token_string, token_string_len, "scanner: non digit in constant");
- break;
-
- case G_ERR_FLOAT_RADIX:
- g_snprintf (token_string, token_string_len, "scanner: invalid radix for floating constant");
- break;
-
- case G_ERR_FLOAT_MALFORMED:
- g_snprintf (token_string, token_string_len, "scanner: malformed floating constant");
- break;
-
- case G_ERR_DIGIT_RADIX:
- g_snprintf (token_string, token_string_len, "scanner: digit is beyond radix");
- break;
-
- case G_ERR_UNKNOWN:
- default:
- g_snprintf (token_string, token_string_len, "scanner: unknown error");
- break;
- }
- break;
-
- case G_TOKEN_CHAR:
- g_snprintf (token_string, token_string_len, "character `%c'", scanner->value.v_char);
- break;
-
- case G_TOKEN_IDENTIFIER:
- case G_TOKEN_IDENTIFIER_NULL:
- if (expected_token == G_TOKEN_IDENTIFIER ||
- expected_token == G_TOKEN_IDENTIFIER_NULL)
- print_unexp = FALSE;
- g_snprintf (token_string,
- token_string_len,
- "%s%s `%s'",
- print_unexp ? "" : "invalid ",
- identifier_spec,
- scanner->token == G_TOKEN_IDENTIFIER ? scanner->value.v_string : "null");
- break;
-
- case G_TOKEN_BINARY:
- case G_TOKEN_OCTAL:
- case G_TOKEN_INT:
- case G_TOKEN_HEX:
- g_snprintf (token_string, token_string_len, "number `%ld'", scanner->value.v_int);
- break;
-
- case G_TOKEN_FLOAT:
- g_snprintf (token_string, token_string_len, "number `%.3f'", scanner->value.v_float);
- break;
-
- case G_TOKEN_STRING:
- if (expected_token == G_TOKEN_STRING)
- print_unexp = FALSE;
- g_snprintf (token_string,
- token_string_len,
- "%s%sstring constant \"%s\"",
- print_unexp ? "" : "invalid ",
- scanner->value.v_string[0] == 0 ? "empty " : "",
- scanner->value.v_string);
- token_string[token_string_len - 2] = '"';
- token_string[token_string_len - 1] = 0;
- break;
-
- case G_TOKEN_COMMENT_SINGLE:
- case G_TOKEN_COMMENT_MULTI:
- g_snprintf (token_string, token_string_len, "comment");
- break;
-
- case G_TOKEN_NONE:
- /* somehow the user's parsing code is screwed, there isn't much
- * we can do about it.
- * Note, a common case to trigger this is
- * g_scanner_peek_next_token(); g_scanner_unexp_token();
- * without an intermediate g_scanner_get_next_token().
- */
- g_assert_not_reached ();
- break;
- }
-
-
- switch (expected_token)
- {
- gboolean need_valid;
-
- default:
- if (expected_token >= 1 && expected_token <= 255)
- {
- if ((expected_token >= ' ' && expected_token <= '~') ||
- strchr (scanner->config->cset_identifier_first, expected_token) ||
- strchr (scanner->config->cset_identifier_nth, expected_token))
- g_snprintf (expected_string, expected_string_len, "character `%c'", expected_token);
- else
- g_snprintf (expected_string, expected_string_len, "character `\\%o'", expected_token);
- break;
- }
- else if (!scanner->config->symbol_2_token)
- {
- g_snprintf (expected_string, expected_string_len, "(unknown) token <%d>", expected_token);
- break;
- }
- /* fall through */
- case G_TOKEN_SYMBOL:
- need_valid = (scanner->token == G_TOKEN_SYMBOL ||
- (scanner->config->symbol_2_token &&
- scanner->token > G_TOKEN_LAST));
- g_snprintf (expected_string,
- expected_string_len,
- "%s%s",
- need_valid ? "valid " : "",
- symbol_spec);
- /* FIXME: should we attempt to lookup the symbol_name for symbol_2_token? */
- break;
-
- case G_TOKEN_INT:
- g_snprintf (expected_string, expected_string_len, "number (integer)");
- break;
-
- case G_TOKEN_FLOAT:
- g_snprintf (expected_string, expected_string_len, "number (float)");
- break;
-
- case G_TOKEN_STRING:
- g_snprintf (expected_string,
- expected_string_len,
- "%sstring constant",
- scanner->token == G_TOKEN_STRING ? "valid " : "");
- break;
-
- case G_TOKEN_IDENTIFIER:
- case G_TOKEN_IDENTIFIER_NULL:
- g_snprintf (expected_string,
- expected_string_len,
- "%s%s",
- (scanner->token == G_TOKEN_IDENTIFIER_NULL ||
- scanner->token == G_TOKEN_IDENTIFIER ? "valid " : ""),
- identifier_spec);
- break;
-
- case G_TOKEN_EOF:
- g_snprintf (expected_string, expected_string_len, "end of file");
- break;
-
- case G_TOKEN_NONE:
- break;
- }
-
- if (message && message[0] != 0)
- message_prefix = " - ";
- else
- {
- message_prefix = "";
- message = "";
- }
-
- if (expected_token != G_TOKEN_NONE)
- {
- if (print_unexp)
- msg_handler (scanner,
- "unexpected %s, expected %s%s%s",
- token_string,
- expected_string,
- message_prefix,
- message);
- else
- msg_handler (scanner,
- "%s, expected %s%s%s",
- token_string,
- expected_string,
- message_prefix,
- message);
- }
- else
- {
- if (print_unexp)
- msg_handler (scanner,
- "unexpected %s%s%s",
- token_string,
- message_prefix,
- message);
- else
- msg_handler (scanner,
- "%s%s%s",
- token_string,
- message_prefix,
- message);
- }
-
- g_free (token_string);
- g_free (expected_string);
-}
-
-gint
-g_scanner_stat_mode (const gchar *filename)
-{
- struct stat *stat_buf;
- gint st_mode;
-
- stat_buf = g_new0 (struct stat, 1);
-#ifdef HAVE_LSTAT
- lstat (filename, stat_buf);
-#else
- stat (filename, stat_buf);
-#endif
- st_mode = stat_buf->st_mode;
-
- g_free (stat_buf);
-
- return st_mode;
-}
-
-static void
-g_scanner_get_token_i (GScanner *scanner,
- GTokenType *token_p,
- GTokenValue *value_p,
- guint *line_p,
- guint *position_p)
-{
- do
- {
- g_scanner_free_value (token_p, value_p);
- g_scanner_get_token_ll (scanner, token_p, value_p, line_p, position_p);
- }
- while (((*token_p > 0 && *token_p < 256) &&
- strchr (scanner->config->cset_skip_characters, *token_p)) ||
- (*token_p == G_TOKEN_CHAR &&
- strchr (scanner->config->cset_skip_characters, value_p->v_char)) ||
- (*token_p == G_TOKEN_COMMENT_MULTI &&
- scanner->config->skip_comment_multi) ||
- (*token_p == G_TOKEN_COMMENT_SINGLE &&
- scanner->config->skip_comment_single));
-
- switch (*token_p)
- {
- case G_TOKEN_IDENTIFIER:
- if (scanner->config->identifier_2_string)
- *token_p = G_TOKEN_STRING;
- break;
-
- case G_TOKEN_SYMBOL:
- if (scanner->config->symbol_2_token)
- *token_p = (GTokenType) value_p->v_symbol;
- break;
-
- case G_TOKEN_BINARY:
- case G_TOKEN_OCTAL:
- case G_TOKEN_HEX:
- if (scanner->config->numbers_2_int)
- *token_p = G_TOKEN_INT;
- break;
-
- default:
- break;
- }
-
- if (*token_p == G_TOKEN_INT &&
- scanner->config->int_2_float)
- {
- *token_p = G_TOKEN_FLOAT;
- value_p->v_float = value_p->v_int;
- }
-
- errno = 0;
-}
-
-static void
-g_scanner_get_token_ll (GScanner *scanner,
- GTokenType *token_p,
- GTokenValue *value_p,
- guint *line_p,
- guint *position_p)
-{
- GScannerConfig *config;
- GTokenType token;
- gboolean in_comment_multi;
- gboolean in_comment_single;
- gboolean in_string_sq;
- gboolean in_string_dq;
- GString *gstring;
- GTokenValue value;
- guchar ch;
-
- config = scanner->config;
- (*value_p).v_int = 0;
-
- if ((scanner->text >= scanner->text_end && scanner->input_fd < 0) ||
- scanner->token == G_TOKEN_EOF)
- {
- *token_p = G_TOKEN_EOF;
- return;
- }
-
- in_comment_multi = FALSE;
- in_comment_single = FALSE;
- in_string_sq = FALSE;
- in_string_dq = FALSE;
- gstring = NULL;
-
- do /* while (ch != 0) */
- {
- gboolean dotted_float = FALSE;
-
- ch = g_scanner_get_char (scanner, line_p, position_p);
-
- value.v_int = 0;
- token = G_TOKEN_NONE;
-
- /* this is *evil*, but needed ;(
- * we first check for identifier first character, because it
- * might interfere with other key chars like slashes or numbers
- */
- if (config->scan_identifier &&
- ch && strchr (config->cset_identifier_first, ch))
- goto identifier_precedence;
-
- switch (ch)
- {
- case 0:
- token = G_TOKEN_EOF;
- (*position_p)++;
- /* ch = 0; */
- break;
-
- case '/':
- if (!config->scan_comment_multi ||
- g_scanner_peek_next_char (scanner) != '*')
- goto default_case;
- g_scanner_get_char (scanner, line_p, position_p);
- token = G_TOKEN_COMMENT_MULTI;
- in_comment_multi = TRUE;
- gstring = g_string_new ("");
- while ((ch = g_scanner_get_char (scanner, line_p, position_p)) != 0)
- {
- if (ch == '*' && g_scanner_peek_next_char (scanner) == '/')
- {
- g_scanner_get_char (scanner, line_p, position_p);
- in_comment_multi = FALSE;
- break;
- }
- else
- gstring = g_string_append_c (gstring, ch);
- }
- ch = 0;
- break;
-
- case '\'':
- if (!config->scan_string_sq)
- goto default_case;
- token = G_TOKEN_STRING;
- in_string_sq = TRUE;
- gstring = g_string_new ("");
- while ((ch = g_scanner_get_char (scanner, line_p, position_p)) != 0)
- {
- if (ch == '\'')
- {
- in_string_sq = FALSE;
- break;
- }
- else
- gstring = g_string_append_c (gstring, ch);
- }
- ch = 0;
- break;
-
- case '"':
- if (!config->scan_string_dq)
- goto default_case;
- token = G_TOKEN_STRING;
- in_string_dq = TRUE;
- gstring = g_string_new ("");
- while ((ch = g_scanner_get_char (scanner, line_p, position_p)) != 0)
- {
- if (ch == '"')
- {
- in_string_dq = FALSE;
- break;
- }
- else
- {
- if (ch == '\\')
- {
- ch = g_scanner_get_char (scanner, line_p, position_p);
- switch (ch)
- {
- guint i;
- guint fchar;
-
- case 0:
- break;
-
- case '\\':
- gstring = g_string_append_c (gstring, '\\');
- break;
-
- case 'n':
- gstring = g_string_append_c (gstring, '\n');
- break;
-
- case 't':
- gstring = g_string_append_c (gstring, '\t');
- break;
-
- case 'r':
- gstring = g_string_append_c (gstring, '\r');
- break;
-
- case 'b':
- gstring = g_string_append_c (gstring, '\b');
- break;
-
- case 'f':
- gstring = g_string_append_c (gstring, '\f');
- break;
-
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- i = ch - '0';
- fchar = g_scanner_peek_next_char (scanner);
- if (fchar >= '0' && fchar <= '7')
- {
- ch = g_scanner_get_char (scanner, line_p, position_p);
- i = i * 8 + ch - '0';
- fchar = g_scanner_peek_next_char (scanner);
- if (fchar >= '0' && fchar <= '7')
- {
- ch = g_scanner_get_char (scanner, line_p, position_p);
- i = i * 8 + ch - '0';
- }
- }
- gstring = g_string_append_c (gstring, i);
- break;
-
- default:
- gstring = g_string_append_c (gstring, ch);
- break;
- }
- }
- else
- gstring = g_string_append_c (gstring, ch);
- }
- }
- ch = 0;
- break;
-
- case '.':
- if (!config->scan_float)
- goto default_case;
- token = G_TOKEN_FLOAT;
- dotted_float = TRUE;
- ch = g_scanner_get_char (scanner, line_p, position_p);
- goto number_parsing;
-
- case '$':
- if (!config->scan_hex_dollar)
- goto default_case;
- token = G_TOKEN_HEX;
- ch = g_scanner_get_char (scanner, line_p, position_p);
- goto number_parsing;
-
- case '0':
- if (config->scan_octal)
- token = G_TOKEN_OCTAL;
- else
- token = G_TOKEN_INT;
- ch = g_scanner_peek_next_char (scanner);
- if (config->scan_hex && (ch == 'x' || ch == 'X'))
- {
- token = G_TOKEN_HEX;
- g_scanner_get_char (scanner, line_p, position_p);
- ch = g_scanner_get_char (scanner, line_p, position_p);
- if (ch == 0)
- {
- token = G_TOKEN_ERROR;
- value.v_error = G_ERR_UNEXP_EOF;
- (*position_p)++;
- break;
- }
- if (g_scanner_char_2_num (ch, 16) < 0)
- {
- token = G_TOKEN_ERROR;
- value.v_error = G_ERR_DIGIT_RADIX;
- ch = 0;
- break;
- }
- }
- else if (config->scan_binary && (ch == 'b' || ch == 'B'))
- {
- token = G_TOKEN_BINARY;
- g_scanner_get_char (scanner, line_p, position_p);
- ch = g_scanner_get_char (scanner, line_p, position_p);
- if (ch == 0)
- {
- token = G_TOKEN_ERROR;
- value.v_error = G_ERR_UNEXP_EOF;
- (*position_p)++;
- break;
- }
- if (g_scanner_char_2_num (ch, 10) < 0)
- {
- token = G_TOKEN_ERROR;
- value.v_error = G_ERR_NON_DIGIT_IN_CONST;
- ch = 0;
- break;
- }
- }
- else
- ch = '0';
- /* fall through */
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- number_parsing:
- {
- gboolean in_number = TRUE;
- gchar *endptr;
-
- if (token == G_TOKEN_NONE)
- token = G_TOKEN_INT;
-
- gstring = g_string_new (dotted_float ? "0." : "");
- gstring = g_string_append_c (gstring, ch);
-
- do /* while (in_number) */
- {
- gboolean is_E;
-
- is_E = token == G_TOKEN_FLOAT && (ch == 'e' || ch == 'E');
-
- ch = g_scanner_peek_next_char (scanner);
-
- if (g_scanner_char_2_num (ch, 36) >= 0 ||
- (config->scan_float && ch == '.') ||
- (is_E && (ch == '+' || ch == '-')))
- {
- ch = g_scanner_get_char (scanner, line_p, position_p);
-
- switch (ch)
- {
- case '.':
- if (token != G_TOKEN_INT && token != G_TOKEN_OCTAL)
- {
- value.v_error = token == G_TOKEN_FLOAT ? G_ERR_FLOAT_MALFORMED : G_ERR_FLOAT_RADIX;
- token = G_TOKEN_ERROR;
- in_number = FALSE;
- }
- else
- {
- token = G_TOKEN_FLOAT;
- gstring = g_string_append_c (gstring, ch);
- }
- break;
-
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- gstring = g_string_append_c (gstring, ch);
- break;
-
- case '-':
- case '+':
- if (token != G_TOKEN_FLOAT)
- {
- token = G_TOKEN_ERROR;
- value.v_error = G_ERR_NON_DIGIT_IN_CONST;
- in_number = FALSE;
- }
- else
- gstring = g_string_append_c (gstring, ch);
- break;
-
- case 'e':
- case 'E':
- if ((token != G_TOKEN_HEX && !config->scan_float) ||
- (token != G_TOKEN_HEX &&
- token != G_TOKEN_OCTAL &&
- token != G_TOKEN_FLOAT &&
- token != G_TOKEN_INT))
- {
- token = G_TOKEN_ERROR;
- value.v_error = G_ERR_NON_DIGIT_IN_CONST;
- in_number = FALSE;
- }
- else
- {
- if (token != G_TOKEN_HEX)
- token = G_TOKEN_FLOAT;
- gstring = g_string_append_c (gstring, ch);
- }
- break;
-
- default:
- if (token != G_TOKEN_HEX)
- {
- token = G_TOKEN_ERROR;
- value.v_error = G_ERR_NON_DIGIT_IN_CONST;
- in_number = FALSE;
- }
- else
- gstring = g_string_append_c (gstring, ch);
- break;
- }
- }
- else
- in_number = FALSE;
- }
- while (in_number);
-
- endptr = NULL;
- switch (token)
- {
- case G_TOKEN_BINARY:
- value.v_binary = strtol (gstring->str, &endptr, 2);
- break;
-
- case G_TOKEN_OCTAL:
- value.v_octal = strtol (gstring->str, &endptr, 8);
- break;
-
- case G_TOKEN_INT:
- value.v_int = strtol (gstring->str, &endptr, 10);
- break;
-
- case G_TOKEN_FLOAT:
- value.v_float = g_strtod (gstring->str, &endptr);
- break;
-
- case G_TOKEN_HEX:
- value.v_hex = strtol (gstring->str, &endptr, 16);
- break;
-
- default:
- break;
- }
- if (endptr && *endptr)
- {
- token = G_TOKEN_ERROR;
- if (*endptr == 'e' || *endptr == 'E')
- value.v_error = G_ERR_NON_DIGIT_IN_CONST;
- else
- value.v_error = G_ERR_DIGIT_RADIX;
- }
- g_string_free (gstring, TRUE);
- gstring = NULL;
- ch = 0;
- } /* number_parsing:... */
- break;
-
- default:
- default_case:
- {
- if (config->cpair_comment_single &&
- ch == config->cpair_comment_single[0])
- {
- token = G_TOKEN_COMMENT_SINGLE;
- in_comment_single = TRUE;
- gstring = g_string_new ("");
- ch = g_scanner_get_char (scanner, line_p, position_p);
- while (ch != 0)
- {
- if (ch == config->cpair_comment_single[1])
- {
- in_comment_single = FALSE;
- ch = 0;
- break;
- }
-
- gstring = g_string_append_c (gstring, ch);
- ch = g_scanner_get_char (scanner, line_p, position_p);
- }
- }
- else if (config->scan_identifier && ch &&
- strchr (config->cset_identifier_first, ch))
- {
- identifier_precedence:
-
- if (config->cset_identifier_nth && ch &&
- strchr (config->cset_identifier_nth,
- g_scanner_peek_next_char (scanner)))
- {
- token = G_TOKEN_IDENTIFIER;
- gstring = g_string_new ("");
- gstring = g_string_append_c (gstring, ch);
- do
- {
- ch = g_scanner_get_char (scanner, line_p, position_p);
- gstring = g_string_append_c (gstring, ch);
- ch = g_scanner_peek_next_char (scanner);
- }
- while (ch && strchr (config->cset_identifier_nth, ch));
- ch = 0;
- }
- else if (config->scan_identifier_1char)
- {
- token = G_TOKEN_IDENTIFIER;
- value.v_identifier = g_new0 (gchar, 2);
- value.v_identifier[0] = ch;
- ch = 0;
- }
- }
- if (ch)
- {
- if (config->char_2_token)
- token = ch;
- else
- {
- token = G_TOKEN_CHAR;
- value.v_char = ch;
- }
- ch = 0;
- }
- } /* default_case:... */
- break;
- }
- g_assert (ch == 0 && token != G_TOKEN_NONE); /* paranoid */
- }
- while (ch != 0);
-
- if (in_comment_multi || in_comment_single ||
- in_string_sq || in_string_dq)
- {
- token = G_TOKEN_ERROR;
- if (gstring)
- {
- g_string_free (gstring, TRUE);
- gstring = NULL;
- }
- (*position_p)++;
- if (in_comment_multi || in_comment_single)
- value.v_error = G_ERR_UNEXP_EOF_IN_COMMENT;
- else /* (in_string_sq || in_string_dq) */
- value.v_error = G_ERR_UNEXP_EOF_IN_STRING;
- }
-
- if (gstring)
- {
- value.v_string = gstring->str;
- g_string_free (gstring, FALSE);
- gstring = NULL;
- }
-
- if (token == G_TOKEN_IDENTIFIER)
- {
- if (config->scan_symbols)
- {
- GScannerKey *key;
- guint scope_id;
-
- scope_id = scanner->scope_id;
- key = g_scanner_lookup_internal (scanner, scope_id, value.v_identifier);
- if (!key && scope_id && scanner->config->scope_0_fallback)
- key = g_scanner_lookup_internal (scanner, 0, value.v_identifier);
-
- if (key)
- {
- g_free (value.v_identifier);
- token = G_TOKEN_SYMBOL;
- value.v_symbol = key->value;
- }
- }
-
- if (token == G_TOKEN_IDENTIFIER &&
- config->scan_identifier_NULL &&
- strlen (value.v_identifier) == 4)
- {
- gchar *null_upper = "NULL";
- gchar *null_lower = "null";
-
- if (scanner->config->case_sensitive)
- {
- if (value.v_identifier[0] == null_upper[0] &&
- value.v_identifier[1] == null_upper[1] &&
- value.v_identifier[2] == null_upper[2] &&
- value.v_identifier[3] == null_upper[3])
- token = G_TOKEN_IDENTIFIER_NULL;
- }
- else
- {
- if ((value.v_identifier[0] == null_upper[0] ||
- value.v_identifier[0] == null_lower[0]) &&
- (value.v_identifier[1] == null_upper[1] ||
- value.v_identifier[1] == null_lower[1]) &&
- (value.v_identifier[2] == null_upper[2] ||
- value.v_identifier[2] == null_lower[2]) &&
- (value.v_identifier[3] == null_upper[3] ||
- value.v_identifier[3] == null_lower[3]))
- token = G_TOKEN_IDENTIFIER_NULL;
- }
- }
- }
-
- *token_p = token;
- *value_p = value;
-}
diff --git a/glib/gslist.c b/glib/gslist.c
deleted file mode 100644
index eed000701..000000000
--- a/glib/gslist.c
+++ /dev/null
@@ -1,595 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "glib.h"
-
-
-struct _GAllocator /* from gmem.c */
-{
- gchar *name;
- guint16 n_preallocs;
- guint is_unused : 1;
- guint type : 4;
- GAllocator *last;
- GMemChunk *mem_chunk;
- GSList *free_lists; /* implementation specific */
-};
-
-G_LOCK_DEFINE_STATIC (current_allocator);
-static GAllocator *current_allocator = NULL;
-
-/* HOLDS: current_allocator_lock */
-static void
-g_slist_validate_allocator (GAllocator *allocator)
-{
- g_return_if_fail (allocator != NULL);
- g_return_if_fail (allocator->is_unused == TRUE);
-
- if (allocator->type != G_ALLOCATOR_SLIST)
- {
- allocator->type = G_ALLOCATOR_SLIST;
- if (allocator->mem_chunk)
- {
- g_mem_chunk_destroy (allocator->mem_chunk);
- allocator->mem_chunk = NULL;
- }
- }
-
- if (!allocator->mem_chunk)
- {
- allocator->mem_chunk = g_mem_chunk_new (allocator->name,
- sizeof (GSList),
- sizeof (GSList) * allocator->n_preallocs,
- G_ALLOC_ONLY);
- allocator->free_lists = NULL;
- }
-
- allocator->is_unused = FALSE;
-}
-
-void
-g_slist_push_allocator (GAllocator *allocator)
-{
- G_LOCK (current_allocator);
- g_slist_validate_allocator (allocator);
- allocator->last = current_allocator;
- current_allocator = allocator;
- G_UNLOCK (current_allocator);
-}
-
-void
-g_slist_pop_allocator (void)
-{
- G_LOCK (current_allocator);
- if (current_allocator)
- {
- GAllocator *allocator;
-
- allocator = current_allocator;
- current_allocator = allocator->last;
- allocator->last = NULL;
- allocator->is_unused = TRUE;
- }
- G_UNLOCK (current_allocator);
-}
-
-GSList*
-g_slist_alloc (void)
-{
- GSList *list;
-
- G_LOCK (current_allocator);
- if (!current_allocator)
- {
- GAllocator *allocator = g_allocator_new ("GLib default GSList allocator",
- 128);
- g_slist_validate_allocator (allocator);
- allocator->last = NULL;
- current_allocator = allocator;
- }
- if (!current_allocator->free_lists)
- {
- list = g_chunk_new (GSList, current_allocator->mem_chunk);
- list->data = NULL;
- }
- else
- {
- if (current_allocator->free_lists->data)
- {
- list = current_allocator->free_lists->data;
- current_allocator->free_lists->data = list->next;
- list->data = NULL;
- }
- else
- {
- list = current_allocator->free_lists;
- current_allocator->free_lists = list->next;
- }
- }
- G_UNLOCK (current_allocator);
-
- list->next = NULL;
-
- return list;
-}
-
-void
-g_slist_free (GSList *list)
-{
- if (list)
- {
- list->data = list->next;
- G_LOCK (current_allocator);
- list->next = current_allocator->free_lists;
- current_allocator->free_lists = list;
- G_UNLOCK (current_allocator);
- }
-}
-
-void
-g_slist_free_1 (GSList *list)
-{
- if (list)
- {
- list->data = NULL;
- G_LOCK (current_allocator);
- list->next = current_allocator->free_lists;
- current_allocator->free_lists = list;
- G_UNLOCK (current_allocator);
- }
-}
-
-GSList*
-g_slist_append (GSList *list,
- gpointer data)
-{
- GSList *new_list;
- GSList *last;
-
- new_list = g_slist_alloc ();
- new_list->data = data;
-
- if (list)
- {
- last = g_slist_last (list);
- /* g_assert (last != NULL); */
- last->next = new_list;
-
- return list;
- }
- else
- return new_list;
-}
-
-GSList*
-g_slist_prepend (GSList *list,
- gpointer data)
-{
- GSList *new_list;
-
- new_list = g_slist_alloc ();
- new_list->data = data;
- new_list->next = list;
-
- return new_list;
-}
-
-GSList*
-g_slist_insert (GSList *list,
- gpointer data,
- gint position)
-{
- GSList *prev_list;
- GSList *tmp_list;
- GSList *new_list;
-
- if (position < 0)
- return g_slist_append (list, data);
- else if (position == 0)
- return g_slist_prepend (list, data);
-
- new_list = g_slist_alloc ();
- new_list->data = data;
-
- if (!list)
- return new_list;
-
- prev_list = NULL;
- tmp_list = list;
-
- while ((position-- > 0) && tmp_list)
- {
- prev_list = tmp_list;
- tmp_list = tmp_list->next;
- }
-
- if (prev_list)
- {
- new_list->next = prev_list->next;
- prev_list->next = new_list;
- }
- else
- {
- new_list->next = list;
- list = new_list;
- }
-
- return list;
-}
-
-GSList *
-g_slist_concat (GSList *list1, GSList *list2)
-{
- if (list2)
- {
- if (list1)
- g_slist_last (list1)->next = list2;
- else
- list1 = list2;
- }
-
- return list1;
-}
-
-GSList*
-g_slist_remove (GSList *list,
- gpointer data)
-{
- GSList *tmp;
- GSList *prev;
-
- prev = NULL;
- tmp = list;
-
- while (tmp)
- {
- if (tmp->data == data)
- {
- if (prev)
- prev->next = tmp->next;
- if (list == tmp)
- list = list->next;
-
- tmp->next = NULL;
- g_slist_free (tmp);
-
- break;
- }
-
- prev = tmp;
- tmp = tmp->next;
- }
-
- return list;
-}
-
-GSList*
-g_slist_remove_link (GSList *list,
- GSList *link)
-{
- GSList *tmp;
- GSList *prev;
-
- prev = NULL;
- tmp = list;
-
- while (tmp)
- {
- if (tmp == link)
- {
- if (prev)
- prev->next = tmp->next;
- if (list == tmp)
- list = list->next;
-
- tmp->next = NULL;
- break;
- }
-
- prev = tmp;
- tmp = tmp->next;
- }
-
- return list;
-}
-
-GSList*
-g_slist_copy (GSList *list)
-{
- GSList *new_list = NULL;
-
- if (list)
- {
- GSList *last;
-
- new_list = g_slist_alloc ();
- new_list->data = list->data;
- last = new_list;
- list = list->next;
- while (list)
- {
- last->next = g_slist_alloc ();
- last = last->next;
- last->data = list->data;
- list = list->next;
- }
- }
-
- return new_list;
-}
-
-GSList*
-g_slist_reverse (GSList *list)
-{
- GSList *prev = NULL;
-
- while (list)
- {
- GSList *next = list->next;
-
- list->next = prev;
-
- prev = list;
- list = next;
- }
-
- return prev;
-}
-
-GSList*
-g_slist_nth (GSList *list,
- guint n)
-{
- while ((n-- > 0) && list)
- list = list->next;
-
- return list;
-}
-
-gpointer
-g_slist_nth_data (GSList *list,
- guint n)
-{
- while ((n-- > 0) && list)
- list = list->next;
-
- return list ? list->data : NULL;
-}
-
-GSList*
-g_slist_find (GSList *list,
- gpointer data)
-{
- while (list)
- {
- if (list->data == data)
- break;
- list = list->next;
- }
-
- return list;
-}
-
-GSList*
-g_slist_find_custom (GSList *list,
- gpointer data,
- GCompareFunc func)
-{
- g_return_val_if_fail (func != NULL, list);
-
- while (list)
- {
- if (! func (list->data, data))
- return list;
- list = list->next;
- }
-
- return NULL;
-}
-
-gint
-g_slist_position (GSList *list,
- GSList *link)
-{
- gint i;
-
- i = 0;
- while (list)
- {
- if (list == link)
- return i;
- i++;
- list = list->next;
- }
-
- return -1;
-}
-
-gint
-g_slist_index (GSList *list,
- gpointer data)
-{
- gint i;
-
- i = 0;
- while (list)
- {
- if (list->data == data)
- return i;
- i++;
- list = list->next;
- }
-
- return -1;
-}
-
-GSList*
-g_slist_last (GSList *list)
-{
- if (list)
- {
- while (list->next)
- list = list->next;
- }
-
- return list;
-}
-
-guint
-g_slist_length (GSList *list)
-{
- guint length;
-
- length = 0;
- while (list)
- {
- length++;
- list = list->next;
- }
-
- return length;
-}
-
-void
-g_slist_foreach (GSList *list,
- GFunc func,
- gpointer user_data)
-{
- while (list)
- {
- (*func) (list->data, user_data);
- list = list->next;
- }
-}
-
-GSList*
-g_slist_insert_sorted (GSList *list,
- gpointer data,
- GCompareFunc func)
-{
- GSList *tmp_list = list;
- GSList *prev_list = NULL;
- GSList *new_list;
- gint cmp;
-
- g_return_val_if_fail (func != NULL, list);
-
- if (!list)
- {
- new_list = g_slist_alloc();
- new_list->data = data;
- return new_list;
- }
-
- cmp = (*func) (data, tmp_list->data);
-
- while ((tmp_list->next) && (cmp > 0))
- {
- prev_list = tmp_list;
- tmp_list = tmp_list->next;
- cmp = (*func) (data, tmp_list->data);
- }
-
- new_list = g_slist_alloc();
- new_list->data = data;
-
- if ((!tmp_list->next) && (cmp > 0))
- {
- tmp_list->next = new_list;
- return list;
- }
-
- if (prev_list)
- {
- prev_list->next = new_list;
- new_list->next = tmp_list;
- return list;
- }
- else
- {
- new_list->next = list;
- return new_list;
- }
-}
-
-static GSList*
-g_slist_sort_merge (GSList *l1,
- GSList *l2,
- GCompareFunc compare_func)
-{
- GSList list, *l;
-
- l=&list;
-
- while (l1 && l2)
- {
- if (compare_func(l1->data,l2->data) < 0)
- {
- l=l->next=l1;
- l1=l1->next;
- }
- else
- {
- l=l->next=l2;
- l2=l2->next;
- }
- }
- l->next= l1 ? l1 : l2;
-
- return list.next;
-}
-
-GSList*
-g_slist_sort (GSList *list,
- GCompareFunc compare_func)
-{
- GSList *l1, *l2;
-
- if (!list)
- return NULL;
- if (!list->next)
- return list;
-
- l1 = list;
- l2 = list->next;
-
- while ((l2 = l2->next) != NULL)
- {
- if ((l2 = l2->next) == NULL)
- break;
- l1=l1->next;
- }
- l2 = l1->next;
- l1->next = NULL;
-
- return g_slist_sort_merge (g_slist_sort (list, compare_func),
- g_slist_sort (l2, compare_func),
- compare_func);
-}
diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c
deleted file mode 100644
index feb457275..000000000
--- a/glib/gstrfuncs.c
+++ /dev/null
@@ -1,1496 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <locale.h>
-#include <errno.h>
-#include <ctype.h> /* For tolower() */
-#if !defined (HAVE_STRSIGNAL) || !defined(NO_SYS_SIGLIST_DECL)
-#include <signal.h>
-#endif
-#include "glib.h"
-/* do not include <unistd.h> in this place since it
- * inteferes with g_strsignal() on some OSes
- */
-
-typedef union _GDoubleIEEE754 GDoubleIEEE754;
-#define G_IEEE754_DOUBLE_BIAS (1023)
-/* multiply with base2 exponent to get base10 exponent (nomal numbers) */
-#define G_LOG_2_BASE_10 (0.30102999566398119521)
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-union _GDoubleIEEE754
-{
- gdouble v_double;
- struct {
- guint mantissa_low : 32;
- guint mantissa_high : 20;
- guint biased_exponent : 11;
- guint sign : 1;
- } mpn;
-};
-#elif G_BYTE_ORDER == G_BIG_ENDIAN
-union _GDoubleIEEE754
-{
- gdouble v_double;
- struct {
- guint sign : 1;
- guint biased_exponent : 11;
- guint mantissa_high : 20;
- guint mantissa_low : 32;
- } mpn;
-};
-#else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
-#error unknown ENDIAN type
-#endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
-
-gchar*
-g_strdup (const gchar *str)
-{
- gchar *new_str;
-
- if (str)
- {
- new_str = g_new (char, strlen (str) + 1);
- strcpy (new_str, str);
- }
- else
- new_str = NULL;
-
- return new_str;
-}
-
-gpointer
-g_memdup (gconstpointer mem,
- guint byte_size)
-{
- gpointer new_mem;
-
- if (mem)
- {
- new_mem = g_malloc (byte_size);
- memcpy (new_mem, mem, byte_size);
- }
- else
- new_mem = NULL;
-
- return new_mem;
-}
-
-gchar*
-g_strndup (const gchar *str,
- guint n)
-{
- gchar *new_str;
-
- if (str)
- {
- new_str = g_new (gchar, n + 1);
- strncpy (new_str, str, n);
- new_str[n] = '\0';
- }
- else
- new_str = NULL;
-
- return new_str;
-}
-
-gchar*
-g_strnfill (guint length,
- gchar fill_char)
-{
- register gchar *str, *s, *end;
-
- str = g_new (gchar, length + 1);
- s = str;
- end = str + length;
- while (s < end)
- *(s++) = fill_char;
- *s = 0;
-
- return str;
-}
-
-gchar*
-g_strdup_vprintf (const gchar *format,
- va_list args1)
-{
- gchar *buffer;
- va_list args2;
-
- G_VA_COPY (args2, args1);
-
- buffer = g_new (gchar, g_printf_string_upper_bound (format, args1));
-
- vsprintf (buffer, format, args2);
- va_end (args2);
-
- return buffer;
-}
-
-gchar*
-g_strdup_printf (const gchar *format,
- ...)
-{
- gchar *buffer;
- va_list args;
-
- va_start (args, format);
- buffer = g_strdup_vprintf (format, args);
- va_end (args);
-
- return buffer;
-}
-
-gchar*
-g_strconcat (const gchar *string1, ...)
-{
- guint l;
- va_list args;
- gchar *s;
- gchar *concat;
-
- g_return_val_if_fail (string1 != NULL, NULL);
-
- l = 1 + strlen (string1);
- va_start (args, string1);
- s = va_arg (args, gchar*);
- while (s)
- {
- l += strlen (s);
- s = va_arg (args, gchar*);
- }
- va_end (args);
-
- concat = g_new (gchar, l);
- concat[0] = 0;
-
- strcat (concat, string1);
- va_start (args, string1);
- s = va_arg (args, gchar*);
- while (s)
- {
- strcat (concat, s);
- s = va_arg (args, gchar*);
- }
- va_end (args);
-
- return concat;
-}
-
-gdouble
-g_strtod (const gchar *nptr,
- gchar **endptr)
-{
- gchar *fail_pos_1;
- gchar *fail_pos_2;
- gdouble val_1;
- gdouble val_2 = 0;
-
- g_return_val_if_fail (nptr != NULL, 0);
-
- fail_pos_1 = NULL;
- fail_pos_2 = NULL;
-
- val_1 = strtod (nptr, &fail_pos_1);
-
- if (fail_pos_1 && fail_pos_1[0] != 0)
- {
- gchar *old_locale;
-
- old_locale = g_strdup (setlocale (LC_NUMERIC, NULL));
- setlocale (LC_NUMERIC, "C");
- val_2 = strtod (nptr, &fail_pos_2);
- setlocale (LC_NUMERIC, old_locale);
- g_free (old_locale);
- }
-
- if (!fail_pos_1 || fail_pos_1[0] == 0 || fail_pos_1 >= fail_pos_2)
- {
- if (endptr)
- *endptr = fail_pos_1;
- return val_1;
- }
- else
- {
- if (endptr)
- *endptr = fail_pos_2;
- return val_2;
- }
-}
-
-gchar*
-g_strerror (gint errnum)
-{
- static GStaticPrivate msg_private = G_STATIC_PRIVATE_INIT;
- char *msg;
-
-#ifdef HAVE_STRERROR
- return strerror (errnum);
-#elif NO_SYS_ERRLIST
- switch (errnum)
- {
-#ifdef E2BIG
- case E2BIG: return "argument list too long";
-#endif
-#ifdef EACCES
- case EACCES: return "permission denied";
-#endif
-#ifdef EADDRINUSE
- case EADDRINUSE: return "address already in use";
-#endif
-#ifdef EADDRNOTAVAIL
- case EADDRNOTAVAIL: return "can't assign requested address";
-#endif
-#ifdef EADV
- case EADV: return "advertise error";
-#endif
-#ifdef EAFNOSUPPORT
- case EAFNOSUPPORT: return "address family not supported by protocol family";
-#endif
-#ifdef EAGAIN
- case EAGAIN: return "try again";
-#endif
-#ifdef EALIGN
- case EALIGN: return "EALIGN";
-#endif
-#ifdef EALREADY
- case EALREADY: return "operation already in progress";
-#endif
-#ifdef EBADE
- case EBADE: return "bad exchange descriptor";
-#endif
-#ifdef EBADF
- case EBADF: return "bad file number";
-#endif
-#ifdef EBADFD
- case EBADFD: return "file descriptor in bad state";
-#endif
-#ifdef EBADMSG
- case EBADMSG: return "not a data message";
-#endif
-#ifdef EBADR
- case EBADR: return "bad request descriptor";
-#endif
-#ifdef EBADRPC
- case EBADRPC: return "RPC structure is bad";
-#endif
-#ifdef EBADRQC
- case EBADRQC: return "bad request code";
-#endif
-#ifdef EBADSLT
- case EBADSLT: return "invalid slot";
-#endif
-#ifdef EBFONT
- case EBFONT: return "bad font file format";
-#endif
-#ifdef EBUSY
- case EBUSY: return "mount device busy";
-#endif
-#ifdef ECHILD
- case ECHILD: return "no children";
-#endif
-#ifdef ECHRNG
- case ECHRNG: return "channel number out of range";
-#endif
-#ifdef ECOMM
- case ECOMM: return "communication error on send";
-#endif
-#ifdef ECONNABORTED
- case ECONNABORTED: return "software caused connection abort";
-#endif
-#ifdef ECONNREFUSED
- case ECONNREFUSED: return "connection refused";
-#endif
-#ifdef ECONNRESET
- case ECONNRESET: return "connection reset by peer";
-#endif
-#if defined(EDEADLK) && (!defined(EWOULDBLOCK) || (EDEADLK != EWOULDBLOCK))
- case EDEADLK: return "resource deadlock avoided";
-#endif
-#ifdef EDEADLOCK
- case EDEADLOCK: return "resource deadlock avoided";
-#endif
-#ifdef EDESTADDRREQ
- case EDESTADDRREQ: return "destination address required";
-#endif
-#ifdef EDIRTY
- case EDIRTY: return "mounting a dirty fs w/o force";
-#endif
-#ifdef EDOM
- case EDOM: return "math argument out of range";
-#endif
-#ifdef EDOTDOT
- case EDOTDOT: return "cross mount point";
-#endif
-#ifdef EDQUOT
- case EDQUOT: return "disk quota exceeded";
-#endif
-#ifdef EDUPPKG
- case EDUPPKG: return "duplicate package name";
-#endif
-#ifdef EEXIST
- case EEXIST: return "file already exists";
-#endif
-#ifdef EFAULT
- case EFAULT: return "bad address in system call argument";
-#endif
-#ifdef EFBIG
- case EFBIG: return "file too large";
-#endif
-#ifdef EHOSTDOWN
- case EHOSTDOWN: return "host is down";
-#endif
-#ifdef EHOSTUNREACH
- case EHOSTUNREACH: return "host is unreachable";
-#endif
-#ifdef EIDRM
- case EIDRM: return "identifier removed";
-#endif
-#ifdef EINIT
- case EINIT: return "initialization error";
-#endif
-#ifdef EINPROGRESS
- case EINPROGRESS: return "operation now in progress";
-#endif
-#ifdef EINTR
- case EINTR: return "interrupted system call";
-#endif
-#ifdef EINVAL
- case EINVAL: return "invalid argument";
-#endif
-#ifdef EIO
- case EIO: return "I/O error";
-#endif
-#ifdef EISCONN
- case EISCONN: return "socket is already connected";
-#endif
-#ifdef EISDIR
- case EISDIR: return "illegal operation on a directory";
-#endif
-#ifdef EISNAME
- case EISNAM: return "is a name file";
-#endif
-#ifdef ELBIN
- case ELBIN: return "ELBIN";
-#endif
-#ifdef EL2HLT
- case EL2HLT: return "level 2 halted";
-#endif
-#ifdef EL2NSYNC
- case EL2NSYNC: return "level 2 not synchronized";
-#endif
-#ifdef EL3HLT
- case EL3HLT: return "level 3 halted";
-#endif
-#ifdef EL3RST
- case EL3RST: return "level 3 reset";
-#endif
-#ifdef ELIBACC
- case ELIBACC: return "can not access a needed shared library";
-#endif
-#ifdef ELIBBAD
- case ELIBBAD: return "accessing a corrupted shared library";
-#endif
-#ifdef ELIBEXEC
- case ELIBEXEC: return "can not exec a shared library directly";
-#endif
-#ifdef ELIBMAX
- case ELIBMAX: return "attempting to link in more shared libraries than system limit";
-#endif
-#ifdef ELIBSCN
- case ELIBSCN: return ".lib section in a.out corrupted";
-#endif
-#ifdef ELNRNG
- case ELNRNG: return "link number out of range";
-#endif
-#ifdef ELOOP
- case ELOOP: return "too many levels of symbolic links";
-#endif
-#ifdef EMFILE
- case EMFILE: return "too many open files";
-#endif
-#ifdef EMLINK
- case EMLINK: return "too many links";
-#endif
-#ifdef EMSGSIZE
- case EMSGSIZE: return "message too long";
-#endif
-#ifdef EMULTIHOP
- case EMULTIHOP: return "multihop attempted";
-#endif
-#ifdef ENAMETOOLONG
- case ENAMETOOLONG: return "file name too long";
-#endif
-#ifdef ENAVAIL
- case ENAVAIL: return "not available";
-#endif
-#ifdef ENET
- case ENET: return "ENET";
-#endif
-#ifdef ENETDOWN
- case ENETDOWN: return "network is down";
-#endif
-#ifdef ENETRESET
- case ENETRESET: return "network dropped connection on reset";
-#endif
-#ifdef ENETUNREACH
- case ENETUNREACH: return "network is unreachable";
-#endif
-#ifdef ENFILE
- case ENFILE: return "file table overflow";
-#endif
-#ifdef ENOANO
- case ENOANO: return "anode table overflow";
-#endif
-#if defined(ENOBUFS) && (!defined(ENOSR) || (ENOBUFS != ENOSR))
- case ENOBUFS: return "no buffer space available";
-#endif
-#ifdef ENOCSI
- case ENOCSI: return "no CSI structure available";
-#endif
-#ifdef ENODATA
- case ENODATA: return "no data available";
-#endif
-#ifdef ENODEV
- case ENODEV: return "no such device";
-#endif
-#ifdef ENOENT
- case ENOENT: return "no such file or directory";
-#endif
-#ifdef ENOEXEC
- case ENOEXEC: return "exec format error";
-#endif
-#ifdef ENOLCK
- case ENOLCK: return "no locks available";
-#endif
-#ifdef ENOLINK
- case ENOLINK: return "link has be severed";
-#endif
-#ifdef ENOMEM
- case ENOMEM: return "not enough memory";
-#endif
-#ifdef ENOMSG
- case ENOMSG: return "no message of desired type";
-#endif
-#ifdef ENONET
- case ENONET: return "machine is not on the network";
-#endif
-#ifdef ENOPKG
- case ENOPKG: return "package not installed";
-#endif
-#ifdef ENOPROTOOPT
- case ENOPROTOOPT: return "bad proocol option";
-#endif
-#ifdef ENOSPC
- case ENOSPC: return "no space left on device";
-#endif
-#ifdef ENOSR
- case ENOSR: return "out of stream resources";
-#endif
-#ifdef ENOSTR
- case ENOSTR: return "not a stream device";
-#endif
-#ifdef ENOSYM
- case ENOSYM: return "unresolved symbol name";
-#endif
-#ifdef ENOSYS
- case ENOSYS: return "function not implemented";
-#endif
-#ifdef ENOTBLK
- case ENOTBLK: return "block device required";
-#endif
-#ifdef ENOTCONN
- case ENOTCONN: return "socket is not connected";
-#endif
-#ifdef ENOTDIR
- case ENOTDIR: return "not a directory";
-#endif
-#ifdef ENOTEMPTY
- case ENOTEMPTY: return "directory not empty";
-#endif
-#ifdef ENOTNAM
- case ENOTNAM: return "not a name file";
-#endif
-#ifdef ENOTSOCK
- case ENOTSOCK: return "socket operation on non-socket";
-#endif
-#ifdef ENOTTY
- case ENOTTY: return "inappropriate device for ioctl";
-#endif
-#ifdef ENOTUNIQ
- case ENOTUNIQ: return "name not unique on network";
-#endif
-#ifdef ENXIO
- case ENXIO: return "no such device or address";
-#endif
-#ifdef EOPNOTSUPP
- case EOPNOTSUPP: return "operation not supported on socket";
-#endif
-#ifdef EPERM
- case EPERM: return "not owner";
-#endif
-#ifdef EPFNOSUPPORT
- case EPFNOSUPPORT: return "protocol family not supported";
-#endif
-#ifdef EPIPE
- case EPIPE: return "broken pipe";
-#endif
-#ifdef EPROCLIM
- case EPROCLIM: return "too many processes";
-#endif
-#ifdef EPROCUNAVAIL
- case EPROCUNAVAIL: return "bad procedure for program";
-#endif
-#ifdef EPROGMISMATCH
- case EPROGMISMATCH: return "program version wrong";
-#endif
-#ifdef EPROGUNAVAIL
- case EPROGUNAVAIL: return "RPC program not available";
-#endif
-#ifdef EPROTO
- case EPROTO: return "protocol error";
-#endif
-#ifdef EPROTONOSUPPORT
- case EPROTONOSUPPORT: return "protocol not suppored";
-#endif
-#ifdef EPROTOTYPE
- case EPROTOTYPE: return "protocol wrong type for socket";
-#endif
-#ifdef ERANGE
- case ERANGE: return "math result unrepresentable";
-#endif
-#if defined(EREFUSED) && (!defined(ECONNREFUSED) || (EREFUSED != ECONNREFUSED))
- case EREFUSED: return "EREFUSED";
-#endif
-#ifdef EREMCHG
- case EREMCHG: return "remote address changed";
-#endif
-#ifdef EREMDEV
- case EREMDEV: return "remote device";
-#endif
-#ifdef EREMOTE
- case EREMOTE: return "pathname hit remote file system";
-#endif
-#ifdef EREMOTEIO
- case EREMOTEIO: return "remote i/o error";
-#endif
-#ifdef EREMOTERELEASE
- case EREMOTERELEASE: return "EREMOTERELEASE";
-#endif
-#ifdef EROFS
- case EROFS: return "read-only file system";
-#endif
-#ifdef ERPCMISMATCH
- case ERPCMISMATCH: return "RPC version is wrong";
-#endif
-#ifdef ERREMOTE
- case ERREMOTE: return "object is remote";
-#endif
-#ifdef ESHUTDOWN
- case ESHUTDOWN: return "can't send afer socket shutdown";
-#endif
-#ifdef ESOCKTNOSUPPORT
- case ESOCKTNOSUPPORT: return "socket type not supported";
-#endif
-#ifdef ESPIPE
- case ESPIPE: return "invalid seek";
-#endif
-#ifdef ESRCH
- case ESRCH: return "no such process";
-#endif
-#ifdef ESRMNT
- case ESRMNT: return "srmount error";
-#endif
-#ifdef ESTALE
- case ESTALE: return "stale remote file handle";
-#endif
-#ifdef ESUCCESS
- case ESUCCESS: return "Error 0";
-#endif
-#ifdef ETIME
- case ETIME: return "timer expired";
-#endif
-#ifdef ETIMEDOUT
- case ETIMEDOUT: return "connection timed out";
-#endif
-#ifdef ETOOMANYREFS
- case ETOOMANYREFS: return "too many references: can't splice";
-#endif
-#ifdef ETXTBSY
- case ETXTBSY: return "text file or pseudo-device busy";
-#endif
-#ifdef EUCLEAN
- case EUCLEAN: return "structure needs cleaning";
-#endif
-#ifdef EUNATCH
- case EUNATCH: return "protocol driver not attached";
-#endif
-#ifdef EUSERS
- case EUSERS: return "too many users";
-#endif
-#ifdef EVERSION
- case EVERSION: return "version mismatch";
-#endif
-#if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
- case EWOULDBLOCK: return "operation would block";
-#endif
-#ifdef EXDEV
- case EXDEV: return "cross-domain link";
-#endif
-#ifdef EXFULL
- case EXFULL: return "message tables full";
-#endif
- }
-#else /* NO_SYS_ERRLIST */
- extern int sys_nerr;
- extern char *sys_errlist[];
-
- if ((errnum > 0) && (errnum <= sys_nerr))
- return sys_errlist [errnum];
-#endif /* NO_SYS_ERRLIST */
-
- msg = g_static_private_get (&msg_private);
- if (!msg)
- {
- msg = g_new (gchar, 64);
- g_static_private_set (&msg_private, msg, g_free);
- }
-
- sprintf (msg, "unknown error (%d)", errnum);
-
- return msg;
-}
-
-gchar*
-g_strsignal (gint signum)
-{
- static GStaticPrivate msg_private = G_STATIC_PRIVATE_INIT;
- char *msg;
-
-#ifdef HAVE_STRSIGNAL
- extern char *strsignal (int sig);
- return strsignal (signum);
-#elif NO_SYS_SIGLIST
- switch (signum)
- {
-#ifdef SIGHUP
- case SIGHUP: return "Hangup";
-#endif
-#ifdef SIGINT
- case SIGINT: return "Interrupt";
-#endif
-#ifdef SIGQUIT
- case SIGQUIT: return "Quit";
-#endif
-#ifdef SIGILL
- case SIGILL: return "Illegal instruction";
-#endif
-#ifdef SIGTRAP
- case SIGTRAP: return "Trace/breakpoint trap";
-#endif
-#ifdef SIGABRT
- case SIGABRT: return "IOT trap/Abort";
-#endif
-#ifdef SIGBUS
- case SIGBUS: return "Bus error";
-#endif
-#ifdef SIGFPE
- case SIGFPE: return "Floating point exception";
-#endif
-#ifdef SIGKILL
- case SIGKILL: return "Killed";
-#endif
-#ifdef SIGUSR1
- case SIGUSR1: return "User defined signal 1";
-#endif
-#ifdef SIGSEGV
- case SIGSEGV: return "Segmentation fault";
-#endif
-#ifdef SIGUSR2
- case SIGUSR2: return "User defined signal 2";
-#endif
-#ifdef SIGPIPE
- case SIGPIPE: return "Broken pipe";
-#endif
-#ifdef SIGALRM
- case SIGALRM: return "Alarm clock";
-#endif
-#ifdef SIGTERM
- case SIGTERM: return "Terminated";
-#endif
-#ifdef SIGSTKFLT
- case SIGSTKFLT: return "Stack fault";
-#endif
-#ifdef SIGCHLD
- case SIGCHLD: return "Child exited";
-#endif
-#ifdef SIGCONT
- case SIGCONT: return "Continued";
-#endif
-#ifdef SIGSTOP
- case SIGSTOP: return "Stopped (signal)";
-#endif
-#ifdef SIGTSTP
- case SIGTSTP: return "Stopped";
-#endif
-#ifdef SIGTTIN
- case SIGTTIN: return "Stopped (tty input)";
-#endif
-#ifdef SIGTTOU
- case SIGTTOU: return "Stopped (tty output)";
-#endif
-#ifdef SIGURG
- case SIGURG: return "Urgent condition";
-#endif
-#ifdef SIGXCPU
- case SIGXCPU: return "CPU time limit exceeded";
-#endif
-#ifdef SIGXFSZ
- case SIGXFSZ: return "File size limit exceeded";
-#endif
-#ifdef SIGVTALRM
- case SIGVTALRM: return "Virtual time alarm";
-#endif
-#ifdef SIGPROF
- case SIGPROF: return "Profile signal";
-#endif
-#ifdef SIGWINCH
- case SIGWINCH: return "Window size changed";
-#endif
-#ifdef SIGIO
- case SIGIO: return "Possible I/O";
-#endif
-#ifdef SIGPWR
- case SIGPWR: return "Power failure";
-#endif
-#ifdef SIGUNUSED
- case SIGUNUSED: return "Unused signal";
-#endif
- }
-#else /* NO_SYS_SIGLIST */
-
-#ifdef NO_SYS_SIGLIST_DECL
- extern char *sys_siglist[]; /*(see Tue Jan 19 00:44:24 1999 in changelog)*/
-#endif
-
- return (char*) /* this function should return const --josh */ sys_siglist [signum];
-#endif /* NO_SYS_SIGLIST */
-
- msg = g_static_private_get (&msg_private);
- if (!msg)
- {
- msg = g_new (gchar, 64);
- g_static_private_set (&msg_private, msg, g_free);
- }
-
- sprintf (msg, "unknown signal (%d)", signum);
-
- return msg;
-}
-
-typedef struct
-{
- guint min_width;
- guint precision;
- gboolean alternate_format, zero_padding, adjust_left, locale_grouping;
- gboolean add_space, add_sign, possible_sign, seen_precision;
- gboolean mod_half, mod_long, mod_extra_long;
-} PrintfArgSpec;
-
-guint
-g_printf_string_upper_bound (const gchar* format,
- va_list args)
-{
- static const gboolean honour_longs = SIZEOF_LONG > 4 || SIZEOF_VOID_P > 4;
- guint len = 1;
-
- if (!format)
- return len;
-
- while (*format)
- {
- register gchar c = *format++;
-
- if (c != '%')
- len += 1;
- else /* (c == '%') */
- {
- PrintfArgSpec spec = { 0, };
- gboolean seen_l = FALSE, conv_done = FALSE;
- guint conv_len = 0;
- const gchar *spec_start = format;
-
- do
- {
- c = *format++;
- switch (c)
- {
- GDoubleIEEE754 u_double;
- guint v_uint;
- gint v_int;
- const gchar *v_string;
-
- /* beware of positional parameters
- */
- case '$':
- g_warning (G_GNUC_PRETTY_FUNCTION
- "(): unable to handle positional parameters (%%n$)");
- len += 1024; /* try adding some safety padding */
- break;
-
- /* parse flags
- */
- case '#':
- spec.alternate_format = TRUE;
- break;
- case '0':
- spec.zero_padding = TRUE;
- break;
- case '-':
- spec.adjust_left = TRUE;
- break;
- case ' ':
- spec.add_space = TRUE;
- break;
- case '+':
- spec.add_sign = TRUE;
- break;
- case '\'':
- spec.locale_grouping = TRUE;
- break;
-
- /* parse output size specifications
- */
- case '.':
- spec.seen_precision = TRUE;
- break;
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- v_uint = c - '0';
- c = *format;
- while (c >= '0' && c <= '9')
- {
- format++;
- v_uint = v_uint * 10 + c - '0';
- c = *format;
- }
- if (spec.seen_precision)
- spec.precision = MAX (spec.precision, v_uint);
- else
- spec.min_width = MAX (spec.min_width, v_uint);
- break;
- case '*':
- v_int = va_arg (args, int);
- if (spec.seen_precision)
- {
- /* forget about negative precision */
- if (v_int >= 0)
- spec.precision = MAX (spec.precision, v_int);
- }
- else
- {
- if (v_int < 0)
- {
- v_int = - v_int;
- spec.adjust_left = TRUE;
- }
- spec.min_width = MAX (spec.min_width, v_int);
- }
- break;
-
- /* parse type modifiers
- */
- case 'h':
- spec.mod_half = TRUE;
- break;
- case 'l':
- if (!seen_l)
- {
- spec.mod_long = TRUE;
- seen_l = TRUE;
- break;
- }
- /* else, fall through */
- case 'L':
- case 'q':
- spec.mod_long = TRUE;
- spec.mod_extra_long = TRUE;
- break;
- case 'z':
- case 'Z':
-#if GLIB_SIZEOF_SIZE_T > 4
- spec.mod_long = TRUE;
- spec.mod_extra_long = TRUE;
-#endif /* GLIB_SIZEOF_SIZE_T > 4 */
- break;
- case 't':
-#if GLIB_SIZEOF_PTRDIFF_T > 4
- spec.mod_long = TRUE;
- spec.mod_extra_long = TRUE;
-#endif /* GLIB_SIZEOF_PTRDIFF_T > 4 */
- break;
- case 'j':
-#if GLIB_SIZEOF_INTMAX_T > 4
- spec.mod_long = TRUE;
- spec.mod_extra_long = TRUE;
-#endif /* GLIB_SIZEOF_INTMAX_T > 4 */
- break;
-
- /* parse output conversions
- */
- case '%':
- conv_len += 1;
- break;
- case 'O':
- case 'D':
- case 'I':
- case 'U':
- /* some C libraries feature long variants for these as well? */
- spec.mod_long = TRUE;
- /* fall through */
- case 'o':
- conv_len += 2;
- /* fall through */
- case 'd':
- case 'i':
- conv_len += 1; /* sign */
- /* fall through */
- case 'u':
- conv_len += 4;
- /* fall through */
- case 'x':
- case 'X':
- spec.possible_sign = TRUE;
- conv_len += 10;
- if (spec.mod_long && honour_longs)
- conv_len *= 2;
- if (spec.mod_extra_long)
- conv_len *= 2;
- if (spec.mod_extra_long)
- {
-#ifdef G_HAVE_GINT64
- (void) va_arg (args, gint64);
-#else /* !G_HAVE_GINT64 */
- (void) va_arg (args, long);
-#endif /* !G_HAVE_GINT64 */
- }
- else if (spec.mod_long)
- (void) va_arg (args, long);
- else
- (void) va_arg (args, int);
- break;
- case 'A':
- case 'a':
- /* 0x */
- conv_len += 2;
- /* fall through */
- case 'g':
- case 'G':
- case 'e':
- case 'E':
- case 'f':
- spec.possible_sign = TRUE;
- /* n . dddddddddddddddddddddddd E +- eeee */
- conv_len += 1 + 1 + MAX (24, spec.precision) + 1 + 1 + 4;
- if (spec.mod_extra_long)
- g_warning (G_GNUC_PRETTY_FUNCTION
- "(): unable to handle long double, collecting double only");
-#ifdef HAVE_LONG_DOUBLE
-#error need to implement special handling for long double
-#endif
- u_double.v_double = va_arg (args, double);
- /* %f can expand up to all significant digits before '.' (308) */
- if (c == 'f' &&
- u_double.mpn.biased_exponent > 0 && u_double.mpn.biased_exponent < 2047)
- {
- gint exp = u_double.mpn.biased_exponent;
-
- exp -= G_IEEE754_DOUBLE_BIAS;
- exp = exp * G_LOG_2_BASE_10 + 1;
- conv_len += exp;
- }
- /* some printf() implementations require extra padding for rounding */
- conv_len += 2;
- /* we can't really handle locale specific grouping here */
- if (spec.locale_grouping)
- conv_len *= 2;
- break;
- case 'C':
- spec.mod_long = TRUE;
- /* fall through */
- case 'c':
- conv_len += spec.mod_long ? MB_LEN_MAX : 1;
- (void) va_arg (args, int);
- break;
- case 'S':
- spec.mod_long = TRUE;
- /* fall through */
- case 's':
- v_string = va_arg (args, char*);
- if (!v_string)
- conv_len += 8; /* hold "(null)" */
- else if (spec.seen_precision)
- conv_len += spec.precision;
- else
- conv_len += strlen (v_string);
- conv_done = TRUE;
- if (spec.mod_long)
- {
- g_warning (G_GNUC_PRETTY_FUNCTION
- "(): unable to handle wide char strings");
- len += 1024; /* try adding some safety padding */
- }
- break;
- case 'P': /* do we actually need this? */
- /* fall through */
- case 'p':
- spec.alternate_format = TRUE;
- conv_len += 10;
- if (honour_longs)
- conv_len *= 2;
- /* fall through */
- case 'n':
- conv_done = TRUE;
- (void) va_arg (args, void*);
- break;
- case 'm':
- /* there's not much we can do to be clever */
- v_string = g_strerror (errno);
- v_uint = v_string ? strlen (v_string) : 0;
- conv_len += MAX (256, v_uint);
- break;
-
- /* handle invalid cases
- */
- case '\000':
- /* no conversion specification, bad bad */
- conv_len += format - spec_start;
- break;
- default:
- g_warning (G_GNUC_PRETTY_FUNCTION
- "(): unable to handle `%c' while parsing format",
- c);
- break;
- }
- conv_done |= conv_len > 0;
- }
- while (!conv_done);
- /* handle width specifications */
- conv_len = MAX (conv_len, MAX (spec.precision, spec.min_width));
- /* handle flags */
- conv_len += spec.alternate_format ? 2 : 0;
- conv_len += (spec.add_space || spec.add_sign || spec.possible_sign);
- /* finally done */
- len += conv_len;
- } /* else (c == '%') */
- } /* while (*format) */
-
- return len;
-}
-
-void
-g_strdown (gchar *string)
-{
- register guchar *s;
-
- g_return_if_fail (string != NULL);
-
- s = string;
-
- while (*s)
- {
- *s = tolower (*s);
- s++;
- }
-}
-
-void
-g_strup (gchar *string)
-{
- register guchar *s;
-
- g_return_if_fail (string != NULL);
-
- s = string;
-
- while (*s)
- {
- *s = toupper (*s);
- s++;
- }
-}
-
-void
-g_strreverse (gchar *string)
-{
- g_return_if_fail (string != NULL);
-
- if (*string)
- {
- register gchar *h, *t;
-
- h = string;
- t = string + strlen (string) - 1;
-
- while (h < t)
- {
- register gchar c;
-
- c = *h;
- *h = *t;
- h++;
- *t = c;
- t--;
- }
- }
-}
-
-gint
-g_strcasecmp (const gchar *s1,
- const gchar *s2)
-{
-#ifdef HAVE_STRCASECMP
- g_return_val_if_fail (s1 != NULL, 0);
- g_return_val_if_fail (s2 != NULL, 0);
-
- return strcasecmp (s1, s2);
-#else
- gint c1, c2;
-
- g_return_val_if_fail (s1 != NULL, 0);
- g_return_val_if_fail (s2 != NULL, 0);
-
- while (*s1 && *s2)
- {
- /* According to A. Cox, some platforms have islower's that
- * don't work right on non-uppercase
- */
- c1 = isupper ((guchar)*s1) ? tolower ((guchar)*s1) : *s1;
- c2 = isupper ((guchar)*s2) ? tolower ((guchar)*s2) : *s2;
- if (c1 != c2)
- return (c1 - c2);
- s1++; s2++;
- }
-
- return (((gint)(guchar) *s1) - ((gint)(guchar) *s2));
-#endif
-}
-
-gint
-g_strncasecmp (const gchar *s1,
- const gchar *s2,
- guint n)
-{
-#ifdef HAVE_STRNCASECMP
- return strncasecmp (s1, s2, n);
-#else
- gint c1, c2;
-
- g_return_val_if_fail (s1 != NULL, 0);
- g_return_val_if_fail (s2 != NULL, 0);
-
- while (n && *s1 && *s2)
- {
- n -= 1;
- /* According to A. Cox, some platforms have islower's that
- * don't work right on non-uppercase
- */
- c1 = isupper ((guchar)*s1) ? tolower ((guchar)*s1) : *s1;
- c2 = isupper ((guchar)*s2) ? tolower ((guchar)*s2) : *s2;
- if (c1 != c2)
- return (c1 - c2);
- s1++; s2++;
- }
-
- if (n)
- return (((gint) (guchar) *s1) - ((gint) (guchar) *s2));
- else
- return 0;
-#endif
-}
-
-gchar*
-g_strdelimit (gchar *string,
- const gchar *delimiters,
- gchar new_delim)
-{
- register gchar *c;
-
- g_return_val_if_fail (string != NULL, NULL);
-
- if (!delimiters)
- delimiters = G_STR_DELIMITERS;
-
- for (c = string; *c; c++)
- {
- if (strchr (delimiters, *c))
- *c = new_delim;
- }
-
- return string;
-}
-
-gchar*
-g_strescape (gchar *string)
-{
- gchar *q;
- gchar *escaped;
- guint backslashes = 0;
- gchar *p = string;
-
- g_return_val_if_fail (string != NULL, NULL);
-
- while (*p != '\000')
- backslashes += (*p++ == '\\');
-
- if (!backslashes)
- return g_strdup (string);
-
- escaped = g_new (gchar, strlen (string) + backslashes + 1);
-
- p = string;
- q = escaped;
-
- while (*p != '\000')
- {
- if (*p == '\\')
- *q++ = '\\';
- *q++ = *p++;
- }
- *q = '\000';
-
- return escaped;
-}
-
-/* blame Elliot for these next five routines */
-gchar*
-g_strchug (gchar *string)
-{
- guchar *start;
-
- g_return_val_if_fail (string != NULL, NULL);
-
- for (start = string; *start && isspace (*start); start++)
- ;
-
- g_memmove(string, start, strlen(start) + 1);
-
- return string;
-}
-
-gchar*
-g_strchomp (gchar *string)
-{
- gchar *s;
-
- g_return_val_if_fail (string != NULL, NULL);
-
- if (!*string)
- return string;
-
- for (s = string + strlen (string) - 1; s >= string && isspace ((guchar)*s);
- s--)
- *s = '\0';
-
- return string;
-}
-
-gchar**
-g_strsplit (const gchar *string,
- const gchar *delimiter,
- gint max_tokens)
-{
- GSList *string_list = NULL, *slist;
- gchar **str_array, *s;
- guint i, n = 1;
-
- g_return_val_if_fail (string != NULL, NULL);
- g_return_val_if_fail (delimiter != NULL, NULL);
-
- if (max_tokens < 1)
- max_tokens = G_MAXINT;
-
- s = strstr (string, delimiter);
- if (s)
- {
- guint delimiter_len = strlen (delimiter);
-
- do
- {
- guint len;
- gchar *new_string;
-
- len = s - string;
- new_string = g_new (gchar, len + 1);
- strncpy (new_string, string, len);
- new_string[len] = 0;
- string_list = g_slist_prepend (string_list, new_string);
- n++;
- string = s + delimiter_len;
- s = strstr (string, delimiter);
- }
- while (--max_tokens && s);
- }
- if (*string)
- {
- n++;
- string_list = g_slist_prepend (string_list, g_strdup (string));
- }
-
- str_array = g_new (gchar*, n);
-
- i = n - 1;
-
- str_array[i--] = NULL;
- for (slist = string_list; slist; slist = slist->next)
- str_array[i--] = slist->data;
-
- g_slist_free (string_list);
-
- return str_array;
-}
-
-void
-g_strfreev (gchar **str_array)
-{
- if (str_array)
- {
- int i;
-
- for(i = 0; str_array[i] != NULL; i++)
- g_free(str_array[i]);
-
- g_free (str_array);
- }
-}
-
-gchar*
-g_strjoinv (const gchar *separator,
- gchar **str_array)
-{
- gchar *string;
-
- g_return_val_if_fail (str_array != NULL, NULL);
-
- if (separator == NULL)
- separator = "";
-
- if (*str_array)
- {
- guint i, len;
- guint separator_len;
-
- separator_len = strlen (separator);
- len = 1 + strlen (str_array[0]);
- for(i = 1; str_array[i] != NULL; i++)
- len += separator_len + strlen(str_array[i]);
-
- string = g_new (gchar, len);
- *string = 0;
- strcat (string, *str_array);
- for (i = 1; str_array[i] != NULL; i++)
- {
- strcat (string, separator);
- strcat (string, str_array[i]);
- }
- }
- else
- string = g_strdup ("");
-
- return string;
-}
-
-gchar*
-g_strjoin (const gchar *separator,
- ...)
-{
- gchar *string, *s;
- va_list args;
- guint len;
- guint separator_len;
-
- if (separator == NULL)
- separator = "";
-
- separator_len = strlen (separator);
-
- va_start (args, separator);
-
- s = va_arg (args, gchar*);
-
- if (s)
- {
- len = strlen (s);
-
- s = va_arg (args, gchar*);
- while (s)
- {
- len += separator_len + strlen (s);
- s = va_arg (args, gchar*);
- }
- va_end (args);
-
- string = g_new (gchar, len + 1);
- *string = 0;
-
- va_start (args, separator);
-
- s = va_arg (args, gchar*);
- strcat (string, s);
-
- s = va_arg (args, gchar*);
- while (s)
- {
- strcat (string, separator);
- strcat (string, s);
- s = va_arg (args, gchar*);
- }
- }
- else
- string = g_strdup ("");
-
- va_end (args);
-
- return string;
-}
diff --git a/glib/gstring.c b/glib/gstring.c
deleted file mode 100644
index a7ed5c6e0..000000000
--- a/glib/gstring.c
+++ /dev/null
@@ -1,512 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include <stdarg.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include "glib.h"
-
-
-typedef struct _GRealStringChunk GRealStringChunk;
-typedef struct _GRealString GRealString;
-
-struct _GRealStringChunk
-{
- GHashTable *const_table;
- GSList *storage_list;
- gint storage_next;
- gint this_size;
- gint default_size;
-};
-
-struct _GRealString
-{
- gchar *str;
- gint len;
- gint alloc;
-};
-
-G_LOCK_DEFINE_STATIC (string_mem_chunk);
-static GMemChunk *string_mem_chunk = NULL;
-
-/* Hash Functions.
- */
-
-gint
-g_str_equal (gconstpointer v, gconstpointer v2)
-{
- return strcmp ((const gchar*) v, (const gchar*)v2) == 0;
-}
-
-/* 31 bit hash function */
-guint
-g_str_hash (gconstpointer key)
-{
- const char *p = key;
- guint h = *p;
-
- if (h)
- for (p += 1; *p != '\0'; p++)
- h = (h << 5) - h + *p;
-
- return h;
-}
-
-/* String Chunks.
- */
-
-GStringChunk*
-g_string_chunk_new (gint default_size)
-{
- GRealStringChunk *new_chunk = g_new (GRealStringChunk, 1);
- gint size = 1;
-
- while (size < default_size)
- size <<= 1;
-
- new_chunk->const_table = NULL;
- new_chunk->storage_list = NULL;
- new_chunk->storage_next = size;
- new_chunk->default_size = size;
- new_chunk->this_size = size;
-
- return (GStringChunk*) new_chunk;
-}
-
-void
-g_string_chunk_free (GStringChunk *fchunk)
-{
- GRealStringChunk *chunk = (GRealStringChunk*) fchunk;
- GSList *tmp_list;
-
- g_return_if_fail (chunk != NULL);
-
- if (chunk->storage_list)
- {
- for (tmp_list = chunk->storage_list; tmp_list; tmp_list = tmp_list->next)
- g_free (tmp_list->data);
-
- g_slist_free (chunk->storage_list);
- }
-
- if (chunk->const_table)
- g_hash_table_destroy (chunk->const_table);
-
- g_free (chunk);
-}
-
-gchar*
-g_string_chunk_insert (GStringChunk *fchunk,
- const gchar *string)
-{
- GRealStringChunk *chunk = (GRealStringChunk*) fchunk;
- gint len = strlen (string);
- char* pos;
-
- g_return_val_if_fail (chunk != NULL, NULL);
-
- if ((chunk->storage_next + len + 1) > chunk->this_size)
- {
- gint new_size = chunk->default_size;
-
- while (new_size < len+1)
- new_size <<= 1;
-
- chunk->storage_list = g_slist_prepend (chunk->storage_list,
- g_new (char, new_size));
-
- chunk->this_size = new_size;
- chunk->storage_next = 0;
- }
-
- pos = ((char*)chunk->storage_list->data) + chunk->storage_next;
-
- strcpy (pos, string);
-
- chunk->storage_next += len + 1;
-
- return pos;
-}
-
-gchar*
-g_string_chunk_insert_const (GStringChunk *fchunk,
- const gchar *string)
-{
- GRealStringChunk *chunk = (GRealStringChunk*) fchunk;
- char* lookup;
-
- g_return_val_if_fail (chunk != NULL, NULL);
-
- if (!chunk->const_table)
- chunk->const_table = g_hash_table_new (g_str_hash, g_str_equal);
-
- lookup = (char*) g_hash_table_lookup (chunk->const_table, (gchar *)string);
-
- if (!lookup)
- {
- lookup = g_string_chunk_insert (fchunk, string);
- g_hash_table_insert (chunk->const_table, lookup, lookup);
- }
-
- return lookup;
-}
-
-/* Strings.
- */
-static gint
-nearest_pow (gint num)
-{
- gint n = 1;
-
- while (n < num)
- n <<= 1;
-
- return n;
-}
-
-static void
-g_string_maybe_expand (GRealString* string, gint len)
-{
- if (string->len + len >= string->alloc)
- {
- string->alloc = nearest_pow (string->len + len + 1);
- string->str = g_realloc (string->str, string->alloc);
- }
-}
-
-GString*
-g_string_sized_new (guint dfl_size)
-{
- GRealString *string;
-
- G_LOCK (string_mem_chunk);
- if (!string_mem_chunk)
- string_mem_chunk = g_mem_chunk_new ("string mem chunk",
- sizeof (GRealString),
- 1024, G_ALLOC_AND_FREE);
-
- string = g_chunk_new (GRealString, string_mem_chunk);
- G_UNLOCK (string_mem_chunk);
-
- string->alloc = 0;
- string->len = 0;
- string->str = NULL;
-
- g_string_maybe_expand (string, MAX (dfl_size, 2));
- string->str[0] = 0;
-
- return (GString*) string;
-}
-
-GString*
-g_string_new (const gchar *init)
-{
- GString *string;
-
- string = g_string_sized_new (2);
-
- if (init)
- g_string_append (string, init);
-
- return string;
-}
-
-void
-g_string_free (GString *string,
- gint free_segment)
-{
- g_return_if_fail (string != NULL);
-
- if (free_segment)
- g_free (string->str);
-
- G_LOCK (string_mem_chunk);
- g_mem_chunk_free (string_mem_chunk, string);
- G_UNLOCK (string_mem_chunk);
-}
-
-GString*
-g_string_assign (GString *lval,
- const gchar *rval)
-{
- g_return_val_if_fail (lval != NULL, NULL);
- g_return_val_if_fail (rval != NULL, NULL);
-
- g_string_truncate (lval, 0);
- g_string_append (lval, rval);
-
- return lval;
-}
-
-GString*
-g_string_truncate (GString* fstring,
- gint len)
-{
- GRealString *string = (GRealString*)fstring;
-
- g_return_val_if_fail (string != NULL, NULL);
- g_return_val_if_fail (len >= 0, NULL);
-
- string->len = len;
-
- string->str[len] = 0;
-
- return fstring;
-}
-
-GString*
-g_string_append (GString *fstring,
- const gchar *val)
-{
- GRealString *string = (GRealString*)fstring;
- int len;
-
- g_return_val_if_fail (string != NULL, NULL);
- g_return_val_if_fail (val != NULL, fstring);
-
- len = strlen (val);
- g_string_maybe_expand (string, len);
-
- strcpy (string->str + string->len, val);
-
- string->len += len;
-
- return fstring;
-}
-
-GString*
-g_string_append_c (GString *fstring,
- gchar c)
-{
- GRealString *string = (GRealString*)fstring;
-
- g_return_val_if_fail (string != NULL, NULL);
- g_string_maybe_expand (string, 1);
-
- string->str[string->len++] = c;
- string->str[string->len] = 0;
-
- return fstring;
-}
-
-GString*
-g_string_prepend (GString *fstring,
- const gchar *val)
-{
- GRealString *string = (GRealString*)fstring;
- gint len;
-
- g_return_val_if_fail (string != NULL, NULL);
- g_return_val_if_fail (val != NULL, fstring);
-
- len = strlen (val);
- g_string_maybe_expand (string, len);
-
- g_memmove (string->str + len, string->str, string->len);
-
- strncpy (string->str, val, len);
-
- string->len += len;
-
- string->str[string->len] = 0;
-
- return fstring;
-}
-
-GString*
-g_string_prepend_c (GString *fstring,
- gchar c)
-{
- GRealString *string = (GRealString*)fstring;
-
- g_return_val_if_fail (string != NULL, NULL);
- g_string_maybe_expand (string, 1);
-
- g_memmove (string->str + 1, string->str, string->len);
-
- string->str[0] = c;
-
- string->len += 1;
-
- string->str[string->len] = 0;
-
- return fstring;
-}
-
-GString*
-g_string_insert (GString *fstring,
- gint pos,
- const gchar *val)
-{
- GRealString *string = (GRealString*)fstring;
- gint len;
-
- g_return_val_if_fail (string != NULL, NULL);
- g_return_val_if_fail (val != NULL, fstring);
- g_return_val_if_fail (pos >= 0, fstring);
- g_return_val_if_fail (pos <= string->len, fstring);
-
- len = strlen (val);
- g_string_maybe_expand (string, len);
-
- g_memmove (string->str + pos + len, string->str + pos, string->len - pos);
-
- strncpy (string->str + pos, val, len);
-
- string->len += len;
-
- string->str[string->len] = 0;
-
- return fstring;
-}
-
-GString *
-g_string_insert_c (GString *fstring,
- gint pos,
- gchar c)
-{
- GRealString *string = (GRealString*)fstring;
-
- g_return_val_if_fail (string != NULL, NULL);
- g_return_val_if_fail (pos <= string->len, fstring);
-
- g_string_maybe_expand (string, 1);
-
- g_memmove (string->str + pos + 1, string->str + pos, string->len - pos);
-
- string->str[pos] = c;
-
- string->len += 1;
-
- string->str[string->len] = 0;
-
- return fstring;
-}
-
-GString*
-g_string_erase (GString *fstring,
- gint pos,
- gint len)
-{
- GRealString *string = (GRealString*)fstring;
-
- g_return_val_if_fail (string != NULL, NULL);
- g_return_val_if_fail (len >= 0, fstring);
- g_return_val_if_fail (pos >= 0, fstring);
- g_return_val_if_fail (pos <= string->len, fstring);
- g_return_val_if_fail (pos + len <= string->len, fstring);
-
- if (pos + len < string->len)
- g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len));
-
- string->len -= len;
-
- string->str[string->len] = 0;
-
- return fstring;
-}
-
-GString*
-g_string_down (GString *fstring)
-{
- GRealString *string = (GRealString*)fstring;
- guchar *s;
-
- g_return_val_if_fail (string != NULL, NULL);
-
- s = string->str;
-
- while (*s)
- {
- *s = tolower (*s);
- s++;
- }
-
- return fstring;
-}
-
-GString*
-g_string_up (GString *fstring)
-{
- GRealString *string = (GRealString*)fstring;
- guchar *s;
-
- g_return_val_if_fail (string != NULL, NULL);
-
- s = string->str;
-
- while (*s)
- {
- *s = toupper (*s);
- s++;
- }
-
- return fstring;
-}
-
-static void
-g_string_sprintfa_int (GString *string,
- const gchar *fmt,
- va_list args)
-{
- gchar *buffer;
-
- buffer = g_strdup_vprintf (fmt, args);
- g_string_append (string, buffer);
- g_free (buffer);
-}
-
-void
-g_string_sprintf (GString *string,
- const gchar *fmt,
- ...)
-{
- va_list args;
-
- g_string_truncate (string, 0);
-
- va_start (args, fmt);
- g_string_sprintfa_int (string, fmt, args);
- va_end (args);
-}
-
-void
-g_string_sprintfa (GString *string,
- const gchar *fmt,
- ...)
-{
- va_list args;
-
- va_start (args, fmt);
- g_string_sprintfa_int (string, fmt, args);
- va_end (args);
-}
diff --git a/glib/gtimer.c b/glib/gtimer.c
deleted file mode 100644
index f4b72edf6..000000000
--- a/glib/gtimer.c
+++ /dev/null
@@ -1,201 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "glib.h"
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#ifndef NATIVE_WIN32
-#include <sys/time.h>
-#endif /* NATIVE_WIN32 */
-
-#ifdef NATIVE_WIN32
-#include <windows.h>
-#endif /* NATIVE_WIN32 */
-
-typedef struct _GRealTimer GRealTimer;
-
-struct _GRealTimer
-{
-#ifdef NATIVE_WIN32
- DWORD start;
- DWORD end;
-#else /* !NATIVE_WIN32 */
- struct timeval start;
- struct timeval end;
-#endif /* !NATIVE_WIN32 */
-
- guint active : 1;
-};
-
-GTimer*
-g_timer_new (void)
-{
- GRealTimer *timer;
-
- timer = g_new (GRealTimer, 1);
- timer->active = TRUE;
-
-#ifdef NATIVE_WIN32
- timer->start = GetTickCount ();
-#else /* !NATIVE_WIN32 */
- gettimeofday (&timer->start, NULL);
-#endif /* !NATIVE_WIN32 */
-
- return ((GTimer*) timer);
-}
-
-void
-g_timer_destroy (GTimer *timer)
-{
- g_return_if_fail (timer != NULL);
-
- g_free (timer);
-}
-
-void
-g_timer_start (GTimer *timer)
-{
- GRealTimer *rtimer;
-
- g_return_if_fail (timer != NULL);
-
- rtimer = (GRealTimer*) timer;
- rtimer->active = TRUE;
-
-#ifdef NATIVE_WIN32
- rtimer->start = GetTickCount ();
-#else /* !NATIVE_WIN32 */
- gettimeofday (&rtimer->start, NULL);
-#endif /* !NATIVE_WIN32 */
-}
-
-void
-g_timer_stop (GTimer *timer)
-{
- GRealTimer *rtimer;
-
- g_return_if_fail (timer != NULL);
-
- rtimer = (GRealTimer*) timer;
- rtimer->active = FALSE;
-
-#ifdef NATIVE_WIN32
- rtimer->end = GetTickCount ();
-#else /* !NATIVE_WIN32 */
- gettimeofday (&rtimer->end, NULL);
-#endif /* !NATIVE_WIN32 */
-}
-
-void
-g_timer_reset (GTimer *timer)
-{
- GRealTimer *rtimer;
-
- g_return_if_fail (timer != NULL);
-
- rtimer = (GRealTimer*) timer;
-
-#ifdef NATIVE_WIN32
- rtimer->start = GetTickCount ();
-#else /* !NATIVE_WIN32 */
- gettimeofday (&rtimer->start, NULL);
-#endif /* !NATIVE_WIN32 */
-}
-
-gdouble
-g_timer_elapsed (GTimer *timer,
- gulong *microseconds)
-{
- GRealTimer *rtimer;
- gdouble total;
-#ifndef NATIVE_WIN32
- struct timeval elapsed;
-#endif /* NATIVE_WIN32 */
-
- g_return_val_if_fail (timer != NULL, 0);
-
- rtimer = (GRealTimer*) timer;
-
-#ifdef NATIVE_WIN32
- if (rtimer->active)
- rtimer->end = GetTickCount ();
-
- /* Check for wraparound, which happens every 49.7 days.
- * No, Win95 machines probably are never running for that long,
- * but NT machines are.
- */
- if (rtimer->end < rtimer->start)
- total = (UINT_MAX - (rtimer->start - rtimer->end)) / 1000.0;
- else
- total = (rtimer->end - rtimer->start) / 1000.0;
-
- if (microseconds)
- {
- if (rtimer->end < rtimer->start)
- *microseconds =
- ((UINT_MAX - (rtimer->start - rtimer->end)) % 1000) * 1000;
- else
- *microseconds =
- ((rtimer->end - rtimer->start) % 1000) * 1000;
- }
-#else /* !NATIVE_WIN32 */
- if (rtimer->active)
- gettimeofday (&rtimer->end, NULL);
-
- if (rtimer->start.tv_usec > rtimer->end.tv_usec)
- {
- rtimer->end.tv_usec += 1000000;
- rtimer->end.tv_sec--;
- }
-
- elapsed.tv_usec = rtimer->end.tv_usec - rtimer->start.tv_usec;
- elapsed.tv_sec = rtimer->end.tv_sec - rtimer->start.tv_sec;
-
- total = elapsed.tv_sec + ((gdouble) elapsed.tv_usec / 1e6);
- if (total < 0)
- {
- total = 0;
-
- if (microseconds)
- *microseconds = 0;
- }
- else
- if (microseconds)
- *microseconds = elapsed.tv_usec;
-
-#endif /* !NATIVE_WIN32 */
-
- return total;
-}
diff --git a/glib/gtree.c b/glib/gtree.c
deleted file mode 100644
index e6c3f19e9..000000000
--- a/glib/gtree.c
+++ /dev/null
@@ -1,744 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe
- */
-
-#include "glib.h"
-
-
-typedef struct _GRealTree GRealTree;
-typedef struct _GTreeNode GTreeNode;
-
-struct _GRealTree
-{
- GTreeNode *root;
- GCompareFunc key_compare;
-};
-
-struct _GTreeNode
-{
- gint balance; /* height (left) - height (right) */
- GTreeNode *left; /* left subtree */
- GTreeNode *right; /* right subtree */
- gpointer key; /* key for this node */
- gpointer value; /* value stored at this node */
-};
-
-
-static GTreeNode* g_tree_node_new (gpointer key,
- gpointer value);
-static void g_tree_node_destroy (GTreeNode *node);
-static GTreeNode* g_tree_node_insert (GTreeNode *node,
- GCompareFunc compare,
- gpointer key,
- gpointer value,
- gint *inserted);
-static GTreeNode* g_tree_node_remove (GTreeNode *node,
- GCompareFunc compare,
- gpointer key);
-static GTreeNode* g_tree_node_balance (GTreeNode *node);
-static GTreeNode* g_tree_node_remove_leftmost (GTreeNode *node,
- GTreeNode **leftmost);
-static GTreeNode* g_tree_node_restore_left_balance (GTreeNode *node,
- gint old_balance);
-static GTreeNode* g_tree_node_restore_right_balance (GTreeNode *node,
- gint old_balance);
-static gpointer g_tree_node_lookup (GTreeNode *node,
- GCompareFunc compare,
- gpointer key);
-static gint g_tree_node_count (GTreeNode *node);
-static gint g_tree_node_pre_order (GTreeNode *node,
- GTraverseFunc traverse_func,
- gpointer data);
-static gint g_tree_node_in_order (GTreeNode *node,
- GTraverseFunc traverse_func,
- gpointer data);
-static gint g_tree_node_post_order (GTreeNode *node,
- GTraverseFunc traverse_func,
- gpointer data);
-static gpointer g_tree_node_search (GTreeNode *node,
- GSearchFunc search_func,
- gpointer data);
-static gint g_tree_node_height (GTreeNode *node);
-static GTreeNode* g_tree_node_rotate_left (GTreeNode *node);
-static GTreeNode* g_tree_node_rotate_right (GTreeNode *node);
-static void g_tree_node_check (GTreeNode *node);
-
-
-G_LOCK_DEFINE_STATIC (g_tree_global);
-static GMemChunk *node_mem_chunk = NULL;
-static GTreeNode *node_free_list = NULL;
-
-
-static GTreeNode*
-g_tree_node_new (gpointer key,
- gpointer value)
-{
- GTreeNode *node;
-
- G_LOCK (g_tree_global);
- if (node_free_list)
- {
- node = node_free_list;
- node_free_list = node->right;
- }
- else
- {
- if (!node_mem_chunk)
- node_mem_chunk = g_mem_chunk_new ("GLib GTreeNode mem chunk",
- sizeof (GTreeNode),
- 1024,
- G_ALLOC_ONLY);
-
- node = g_chunk_new (GTreeNode, node_mem_chunk);
- }
- G_UNLOCK (g_tree_global);
-
- node->balance = 0;
- node->left = NULL;
- node->right = NULL;
- node->key = key;
- node->value = value;
-
- return node;
-}
-
-static void
-g_tree_node_destroy (GTreeNode *node)
-{
- if (node)
- {
- g_tree_node_destroy (node->right);
- g_tree_node_destroy (node->left);
- G_LOCK (g_tree_global);
- node->right = node_free_list;
- node_free_list = node;
- G_UNLOCK (g_tree_global);
- }
-}
-
-
-GTree*
-g_tree_new (GCompareFunc key_compare_func)
-{
- GRealTree *rtree;
-
- g_return_val_if_fail (key_compare_func != NULL, NULL);
-
- rtree = g_new (GRealTree, 1);
- rtree->root = NULL;
- rtree->key_compare = key_compare_func;
-
- return (GTree*) rtree;
-}
-
-void
-g_tree_destroy (GTree *tree)
-{
- GRealTree *rtree;
-
- g_return_if_fail (tree != NULL);
-
- rtree = (GRealTree*) tree;
-
- g_tree_node_destroy (rtree->root);
- g_free (rtree);
-}
-
-void
-g_tree_insert (GTree *tree,
- gpointer key,
- gpointer value)
-{
- GRealTree *rtree;
- gint inserted;
-
- g_return_if_fail (tree != NULL);
-
- rtree = (GRealTree*) tree;
-
- inserted = FALSE;
- rtree->root = g_tree_node_insert (rtree->root, rtree->key_compare,
- key, value, &inserted);
-}
-
-void
-g_tree_remove (GTree *tree,
- gpointer key)
-{
- GRealTree *rtree;
-
- g_return_if_fail (tree != NULL);
-
- rtree = (GRealTree*) tree;
-
- rtree->root = g_tree_node_remove (rtree->root, rtree->key_compare, key);
-}
-
-gpointer
-g_tree_lookup (GTree *tree,
- gpointer key)
-{
- GRealTree *rtree;
-
- g_return_val_if_fail (tree != NULL, NULL);
-
- rtree = (GRealTree*) tree;
-
- return g_tree_node_lookup (rtree->root, rtree->key_compare, key);
-}
-
-void
-g_tree_traverse (GTree *tree,
- GTraverseFunc traverse_func,
- GTraverseType traverse_type,
- gpointer data)
-{
- GRealTree *rtree;
-
- g_return_if_fail (tree != NULL);
-
- rtree = (GRealTree*) tree;
-
- if (!rtree->root)
- return;
-
- switch (traverse_type)
- {
- case G_PRE_ORDER:
- g_tree_node_pre_order (rtree->root, traverse_func, data);
- break;
-
- case G_IN_ORDER:
- g_tree_node_in_order (rtree->root, traverse_func, data);
- break;
-
- case G_POST_ORDER:
- g_tree_node_post_order (rtree->root, traverse_func, data);
- break;
-
- case G_LEVEL_ORDER:
- g_warning ("g_tree_traverse(): traverse type G_LEVEL_ORDER isn't implemented.");
- break;
- }
-}
-
-gpointer
-g_tree_search (GTree *tree,
- GSearchFunc search_func,
- gpointer data)
-{
- GRealTree *rtree;
-
- g_return_val_if_fail (tree != NULL, NULL);
-
- rtree = (GRealTree*) tree;
-
- if (rtree->root)
- return g_tree_node_search (rtree->root, search_func, data);
- else
- return NULL;
-}
-
-gint
-g_tree_height (GTree *tree)
-{
- GRealTree *rtree;
-
- g_return_val_if_fail (tree != NULL, 0);
-
- rtree = (GRealTree*) tree;
-
- if (rtree->root)
- return g_tree_node_height (rtree->root);
- else
- return 0;
-}
-
-gint
-g_tree_nnodes (GTree *tree)
-{
- GRealTree *rtree;
-
- g_return_val_if_fail (tree != NULL, 0);
-
- rtree = (GRealTree*) tree;
-
- if (rtree->root)
- return g_tree_node_count (rtree->root);
- else
- return 0;
-}
-
-static GTreeNode*
-g_tree_node_insert (GTreeNode *node,
- GCompareFunc compare,
- gpointer key,
- gpointer value,
- gint *inserted)
-{
- gint old_balance;
- gint cmp;
-
- if (!node)
- {
- *inserted = TRUE;
- return g_tree_node_new (key, value);
- }
-
- cmp = (* compare) (key, node->key);
- if (cmp == 0)
- {
- *inserted = FALSE;
- node->value = value;
- return node;
- }
-
- if (cmp < 0)
- {
- if (node->left)
- {
- old_balance = node->left->balance;
- node->left = g_tree_node_insert (node->left, compare, key, value, inserted);
-
- if ((old_balance != node->left->balance) && node->left->balance)
- node->balance -= 1;
- }
- else
- {
- *inserted = TRUE;
- node->left = g_tree_node_new (key, value);
- node->balance -= 1;
- }
- }
- else if (cmp > 0)
- {
- if (node->right)
- {
- old_balance = node->right->balance;
- node->right = g_tree_node_insert (node->right, compare, key, value, inserted);
-
- if ((old_balance != node->right->balance) && node->right->balance)
- node->balance += 1;
- }
- else
- {
- *inserted = TRUE;
- node->right = g_tree_node_new (key, value);
- node->balance += 1;
- }
- }
-
- if (*inserted)
- {
- if ((node->balance < -1) || (node->balance > 1))
- node = g_tree_node_balance (node);
- }
-
- return node;
-}
-
-static GTreeNode*
-g_tree_node_remove (GTreeNode *node,
- GCompareFunc compare,
- gpointer key)
-{
- GTreeNode *new_root;
- gint old_balance;
- gint cmp;
-
- if (!node)
- return NULL;
-
- cmp = (* compare) (key, node->key);
- if (cmp == 0)
- {
- GTreeNode *garbage;
-
- garbage = node;
-
- if (!node->right)
- {
- node = node->left;
- }
- else
- {
- old_balance = node->right->balance;
- node->right = g_tree_node_remove_leftmost (node->right, &new_root);
- new_root->left = node->left;
- new_root->right = node->right;
- new_root->balance = node->balance;
- node = g_tree_node_restore_right_balance (new_root, old_balance);
- }
-
- G_LOCK (g_tree_global);
- garbage->right = node_free_list;
- node_free_list = garbage;
- G_UNLOCK (g_tree_global);
- }
- else if (cmp < 0)
- {
- if (node->left)
- {
- old_balance = node->left->balance;
- node->left = g_tree_node_remove (node->left, compare, key);
- node = g_tree_node_restore_left_balance (node, old_balance);
- }
- }
- else if (cmp > 0)
- {
- if (node->right)
- {
- old_balance = node->right->balance;
- node->right = g_tree_node_remove (node->right, compare, key);
- node = g_tree_node_restore_right_balance (node, old_balance);
- }
- }
-
- return node;
-}
-
-static GTreeNode*
-g_tree_node_balance (GTreeNode *node)
-{
- if (node->balance < -1)
- {
- if (node->left->balance > 0)
- node->left = g_tree_node_rotate_left (node->left);
- node = g_tree_node_rotate_right (node);
- }
- else if (node->balance > 1)
- {
- if (node->right->balance < 0)
- node->right = g_tree_node_rotate_right (node->right);
- node = g_tree_node_rotate_left (node);
- }
-
- return node;
-}
-
-static GTreeNode*
-g_tree_node_remove_leftmost (GTreeNode *node,
- GTreeNode **leftmost)
-{
- gint old_balance;
-
- if (!node->left)
- {
- *leftmost = node;
- return node->right;
- }
-
- old_balance = node->left->balance;
- node->left = g_tree_node_remove_leftmost (node->left, leftmost);
- return g_tree_node_restore_left_balance (node, old_balance);
-}
-
-static GTreeNode*
-g_tree_node_restore_left_balance (GTreeNode *node,
- gint old_balance)
-{
- if (!node->left)
- node->balance += 1;
- else if ((node->left->balance != old_balance) &&
- (node->left->balance == 0))
- node->balance += 1;
-
- if (node->balance > 1)
- return g_tree_node_balance (node);
- return node;
-}
-
-static GTreeNode*
-g_tree_node_restore_right_balance (GTreeNode *node,
- gint old_balance)
-{
- if (!node->right)
- node->balance -= 1;
- else if ((node->right->balance != old_balance) &&
- (node->right->balance == 0))
- node->balance -= 1;
-
- if (node->balance < -1)
- return g_tree_node_balance (node);
- return node;
-}
-
-static gpointer
-g_tree_node_lookup (GTreeNode *node,
- GCompareFunc compare,
- gpointer key)
-{
- gint cmp;
-
- if (!node)
- return NULL;
-
- cmp = (* compare) (key, node->key);
- if (cmp == 0)
- return node->value;
-
- if (cmp < 0)
- {
- if (node->left)
- return g_tree_node_lookup (node->left, compare, key);
- }
- else if (cmp > 0)
- {
- if (node->right)
- return g_tree_node_lookup (node->right, compare, key);
- }
-
- return NULL;
-}
-
-static gint
-g_tree_node_count (GTreeNode *node)
-{
- gint count;
-
- count = 1;
- if (node->left)
- count += g_tree_node_count (node->left);
- if (node->right)
- count += g_tree_node_count (node->right);
-
- return count;
-}
-
-static gint
-g_tree_node_pre_order (GTreeNode *node,
- GTraverseFunc traverse_func,
- gpointer data)
-{
- if ((*traverse_func) (node->key, node->value, data))
- return TRUE;
- if (node->left)
- {
- if (g_tree_node_pre_order (node->left, traverse_func, data))
- return TRUE;
- }
- if (node->right)
- {
- if (g_tree_node_pre_order (node->right, traverse_func, data))
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gint
-g_tree_node_in_order (GTreeNode *node,
- GTraverseFunc traverse_func,
- gpointer data)
-{
- if (node->left)
- {
- if (g_tree_node_in_order (node->left, traverse_func, data))
- return TRUE;
- }
- if ((*traverse_func) (node->key, node->value, data))
- return TRUE;
- if (node->right)
- {
- if (g_tree_node_in_order (node->right, traverse_func, data))
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gint
-g_tree_node_post_order (GTreeNode *node,
- GTraverseFunc traverse_func,
- gpointer data)
-{
- if (node->left)
- {
- if (g_tree_node_post_order (node->left, traverse_func, data))
- return TRUE;
- }
- if (node->right)
- {
- if (g_tree_node_post_order (node->right, traverse_func, data))
- return TRUE;
- }
- if ((*traverse_func) (node->key, node->value, data))
- return TRUE;
-
- return FALSE;
-}
-
-static gpointer
-g_tree_node_search (GTreeNode *node,
- GSearchFunc search_func,
- gpointer data)
-{
- gint dir;
-
- if (!node)
- return NULL;
-
- do {
- dir = (* search_func) (node->key, data);
- if (dir == 0)
- return node->value;
-
- if (dir < 0)
- node = node->left;
- else if (dir > 0)
- node = node->right;
- } while (node && (dir != 0));
-
- return NULL;
-}
-
-static gint
-g_tree_node_height (GTreeNode *node)
-{
- gint left_height;
- gint right_height;
-
- if (node)
- {
- left_height = 0;
- right_height = 0;
-
- if (node->left)
- left_height = g_tree_node_height (node->left);
-
- if (node->right)
- right_height = g_tree_node_height (node->right);
-
- return MAX (left_height, right_height) + 1;
- }
-
- return 0;
-}
-
-static GTreeNode*
-g_tree_node_rotate_left (GTreeNode *node)
-{
- GTreeNode *left;
- GTreeNode *right;
- gint a_bal;
- gint b_bal;
-
- left = node->left;
- right = node->right;
-
- node->right = right->left;
- right->left = node;
-
- a_bal = node->balance;
- b_bal = right->balance;
-
- if (b_bal <= 0)
- {
- if (a_bal >= 1)
- right->balance = b_bal - 1;
- else
- right->balance = a_bal + b_bal - 2;
- node->balance = a_bal - 1;
- }
- else
- {
- if (a_bal <= b_bal)
- right->balance = a_bal - 2;
- else
- right->balance = b_bal - 1;
- node->balance = a_bal - b_bal - 1;
- }
-
- return right;
-}
-
-static GTreeNode*
-g_tree_node_rotate_right (GTreeNode *node)
-{
- GTreeNode *left;
- gint a_bal;
- gint b_bal;
-
- left = node->left;
-
- node->left = left->right;
- left->right = node;
-
- a_bal = node->balance;
- b_bal = left->balance;
-
- if (b_bal <= 0)
- {
- if (b_bal > a_bal)
- left->balance = b_bal + 1;
- else
- left->balance = a_bal + 2;
- node->balance = a_bal - b_bal + 1;
- }
- else
- {
- if (a_bal <= -1)
- left->balance = b_bal + 1;
- else
- left->balance = a_bal + b_bal + 2;
- node->balance = a_bal + 1;
- }
-
- return left;
-}
-
-static void
-g_tree_node_check (GTreeNode *node)
-{
- gint left_height;
- gint right_height;
- gint balance;
-
- if (node)
- {
- left_height = 0;
- right_height = 0;
-
- if (node->left)
- left_height = g_tree_node_height (node->left);
- if (node->right)
- right_height = g_tree_node_height (node->right);
-
- balance = right_height - left_height;
- if (balance != node->balance)
- g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,
- "g_tree_node_check: failed: %d ( %d )\n",
- balance, node->balance);
-
- if (node->left)
- g_tree_node_check (node->left);
- if (node->right)
- g_tree_node_check (node->right);
- }
-}
diff --git a/glib/gutils.c b/glib/gutils.c
deleted file mode 100644
index a93ed9508..000000000
--- a/glib/gutils.c
+++ /dev/null
@@ -1,927 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1998 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * MT safe for the unix part, FIXME: make the win32 part MT safe as well.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "glibconfig.h"
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <stdarg.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#ifdef HAVE_PWD_H
-#include <pwd.h>
-#endif
-#include <sys/types.h>
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-
-#ifdef NATIVE_WIN32
-# define STRICT /* Strict typing, please */
-# include <windows.h>
-# include <direct.h>
-# include <errno.h>
-# include <ctype.h>
-# ifdef _MSC_VER
-# include <io.h>
-# endif /* _MSC_VER */
-#endif /* NATIVE_WIN32 */
-
-/* implement Glib's inline functions
- */
-#define G_INLINE_FUNC extern
-#define G_CAN_INLINE 1
-#include "glib.h"
-
-#ifdef MAXPATHLEN
-#define G_PATH_LENGTH (MAXPATHLEN + 1)
-#elif defined (PATH_MAX)
-#define G_PATH_LENGTH (PATH_MAX + 1)
-#else /* !MAXPATHLEN */
-#define G_PATH_LENGTH (2048 + 1)
-#endif /* !MAXPATHLEN && !PATH_MAX */
-
-const guint glib_major_version = GLIB_MAJOR_VERSION;
-const guint glib_minor_version = GLIB_MINOR_VERSION;
-const guint glib_micro_version = GLIB_MICRO_VERSION;
-const guint glib_interface_age = GLIB_INTERFACE_AGE;
-const guint glib_binary_age = GLIB_BINARY_AGE;
-
-#if defined (NATIVE_WIN32) && defined (__LCC__)
-int __stdcall
-LibMain (void *hinstDll,
- unsigned long dwReason,
- void *reserved)
-{
- return 1;
-}
-#endif /* NATIVE_WIN32 && __LCC__ */
-
-void
-g_atexit (GVoidFunc func)
-{
- gint result;
- gchar *error = NULL;
-
- /* keep this in sync with glib.h */
-
-#ifdef G_NATIVE_ATEXIT
- result = ATEXIT (func);
- if (result)
- error = g_strerror (errno);
-#elif defined (HAVE_ATEXIT)
-# ifdef NeXT /* @#%@! NeXTStep */
- result = !atexit ((void (*)(void)) func);
- if (result)
- error = g_strerror (errno);
-# else
- result = atexit ((void (*)(void)) func);
- if (result)
- error = g_strerror (errno);
-# endif /* NeXT */
-#elif defined (HAVE_ON_EXIT)
- result = on_exit ((void (*)(int, void *)) func, NULL);
- if (result)
- error = g_strerror (errno);
-#else
- result = 0;
- error = "no implementation";
-#endif /* G_NATIVE_ATEXIT */
-
- if (error)
- g_error ("Could not register atexit() function: %s", error);
-}
-
-gint
-g_snprintf (gchar *str,
- gulong n,
- gchar const *fmt,
- ...)
-{
-#ifdef HAVE_VSNPRINTF
- va_list args;
- gint retval;
-
- g_return_val_if_fail (str != NULL, 0);
- g_return_val_if_fail (n > 0, 0);
- g_return_val_if_fail (fmt != NULL, 0);
-
- va_start (args, fmt);
- retval = vsnprintf (str, n, fmt, args);
- va_end (args);
-
- if (retval < 0)
- {
- str[n-1] = '\0';
- retval = strlen (str);
- }
-
- return retval;
-#else /* !HAVE_VSNPRINTF */
- gchar *printed;
- va_list args;
-
- g_return_val_if_fail (str != NULL, 0);
- g_return_val_if_fail (n > 0, 0);
- g_return_val_if_fail (fmt != NULL, 0);
-
- va_start (args, fmt);
- printed = g_strdup_vprintf (fmt, args);
- va_end (args);
-
- strncpy (str, printed, n);
- str[n-1] = '\0';
-
- g_free (printed);
-
- return strlen (str);
-#endif /* !HAVE_VSNPRINTF */
-}
-
-gint
-g_vsnprintf (gchar *str,
- gulong n,
- gchar const *fmt,
- va_list args)
-{
-#ifdef HAVE_VSNPRINTF
- gint retval;
-
- g_return_val_if_fail (str != NULL, 0);
- g_return_val_if_fail (n > 0, 0);
- g_return_val_if_fail (fmt != NULL, 0);
-
- retval = vsnprintf (str, n, fmt, args);
-
- if (retval < 0)
- {
- str[n-1] = '\0';
- retval = strlen (str);
- }
-
- return retval;
-#else /* !HAVE_VSNPRINTF */
- gchar *printed;
-
- g_return_val_if_fail (str != NULL, 0);
- g_return_val_if_fail (n > 0, 0);
- g_return_val_if_fail (fmt != NULL, 0);
-
- printed = g_strdup_vprintf (fmt, args);
- strncpy (str, printed, n);
- str[n-1] = '\0';
-
- g_free (printed);
-
- return strlen (str);
-#endif /* !HAVE_VSNPRINTF */
-}
-
-guint
-g_parse_debug_string (const gchar *string,
- GDebugKey *keys,
- guint nkeys)
-{
- guint i;
- guint result = 0;
-
- g_return_val_if_fail (string != NULL, 0);
-
- if (!g_strcasecmp (string, "all"))
- {
- for (i=0; i<nkeys; i++)
- result |= keys[i].value;
- }
- else
- {
- gchar *str = g_strdup (string);
- gchar *p = str;
- gchar *q;
- gboolean done = FALSE;
-
- while (*p && !done)
- {
- q = strchr (p, ':');
- if (!q)
- {
- q = p + strlen(p);
- done = TRUE;
- }
-
- *q = 0;
-
- for (i=0; i<nkeys; i++)
- if (!g_strcasecmp(keys[i].key, p))
- result |= keys[i].value;
-
- p = q+1;
- }
-
- g_free (str);
- }
-
- return result;
-}
-
-gchar*
-g_basename (const gchar *file_name)
-{
- register gchar *base;
-
- g_return_val_if_fail (file_name != NULL, NULL);
-
- base = strrchr (file_name, G_DIR_SEPARATOR);
- if (base)
- return base + 1;
-
-#ifdef NATIVE_WIN32
- if (isalpha (file_name[0]) && file_name[1] == ':')
- return (gchar*) file_name + 2;
-#endif /* NATIVE_WIN32 */
-
- return (gchar*) file_name;
-}
-
-gboolean
-g_path_is_absolute (const gchar *file_name)
-{
- g_return_val_if_fail (file_name != NULL, FALSE);
-
- if (file_name[0] == G_DIR_SEPARATOR)
- return TRUE;
-
-#ifdef NATIVE_WIN32
- if (isalpha (file_name[0]) && file_name[1] == ':' && file_name[2] == G_DIR_SEPARATOR)
- return TRUE;
-#endif
-
- return FALSE;
-}
-
-gchar*
-g_path_skip_root (gchar *file_name)
-{
- g_return_val_if_fail (file_name != NULL, NULL);
-
- if (file_name[0] == G_DIR_SEPARATOR)
- return file_name + 1;
-
-#ifdef NATIVE_WIN32
- if (isalpha (file_name[0]) && file_name[1] == ':' && file_name[2] == G_DIR_SEPARATOR)
- return file_name + 3;
-#endif
-
- return NULL;
-}
-
-gchar*
-g_dirname (const gchar *file_name)
-{
- register gchar *base;
- register guint len;
-
- g_return_val_if_fail (file_name != NULL, NULL);
-
- base = strrchr (file_name, G_DIR_SEPARATOR);
- if (!base)
- return g_strdup (".");
- while (base > file_name && *base == G_DIR_SEPARATOR)
- base--;
- len = (guint) 1 + base - file_name;
-
- base = g_new (gchar, len + 1);
- g_memmove (base, file_name, len);
- base[len] = 0;
-
- return base;
-}
-
-gchar*
-g_get_current_dir (void)
-{
- gchar *buffer;
- gchar *dir;
-
- buffer = g_new (gchar, G_PATH_LENGTH);
- *buffer = 0;
-
- /* We don't use getcwd(3) on SUNOS, because, it does a popen("pwd")
- * and, if that wasn't bad enough, hangs in doing so.
- */
-#if defined (sun) && !defined (__SVR4)
- dir = getwd (buffer);
-#else /* !sun */
- dir = getcwd (buffer, G_PATH_LENGTH - 1);
-#endif /* !sun */
-
- if (!dir || !*buffer)
- {
- /* hm, should we g_error() out here?
- * this can happen if e.g. "./" has mode \0000
- */
- buffer[0] = G_DIR_SEPARATOR;
- buffer[1] = 0;
- }
-
- dir = g_strdup (buffer);
- g_free (buffer);
-
- return dir;
-}
-
-gchar*
-g_getenv (const gchar *variable)
-{
-#ifndef NATIVE_WIN32
- g_return_val_if_fail (variable != NULL, NULL);
-
- return getenv (variable);
-#else
- gchar *v;
- guint k;
- static gchar *p = NULL;
- static gint l;
- gchar dummy[2];
-
- g_return_val_if_fail (variable != NULL, NULL);
-
- v = getenv (variable);
- if (!v)
- return NULL;
-
- /* On Windows NT, it is relatively typical that environment variables
- * contain references to other environment variables. Handle that by
- * calling ExpandEnvironmentStrings.
- */
-
- /* First check how much space we need */
- k = ExpandEnvironmentStrings (v, dummy, 2);
- /* Then allocate that much, and actualy do the expansion */
- if (p == NULL)
- {
- p = g_malloc (k);
- l = k;
- }
- else if (k > l)
- {
- p = g_realloc (p, k);
- l = k;
- }
- ExpandEnvironmentStrings (v, p, k);
- return p;
-#endif
-}
-
-
-G_LOCK_DEFINE_STATIC (g_utils_global);
-
-static gchar *g_tmp_dir = NULL;
-static gchar *g_user_name = NULL;
-static gchar *g_real_name = NULL;
-static gchar *g_home_dir = NULL;
-
-/* HOLDS: g_utils_global_lock */
-static void
-g_get_any_init (void)
-{
- if (!g_tmp_dir)
- {
- g_tmp_dir = g_strdup (g_getenv ("TMPDIR"));
- if (!g_tmp_dir)
- g_tmp_dir = g_strdup (g_getenv ("TMP"));
- if (!g_tmp_dir)
- g_tmp_dir = g_strdup (g_getenv ("TEMP"));
-
-#ifdef P_tmpdir
- if (!g_tmp_dir)
- {
- int k;
- g_tmp_dir = g_strdup (P_tmpdir);
- k = strlen (g_tmp_dir);
- if (g_tmp_dir[k-1] == G_DIR_SEPARATOR)
- g_tmp_dir[k-1] = '\0';
- }
-#endif
-
- if (!g_tmp_dir)
- {
-#ifndef NATIVE_WIN32
- g_tmp_dir = g_strdup ("/tmp");
-#else /* NATIVE_WIN32 */
- g_tmp_dir = g_strdup ("C:\\");
-#endif /* NATIVE_WIN32 */
- }
-
- if (!g_home_dir)
- g_home_dir = g_strdup (g_getenv ("HOME"));
-
-#ifdef NATIVE_WIN32
- if (!g_home_dir)
- {
- /* The official way to specify a home directory on NT is
- * the HOMEDRIVE and HOMEPATH environment variables.
- *
- * This is inside #ifdef NATIVE_WIN32 because with the cygwin dll,
- * HOME should be a POSIX style pathname.
- */
-
- if (getenv ("HOMEDRIVE") != NULL && getenv ("HOMEPATH") != NULL)
- {
- gchar *homedrive, *homepath;
-
- homedrive = g_strdup (g_getenv ("HOMEDRIVE"));
- homepath = g_strdup (g_getenv ("HOMEPATH"));
-
- g_home_dir = g_strconcat (homedrive, homepath, NULL);
- g_free (homedrive);
- g_free (homepath);
- }
- }
-#endif /* !NATIVE_WIN32 */
-
-#ifdef HAVE_PWD_H
- {
- struct passwd *pw = NULL;
- gpointer buffer = NULL;
-
-# ifdef HAVE_GETPWUID_R
- struct passwd pwd;
-# ifdef _SC_GETPW_R_SIZE_MAX
- /* This reurns the maximum length */
- guint bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
-# else /* _SC_GETPW_R_SIZE_MAX */
- guint bufsize = 64;
-# endif /* _SC_GETPW_R_SIZE_MAX */
- gint error;
-
- do
- {
- g_free (buffer);
- buffer = g_malloc (bufsize);
- errno = 0;
-
-# ifdef HAVE_GETPWUID_R_POSIX
- error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw);
- error = error < 0 ? errno : error;
-# else /* !HAVE_GETPWUID_R_POSIX */
-# ifdef _AIX
- error = getpwuid_r (getuid (), &pwd, buffer, bufsize);
- pw = error == 0 ? &pwd : NULL;
-# else /* !_AIX */
- pw = getpwuid_r (getuid (), &pwd, buffer, bufsize);
- error = pw ? 0 : errno;
-# endif /* !_AIX */
-# endif /* !HAVE_GETPWUID_R_POSIX */
-
- if (!pw)
- {
- /* we bail out prematurely if the user id can't be found
- * (should be pretty rare case actually), or if the buffer
- * should be sufficiently big and lookups are still not
- * successfull.
- */
- if (error == 0 || error == ENOENT)
- {
- g_warning ("getpwuid_r(): failed due to: No such user %d.",
- getuid ());
- break;
- }
- if (bufsize > 32 * 1024)
- {
- g_warning ("getpwuid_r(): failed due to: %s.",
- g_strerror (error));
- break;
- }
-
- bufsize *= 2;
- }
- }
- while (!pw);
-# endif /* !HAVE_GETPWUID_R */
-
- if (!pw)
- {
- setpwent ();
- pw = getpwuid (getuid ());
- endpwent ();
- }
- if (pw)
- {
- g_user_name = g_strdup (pw->pw_name);
- g_real_name = g_strdup (pw->pw_gecos);
- if (!g_home_dir)
- g_home_dir = g_strdup (pw->pw_dir);
- }
- g_free (buffer);
- }
-
-#else /* !HAVE_PWD_H */
-
-# ifdef NATIVE_WIN32
- {
- guint len = 17;
- gchar buffer[17];
-
- if (GetUserName (buffer, &len))
- {
- g_user_name = g_strdup (buffer);
- g_real_name = g_strdup (buffer);
- }
- }
-# endif /* NATIVE_WIN32 */
-
-#endif /* !HAVE_PWD_H */
-
- if (!g_user_name)
- g_user_name = g_strdup ("somebody");
- if (!g_real_name)
- g_real_name = g_strdup ("Unknown");
- else
- {
- gchar *p;
-
- for (p = g_real_name; *p; p++)
- if (*p == ',')
- {
- *p = 0;
- p = g_strdup (g_real_name);
- g_free (g_real_name);
- g_real_name = p;
- break;
- }
- }
- }
-}
-
-gchar*
-g_get_user_name (void)
-{
- G_LOCK (g_utils_global);
- if (!g_tmp_dir)
- g_get_any_init ();
- G_UNLOCK (g_utils_global);
-
- return g_user_name;
-}
-
-gchar*
-g_get_real_name (void)
-{
- G_LOCK (g_utils_global);
- if (!g_tmp_dir)
- g_get_any_init ();
- G_UNLOCK (g_utils_global);
-
- return g_real_name;
-}
-
-/* Return the home directory of the user. If there is a HOME
- * environment variable, its value is returned, otherwise use some
- * system-dependent way of finding it out. If no home directory can be
- * deduced, return NULL.
- */
-
-gchar*
-g_get_home_dir (void)
-{
- G_LOCK (g_utils_global);
- if (!g_tmp_dir)
- g_get_any_init ();
- G_UNLOCK (g_utils_global);
-
- return g_home_dir;
-}
-
-/* Return a directory to be used to store temporary files. This is the
- * value of the TMPDIR, TMP or TEMP environment variables (they are
- * checked in that order). If none of those exist, use P_tmpdir from
- * stdio.h. If that isn't defined, return "/tmp" on POSIXly systems,
- * and C:\ on Windows.
- */
-
-gchar*
-g_get_tmp_dir (void)
-{
- G_LOCK (g_utils_global);
- if (!g_tmp_dir)
- g_get_any_init ();
- G_UNLOCK (g_utils_global);
-
- return g_tmp_dir;
-}
-
-static gchar *g_prgname = NULL;
-
-gchar*
-g_get_prgname (void)
-{
- gchar* retval;
-
- G_LOCK (g_utils_global);
- retval = g_prgname;
- G_UNLOCK (g_utils_global);
-
- return retval;
-}
-
-void
-g_set_prgname (const gchar *prgname)
-{
- gchar *c;
-
- G_LOCK (g_utils_global);
- c = g_prgname;
- g_prgname = g_strdup (prgname);
- g_free (c);
- G_UNLOCK (g_utils_global);
-}
-
-guint
-g_direct_hash (gconstpointer v)
-{
- return GPOINTER_TO_UINT (v);
-}
-
-gint
-g_direct_equal (gconstpointer v1,
- gconstpointer v2)
-{
- return v1 == v2;
-}
-
-gint
-g_int_equal (gconstpointer v1,
- gconstpointer v2)
-{
- return *((const gint*) v1) == *((const gint*) v2);
-}
-
-guint
-g_int_hash (gconstpointer v)
-{
- return *(const gint*) v;
-}
-
-#if 0 /* Old IO Channels */
-
-GIOChannel*
-g_iochannel_new (gint fd)
-{
- GIOChannel *channel = g_new (GIOChannel, 1);
-
- channel->fd = fd;
-
-#ifdef NATIVE_WIN32
- channel->peer = 0;
- channel->peer_fd = 0;
- channel->offset = 0;
- channel->need_wakeups = 0;
-#endif /* NATIVE_WIN32 */
-
- return channel;
-}
-
-void
-g_iochannel_free (GIOChannel *channel)
-{
- g_return_if_fail (channel != NULL);
-
- g_free (channel);
-}
-
-void
-g_iochannel_close_and_free (GIOChannel *channel)
-{
- g_return_if_fail (channel != NULL);
-
- close (channel->fd);
-
- g_iochannel_free (channel);
-}
-
-#undef g_iochannel_wakeup_peer
-
-void
-g_iochannel_wakeup_peer (GIOChannel *channel)
-{
-#ifdef NATIVE_WIN32
- static guint message = 0;
-#endif
-
- g_return_if_fail (channel != NULL);
-
-#ifdef NATIVE_WIN32
- if (message == 0)
- message = RegisterWindowMessage ("gdk-pipe-readable");
-
-# if 0
- g_print ("g_iochannel_wakeup_peer: calling PostThreadMessage (%#x, %d, %d, %d)\n",
- channel->peer, message, channel->peer_fd, channel->offset);
-# endif
- PostThreadMessage (channel->peer, message,
- channel->peer_fd, channel->offset);
-#endif /* NATIVE_WIN32 */
-}
-
-#endif /* Old IO Channels */
-
-#ifdef NATIVE_WIN32
-#ifdef _MSC_VER
-
-int
-gwin_ftruncate (gint fd,
- guint size)
-{
- HANDLE hfile;
- guint curpos;
-
- g_return_val_if_fail (fd >= 0, -1);
-
- hfile = (HANDLE) _get_osfhandle (fd);
- curpos = SetFilePointer (hfile, 0, NULL, FILE_CURRENT);
- if (curpos == 0xFFFFFFFF
- || SetFilePointer (hfile, size, NULL, FILE_BEGIN) == 0xFFFFFFFF
- || !SetEndOfFile (hfile))
- {
- gint error = GetLastError ();
-
- switch (error)
- {
- case ERROR_INVALID_HANDLE:
- errno = EBADF;
- break;
- default:
- errno = EIO;
- break;
- }
-
- return -1;
- }
-
- return 0;
-}
-
-DIR*
-gwin_opendir (const char *dirname)
-{
- DIR *result;
- gchar *mask;
- guint k;
-
- g_return_val_if_fail (dirname != NULL, NULL);
-
- result = g_new0 (DIR, 1);
- result->find_file_data = g_new0 (WIN32_FIND_DATA, 1);
- result->dir_name = g_strdup (dirname);
-
- k = strlen (result->dir_name);
- if (k && result->dir_name[k - 1] == '\\')
- {
- result->dir_name[k - 1] = '\0';
- k--;
- }
- mask = g_strdup_printf ("%s\\*", result->dir_name);
-
- result->find_file_handle = (guint) FindFirstFile (mask,
- (LPWIN32_FIND_DATA) result->find_file_data);
- g_free (mask);
-
- if (result->find_file_handle == (guint) INVALID_HANDLE_VALUE)
- {
- int error = GetLastError ();
-
- g_free (result->dir_name);
- g_free (result->find_file_data);
- g_free (result);
- switch (error)
- {
- default:
- errno = EIO;
- return NULL;
- }
- }
- result->just_opened = TRUE;
-
- return result;
-}
-
-struct dirent*
-gwin_readdir (DIR *dir)
-{
- static struct dirent result;
-
- g_return_val_if_fail (dir != NULL, NULL);
-
- if (dir->just_opened)
- dir->just_opened = FALSE;
- else
- {
- if (!FindNextFile ((HANDLE) dir->find_file_handle,
- (LPWIN32_FIND_DATA) dir->find_file_data))
- {
- int error = GetLastError ();
-
- switch (error)
- {
- case ERROR_NO_MORE_FILES:
- return NULL;
- default:
- errno = EIO;
- return NULL;
- }
- }
- }
- strcpy (result.d_name, g_basename (((LPWIN32_FIND_DATA) dir->find_file_data)->cFileName));
-
- return &result;
-}
-
-void
-gwin_rewinddir (DIR *dir)
-{
- gchar *mask;
-
- g_return_if_fail (dir != NULL);
-
- if (!FindClose ((HANDLE) dir->find_file_handle))
- g_warning ("gwin_rewinddir(): FindClose() failed\n");
-
- mask = g_strdup_printf ("%s\\*", dir->dir_name);
- dir->find_file_handle = (guint) FindFirstFile (mask,
- (LPWIN32_FIND_DATA) dir->find_file_data);
- g_free (mask);
-
- if (dir->find_file_handle == (guint) INVALID_HANDLE_VALUE)
- {
- int error = GetLastError ();
-
- switch (error)
- {
- default:
- errno = EIO;
- return;
- }
- }
- dir->just_opened = TRUE;
-}
-
-gint
-gwin_closedir (DIR *dir)
-{
- g_return_val_if_fail (dir != NULL, -1);
-
- if (!FindClose ((HANDLE) dir->find_file_handle))
- {
- int error = GetLastError ();
-
- switch (error)
- {
- default:
- errno = EIO; return -1;
- }
- }
-
- g_free (dir->dir_name);
- g_free (dir->find_file_data);
- g_free (dir);
-
- return 0;
-}
-
-#endif /* _MSC_VER */
-
-#endif /* NATIVE_WIN32 */
diff --git a/tests/testgdate.c b/tests/testgdate.c
deleted file mode 100644
index f74e00a3b..000000000
--- a/tests/testgdate.c
+++ /dev/null
@@ -1,486 +0,0 @@
-
-#include "glib.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <locale.h>
-#include <time.h>
-
-gboolean failed = FALSE;
-guint32 passed = 0;
-guint32 notpassed = 0;
-
-#define TEST(m,cond) G_STMT_START { failed = !(cond); \
-if (failed) \
- { ++notpassed; \
- if (!m) \
- g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
- else \
- g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
- } \
-else \
- ++passed; \
- if ((passed+notpassed) % 10000 == 0) g_print ("."); fflush (stdout); \
-} G_STMT_END
-
-void g_date_debug_print(GDate* d)
-{
- if (!d) g_print("NULL!\n");
- else
- g_print("julian: %u (%s) DMY: %u %u %u (%s)\n",
- d->julian_days,
- d->julian ? "valid" : "invalid",
- d->day,
- d->month,
- d->year,
- d->dmy ? "valid" : "invalid");
-
- fflush(stdout);
-}
-
-int main(int argc, char** argv)
-{
- GDate* d;
- guint32 j;
- GDateMonth m;
- GDateYear y, prev_y;
- GDateDay day;
- gchar buf[101];
- gchar* loc;
- /* Try to get all the leap year cases. */
- GDateYear check_years[] = {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
- 11, 12, 13, 14, 98, 99, 100, 101, 102, 103, 397,
- 398, 399, 400, 401, 402, 403, 404, 405, 406,
- 1598, 1599, 1600, 1601, 1602, 1650, 1651,
- 1897, 1898, 1899, 1900, 1901, 1902, 1903,
- 1961, 1962, 1963, 1964, 1965, 1967,
- 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976,
- 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985,
- 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
- 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
- 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012,
- 3000, 3001, 3002, 3998, 3999, 4000, 4001, 4002, 4003
- };
- guint n_check_years = sizeof(check_years)/sizeof(GDateYear);
- guint i;
- gboolean discontinuity;
-
- g_print("checking GDate...");
-
- TEST("sizeof(GDate) is not more than 8 bytes on this platform", sizeof(GDate) < 9);
-
- d = g_date_new();
-
- TEST("Empty constructor produces invalid date", !g_date_valid(d));
-
- g_date_free(d);
-
- d = g_date_new_dmy(1,1,1);
-
- TEST("January 1, Year 1 created and valid", g_date_valid(d));
-
- j = g_date_julian(d);
-
- TEST("January 1, Year 1 is Julian date 1", j == 1);
-
- TEST("Returned month is January", g_date_month(d) == G_DATE_JANUARY);
- TEST("Returned day is 1", g_date_day(d) == 1);
- TEST("Returned year is 1", g_date_year(d) == 1);
-
- TEST("Bad month is invalid", !g_date_valid_month(G_DATE_BAD_MONTH));
- TEST("Month 13 is invalid", !g_date_valid_month(13));
- TEST("Bad day is invalid", !g_date_valid_day(G_DATE_BAD_DAY));
- TEST("Day 32 is invalid", !g_date_valid_day(32));
- TEST("Bad year is invalid", !g_date_valid_year(G_DATE_BAD_YEAR));
- TEST("Bad julian is invalid", !g_date_valid_julian(G_DATE_BAD_JULIAN));
- TEST("Bad weekday is invalid", !g_date_valid_weekday(G_DATE_BAD_WEEKDAY));
- TEST("Year 2000 is a leap year", g_date_is_leap_year(2000));
- TEST("Year 1999 is not a leap year", !g_date_is_leap_year(1999));
- TEST("Year 1996 is a leap year", g_date_is_leap_year(1996));
- TEST("Year 1600 is a leap year", g_date_is_leap_year(1600));
- TEST("Year 2100 is not a leap year", !g_date_is_leap_year(2100));
- TEST("Year 1800 is not a leap year", !g_date_is_leap_year(1800));
-
- g_date_free(d);
-
- loc = setlocale(LC_ALL,"");
- if (loc)
- g_print("\nLocale set to %s\n", loc);
- else
- g_print("\nLocale unchanged\n");
-
- d = g_date_new();
- g_date_set_time(d, time(NULL));
- TEST("Today is valid", g_date_valid(d));
-
- g_date_strftime(buf,100,"Today is a %A, %x\n", d);
- g_print("%s", buf);
-
- g_date_set_time(d, 1);
- TEST("Beginning of Unix epoch is valid", g_date_valid(d));
-
- g_date_strftime(buf,100,"1 second into the Unix epoch it was a %A, in the month of %B, %x\n", d);
- g_print("%s", buf);
-
- g_date_set_julian(d, 1);
- TEST("GDate's \"Julian\" epoch's first day is valid", g_date_valid(d));
-
- g_date_strftime(buf,100,"Our \"Julian\" epoch begins on a %A, in the month of %B, %x\n",
- d);
- g_print("%s", buf);
-
- g_date_set_dmy(d, 10, 1, 2000);
-
- g_date_strftime(buf,100,"%x", d);
-
- g_date_set_parse(d, buf);
- /* Note: this test will hopefully work, but no promises. */
- TEST("Successfully parsed a %x-formatted string",
- g_date_valid(d) &&
- g_date_month(d) == 1 &&
- g_date_day(d) == 10 &&
- g_date_year(d) == 2000);
- if (failed)
- g_date_debug_print(d);
-
- g_date_free(d);
-
- j = G_DATE_BAD_JULIAN;
-
- i = 0;
- discontinuity = TRUE;
- y = check_years[0];
- prev_y = G_DATE_BAD_YEAR;
- while (i < n_check_years)
- {
- guint32 first_day_of_year = G_DATE_BAD_JULIAN;
- guint16 days_in_year = g_date_is_leap_year(y) ? 366 : 365;
- guint sunday_week_of_year = 0;
- guint sunday_weeks_in_year = g_date_sunday_weeks_in_year(y);
- guint monday_week_of_year = 0;
- guint monday_weeks_in_year = g_date_monday_weeks_in_year(y);
-
- if (discontinuity)
- g_print(" (Break in sequence of requested years to check)\n");
-
- g_print("Checking year %u", y);
-
- TEST("Year is valid", g_date_valid_year(y));
-
- TEST("Number of Sunday weeks in year is 52 or 53",
- sunday_weeks_in_year == 52 || sunday_weeks_in_year == 53);
-
- TEST("Number of Monday weeks in year is 52 or 53",
- monday_weeks_in_year == 52 || monday_weeks_in_year == 53);
-
- m = 1;
- while (m < 13)
- {
- guint8 dim = g_date_days_in_month(m,y);
- GDate days[31]; /* This is the fast way, no allocation */
-
- TEST("Sensible number of days in month", (dim > 0 && dim < 32));
-
- TEST("Month between 1 and 12 is valid", g_date_valid_month(m));
-
- day = 1;
-
- g_date_clear(days, 31);
-
- while (day <= dim)
- {
- guint i;
- GDate tmp;
-
- TEST("DMY triplet is valid", g_date_valid_dmy(day,m,y));
-
- /* Create GDate with triplet */
-
- d = &days[day-1];
-
- TEST("Cleared day is invalid", !g_date_valid(d));
-
- g_date_set_dmy(d,day,m,y);
-
- TEST("Set day is valid", g_date_valid(d));
-
- if (m == G_DATE_JANUARY && day == 1)
- {
- first_day_of_year = g_date_julian(d);
- }
-
- g_assert(first_day_of_year != G_DATE_BAD_JULIAN);
-
- TEST("Date with DMY triplet is valid", g_date_valid(d));
- TEST("Month accessor works", g_date_month(d) == m);
- TEST("Year accessor works", g_date_year(d) == y);
- TEST("Day of month accessor works", g_date_day(d) == day);
-
- TEST("Day of year is consistent with Julian dates",
- ((g_date_julian(d) + 1 - first_day_of_year) ==
- (g_date_day_of_year(d))));
-
- if (failed)
- {
- g_print("first day: %u this day: %u day of year: %u\n",
- first_day_of_year,
- g_date_julian(d),
- g_date_day_of_year(d));
- }
-
- if (m == G_DATE_DECEMBER && day == 31)
- {
- TEST("Last day of year equals number of days in year",
- g_date_day_of_year(d) == days_in_year);
- if (failed)
- {
- g_print("last day: %u days in year: %u\n",
- g_date_day_of_year(d), days_in_year);
- }
- }
-
- TEST("Day of year is not more than number of days in the year",
- g_date_day_of_year(d) <= days_in_year);
-
- TEST("Monday week of year is not more than number of weeks in the year",
- g_date_monday_week_of_year(d) <= monday_weeks_in_year);
- if (failed)
- {
- g_print("Weeks in year: %u\n", monday_weeks_in_year);
- g_date_debug_print(d);
- }
- TEST("Monday week of year is >= than last week of year",
- g_date_monday_week_of_year(d) >= monday_week_of_year);
-
- if (g_date_weekday(d) == G_DATE_MONDAY)
- {
-
- TEST("Monday week of year on Monday 1 more than previous day's week of year",
- (g_date_monday_week_of_year(d) - monday_week_of_year) == 1);
- }
- else
- {
- TEST("Monday week of year on non-Monday 0 more than previous day's week of year",
- (g_date_monday_week_of_year(d) - monday_week_of_year) == 0);
- }
-
-
- monday_week_of_year = g_date_monday_week_of_year(d);
-
-
- TEST("Sunday week of year is not more than number of weeks in the year",
- g_date_sunday_week_of_year(d) <= sunday_weeks_in_year);
- if (failed)
- {
- g_date_debug_print(d);
- }
- TEST("Sunday week of year is >= than last week of year",
- g_date_sunday_week_of_year(d) >= sunday_week_of_year);
-
- if (g_date_weekday(d) == G_DATE_SUNDAY)
- {
- TEST("Sunday week of year on Sunday 1 more than previous day's week of year",
- (g_date_sunday_week_of_year(d) - sunday_week_of_year) == 1);
- }
- else
- {
- TEST("Sunday week of year on non-Sunday 0 more than previous day's week of year",
- (g_date_sunday_week_of_year(d) - sunday_week_of_year) == 0);
- }
-
- sunday_week_of_year = g_date_sunday_week_of_year(d);
-
- TEST("Date is equal to itself",
- g_date_compare(d,d) == 0);
-
-
- /*************** Increments ***********/
-
- i = 1;
- while (i < 402) /* Need to get 400 year increments in */
- {
-
- /***** Days ******/
- tmp = *d;
- g_date_add_days(d, i);
-
- TEST("Adding days gives a value greater than previous",
- g_date_compare(d, &tmp) > 0);
-
- g_date_subtract_days(d, i);
- TEST("Forward days then backward days returns us to current day",
- g_date_day(d) == day);
-
- if (failed)
- {
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
- g_date_debug_print(d);
- }
-
- TEST("Forward days then backward days returns us to current month",
- g_date_month(d) == m);
-
- if (failed)
- {
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
- g_date_debug_print(d);
- }
-
- TEST("Forward days then backward days returns us to current year",
- g_date_year(d) == y);
-
- if (failed)
- {
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
- g_date_debug_print(d);
- }
-
- /******* Months ********/
-
- tmp = *d;
- g_date_add_months(d, i);
- TEST("Adding months gives a larger value",
- g_date_compare(d, &tmp) > 0);
- g_date_subtract_months(d, i);
-
- TEST("Forward months then backward months returns us to current month",
- g_date_month(d) == m);
-
- if (failed)
- {
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
- g_date_debug_print(d);
- }
-
- TEST("Forward months then backward months returns us to current year",
- g_date_year(d) == y);
-
- if (failed)
- {
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
- g_date_debug_print(d);
- }
-
-
- if (day < 29)
- {
- /* Day should be unchanged */
-
- TEST("Forward months then backward months returns us to current day",
- g_date_day(d) == day);
-
- if (failed)
- {
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
- g_date_debug_print(d);
- }
- }
- else
- {
- /* reset the day for later tests */
- g_date_set_day(d, day);
- }
-
- /******* Years ********/
-
- tmp = *d;
- g_date_add_years(d, i);
-
- TEST("Adding years gives a larger value",
- g_date_compare(d,&tmp) > 0);
-
- g_date_subtract_years(d, i);
-
- TEST("Forward years then backward years returns us to current month",
- g_date_month(d) == m);
-
- if (failed)
- {
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
- g_date_debug_print(d);
- }
-
- TEST("Forward years then backward years returns us to current year",
- g_date_year(d) == y);
-
- if (failed)
- {
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
- g_date_debug_print(d);
- }
-
- if (m != 2 && day != 29)
- {
- TEST("Forward years then backward years returns us to current day",
- g_date_day(d) == day);
-
- if (failed)
- {
- g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y);
- g_date_debug_print(d);
- }
- }
- else
- {
- g_date_set_day(d, day); /* reset */
- }
-
- i += 10;
- }
-
- /***** increment test relative to our local Julian count */
-
- if (!discontinuity) {
-
- /* We can only run sequence tests between sequential years */
-
- TEST("Julians are sequential with increment 1",
- j+1 == g_date_julian(d));
- if (failed)
- {
- g_print("Out of sequence, prev: %u expected: %u got: %u\n",
- j, j+1, g_date_julian(d));
- }
-
- g_date_add_days(d,1);
- TEST("Next day has julian 1 higher",
- g_date_julian(d) == j + 2);
- g_date_subtract_days(d, 1);
-
- if (j != G_DATE_BAD_JULIAN)
- {
- g_date_subtract_days(d, 1);
-
- TEST("Previous day has julian 1 lower",
- g_date_julian(d) == j);
-
- g_date_add_days(d, 1); /* back to original */
- }
- }
- discontinuity = FALSE; /* goes away now */
-
- fflush(stdout);
- fflush(stderr);
-
- j = g_date_julian(d); /* inc current julian */
-
- ++day;
- }
- ++m;
- }
- g_print(" done\n");
- ++i;
- prev_y = y;
- y = check_years[i];
- if (prev_y == G_DATE_BAD_YEAR ||
- (prev_y + 1) != y) discontinuity = TRUE;
- }
-
-
- g_print("\n%u tests passed, %u failed\n",passed, notpassed);
-
- return 0;
-}
-
-
diff --git a/tests/testgdateparser.c b/tests/testgdateparser.c
deleted file mode 100644
index 1e482ffb5..000000000
--- a/tests/testgdateparser.c
+++ /dev/null
@@ -1,109 +0,0 @@
-
-#include "glib.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <locale.h>
-
-void g_date_debug_print(GDate* d)
-{
- if (!d) g_print("NULL!\n");
- else
- g_print("julian: %u (%s) DMY: %u %u %u (%s)\n",
- d->julian_days,
- d->julian ? "valid" : "invalid",
- d->day,
- d->month,
- d->year,
- d->dmy ? "valid" : "invalid");
-
- fflush(stdout);
-}
-
-/* These only work in the POSIX locale, maybe C too -
- * type POSIX into the program to check them
- */
-char* posix_tests [] = {
- "19981024",
- "981024",
- "October 1998",
- "October 98",
- "oCT 98",
- "10/24/98",
- "10 -- 24 -- 98",
- "10/24/1998",
- "October 24, 1998",
- NULL
-};
-
-int main(int argc, char** argv)
-{
- GDate* d;
- gchar* loc;
- gchar input[1024];
-
- loc = setlocale(LC_ALL,"");
- if (loc)
- g_print("\nLocale set to %s\n", loc);
- else
- g_print("\nLocale unchanged\n");
-
- d = g_date_new();
-
- while (fgets(input, 1023, stdin))
- {
- if (input[0] == '\n')
- {
- g_print("Enter a date to parse and press enter, or type `POSIX':\n");
- continue;
- }
-
- if (strcmp(input,"POSIX\n") == 0)
- {
- char** s = posix_tests;
- while (*s) {
- g_date_set_parse(d, *s);
-
- g_print("POSIXy parse test `%s' ...", *s);
-
- if (!g_date_valid(d))
- {
- g_print(" failed.\n");
- }
- else
- {
- gchar buf[256];
-
- g_date_strftime(buf,100," parsed `%x' (%B %d %Y)\n",
- d);
- g_print("%s", buf);
- }
-
- ++s;
- }
- }
- else
- {
- g_date_set_parse(d, input);
-
- if (!g_date_valid(d))
- {
- g_print("Parse failed.\n");
- }
- else
- {
- gchar buf[256];
-
- g_date_strftime(buf,100,"Parsed: `%x' (%B %d %Y)\n",
- d);
- g_print("%s", buf);
- }
- }
- }
-
- g_date_free(d);
-
- return 0;
-}
-
-
diff --git a/tests/testglib.c b/tests/testglib.c
deleted file mode 100644
index 843b49ede..000000000
--- a/tests/testglib.c
+++ /dev/null
@@ -1,921 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * 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.
- */
-
-/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
- * file for a list of people on the GLib Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#undef G_LOG_DOMAIN
-
-#include <stdio.h>
-#include <string.h>
-#include "glib.h"
-
-int array[10000];
-gboolean failed = FALSE;
-
-#define TEST(m,cond) G_STMT_START { failed = !(cond); \
-if (failed) \
- { if (!m) \
- g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
- else \
- g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
- } \
-else \
- g_print ("."); fflush (stdout); \
-} G_STMT_END
-
-#define C2P(c) ((gpointer) ((long) (c)))
-#define P2C(p) ((gchar) ((long) (p)))
-
-#define GLIB_TEST_STRING "el dorado "
-#define GLIB_TEST_STRING_5 "el do"
-
-static gboolean
-node_build_string (GNode *node,
- gpointer data)
-{
- gchar **p = data;
- gchar *string;
- gchar c[2] = "_";
-
- c[0] = P2C (node->data);
-
- string = g_strconcat (*p ? *p : "", c, NULL);
- g_free (*p);
- *p = string;
-
- return FALSE;
-}
-
-static void
-g_node_test (void)
-{
- GNode *root;
- GNode *node;
- GNode *node_B;
- GNode *node_F;
- GNode *node_G;
- GNode *node_J;
- guint i;
- gchar *tstring;
-
- g_print ("checking n-way trees: ");
- failed = FALSE;
-
- root = g_node_new (C2P ('A'));
- TEST (NULL, g_node_depth (root) == 1 && g_node_max_height (root) == 1);
-
- node_B = g_node_new (C2P ('B'));
- g_node_append (root, node_B);
- TEST (NULL, root->children == node_B);
-
- g_node_append_data (node_B, C2P ('E'));
- g_node_prepend_data (node_B, C2P ('C'));
- g_node_insert (node_B, 1, g_node_new (C2P ('D')));
-
- node_F = g_node_new (C2P ('F'));
- g_node_append (root, node_F);
- TEST (NULL, root->children->next == node_F);
-
- node_G = g_node_new (C2P ('G'));
- g_node_append (node_F, node_G);
- node_J = g_node_new (C2P ('J'));
- g_node_prepend (node_G, node_J);
- g_node_insert (node_G, 42, g_node_new (C2P ('K')));
- g_node_insert_data (node_G, 0, C2P ('H'));
- g_node_insert (node_G, 1, g_node_new (C2P ('I')));
-
- TEST (NULL, g_node_depth (root) == 1);
- TEST (NULL, g_node_max_height (root) == 4);
- TEST (NULL, g_node_depth (node_G->children->next) == 4);
- TEST (NULL, g_node_n_nodes (root, G_TRAVERSE_LEAFS) == 7);
- TEST (NULL, g_node_n_nodes (root, G_TRAVERSE_NON_LEAFS) == 4);
- TEST (NULL, g_node_n_nodes (root, G_TRAVERSE_ALL) == 11);
- TEST (NULL, g_node_max_height (node_F) == 3);
- TEST (NULL, g_node_n_children (node_G) == 4);
- TEST (NULL, g_node_find_child (root, G_TRAVERSE_ALL, C2P ('F')) == node_F);
- TEST (NULL, g_node_find (root, G_LEVEL_ORDER, G_TRAVERSE_NON_LEAFS, C2P ('I')) == NULL);
- TEST (NULL, g_node_find (root, G_IN_ORDER, G_TRAVERSE_LEAFS, C2P ('J')) == node_J);
-
- for (i = 0; i < g_node_n_children (node_B); i++)
- {
- node = g_node_nth_child (node_B, i);
- TEST (NULL, P2C (node->data) == ('C' + i));
- }
-
- for (i = 0; i < g_node_n_children (node_G); i++)
- TEST (NULL, g_node_child_position (node_G, g_node_nth_child (node_G, i)) == i);
-
- /* we have built: A
- * / \
- * B F
- * / | \ \
- * C D E G
- * / /\ \
- * H I J K
- *
- * for in-order traversal, 'G' is considered to be the "left"
- * child of 'F', which will cause 'F' to be the last node visited.
- */
-
- tstring = NULL;
- g_node_traverse (root, G_PRE_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
- TEST (tstring, strcmp (tstring, "ABCDEFGHIJK") == 0);
- g_free (tstring); tstring = NULL;
- g_node_traverse (root, G_POST_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
- TEST (tstring, strcmp (tstring, "CDEBHIJKGFA") == 0);
- g_free (tstring); tstring = NULL;
- g_node_traverse (root, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
- TEST (tstring, strcmp (tstring, "CBDEAHGIJKF") == 0);
- g_free (tstring); tstring = NULL;
- g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
- TEST (tstring, strcmp (tstring, "ABFCDEGHIJK") == 0);
- g_free (tstring); tstring = NULL;
-
- g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_LEAFS, -1, node_build_string, &tstring);
- TEST (tstring, strcmp (tstring, "CDEHIJK") == 0);
- g_free (tstring); tstring = NULL;
- g_node_traverse (root, G_PRE_ORDER, G_TRAVERSE_NON_LEAFS, -1, node_build_string, &tstring);
- TEST (tstring, strcmp (tstring, "ABFG") == 0);
- g_free (tstring); tstring = NULL;
-
- g_node_reverse_children (node_B);
- g_node_reverse_children (node_G);
-
- g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
- TEST (tstring, strcmp (tstring, "ABFEDCGKJIH") == 0);
- g_free (tstring); tstring = NULL;
-
- g_node_destroy (root);
-
- /* allocation tests */
-
- root = g_node_new (NULL);
- node = root;
-
- for (i = 0; i < 2048; i++)
- {
- g_node_append (node, g_node_new (NULL));
- if ((i%5) == 4)
- node = node->children->next;
- }
- TEST (NULL, g_node_max_height (root) > 100);
- TEST (NULL, g_node_n_nodes (root, G_TRAVERSE_ALL) == 1 + 2048);
-
- g_node_destroy (root);
-
- if (!failed)
- g_print ("ok\n");
-}
-
-static gboolean
-my_hash_callback_remove (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- int *d = value;
-
- if ((*d) % 2)
- return TRUE;
-
- return FALSE;
-}
-
-static void
-my_hash_callback_remove_test (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- int *d = value;
-
- if ((*d) % 2)
- g_print ("bad!\n");
-}
-
-static void
-my_hash_callback (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- int *d = value;
- *d = 1;
-}
-
-static guint
-my_hash (gconstpointer key)
-{
- return (guint) *((const gint*) key);
-}
-
-static gint
-my_hash_compare (gconstpointer a,
- gconstpointer b)
-{
- return *((const gint*) a) == *((const gint*) b);
-}
-
-static gint
-my_list_compare_one (gconstpointer a, gconstpointer b)
-{
- gint one = *((const gint*)a);
- gint two = *((const gint*)b);
- return one-two;
-}
-
-static gint
-my_list_compare_two (gconstpointer a, gconstpointer b)
-{
- gint one = *((const gint*)a);
- gint two = *((const gint*)b);
- return two-one;
-}
-
-/* static void
-my_list_print (gpointer a, gpointer b)
-{
- gint three = *((gint*)a);
- g_print("%d", three);
-}; */
-
-static gint
-my_compare (gconstpointer a,
- gconstpointer b)
-{
- const char *cha = a;
- const char *chb = b;
-
- return *cha - *chb;
-}
-
-static gint
-my_traverse (gpointer key,
- gpointer value,
- gpointer data)
-{
- char *ch = key;
- g_print ("%c ", *ch);
- return FALSE;
-}
-
-int
-main (int argc,
- char *argv[])
-{
- GList *list, *t;
- GSList *slist, *st;
- GHashTable *hash_table;
- GMemChunk *mem_chunk;
- GStringChunk *string_chunk;
- GTimer *timer;
- gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- gint morenums[10] = { 8, 9, 7, 0, 3, 2, 5, 1, 4, 6};
- gchar *string;
-
- gchar *mem[10000], *tmp_string = NULL, *tmp_string_2;
- gint i, j;
- GArray *garray;
- GPtrArray *gparray;
- GByteArray *gbarray;
- GString *string1, *string2;
- GTree *tree;
- char chars[62];
- GRelation *relation;
- GTuples *tuples;
- gint data [1024];
- struct {
- gchar *filename;
- gchar *dirname;
- } dirname_checks[] = {
-#ifndef NATIVE_WIN32
- { "/", "/" },
- { "////", "/" },
- { ".////", "." },
- { ".", "." },
- { "..", "." },
- { "../", ".." },
- { "..////", ".." },
- { "", "." },
- { "a/b", "a" },
- { "a/b/", "a/b" },
- { "c///", "c" },
-#else
- { "\\", "\\" },
- { ".\\\\\\\\", "." },
- { ".", "." },
- { "..", "." },
- { "..\\", ".." },
- { "..\\\\\\\\", ".." },
- { "", "." },
- { "a\\b", "a" },
- { "a\\b\\", "a\\b" },
- { "c\\\\\\", "c" },
-#endif
- };
- guint n_dirname_checks = sizeof (dirname_checks) / sizeof (dirname_checks[0]);
- guint16 gu16t1 = 0x44afU, gu16t2 = 0xaf44U;
- guint32 gu32t1 = 0x02a7f109U, gu32t2 = 0x09f1a702U;
-#ifdef G_HAVE_GINT64
- guint64 gu64t1 = G_GINT64_CONSTANT(0x1d636b02300a7aa7U),
- gu64t2 = G_GINT64_CONSTANT(0xa77a0a30026b631dU);
-#endif
-
- g_print ("TestGLib v%u.%u.%u (i:%u b:%u)\n",
- glib_major_version,
- glib_minor_version,
- glib_micro_version,
- glib_interface_age,
- glib_binary_age);
-
- string = g_get_current_dir ();
- g_print ("cwd: %s\n", string);
- g_free (string);
- g_print ("user: %s\n", g_get_user_name ());
- g_print ("real: %s\n", g_get_real_name ());
- g_print ("home: %s\n", g_get_home_dir ());
- g_print ("tmp-dir: %s\n", g_get_tmp_dir ());
-
- /* type sizes */
- g_print ("checking size of gint8: %d", (int)sizeof (gint8));
- TEST (NULL, sizeof (gint8) == 1);
- g_print ("\nchecking size of gint16: %d", (int)sizeof (gint16));
- TEST (NULL, sizeof (gint16) == 2);
- g_print ("\nchecking size of gint32: %d", (int)sizeof (gint32));
- TEST (NULL, sizeof (gint32) == 4);
-#ifdef G_HAVE_GINT64
- g_print ("\nchecking size of gint64: %d", (int)sizeof (gint64));
- TEST (NULL, sizeof (gint64) == 8);
-#endif /* G_HAVE_GINT64 */
- g_print ("\n");
-
- g_print ("checking g_dirname()...");
- for (i = 0; i < n_dirname_checks; i++)
- {
- gchar *dirname;
-
- dirname = g_dirname (dirname_checks[i].filename);
- if (strcmp (dirname, dirname_checks[i].dirname) != 0)
- {
- g_print ("\nfailed for \"%s\"==\"%s\" (returned: \"%s\")\n",
- dirname_checks[i].filename,
- dirname_checks[i].dirname,
- dirname);
- n_dirname_checks = 0;
- }
- g_free (dirname);
- }
- if (n_dirname_checks)
- g_print ("ok\n");
-
- g_print ("checking doubly linked lists...");
-
- list = NULL;
- for (i = 0; i < 10; i++)
- list = g_list_append (list, &nums[i]);
- list = g_list_reverse (list);
-
- for (i = 0; i < 10; i++)
- {
- t = g_list_nth (list, i);
- if (*((gint*) t->data) != (9 - i))
- g_error ("Regular insert failed");
- }
-
- for (i = 0; i < 10; i++)
- if(g_list_position(list, g_list_nth (list, i)) != i)
- g_error("g_list_position does not seem to be the inverse of g_list_nth\n");
-
- g_list_free (list);
- list = NULL;
-
- for (i = 0; i < 10; i++)
- list = g_list_insert_sorted (list, &morenums[i], my_list_compare_one);
-
- /*
- g_print("\n");
- g_list_foreach (list, my_list_print, NULL);
- */
-
- for (i = 0; i < 10; i++)
- {
- t = g_list_nth (list, i);
- if (*((gint*) t->data) != i)
- g_error ("Sorted insert failed");
- }
-
- g_list_free (list);
- list = NULL;
-
- for (i = 0; i < 10; i++)
- list = g_list_insert_sorted (list, &morenums[i], my_list_compare_two);
-
- /*
- g_print("\n");
- g_list_foreach (list, my_list_print, NULL);
- */
-
- for (i = 0; i < 10; i++)
- {
- t = g_list_nth (list, i);
- if (*((gint*) t->data) != (9 - i))
- g_error ("Sorted insert failed");
- }
-
- g_list_free (list);
- list = NULL;
-
- for (i = 0; i < 10; i++)
- list = g_list_prepend (list, &morenums[i]);
-
- list = g_list_sort (list, my_list_compare_two);
-
- /*
- g_print("\n");
- g_list_foreach (list, my_list_print, NULL);
- */
-
- for (i = 0; i < 10; i++)
- {
- t = g_list_nth (list, i);
- if (*((gint*) t->data) != (9 - i))
- g_error ("Merge sort failed");
- }
-
- g_list_free (list);
-
- g_print ("ok\n");
-
-
- g_print ("checking singly linked lists...");
-
- slist = NULL;
- for (i = 0; i < 10; i++)
- slist = g_slist_append (slist, &nums[i]);
- slist = g_slist_reverse (slist);
-
- for (i = 0; i < 10; i++)
- {
- st = g_slist_nth (slist, i);
- if (*((gint*) st->data) != (9 - i))
- g_error ("failed");
- }
-
- g_slist_free (slist);
- slist = NULL;
-
- for (i = 0; i < 10; i++)
- slist = g_slist_insert_sorted (slist, &morenums[i], my_list_compare_one);
-
- /*
- g_print("\n");
- g_slist_foreach (slist, my_list_print, NULL);
- */
-
- for (i = 0; i < 10; i++)
- {
- st = g_slist_nth (slist, i);
- if (*((gint*) st->data) != i)
- g_error ("Sorted insert failed");
- }
-
- g_slist_free(slist);
- slist = NULL;
-
- for (i = 0; i < 10; i++)
- slist = g_slist_insert_sorted (slist, &morenums[i], my_list_compare_two);
-
- /*
- g_print("\n");
- g_slist_foreach (slist, my_list_print, NULL);
- */
-
- for (i = 0; i < 10; i++)
- {
- st = g_slist_nth (slist, i);
- if (*((gint*) st->data) != (9 - i))
- g_error("Sorted insert failed");
- }
-
- g_slist_free(slist);
- slist = NULL;
-
- for (i = 0; i < 10; i++)
- slist = g_slist_prepend (slist, &morenums[i]);
-
- slist = g_slist_sort (slist, my_list_compare_two);
-
- /*
- g_print("\n");
- g_slist_foreach (slist, my_list_print, NULL);
- */
-
- for (i = 0; i < 10; i++)
- {
- st = g_slist_nth (slist, i);
- if (*((gint*) st->data) != (9 - i))
- g_error("Sorted insert failed");
- }
-
- g_slist_free(slist);
-
- g_print ("ok\n");
-
-
- g_print ("checking binary trees...\n");
-
- tree = g_tree_new (my_compare);
- i = 0;
- for (j = 0; j < 10; j++, i++)
- {
- chars[i] = '0' + j;
- g_tree_insert (tree, &chars[i], &chars[i]);
- }
- for (j = 0; j < 26; j++, i++)
- {
- chars[i] = 'A' + j;
- g_tree_insert (tree, &chars[i], &chars[i]);
- }
- for (j = 0; j < 26; j++, i++)
- {
- chars[i] = 'a' + j;
- g_tree_insert (tree, &chars[i], &chars[i]);
- }
-
- g_print ("tree height: %d\n", g_tree_height (tree));
- g_print ("tree nnodes: %d\n", g_tree_nnodes (tree));
-
- g_print ("tree: ");
- g_tree_traverse (tree, my_traverse, G_IN_ORDER, NULL);
- g_print ("\n");
-
- for (i = 0; i < 10; i++)
- g_tree_remove (tree, &chars[i]);
-
- g_print ("tree height: %d\n", g_tree_height (tree));
- g_print ("tree nnodes: %d\n", g_tree_nnodes (tree));
-
- g_print ("tree: ");
- g_tree_traverse (tree, my_traverse, G_IN_ORDER, NULL);
- g_print ("\n");
-
- g_print ("ok\n");
-
-
- /* check n-way trees */
- g_node_test ();
-
- g_print ("checking mem chunks...");
-
- mem_chunk = g_mem_chunk_new ("test mem chunk", 50, 100, G_ALLOC_AND_FREE);
-
- for (i = 0; i < 10000; i++)
- {
- mem[i] = g_chunk_new (gchar, mem_chunk);
-
- for (j = 0; j < 50; j++)
- mem[i][j] = i * j;
- }
-
- for (i = 0; i < 10000; i++)
- {
- g_mem_chunk_free (mem_chunk, mem[i]);
- }
-
- g_print ("ok\n");
-
-
- g_print ("checking hash tables...");
-
- hash_table = g_hash_table_new (my_hash, my_hash_compare);
- for (i = 0; i < 10000; i++)
- {
- array[i] = i;
- g_hash_table_insert (hash_table, &array[i], &array[i]);
- }
- g_hash_table_foreach (hash_table, my_hash_callback, NULL);
-
- for (i = 0; i < 10000; i++)
- if (array[i] == 0)
- g_print ("%d\n", i);
-
- for (i = 0; i < 10000; i++)
- g_hash_table_remove (hash_table, &array[i]);
-
- for (i = 0; i < 10000; i++)
- {
- array[i] = i;
- g_hash_table_insert (hash_table, &array[i], &array[i]);
- }
-
- if (g_hash_table_foreach_remove (hash_table, my_hash_callback_remove, NULL) != 5000 ||
- g_hash_table_size (hash_table) != 5000)
- g_print ("bad!\n");
-
- g_hash_table_foreach (hash_table, my_hash_callback_remove_test, NULL);
-
-
- g_hash_table_destroy (hash_table);
-
- g_print ("ok\n");
-
-
- g_print ("checking string chunks...");
-
- string_chunk = g_string_chunk_new (1024);
-
- for (i = 0; i < 100000; i ++)
- {
- tmp_string = g_string_chunk_insert (string_chunk, "hi pete");
-
- if (strcmp ("hi pete", tmp_string) != 0)
- g_error ("string chunks are broken.\n");
- }
-
- tmp_string_2 = g_string_chunk_insert_const (string_chunk, tmp_string);
-
- g_assert (tmp_string_2 != tmp_string &&
- strcmp(tmp_string_2, tmp_string) == 0);
-
- tmp_string = g_string_chunk_insert_const (string_chunk, tmp_string);
-
- g_assert (tmp_string_2 == tmp_string);
-
- g_string_chunk_free (string_chunk);
-
- g_print ("ok\n");
-
-
- g_print ("checking arrays...");
-
- garray = g_array_new (FALSE, FALSE, sizeof (gint));
- for (i = 0; i < 10000; i++)
- g_array_append_val (garray, i);
-
- for (i = 0; i < 10000; i++)
- if (g_array_index (garray, gint, i) != i)
- g_print ("uh oh: %d ( %d )\n", g_array_index (garray, gint, i), i);
-
- g_array_free (garray, TRUE);
-
- garray = g_array_new (FALSE, FALSE, sizeof (gint));
- for (i = 0; i < 100; i++)
- g_array_prepend_val (garray, i);
-
- for (i = 0; i < 100; i++)
- if (g_array_index (garray, gint, i) != (100 - i - 1))
- g_print ("uh oh: %d ( %d )\n", g_array_index (garray, gint, i), 100 - i - 1);
-
- g_array_free (garray, TRUE);
-
- g_print ("ok\n");
-
-
- g_print ("checking strings...");
-
- string1 = g_string_new ("hi pete!");
- string2 = g_string_new ("");
-
- g_assert (strcmp ("hi pete!", string1->str) == 0);
-
- for (i = 0; i < 10000; i++)
- g_string_append_c (string1, 'a'+(i%26));
-
-#if !(defined (_MSC_VER) || defined (__LCC__))
- /* MSVC and LCC use the same run-time C library, which doesn't like
- the %10000.10000f format... */
- g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%10000.10000f",
- "this pete guy sure is a wuss, like he's the number ",
- 1,
- " wuss. everyone agrees.\n",
- string1->str,
- 10, 666, 15, 15, 666.666666666, 666.666666666);
-#else
- g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%100.100f",
- "this pete guy sure is a wuss, like he's the number ",
- 1,
- " wuss. everyone agrees.\n",
- string1->str,
- 10, 666, 15, 15, 666.666666666, 666.666666666);
-#endif
-
- g_print ("string2 length = %d...\n", string2->len);
- string2->str[70] = '\0';
- g_print ("first 70 chars:\n%s\n", string2->str);
- string2->str[141] = '\0';
- g_print ("next 70 chars:\n%s\n", string2->str+71);
- string2->str[212] = '\0';
- g_print ("and next 70:\n%s\n", string2->str+142);
- g_print ("last 70 chars:\n%s\n", string2->str+string2->len - 70);
-
- g_print ("ok\n");
-
- g_print ("checking timers...\n");
-
- timer = g_timer_new ();
- g_print (" spinning for 3 seconds...\n");
-
- g_timer_start (timer);
- while (g_timer_elapsed (timer, NULL) < 3)
- ;
-
- g_timer_stop (timer);
- g_timer_destroy (timer);
-
- g_print ("ok\n");
-
- g_print ("checking g_strcasecmp...");
- g_assert (g_strcasecmp ("FroboZZ", "frobozz") == 0);
- g_assert (g_strcasecmp ("frobozz", "frobozz") == 0);
- g_assert (g_strcasecmp ("frobozz", "FROBOZZ") == 0);
- g_assert (g_strcasecmp ("FROBOZZ", "froboz") != 0);
- g_assert (g_strcasecmp ("", "") == 0);
- g_assert (g_strcasecmp ("!#%&/()", "!#%&/()") == 0);
- g_assert (g_strcasecmp ("a", "b") < 0);
- g_assert (g_strcasecmp ("a", "B") < 0);
- g_assert (g_strcasecmp ("A", "b") < 0);
- g_assert (g_strcasecmp ("A", "B") < 0);
- g_assert (g_strcasecmp ("b", "a") > 0);
- g_assert (g_strcasecmp ("b", "A") > 0);
- g_assert (g_strcasecmp ("B", "a") > 0);
- g_assert (g_strcasecmp ("B", "A") > 0);
-
- g_print ("ok\n");
-
- g_print ("checking g_strdup...");
- g_assert(g_strdup(NULL) == NULL);
- string = g_strdup(GLIB_TEST_STRING);
- g_assert(string != NULL);
- g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
- g_free(string);
-
- g_print ("ok\n");
-
- g_print ("checking g_strconcat...");
- string = g_strconcat(GLIB_TEST_STRING, NULL);
- g_assert(string != NULL);
- g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
- g_free(string);
- string = g_strconcat(GLIB_TEST_STRING, GLIB_TEST_STRING,
- GLIB_TEST_STRING, NULL);
- g_assert(string != NULL);
- g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING
- GLIB_TEST_STRING) == 0);
- g_free(string);
-
- g_print ("ok\n");
-
- g_print ("checking g_strdup_printf...");
- string = g_strdup_printf ("%05d %-5s", 21, "test");
- g_assert (string != NULL);
- g_assert (strcmp(string, "00021 test ") == 0);
- g_free (string);
-
- g_print ("ok\n");
-
- /* g_debug (argv[0]); */
-
- /* Relation tests */
-
- g_print ("checking relations...");
-
- relation = g_relation_new (2);
-
- g_relation_index (relation, 0, g_int_hash, g_int_equal);
- g_relation_index (relation, 1, g_int_hash, g_int_equal);
-
- for (i = 0; i < 1024; i += 1)
- data[i] = i;
-
- for (i = 1; i < 1023; i += 1)
- {
- g_relation_insert (relation, data + i, data + i + 1);
- g_relation_insert (relation, data + i, data + i - 1);
- }
-
- for (i = 2; i < 1022; i += 1)
- {
- g_assert (! g_relation_exists (relation, data + i, data + i));
- g_assert (! g_relation_exists (relation, data + i, data + i + 2));
- g_assert (! g_relation_exists (relation, data + i, data + i - 2));
- }
-
- for (i = 1; i < 1023; i += 1)
- {
- g_assert (g_relation_exists (relation, data + i, data + i + 1));
- g_assert (g_relation_exists (relation, data + i, data + i - 1));
- }
-
- for (i = 2; i < 1022; i += 1)
- {
- g_assert (g_relation_count (relation, data + i, 0) == 2);
- g_assert (g_relation_count (relation, data + i, 1) == 2);
- }
-
- g_assert (g_relation_count (relation, data, 0) == 0);
-
- g_assert (g_relation_count (relation, data + 42, 0) == 2);
- g_assert (g_relation_count (relation, data + 43, 1) == 2);
- g_assert (g_relation_count (relation, data + 41, 1) == 2);
- g_relation_delete (relation, data + 42, 0);
- g_assert (g_relation_count (relation, data + 42, 0) == 0);
- g_assert (g_relation_count (relation, data + 43, 1) == 1);
- g_assert (g_relation_count (relation, data + 41, 1) == 1);
-
- tuples = g_relation_select (relation, data + 200, 0);
-
- g_assert (tuples->len == 2);
-
-#if 0
- for (i = 0; i < tuples->len; i += 1)
- {
- printf ("%d %d\n",
- *(gint*) g_tuples_index (tuples, i, 0),
- *(gint*) g_tuples_index (tuples, i, 1));
- }
-#endif
-
- g_assert (g_relation_exists (relation, data + 300, data + 301));
- g_relation_delete (relation, data + 300, 0);
- g_assert (!g_relation_exists (relation, data + 300, data + 301));
-
- g_tuples_destroy (tuples);
-
- g_relation_destroy (relation);
-
- relation = NULL;
-
- g_print ("ok\n");
-
- g_print ("checking pointer arrays...");
-
- gparray = g_ptr_array_new ();
- for (i = 0; i < 10000; i++)
- g_ptr_array_add (gparray, GINT_TO_POINTER (i));
-
- for (i = 0; i < 10000; i++)
- if (g_ptr_array_index (gparray, i) != GINT_TO_POINTER (i))
- g_print ("array fails: %p ( %p )\n", g_ptr_array_index (gparray, i), GINT_TO_POINTER (i));
-
- g_ptr_array_free (gparray, TRUE);
-
- g_print ("ok\n");
-
-
- g_print ("checking byte arrays...");
-
- gbarray = g_byte_array_new ();
- for (i = 0; i < 10000; i++)
- g_byte_array_append (gbarray, (guint8*) "abcd", 4);
-
- for (i = 0; i < 10000; i++)
- {
- g_assert (gbarray->data[4*i] == 'a');
- g_assert (gbarray->data[4*i+1] == 'b');
- g_assert (gbarray->data[4*i+2] == 'c');
- g_assert (gbarray->data[4*i+3] == 'd');
- }
-
- g_byte_array_free (gbarray, TRUE);
- g_print ("ok\n");
-
- g_printerr ("g_log tests:");
- g_warning ("harmless warning with parameters: %d %s %#x", 42, "Boo", 12345);
- g_message ("the next warning is a test:");
- string = NULL;
- g_print (string);
-
- g_print ("checking endian macros (host is ");
-#if G_BYTE_ORDER == G_BIG_ENDIAN
- g_print ("big endian)...");
-#else
- g_print ("little endian)...");
-#endif
- g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2);
- g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2);
-#ifdef G_HAVE_GINT64
- g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);
-#endif
- g_print ("ok\n");
-
- return 0;
-}
-