Import Upstream version 2.72.4

This commit is contained in:
evinadmin 2023-07-04 11:23:22 +02:00
commit 4ef3ff9793
2003 changed files with 1332420 additions and 0 deletions

View file

@ -0,0 +1,104 @@
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
/* we know we are deprecated here, no need for warnings */
#ifndef GLIB_DISABLE_DEPRECATION_WARNINGS
#define GLIB_DISABLE_DEPRECATION_WARNINGS
#endif
#include "gallocator.h"
#include <glib/gmessages.h>
#include <glib/gslice.h>
struct _GMemChunk {
guint alloc_size; /* the size of an atom */
};
GMemChunk*
g_mem_chunk_new (const gchar *name,
gint atom_size,
gsize area_size,
gint type)
{
GMemChunk *mem_chunk;
g_return_val_if_fail (atom_size > 0, NULL);
mem_chunk = g_slice_new (GMemChunk);
mem_chunk->alloc_size = atom_size;
return mem_chunk;
}
void
g_mem_chunk_destroy (GMemChunk *mem_chunk)
{
g_return_if_fail (mem_chunk != NULL);
g_slice_free (GMemChunk, mem_chunk);
}
gpointer
g_mem_chunk_alloc (GMemChunk *mem_chunk)
{
g_return_val_if_fail (mem_chunk != NULL, NULL);
return g_slice_alloc (mem_chunk->alloc_size);
}
gpointer
g_mem_chunk_alloc0 (GMemChunk *mem_chunk)
{
g_return_val_if_fail (mem_chunk != NULL, NULL);
return g_slice_alloc0 (mem_chunk->alloc_size);
}
void
g_mem_chunk_free (GMemChunk *mem_chunk,
gpointer mem)
{
g_return_if_fail (mem_chunk != NULL);
g_slice_free1 (mem_chunk->alloc_size, mem);
}
GAllocator*
g_allocator_new (const gchar *name,
guint n_preallocs)
{
/* some (broken) GAllocator uses depend on non-NULL allocators */
return (void *) 1;
}
void g_allocator_free (GAllocator *allocator) { }
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) { }
void g_blow_chunks (void) { }
void g_list_push_allocator (GAllocator *allocator) { }
void g_list_pop_allocator (void) { }
void g_slist_push_allocator (GAllocator *allocator) { }
void g_slist_pop_allocator (void) { }
void g_node_push_allocator (GAllocator *allocator) { }
void g_node_pop_allocator (void) { }

View file

@ -0,0 +1,88 @@
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __G_ALLOCATOR_H__
#define __G_ALLOCATOR_H__
#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#include <glib/gtypes.h>
G_BEGIN_DECLS
typedef struct _GAllocator GAllocator;
typedef struct _GMemChunk GMemChunk;
#define G_ALLOC_ONLY 1
#define G_ALLOC_AND_FREE 2
#define G_ALLOCATOR_LIST 1
#define G_ALLOCATOR_SLIST 2
#define G_ALLOCATOR_NODE 3
#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_mem_chunk_free (mem_chunk, mem))
#define g_mem_chunk_create(type, x, y) (g_mem_chunk_new (NULL, sizeof (type), 0, 0))
GLIB_DEPRECATED
GMemChunk * g_mem_chunk_new (const gchar *name,
gint atom_size,
gsize area_size,
gint type);
GLIB_DEPRECATED
void g_mem_chunk_destroy (GMemChunk *mem_chunk);
GLIB_DEPRECATED
gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
GLIB_DEPRECATED
gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
GLIB_DEPRECATED
void g_mem_chunk_free (GMemChunk *mem_chunk,
gpointer mem);
GLIB_DEPRECATED
void g_mem_chunk_clean (GMemChunk *mem_chunk);
GLIB_DEPRECATED
void g_mem_chunk_reset (GMemChunk *mem_chunk);
GLIB_DEPRECATED
void g_mem_chunk_print (GMemChunk *mem_chunk);
GLIB_DEPRECATED
void g_mem_chunk_info (void);
GLIB_DEPRECATED
void g_blow_chunks (void);
GLIB_DEPRECATED
GAllocator * g_allocator_new (const gchar *name,
guint n_preallocs);
GLIB_DEPRECATED
void g_allocator_free (GAllocator *allocator);
GLIB_DEPRECATED
void g_list_push_allocator (GAllocator *allocator);
GLIB_DEPRECATED
void g_list_pop_allocator (void);
GLIB_DEPRECATED
void g_slist_push_allocator (GAllocator *allocator);
GLIB_DEPRECATED
void g_slist_pop_allocator (void);
GLIB_DEPRECATED
void g_node_push_allocator (GAllocator *allocator);
GLIB_DEPRECATED
void g_node_pop_allocator (void);
G_END_DECLS
#endif /* __G_ALLOCATOR_H__ */

350
glib/deprecated/gcache.c Normal file
View file

@ -0,0 +1,350 @@
/* 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 Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GLib Team and others 1997-2000. 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"
/* we know we are deprecated here, no need for warnings */
#ifndef GLIB_DISABLE_DEPRECATION_WARNINGS
#define GLIB_DISABLE_DEPRECATION_WARNINGS
#endif
#include "gcache.h"
#include "gslice.h"
#include "ghash.h"
#include "gtestutils.h"
/**
* SECTION:caches
* @title: Caches
* @short_description: caches allow sharing of complex data structures
* to save resources
*
* A #GCache allows sharing of complex data structures, in order to
* save system resources.
*
* GCache uses keys and values. A GCache key describes the properties
* of a particular resource. A GCache value is the actual resource.
*
* GCache has been marked as deprecated, since this API is rarely
* used and not very actively maintained.
*/
typedef struct _GCacheNode GCacheNode;
struct _GCacheNode
{
/* A reference counted node */
gpointer value;
gint ref_count;
};
/**
* GCache:
*
* The #GCache struct is an opaque data structure containing
* information about a #GCache. It should only be accessed via the
* following functions.
*
* Deprecated:2.32: Use a #GHashTable instead
*/
struct _GCache
{
/* 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 inline GCacheNode*
g_cache_node_new (gpointer value)
{
GCacheNode *node = g_slice_new (GCacheNode);
node->value = value;
node->ref_count = 1;
return node;
}
static inline void
g_cache_node_destroy (GCacheNode *node)
{
g_slice_free (GCacheNode, node);
}
/**
* g_cache_new:
* @value_new_func: a function to create a new object given a key.
* This is called by g_cache_insert() if an object
* with the given key does not already exist
* @value_destroy_func: a function to destroy an object. It is called
* by g_cache_remove() when the object is no
* longer needed (i.e. its reference count drops
* to 0)
* @key_dup_func: a function to copy a key. It is called by
* g_cache_insert() if the key does not already exist in
* the #GCache
* @key_destroy_func: a function to destroy a key. It is called by
* g_cache_remove() when the object is no longer
* needed (i.e. its reference count drops to 0)
* @hash_key_func: a function to create a hash value from a key
* @hash_value_func: a function to create a hash value from a value
* @key_equal_func: a function to compare two keys. It should return
* %TRUE if the two keys are equivalent
*
* Creates a new #GCache.
*
* Returns: a new #GCache
*
* Deprecated:2.32: Use a #GHashTable instead
*/
/**
* GCacheNewFunc:
* @key: a #GCache key
*
* Specifies the type of the @value_new_func function passed to
* g_cache_new(). It is passed a #GCache key and should create the
* value corresponding to the key.
*
* Returns: a new #GCache value corresponding to the key.
*/
/**
* GCacheDestroyFunc:
* @value: the #GCache value to destroy
*
* Specifies the type of the @value_destroy_func and @key_destroy_func
* functions passed to g_cache_new(). The functions are passed a
* pointer to the #GCache key or #GCache value and should free any
* memory and other resources associated with it.
*/
/**
* GCacheDupFunc:
* @value: the #GCache key to destroy (__not__ a
* #GCache value as it seems)
*
* Specifies the type of the @key_dup_func function passed to
* g_cache_new(). The function is passed a key
* (__not__ a value as the prototype implies) and
* should return a duplicate of the key.
*
* Returns: a copy of the #GCache key
*/
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,
GEqualFunc key_equal_func)
{
GCache *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_equal_func != NULL, NULL);
cache = g_slice_new (GCache);
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_equal_func);
cache->value_table = g_hash_table_new (hash_value_func, NULL);
return cache;
}
/**
* g_cache_destroy:
* @cache: a #GCache
*
* Frees the memory allocated for the #GCache.
*
* Note that it does not destroy the keys and values which were
* contained in the #GCache.
*
* Deprecated:2.32: Use a #GHashTable instead
*/
void
g_cache_destroy (GCache *cache)
{
g_return_if_fail (cache != NULL);
g_hash_table_destroy (cache->key_table);
g_hash_table_destroy (cache->value_table);
g_slice_free (GCache, cache);
}
/**
* g_cache_insert:
* @cache: a #GCache
* @key: a key describing a #GCache object
*
* Gets the value corresponding to the given key, creating it if
* necessary. It first checks if the value already exists in the
* #GCache, by using the @key_equal_func function passed to
* g_cache_new(). If it does already exist it is returned, and its
* reference count is increased by one. If the value does not currently
* exist, if is created by calling the @value_new_func. The key is
* duplicated by calling @key_dup_func and the duplicated key and value
* are inserted into the #GCache.
*
* Returns: a pointer to a #GCache value
*
* Deprecated:2.32: Use a #GHashTable instead
*/
gpointer
g_cache_insert (GCache *cache,
gpointer key)
{
GCacheNode *node;
gpointer value;
g_return_val_if_fail (cache != NULL, NULL);
node = g_hash_table_lookup (cache->key_table, key);
if (node)
{
node->ref_count += 1;
return node->value;
}
key = (* cache->key_dup_func) (key);
value = (* cache->value_new_func) (key);
node = g_cache_node_new (value);
g_hash_table_insert (cache->key_table, key, node);
g_hash_table_insert (cache->value_table, value, key);
return node->value;
}
/**
* g_cache_remove:
* @cache: a #GCache
* @value: the value to remove
*
* Decreases the reference count of the given value. If it drops to 0
* then the value and its corresponding key are destroyed, using the
* @value_destroy_func and @key_destroy_func passed to g_cache_new().
*
* Deprecated:2.32: Use a #GHashTable instead
*/
void
g_cache_remove (GCache *cache,
gconstpointer value)
{
GCacheNode *node;
gpointer key;
g_return_if_fail (cache != NULL);
key = g_hash_table_lookup (cache->value_table, value);
node = g_hash_table_lookup (cache->key_table, key);
g_return_if_fail (node != NULL);
node->ref_count -= 1;
if (node->ref_count == 0)
{
g_hash_table_remove (cache->value_table, value);
g_hash_table_remove (cache->key_table, key);
(* cache->key_destroy_func) (key);
(* cache->value_destroy_func) (node->value);
g_cache_node_destroy (node);
}
}
/**
* g_cache_key_foreach:
* @cache: a #GCache
* @func: the function to call with each #GCache key
* @user_data: user data to pass to the function
*
* Calls the given function for each of the keys in the #GCache.
*
* NOTE @func is passed three parameters, the value and key of a cache
* entry and the @user_data. The order of value and key is different
* from the order in which g_hash_table_foreach() passes key-value
* pairs to its callback function !
*
* Deprecated:2.32: Use a #GHashTable instead
*/
void
g_cache_key_foreach (GCache *cache,
GHFunc func,
gpointer user_data)
{
g_return_if_fail (cache != NULL);
g_return_if_fail (func != NULL);
g_hash_table_foreach (cache->value_table, func, user_data);
}
/**
* g_cache_value_foreach:
* @cache: a #GCache
* @func: the function to call with each #GCache value
* @user_data: user data to pass to the function
*
* Calls the given function for each of the values in the #GCache.
*
* Deprecated:2.10: The reason is that it passes pointers to internal
* data structures to @func; use g_cache_key_foreach() instead
*/
void
g_cache_value_foreach (GCache *cache,
GHFunc func,
gpointer user_data)
{
g_return_if_fail (cache != NULL);
g_return_if_fail (func != NULL);
g_hash_table_foreach (cache->key_table, func, user_data);
}

75
glib/deprecated/gcache.h Normal file
View file

@ -0,0 +1,75 @@
/* 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 Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GLib Team and others 1997-2000. 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_CACHE_H__
#define __G_CACHE_H__
#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#include <glib/glist.h>
G_BEGIN_DECLS
typedef struct _GCache GCache GLIB_DEPRECATED_TYPE_IN_2_26_FOR(GHashTable);
typedef gpointer (*GCacheNewFunc) (gpointer key) GLIB_DEPRECATED_TYPE_IN_2_26;
typedef gpointer (*GCacheDupFunc) (gpointer value) GLIB_DEPRECATED_TYPE_IN_2_26;
typedef void (*GCacheDestroyFunc) (gpointer value) GLIB_DEPRECATED_TYPE_IN_2_26;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/* Caches
*/
GLIB_DEPRECATED
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,
GEqualFunc key_equal_func);
GLIB_DEPRECATED
void g_cache_destroy (GCache *cache);
GLIB_DEPRECATED
gpointer g_cache_insert (GCache *cache,
gpointer key);
GLIB_DEPRECATED
void g_cache_remove (GCache *cache,
gconstpointer value);
GLIB_DEPRECATED
void g_cache_key_foreach (GCache *cache,
GHFunc func,
gpointer user_data);
GLIB_DEPRECATED
void g_cache_value_foreach (GCache *cache,
GHFunc func,
gpointer user_data);
G_GNUC_END_IGNORE_DEPRECATIONS
G_END_DECLS
#endif /* __G_CACHE_H__ */

View file

@ -0,0 +1,503 @@
/* 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 Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GLib Team and others 1997-2000. 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"
/* we know we are deprecated here, no need for warnings */
#ifndef GLIB_DISABLE_DEPRECATION_WARNINGS
#define GLIB_DISABLE_DEPRECATION_WARNINGS
#endif
#include "gcompletion.h"
#include <glib/gstrfuncs.h>
#include <glib/gmessages.h>
#include <glib/gunicode.h>
#include <string.h>
/**
* SECTION:completion
* @title: Automatic String Completion
* @short_description: support for automatic completion using a group
* of target strings
*
* #GCompletion provides support for automatic completion of a string
* using any group of target strings. It is typically used for file
* name completion as is common in many UNIX shells.
*
* A #GCompletion is created using g_completion_new(). Target items are
* added and removed with g_completion_add_items(),
* g_completion_remove_items() and g_completion_clear_items(). A
* completion attempt is requested with g_completion_complete() or
* g_completion_complete_utf8(). When no longer needed, the
* #GCompletion is freed with g_completion_free().
*
* Items in the completion can be simple strings (e.g. filenames), or
* pointers to arbitrary data structures. If data structures are used
* you must provide a #GCompletionFunc in g_completion_new(), which
* retrieves the item's string from the data structure. You can change
* the way in which strings are compared by setting a different
* #GCompletionStrncmpFunc in g_completion_set_compare().
*
* GCompletion has been marked as deprecated, since this API is rarely
* used and not very actively maintained.
**/
/**
* GCompletion:
* @items: list of target items (strings or data structures).
* @func: function which is called to get the string associated with a
* target item. It is %NULL if the target items are strings.
* @prefix: the last prefix passed to g_completion_complete() or
* g_completion_complete_utf8().
* @cache: the list of items which begin with @prefix.
* @strncmp_func: The function to use when comparing strings. Use
* g_completion_set_compare() to modify this function.
*
* The data structure used for automatic completion.
**/
/**
* GCompletionFunc:
* @Param1: the completion item.
*
* Specifies the type of the function passed to g_completion_new(). It
* should return the string corresponding to the given target item.
* This is used when you use data structures as #GCompletion items.
*
* Returns: the string corresponding to the item.
**/
/**
* GCompletionStrncmpFunc:
* @s1: string to compare with @s2.
* @s2: string to compare with @s1.
* @n: maximal number of bytes to compare.
*
* Specifies the type of the function passed to
* g_completion_set_compare(). This is used when you use strings as
* #GCompletion items.
*
* Returns: an integer less than, equal to, or greater than zero if
* the first @n bytes of @s1 is found, respectively, to be
* less than, to match, or to be greater than the first @n
* bytes of @s2.
**/
static void completion_check_cache (GCompletion* cmp,
gchar** new_prefix);
/**
* g_completion_new:
* @func: the function to be called to return the string representing
* an item in the #GCompletion, or %NULL if strings are going to
* be used as the #GCompletion items.
*
* Creates a new #GCompletion.
*
* Returns: the new #GCompletion.
**/
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;
gcomp->strncmp_func = strncmp;
return gcomp;
}
/**
* g_completion_add_items:
* @cmp: the #GCompletion.
* @items: (transfer none): the list of items to add.
*
* Adds items to the #GCompletion.
*
* Deprecated: 2.26: Rarely used API
**/
void
g_completion_add_items (GCompletion* cmp,
GList* items)
{
GList* it;
g_return_if_fail (cmp != 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;
}
}
/**
* g_completion_remove_items:
* @cmp: the #GCompletion.
* @items: (transfer none): the items to remove.
*
* Removes items from a #GCompletion. The items are not freed, so if the memory
* was dynamically allocated, free @items with g_list_free_full() after calling
* this function.
*
* Deprecated: 2.26: Rarely used API
**/
void
g_completion_remove_items (GCompletion* cmp,
GList* items)
{
GList* it;
g_return_if_fail (cmp != 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;
}
}
/**
* g_completion_clear_items:
* @cmp: the #GCompletion.
*
* Removes all items from the #GCompletion. The items are not freed, so if the
* memory was dynamically allocated, it should be freed after calling this
* function.
*
* Deprecated: 2.26: Rarely used API
**/
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)
{
GList* list;
gsize len;
gsize i;
gsize 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);
}
/**
* g_completion_complete_utf8:
* @cmp: the #GCompletion
* @prefix: the prefix string, typically used by the user, which is compared
* with each of the items
* @new_prefix: if non-%NULL, returns the longest prefix which is common to all
* items that matched @prefix, or %NULL if no items matched @prefix.
* This string should be freed when no longer needed.
*
* Attempts to complete the string @prefix using the #GCompletion target items.
* In contrast to g_completion_complete(), this function returns the largest common
* prefix that is a valid UTF-8 string, omitting a possible common partial
* character.
*
* You should use this function instead of g_completion_complete() if your
* items are UTF-8 strings.
*
* Returns: (element-type utf8) (transfer none): the list of items whose strings begin with @prefix. This should
* not be changed.
*
* Since: 2.4
*
* Deprecated: 2.26: Rarely used API
**/
GList*
g_completion_complete_utf8 (GCompletion *cmp,
const gchar *prefix,
gchar **new_prefix)
{
GList *list;
gchar *p, *q;
list = g_completion_complete (cmp, prefix, new_prefix);
if (new_prefix && *new_prefix)
{
p = *new_prefix + strlen (*new_prefix);
q = g_utf8_find_prev_char (*new_prefix, p);
switch (g_utf8_get_char_validated (q, p - q))
{
case (gunichar)-2:
case (gunichar)-1:
*q = 0;
break;
default: ;
}
}
return list;
}
/**
* g_completion_complete:
* @cmp: the #GCompletion.
* @prefix: the prefix string, typically typed by the user, which is
* compared with each of the items.
* @new_prefix: if non-%NULL, returns the longest prefix which is
* common to all items that matched @prefix, or %NULL if
* no items matched @prefix. This string should be freed
* when no longer needed.
*
* Attempts to complete the string @prefix using the #GCompletion
* target items.
*
* Returns: (transfer none): the list of items whose strings begin with
* @prefix. This should not be changed.
*
* Deprecated: 2.26: Rarely used API
**/
GList*
g_completion_complete (GCompletion* cmp,
const gchar* prefix,
gchar** new_prefix)
{
gsize plen, len;
gboolean done = FALSE;
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 && ! cmp->strncmp_func (prefix, cmp->prefix, plen))
{
/* use the cache */
list = cmp->cache;
while (list)
{
GList *next = list->next;
if (cmp->strncmp_func (prefix,
cmp->func ? cmp->func (list->data) : (gchar*) list->data,
len))
cmp->cache = g_list_delete_link (cmp->cache, list);
list = next;
}
done = TRUE;
}
}
if (!done)
{
/* normal code */
g_list_free (cmp->cache);
cmp->cache = NULL;
list = cmp->items;
while (*prefix && list)
{
if (!cmp->strncmp_func (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;
}
/**
* g_completion_free:
* @cmp: the #GCompletion.
*
* Frees all memory used by the #GCompletion. The items are not freed, so if
* the memory was dynamically allocated, it should be freed after calling this
* function.
*
* Deprecated: 2.26: Rarely used API
**/
void
g_completion_free (GCompletion* cmp)
{
g_return_if_fail (cmp != NULL);
g_completion_clear_items (cmp);
g_free (cmp);
}
/**
* g_completion_set_compare:
* @cmp: a #GCompletion.
* @strncmp_func: the string comparison function.
*
* Sets the function to use for string comparisons. The default string
* comparison function is strncmp().
*
* Deprecated: 2.26: Rarely used API
**/
void
g_completion_set_compare(GCompletion *cmp,
GCompletionStrncmpFunc strncmp_func)
{
cmp->strncmp_func = strncmp_func;
}
#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 ...]",
(argc > 0) ? argv[0] : "gcompletion");
return 1;
}
file = fopen (argv[1], "r");
if (!file)
{
g_warning ("Cannot open %s", 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

View file

@ -0,0 +1,83 @@
/* 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 Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GLib Team and others 1997-2000. 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_COMPLETION_H__
#define __G_COMPLETION_H__
#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#include <glib/glist.h>
G_BEGIN_DECLS
typedef struct _GCompletion GCompletion;
typedef gchar* (*GCompletionFunc) (gpointer);
/* GCompletion
*/
typedef gint (*GCompletionStrncmpFunc) (const gchar *s1,
const gchar *s2,
gsize n);
struct _GCompletion
{
GList* items;
GCompletionFunc func;
gchar* prefix;
GList* cache;
GCompletionStrncmpFunc strncmp_func;
};
GLIB_DEPRECATED_IN_2_26
GCompletion* g_completion_new (GCompletionFunc func);
GLIB_DEPRECATED_IN_2_26
void g_completion_add_items (GCompletion* cmp,
GList* items);
GLIB_DEPRECATED_IN_2_26
void g_completion_remove_items (GCompletion* cmp,
GList* items);
GLIB_DEPRECATED_IN_2_26
void g_completion_clear_items (GCompletion* cmp);
GLIB_DEPRECATED_IN_2_26
GList* g_completion_complete (GCompletion* cmp,
const gchar* prefix,
gchar** new_prefix);
GLIB_DEPRECATED_IN_2_26
GList* g_completion_complete_utf8 (GCompletion *cmp,
const gchar* prefix,
gchar** new_prefix);
GLIB_DEPRECATED_IN_2_26
void g_completion_set_compare (GCompletion *cmp,
GCompletionStrncmpFunc strncmp_func);
GLIB_DEPRECATED_IN_2_26
void g_completion_free (GCompletion* cmp);
G_END_DECLS
#endif /* __G_COMPLETION_H__ */

135
glib/deprecated/gmain.h Normal file
View file

@ -0,0 +1,135 @@
/* 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 Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GLib Team and others 1997-2000. 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_DEPRECATED_MAIN_H__
#define __G_DEPRECATED_MAIN_H__
#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#include <glib/gmain.h>
G_BEGIN_DECLS
/* ============== Compat main loop stuff ================== */
/**
* g_main_new:
* @is_running: set to %TRUE to indicate that the loop is running. This
* is not very important since calling g_main_run() will set this
* to %TRUE anyway.
*
* Creates a new #GMainLoop for th default main context.
*
* Returns: a new #GMainLoop
*
* Deprecated: 2.2: Use g_main_loop_new() instead
*/
#define g_main_new(is_running) g_main_loop_new (NULL, is_running) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_loop_new)
/**
* g_main_run:
* @loop: a #GMainLoop
*
* Runs a main loop until it stops running.
*
* Deprecated: 2.2: Use g_main_loop_run() instead
*/
#define g_main_run(loop) g_main_loop_run(loop) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_loop_run)
/**
* g_main_quit:
* @loop: a #GMainLoop
*
* Stops the #GMainLoop.
* If g_main_run() was called to run the #GMainLoop, it will now return.
*
* Deprecated: 2.2: Use g_main_loop_quit() instead
*/
#define g_main_quit(loop) g_main_loop_quit(loop) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_loop_quit)
/**
* g_main_destroy:
* @loop: a #GMainLoop
*
* Frees the memory allocated for the #GMainLoop.
*
* Deprecated: 2.2: Use g_main_loop_unref() instead
*/
#define g_main_destroy(loop) g_main_loop_unref(loop) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_loop_unref)
/**
* g_main_is_running:
* @loop: a #GMainLoop
*
* Checks if the main loop is running.
*
* Returns: %TRUE if the main loop is running
*
* Deprecated: 2.2: Use g_main_loop_is_running() instead
*/
#define g_main_is_running(loop) g_main_loop_is_running(loop) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_loop_is_running)
/**
* g_main_iteration:
* @may_block: set to %TRUE if it should block (i.e. wait) until an event
* source becomes ready. It will return after an event source has been
* processed. If set to %FALSE it will return immediately if no event
* source is ready to be processed.
*
* Runs a single iteration for the default #GMainContext.
*
* Returns: %TRUE if more events are pending.
*
* Deprecated: 2.2: Use g_main_context_iteration() instead.
*/
#define g_main_iteration(may_block) g_main_context_iteration (NULL, may_block) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_context_iteration)
/**
* g_main_pending:
*
* Checks if any events are pending for the default #GMainContext
* (i.e. ready to be processed).
*
* Returns: %TRUE if any events are pending.
*
* Deprecated: 2.2: Use g_main_context_pending() instead.
*/
#define g_main_pending() g_main_context_pending (NULL) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_context_pending)
/**
* g_main_set_poll_func:
* @func: the function to call to poll all file descriptors
*
* Sets the function to use for the handle polling of file descriptors
* for the default main context.
*
* Deprecated: 2.2: Use g_main_context_set_poll_func() again
*/
#define g_main_set_poll_func(func) g_main_context_set_poll_func (NULL, func) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_context_set_poll_func)
G_END_DECLS
#endif /* __G_DEPRECATED_MAIN_H__ */

685
glib/deprecated/grel.c Normal file
View file

@ -0,0 +1,685 @@
/* 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 Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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-2000. 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"
/* we know we are deprecated here, no need for warnings */
#ifndef GLIB_DISABLE_DEPRECATION_WARNINGS
#define GLIB_DISABLE_DEPRECATION_WARNINGS
#endif
#include "grel.h"
#include <glib/gmessages.h>
#include <glib/gtestutils.h>
#include <glib/gstring.h>
#include <glib/gslice.h>
#include <glib/ghash.h>
#include <stdarg.h>
#include <string.h>
/**
* SECTION:relations
* @title: Relations and Tuples
* @short_description: tables of data which can be indexed on any
* number of fields
*
* A #GRelation is a table of data which can be indexed on any number
* of fields, rather like simple database tables. A #GRelation contains
* a number of records, called tuples. Each record contains a number of
* fields. Records are not ordered, so it is not possible to find the
* record at a particular index.
*
* Note that #GRelation tables are currently limited to 2 fields.
*
* To create a GRelation, use g_relation_new().
*
* To specify which fields should be indexed, use g_relation_index().
* Note that this must be called before any tuples are added to the
* #GRelation.
*
* To add records to a #GRelation use g_relation_insert().
*
* To determine if a given record appears in a #GRelation, use
* g_relation_exists(). Note that fields are compared directly, so
* pointers must point to the exact same position (i.e. different
* copies of the same string will not match.)
*
* To count the number of records which have a particular value in a
* given field, use g_relation_count().
*
* To get all the records which have a particular value in a given
* field, use g_relation_select(). To access fields of the resulting
* records, use g_tuples_index(). To free the resulting records use
* g_tuples_destroy().
*
* To delete all records which have a particular value in a given
* field, use g_relation_delete().
*
* To destroy the #GRelation, use g_relation_destroy().
*
* To help debug #GRelation objects, use g_relation_print().
*
* GRelation has been marked as deprecated, since this API has never
* been fully implemented, is not very actively maintained and rarely
* used.
**/
typedef struct _GRealTuples GRealTuples;
/**
* GRelation:
*
* The #GRelation struct is an opaque data structure to represent a
* [Relation][glib-Relations-and-Tuples]. It should
* only be accessed via the following functions.
**/
struct _GRelation
{
gint fields;
gint current_field;
GHashTable *all_tuples;
GHashTable **hashed_tuple_tables;
gint count;
};
/**
* GTuples:
* @len: the number of records that matched.
*
* The #GTuples struct is used to return records (or tuples) from the
* #GRelation by g_relation_select(). It only contains one public
* member - the number of records that matched. To access the matched
* records, you must use g_tuples_index().
**/
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)
{
#if GLIB_SIZEOF_VOID_P > GLIB_SIZEOF_LONG
/* In practise this snippet has been written for 64-bit Windows
* where ints are 32 bits, pointers 64 bits. More exotic platforms
* need more tweaks.
*/
guint* a = (guint*) v_a;
return (a[0] ^ a[1] ^ a[2] ^ a[3]);
#else
gpointer* a = (gpointer*) v_a;
return (gulong)a[0] ^ (gulong)a[1];
#endif
}
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 GEqualFunc
tuple_equal (gint fields)
{
switch (fields)
{
case 2:
return tuple_equal_2;
default:
g_error ("no tuple equal for %d", fields);
}
return NULL;
}
/**
* g_relation_new:
* @fields: the number of fields.
*
* Creates a new #GRelation with the given number of fields. Note that
* currently the number of fields must be 2.
*
* Returns: a new #GRelation.
*
* Deprecated: 2.26: Rarely used API
**/
GRelation*
g_relation_new (gint fields)
{
GRelation* rel = g_new0 (GRelation, 1);
rel->fields = fields;
rel->all_tuples = g_hash_table_new (tuple_hash (fields), tuple_equal (fields));
rel->hashed_tuple_tables = g_new0 (GHashTable*, fields);
return rel;
}
static void
relation_delete_value_tuple (gpointer tuple_key,
gpointer tuple_value,
gpointer user_data)
{
GRelation *relation = user_data;
gpointer *tuple = tuple_value;
g_slice_free1 (relation->fields * sizeof (gpointer), tuple);
}
static void
g_relation_free_array (gpointer key, gpointer value, gpointer user_data)
{
g_hash_table_destroy ((GHashTable*) value);
}
/**
* g_relation_destroy:
* @relation: a #GRelation.
*
* Destroys the #GRelation, freeing all memory allocated. However, it
* does not free memory allocated for the tuple data, so you should
* free that first if appropriate.
*
* Deprecated: 2.26: Rarely used API
**/
void
g_relation_destroy (GRelation *relation)
{
gint i;
if (relation)
{
for (i = 0; i < relation->fields; i += 1)
{
if (relation->hashed_tuple_tables[i])
{
g_hash_table_foreach (relation->hashed_tuple_tables[i], g_relation_free_array, NULL);
g_hash_table_destroy (relation->hashed_tuple_tables[i]);
}
}
g_hash_table_foreach (relation->all_tuples, relation_delete_value_tuple, relation);
g_hash_table_destroy (relation->all_tuples);
g_free (relation->hashed_tuple_tables);
g_free (relation);
}
}
/**
* g_relation_index:
* @relation: a #GRelation.
* @field: the field to index, counting from 0.
* @hash_func: a function to produce a hash value from the field data.
* @key_equal_func: a function to compare two values of the given field.
*
* Creates an index on the given field. Note that this must be called
* before any records are added to the #GRelation.
*
* Deprecated: 2.26: Rarely used API
**/
void
g_relation_index (GRelation *relation,
gint field,
GHashFunc hash_func,
GEqualFunc key_equal_func)
{
g_return_if_fail (relation != NULL);
g_return_if_fail (relation->count == 0 && relation->hashed_tuple_tables[field] == NULL);
relation->hashed_tuple_tables[field] = g_hash_table_new (hash_func, key_equal_func);
}
/**
* g_relation_insert:
* @relation: a #GRelation.
* @...: the fields of the record to add. These must match the
* number of fields in the #GRelation, and of type #gpointer
* or #gconstpointer.
*
* Inserts a record into a #GRelation.
*
* Deprecated: 2.26: Rarely used API
**/
void
g_relation_insert (GRelation *relation,
...)
{
gpointer* tuple = g_slice_alloc (relation->fields * sizeof (gpointer));
va_list args;
gint i;
va_start (args, relation);
for (i = 0; i < relation->fields; i += 1)
tuple[i] = va_arg (args, gpointer);
va_end (args);
g_hash_table_insert (relation->all_tuples, tuple, tuple);
relation->count += 1;
for (i = 0; i < relation->fields; i += 1)
{
GHashTable *table;
gpointer key;
GHashTable *per_key_table;
table = relation->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 (relation->fields), tuple_equal (relation->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;
GRelation *relation = (GRelation *) user_data;
gint j;
g_assert (tuple_key == tuple_value);
for (j = 0; j < relation->fields; j += 1)
{
GHashTable *one_table = relation->hashed_tuple_tables[j];
gpointer one_key;
GHashTable *per_key_table;
if (one_table == NULL)
continue;
if (j == relation->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);
}
if (g_hash_table_remove (relation->all_tuples, tuple))
g_slice_free1 (relation->fields * sizeof (gpointer), tuple);
relation->count -= 1;
}
/**
* g_relation_delete:
* @relation: a #GRelation.
* @key: the value to compare with.
* @field: the field of each record to match.
*
* Deletes any records from a #GRelation that have the given key value
* in the given field.
*
* Returns: the number of records deleted.
*
* Deprecated: 2.26: Rarely used API
**/
gint
g_relation_delete (GRelation *relation,
gconstpointer key,
gint field)
{
GHashTable *table;
GHashTable *key_table;
gint count;
g_return_val_if_fail (relation != NULL, 0);
table = relation->hashed_tuple_tables[field];
count = relation->count;
g_return_val_if_fail (table != NULL, 0);
key_table = g_hash_table_lookup (table, key);
if (!key_table)
return 0;
relation->current_field = field;
g_hash_table_foreach (key_table, g_relation_delete_tuple, relation);
g_hash_table_remove (table, key);
g_hash_table_destroy (key_table);
/* @@@ FIXME: Remove empty hash tables. */
return count - relation->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;
}
/**
* g_relation_select:
* @relation: a #GRelation.
* @key: the value to compare with.
* @field: the field of each record to match.
*
* Returns all of the tuples which have the given key in the given
* field. Use g_tuples_index() to access the returned records. The
* returned records should be freed with g_tuples_destroy().
*
* Returns: the records (tuples) that matched.
*
* Deprecated: 2.26: Rarely used API
**/
GTuples*
g_relation_select (GRelation *relation,
gconstpointer key,
gint field)
{
GHashTable *table;
GHashTable *key_table;
GRealTuples *tuples;
gint count;
g_return_val_if_fail (relation != NULL, NULL);
table = relation->hashed_tuple_tables[field];
g_return_val_if_fail (table != NULL, NULL);
tuples = g_new0 (GRealTuples, 1);
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) * relation->fields * count);
tuples->width = relation->fields;
g_hash_table_foreach (key_table, g_relation_select_tuple, tuples);
g_assert (count == tuples->len);
return (GTuples*)tuples;
}
/**
* g_relation_count:
* @relation: a #GRelation.
* @key: the value to compare with.
* @field: the field of each record to match.
*
* Returns the number of tuples in a #GRelation that have the given
* value in the given field.
*
* Returns: the number of matches.
*
* Deprecated: 2.26: Rarely used API
**/
gint
g_relation_count (GRelation *relation,
gconstpointer key,
gint field)
{
GHashTable *table;
GHashTable *key_table;
g_return_val_if_fail (relation != NULL, 0);
table = relation->hashed_tuple_tables[field];
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);
}
/**
* g_relation_exists:
* @relation: a #GRelation.
* @...: the fields of the record to compare. The number must match
* the number of fields in the #GRelation.
*
* Returns %TRUE if a record with the given values exists in a
* #GRelation. Note that the values are compared directly, so that, for
* example, two copies of the same string will not match.
*
* Returns: %TRUE if a record matches.
*
* Deprecated: 2.26: Rarely used API
**/
gboolean
g_relation_exists (GRelation *relation, ...)
{
gpointer *tuple = g_slice_alloc (relation->fields * sizeof (gpointer));
va_list args;
gint i;
gboolean result;
va_start(args, relation);
for (i = 0; i < relation->fields; i += 1)
tuple[i] = va_arg(args, gpointer);
va_end(args);
result = g_hash_table_lookup (relation->all_tuples, tuple) != NULL;
g_slice_free1 (relation->fields * sizeof (gpointer), tuple);
return result;
}
/**
* g_tuples_destroy:
* @tuples: the tuple data to free.
*
* Frees the records which were returned by g_relation_select(). This
* should always be called after g_relation_select() when you are
* finished with the records. The records are not removed from the
* #GRelation.
*
* Deprecated: 2.26: Rarely used API
**/
void
g_tuples_destroy (GTuples *tuples0)
{
GRealTuples *tuples = (GRealTuples*) tuples0;
if (tuples)
{
g_free (tuples->data);
g_free (tuples);
}
}
/**
* g_tuples_index:
* @tuples: the tuple data, returned by g_relation_select().
* @index_: the index of the record.
* @field: the field to return.
*
* Gets a field from the records returned by g_relation_select(). It
* returns the given field of the record at the given index. The
* returned value should not be changed.
*
* Returns: the field of the record.
*
* Deprecated: 2.26: Rarely used API
**/
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;
GRelation* rel = (GRelation*) user_data;
gpointer* tuples = (gpointer*) tuple_value;
gstring = g_string_new ("[");
for (i = 0; i < rel->fields; i += 1)
{
g_string_append_printf (gstring, "%p", tuples[i]);
if (i < (rel->fields - 1))
g_string_append (gstring, ",");
}
g_string_append (gstring, "]");
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "%s", gstring->str);
g_string_free (gstring, TRUE);
}
static void
g_relation_print_index (gpointer tuple_key,
gpointer tuple_value,
gpointer user_data)
{
GRelation* rel = (GRelation*) user_data;
GHashTable* table = (GHashTable*) tuple_value;
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "*** key %p", tuple_key);
g_hash_table_foreach (table,
g_relation_print_one,
rel);
}
/**
* g_relation_print:
* @relation: a #GRelation.
*
* Outputs information about all records in a #GRelation, as well as
* the indexes. It is for debugging.
*
* Deprecated: 2.26: Rarely used API
**/
void
g_relation_print (GRelation *relation)
{
gint i;
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "*** all tuples (%d)", relation->count);
g_hash_table_foreach (relation->all_tuples,
g_relation_print_one,
relation);
for (i = 0; i < relation->fields; i += 1)
{
if (relation->hashed_tuple_tables[i] == NULL)
continue;
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "*** index %d", i);
g_hash_table_foreach (relation->hashed_tuple_tables[i],
g_relation_print_index,
relation);
}
}

105
glib/deprecated/grel.h Normal file
View file

@ -0,0 +1,105 @@
/* 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 Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GLib Team and others 1997-2000. 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_REL_H__
#define __G_REL_H__
#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#include <glib/gtypes.h>
G_BEGIN_DECLS
typedef struct _GRelation GRelation;
typedef struct _GTuples GTuples;
struct _GTuples
{
guint len;
};
/* 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 ...
*/
GLIB_DEPRECATED_IN_2_26
GRelation* g_relation_new (gint fields);
GLIB_DEPRECATED_IN_2_26
void g_relation_destroy (GRelation *relation);
GLIB_DEPRECATED_IN_2_26
void g_relation_index (GRelation *relation,
gint field,
GHashFunc hash_func,
GEqualFunc key_equal_func);
GLIB_DEPRECATED_IN_2_26
void g_relation_insert (GRelation *relation,
...);
GLIB_DEPRECATED_IN_2_26
gint g_relation_delete (GRelation *relation,
gconstpointer key,
gint field);
GLIB_DEPRECATED_IN_2_26
GTuples* g_relation_select (GRelation *relation,
gconstpointer key,
gint field);
GLIB_DEPRECATED_IN_2_26
gint g_relation_count (GRelation *relation,
gconstpointer key,
gint field);
GLIB_DEPRECATED_IN_2_26
gboolean g_relation_exists (GRelation *relation,
...);
GLIB_DEPRECATED_IN_2_26
void g_relation_print (GRelation *relation);
GLIB_DEPRECATED_IN_2_26
void g_tuples_destroy (GTuples *tuples);
GLIB_DEPRECATED_IN_2_26
gpointer g_tuples_index (GTuples *tuples,
gint index_,
gint field);
G_END_DECLS
#endif /* __G_REL_H__ */

File diff suppressed because it is too large Load diff

293
glib/deprecated/gthread.h Normal file
View file

@ -0,0 +1,293 @@
/* 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 Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GLib Team and others 1997-2000. 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_DEPRECATED_THREAD_H__
#define __G_DEPRECATED_THREAD_H__
#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#include <glib/gthread.h>
G_BEGIN_DECLS
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
typedef enum
{
G_THREAD_PRIORITY_LOW,
G_THREAD_PRIORITY_NORMAL,
G_THREAD_PRIORITY_HIGH,
G_THREAD_PRIORITY_URGENT
} GThreadPriority GLIB_DEPRECATED_TYPE_IN_2_32;
struct _GThread
{
/*< private >*/
GThreadFunc func;
gpointer data;
gboolean joinable;
GThreadPriority priority;
};
typedef struct _GThreadFunctions GThreadFunctions GLIB_DEPRECATED_TYPE_IN_2_32;
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);
void (*thread_create) (GThreadFunc func,
gpointer data,
gulong stack_size,
gboolean joinable,
gboolean bound,
GThreadPriority priority,
gpointer thread,
GError **error);
void (*thread_yield) (void);
void (*thread_join) (gpointer thread);
void (*thread_exit) (void);
void (*thread_set_priority)(gpointer thread,
GThreadPriority priority);
void (*thread_self) (gpointer thread);
gboolean (*thread_equal) (gpointer thread1,
gpointer thread2);
} GLIB_DEPRECATED_TYPE_IN_2_32;
GLIB_VAR GThreadFunctions g_thread_functions_for_glib_use;
GLIB_VAR gboolean g_thread_use_default_impl;
GLIB_VAR guint64 (*g_thread_gettime) (void);
GLIB_DEPRECATED_IN_2_32_FOR(g_thread_new)
GThread *g_thread_create (GThreadFunc func,
gpointer data,
gboolean joinable,
GError **error);
GLIB_DEPRECATED_IN_2_32_FOR(g_thread_new)
GThread *g_thread_create_full (GThreadFunc func,
gpointer data,
gulong stack_size,
gboolean joinable,
gboolean bound,
GThreadPriority priority,
GError **error);
GLIB_DEPRECATED_IN_2_32
void g_thread_set_priority (GThread *thread,
GThreadPriority priority);
GLIB_DEPRECATED_IN_2_32
void g_thread_foreach (GFunc thread_func,
gpointer user_data);
#ifndef G_OS_WIN32
#include <sys/types.h>
#include <pthread.h>
#endif
#define g_static_mutex_get_mutex g_static_mutex_get_mutex_impl GLIB_DEPRECATED_MACRO_IN_2_32
#ifndef G_OS_WIN32
#define G_STATIC_MUTEX_INIT { NULL, PTHREAD_MUTEX_INITIALIZER } GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_mutex_init)
#else
#define G_STATIC_MUTEX_INIT { NULL } GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_mutex_init)
#endif
typedef struct
{
GMutex *mutex;
#ifndef G_OS_WIN32
/* only for ABI compatibility reasons */
pthread_mutex_t unused;
#endif
} GStaticMutex GLIB_DEPRECATED_TYPE_IN_2_32_FOR(GMutex);
#define g_static_mutex_lock(mutex) \
g_mutex_lock (g_static_mutex_get_mutex (mutex)) GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_mutex_lock)
#define g_static_mutex_trylock(mutex) \
g_mutex_trylock (g_static_mutex_get_mutex (mutex)) GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_mutex_trylock)
#define g_static_mutex_unlock(mutex) \
g_mutex_unlock (g_static_mutex_get_mutex (mutex)) GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_mutex_unlock)
GLIB_DEPRECATED_IN_2_32_FOR(g_mutex_init)
void g_static_mutex_init (GStaticMutex *mutex);
GLIB_DEPRECATED_IN_2_32_FOR(g_mutex_clear)
void g_static_mutex_free (GStaticMutex *mutex);
GLIB_DEPRECATED_IN_2_32_FOR(GMutex)
GMutex *g_static_mutex_get_mutex_impl (GStaticMutex *mutex);
typedef struct _GStaticRecMutex GStaticRecMutex GLIB_DEPRECATED_TYPE_IN_2_32_FOR(GRecMutex);
struct _GStaticRecMutex
{
/*< private >*/
GStaticMutex mutex;
guint depth;
/* ABI compat only */
union {
#ifdef G_OS_WIN32
void *owner;
#else
pthread_t owner;
#endif
gdouble dummy;
} unused;
} GLIB_DEPRECATED_TYPE_IN_2_32_FOR(GRecMutex);
#define G_STATIC_REC_MUTEX_INIT { G_STATIC_MUTEX_INIT, 0, { 0 } } GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_rec_mutex_init)
GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_init)
void g_static_rec_mutex_init (GStaticRecMutex *mutex);
GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_lock)
void g_static_rec_mutex_lock (GStaticRecMutex *mutex);
GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_try_lock)
gboolean g_static_rec_mutex_trylock (GStaticRecMutex *mutex);
GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_unlock)
void g_static_rec_mutex_unlock (GStaticRecMutex *mutex);
GLIB_DEPRECATED_IN_2_32
void g_static_rec_mutex_lock_full (GStaticRecMutex *mutex,
guint depth);
GLIB_DEPRECATED_IN_2_32
guint g_static_rec_mutex_unlock_full (GStaticRecMutex *mutex);
GLIB_DEPRECATED_IN_2_32_FOR(g_rec_mutex_free)
void g_static_rec_mutex_free (GStaticRecMutex *mutex);
typedef struct _GStaticRWLock GStaticRWLock GLIB_DEPRECATED_TYPE_IN_2_32_FOR(GRWLock);
struct _GStaticRWLock
{
/*< private >*/
GStaticMutex mutex;
GCond *read_cond;
GCond *write_cond;
guint read_counter;
gboolean have_writer;
guint want_to_read;
guint want_to_write;
} GLIB_DEPRECATED_TYPE_IN_2_32_FOR(GRWLock);
#define G_STATIC_RW_LOCK_INIT { G_STATIC_MUTEX_INIT, NULL, NULL, 0, FALSE, 0, 0 } GLIB_DEPRECATED_MACRO_IN_2_32_FOR(g_rw_lock_init)
GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_init)
void g_static_rw_lock_init (GStaticRWLock *lock);
GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_reader_lock)
void g_static_rw_lock_reader_lock (GStaticRWLock *lock);
GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_reader_trylock)
gboolean g_static_rw_lock_reader_trylock (GStaticRWLock *lock);
GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_reader_unlock)
void g_static_rw_lock_reader_unlock (GStaticRWLock *lock);
GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_writer_lock)
void g_static_rw_lock_writer_lock (GStaticRWLock *lock);
GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_writer_trylock)
gboolean g_static_rw_lock_writer_trylock (GStaticRWLock *lock);
GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_writer_unlock)
void g_static_rw_lock_writer_unlock (GStaticRWLock *lock);
GLIB_DEPRECATED_IN_2_32_FOR(g_rw_lock_free)
void g_static_rw_lock_free (GStaticRWLock *lock);
GLIB_DEPRECATED_IN_2_32
GPrivate * g_private_new (GDestroyNotify notify);
typedef struct _GStaticPrivate GStaticPrivate GLIB_DEPRECATED_TYPE_IN_2_32_FOR(GPrivate);
struct _GStaticPrivate
{
/*< private >*/
guint index;
} GLIB_DEPRECATED_TYPE_IN_2_32_FOR(GPrivate);
#define G_STATIC_PRIVATE_INIT { 0 } GLIB_DEPRECATED_MACRO_IN_2_32_FOR(G_PRIVATE_INIT)
GLIB_DEPRECATED_IN_2_32
void g_static_private_init (GStaticPrivate *private_key);
GLIB_DEPRECATED_IN_2_32_FOR(g_private_get)
gpointer g_static_private_get (GStaticPrivate *private_key);
GLIB_DEPRECATED_IN_2_32_FOR(g_private_set)
void g_static_private_set (GStaticPrivate *private_key,
gpointer data,
GDestroyNotify notify);
GLIB_DEPRECATED_IN_2_32
void g_static_private_free (GStaticPrivate *private_key);
GLIB_DEPRECATED_IN_2_32
gboolean g_once_init_enter_impl (volatile gsize *location);
GLIB_DEPRECATED_IN_2_32
void g_thread_init (gpointer vtable);
GLIB_DEPRECATED_IN_2_32
void g_thread_init_with_errorcheck_mutexes (gpointer vtable);
GLIB_DEPRECATED_IN_2_32
gboolean g_thread_get_initialized (void);
GLIB_VAR gboolean g_threads_got_initialized;
#define g_thread_supported() (1) GLIB_DEPRECATED_MACRO_IN_2_32
GLIB_DEPRECATED_IN_2_32
GMutex * g_mutex_new (void);
GLIB_DEPRECATED_IN_2_32
void g_mutex_free (GMutex *mutex);
GLIB_DEPRECATED_IN_2_32
GCond * g_cond_new (void);
GLIB_DEPRECATED_IN_2_32
void g_cond_free (GCond *cond);
GLIB_DEPRECATED_IN_2_32
gboolean g_cond_timed_wait (GCond *cond,
GMutex *mutex,
GTimeVal *timeval);
G_GNUC_END_IGNORE_DEPRECATIONS
G_END_DECLS
#endif /* __G_DEPRECATED_THREAD_H__ */