1998-07-31 20:21:10 +00:00
|
|
|
/* 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
|
2000-07-26 11:02:02 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1998-07-31 20:21:10 +00:00
|
|
|
* 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
|
2000-07-26 11:02:02 +00:00
|
|
|
* Lesser General Public License for more details.
|
1998-07-31 20:21:10 +00:00
|
|
|
*
|
2000-07-26 11:02:02 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1998-07-31 20:21:10 +00:00
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
1998-12-15 05:28:02 +00:00
|
|
|
|
1999-02-24 06:14:27 +00:00
|
|
|
/*
|
2000-07-26 11:02:02 +00:00
|
|
|
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
1999-02-24 06:14:27 +00:00
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
1998-12-15 05:28:02 +00:00
|
|
|
/*
|
|
|
|
* MT safe
|
|
|
|
*/
|
|
|
|
|
2002-12-04 01:27:44 +00:00
|
|
|
#include "config.h"
|
2000-12-19 09:35:44 +00:00
|
|
|
|
1998-07-31 20:21:10 +00:00
|
|
|
#include "glib.h"
|
2005-03-14 04:26:57 +00:00
|
|
|
#include "galias.h"
|
1998-07-31 20:21:10 +00:00
|
|
|
|
2005-11-01 18:10:31 +00:00
|
|
|
void g_node_push_allocator (gpointer dummy) { /* present for binary compat only */ }
|
|
|
|
void g_node_pop_allocator (void) { /* present for binary compat only */ }
|
1998-07-31 20:21:10 +00:00
|
|
|
|
2005-11-01 18:10:31 +00:00
|
|
|
#define g_node_alloc0() g_slice_new0 (GNode)
|
|
|
|
#define g_node_free(node) g_slice_free (GNode, node)
|
1998-07-31 20:21:10 +00:00
|
|
|
|
|
|
|
/* --- functions --- */
|
|
|
|
GNode*
|
|
|
|
g_node_new (gpointer data)
|
|
|
|
{
|
2005-11-01 18:10:31 +00:00
|
|
|
GNode *node = g_node_alloc0();
|
1998-08-03 14:06:18 +00:00
|
|
|
node->data = data;
|
1998-07-31 20:21:10 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-11-24 12:18:22 +00:00
|
|
|
g_nodes_free (GNode *node)
|
1998-07-31 20:21:10 +00:00
|
|
|
{
|
2005-11-01 18:10:31 +00:00
|
|
|
while (node)
|
2000-12-19 09:35:44 +00:00
|
|
|
{
|
2005-11-01 18:10:31 +00:00
|
|
|
GNode *next = node->next;
|
|
|
|
if (node->children)
|
|
|
|
g_nodes_free (node->children);
|
|
|
|
g_node_free (node);
|
2000-12-19 09:35:44 +00:00
|
|
|
node = next;
|
|
|
|
}
|
|
|
|
}
|
1998-07-31 20:21:10 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
g_node_destroy (GNode *root)
|
|
|
|
{
|
|
|
|
g_return_if_fail (root != NULL);
|
|
|
|
|
|
|
|
if (!G_NODE_IS_ROOT (root))
|
|
|
|
g_node_unlink (root);
|
|
|
|
|
1998-11-24 12:18:22 +00:00
|
|
|
g_nodes_free (root);
|
1998-07-31 20:21:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-02-21 23:56:54 +00:00
|
|
|
/**
|
|
|
|
* g_node_copy_deep:
|
|
|
|
* @node: a #GNode
|
|
|
|
* @copy_func: the function which is called to copy the data inside each node,
|
|
|
|
* or %NULL to use the original data.
|
|
|
|
* @data: data to pass to @copy_func
|
|
|
|
*
|
|
|
|
* Recursively copies a #GNode and its data.
|
|
|
|
*
|
|
|
|
* Return value: a new #GNode containing copies of the data in @node.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
GNode*
|
|
|
|
g_node_copy_deep (GNode *node,
|
|
|
|
GCopyFunc copy_func,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GNode *new_node = NULL;
|
|
|
|
|
|
|
|
if (copy_func == NULL)
|
|
|
|
return g_node_copy (node);
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
GNode *child, *new_child;
|
|
|
|
|
|
|
|
new_node = g_node_new (copy_func (node->data, data));
|
|
|
|
|
|
|
|
for (child = g_node_last_child (node); child; child = child->prev)
|
|
|
|
{
|
|
|
|
new_child = g_node_copy_deep (child, copy_func, data);
|
|
|
|
g_node_prepend (new_node, new_child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_node;
|
|
|
|
}
|
|
|
|
|
2000-03-01 09:44:10 +00:00
|
|
|
GNode*
|
|
|
|
g_node_copy (GNode *node)
|
|
|
|
{
|
|
|
|
GNode *new_node = NULL;
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
GNode *child;
|
|
|
|
|
|
|
|
new_node = g_node_new (node->data);
|
|
|
|
|
|
|
|
for (child = g_node_last_child (node); child; child = child->prev)
|
|
|
|
g_node_prepend (new_node, g_node_copy (child));
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_node;
|
|
|
|
}
|
|
|
|
|
version bump to 1.1.3, binary age 0, interface age 0.
Sun Aug 16 20:28:27 1998 Tim Janik <timj@gtk.org>
* version bump to 1.1.3, binary age 0, interface age 0.
* glib.h: be nice to platforms that don't have gint64 and don't
issue #warning on every compilation. since glib doesn't require
gint64 itself, packages that need gint64 should test for this
themselves.
* glib.h:
* gutils.c: added a new function g_vsnprintf().
Fri Aug 14 16:41:53 1998 Tim Janik <timj@gtk.org>
* glib.h: added static inline functions for bit mask tests:
g_bit_nth_lsf, g_bit_nth_msf and g_bit_storage.
Fri Aug 13 14:23:37 1998 Tim Janik <timj@gtk.org>
* glib.h:
* gmessages.c:
revised the message handling system, which is now based on a new
mechanism g_log*. most of the assertment macros got adapted to
feature the new g_log() call with an additional specification of
the log level in a preprocessor macro G_LOG_DOMAIN. if G_LOG_DOMAIN
is undefined upon the includion of glib.h, it'll be defined with a
value of (NULL) and thus preserves the original bahaviour for
warning and error messages. the message handler setting functions
for g_warning, g_error and g_message are only provided for backwards
compatibility and might get removed somewhen.
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GLib" upon compilation. we currently have to add this definition
to the DEFS variable.
* testglib.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
* glib.h: changed some gints to gbooleans, made a few const corrections,
removed some superfluous G_STMT_START{}G_STMT_END wrappers, added some
in other required places.
* gnode.c:
(g_node_prepend):
(g_node_insert_before):
(g_node_insert):
(g_node_append_data):
(g_node_prepend_data):
(g_node_insert_data_before):
(g_node_insert_data):
(g_node_append):
return (node), so these macros/functions can be usefully chained with
g_node_new().
[GModule]
Fri Aug 14 02:24:39 1998 Tim Janik <timj@gtk.org>
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GModule" upon compilation. we currently have to add this definition
to the DEFS variable.
* testgmodule.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
1998-08-16 21:14:11 +00:00
|
|
|
GNode*
|
1998-07-31 20:21:10 +00:00
|
|
|
g_node_insert (GNode *parent,
|
|
|
|
gint position,
|
|
|
|
GNode *node)
|
|
|
|
{
|
version bump to 1.1.3, binary age 0, interface age 0.
Sun Aug 16 20:28:27 1998 Tim Janik <timj@gtk.org>
* version bump to 1.1.3, binary age 0, interface age 0.
* glib.h: be nice to platforms that don't have gint64 and don't
issue #warning on every compilation. since glib doesn't require
gint64 itself, packages that need gint64 should test for this
themselves.
* glib.h:
* gutils.c: added a new function g_vsnprintf().
Fri Aug 14 16:41:53 1998 Tim Janik <timj@gtk.org>
* glib.h: added static inline functions for bit mask tests:
g_bit_nth_lsf, g_bit_nth_msf and g_bit_storage.
Fri Aug 13 14:23:37 1998 Tim Janik <timj@gtk.org>
* glib.h:
* gmessages.c:
revised the message handling system, which is now based on a new
mechanism g_log*. most of the assertment macros got adapted to
feature the new g_log() call with an additional specification of
the log level in a preprocessor macro G_LOG_DOMAIN. if G_LOG_DOMAIN
is undefined upon the includion of glib.h, it'll be defined with a
value of (NULL) and thus preserves the original bahaviour for
warning and error messages. the message handler setting functions
for g_warning, g_error and g_message are only provided for backwards
compatibility and might get removed somewhen.
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GLib" upon compilation. we currently have to add this definition
to the DEFS variable.
* testglib.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
* glib.h: changed some gints to gbooleans, made a few const corrections,
removed some superfluous G_STMT_START{}G_STMT_END wrappers, added some
in other required places.
* gnode.c:
(g_node_prepend):
(g_node_insert_before):
(g_node_insert):
(g_node_append_data):
(g_node_prepend_data):
(g_node_insert_data_before):
(g_node_insert_data):
(g_node_append):
return (node), so these macros/functions can be usefully chained with
g_node_new().
[GModule]
Fri Aug 14 02:24:39 1998 Tim Janik <timj@gtk.org>
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GModule" upon compilation. we currently have to add this definition
to the DEFS variable.
* testgmodule.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
1998-08-16 21:14:11 +00:00
|
|
|
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);
|
1998-07-31 20:21:10 +00:00
|
|
|
|
|
|
|
if (position > 0)
|
version bump to 1.1.3, binary age 0, interface age 0.
Sun Aug 16 20:28:27 1998 Tim Janik <timj@gtk.org>
* version bump to 1.1.3, binary age 0, interface age 0.
* glib.h: be nice to platforms that don't have gint64 and don't
issue #warning on every compilation. since glib doesn't require
gint64 itself, packages that need gint64 should test for this
themselves.
* glib.h:
* gutils.c: added a new function g_vsnprintf().
Fri Aug 14 16:41:53 1998 Tim Janik <timj@gtk.org>
* glib.h: added static inline functions for bit mask tests:
g_bit_nth_lsf, g_bit_nth_msf and g_bit_storage.
Fri Aug 13 14:23:37 1998 Tim Janik <timj@gtk.org>
* glib.h:
* gmessages.c:
revised the message handling system, which is now based on a new
mechanism g_log*. most of the assertment macros got adapted to
feature the new g_log() call with an additional specification of
the log level in a preprocessor macro G_LOG_DOMAIN. if G_LOG_DOMAIN
is undefined upon the includion of glib.h, it'll be defined with a
value of (NULL) and thus preserves the original bahaviour for
warning and error messages. the message handler setting functions
for g_warning, g_error and g_message are only provided for backwards
compatibility and might get removed somewhen.
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GLib" upon compilation. we currently have to add this definition
to the DEFS variable.
* testglib.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
* glib.h: changed some gints to gbooleans, made a few const corrections,
removed some superfluous G_STMT_START{}G_STMT_END wrappers, added some
in other required places.
* gnode.c:
(g_node_prepend):
(g_node_insert_before):
(g_node_insert):
(g_node_append_data):
(g_node_prepend_data):
(g_node_insert_data_before):
(g_node_insert_data):
(g_node_append):
return (node), so these macros/functions can be usefully chained with
g_node_new().
[GModule]
Fri Aug 14 02:24:39 1998 Tim Janik <timj@gtk.org>
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GModule" upon compilation. we currently have to add this definition
to the DEFS variable.
* testgmodule.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
1998-08-16 21:14:11 +00:00
|
|
|
return g_node_insert_before (parent,
|
|
|
|
g_node_nth_child (parent, position),
|
|
|
|
node);
|
1998-07-31 20:21:10 +00:00
|
|
|
else if (position == 0)
|
version bump to 1.1.3, binary age 0, interface age 0.
Sun Aug 16 20:28:27 1998 Tim Janik <timj@gtk.org>
* version bump to 1.1.3, binary age 0, interface age 0.
* glib.h: be nice to platforms that don't have gint64 and don't
issue #warning on every compilation. since glib doesn't require
gint64 itself, packages that need gint64 should test for this
themselves.
* glib.h:
* gutils.c: added a new function g_vsnprintf().
Fri Aug 14 16:41:53 1998 Tim Janik <timj@gtk.org>
* glib.h: added static inline functions for bit mask tests:
g_bit_nth_lsf, g_bit_nth_msf and g_bit_storage.
Fri Aug 13 14:23:37 1998 Tim Janik <timj@gtk.org>
* glib.h:
* gmessages.c:
revised the message handling system, which is now based on a new
mechanism g_log*. most of the assertment macros got adapted to
feature the new g_log() call with an additional specification of
the log level in a preprocessor macro G_LOG_DOMAIN. if G_LOG_DOMAIN
is undefined upon the includion of glib.h, it'll be defined with a
value of (NULL) and thus preserves the original bahaviour for
warning and error messages. the message handler setting functions
for g_warning, g_error and g_message are only provided for backwards
compatibility and might get removed somewhen.
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GLib" upon compilation. we currently have to add this definition
to the DEFS variable.
* testglib.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
* glib.h: changed some gints to gbooleans, made a few const corrections,
removed some superfluous G_STMT_START{}G_STMT_END wrappers, added some
in other required places.
* gnode.c:
(g_node_prepend):
(g_node_insert_before):
(g_node_insert):
(g_node_append_data):
(g_node_prepend_data):
(g_node_insert_data_before):
(g_node_insert_data):
(g_node_append):
return (node), so these macros/functions can be usefully chained with
g_node_new().
[GModule]
Fri Aug 14 02:24:39 1998 Tim Janik <timj@gtk.org>
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GModule" upon compilation. we currently have to add this definition
to the DEFS variable.
* testgmodule.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
1998-08-16 21:14:11 +00:00
|
|
|
return g_node_prepend (parent, node);
|
|
|
|
else /* if (position < 0) */
|
|
|
|
return g_node_append (parent, node);
|
1998-07-31 20:21:10 +00:00
|
|
|
}
|
|
|
|
|
version bump to 1.1.3, binary age 0, interface age 0.
Sun Aug 16 20:28:27 1998 Tim Janik <timj@gtk.org>
* version bump to 1.1.3, binary age 0, interface age 0.
* glib.h: be nice to platforms that don't have gint64 and don't
issue #warning on every compilation. since glib doesn't require
gint64 itself, packages that need gint64 should test for this
themselves.
* glib.h:
* gutils.c: added a new function g_vsnprintf().
Fri Aug 14 16:41:53 1998 Tim Janik <timj@gtk.org>
* glib.h: added static inline functions for bit mask tests:
g_bit_nth_lsf, g_bit_nth_msf and g_bit_storage.
Fri Aug 13 14:23:37 1998 Tim Janik <timj@gtk.org>
* glib.h:
* gmessages.c:
revised the message handling system, which is now based on a new
mechanism g_log*. most of the assertment macros got adapted to
feature the new g_log() call with an additional specification of
the log level in a preprocessor macro G_LOG_DOMAIN. if G_LOG_DOMAIN
is undefined upon the includion of glib.h, it'll be defined with a
value of (NULL) and thus preserves the original bahaviour for
warning and error messages. the message handler setting functions
for g_warning, g_error and g_message are only provided for backwards
compatibility and might get removed somewhen.
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GLib" upon compilation. we currently have to add this definition
to the DEFS variable.
* testglib.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
* glib.h: changed some gints to gbooleans, made a few const corrections,
removed some superfluous G_STMT_START{}G_STMT_END wrappers, added some
in other required places.
* gnode.c:
(g_node_prepend):
(g_node_insert_before):
(g_node_insert):
(g_node_append_data):
(g_node_prepend_data):
(g_node_insert_data_before):
(g_node_insert_data):
(g_node_append):
return (node), so these macros/functions can be usefully chained with
g_node_new().
[GModule]
Fri Aug 14 02:24:39 1998 Tim Janik <timj@gtk.org>
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GModule" upon compilation. we currently have to add this definition
to the DEFS variable.
* testgmodule.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
1998-08-16 21:14:11 +00:00
|
|
|
GNode*
|
1998-07-31 20:21:10 +00:00
|
|
|
g_node_insert_before (GNode *parent,
|
|
|
|
GNode *sibling,
|
|
|
|
GNode *node)
|
|
|
|
{
|
version bump to 1.1.3, binary age 0, interface age 0.
Sun Aug 16 20:28:27 1998 Tim Janik <timj@gtk.org>
* version bump to 1.1.3, binary age 0, interface age 0.
* glib.h: be nice to platforms that don't have gint64 and don't
issue #warning on every compilation. since glib doesn't require
gint64 itself, packages that need gint64 should test for this
themselves.
* glib.h:
* gutils.c: added a new function g_vsnprintf().
Fri Aug 14 16:41:53 1998 Tim Janik <timj@gtk.org>
* glib.h: added static inline functions for bit mask tests:
g_bit_nth_lsf, g_bit_nth_msf and g_bit_storage.
Fri Aug 13 14:23:37 1998 Tim Janik <timj@gtk.org>
* glib.h:
* gmessages.c:
revised the message handling system, which is now based on a new
mechanism g_log*. most of the assertment macros got adapted to
feature the new g_log() call with an additional specification of
the log level in a preprocessor macro G_LOG_DOMAIN. if G_LOG_DOMAIN
is undefined upon the includion of glib.h, it'll be defined with a
value of (NULL) and thus preserves the original bahaviour for
warning and error messages. the message handler setting functions
for g_warning, g_error and g_message are only provided for backwards
compatibility and might get removed somewhen.
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GLib" upon compilation. we currently have to add this definition
to the DEFS variable.
* testglib.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
* glib.h: changed some gints to gbooleans, made a few const corrections,
removed some superfluous G_STMT_START{}G_STMT_END wrappers, added some
in other required places.
* gnode.c:
(g_node_prepend):
(g_node_insert_before):
(g_node_insert):
(g_node_append_data):
(g_node_prepend_data):
(g_node_insert_data_before):
(g_node_insert_data):
(g_node_append):
return (node), so these macros/functions can be usefully chained with
g_node_new().
[GModule]
Fri Aug 14 02:24:39 1998 Tim Janik <timj@gtk.org>
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GModule" upon compilation. we currently have to add this definition
to the DEFS variable.
* testgmodule.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
1998-08-16 21:14:11 +00:00
|
|
|
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);
|
1998-07-31 20:21:10 +00:00
|
|
|
if (sibling)
|
version bump to 1.1.3, binary age 0, interface age 0.
Sun Aug 16 20:28:27 1998 Tim Janik <timj@gtk.org>
* version bump to 1.1.3, binary age 0, interface age 0.
* glib.h: be nice to platforms that don't have gint64 and don't
issue #warning on every compilation. since glib doesn't require
gint64 itself, packages that need gint64 should test for this
themselves.
* glib.h:
* gutils.c: added a new function g_vsnprintf().
Fri Aug 14 16:41:53 1998 Tim Janik <timj@gtk.org>
* glib.h: added static inline functions for bit mask tests:
g_bit_nth_lsf, g_bit_nth_msf and g_bit_storage.
Fri Aug 13 14:23:37 1998 Tim Janik <timj@gtk.org>
* glib.h:
* gmessages.c:
revised the message handling system, which is now based on a new
mechanism g_log*. most of the assertment macros got adapted to
feature the new g_log() call with an additional specification of
the log level in a preprocessor macro G_LOG_DOMAIN. if G_LOG_DOMAIN
is undefined upon the includion of glib.h, it'll be defined with a
value of (NULL) and thus preserves the original bahaviour for
warning and error messages. the message handler setting functions
for g_warning, g_error and g_message are only provided for backwards
compatibility and might get removed somewhen.
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GLib" upon compilation. we currently have to add this definition
to the DEFS variable.
* testglib.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
* glib.h: changed some gints to gbooleans, made a few const corrections,
removed some superfluous G_STMT_START{}G_STMT_END wrappers, added some
in other required places.
* gnode.c:
(g_node_prepend):
(g_node_insert_before):
(g_node_insert):
(g_node_append_data):
(g_node_prepend_data):
(g_node_insert_data_before):
(g_node_insert_data):
(g_node_append):
return (node), so these macros/functions can be usefully chained with
g_node_new().
[GModule]
Fri Aug 14 02:24:39 1998 Tim Janik <timj@gtk.org>
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GModule" upon compilation. we currently have to add this definition
to the DEFS variable.
* testgmodule.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
1998-08-16 21:14:11 +00:00
|
|
|
g_return_val_if_fail (sibling->parent == parent, node);
|
1998-07-31 20:21:10 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
version bump to 1.1.3, binary age 0, interface age 0.
Sun Aug 16 20:28:27 1998 Tim Janik <timj@gtk.org>
* version bump to 1.1.3, binary age 0, interface age 0.
* glib.h: be nice to platforms that don't have gint64 and don't
issue #warning on every compilation. since glib doesn't require
gint64 itself, packages that need gint64 should test for this
themselves.
* glib.h:
* gutils.c: added a new function g_vsnprintf().
Fri Aug 14 16:41:53 1998 Tim Janik <timj@gtk.org>
* glib.h: added static inline functions for bit mask tests:
g_bit_nth_lsf, g_bit_nth_msf and g_bit_storage.
Fri Aug 13 14:23:37 1998 Tim Janik <timj@gtk.org>
* glib.h:
* gmessages.c:
revised the message handling system, which is now based on a new
mechanism g_log*. most of the assertment macros got adapted to
feature the new g_log() call with an additional specification of
the log level in a preprocessor macro G_LOG_DOMAIN. if G_LOG_DOMAIN
is undefined upon the includion of glib.h, it'll be defined with a
value of (NULL) and thus preserves the original bahaviour for
warning and error messages. the message handler setting functions
for g_warning, g_error and g_message are only provided for backwards
compatibility and might get removed somewhen.
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GLib" upon compilation. we currently have to add this definition
to the DEFS variable.
* testglib.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
* glib.h: changed some gints to gbooleans, made a few const corrections,
removed some superfluous G_STMT_START{}G_STMT_END wrappers, added some
in other required places.
* gnode.c:
(g_node_prepend):
(g_node_insert_before):
(g_node_insert):
(g_node_append_data):
(g_node_prepend_data):
(g_node_insert_data_before):
(g_node_insert_data):
(g_node_append):
return (node), so these macros/functions can be usefully chained with
g_node_new().
[GModule]
Fri Aug 14 02:24:39 1998 Tim Janik <timj@gtk.org>
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GModule" upon compilation. we currently have to add this definition
to the DEFS variable.
* testgmodule.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
1998-08-16 21:14:11 +00:00
|
|
|
|
|
|
|
return node;
|
1998-07-31 20:21:10 +00:00
|
|
|
}
|
|
|
|
|
2000-09-29 23:13:02 +00:00
|
|
|
GNode*
|
|
|
|
g_node_insert_after (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->next)
|
|
|
|
{
|
|
|
|
sibling->next->prev = node;
|
|
|
|
}
|
|
|
|
node->next = sibling->next;
|
|
|
|
node->prev = sibling;
|
|
|
|
sibling->next = node;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (parent->children)
|
|
|
|
{
|
|
|
|
node->next = parent->children;
|
|
|
|
parent->children->prev = node;
|
|
|
|
}
|
|
|
|
parent->children = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
version bump to 1.1.3, binary age 0, interface age 0.
Sun Aug 16 20:28:27 1998 Tim Janik <timj@gtk.org>
* version bump to 1.1.3, binary age 0, interface age 0.
* glib.h: be nice to platforms that don't have gint64 and don't
issue #warning on every compilation. since glib doesn't require
gint64 itself, packages that need gint64 should test for this
themselves.
* glib.h:
* gutils.c: added a new function g_vsnprintf().
Fri Aug 14 16:41:53 1998 Tim Janik <timj@gtk.org>
* glib.h: added static inline functions for bit mask tests:
g_bit_nth_lsf, g_bit_nth_msf and g_bit_storage.
Fri Aug 13 14:23:37 1998 Tim Janik <timj@gtk.org>
* glib.h:
* gmessages.c:
revised the message handling system, which is now based on a new
mechanism g_log*. most of the assertment macros got adapted to
feature the new g_log() call with an additional specification of
the log level in a preprocessor macro G_LOG_DOMAIN. if G_LOG_DOMAIN
is undefined upon the includion of glib.h, it'll be defined with a
value of (NULL) and thus preserves the original bahaviour for
warning and error messages. the message handler setting functions
for g_warning, g_error and g_message are only provided for backwards
compatibility and might get removed somewhen.
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GLib" upon compilation. we currently have to add this definition
to the DEFS variable.
* testglib.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
* glib.h: changed some gints to gbooleans, made a few const corrections,
removed some superfluous G_STMT_START{}G_STMT_END wrappers, added some
in other required places.
* gnode.c:
(g_node_prepend):
(g_node_insert_before):
(g_node_insert):
(g_node_append_data):
(g_node_prepend_data):
(g_node_insert_data_before):
(g_node_insert_data):
(g_node_append):
return (node), so these macros/functions can be usefully chained with
g_node_new().
[GModule]
Fri Aug 14 02:24:39 1998 Tim Janik <timj@gtk.org>
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GModule" upon compilation. we currently have to add this definition
to the DEFS variable.
* testgmodule.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
1998-08-16 21:14:11 +00:00
|
|
|
GNode*
|
1998-07-31 20:21:10 +00:00
|
|
|
g_node_prepend (GNode *parent,
|
|
|
|
GNode *node)
|
|
|
|
{
|
version bump to 1.1.3, binary age 0, interface age 0.
Sun Aug 16 20:28:27 1998 Tim Janik <timj@gtk.org>
* version bump to 1.1.3, binary age 0, interface age 0.
* glib.h: be nice to platforms that don't have gint64 and don't
issue #warning on every compilation. since glib doesn't require
gint64 itself, packages that need gint64 should test for this
themselves.
* glib.h:
* gutils.c: added a new function g_vsnprintf().
Fri Aug 14 16:41:53 1998 Tim Janik <timj@gtk.org>
* glib.h: added static inline functions for bit mask tests:
g_bit_nth_lsf, g_bit_nth_msf and g_bit_storage.
Fri Aug 13 14:23:37 1998 Tim Janik <timj@gtk.org>
* glib.h:
* gmessages.c:
revised the message handling system, which is now based on a new
mechanism g_log*. most of the assertment macros got adapted to
feature the new g_log() call with an additional specification of
the log level in a preprocessor macro G_LOG_DOMAIN. if G_LOG_DOMAIN
is undefined upon the includion of glib.h, it'll be defined with a
value of (NULL) and thus preserves the original bahaviour for
warning and error messages. the message handler setting functions
for g_warning, g_error and g_message are only provided for backwards
compatibility and might get removed somewhen.
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GLib" upon compilation. we currently have to add this definition
to the DEFS variable.
* testglib.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
* glib.h: changed some gints to gbooleans, made a few const corrections,
removed some superfluous G_STMT_START{}G_STMT_END wrappers, added some
in other required places.
* gnode.c:
(g_node_prepend):
(g_node_insert_before):
(g_node_insert):
(g_node_append_data):
(g_node_prepend_data):
(g_node_insert_data_before):
(g_node_insert_data):
(g_node_append):
return (node), so these macros/functions can be usefully chained with
g_node_new().
[GModule]
Fri Aug 14 02:24:39 1998 Tim Janik <timj@gtk.org>
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GModule" upon compilation. we currently have to add this definition
to the DEFS variable.
* testgmodule.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
1998-08-16 21:14:11 +00:00
|
|
|
g_return_val_if_fail (parent != NULL, node);
|
1998-07-31 20:21:10 +00:00
|
|
|
|
version bump to 1.1.3, binary age 0, interface age 0.
Sun Aug 16 20:28:27 1998 Tim Janik <timj@gtk.org>
* version bump to 1.1.3, binary age 0, interface age 0.
* glib.h: be nice to platforms that don't have gint64 and don't
issue #warning on every compilation. since glib doesn't require
gint64 itself, packages that need gint64 should test for this
themselves.
* glib.h:
* gutils.c: added a new function g_vsnprintf().
Fri Aug 14 16:41:53 1998 Tim Janik <timj@gtk.org>
* glib.h: added static inline functions for bit mask tests:
g_bit_nth_lsf, g_bit_nth_msf and g_bit_storage.
Fri Aug 13 14:23:37 1998 Tim Janik <timj@gtk.org>
* glib.h:
* gmessages.c:
revised the message handling system, which is now based on a new
mechanism g_log*. most of the assertment macros got adapted to
feature the new g_log() call with an additional specification of
the log level in a preprocessor macro G_LOG_DOMAIN. if G_LOG_DOMAIN
is undefined upon the includion of glib.h, it'll be defined with a
value of (NULL) and thus preserves the original bahaviour for
warning and error messages. the message handler setting functions
for g_warning, g_error and g_message are only provided for backwards
compatibility and might get removed somewhen.
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GLib" upon compilation. we currently have to add this definition
to the DEFS variable.
* testglib.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
* glib.h: changed some gints to gbooleans, made a few const corrections,
removed some superfluous G_STMT_START{}G_STMT_END wrappers, added some
in other required places.
* gnode.c:
(g_node_prepend):
(g_node_insert_before):
(g_node_insert):
(g_node_append_data):
(g_node_prepend_data):
(g_node_insert_data_before):
(g_node_insert_data):
(g_node_append):
return (node), so these macros/functions can be usefully chained with
g_node_new().
[GModule]
Fri Aug 14 02:24:39 1998 Tim Janik <timj@gtk.org>
* Makefile.am: feature the G_LOG_DOMAIN macro to set the log domain
to "GModule" upon compilation. we currently have to add this definition
to the DEFS variable.
* testgmodule.c: we need an ugly #undef G_LOG_DOMAIN at the start
of this file currently, since automake doesn't support per target
_CFLAGS yet.
1998-08-16 21:14:11 +00:00
|
|
|
return g_node_insert_before (parent, parent->children, node);
|
1998-07-31 20:21:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2001-11-26 19:08:46 +00:00
|
|
|
g_node_traverse_level (GNode *node,
|
|
|
|
GTraverseFlags flags,
|
|
|
|
guint level,
|
|
|
|
GNodeTraverseFunc func,
|
|
|
|
gpointer data,
|
|
|
|
gboolean *more_levels)
|
|
|
|
{
|
|
|
|
if (level == 0)
|
1998-07-31 20:21:10 +00:00
|
|
|
{
|
2001-11-26 19:08:46 +00:00
|
|
|
if (node->children)
|
1998-07-31 20:21:10 +00:00
|
|
|
{
|
2001-11-26 19:08:46 +00:00
|
|
|
*more_levels = TRUE;
|
|
|
|
return (flags & G_TRAVERSE_NON_LEAFS) && func (node, data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return (flags & G_TRAVERSE_LEAFS) && func (node, data);
|
1998-07-31 20:21:10 +00:00
|
|
|
}
|
|
|
|
}
|
2001-11-26 19:08:46 +00:00
|
|
|
else
|
1998-07-31 20:21:10 +00:00
|
|
|
{
|
2001-11-26 19:08:46 +00:00
|
|
|
node = node->children;
|
1998-07-31 20:21:10 +00:00
|
|
|
|
2001-11-26 19:08:46 +00:00
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
if (g_node_traverse_level (node, flags, level - 1, func, data, more_levels))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
node = node->next;
|
|
|
|
}
|
1998-07-31 20:21:10 +00:00
|
|
|
}
|
2001-11-26 19:08:46 +00:00
|
|
|
|
1998-07-31 20:21:10 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2001-11-26 19:08:46 +00:00
|
|
|
g_node_depth_traverse_level (GNode *node,
|
|
|
|
GTraverseFlags flags,
|
|
|
|
guint depth,
|
|
|
|
GNodeTraverseFunc func,
|
|
|
|
gpointer data)
|
1998-07-31 20:21:10 +00:00
|
|
|
{
|
2005-11-28 18:31:03 +00:00
|
|
|
guint level;
|
2001-11-26 19:08:46 +00:00
|
|
|
gboolean more_levels;
|
|
|
|
|
|
|
|
level = 0;
|
|
|
|
while (level != depth)
|
1998-07-31 20:21:10 +00:00
|
|
|
{
|
2001-11-26 19:08:46 +00:00
|
|
|
more_levels = FALSE;
|
|
|
|
if (g_node_traverse_level (node, flags, level, func, data, &more_levels))
|
1998-07-31 20:21:10 +00:00
|
|
|
return TRUE;
|
2001-11-26 19:08:46 +00:00
|
|
|
if (!more_levels)
|
|
|
|
break;
|
|
|
|
level++;
|
1998-07-31 20:21:10 +00:00
|
|
|
}
|
|
|
|
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:
|
2001-11-26 19:08:46 +00:00
|
|
|
g_node_depth_traverse_level (root, flags, depth, func, data);
|
1998-07-31 20:21:10 +00:00
|
|
|
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);
|
|
|
|
|
2000-03-01 09:44:10 +00:00
|
|
|
if (node->parent)
|
|
|
|
return node->parent->children;
|
|
|
|
|
1998-07-31 20:21:10 +00:00
|
|
|
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;
|
1998-10-25 05:24:49 +00:00
|
|
|
if (G_NODE_IS_LEAF (current))
|
1998-07-31 20:21:10 +00:00
|
|
|
{
|
|
|
|
if (flags & G_TRAVERSE_LEAFS)
|
|
|
|
func (current, data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (flags & G_TRAVERSE_NON_LEAFS)
|
|
|
|
func (current, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-03-14 04:26:57 +00:00
|
|
|
|
|
|
|
#define __G_NODE_C__
|
|
|
|
#include "galiasdef.c"
|