From 35f43c0a1adf5a9a08db7f06ba0dc1be41ead884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=B6hler?= Date: Sat, 20 Jan 2007 15:21:35 +0000 Subject: [PATCH] Raise dependencies: GLib 2.6, Pango 1.8, GTK+ 2.6. Ask for GLib 2.6 and GTK+ 2.6. Let the included GOffice 0.0.4 and LibGSF 1.12.3 use their native base dependencies. Remove all #ifdefs and compatibility code that were necessary to make GnuCash, GOffice and LibGSF compile on an older setup (GLib 2.4, Pango 1.6, GTK+ 2.4). git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15400 57a11ea4-9604-0410-9ed3-97b8803252fd --- configure.in | 64 +- goffice-config.h.in | 7 - gsf-config.h.in | 3 - lib/Makefile.am | 4 +- lib/glib26/Makefile.am | 16 - lib/glib26/dummy.c | 6 - lib/glib26/gkeyfile.c | 3286 ----------------- lib/glib26/gkeyfile.h | 199 - lib/glib26/gutils26.c | 1065 ------ lib/glib26/gutils26.h | 185 - lib/goffice-0.0.4/goffice/Makefile.am | 6 - .../drawing/god-drawing-renderer-gdk.c | 7 - lib/goffice-0.0.4/goffice/glib24_26-compat.c | 359 -- lib/goffice-0.0.4/goffice/glib24_26-compat.h | 39 - lib/goffice-0.0.4/goffice/graph/gog-chart.c | 4 - lib/goffice-0.0.4/goffice/graph/gog-object.c | 4 - lib/goffice-0.0.4/goffice/graph/gog-plot.c | 4 - lib/goffice-0.0.4/goffice/gtk/goffice-gtk.c | 9 - lib/goffice-0.0.4/goffice/utils/datetime.c | 4 - .../goffice/utils/go-libxml-extras.c | 4 - lib/libgsf-1.12.3/gsf/Makefile.am | 8 - lib/libgsf-1.12.3/gsf/glib24_26-compat.c | 204 - lib/libgsf-1.12.3/gsf/glib24_26-compat.h | 79 - lib/libgsf-1.12.3/gsf/gsf-input-memory.c | 4 - lib/libgsf-1.12.3/gsf/gsf-input-stdio.c | 4 - lib/libgsf-1.12.3/gsf/gsf-outfile-stdio.c | 4 - lib/libgsf-1.12.3/gsf/gsf-outfile-zip.c | 4 - lib/libgsf-1.12.3/gsf/gsf-output-stdio.c | 4 - lib/libgsf-1.12.3/gsf/gsf-utils.c | 4 - lib/libgsf-1.12.3/tests/test-cp-zip.c | 4 - src/Makefile.am | 3 +- src/app-utils/file-utils.h | 3 - src/bin/gnucash-bin.c | 51 - src/business/business-gnome/dialog-invoice.c | 4 - src/core-utils/gnc-gkeyfile-utils.h | 4 - src/core-utils/gnc-gtk-utils.c | 21 - src/core-utils/gnc-gtk-utils.h | 10 - src/engine/gnc-filepath-utils.c | 4 - src/gnome-utils/dialog-account.c | 3 - src/gnome-utils/dialog-options.c | 44 - src/gnome-utils/dialog-utils.c | 62 - src/gnome-utils/dialog-utils.h | 7 - src/gnome-utils/gnc-main-window.c | 46 - src/gnome-utils/gnc-plugin-file-history.c | 1 - src/gnome-utils/gnc-plugin-page.h | 4 - src/gnome-utils/gnc-tree-view-account.c | 4 - src/gnome-utils/gnc-tree-view.c | 2 - src/gnome-utils/gnc-tree-view.h | 3 +- src/gnome-utils/gnctreemodelsort.c | 1 - src/gnome/gnc-plugin-page-account-tree.c | 3 - src/gnome/gnc-plugin-page-budget.c | 4 - src/gnome/gnc-plugin-page-register.c | 5 - src/gnome/gnc-plugin-page-sx-list.c | 3 - src/gnome/window-reconcile.c | 1 - src/gtk-compat.h | 29 - src/import-export/hbci/dialog-hbcitrans.c | 1 - .../register-gnome/gnucash-item-list.c | 1 - .../report-gnome/gnc-plugin-page-report.c | 4 - 58 files changed, 15 insertions(+), 5907 deletions(-) delete mode 100644 lib/glib26/Makefile.am delete mode 100644 lib/glib26/dummy.c delete mode 100644 lib/glib26/gkeyfile.c delete mode 100644 lib/glib26/gkeyfile.h delete mode 100644 lib/glib26/gutils26.c delete mode 100644 lib/glib26/gutils26.h delete mode 100644 lib/goffice-0.0.4/goffice/glib24_26-compat.c delete mode 100644 lib/goffice-0.0.4/goffice/glib24_26-compat.h delete mode 100644 lib/libgsf-1.12.3/gsf/glib24_26-compat.c delete mode 100644 lib/libgsf-1.12.3/gsf/glib24_26-compat.h delete mode 100644 src/gtk-compat.h diff --git a/configure.in b/configure.in index 9379baf8fb..fddb92dc34 100644 --- a/configure.in +++ b/configure.in @@ -182,8 +182,8 @@ fi ### -------------------------------------------------------------------------- ### Glib checks.. -AM_PATH_GLIB_2_0(2.4.0,,AC_MSG_ERROR([ -*** GLIB >= 2.4 is required to build Gnucash; please make sure you have the +AM_PATH_GLIB_2_0(2.6.0,,AC_MSG_ERROR([ +*** GLIB >= 2.6 is required to build Gnucash; please make sure you have the *** development headers installed. The latest version of GLIB is *** always available at ftp://ftp.gnome.org/pub/gnome/sources/glib/.]), gthread gobject gmodule) @@ -193,21 +193,6 @@ then AC_MSG_ERROR([Cannot find glib. Check config.log]) fi -AC_MSG_CHECKING(for GLIB - version >= 2.6.0) -if $PKG_CONFIG 'glib-2.0 >= 2.6.0' -then - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_GLIB26,1,[System has glib 2.6.0 or better]) - HAVE_GLIB26=yes -else - GLIB24_LIBS="$GLIB_LIBS" - GLIB_LIBS="\${top_builddir}/lib/glib26/libgncglib.la $GLIB_LIBS" - GLIB_CFLAGS="-I\${top_srcdir}/lib/glib26 $GLIB_CFLAGS" - AC_MSG_RESULT(no) - AC_SUBST(GLIB24_LIBS) -fi -AM_CONDITIONAL(HAVE_GLIB26, test "x$HAVE_GLIB26" = "xyes" ) - AC_MSG_CHECKING(for GLIB - version >= 2.9.0) if $PKG_CONFIG 'glib-2.0 >= 2.9.0' then @@ -1014,7 +999,7 @@ then fi GNOME_COMPILE_WARNINGS - PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.4) + PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.6) AS_SCRUB_INCLUDE(GTK_CFLAGS) AC_SUBST(GTK_CFLAGS) AC_SUBST(GTK_LIBS) @@ -1115,18 +1100,6 @@ fi ### Only test this if we're building the GUI if test x${gnc_build_gui} = xtrue ; then - AC_MSG_CHECKING(for GTK - version >= 2.6.0) - if $PKG_CONFIG 'gtk+-2.0 >= 2.6.0' - then - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_GTK26,1,[System has gtk 2.6.0 or better]) - HAVE_GTK26=yes - else - AC_MSG_RESULT(no) - fi - AM_CONDITIONAL(HAVE_GTK26, test "x$HAVE_GTK26" = "xyes" ) - - AC_MSG_CHECKING(for GTK - version >= 2.10.0) if $PKG_CONFIG 'gtk+-2.0 >= 2.10.0' then @@ -1139,18 +1112,6 @@ then AM_CONDITIONAL(HAVE_GTK_2_10, test "x$HAVE_GTK_2_10" = "xyes" ) - AC_MSG_CHECKING(for pango version >= 1.8.0) - if $PKG_CONFIG 'pango >= 1.8.0' - then - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_PANGO18,1,[System has pango 1.8.0 or better]) - HAVE_PANGO18=yes - else - AC_MSG_RESULT(no) - fi - AM_CONDITIONAL(HAVE_PANGO18, test "x$HAVE_PANGO18" = "xyes" ) - - dnl @@fixme dnl use both PKG_CHECK_MODULES and `$PKG_CONFIG`; the first importantly sets dnl MUMBLE_{LIBS,CFLAGS}... @@ -1245,8 +1206,8 @@ then ]) dnl Modules common to libgsf and libgsf-gnome libgsf_reqs=" - gobject-2.0 >= 2.4.0 - glib-2.0 >= 2.4.0 + gobject-2.0 >= 2.6.0 + glib-2.0 >= 2.6.0 libxml-2.0 >= 2.4.16 " dnl Modules required for libgsf-gnome @@ -1523,15 +1484,15 @@ then dnl ***************************** # libgsf-1 >= 1.12.2 goffice_reqs=" - glib-2.0 >= 2.4.7 - gobject-2.0 >= 2.4.7 - gmodule-2.0 >= 2.4.7 + glib-2.0 >= 2.6.4 + gobject-2.0 >= 2.6.4 + gmodule-2.0 >= 2.6.4 libxml-2.0 >= 2.4.12 - pango >= 1.6.0 - pangoft2 >= 1.6.0 + pango >= 1.8.1 + pangoft2 >= 1.8.1 " goffice_gtk_reqs=" - gtk+-2.0 >= 2.4.13 + gtk+-2.0 >= 2.6.0 libglade-2.0 >= 2.3.6 libgnomeprint-2.2 >= 2.8.0 libart-2.0 >= 2.3.11 @@ -1829,9 +1790,7 @@ then ### ------------------------------------------------------------------------ else ### A bunch of am conditionals that need to be set - AM_CONDITIONAL(HAVE_GTK26, false ) AM_CONDITIONAL(HAVE_GTK_2_10, false) - AM_CONDITIONAL(HAVE_PANGO18, false ) AM_CONDITIONAL(HAVE_LIBGSF, false) AM_CONDITIONAL(HAVE_GOFFICE, false) AM_CONDITIONAL(WITH_LIBGSF_GNOME, false) @@ -2091,7 +2050,6 @@ AC_CONFIG_FILES(po/Makefile.in doc/examples/Makefile intl-scm/Makefile lib/Makefile - lib/glib26/Makefile lib/guile-www/Makefile lib/srfi/Makefile lib/libc/Makefile diff --git a/goffice-config.h.in b/goffice-config.h.in index 8af504eff8..3908a015cf 100644 --- a/goffice-config.h.in +++ b/goffice-config.h.in @@ -1,12 +1,5 @@ /* goffice/goffice-config.h.in. Generated from configure.in by autoheader. */ -/* Conditionally include >2.4 pieces we use. */ -#undef HAVE_GLIB26 -#undef HAVE_GTK26 - -/* Conditionally work around exposed-in-1.8-functionality. */ -#undef HAVE_PANGO18 - /* always defined to indicate that i18n is enabled */ #undef ENABLE_NLS diff --git a/gsf-config.h.in b/gsf-config.h.in index 061e504fe1..2cfd747274 100644 --- a/gsf-config.h.in +++ b/gsf-config.h.in @@ -9,9 +9,6 @@ /* Define to 1 if you have the `bind_textdomain_codeset' function. */ #undef HAVE_BIND_TEXTDOMAIN_CODESET -/* Conditionally include glib-2.0 > 2.4 functionality. */ -#undef HAVE_GLIB26 - /* Is bzip2 available and enabled */ #undef HAVE_BZ2 diff --git a/lib/Makefile.am b/lib/Makefile.am index 4dfee835b5..056da09acc 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,5 +1,5 @@ -SUBDIRS = libc glib26 guile-www srfi -DIST_SUBDIRS = libc glib26 guile-www srfi libgsf-1.12.3 goffice-0.0.4 libqof +SUBDIRS = libc guile-www srfi +DIST_SUBDIRS = libc guile-www srfi libgsf-1.12.3 goffice-0.0.4 libqof if !HAVE_GOFFICE if !HAVE_LIBGSF diff --git a/lib/glib26/Makefile.am b/lib/glib26/Makefile.am deleted file mode 100644 index 9032780ab2..0000000000 --- a/lib/glib26/Makefile.am +++ /dev/null @@ -1,16 +0,0 @@ -noinst_LTLIBRARIES = libgncglib.la - -DUMMYSRCS=dummy.c -REALSRCS=gkeyfile.c gkeyfile.h gutils26.c gutils26.h - -if HAVE_GLIB26 -libgncglib_la_SOURCES = $(DUMMYSRCS) -else -libgncglib_la_SOURCES = $(REALSRCS) -endif - -libgncglib_la_LIBADD = ${GLIB24_LIBS} - -AM_CFLAGS = ${GLIB_CFLAGS} - -EXTRA_DIST=$(DUMMYSRCS) $(REALSRCS) diff --git a/lib/glib26/dummy.c b/lib/glib26/dummy.c deleted file mode 100644 index 28834314c2..0000000000 --- a/lib/glib26/dummy.c +++ /dev/null @@ -1,6 +0,0 @@ -void g_key_file_dumy_function (void); - -void -g_key_file_dumy_function (void) -{ -} diff --git a/lib/glib26/gkeyfile.c b/lib/glib26/gkeyfile.c deleted file mode 100644 index 9080946f12..0000000000 --- a/lib/glib26/gkeyfile.c +++ /dev/null @@ -1,3286 +0,0 @@ -/* gkeyfile.c - key file parser - * - * Copyright 2004 Red Hat, Inc. - * - * Written by Ray Strode - * Matthias Clasen - * - * GLib 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 of the - * License, or (at your option) any later version. - * - * GLib 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 GLib; see the file COPYING.LIB. If not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include "config.h" - -#include "gkeyfile.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef G_OS_WIN32 -#include - -#ifndef S_ISREG -#define S_ISREG(mode) ((mode)&_S_IFREG) -#endif - -#endif /* G_OS_WIN23 */ - -/* Start hacks to make this file compile with glib 2.4 */ -#include "gutils26.h" -#include -#define g_open(X,Y,Z) open(X,Y,Z) -#define _(X) X -/* End hacks to make this file compile with glib 2.4 */ - -#if 0 -#include "gconvert.h" -#include "gdataset.h" -#include "gerror.h" -#include "gfileutils.h" -#include "ghash.h" -#include "glibintl.h" -#include "glist.h" -#include "gslist.h" -#include "gmem.h" -#include "gmessages.h" -#include "gstdio.h" -#include "gstring.h" -#include "gstrfuncs.h" -#include "gutils.h" - -#include "galias.h" -#endif - -typedef struct _GKeyFileGroup GKeyFileGroup; - -struct _GKeyFile -{ - GList *groups; - - GKeyFileGroup *start_group; - GKeyFileGroup *current_group; - - GString *parse_buffer; /* Holds up to one line of not-yet-parsed data */ - - /* Used for sizing the output buffer during serialization - */ - gsize approximate_size; - - gchar list_separator; - - GKeyFileFlags flags; -}; - -typedef struct _GKeyFileKeyValuePair GKeyFileKeyValuePair; - -struct _GKeyFileGroup -{ - const gchar *name; /* NULL for above first group (which will be comments) */ - - GKeyFileKeyValuePair *comment; /* Special comment that is stuck to the top of a group */ - - GList *key_value_pairs; - - /* Used in parallel with key_value_pairs for - * increased lookup performance - */ - GHashTable *lookup_map; -}; - -struct _GKeyFileKeyValuePair -{ - gchar *key; /* NULL for comments */ - gchar *value; -}; - -static gint find_file_in_data_dirs (const gchar *file, - gchar **output_file, - gchar ***data_dirs, - GError **error); -static gboolean g_key_file_load_from_fd (GKeyFile *key_file, - gint fd, - GKeyFileFlags flags, - GError **error); -static GList *g_key_file_lookup_group_node (GKeyFile *key_file, - const gchar *group_name); -static GKeyFileGroup *g_key_file_lookup_group (GKeyFile *key_file, - const gchar *group_name); - -static GList *g_key_file_lookup_key_value_pair_node (GKeyFile *key_file, - GKeyFileGroup *group, - const gchar *key); -static GKeyFileKeyValuePair *g_key_file_lookup_key_value_pair (GKeyFile *key_file, - GKeyFileGroup *group, - const gchar *key); - -static void g_key_file_remove_group_node (GKeyFile *key_file, - GList *group_node); -static void g_key_file_remove_key_value_pair_node (GKeyFile *key_file, - GKeyFileGroup *group, - GList *pair_node); - -static void g_key_file_add_key (GKeyFile *key_file, - GKeyFileGroup *group, - const gchar *key, - const gchar *value); -static void g_key_file_add_group (GKeyFile *key_file, - const gchar *group_name); -static void g_key_file_key_value_pair_free (GKeyFileKeyValuePair *pair); -static gboolean g_key_file_line_is_comment (const gchar *line); -static gboolean g_key_file_line_is_group (const gchar *line); -static gboolean g_key_file_line_is_key_value_pair (const gchar *line); -static gchar *g_key_file_parse_value_as_string (GKeyFile *key_file, - const gchar *value, - GSList **separators, - GError **error); -static gchar *g_key_file_parse_string_as_value (GKeyFile *key_file, - const gchar *string, - gboolean escape_separator); -static gint g_key_file_parse_value_as_integer (GKeyFile *key_file, - const gchar *value, - GError **error); -static gchar *g_key_file_parse_integer_as_value (GKeyFile *key_file, - gint value); -static gboolean g_key_file_parse_value_as_boolean (GKeyFile *key_file, - const gchar *value, - GError **error); -static gchar *g_key_file_parse_boolean_as_value (GKeyFile *key_file, - gboolean value); -static gchar *g_key_file_parse_value_as_comment (GKeyFile *key_file, - const gchar *value); -static gchar *g_key_file_parse_comment_as_value (GKeyFile *key_file, - const gchar *comment); -static void g_key_file_parse_key_value_pair (GKeyFile *key_file, - const gchar *line, - gsize length, - GError **error); -static void g_key_file_parse_comment (GKeyFile *key_file, - const gchar *line, - gsize length, - GError **error); -static void g_key_file_parse_group (GKeyFile *key_file, - const gchar *line, - gsize length, - GError **error); -static gchar *key_get_locale (const gchar *key); -static void g_key_file_parse_data (GKeyFile *key_file, - const gchar *data, - gsize length, - GError **error); -static void g_key_file_flush_parse_buffer (GKeyFile *key_file, - GError **error); - - -GQuark -g_key_file_error_quark (void) -{ - static GQuark error_quark = 0; - - if (error_quark == 0) - error_quark = g_quark_from_static_string ("g-key-file-error-quark"); - - return error_quark; -} - -static void -g_key_file_init (GKeyFile *key_file) -{ - key_file->current_group = g_new0 (GKeyFileGroup, 1); - key_file->groups = g_list_prepend (NULL, key_file->current_group); - key_file->start_group = NULL; - key_file->parse_buffer = g_string_sized_new (128); - key_file->approximate_size = 0; - key_file->list_separator = ';'; - key_file->flags = 0; -} - -static void -g_key_file_clear (GKeyFile *key_file) -{ - GList *tmp, *group_node; - - if (key_file->parse_buffer) - g_string_free (key_file->parse_buffer, TRUE); - - tmp = key_file->groups; - while (tmp != NULL) - { - group_node = tmp; - tmp = tmp->next; - g_key_file_remove_group_node (key_file, group_node); - } - - g_assert (key_file->groups == NULL); -} - - -/** - * g_key_file_new: - * - * Creates a new empty #GKeyFile object. Use g_key_file_load_from_file(), - * g_key_file_load_from_data() or g_key_file_load_from_data_dirs() to - * read an existing key file. - * - * Return value: an empty #GKeyFile. - * - * Since: 2.6 - **/ -GKeyFile * -g_key_file_new (void) -{ - GKeyFile *key_file; - - key_file = g_new0 (GKeyFile, 1); - g_key_file_init (key_file); - - return key_file; -} - -/** - * g_key_file_set_list_separator: - * @key_file: a #GKeyFile - * @separator: the separator - * - * Sets the character which is used to separate - * values in lists. Typically ';' or ',' are used - * as separators. The default list separator is ';'. - * - * Since: 2.6 - */ -void -g_key_file_set_list_separator (GKeyFile *key_file, - gchar separator) -{ - key_file->list_separator = separator; -} - - -/* Iterates through all the directories in *dirs trying to - * open file. When it successfully locates and opens a file it - * returns the file descriptor to the open file. It also - * outputs the absolute path of the file in output_file and - * leaves the unchecked directories in *dirs. - */ -static gint -find_file_in_data_dirs (const gchar *file, - gchar **output_file, - gchar ***dirs, - GError **error) -{ - gchar **data_dirs, *data_dir, *path; - gint fd; - - path = NULL; - fd = -1; - - if (dirs == NULL) - return fd; - - data_dirs = *dirs; - - while (data_dirs && (data_dir = *data_dirs) && fd < 0) - { - gchar *candidate_file, *sub_dir; - - candidate_file = (gchar *) file; - sub_dir = g_strdup (""); - while (candidate_file != NULL && fd < 0) - { - gchar *p; - - path = g_build_filename (data_dir, sub_dir, - candidate_file, NULL); - - fd = g_open (path, O_RDONLY, 0); - - if (fd < 0) - { - g_free (path); - path = NULL; - } - - candidate_file = strchr (candidate_file, '-'); - - if (candidate_file == NULL) - break; - - candidate_file++; - - g_free (sub_dir); - sub_dir = g_strndup (file, candidate_file - file - 1); - - for (p = sub_dir; *p != '\0'; p++) - { - if (*p == '-') - *p = G_DIR_SEPARATOR; - } - } - g_free (sub_dir); - data_dirs++; - } - - *dirs = data_dirs; - - if (fd < 0) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_NOT_FOUND, - _("Valid key file could not be " - "found in data dirs")); - } - - if (output_file != NULL && fd > 0) - *output_file = g_strdup (path); - - g_free (path); - - return fd; -} - -static gboolean -g_key_file_load_from_fd (GKeyFile *key_file, - gint fd, - GKeyFileFlags flags, - GError **error) -{ - GError *key_file_error = NULL; - gsize bytes_read; - struct stat stat_buf; - gchar read_buf[4096]; - - if (fstat (fd, &stat_buf) < 0) - { - g_set_error (error, G_FILE_ERROR, - g_file_error_from_errno (errno), - "%s", g_strerror (errno)); - return FALSE; - } - - if (!S_ISREG (stat_buf.st_mode)) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_PARSE, - _("Not a regular file")); - return FALSE; - } - - if (stat_buf.st_size == 0) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_PARSE, - _("File is empty")); - return FALSE; - } - - if (key_file->approximate_size > 0) - { - g_key_file_clear (key_file); - g_key_file_init (key_file); - } - key_file->flags = flags; - - bytes_read = 0; - do - { - bytes_read = read (fd, read_buf, 4096); - - if (bytes_read == 0) /* End of File */ - break; - - if (bytes_read < 0) - { - if (errno == EINTR || errno == EAGAIN) - continue; - - g_set_error (error, G_FILE_ERROR, - g_file_error_from_errno (errno), - "%s", g_strerror (errno)); - return FALSE; - } - - g_key_file_parse_data (key_file, - read_buf, bytes_read, - &key_file_error); - } - while (!key_file_error); - - if (key_file_error) - { - g_propagate_error (error, key_file_error); - return FALSE; - } - - g_key_file_flush_parse_buffer (key_file, &key_file_error); - - if (key_file_error) - { - g_propagate_error (error, key_file_error); - return FALSE; - } - - return TRUE; -} - -/** - * g_key_file_load_from_file: - * @key_file: an empty #GKeyFile struct - * @file: the path of a filename to load, in the GLib file name encoding - * @flags: flags from #GKeyFileFlags - * @error: return location for a #GError, or %NULL - * - * Loads a key file into an empty #GKeyFile structure. - * If the file could not be loaded then %error is set to - * either a #GFileError or #GKeyFileError. - * - * Return value: %TRUE if a key file could be loaded, %FALSE othewise - * Since: 2.6 - **/ -gboolean -g_key_file_load_from_file (GKeyFile *key_file, - const gchar *file, - GKeyFileFlags flags, - GError **error) -{ - GError *key_file_error = NULL; - gint fd; - - g_return_val_if_fail (key_file != NULL, FALSE); - g_return_val_if_fail (file != NULL, FALSE); - - fd = g_open (file, O_RDONLY, 0); - - if (fd < 0) - { - g_set_error (error, G_FILE_ERROR, - g_file_error_from_errno (errno), - "%s", g_strerror (errno)); - return FALSE; - } - - g_key_file_load_from_fd (key_file, fd, flags, &key_file_error); - close (fd); - - if (key_file_error) - { - g_propagate_error (error, key_file_error); - return FALSE; - } - - return TRUE; -} - -/** - * g_key_file_load_from_data: - * @key_file: an empty #GKeyFile struct - * @data: key file loaded in memory. - * @length: the length of @data in bytes - * @flags: flags from #GKeyFileFlags - * @error: return location for a #GError, or %NULL - * - * Loads a key file from memory into an empty #GKeyFile structure. If - * the object cannot be created then %error is set to a - * #GKeyFileError. - * - * Return value: %TRUE if a key file could be loaded, %FALSE othewise - * Since: 2.6 - **/ -gboolean -g_key_file_load_from_data (GKeyFile *key_file, - const gchar *data, - gsize length, - GKeyFileFlags flags, - GError **error) -{ - GError *key_file_error = NULL; - - g_return_val_if_fail (key_file != NULL, FALSE); - g_return_val_if_fail (data != NULL, FALSE); - g_return_val_if_fail (length != 0, FALSE); - - if (length == (gsize)-1) - length = strlen (data); - - if (key_file->approximate_size > 0) - { - g_key_file_clear (key_file); - g_key_file_init (key_file); - } - key_file->flags = flags; - - g_key_file_parse_data (key_file, data, length, &key_file_error); - - if (key_file_error) - { - g_propagate_error (error, key_file_error); - return FALSE; - } - - g_key_file_flush_parse_buffer (key_file, &key_file_error); - - if (key_file_error) - { - g_propagate_error (error, key_file_error); - return FALSE; - } - - return TRUE; -} - -/** - * g_key_file_load_from_data_dirs: - * @key_file: an empty #GKeyFile struct - * @file: a relative path to a filename to open and parse - * @full_path: return location for a string containing the full path - * of the file, or %NULL - * @flags: flags from #GKeyFileFlags - * @error: return location for a #GError, or %NULL - * - * This function looks for a key file named @file in the paths - * returned from g_get_user_data_dir() and g_get_system_data_dirs(), - * loads the file into @key_file and returns the file's full path in - * @full_path. If the file could not be loaded then an %error is - * set to either a #GFileError or #GKeyFileError. - * - * Return value: %TRUE if a key file could be loaded, %FALSE othewise - * Since: 2.6 - **/ -gboolean -g_key_file_load_from_data_dirs (GKeyFile *key_file, - const gchar *file, - gchar **full_path, - GKeyFileFlags flags, - GError **error) -{ - GError *key_file_error = NULL; - gchar **all_data_dirs, **data_dirs; - const gchar * user_data_dir; - const gchar * const * system_data_dirs; - gsize i, j; - gchar *output_path = NULL; - gint fd; - gboolean found_file; - - g_return_val_if_fail (key_file != NULL, FALSE); - g_return_val_if_fail (!g_path_is_absolute (file), FALSE); - - user_data_dir = g_get_user_data_dir (); - system_data_dirs = g_get_system_data_dirs (); - all_data_dirs = g_new0 (gchar *, g_strv_length ((gchar **)system_data_dirs) + 2); - - i = 0; - all_data_dirs[i++] = g_strdup (user_data_dir); - - j = 0; - while (system_data_dirs[j] != NULL) - all_data_dirs[i++] = g_strdup (system_data_dirs[j++]); - - found_file = FALSE; - data_dirs = all_data_dirs; - while (*data_dirs != NULL && !found_file) - { - fd = find_file_in_data_dirs (file, &output_path, &data_dirs, - &key_file_error); - - if (fd < 0) - { - if (key_file_error) - g_propagate_error (error, key_file_error); - break; - } - - found_file = g_key_file_load_from_fd (key_file, fd, flags, - &key_file_error); - close (fd); - - if (key_file_error) - { - g_propagate_error (error, key_file_error); - g_free (output_path); - break; - } - - if (full_path) - *full_path = output_path; - } - - g_strfreev (all_data_dirs); - return found_file; -} - -/** - * g_key_file_free: - * @key_file: a #GKeyFile - * - * Frees a #GKeyFile. - * - * Since: 2.6 - **/ -void -g_key_file_free (GKeyFile *key_file) -{ - g_return_if_fail (key_file != NULL); - - g_key_file_clear (key_file); - g_free (key_file); -} - -/* If G_KEY_FILE_KEEP_TRANSLATIONS is not set, only returns - * true for locales that match those in g_get_language_names(). - */ -static gboolean -g_key_file_locale_is_interesting (GKeyFile *key_file, - const gchar *locale) -{ - const gchar * const * current_locales; - gsize i; - - if (key_file->flags & G_KEY_FILE_KEEP_TRANSLATIONS) - return TRUE; - - current_locales = g_get_language_names (); - - for (i = 0; current_locales[i] != NULL; i++) - { - if (g_ascii_strcasecmp (current_locales[i], locale) == 0) - return TRUE; - } - - return FALSE; -} - -static void -g_key_file_parse_line (GKeyFile *key_file, - const gchar *line, - gsize length, - GError **error) -{ - GError *parse_error = NULL; - gchar *line_start; - - g_return_if_fail (key_file != NULL); - g_return_if_fail (line != NULL); - - line_start = (gchar *) line; - while (g_ascii_isspace (*line_start)) - line_start++; - - if (g_key_file_line_is_comment (line_start)) - g_key_file_parse_comment (key_file, line, length, &parse_error); - else if (g_key_file_line_is_group (line_start)) - g_key_file_parse_group (key_file, line_start, - length - (line_start - line), - &parse_error); - else if (g_key_file_line_is_key_value_pair (line_start)) - g_key_file_parse_key_value_pair (key_file, line_start, - length - (line_start - line), - &parse_error); - else - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_PARSE, - _("Key file contains line '%s' which is not " - "a key-value pair, group, or comment"), line); - return; - } - - if (parse_error) - g_propagate_error (error, parse_error); -} - -static void -g_key_file_parse_comment (GKeyFile *key_file, - const gchar *line, - gsize length, - GError **error) -{ - GKeyFileKeyValuePair *pair; - - if (!(key_file->flags & G_KEY_FILE_KEEP_COMMENTS)) - return; - - g_assert (key_file->current_group != NULL); - - pair = g_new0 (GKeyFileKeyValuePair, 1); - - pair->key = NULL; - pair->value = g_strndup (line, length); - - key_file->current_group->key_value_pairs = - g_list_prepend (key_file->current_group->key_value_pairs, pair); -} - -static void -g_key_file_parse_group (GKeyFile *key_file, - const gchar *line, - gsize length, - GError **error) -{ - gchar *group_name; - const gchar *group_name_start, *group_name_end; - - /* advance past opening '[' - */ - group_name_start = line + 1; - group_name_end = line + length - 1; - - while (*group_name_end != ']') - group_name_end--; - - group_name = g_strndup (group_name_start, - group_name_end - group_name_start); - - g_key_file_add_group (key_file, group_name); - g_free (group_name); -} - -static void -g_key_file_parse_key_value_pair (GKeyFile *key_file, - const gchar *line, - gsize length, - GError **error) -{ - gchar *key, *value, *key_end, *value_start, *locale; - gsize key_len, value_len; - - if (key_file->current_group == NULL || key_file->current_group->name == NULL) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_GROUP_NOT_FOUND, - _("Key file does not start with a group")); - return; - } - - key_end = value_start = strchr (line, '='); - - g_assert (key_end != NULL); - - key_end--; - value_start++; - - /* Pull the key name from the line (chomping trailing whitespace) - */ - while (g_ascii_isspace (*key_end)) - key_end--; - - key_len = key_end - line + 2; - - g_assert (key_len <= length); - - key = g_strndup (line, key_len - 1); - - /* Pull the value from the line (chugging leading whitespace) - */ - while (g_ascii_isspace (*value_start)) - value_start++; - - value_len = line + length - value_start + 1; - - value = g_strndup (value_start, value_len); - - g_assert (key_file->start_group != NULL); - - if (key_file->current_group - && key_file->current_group->name - && strcmp (key_file->start_group->name, - key_file->current_group->name) == 0 - && strcmp (key, "Encoding") == 0) - { - if (g_ascii_strcasecmp (value, "UTF-8") != 0) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_UNKNOWN_ENCODING, - _("Key file contains unsupported encoding '%s'"), value); - - g_free (key); - g_free (value); - return; - } - } - - /* Is this key a translation? If so, is it one that we care about? - */ - locale = key_get_locale (key); - - if (locale == NULL || g_key_file_locale_is_interesting (key_file, locale)) - g_key_file_add_key (key_file, key_file->current_group, key, value); - - g_free (locale); - g_free (key); - g_free (value); -} - -static gchar * -key_get_locale (const gchar *key) -{ - gchar *locale; - - locale = g_strrstr (key, "["); - - if (locale && strlen (locale) <= 2) - locale = NULL; - - if (locale) - locale = g_strndup (locale + 1, strlen (locale) - 2); - - return locale; -} - -static void -g_key_file_parse_data (GKeyFile *key_file, - const gchar *data, - gsize length, - GError **error) -{ - GError *parse_error; - gsize i; - - g_return_if_fail (key_file != NULL); - g_return_if_fail (data != NULL); - - parse_error = NULL; - - for (i = 0; i < length; i++) - { - if (data[i] == '\n') - { - if (i > 0 && data[i - 1] == '\r') - g_string_erase (key_file->parse_buffer, - key_file->parse_buffer->len - 1, - 1); - - /* When a newline is encountered flush the parse buffer so that the - * line can be parsed. Note that completely blank lines won't show - * up in the parse buffer, so they get parsed directly. - */ - if (key_file->parse_buffer->len > 0) - g_key_file_flush_parse_buffer (key_file, &parse_error); - else - g_key_file_parse_comment (key_file, "", 1, &parse_error); - - if (parse_error) - { - g_propagate_error (error, parse_error); - return; - } - } - else - g_string_append_c (key_file->parse_buffer, data[i]); - } - - key_file->approximate_size += length; -} - -static void -g_key_file_flush_parse_buffer (GKeyFile *key_file, - GError **error) -{ - GError *file_error = NULL; - - g_return_if_fail (key_file != NULL); - - file_error = NULL; - - if (key_file->parse_buffer->len > 0) - { - g_key_file_parse_line (key_file, key_file->parse_buffer->str, - key_file->parse_buffer->len, - &file_error); - g_string_erase (key_file->parse_buffer, 0, -1); - - if (file_error) - { - g_propagate_error (error, file_error); - return; - } - } -} - -/** - * g_key_file_to_data: - * @key_file: a #GKeyFile - * @length: return location for the length of the - * returned string, or %NULL - * @error: return location for a #GError, or %NULL - * - * This function outputs @key_file as a string. - * - * Return value: a newly allocated string holding - * the contents of the #GKeyFile - * - * Since: 2.6 - **/ -gchar * -g_key_file_to_data (GKeyFile *key_file, - gsize *length, - GError **error) -{ - GString *data_string; - gchar *data; - GList *group_node, *key_file_node; - - g_return_val_if_fail (key_file != NULL, NULL); - - data_string = g_string_sized_new (2 * key_file->approximate_size); - - for (group_node = g_list_last (key_file->groups); - group_node != NULL; - group_node = group_node->prev) - { - GKeyFileGroup *group; - - group = (GKeyFileGroup *) group_node->data; - - if (group->comment != NULL) - g_string_append_printf (data_string, "%s\n", group->comment->value); - if (group->name != NULL) - g_string_append_printf (data_string, "[%s]\n", group->name); - - for (key_file_node = g_list_last (group->key_value_pairs); - key_file_node != NULL; - key_file_node = key_file_node->prev) - { - GKeyFileKeyValuePair *pair; - - pair = (GKeyFileKeyValuePair *) key_file_node->data; - - if (pair->key != NULL) - g_string_append_printf (data_string, "%s=%s\n", pair->key, pair->value); - else - g_string_append_printf (data_string, "%s\n", pair->value); - } - } - - if (length) - *length = data_string->len; - - data = data_string->str; - - g_string_free (data_string, FALSE); - - return data; -} - -/** - * g_key_file_get_keys: - * @key_file: a #GKeyFile - * @group_name: a group name - * @length: return location for the number of keys returned, or %NULL - * @error: return location for a #GError, or %NULL - * - * Returns all keys for the group name @group_name. The array of - * returned keys will be %NULL-terminated, so @length may - * optionally be %NULL. In the event that the @group_name cannot - * be found, %NULL is returned and @error is set to - * #G_KEY_FILE_ERROR_GROUP_NOT_FOUND. - * - * Return value: a newly-allocated %NULL-terminated array of - * strings. Use g_strfreev() to free it. - * - * Since: 2.6 - **/ -gchar ** -g_key_file_get_keys (GKeyFile *key_file, - const gchar *group_name, - gsize *length, - GError **error) -{ - GKeyFileGroup *group; - GList *tmp; - gchar **keys; - gsize i, num_keys; - - g_return_val_if_fail (key_file != NULL, NULL); - g_return_val_if_fail (group_name != NULL, NULL); - - group = g_key_file_lookup_group (key_file, group_name); - - if (!group) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_GROUP_NOT_FOUND, - _("Key file does not have group '%s'"), - group_name ? group_name : "(null)"); - return NULL; - } - - num_keys = g_list_length (group->key_value_pairs); - - keys = (gchar **) g_new0 (gchar **, num_keys + 1); - - tmp = group->key_value_pairs; - for (i = 1; i <= num_keys; i++) - { - GKeyFileKeyValuePair *pair; - - pair = (GKeyFileKeyValuePair *) tmp->data; - keys[num_keys - i] = g_strdup (pair->key); - - tmp = tmp->next; - } - keys[num_keys] = NULL; - - if (length) - *length = num_keys; - - return keys; -} - -/** - * g_key_file_get_start_group: - * @key_file: a #GKeyFile - * - * Returns the name of the start group of the file. - * - * Return value: The start group of the key file. - * - * Since: 2.6 - **/ -gchar * -g_key_file_get_start_group (GKeyFile *key_file) -{ - g_return_val_if_fail (key_file != NULL, NULL); - - if (key_file->start_group) - return g_strdup (key_file->start_group->name); - - return NULL; -} - -/** - * g_key_file_get_groups: - * @key_file: a #GKeyFile - * @length: return location for the number of returned groups, or %NULL - * - * Returns all groups in the key file loaded with @key_file. The - * array of returned groups will be %NULL-terminated, so @length may - * optionally be %NULL. - * - * Return value: a newly-allocated %NULL-terminated array of strings. - * Use g_strfreev() to free it. - * Since: 2.6 - **/ -gchar ** -g_key_file_get_groups (GKeyFile *key_file, - gsize *length) -{ - GList *group_node; - gchar **groups; - gsize i, num_groups; - - g_return_val_if_fail (key_file != NULL, NULL); - - num_groups = g_list_length (key_file->groups); - - g_assert (num_groups > 0); - - /* Only need num_groups instead of num_groups + 1 - * because the first group of the file (last in the - * list) is always the comment group at the top, - * which we skip - */ - groups = (gchar **) g_new0 (gchar **, num_groups); - - group_node = g_list_last (key_file->groups); - - g_assert (((GKeyFileGroup *) group_node->data)->name == NULL); - - i = 0; - for (group_node = group_node->prev; - group_node != NULL; - group_node = group_node->prev) - { - GKeyFileGroup *group; - - group = (GKeyFileGroup *) group_node->data; - - g_assert (group->name != NULL); - - groups[i++] = g_strdup (group->name); - } - groups[i] = NULL; - - if (length) - *length = i; - - return groups; -} - -/** - * g_key_file_get_value: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @error: return location for a #GError, or %NULL - * - * Returns the value associated with @key under @group_name. - * - * In the event the key cannot be found, %NULL is returned and - * @error is set to #G_KEY_FILE_ERROR_KEY_NOT_FOUND. In the - * event that the @group_name cannot be found, %NULL is returned - * and @error is set to #G_KEY_FILE_ERROR_GROUP_NOT_FOUND. - * - * Return value: a newly allocated string or %NULL if the specified - * key cannot be found. - * - * Since: 2.6 - **/ -gchar * -g_key_file_get_value (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error) -{ - GKeyFileGroup *group; - GKeyFileKeyValuePair *pair; - gchar *value = NULL; - - g_return_val_if_fail (key_file != NULL, NULL); - g_return_val_if_fail (group_name != NULL, NULL); - g_return_val_if_fail (key != NULL, NULL); - - group = g_key_file_lookup_group (key_file, group_name); - - if (!group) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_GROUP_NOT_FOUND, - _("Key file does not have group '%s'"), - group_name ? group_name : "(null)"); - return NULL; - } - - pair = g_key_file_lookup_key_value_pair (key_file, group, key); - - if (pair) - value = g_strdup (pair->value); - else - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_KEY_NOT_FOUND, - _("Key file does not have key '%s'"), key); - - return value; -} - -/** - * g_key_file_set_value: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @value: a string - * - * Associates a new value with @key under @group_name. If @key - * cannot be found then it is created. If @group_name cannot be - * found then it is created. - * - * Since: 2.6 - **/ -void -g_key_file_set_value (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar *value) -{ - GKeyFileGroup *group; - GKeyFileKeyValuePair *pair; - - g_return_if_fail (key_file != NULL); - g_return_if_fail (group_name != NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (value != NULL); - - group = g_key_file_lookup_group (key_file, group_name); - - if (!group) - { - g_key_file_add_group (key_file, group_name); - group = (GKeyFileGroup *) key_file->groups->data; - - g_key_file_add_key (key_file, group, key, value); - } - else - { - pair = g_key_file_lookup_key_value_pair (key_file, group, key); - - if (!pair) - g_key_file_add_key (key_file, group, key, value); - else - { - g_free (pair->value); - pair->value = g_strdup (value); - } - } -} - -/** - * g_key_file_get_string: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @error: return location for a #GError, or %NULL - * - * Returns the value associated with @key under @group_name. - * - * In the event the key cannot be found, %NULL is returned and - * @error is set to #G_KEY_FILE_ERROR_KEY_NOT_FOUND. In the - * event that the @group_name cannot be found, %NULL is returned - * and @error is set to #G_KEY_FILE_ERROR_GROUP_NOT_FOUND. - * - * Return value: a newly allocated string or %NULL if the specified - * key cannot be found. - * - * Since: 2.6 - **/ -gchar * -g_key_file_get_string (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error) -{ - gchar *value, *string_value; - GError *key_file_error; - - g_return_val_if_fail (key_file != NULL, NULL); - g_return_val_if_fail (group_name != NULL, NULL); - g_return_val_if_fail (key != NULL, NULL); - - key_file_error = NULL; - - value = g_key_file_get_value (key_file, group_name, key, &key_file_error); - - if (key_file_error) - { - g_propagate_error (error, key_file_error); - return NULL; - } - - if (!g_utf8_validate (value, -1, NULL)) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_UNKNOWN_ENCODING, - _("Key file contains key '%s' with value '%s' " - "which is not UTF-8"), key, value); - g_free (value); - return NULL; - } - - string_value = g_key_file_parse_value_as_string (key_file, value, NULL, - &key_file_error); - g_free (value); - - if (key_file_error) - { - if (g_error_matches (key_file_error, - G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_INVALID_VALUE)) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_INVALID_VALUE, - _("Key file contains key '%s' " - "which has value that cannot be interpreted."), - key); - g_error_free (key_file_error); - } - else - g_propagate_error (error, key_file_error); - } - - return string_value; -} - -/** - * g_key_file_set_string: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @string: a string - * - * Associates a new string value with @key under @group_name. If - * @key cannot be found then it is created. If @group_name - * cannot be found then it is created. - * - * Since: 2.6 - **/ -void -g_key_file_set_string (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar *string) -{ - gchar *value; - - g_return_if_fail (key_file != NULL); - g_return_if_fail (group_name != NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (string != NULL); - - value = g_key_file_parse_string_as_value (key_file, string, FALSE); - g_key_file_set_value (key_file, group_name, key, value); - g_free (value); -} - -/** - * g_key_file_get_string_list: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @length: return location for the number of returned strings, or %NULL - * @error: return location for a #GError, or %NULL - * - * Returns the values associated with @key under @group_name. - * - * In the event the key cannot be found, %NULL is returned and - * @error is set to #G_KEY_FILE_ERROR_KEY_NOT_FOUND. In the - * event that the @group_name cannot be found, %NULL is returned - * and @error is set to #G_KEY_FILE_ERROR_GROUP_NOT_FOUND. - * - * Return value: a %NULL-terminated string array or %NULL if the specified - * key cannot be found. The array should be freed with g_strfreev(). - * - * Since: 2.6 - **/ -gchar ** -g_key_file_get_string_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - gsize *length, - GError **error) -{ - GError *key_file_error = NULL; - gchar *value, *string_value, **values; - gint i, len; - GSList *p, *pieces = NULL; - - g_return_val_if_fail (key_file != NULL, NULL); - g_return_val_if_fail (group_name != NULL, NULL); - g_return_val_if_fail (key != NULL, NULL); - - value = g_key_file_get_value (key_file, group_name, key, &key_file_error); - - if (key_file_error) - { - g_propagate_error (error, key_file_error); - return NULL; - } - - if (!g_utf8_validate (value, -1, NULL)) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_UNKNOWN_ENCODING, - _("Key file contains key '%s' with value '%s' " - "which is not UTF-8"), key, value); - g_free (value); - return NULL; - } - - string_value = g_key_file_parse_value_as_string (key_file, value, &pieces, &key_file_error); - g_free (value); - g_free (string_value); - - if (key_file_error) - { - if (g_error_matches (key_file_error, - G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_INVALID_VALUE)) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_INVALID_VALUE, - _("Key file contains key '%s' " - "which has value that cannot be interpreted."), - key); - g_error_free (key_file_error); - } - else - g_propagate_error (error, key_file_error); - } - - len = g_slist_length (pieces); - values = g_new0 (gchar *, len + 1); - for (p = pieces, i = 0; p; p = p->next) - values[i++] = p->data; - values[len] = NULL; - - g_slist_free (pieces); - - if (length) - *length = len; - - return values; -} - -/** - * g_key_file_set_string_list: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @list: an array of locale string values - * @length: number of locale string values in @list - * - * Associates a list of string values for @key under @group_name. - * If @key cannot be found then it is created. If @group_name - * cannot be found then it is created. - * - * Since: 2.6 - **/ -void -g_key_file_set_string_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar * const list[], - gsize length) -{ - GString *value_list; - gsize i; - - g_return_if_fail (key_file != NULL); - g_return_if_fail (group_name != NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (list != NULL); - - value_list = g_string_sized_new (length * 128); - for (i = 0; list[i] != NULL && i < length; i++) - { - gchar *value; - - value = g_key_file_parse_string_as_value (key_file, list[i], TRUE); - g_string_append (value_list, value); - g_string_append_c (value_list, key_file->list_separator); - - g_free (value); - } - - g_key_file_set_value (key_file, group_name, key, value_list->str); - g_string_free (value_list, TRUE); -} - -/** - * g_key_file_set_locale_string: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @locale: a locale - * @string: a string - * - * Associates a string value for @key and @locale under - * @group_name. If the translation for @key cannot be found - * then it is created. - * - * Since: 2.6 - **/ -void -g_key_file_set_locale_string (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar *locale, - const gchar *string) -{ - gchar *full_key, *value; - - g_return_if_fail (key_file != NULL); - g_return_if_fail (group_name != NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (locale != NULL); - g_return_if_fail (string != NULL); - - value = g_key_file_parse_string_as_value (key_file, string, FALSE); - full_key = g_strdup_printf ("%s[%s]", key, locale); - g_key_file_set_value (key_file, group_name, full_key, value); - g_free (full_key); - g_free (value); -} - -extern GSList *_g_compute_locale_variants (const gchar *locale); - -/** - * g_key_file_get_locale_string: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @locale: a locale or %NULL - * @error: return location for a #GError, or %NULL - * - * Returns the value associated with @key under @group_name - * translated in the given @locale if available. If @locale is - * %NULL then the current locale is assumed. - * - * If @key cannot be found then %NULL is returned and @error is set to - * #G_KEY_FILE_ERROR_KEY_NOT_FOUND. If the value associated - * with @key cannot be interpreted or no suitable translation can - * be found then the untranslated value is returned. - * - * Return value: a newly allocated string or %NULL if the specified key - * cannot be found. - * - * Since: 2.6 - **/ -gchar * -g_key_file_get_locale_string (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar *locale, - GError **error) -{ - gchar *candidate_key, *translated_value; - GError *key_file_error; - gchar **languages; - gboolean free_languages = FALSE; - gint i; - - g_return_val_if_fail (key_file != NULL, NULL); - g_return_val_if_fail (group_name != NULL, NULL); - g_return_val_if_fail (key != NULL, NULL); - - candidate_key = NULL; - translated_value = NULL; - key_file_error = NULL; - - if (locale) - { - GSList *l, *list; - - list = _g_compute_locale_variants (locale); - - languages = g_new0 (gchar *, g_slist_length (list) + 1); - for (l = list, i = 0; l; l = l->next, i++) - languages[i] = l->data; - languages[i] = NULL; - - g_slist_free (list); - free_languages = TRUE; - } - else - { - languages = (gchar **) g_get_language_names (); - free_languages = FALSE; - } - - for (i = 0; languages[i]; i++) - { - candidate_key = g_strdup_printf ("%s[%s]", key, languages[i]); - - translated_value = g_key_file_get_string (key_file, - group_name, - candidate_key, NULL); - g_free (candidate_key); - - if (translated_value && g_utf8_validate (translated_value, -1, NULL)) - break; - - g_free (translated_value); - translated_value = NULL; - } - - /* Fallback to untranslated key - */ - if (!translated_value) - { - translated_value = g_key_file_get_string (key_file, group_name, key, - &key_file_error); - - if (!translated_value) - g_propagate_error (error, key_file_error); - } - - if (free_languages) - g_strfreev (languages); - - return translated_value; -} - -/** - * g_key_file_get_locale_string_list: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @locale: a locale - * @length: return location for the number of returned strings or %NULL - * @error: return location for a #GError or %NULL - * - * Returns the values associated with @key under @group_name - * translated in the given @locale if available. If @locale is - * %NULL then the current locale is assumed. - - * If @key cannot be found then %NULL is returned and @error is set to - * #G_KEY_FILE_ERROR_KEY_NOT_FOUND. If the values associated - * with @key cannot be interpreted or no suitable translations - * can be found then the untranslated values are returned. - * The returned array is %NULL-terminated, so @length may optionally be %NULL. - * - * Return value: a newly allocated %NULL-terminated string array - * or %NULL if the key isn't found. The string array should be freed - * with g_strfreev(). - * - * Since: 2.6 - **/ -gchar ** -g_key_file_get_locale_string_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar *locale, - gsize *length, - GError **error) -{ - GError *key_file_error; - gchar **values, *value; - - g_return_val_if_fail (key_file != NULL, NULL); - g_return_val_if_fail (group_name != NULL, NULL); - g_return_val_if_fail (key != NULL, NULL); - - key_file_error = NULL; - - value = g_key_file_get_locale_string (key_file, group_name, - key, locale, - &key_file_error); - - if (key_file_error) - g_propagate_error (error, key_file_error); - - if (!value) - return NULL; - - if (value[strlen (value) - 1] == ';') - value[strlen (value) - 1] = '\0'; - - values = g_strsplit (value, ";", 0); - - g_free (value); - - if (length) - *length = g_strv_length (values); - - return values; -} - -/** - * g_key_file_set_locale_string_list: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @locale: a locale - * @list: a %NULL-terminated array of locale string values - * @length: the length of @list - * - * Associates a list of string values for @key and @locale under - * @group_name. If the translation for @key cannot be found then - * it is created. - * - * Since: 2.6 - **/ -void -g_key_file_set_locale_string_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar *locale, - const gchar * const list[], - gsize length) -{ - GString *value_list; - gchar *full_key; - gsize i; - - g_return_if_fail (key_file != NULL); - g_return_if_fail (group_name != NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (locale != NULL); - g_return_if_fail (length != 0); - - value_list = g_string_sized_new (length * 128); - for (i = 0; list[i] != NULL && i < length; i++) - { - gchar *value; - - value = g_key_file_parse_string_as_value (key_file, list[i], TRUE); - - g_string_append (value_list, value); - g_string_append_c (value_list, ';'); - - g_free (value); - } - - full_key = g_strdup_printf ("%s[%s]", key, locale); - g_key_file_set_value (key_file, group_name, full_key, value_list->str); - g_free (full_key); - g_string_free (value_list, TRUE); -} - -/** - * g_key_file_get_boolean: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @error: return location for a #GError - * - * Returns the value associated with @key under @group_name as a - * boolean. - * - * If @key cannot be found then the return value is undefined and - * @error is set to #G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if - * the value associated with @key cannot be interpreted as a boolean - * then the return value is also undefined and @error is set to - * #G_KEY_FILE_ERROR_INVALID_VALUE. - * - * Return value: the value associated with the key as a boolean - * Since: 2.6 - **/ -gboolean -g_key_file_get_boolean (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error) -{ - GError *key_file_error = NULL; - gchar *value; - gboolean bool_value; - - g_return_val_if_fail (key_file != NULL, FALSE); - g_return_val_if_fail (group_name != NULL, FALSE); - g_return_val_if_fail (key != NULL, FALSE); - - value = g_key_file_get_value (key_file, group_name, key, &key_file_error); - - if (!value) - { - g_propagate_error (error, key_file_error); - return FALSE; - } - - bool_value = g_key_file_parse_value_as_boolean (key_file, value, - &key_file_error); - g_free (value); - - if (key_file_error) - { - if (g_error_matches (key_file_error, - G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_INVALID_VALUE)) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_INVALID_VALUE, - _("Key file contains key '%s' " - "which has value that cannot be interpreted."), - key); - g_error_free (key_file_error); - } - else - g_propagate_error (error, key_file_error); - } - - return bool_value; -} - -/** - * g_key_file_set_boolean: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @value: %TRUE or %FALSE - * - * Associates a new boolean value with @key under @group_name. - * If @key cannot be found then it is created. - * - * Since: 2.6 - **/ -void -g_key_file_set_boolean (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - gboolean value) -{ - gchar *result; - - g_return_if_fail (key_file != NULL); - g_return_if_fail (group_name != NULL); - g_return_if_fail (key != NULL); - - result = g_key_file_parse_boolean_as_value (key_file, value); - g_key_file_set_value (key_file, group_name, key, result); - g_free (result); -} - -/** - * g_key_file_get_boolean_list: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @length: the number of booleans returned - * @error: return location for a #GError - * - * Returns the values associated with @key under @group_name as - * booleans. If @group_name is %NULL, the start_group is used. - * - * If @key cannot be found then the return value is undefined and - * @error is set to #G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if - * the values associated with @key cannot be interpreted as booleans - * then the return value is also undefined and @error is set to - * #G_KEY_FILE_ERROR_INVALID_VALUE. - * - * Return value: the values associated with the key as a boolean - * - * Since: 2.6 - **/ -gboolean * -g_key_file_get_boolean_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - gsize *length, - GError **error) -{ - GError *key_file_error; - gchar **values; - gboolean *bool_values; - gsize i, num_bools; - - g_return_val_if_fail (key_file != NULL, NULL); - g_return_val_if_fail (group_name != NULL, NULL); - g_return_val_if_fail (key != NULL, NULL); - - key_file_error = NULL; - - values = g_key_file_get_string_list (key_file, group_name, key, - &num_bools, &key_file_error); - - if (key_file_error) - g_propagate_error (error, key_file_error); - - if (!values) - return NULL; - - bool_values = g_new0 (gboolean, num_bools); - - for (i = 0; i < num_bools; i++) - { - bool_values[i] = g_key_file_parse_value_as_boolean (key_file, - values[i], - &key_file_error); - - if (key_file_error) - { - g_propagate_error (error, key_file_error); - g_strfreev (values); - g_free (bool_values); - - return NULL; - } - } - g_strfreev (values); - - if (length) - *length = num_bools; - - return bool_values; -} - -/** - * g_key_file_set_boolean_list: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @list: an array of boolean values - * @length: length of @list - * - * Associates a list of boolean values with @key under - * @group_name. If @key cannot be found then it is created. - * If @group_name is %NULL, the start_group is used. - * - * Since: 2.6 - **/ -void -g_key_file_set_boolean_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - gboolean list[], - gsize length) -{ - GString *value_list; - gsize i; - - g_return_if_fail (key_file != NULL); - g_return_if_fail (group_name != NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (list != NULL); - - value_list = g_string_sized_new (length * 8); - for (i = 0; i < length; i++) - { - gchar *value; - - value = g_key_file_parse_boolean_as_value (key_file, list[i]); - - g_string_append (value_list, value); - g_string_append_c (value_list, key_file->list_separator); - - g_free (value); - } - - g_key_file_set_value (key_file, group_name, key, value_list->str); - g_string_free (value_list, TRUE); -} - -/** - * g_key_file_get_integer: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @error: return location for a #GError - * - * Returns the value associated with @key under @group_name as an - * integer. If @group_name is %NULL, the start_group is used. - * - * If @key cannot be found then the return value is undefined and - * @error is set to #G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if - * the value associated with @key cannot be interpreted as an integer - * then the return value is also undefined and @error is set to - * #G_KEY_FILE_ERROR_INVALID_VALUE. - * - * Return value: the value associated with the key as an integer. - * - * Since: 2.6 - **/ -gint -g_key_file_get_integer (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error) -{ - GError *key_file_error; - gchar *value; - gint int_value; - - g_return_val_if_fail (key_file != NULL, -1); - g_return_val_if_fail (group_name != NULL, -1); - g_return_val_if_fail (key != NULL, -1); - - key_file_error = NULL; - - value = g_key_file_get_value (key_file, group_name, key, &key_file_error); - - if (key_file_error) - { - g_propagate_error (error, key_file_error); - return 0; - } - - int_value = g_key_file_parse_value_as_integer (key_file, value, - &key_file_error); - g_free (value); - - if (key_file_error) - { - if (g_error_matches (key_file_error, - G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_INVALID_VALUE)) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_INVALID_VALUE, - _("Key file contains key '%s' in group '%s' " - "which has value that cannot be interpreted."), key, - group_name); - g_error_free (key_file_error); - } - else - g_propagate_error (error, key_file_error); - } - - return int_value; -} - -/** - * g_key_file_set_integer: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @value: an integer value - * - * Associates a new integer value with @key under @group_name. - * If @key cannot be found then it is created. - * - * Since: 2.6 - **/ -void -g_key_file_set_integer (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - gint value) -{ - gchar *result; - - g_return_if_fail (key_file != NULL); - g_return_if_fail (group_name != NULL); - g_return_if_fail (key != NULL); - - result = g_key_file_parse_integer_as_value (key_file, value); - g_key_file_set_value (key_file, group_name, key, result); - g_free (result); -} - -/** - * g_key_file_get_integer_list: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @length: the number of integers returned - * @error: return location for a #GError - * - * Returns the values associated with @key under @group_name as - * integers. If @group_name is %NULL, the start group is used. - * - * If @key cannot be found then the return value is undefined and - * @error is set to #G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if - * the values associated with @key cannot be interpreted as integers - * then the return value is also undefined and @error is set to - * #G_KEY_FILE_ERROR_INVALID_VALUE. - * - * Return value: the values associated with the key as a integer - * - * Since: 2.6 - **/ -gint * -g_key_file_get_integer_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - gsize *length, - GError **error) -{ - GError *key_file_error = NULL; - gchar **values; - gint *int_values; - gsize i, num_ints; - - g_return_val_if_fail (key_file != NULL, NULL); - g_return_val_if_fail (group_name != NULL, NULL); - g_return_val_if_fail (key != NULL, NULL); - - values = g_key_file_get_string_list (key_file, group_name, key, - &num_ints, &key_file_error); - - if (key_file_error) - g_propagate_error (error, key_file_error); - - if (!values) - return NULL; - - int_values = g_new0 (gint, num_ints); - - for (i = 0; i < num_ints; i++) - { - int_values[i] = g_key_file_parse_value_as_integer (key_file, - values[i], - &key_file_error); - - if (key_file_error) - { - g_propagate_error (error, key_file_error); - g_strfreev (values); - g_free (int_values); - - return NULL; - } - } - g_strfreev (values); - - if (length) - *length = num_ints; - - return int_values; -} - -/** - * g_key_file_set_integer_list: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key - * @list: an array of integer values - * @length: number of integer values in @list - * - * Associates a list of integer values with @key under - * @group_name. If @key cannot be found then it is created. - * - * Since: 2.6 - **/ -void -g_key_file_set_integer_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - gint list[], - gsize length) -{ - GString *values; - gsize i; - - g_return_if_fail (key_file != NULL); - g_return_if_fail (group_name != NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (list != NULL); - - values = g_string_sized_new (length * 16); - for (i = 0; i < length; i++) - { - gchar *value; - - value = g_key_file_parse_integer_as_value (key_file, list[i]); - - g_string_append (values, value); - g_string_append_c (values, ';'); - - g_free (value); - } - - g_key_file_set_value (key_file, group_name, key, values->str); - g_string_free (values, TRUE); -} - -static void -g_key_file_set_key_comment (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar *comment, - GError **error) -{ - GKeyFileGroup *group; - GKeyFileKeyValuePair *pair; - GList *key_node, *comment_node, *tmp; - - group = g_key_file_lookup_group (key_file, group_name); - if (!group) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_GROUP_NOT_FOUND, - _("Key file does not have group '%s'"), - group_name ? group_name : "(null)"); - - return; - } - - /* First find the key the comments are supposed to be - * associated with - */ - key_node = g_key_file_lookup_key_value_pair_node (key_file, group, key); - - if (key_node == NULL) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_KEY_NOT_FOUND, - _("Key file does not have key '%s' in group '%s'"), - key, group->name); - return; - } - - /* Then find all the comments already associated with the - * key and free them - */ - tmp = key_node->next; - while (tmp != NULL) - { - GKeyFileKeyValuePair *pair; - - pair = (GKeyFileKeyValuePair *) tmp->data; - - if (pair->key != NULL) - break; - - comment_node = tmp; - tmp = tmp->next; - g_key_file_remove_key_value_pair_node (key_file, group, - comment_node); - } - - if (comment == NULL) - return; - - /* Now we can add our new comment - */ - pair = g_new0 (GKeyFileKeyValuePair, 1); - - pair->key = NULL; - pair->value = g_key_file_parse_comment_as_value (key_file, comment); - - key_node = g_list_insert (key_node, pair, 1); -} - -static void -g_key_file_set_group_comment (GKeyFile *key_file, - const gchar *group_name, - const gchar *comment, - GError **error) -{ - GKeyFileGroup *group; - - group = g_key_file_lookup_group (key_file, group_name); - if (!group) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_GROUP_NOT_FOUND, - _("Key file does not have group '%s'"), - group_name ? group_name : "(null)"); - - return; - } - - /* First remove any existing comment - */ - if (group->comment) - { - g_key_file_key_value_pair_free (group->comment); - group->comment = NULL; - } - - if (comment == NULL) - return; - - /* Now we can add our new comment - */ - group->comment = g_new0 (GKeyFileKeyValuePair, 1); - - group->comment->key = NULL; - group->comment->value = g_key_file_parse_comment_as_value (key_file, comment); -} - -static void -g_key_file_set_top_comment (GKeyFile *key_file, - const gchar *comment, - GError **error) -{ - GList *group_node; - GKeyFileGroup *group; - GKeyFileKeyValuePair *pair; - - /* The last group in the list should be the top (comments only) - * group in the file - */ - g_assert (key_file->groups != NULL); - group_node = g_list_last (key_file->groups); - group = (GKeyFileGroup *) group_node->data; - g_assert (group->name == NULL); - - /* Note all keys must be comments at the top of - * the file, so we can just free it all. - */ - if (group->key_value_pairs != NULL) - { - g_list_foreach (group->key_value_pairs, - (GFunc) g_key_file_key_value_pair_free, - NULL); - g_list_free (group->key_value_pairs); - group->key_value_pairs = NULL; - } - - if (comment == NULL) - return; - - pair = g_new0 (GKeyFileKeyValuePair, 1); - - pair->key = NULL; - pair->value = g_key_file_parse_comment_as_value (key_file, comment); - - group->key_value_pairs = - g_list_prepend (group->key_value_pairs, pair); -} - -/** - * g_key_file_set_comment: - * @key_file: a #GKeyFile - * @group_name: a group name, or %NULL - * @key: a key - * @comment: a comment - * @error: return location for a #GError - * - * Places a comment above @key from @group_name. - * @group_name. If @key is %NULL then @comment will - * be written above @group_name. If both @key - * and @group_name are NULL, then @comment will - * be written above the first group in the file. - * - * Since: 2.6 - **/ -void -g_key_file_set_comment (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar *comment, - GError **error) -{ - g_return_if_fail (key_file != NULL); - - if (group_name != NULL && key != NULL) - g_key_file_set_key_comment (key_file, group_name, key, comment, error); - else if (group_name != NULL) - g_key_file_set_group_comment (key_file, group_name, comment, error); - else - g_key_file_set_top_comment (key_file, comment, error); - - if (comment != NULL) - key_file->approximate_size += strlen (comment); -} - -static gchar * -g_key_file_get_key_comment (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error) -{ - GKeyFileGroup *group; - GList *key_node, *tmp; - GString *string; - gchar *comment; - - group = g_key_file_lookup_group (key_file, group_name); - if (!group) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_GROUP_NOT_FOUND, - _("Key file does not have group '%s'"), - group_name ? group_name : "(null)"); - - return NULL; - } - - /* First find the key the comments are supposed to be - * associated with - */ - key_node = g_key_file_lookup_key_value_pair_node (key_file, group, key); - - if (key_node == NULL) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_KEY_NOT_FOUND, - _("Key file does not have key '%s' in group '%s'"), - key, group->name); - return NULL; - } - - string = NULL; - - /* Then find all the comments already associated with the - * key and concatentate them. - */ - tmp = key_node->next; - while (tmp != NULL) - { - GKeyFileKeyValuePair *pair; - - pair = (GKeyFileKeyValuePair *) tmp->data; - - if (pair->key != NULL) - break; - - if (string == NULL) - string = g_string_sized_new (512); - - comment = g_key_file_parse_value_as_comment (key_file, pair->value); - g_string_append (string, comment); - g_free (comment); - - tmp = tmp->next; - } - - if (string != NULL) - { - comment = string->str; - g_string_free (string, FALSE); - } - else - comment = NULL; - - return comment; -} - -static gchar * -g_key_file_get_group_comment (GKeyFile *key_file, - const gchar *group_name, - GError **error) -{ - GKeyFileGroup *group; - - group = g_key_file_lookup_group (key_file, group_name); - if (!group) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_GROUP_NOT_FOUND, - _("Key file does not have group '%s'"), - group_name ? group_name : "(null)"); - - return NULL; - } - - if (group->comment) - return g_strdup (group->comment->value); - - return NULL; -} - -static gchar * -g_key_file_get_top_comment (GKeyFile *key_file, - GError **error) -{ - GList *group_node, *tmp; - GKeyFileGroup *group; - GString *string; - gchar *comment; - - /* The last group in the list should be the top (comments only) - * group in the file - */ - g_assert (key_file->groups != NULL); - group_node = g_list_last (key_file->groups); - group = (GKeyFileGroup *) group_node->data; - g_assert (group->name == NULL); - - string = NULL; - - /* Then find all the comments already associated with the - * key and concatentate them. - */ - tmp = group->key_value_pairs; - while (tmp != NULL) - { - GKeyFileKeyValuePair *pair; - - pair = (GKeyFileKeyValuePair *) tmp->data; - - if (pair->key != NULL) - break; - - if (string == NULL) - string = g_string_sized_new (512); - - comment = g_key_file_parse_value_as_comment (key_file, pair->value); - g_string_append (string, comment); - g_free (comment); - - tmp = tmp->next; - } - - if (string != NULL) - { - comment = string->str; - g_string_free (string, FALSE); - } - else - comment = NULL; - - return comment; -} - -/** - * g_key_file_get_comment: - * @key_file: a #GKeyFile - * @group_name: a group name, or %NULL - * @key: a key - * @error: return location for a #GError - * - * Retreives a comment above @key from @group_name. - * @group_name. If @key is %NULL then @comment will - * be read from above @group_name. If both @key - * and @group_name are NULL, then @comment will - * be read from above the first group in the file. - * - * Since: 2.6 - * Returns: a comment that should be freed with g_free() - **/ -gchar * -g_key_file_get_comment (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error) -{ - g_return_val_if_fail (key_file != NULL, NULL); - - if (group_name != NULL && key != NULL) - return g_key_file_get_key_comment (key_file, group_name, key, error); - else if (group_name != NULL) - return g_key_file_get_group_comment (key_file, group_name, error); - else - return g_key_file_get_top_comment (key_file, error); -} - -/** - * g_key_file_remove_comment: - * @key_file: a #GKeyFile - * @group_name: a group name, or %NULL - * @key: a key - * @error: return location for a #GError - * - * Removes a comment above @key from @group_name. - * @group_name. If @key is %NULL then @comment will - * be written above @group_name. If both @key - * and @group_name are NULL, then @comment will - * be written above the first group in the file. - * - * Since: 2.6 - **/ - -void -g_key_file_remove_comment (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error) -{ - g_return_if_fail (key_file != NULL); - - if (group_name != NULL && key != NULL) - g_key_file_set_key_comment (key_file, group_name, key, NULL, error); - else if (group_name != NULL) - g_key_file_set_group_comment (key_file, group_name, NULL, error); - else - g_key_file_set_top_comment (key_file, NULL, error); -} - -/** - * g_key_file_has_group: - * @key_file: a #GKeyFile - * @group_name: a group name - * - * Looks whether the key file has the group @group_name. - * - * Return value: %TRUE if @group_name is a part of @key_file, %FALSE - * otherwise. - * Since: 2.6 - **/ -gboolean -g_key_file_has_group (GKeyFile *key_file, - const gchar *group_name) -{ - g_return_val_if_fail (key_file != NULL, FALSE); - g_return_val_if_fail (group_name != NULL, FALSE); - - return g_key_file_lookup_group_node (key_file, group_name) != NULL; -} - -/** - * g_key_file_has_key: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key name - * @error: return location for a #GError - * - * Looks whether the key file has the key @key in the group - * @group_name. - * - * Return value: %TRUE if @key is a part of @group_name, %FALSE - * otherwise. - * - * Since: 2.6 - **/ -gboolean -g_key_file_has_key (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error) -{ - GKeyFileKeyValuePair *pair; - GKeyFileGroup *group; - - g_return_val_if_fail (key_file != NULL, FALSE); - g_return_val_if_fail (group_name != NULL, FALSE); - g_return_val_if_fail (key != NULL, FALSE); - - group = g_key_file_lookup_group (key_file, group_name); - - if (!group) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_GROUP_NOT_FOUND, - _("Key file does not have group '%s'"), - group_name ? group_name : "(null)"); - - return FALSE; - } - - pair = g_key_file_lookup_key_value_pair (key_file, group, key); - - return pair != NULL; -} - -static void -g_key_file_add_group (GKeyFile *key_file, - const gchar *group_name) -{ - GKeyFileGroup *group; - - g_return_if_fail (key_file != NULL); - g_return_if_fail (group_name != NULL); - g_return_if_fail (g_key_file_lookup_group_node (key_file, group_name) == NULL); - - group = g_new0 (GKeyFileGroup, 1); - group->name = g_strdup (group_name); - group->lookup_map = g_hash_table_new (g_str_hash, g_str_equal); - key_file->groups = g_list_prepend (key_file->groups, group); - key_file->approximate_size += strlen (group_name) + 3; - key_file->current_group = group; - - if (key_file->start_group == NULL) - key_file->start_group = group; -} - -static void -g_key_file_key_value_pair_free (GKeyFileKeyValuePair *pair) -{ - if (pair != NULL) - { - g_free (pair->key); - g_free (pair->value); - g_free (pair); - } -} - -/* Be careful not to call this function on a node with data in the - * lookup map without removing it from the lookup map, first. - * - * Some current cases where this warning is not a concern are - * when: - * - the node being removed is a comment node - * - the entire lookup map is getting destroyed soon after - * anyway. - */ -static void -g_key_file_remove_key_value_pair_node (GKeyFile *key_file, - GKeyFileGroup *group, - GList *pair_node) -{ - - GKeyFileKeyValuePair *pair; - - pair = (GKeyFileKeyValuePair *) pair_node->data; - - group->key_value_pairs = g_list_remove_link (group->key_value_pairs, pair_node); - - if (pair->key != NULL) - key_file->approximate_size -= strlen (pair->key) + 1; - - g_assert (pair->value != NULL); - key_file->approximate_size -= strlen (pair->value); - - g_key_file_key_value_pair_free (pair); - - g_list_free_1 (pair_node); -} - -static void -g_key_file_remove_group_node (GKeyFile *key_file, - GList *group_node) -{ - GKeyFileGroup *group; - GList *tmp; - - group = (GKeyFileGroup *) group_node->data; - - /* If the current group gets deleted make the current group the last - * added group. - */ - if (key_file->current_group == group) - { - /* groups should always contain at least the top comment group, - * unless g_key_file_clear has been called - */ - if (key_file->groups) - key_file->current_group = (GKeyFileGroup *) key_file->groups->data; - else - key_file->current_group = NULL; - } - - /* If the start group gets deleted make the start group the first - * added group. - */ - if (key_file->start_group == group) - { - tmp = g_list_last (key_file->groups); - while (tmp != NULL) - { - if (tmp != group_node && - ((GKeyFileGroup *) tmp->data)->name != NULL) - break; - - tmp = tmp->prev; - } - - if (tmp) - key_file->start_group = (GKeyFileGroup *) tmp->data; - else - key_file->start_group = NULL; - } - - key_file->groups = g_list_remove_link (key_file->groups, group_node); - - if (group->name != NULL) - key_file->approximate_size -= strlen (group->name) + 3; - - tmp = group->key_value_pairs; - while (tmp != NULL) - { - GList *pair_node; - - pair_node = tmp; - tmp = tmp->next; - g_key_file_remove_key_value_pair_node (key_file, group, pair_node); - } - - g_assert (group->key_value_pairs == NULL); - - if (group->lookup_map) - { - g_hash_table_destroy (group->lookup_map); - group->lookup_map = NULL; - } - - g_free ((gchar *) group->name); - g_free (group); - g_list_free_1 (group_node); -} - -/** - * g_key_file_remove_group: - * @key_file: a #GKeyFile - * @group_name: a group name - * @error: return location for a #GError or %NULL - * - * Removes the specified group, @group_name, - * from the key file. - * - * Since: 2.6 - **/ -void -g_key_file_remove_group (GKeyFile *key_file, - const gchar *group_name, - GError **error) -{ - GList *group_node; - - g_return_if_fail (key_file != NULL); - g_return_if_fail (group_name != NULL); - - group_node = g_key_file_lookup_group_node (key_file, group_name); - - if (!group_node) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_GROUP_NOT_FOUND, - _("Key file does not have group '%s'"), - group_name); - return; - } - - g_key_file_remove_group_node (key_file, group_node); -} - -static void -g_key_file_add_key (GKeyFile *key_file, - GKeyFileGroup *group, - const gchar *key, - const gchar *value) -{ - GKeyFileKeyValuePair *pair; - - pair = g_new0 (GKeyFileKeyValuePair, 1); - - pair->key = g_strdup (key); - pair->value = g_strdup (value); - - g_hash_table_replace (group->lookup_map, pair->key, pair); - group->key_value_pairs = g_list_prepend (group->key_value_pairs, pair); - key_file->approximate_size += strlen (key) + strlen (value) + 2; -} - -/** - * g_key_file_remove_key: - * @key_file: a #GKeyFile - * @group_name: a group name - * @key: a key name to remove - * @error: return location for a #GError or %NULL - * - * Removes @key in @group_name from the key file. - * - * Since: 2.6 - **/ -void -g_key_file_remove_key (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error) -{ - GKeyFileGroup *group; - GKeyFileKeyValuePair *pair; - - g_return_if_fail (key_file != NULL); - g_return_if_fail (group_name != NULL); - g_return_if_fail (key != NULL); - - pair = NULL; - - group = g_key_file_lookup_group (key_file, group_name); - if (!group) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_GROUP_NOT_FOUND, - _("Key file does not have group '%s'"), - group_name ? group_name : "(null)"); - return; - } - - pair = g_key_file_lookup_key_value_pair (key_file, group, key); - - if (!pair) - { - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_KEY_NOT_FOUND, - _("Key file does not have key '%s' in group '%s'"), - key, group->name); - return; - } - - key_file->approximate_size -= strlen (pair->key) + strlen (pair->value) + 2; - - group->key_value_pairs = g_list_remove (group->key_value_pairs, pair); - g_hash_table_remove (group->lookup_map, pair->key); - g_key_file_key_value_pair_free (pair); -} - -static GList * -g_key_file_lookup_group_node (GKeyFile *key_file, - const gchar *group_name) -{ - GKeyFileGroup *group; - GList *tmp; - - group = NULL; - for (tmp = key_file->groups; tmp != NULL; tmp = tmp->next) - { - group = (GKeyFileGroup *) tmp->data; - - if (group && group->name && strcmp (group->name, group_name) == 0) - break; - - group = NULL; - } - - return tmp; -} - -static GKeyFileGroup * -g_key_file_lookup_group (GKeyFile *key_file, - const gchar *group_name) -{ - GList *group_node; - - group_node = g_key_file_lookup_group_node (key_file, group_name); - - if (group_node != NULL) - return (GKeyFileGroup *) group_node->data; - - return NULL; -} - -static GList * -g_key_file_lookup_key_value_pair_node (GKeyFile *key_file, - GKeyFileGroup *group, - const gchar *key) -{ - GList *key_node; - - for (key_node = group->key_value_pairs; - key_node != NULL; - key_node = key_node->next) - { - GKeyFileKeyValuePair *pair; - - pair = (GKeyFileKeyValuePair *) key_node->data; - - if (pair->key && strcmp (pair->key, key) == 0) - break; - } - - return key_node; -} - -static GKeyFileKeyValuePair * -g_key_file_lookup_key_value_pair (GKeyFile *key_file, - GKeyFileGroup *group, - const gchar *key) -{ - return (GKeyFileKeyValuePair *) g_hash_table_lookup (group->lookup_map, key); -} - -/* Lines starting with # or consisting entirely of whitespace are merely - * recorded, not parsed. This function assumes all leading whitespace - * has been stripped. - */ -static gboolean -g_key_file_line_is_comment (const gchar *line) -{ - return (*line == '#' || *line == '\0' || *line == '\n'); -} - -/* A group in a key file is made up of a starting '[' followed by one - * or more letters making up the group name followed by ']'. - */ -static gboolean -g_key_file_line_is_group (const gchar *line) -{ - gchar *p; - - p = (gchar *) line; - if (*p != '[') - return FALSE; - - p = g_utf8_next_char (p); - - if (!*p) - return FALSE; - - p = g_utf8_next_char (p); - - /* Group name must be non-empty - */ - if (*p == ']') - return FALSE; - - while (*p && *p != ']') - p = g_utf8_next_char (p); - - if (!*p) - return FALSE; - - return TRUE; -} - -static gboolean -g_key_file_line_is_key_value_pair (const gchar *line) -{ - gchar *p; - - p = (gchar *) g_utf8_strchr (line, -1, '='); - - if (!p) - return FALSE; - - /* Key must be non-empty - */ - if (*p == line[0]) - return FALSE; - - return TRUE; -} - -static gchar * -g_key_file_parse_value_as_string (GKeyFile *key_file, - const gchar *value, - GSList **pieces, - GError **error) -{ - gchar *string_value, *p, *q0, *q; - - string_value = g_new0 (gchar, strlen (value) + 1); - - p = (gchar *) value; - q0 = q = string_value; - while (*p) - { - if (*p == '\\') - { - p++; - - switch (*p) - { - case 's': - *q = ' '; - break; - - case 'n': - *q = '\n'; - break; - - case 't': - *q = '\t'; - break; - - case 'r': - *q = '\r'; - break; - - case '\\': - *q = '\\'; - break; - - case '\0': - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_INVALID_VALUE, - _("Key file contains escape character " - "at end of line")); - break; - - default: - if (pieces && *p == key_file->list_separator) - *q = key_file->list_separator; - else - { - *q++ = '\\'; - *q = *p; - - if (*error == NULL) - { - gchar sequence[3]; - - sequence[0] = '\\'; - sequence[1] = *p; - sequence[2] = '\0'; - - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_INVALID_VALUE, - _("Key file contains invalid escape " - "sequence '%s'"), sequence); - } - } - break; - } - } - else - { - *q = *p; - if (pieces && (*p == key_file->list_separator)) - { - *pieces = g_slist_prepend (*pieces, g_strndup (q0, q - q0)); - q0 = q + 1; - } - } - - if (*p == '\0') - break; - - q++; - p++; - } - - *q = '\0'; - if (pieces) - { - if (q0 < q) - *pieces = g_slist_prepend (*pieces, g_strndup (q0, q - q0)); - *pieces = g_slist_reverse (*pieces); - } - - return string_value; -} - -static gchar * -g_key_file_parse_string_as_value (GKeyFile *key_file, - const gchar *string, - gboolean escape_separator) -{ - gchar *value, *p, *q; - gsize length; - gboolean parsing_leading_space; - - length = strlen (string) + 1; - - /* Worst case would be that every character needs to be escaped. - * In other words every character turns to two characters - */ - value = g_new0 (gchar, 2 * length); - - p = (gchar *) string; - q = value; - parsing_leading_space = TRUE; - while (p < (string + length - 1)) - { - gchar escaped_character[3] = { '\\', 0, 0 }; - - switch (*p) - { - case ' ': - if (parsing_leading_space) - { - escaped_character[1] = 's'; - strcpy (q, escaped_character); - q += 2; - } - else - { - *q = *p; - q++; - } - break; - case '\t': - if (parsing_leading_space) - { - escaped_character[1] = 't'; - strcpy (q, escaped_character); - q += 2; - } - else - { - *q = *p; - q++; - } - break; - case '\n': - escaped_character[1] = 'n'; - strcpy (q, escaped_character); - q += 2; - break; - case '\r': - escaped_character[1] = 'r'; - strcpy (q, escaped_character); - q += 2; - break; - case '\\': - escaped_character[1] = '\\'; - strcpy (q, escaped_character); - q += 2; - parsing_leading_space = FALSE; - break; - default: - if (escape_separator && *p == key_file->list_separator) - { - escaped_character[1] = key_file->list_separator; - strcpy (q, escaped_character); - q += 2; - parsing_leading_space = TRUE; - } - else - { - *q = *p; - q++; - parsing_leading_space = FALSE; - } - break; - } - p++; - } - *q = '\0'; - - return value; -} - -static gint -g_key_file_parse_value_as_integer (GKeyFile *key_file, - const gchar *value, - GError **error) -{ - gchar *end_of_valid_int; - gint int_value = 0; - - int_value = strtol (value, &end_of_valid_int, 10); - - if (*end_of_valid_int != '\0') - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_INVALID_VALUE, - _("Value '%s' cannot be interpreted as a number."), value); - - return int_value; -} - -static gchar * -g_key_file_parse_integer_as_value (GKeyFile *key_file, - gint value) - -{ - return g_strdup_printf ("%d", value); -} - -static gboolean -g_key_file_parse_value_as_boolean (GKeyFile *key_file, - const gchar *value, - GError **error) -{ - if (value) - { - if (strcmp (value, "true") == 0 || strcmp (value, "1") == 0) - return TRUE; - else if (strcmp (value, "false") == 0 || strcmp (value, "0") == 0) - return FALSE; - } - - g_set_error (error, G_KEY_FILE_ERROR, - G_KEY_FILE_ERROR_INVALID_VALUE, - _("Value '%s' cannot be interpreted as a boolean."), value); - - return FALSE; -} - -static gchar * -g_key_file_parse_boolean_as_value (GKeyFile *key_file, - gboolean value) -{ - if (value) - return g_strdup ("true"); - else - return g_strdup ("false"); -} - -static gchar * -g_key_file_parse_value_as_comment (GKeyFile *key_file, - const gchar *value) -{ - GString *string; - gchar **lines, *comment; - gsize i; - - string = g_string_sized_new (512); - - lines = g_strsplit (value, "\n", 0); - - for (i = 0; lines[i] != NULL; i++) - { - if (lines[i][0] != '#') - g_string_append_printf (string, "%s\n", lines[i]); - else - g_string_append_printf (string, "%s\n", lines[i] + 1); - } - g_strfreev (lines); - - comment = string->str; - - g_string_free (string, FALSE); - - return comment; -} - -static gchar * -g_key_file_parse_comment_as_value (GKeyFile *key_file, - const gchar *comment) -{ - GString *string; - gchar **lines, *value; - gsize i; - - string = g_string_sized_new (512); - - lines = g_strsplit (comment, "\n", 0); - - for (i = 0; lines[i] != NULL; i++) - g_string_append_printf (string, "#%s%s", lines[i], - lines[i + 1] == NULL? "" : "\n"); - g_strfreev (lines); - - value = string->str; - - g_string_free (string, FALSE); - - return value; -} - -/* Start hacks to make this file compile with glib 2.4 */ -#if 0 -#define __G_KEY_FILE_C__ -#include "galiasdef.c" -#endif -/* End hacks to make this file compile with glib 2.4 */ diff --git a/lib/glib26/gkeyfile.h b/lib/glib26/gkeyfile.h deleted file mode 100644 index 5688c16433..0000000000 --- a/lib/glib26/gkeyfile.h +++ /dev/null @@ -1,199 +0,0 @@ -/* gkeyfile.h - desktop entry file parser - * - * Copyright 2004 Red Hat, Inc. - * - * Ray Strode - * - * GLib 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 of the - * License, or (at your option) any later version. - * - * GLib 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 GLib; see the file COPYING.LIB. If not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef __G_KEY_FILE_H__ -#define __G_KEY_FILE_H__ - -#include - -/* Start hacks to make this file compile with glib 2.4 */ -#define G_GNUC_MALLOC -/* End hacks to make this file compile with glib 2.4 */ - -G_BEGIN_DECLS - -typedef enum -{ - G_KEY_FILE_ERROR_UNKNOWN_ENCODING, - G_KEY_FILE_ERROR_PARSE, - G_KEY_FILE_ERROR_NOT_FOUND, - G_KEY_FILE_ERROR_KEY_NOT_FOUND, - G_KEY_FILE_ERROR_GROUP_NOT_FOUND, - G_KEY_FILE_ERROR_INVALID_VALUE -} GKeyFileError; - -#define G_KEY_FILE_ERROR g_key_file_error_quark() - -GQuark g_key_file_error_quark (void); - -typedef struct _GKeyFile GKeyFile; - -typedef enum -{ - G_KEY_FILE_NONE = 0, - G_KEY_FILE_KEEP_COMMENTS = 1 << 0, - G_KEY_FILE_KEEP_TRANSLATIONS = 1 << 1 -} GKeyFileFlags; - -GKeyFile *g_key_file_new (void); -void g_key_file_free (GKeyFile *key_file); -void g_key_file_set_list_separator (GKeyFile *key_file, - gchar separator); -gboolean g_key_file_load_from_file (GKeyFile *key_file, - const gchar *file, - GKeyFileFlags flags, - GError **error); -gboolean g_key_file_load_from_data (GKeyFile *key_file, - const gchar *data, - gsize length, - GKeyFileFlags flags, - GError **error); -gboolean g_key_file_load_from_data_dirs (GKeyFile *key_file, - const gchar *file, - gchar **full_path, - GKeyFileFlags flags, - GError **error); -gchar *g_key_file_to_data (GKeyFile *key_file, - gsize *length, - GError **error) G_GNUC_MALLOC; -gchar *g_key_file_get_start_group (GKeyFile *key_file) G_GNUC_MALLOC; -gchar **g_key_file_get_groups (GKeyFile *key_file, - gsize *length) G_GNUC_MALLOC; -gchar **g_key_file_get_keys (GKeyFile *key_file, - const gchar *group_name, - gsize *length, - GError **error) G_GNUC_MALLOC; -gboolean g_key_file_has_group (GKeyFile *key_file, - const gchar *group_name); -gboolean g_key_file_has_key (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error); -gchar *g_key_file_get_value (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error) G_GNUC_MALLOC; -void g_key_file_set_value (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar *value); -gchar *g_key_file_get_string (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error) G_GNUC_MALLOC; -void g_key_file_set_string (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar *string); -gchar *g_key_file_get_locale_string (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar *locale, - GError **error) G_GNUC_MALLOC; -void g_key_file_set_locale_string (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar *locale, - const gchar *string); -gboolean g_key_file_get_boolean (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error); -void g_key_file_set_boolean (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - gboolean value); -gint g_key_file_get_integer (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error); -void g_key_file_set_integer (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - gint value); -gchar **g_key_file_get_string_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - gsize *length, - GError **error) G_GNUC_MALLOC; -void g_key_file_set_string_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar * const list[], - gsize length); -gchar **g_key_file_get_locale_string_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar *locale, - gsize *length, - GError **error) G_GNUC_MALLOC; -void g_key_file_set_locale_string_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar *locale, - const gchar * const list[], - gsize length); -gboolean *g_key_file_get_boolean_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - gsize *length, - GError **error) G_GNUC_MALLOC; -void g_key_file_set_boolean_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - gboolean list[], - gsize length); -gint *g_key_file_get_integer_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - gsize *length, - GError **error) G_GNUC_MALLOC; -void g_key_file_set_integer_list (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - gint list[], - gsize length); -void g_key_file_set_comment (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - const gchar *comment, - GError **error); -gchar *g_key_file_get_comment (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error) G_GNUC_MALLOC; - -void g_key_file_remove_comment (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error); -void g_key_file_remove_key (GKeyFile *key_file, - const gchar *group_name, - const gchar *key, - GError **error); -void g_key_file_remove_group (GKeyFile *key_file, - const gchar *group_name, - GError **error); - -G_END_DECLS - -#endif /* __G_KEY_FILE_H__ */ diff --git a/lib/glib26/gutils26.c b/lib/glib26/gutils26.c deleted file mode 100644 index 2f9d3b9d59..0000000000 --- a/lib/glib26/gutils26.c +++ /dev/null @@ -1,1065 +0,0 @@ -/* GLIB - Library of useful routines for C programming - * Copyright (C) 1995-1998 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, 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 for the unix part, FIXME: make the win32 part MT safe as well. - */ - -#include "config.h" - -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#include -#include -#include -#include -#include -#ifdef HAVE_PWD_H -#include -#endif -#include -#ifdef HAVE_SYS_PARAM_H -#include -#endif - -/* implement gutils's inline functions - */ -#define G_IMPLEMENT_INLINES 1 -#define __G_UTILS_C__ -/* Start hacks to make this file compile with glib 2.4 */ -#include -#include "gutils26.h" -/* End hacks to make this file compile with glib 2.4 */ -#if 0 -#include "glib.h" -#include "gprintfint.h" -#include "gthreadinit.h" -#include "galias.h" -#endif - -#ifdef G_PLATFORM_WIN32 -# define STRICT /* Strict typing, please */ -# include -# undef STRICT -# include /* For UNLEN */ -#endif /* G_PLATFORM_WIN32 */ - -#ifdef G_OS_WIN32 -# include -# include - /* older SDK (e.g. msvc 5.0) does not have these*/ -# ifndef CSIDL_INTERNET_CACHE -# define CSIDL_INTERNET_CACHE 32 -# endif -# ifndef CSIDL_COMMON_APPDATA -# define CSIDL_COMMON_APPDATA 35 -# endif -# ifndef CSIDL_COMMON_DOCUMENTS -# define CSIDL_COMMON_DOCUMENTS 46 -# endif -# ifndef CSIDL_PROFILE -# define CSIDL_PROFILE 40 -# endif -#endif - -#ifdef HAVE_CODESET -#include -#endif - -#ifdef HAVE_BIND_TEXTDOMAIN_CODESET -#include -#endif - -const guint glib_major_version = GLIB_MAJOR_VERSION; -const guint glib_minor_version = GLIB_MINOR_VERSION; -const guint glib_micro_version = GLIB_MICRO_VERSION; -#if 0 -const guint glib_interface_age = GLIB_INTERFACE_AGE; -const guint glib_binary_age = GLIB_BINARY_AGE; -#endif - -/** - * glib_check_version: - * @required_major: the required major version. - * @required_minor: the required major version. - * @required_micro: the required major version. - * - * Checks that the GLib library in use is compatible with the - * given version. Generally you would pass in the constants - * #GLIB_MAJOR_VERSION, #GLIB_MINOR_VERSION, #GLIB_MICRO_VERSION - * as the three arguments to this function; that produces - * a check that the library in use is compatible with - * the version of GLib the application or module was compiled - * against. - * - * Compatibility is defined by two things: first the version - * of the running library is newer than the version - * @required_major.required_minor.@required_micro. Second - * the running library must be binary compatible with the - * version @required_major.required_minor.@required_micro - * (same major version.) - * - * Return value: %NULL if the GLib library is compatible with the - * given version, or a string describing the version mismatch. - * The returned string is owned by GLib and must not be modified - * or freed. - * - * Since: 2.6 - **/ -const gchar * -glib_check_version (guint required_major, - guint required_minor, - guint required_micro) -{ - gint glib_effective_micro = 100 * GLIB_MINOR_VERSION + GLIB_MICRO_VERSION; - gint required_effective_micro = 100 * required_minor + required_micro; - - if (required_major > GLIB_MAJOR_VERSION) - return "GLib version too old (major mismatch)"; - if (required_major < GLIB_MAJOR_VERSION) - return "GLib version too new (major mismatch)"; -#if 0 - if (required_effective_micro < glib_effective_micro - GLIB_BINARY_AGE) - return "GLib version too new (micro mismatch)"; -#endif - if (required_effective_micro > glib_effective_micro) - return "GLib version too old (micro mismatch)"; - return NULL; -} - -/* Based on execvp() from GNU Libc. - * Some of this code is cut-and-pasted into gspawn.c - */ - -G_LOCK_DEFINE_STATIC (g_utils_global); - -static gchar *g_user_data_dir = NULL; -static gchar **g_system_data_dirs = NULL; -static gchar *g_user_cache_dir = NULL; -static gchar *g_user_config_dir = NULL; -static gchar **g_system_config_dirs = NULL; - -#ifdef G_OS_WIN32 - -static gchar * -get_special_folder (int csidl) -{ - union { - char c[MAX_PATH+1]; - wchar_t wc[MAX_PATH+1]; - } path; - HRESULT hr; - LPITEMIDLIST pidl = NULL; - BOOL b; - gchar *retval = NULL; - - hr = SHGetSpecialFolderLocation (NULL, csidl, &pidl); - if (hr == S_OK) - { - if (G_WIN32_HAVE_WIDECHAR_API ()) - { - b = SHGetPathFromIDListW (pidl, path.wc); - if (b) - retval = g_utf16_to_utf8 (path.wc, -1, NULL, NULL, NULL); - } - else - { - b = SHGetPathFromIDListA (pidl, path.c); - if (b) - retval = g_locale_to_utf8 (path.c, -1, NULL, NULL, NULL); - } - CoTaskMemFree (pidl); - } - return retval; -} - -#endif - -G_LOCK_DEFINE_STATIC (g_prgname); -static gchar *g_prgname = NULL; - -gchar* -g_get_prgname (void) -{ - gchar* retval; - - G_LOCK (g_prgname); -#ifdef G_OS_WIN32 - if (g_prgname == NULL) - { - static gboolean beenhere = FALSE; - - if (!beenhere) - { - gchar *utf8_buf = NULL; - - beenhere = TRUE; - if (G_WIN32_HAVE_WIDECHAR_API ()) - { - wchar_t buf[MAX_PATH+1]; - if (GetModuleFileNameW (GetModuleHandle (NULL), - buf, G_N_ELEMENTS (buf)) > 0) - utf8_buf = g_utf16_to_utf8 (buf, -1, NULL, NULL, NULL); - } - else - { - gchar buf[MAX_PATH+1]; - if (GetModuleFileNameA (GetModuleHandle (NULL), - buf, G_N_ELEMENTS (buf)) > 0) - utf8_buf = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); - } - if (utf8_buf) - { - g_prgname = g_path_get_basename (utf8_buf); - g_free (utf8_buf); - } - } - } -#endif - retval = g_prgname; - G_UNLOCK (g_prgname); - - return retval; -} - -void -g_set_prgname (const gchar *prgname) -{ - G_LOCK (g_prgname); - g_free (g_prgname); - g_prgname = g_strdup (prgname); - G_UNLOCK (g_prgname); -} - -G_LOCK_DEFINE_STATIC (g_application_name); -static gchar *g_application_name = NULL; - -/** - * g_get_application_name: - * - * Gets a human-readable name for the application, as set by - * g_set_application_name(). This name should be localized if - * possible, and is intended for display to the user. Contrast with - * g_get_prgname(), which gets a non-localized name. If - * g_set_application_name() has not been called, returns the result of - * g_get_prgname() (which may be %NULL if g_set_prgname() has also not - * been called). - * - * Return value: human-readable application name. may return %NULL - * - * Since: 2.2 - **/ -G_CONST_RETURN gchar* -g_get_application_name (void) -{ - gchar* retval; - - G_LOCK (g_application_name); - retval = g_application_name; - G_UNLOCK (g_application_name); - - if (retval == NULL) - return g_get_prgname (); - - return retval; -} - -/** - * g_set_application_name: - * @application_name: localized name of the application - * - * Sets a human-readable name for the application. This name should be - * localized if possible, and is intended for display to the user. - * Contrast with g_set_prgname(), which sets a non-localized name. - * g_set_prgname() will be called automatically by gtk_init(), - * but g_set_application_name() will not. - * - * Note that for thread safety reasons, this function can only - * be called once. - * - * The application name will be used in contexts such as error messages, - * or when displaying an application's name in the task list. - * - **/ -void -g_set_application_name (const gchar *application_name) -{ - gboolean already_set = FALSE; - - G_LOCK (g_application_name); - if (g_application_name) - already_set = TRUE; - else - g_application_name = g_strdup (application_name); - G_UNLOCK (g_application_name); - - if (already_set) - g_warning ("g_set_application() name called multiple times"); -} - -/** - * g_get_user_data_dir: - * - * Returns a base directory in which to access application data such - * as icons that is customized for a particular user. - * - * On Unix platforms this is determined using the mechanisms described in - * the - * XDG Base Directory Specification - * - * Return value: a string owned by GLib that must not be modified - * or freed. - * Since: 2.6 - **/ -G_CONST_RETURN gchar* -g_get_user_data_dir (void) -{ - gchar *data_dir; - - G_LOCK (g_utils_global); - - if (!g_user_data_dir) - { -#ifdef G_OS_WIN32 - data_dir = get_special_folder (CSIDL_PERSONAL); -#else - data_dir = (gchar *) g_getenv ("XDG_DATA_HOME"); - - if (data_dir && data_dir[0]) - data_dir = g_strdup (data_dir); -#endif - if (!data_dir || !data_dir[0]) - { - if (g_get_home_dir()) - data_dir = g_build_filename (g_get_home_dir(), ".local", - "share", NULL); - else - data_dir = g_build_filename (g_get_tmp_dir(), g_get_user_name(), ".local", - "share", NULL); - } - - g_user_data_dir = data_dir; - } - else - data_dir = g_user_data_dir; - - G_UNLOCK (g_utils_global); - - return data_dir; -} - -/** - * g_get_user_config_dir: - * - * Returns a base directory in which to store user-specific application - * configuration information such as user preferences and settings. - * - * On Unix platforms this is determined using the mechanisms described in - * the - * XDG Base Directory Specification - * - * Return value: a string owned by GLib that must not be modified - * or freed. - * Since: 2.6 - **/ -G_CONST_RETURN gchar* -g_get_user_config_dir (void) -{ - gchar *config_dir; - - G_LOCK (g_utils_global); - - if (!g_user_config_dir) - { -#ifdef G_OS_WIN32 - config_dir = get_special_folder (CSIDL_APPDATA); -#else - config_dir = (gchar *) g_getenv ("XDG_CONFIG_HOME"); - - if (config_dir && config_dir[0]) - config_dir = g_strdup (config_dir); -#endif - if (!config_dir || !config_dir[0]) - { - if (g_get_home_dir()) - config_dir = g_build_filename (g_get_home_dir(), ".config", NULL); - else - config_dir = g_build_filename (g_get_tmp_dir(), g_get_user_name(), ".config", NULL); - } - g_user_config_dir = config_dir; - } - else - config_dir = g_user_config_dir; - - G_UNLOCK (g_utils_global); - - return config_dir; -} - -/** - * g_get_user_cache_dir: - * - * Returns a base directory in which to store non-essential, cached - * data specific to particular user. - * - * On Unix platforms this is determined using the mechanisms described in - * the - * XDG Base Directory Specification - * - * Return value: a string owned by GLib that must not be modified - * or freed. - * Since: 2.6 - **/ -G_CONST_RETURN gchar* -g_get_user_cache_dir (void) -{ - gchar *cache_dir; - - G_LOCK (g_utils_global); - - if (!g_user_cache_dir) - { -#ifdef G_OS_WIN32 - cache_dir = get_special_folder (CSIDL_INTERNET_CACHE); /* XXX correct? */ -#else - cache_dir = (gchar *) g_getenv ("XDG_CACHE_HOME"); - - if (cache_dir && cache_dir[0]) - cache_dir = g_strdup (cache_dir); -#endif - if (!cache_dir || !cache_dir[0]) - { - if (g_get_home_dir()) - cache_dir = g_build_filename (g_get_home_dir(), ".cache", NULL); - else - cache_dir = g_build_filename (g_get_tmp_dir(), g_get_user_name(), ".cache", NULL); - } - g_user_cache_dir = cache_dir; - } - else - cache_dir = g_user_cache_dir; - - G_UNLOCK (g_utils_global); - - return cache_dir; -} - -/** - * g_get_system_data_dirs: - * - * Returns an ordered list of base directories in which to access - * system-wide application data. - * - * On Unix platforms this is determined using the mechanisms described in - * the - * XDG Base Directory Specification - * - * Return value: a %NULL-terminated array of strings owned by GLib that must - * not be modified or freed. - * Since: 2.6 - **/ -G_CONST_RETURN gchar * G_CONST_RETURN * -g_get_system_data_dirs (void) -{ - gchar *data_dirs, **data_dir_vector; - - G_LOCK (g_utils_global); - - if (!g_system_data_dirs) - { -#ifdef G_OS_WIN32 - char *appdata = get_special_folder (CSIDL_COMMON_APPDATA); - char *docs = get_special_folder (CSIDL_COMMON_DOCUMENTS); - - if (appdata && docs) - { - data_dirs = g_strconcat (appdata, - G_SEARCHPATH_SEPARATOR_S, - docs, - NULL); - g_free (appdata); - g_free (docs); - } - else if (appdata) - data_dirs = appdata; - else if (docs) - data_dirs = docs; - else - data_dirs = NULL; - - if (data_dirs) - { - data_dir_vector = g_strsplit (data_dirs, G_SEARCHPATH_SEPARATOR_S, 0); - g_free (data_dirs); - } - else - { - /* Punt, return empty list */ - data_dir_vector = g_strsplit ("", G_SEARCHPATH_SEPARATOR_S, 0); - } -#else - data_dirs = (gchar *) g_getenv ("XDG_DATA_DIRS"); - - if (!data_dirs || !data_dirs[0]) - data_dirs = "/usr/local/share/:/usr/share/"; - - data_dir_vector = g_strsplit (data_dirs, G_SEARCHPATH_SEPARATOR_S, 0); -#endif - - g_system_data_dirs = data_dir_vector; - } - else - data_dir_vector = g_system_data_dirs; - - G_UNLOCK (g_utils_global); - - return (G_CONST_RETURN gchar * G_CONST_RETURN *) data_dir_vector; -} - -/** - * g_get_system_config_dirs: - * - * Returns an ordered list of base directories in which to access - * system-wide configuration information. - * - * On Unix platforms this is determined using the mechanisms described in - * the - * XDG Base Directory Specification - * - * Return value: a %NULL-terminated array of strings owned by GLib that must - * not be modified or freed. - * Since: 2.6 - **/ -G_CONST_RETURN gchar * G_CONST_RETURN * -g_get_system_config_dirs (void) -{ - gchar *conf_dirs, **conf_dir_vector; - - G_LOCK (g_utils_global); - - if (!g_system_config_dirs) - { -#ifdef G_OS_WIN32 - conf_dirs = get_special_folder (CSIDL_COMMON_APPDATA); - if (conf_dirs) - { - conf_dir_vector = g_strsplit (conf_dirs, G_SEARCHPATH_SEPARATOR_S, 0); - g_free (conf_dirs); - } - else - { - /* Return empty list */ - conf_dir_vector = g_strsplit ("", G_SEARCHPATH_SEPARATOR_S, 0); - } -#else - conf_dirs = (gchar *) g_getenv ("XDG_CONFIG_DIRS"); - - if (!conf_dirs || !conf_dirs[0]) - conf_dirs = "/etc/xdg"; - - conf_dir_vector = g_strsplit (conf_dirs, G_SEARCHPATH_SEPARATOR_S, 0); -#endif - - g_system_config_dirs = conf_dir_vector; - } - else - conf_dir_vector = g_system_config_dirs; - G_UNLOCK (g_utils_global); - - return (G_CONST_RETURN gchar * G_CONST_RETURN *) conf_dir_vector; -} - -static GHashTable *alias_table = NULL; - -/* read an alias file for the locales */ -static void -read_aliases (gchar *file) -{ - FILE *fp; - char buf[256]; - - if (!alias_table) - alias_table = g_hash_table_new (g_str_hash, g_str_equal); - fp = fopen (file,"r"); - if (!fp) - return; - while (fgets (buf, 256, fp)) - { - char *p, *q; - - g_strstrip (buf); - - /* Line is a comment */ - if ((buf[0] == '#') || (buf[0] == '\0')) - continue; - - /* Reads first column */ - for (p = buf, q = NULL; *p; p++) { - if ((*p == '\t') || (*p == ' ') || (*p == ':')) { - *p = '\0'; - q = p+1; - while ((*q == '\t') || (*q == ' ')) { - q++; - } - break; - } - } - /* The line only had one column */ - if (!q || *q == '\0') - continue; - - /* Read second column */ - for (p = q; *p; p++) { - if ((*p == '\t') || (*p == ' ')) { - *p = '\0'; - break; - } - } - - /* Add to alias table if necessary */ - if (!g_hash_table_lookup (alias_table, buf)) { - g_hash_table_insert (alias_table, g_strdup (buf), g_strdup (q)); - } - } - fclose (fp); -} - -static char * -unalias_lang (char *lang) -{ - char *p; - int i; - - if (!alias_table) - read_aliases ("/usr/share/locale/locale.alias"); - - i = 0; - while ((p = g_hash_table_lookup (alias_table, lang)) && (strcmp (p, lang) != 0)) - { - lang = p; - if (i++ == 30) - { - static gboolean said_before = FALSE; - if (!said_before) - g_warning ("Too many alias levels for a locale, " - "may indicate a loop"); - said_before = TRUE; - return lang; - } - } - return lang; -} - -/* Mask for components of locale spec. The ordering here is from - * least significant to most significant - */ -enum -{ - COMPONENT_CODESET = 1 << 0, - COMPONENT_TERRITORY = 1 << 1, - COMPONENT_MODIFIER = 1 << 2 -}; - -/* Break an X/Open style locale specification into components - */ -static guint -explode_locale (const gchar *locale, - gchar **language, - gchar **territory, - gchar **codeset, - gchar **modifier) -{ - const gchar *uscore_pos; - const gchar *at_pos; - const gchar *dot_pos; - - guint mask = 0; - - uscore_pos = strchr (locale, '_'); - dot_pos = strchr (uscore_pos ? uscore_pos : locale, '.'); - at_pos = strchr (dot_pos ? dot_pos : (uscore_pos ? uscore_pos : locale), '@'); - - if (at_pos) - { - mask |= COMPONENT_MODIFIER; - *modifier = g_strdup (at_pos); - } - else - at_pos = locale + strlen (locale); - - if (dot_pos) - { - mask |= COMPONENT_CODESET; - *codeset = g_strndup (dot_pos, at_pos - dot_pos); - } - else - dot_pos = at_pos; - - if (uscore_pos) - { - mask |= COMPONENT_TERRITORY; - *territory = g_strndup (uscore_pos, dot_pos - uscore_pos); - } - else - uscore_pos = dot_pos; - - *language = g_strndup (locale, uscore_pos - locale); - - return mask; -} - -/* - * Compute all interesting variants for a given locale name - - * by stripping off different components of the value. - * - * For simplicity, we assume that the locale is in - * X/Open format: language[_territory][.codeset][@modifier] - * - * TODO: Extend this to handle the CEN format (see the GNUlibc docs) - * as well. We could just copy the code from glibc wholesale - * but it is big, ugly, and complicated, so I'm reluctant - * to do so when this should handle 99% of the time... - */ -GSList *_g_compute_locale_variants (const gchar *locale); -GSList * -_g_compute_locale_variants (const gchar *locale) -{ - GSList *retval = NULL; - - gchar *language = NULL; - gchar *territory = NULL; - gchar *codeset = NULL; - gchar *modifier = NULL; - - guint mask; - guint i; - - g_return_val_if_fail (locale != NULL, NULL); - - mask = explode_locale (locale, &language, &territory, &codeset, &modifier); - - /* Iterate through all possible combinations, from least attractive - * to most attractive. - */ - for (i = 0; i <= mask; i++) - if ((i & ~mask) == 0) - { - gchar *val = g_strconcat (language, - (i & COMPONENT_TERRITORY) ? territory : "", - (i & COMPONENT_CODESET) ? codeset : "", - (i & COMPONENT_MODIFIER) ? modifier : "", - NULL); - retval = g_slist_prepend (retval, val); - } - - g_free (language); - if (mask & COMPONENT_CODESET) - g_free (codeset); - if (mask & COMPONENT_TERRITORY) - g_free (territory); - if (mask & COMPONENT_MODIFIER) - g_free (modifier); - - return retval; -} - -/* The following is (partly) taken from the gettext package. - Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. */ - -static const gchar * -guess_category_value (const gchar *category_name) -{ - const gchar *retval; - - /* The highest priority value is the `LANGUAGE' environment - variable. This is a GNU extension. */ - retval = g_getenv ("LANGUAGE"); - if ((retval != NULL) && (retval[0] != '\0')) - return retval; - - /* `LANGUAGE' is not set. So we have to proceed with the POSIX - methods of looking to `LC_ALL', `LC_xxx', and `LANG'. On some - systems this can be done by the `setlocale' function itself. */ - - /* Setting of LC_ALL overwrites all other. */ - retval = g_getenv ("LC_ALL"); - if ((retval != NULL) && (retval[0] != '\0')) - return retval; - - /* Next comes the name of the desired category. */ - retval = g_getenv (category_name); - if ((retval != NULL) && (retval[0] != '\0')) - return retval; - - /* Last possibility is the LANG environment variable. */ - retval = g_getenv ("LANG"); - if ((retval != NULL) && (retval[0] != '\0')) - return retval; - -#ifdef G_PLATFORM_WIN32 - /* g_win32_getlocale() first checks for LC_ALL, LC_MESSAGES and - * LANG, which we already did above. Oh well. The main point of - * calling g_win32_getlocale() is to get the thread's locale as used - * by Windows and the Microsoft C runtime (in the "English_United - * States" format) translated into the Unixish format. - */ - retval = g_win32_getlocale (); - if ((retval != NULL) && (retval[0] != '\0')) - return retval; -#endif - - return NULL; -} - -typedef struct _GLanguageNamesCache GLanguageNamesCache; - -struct _GLanguageNamesCache { - gchar *languages; - gchar **language_names; -}; - -static void -language_names_cache_free (gpointer data) -{ - GLanguageNamesCache *cache = data; - g_free (cache->languages); - g_strfreev (cache->language_names); - g_free (cache); -} - -/** - * g_get_language_names: - * - * Computes a list of applicable locale names, which can be used to - * e.g. construct locale-dependent filenames or search paths. The returned - * list is sorted from most desirable to least desirable and always contains - * the default locale "C". - * - * For example, if LANGUAGE=de:en_US, then the returned list is - * "de", "en_US", "en", "C". - * - * This function consults the environment variables LANGUAGE, - * LC_ALL, LC_MESSAGES and LANG - * to find the list of locales specified by the user. - * - * Return value: a %NULL-terminated array of strings owned by GLib - * that must not be modified or freed. - * - * Since: 2.6 - **/ -G_CONST_RETURN gchar * G_CONST_RETURN * -g_get_language_names (void) -{ - static GStaticPrivate cache_private = G_STATIC_PRIVATE_INIT; - GLanguageNamesCache *cache = g_static_private_get (&cache_private); - const gchar *value; - - if (!cache) - { - cache = g_new0 (GLanguageNamesCache, 1); - g_static_private_set (&cache_private, cache, language_names_cache_free); - } - - value = guess_category_value ("LC_MESSAGES"); - if (!value) - value = "C"; - - if (!(cache->languages && strcmp (cache->languages, value) == 0)) - { - gchar **languages; - gchar **alist, **a; - GSList *list, *l; - gint i; - - g_free (cache->languages); - g_strfreev (cache->language_names); - cache->languages = g_strdup (value); - - alist = g_strsplit (value, ":", 0); - list = NULL; - for (a = alist; *a; a++) - { - gchar *b = unalias_lang (*a); - list = g_slist_concat (list, _g_compute_locale_variants (b)); - } - g_strfreev (alist); - list = g_slist_append (list, g_strdup ("C")); - - cache->language_names = languages = g_new (gchar *, g_slist_length (list) + 1); - for (l = list, i = 0; l; l = l->next, i++) - languages[i] = l->data; - languages[i] = NULL; - - g_slist_free (list); - } - - return (G_CONST_RETURN gchar * G_CONST_RETURN *) cache->language_names; -} - -guint -g_direct_hash (gconstpointer v) -{ - return GPOINTER_TO_UINT (v); -} - -gboolean -g_direct_equal (gconstpointer v1, - gconstpointer v2) -{ - return v1 == v2; -} - -gboolean -g_int_equal (gconstpointer v1, - gconstpointer v2) -{ - return *((const gint*) v1) == *((const gint*) v2); -} - -guint -g_int_hash (gconstpointer v) -{ - return *(const gint*) v; -} - -/** - * g_nullify_pointer: - * @nullify_location: the memory address of the pointer. - * - * Set the pointer at the specified location to %NULL. - **/ -void -g_nullify_pointer (gpointer *nullify_location) -{ - g_return_if_fail (nullify_location != NULL); - - *nullify_location = NULL; -} - -#if 0 -/** - * g_get_codeset: - * - * Get the codeset for the current locale. - * - * Return value: a newly allocated string containing the name - * of the codeset. This string must be freed with g_free(). - **/ -gchar * -g_get_codeset (void) -{ - const gchar *charset; - - g_get_charset (&charset); - - return g_strdup (charset); -} - -/* This is called from g_thread_init(). It's used to - * initialize some static data in a threadsafe way. - */ -void -_g_utils_thread_init (void) -{ - g_get_language_names (); -} -#endif - -#ifdef ENABLE_NLS - -#include - -#ifdef G_PLATFORM_WIN32 - -G_WIN32_DLLMAIN_FOR_DLL_NAME (static, dll_name) - -static const gchar * -_glib_get_locale_dir (void) -{ - static const gchar *cache = NULL; - if (cache == NULL) - cache = g_win32_get_package_installation_subdirectory - (GETTEXT_PACKAGE, dll_name, "lib\\locale"); - - return cache; -} - -#undef GLIB_LOCALE_DIR -#define GLIB_LOCALE_DIR _glib_get_locale_dir () - -#endif /* G_PLATFORM_WIN32 */ - -#if 0 -G_CONST_RETURN gchar * -_glib_gettext (const gchar *str) -{ - static gboolean _glib_gettext_initialized = FALSE; - - if (!_glib_gettext_initialized) - { - bindtextdomain(GETTEXT_PACKAGE, GLIB_LOCALE_DIR); -# ifdef HAVE_BIND_TEXTDOMAIN_CODESET - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); -# endif - _glib_gettext_initialized = TRUE; - } - - return dgettext (GETTEXT_PACKAGE, str); -} -#endif - -#endif /* ENABLE_NLS */ - -/** - * g_strv_length: - * @str_array: a %NULL-terminated array of strings. - * - * Returns the length of the given %NULL-terminated - * string array @str_array. - * - * Return value: length of @str_array. - * - * Since: 2.6 - **/ -guint -g_strv_length (gchar **str_array) -{ - guint i = 0; - - g_return_val_if_fail (str_array != NULL, 0); - - while (str_array[i]) - ++i; - - return i; -} - -#if 0 -#define __G_UTILS_C__ -#include "galiasdef.c" -#endif diff --git a/lib/glib26/gutils26.h b/lib/glib26/gutils26.h deleted file mode 100644 index 544bd30594..0000000000 --- a/lib/glib26/gutils26.h +++ /dev/null @@ -1,185 +0,0 @@ -/* GLIB - Library of useful routines for C programming - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, 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/. - */ - -#ifndef __G_UTILS_26_H__ -#define __G_UTILS_26_H__ - -#include -#include - -/* Start hacks to make this file compile with glib 2.4 */ -#define G_GNUC_MALLOC -/* End hacks to make this file compile with glib 2.4 */ - -G_BEGIN_DECLS - -#ifdef G_OS_WIN32 - -/* On native Win32, directory separator is the backslash, and search path - * separator is the semicolon. - */ -#define G_DIR_SEPARATOR '\\' -#define G_DIR_SEPARATOR_S "\\" -#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/') -#define G_SEARCHPATH_SEPARATOR ';' -#define G_SEARCHPATH_SEPARATOR_S ";" - -#else /* !G_OS_WIN32 */ - -/* Unix */ - -#define G_DIR_SEPARATOR '/' -#define G_DIR_SEPARATOR_S "/" -#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR) -#define G_SEARCHPATH_SEPARATOR ':' -#define G_SEARCHPATH_SEPARATOR_S ":" - -#endif /* !G_OS_WIN32 */ - -/* Retrive static string info - */ -#ifdef G_OS_WIN32 -#define g_get_user_name g_get_user_name_utf8 -#define g_get_real_name g_get_real_name_utf8 -#define g_get_home_dir g_get_home_dir_utf8 -#define g_get_tmp_dir g_get_tmp_dir_utf8 -#endif - -G_CONST_RETURN gchar* g_get_user_name (void); -G_CONST_RETURN gchar* g_get_real_name (void); -G_CONST_RETURN gchar* g_get_home_dir (void); -G_CONST_RETURN gchar* g_get_tmp_dir (void); -gchar* g_get_prgname (void); -void g_set_prgname (const gchar *prgname); -G_CONST_RETURN gchar* g_get_application_name (void); -void g_set_application_name (const gchar *application_name); - -G_CONST_RETURN gchar* g_get_user_data_dir (void); -G_CONST_RETURN gchar* g_get_user_config_dir (void); -G_CONST_RETURN gchar* g_get_user_cache_dir (void); -G_CONST_RETURN gchar* G_CONST_RETURN * g_get_system_data_dirs (void); -G_CONST_RETURN gchar* G_CONST_RETURN * g_get_system_config_dirs (void); - -G_CONST_RETURN gchar* G_CONST_RETURN * g_get_language_names (void); - -/* Miscellaneous utility functions - */ -gint g_snprintf (gchar *string, - gulong n, - gchar const *format, - ...) G_GNUC_PRINTF (3, 4); -gint g_vsnprintf (gchar *string, - gulong n, - gchar const *format, - va_list args); - -#ifndef G_DISABLE_DEPRECATED - -/* These two functions are deprecated and will be removed in the next - * major release of GLib. Use g_path_get_dirname/g_path_get_basename - * instead. Whatch out! The string returned by g_path_get_basename - * must be g_freed, while the string returned by g_basename must not.*/ -G_CONST_RETURN gchar* g_basename (const gchar *file_name); -#define g_dirname g_path_get_dirname - -#endif /* G_DISABLE_DEPRECATED */ - -#ifdef G_OS_WIN32 -#define g_get_current_dir g_get_current_dir_utf8 -#endif - -/* The returned strings are newly allocated with g_malloc() */ -gchar* g_get_current_dir (void); -gchar* g_path_get_basename (const gchar *file_name) G_GNUC_MALLOC; -gchar* g_path_get_dirname (const gchar *file_name) G_GNUC_MALLOC; - -/* Set the pointer at the specified location to NULL */ -void g_nullify_pointer (gpointer *nullify_location); - -/* Look for an executable in PATH, following execvp() rules */ -gchar* g_find_program_in_path (const gchar *program); - - -/* Glib version. - * we prefix variable declarations so they can - * properly get exported in windows dlls. - */ -GLIB_VAR const guint glib_major_version; -GLIB_VAR const guint glib_minor_version; -GLIB_VAR const guint glib_micro_version; -GLIB_VAR const guint glib_interface_age; -GLIB_VAR const guint glib_binary_age; - -const gchar * glib_check_version (guint required_major, - guint required_minor, - guint required_micro); - -#define GLIB_CHECK_VERSION(major,minor,micro) \ - (GLIB_MAJOR_VERSION > (major) || \ - (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION > (minor)) || \ - (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION == (minor) && \ - GLIB_MICRO_VERSION >= (micro))) - -G_END_DECLS - -/* - * On Windows, this macro defines a DllMain function that stores the - * actual DLL name that the code being compiled will be included in. - * STATIC should be empty or 'static'. DLL_NAME is the name of the - * (pointer to the) char array where the DLL name will be stored. If - * this is used, you must also include . If you need a more complex - * DLL entry point function, you cannot use this. - * - * On non-Windows platforms, expands to nothing. - */ - -#ifndef G_PLATFORM_WIN32 -# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) -#else -# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) \ -static char *dll_name; \ - \ -BOOL WINAPI \ -DllMain (HINSTANCE hinstDLL, \ - DWORD fdwReason, \ - LPVOID lpvReserved) \ -{ \ - char bfr[1000]; \ - switch (fdwReason) \ - { \ - case DLL_PROCESS_ATTACH: \ - GetModuleFileName ((HMODULE) hinstDLL, bfr, sizeof (bfr)); \ - dll_name = g_path_get_basename (bfr); \ - break; \ - } \ - \ - return TRUE; \ -} -#endif /* G_PLATFORM_WIN32 */ - -guint g_strv_length (gchar **str_array); - -#endif /* __G_UTILS_26_H__ */ diff --git a/lib/goffice-0.0.4/goffice/Makefile.am b/lib/goffice-0.0.4/goffice/Makefile.am index fb717ff022..924adbaeff 100644 --- a/lib/goffice-0.0.4/goffice/Makefile.am +++ b/lib/goffice-0.0.4/goffice/Makefile.am @@ -26,16 +26,10 @@ CLEANFILES = $(BUILT_SOURCES) libgoffice_1_la_SOURCES = \ goffice.c \ goffice-priv.h -if !HAVE_GLIB26 - libgoffice_1_la_SOURCES += glib24_26-compat.c -endif libgoffice_1_ladir = $(goffice_include_dir) noinst_HEADERS = \ goffice.h -if !HAVE_GLIB26 - noinst_HEADERS += glib24_26-compat.h -endif # Depends on this Makefile, because it uses make variables. goffice-paths.h: Makefile diff --git a/lib/goffice-0.0.4/goffice/drawing/god-drawing-renderer-gdk.c b/lib/goffice-0.0.4/goffice/drawing/god-drawing-renderer-gdk.c index e5d7540927..c2240a0967 100644 --- a/lib/goffice-0.0.4/goffice/drawing/god-drawing-renderer-gdk.c +++ b/lib/goffice-0.0.4/goffice/drawing/god-drawing-renderer-gdk.c @@ -182,19 +182,12 @@ static gboolean make_absolute (PangoAttribute *attr, gpointer user_data) { DrawTextContext *draw_context = user_data; -#if HAVE_PANGO18 if (attr->klass->type == PANGO_ATTR_SIZE && ! ((PangoAttrSize *) attr)->absolute) { PangoAttrSize *size_attr = (PangoAttrSize *) attr; size_attr->size = GO_PT_TO_UN ((long long) size_attr->size) / draw_context->renderer->priv->y_units_per_pixel; size_attr->absolute = TRUE; } -#else - if (attr->klass->type == PANGO_ATTR_SIZE) { - PangoAttrInt *size_attr = (PangoAttrInt *) attr; - size_attr->value = GO_PT_TO_UN ((long long) size_attr->value) / draw_context->renderer->priv->y_units_per_pixel; - } -#endif // HAVE_PANGO18 return FALSE; } diff --git a/lib/goffice-0.0.4/goffice/glib24_26-compat.c b/lib/goffice-0.0.4/goffice/glib24_26-compat.c deleted file mode 100644 index e2ececb322..0000000000 --- a/lib/goffice-0.0.4/goffice/glib24_26-compat.c +++ /dev/null @@ -1,359 +0,0 @@ -#include - -#include - -static const guint16 days_in_year[2][14] = -{ /* 0, jan feb mar apr may jun jul aug sep oct nov dec */ - { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, - { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } -}; - -/* "Julian days" just means an absolute number of days, where Day 1 == - * Jan 1, Year 1 - */ -static void -g_date_update_julian (const GDate *const_d) -{ - GDate *d = (GDate *) const_d; - GDateYear year; - gint index; - - g_return_if_fail (d != NULL); - g_return_if_fail (d->dmy); - g_return_if_fail (!d->julian); - g_return_if_fail (g_date_valid_dmy (d->day, d->month, d->year)); - - /* What we actually do is: multiply years * 365 days in the year, - * add the number of years divided by 4, subtract the number of - * years divided by 100 and add the number of years divided by 400, - * which accounts for leap year stuff. Code from Steffen Beyer's - * DateCalc. - */ - - year = d->year - 1; /* we know d->year > 0 since it's valid */ - - d->julian_days = year * 365U; - d->julian_days += (year >>= 2); /* divide by 4 and add */ - d->julian_days -= (year /= 25); /* divides original # years by 100 */ - d->julian_days += year >> 2; /* divides by 4, which divides original by 400 */ - - index = g_date_is_leap_year (d->year) ? 1 : 0; - - d->julian_days += days_in_year[index][d->month] + d->day; - - g_return_if_fail (g_date_valid_julian (d->julian_days)); - - d->julian = TRUE; -} - -/** - * g_date_get_iso8601_week_of_year: - * @date: a valid #GDate - * - * Returns the week of the year, where weeks are interpreted according - * to ISO 8601. - * - * Returns: ISO 8601 week number of the year. - * - * Since: 2.6 - **/ -guint -g_date_get_iso8601_week_of_year (const GDate *d) -{ - guint j, d4, L, d1, w; - - g_return_val_if_fail (g_date_valid (d), 0); - - if (!d->julian) - g_date_update_julian (d); - g_return_val_if_fail (d->julian, 0); - - /* Formula taken from the Calendar FAQ; the formula was for the - * Julian Period which starts on 1 January 4713 BC, so we add - * 1,721,425 to the number of days before doing the formula. - */ - j = d->julian_days + 1721425; - d4 = (j + 31741 - (j % 7)) % 146097 % 36524 % 1461; - L = d4 / 1460; - d1 = ((d4 - L) % 365) + L; - w = d1 / 7 + 1; - - return w; -} - -/** ------------------------------------------------------------ **/ - -/* The following is (partly) taken from the gettext package. - Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. */ - -static const gchar * -guess_category_value (const gchar *category_name) -{ - const gchar *retval; - - /* The highest priority value is the `LANGUAGE' environment - variable. This is a GNU extension. */ - retval = g_getenv ("LANGUAGE"); - if ((retval != NULL) && (retval[0] != '\0')) - return retval; - - /* `LANGUAGE' is not set. So we have to proceed with the POSIX - methods of looking to `LC_ALL', `LC_xxx', and `LANG'. On some - systems this can be done by the `setlocale' function itself. */ - - /* Setting of LC_ALL overwrites all other. */ - retval = g_getenv ("LC_ALL"); - if ((retval != NULL) && (retval[0] != '\0')) - return retval; - - /* Next comes the name of the desired category. */ - retval = g_getenv (category_name); - if ((retval != NULL) && (retval[0] != '\0')) - return retval; - - /* Last possibility is the LANG environment variable. */ - retval = g_getenv ("LANG"); - if ((retval != NULL) && (retval[0] != '\0')) - return retval; - -#ifdef G_PLATFORM_WIN32 - /* g_win32_getlocale() first checks for LC_ALL, LC_MESSAGES and - * LANG, which we already did above. Oh well. The main point of - * calling g_win32_getlocale() is to get the thread's locale as used - * by Windows and the Microsoft C runtime (in the "English_United - * States" format) translated into the Unixish format. - */ - retval = g_win32_getlocale (); - if ((retval != NULL) && (retval[0] != '\0')) - return retval; -#endif - - return NULL; -} - -typedef struct _GLanguageNamesCache GLanguageNamesCache; - -struct _GLanguageNamesCache { - gchar *languages; - gchar **language_names; -}; - -static void -language_names_cache_free (gpointer data) -{ - GLanguageNamesCache *cache = data; - g_free (cache->languages); - g_strfreev (cache->language_names); - g_free (cache); -} - -static char * -unalias_lang (char *lang) -{ - return lang; -} - -/* Mask for components of locale spec. The ordering here is from - * least significant to most significant - */ -enum -{ - COMPONENT_CODESET = 1 << 0, - COMPONENT_TERRITORY = 1 << 1, - COMPONENT_MODIFIER = 1 << 2 -}; - -/* Break an X/Open style locale specification into components - */ -static guint -explode_locale (const gchar *locale, - gchar **language, - gchar **territory, - gchar **codeset, - gchar **modifier) -{ - const gchar *uscore_pos; - const gchar *at_pos; - const gchar *dot_pos; - - guint mask = 0; - - uscore_pos = strchr (locale, '_'); - dot_pos = strchr (uscore_pos ? uscore_pos : locale, '.'); - at_pos = strchr (dot_pos ? dot_pos : (uscore_pos ? uscore_pos : locale), '@'); - - if (at_pos) - { - mask |= COMPONENT_MODIFIER; - *modifier = g_strdup (at_pos); - } - else - at_pos = locale + strlen (locale); - - if (dot_pos) - { - mask |= COMPONENT_CODESET; - *codeset = g_strndup (dot_pos, at_pos - dot_pos); - } - else - dot_pos = at_pos; - - if (uscore_pos) - { - mask |= COMPONENT_TERRITORY; - *territory = g_strndup (uscore_pos, dot_pos - uscore_pos); - } - else - uscore_pos = dot_pos; - - *language = g_strndup (locale, uscore_pos - locale); - - return mask; -} - -/* - * Compute all interesting variants for a given locale name - - * by stripping off different components of the value. - * - * For simplicity, we assume that the locale is in - * X/Open format: language[_territory][.codeset][@modifier] - * - * TODO: Extend this to handle the CEN format (see the GNUlibc docs) - * as well. We could just copy the code from glibc wholesale - * but it is big, ugly, and complicated, so I'm reluctant - * to do so when this should handle 99% of the time... - */ -static GSList * -_g_compute_locale_variants (const gchar *locale) -{ - GSList *retval = NULL; - - gchar *language; - gchar *territory = NULL; - gchar *codeset = NULL; - gchar *modifier = NULL; - - guint mask; - guint i; - - g_return_val_if_fail (locale != NULL, NULL); - - mask = explode_locale (locale, &language, &territory, &codeset, &modifier); - - /* Iterate through all possible combinations, from least attractive - * to most attractive. - */ - for (i = 0; i <= mask; i++) - if ((i & ~mask) == 0) - { - gchar *val = g_strconcat (language, - (i & COMPONENT_TERRITORY) ? territory : "", - (i & COMPONENT_CODESET) ? codeset : "", - (i & COMPONENT_MODIFIER) ? modifier : "", - NULL); - retval = g_slist_prepend (retval, val); - } - - g_free (language); - if (mask & COMPONENT_CODESET) - g_free (codeset); - if (mask & COMPONENT_TERRITORY) - g_free (territory); - if (mask & COMPONENT_MODIFIER) - g_free (modifier); - - return retval; -} - -/** - * g_get_language_names: - * - * Computes a list of applicable locale names, which can be used to - * e.g. construct locale-dependent filenames or search paths. The returned - * list is sorted from most desirable to least desirable and always contains - * the default locale "C". - * - * For example, if LANGUAGE=de:en_US, then the returned list is - * "de", "en_US", "en", "C". - * - * This function consults the environment variables LANGUAGE, - * LC_ALL, LC_MESSAGES and LANG - * to find the list of locales specified by the user. - * - * Return value: a %NULL-terminated array of strings owned by GLib - * that must not be modified or freed. - * - * Since: 2.6 - **/ -G_CONST_RETURN gchar * G_CONST_RETURN * -g_get_language_names (void) -{ - static GStaticPrivate cache_private = G_STATIC_PRIVATE_INIT; - GLanguageNamesCache *cache = g_static_private_get (&cache_private); - const gchar *value; - - if (!cache) - { - cache = g_new0 (GLanguageNamesCache, 1); - g_static_private_set (&cache_private, cache, language_names_cache_free); - } - - value = guess_category_value ("LC_MESSAGES"); - if (!value) - value = "C"; - - if (!(cache->languages && strcmp (cache->languages, value) == 0)) - { - gchar **languages; - gchar **alist, **a; - GSList *list, *l; - gint i; - - g_free (cache->languages); - g_strfreev (cache->language_names); - cache->languages = g_strdup (value); - - alist = g_strsplit (value, ":", 0); - list = NULL; - for (a = alist; *a; a++) - { - gchar *b = unalias_lang (*a); - list = g_slist_concat (list, _g_compute_locale_variants (b)); - } - g_strfreev (alist); - list = g_slist_append (list, g_strdup ("C")); - - cache->language_names = languages = g_new (gchar *, g_slist_length (list) + 1); - for (l = list, i = 0; l; l = l->next, i++) - languages[i] = l->data; - languages[i] = NULL; - - g_slist_free (list); - } - - return (G_CONST_RETURN gchar * G_CONST_RETURN *) cache->language_names; -} - -/** - * g_strv_length: - * @str_array: a %NULL-terminated array of strings. - * - * Returns the length of the given %NULL-terminated - * string array @str_array. - * - * Return value: length of @str_array. - * - * Since: 2.6 - **/ -guint -g_strv_length (gchar **str_array) -{ - guint i = 0; - - g_return_val_if_fail (str_array != NULL, 0); - - while (str_array[i]) - ++i; - - return i; -} diff --git a/lib/goffice-0.0.4/goffice/glib24_26-compat.h b/lib/goffice-0.0.4/goffice/glib24_26-compat.h deleted file mode 100644 index 9703fe9fcb..0000000000 --- a/lib/goffice-0.0.4/goffice/glib24_26-compat.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef GLIB24_26_COMPAT_H -#define GLIB24_26_COMPAT_H - -#include - -/* from glib-2.6[.6] gdate.h */ -guint g_date_get_iso8601_week_of_year (const GDate *date); - -/* from glib-2.6[.6] gutils.h */ -G_CONST_RETURN gchar* G_CONST_RETURN * g_get_language_names (void); - -#ifdef G_OS_WIN32 - -/* On Win32, the canonical directory separator is the backslash, and - * the search path separator is the semicolon. Note that also the - * (forward) slash works as directory separator. - */ -#define G_DIR_SEPARATOR '\\' -#define G_DIR_SEPARATOR_S "\\" -#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/') -#define G_SEARCHPATH_SEPARATOR ';' -#define G_SEARCHPATH_SEPARATOR_S ";" - -#else /* !G_OS_WIN32 */ - -/* Unix */ - -#define G_DIR_SEPARATOR '/' -#define G_DIR_SEPARATOR_S "/" -#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR) -#define G_SEARCHPATH_SEPARATOR ':' -#define G_SEARCHPATH_SEPARATOR_S ":" - -#endif /* !G_OS_WIN32 */ - -/* from glib-2.6[.6] gstrfuncs.h */ -guint g_strv_length (gchar **str_array); - -#endif // GLIB24_26_COMPAT_H diff --git a/lib/goffice-0.0.4/goffice/graph/gog-chart.c b/lib/goffice-0.0.4/goffice/graph/gog-chart.c index 75ff88c5a0..ce0defdf12 100644 --- a/lib/goffice-0.0.4/goffice/graph/gog-chart.c +++ b/lib/goffice-0.0.4/goffice/graph/gog-chart.c @@ -41,10 +41,6 @@ #include #include -#ifndef HAVE_GLIB26 -#include "goffice/glib24_26-compat.h" -#endif - const struct { char const *name; GogAxisSet const axis_set; diff --git a/lib/goffice-0.0.4/goffice/graph/gog-object.c b/lib/goffice-0.0.4/goffice/graph/gog-object.c index f42c545c72..f210ba41d8 100644 --- a/lib/goffice-0.0.4/goffice/graph/gog-object.c +++ b/lib/goffice-0.0.4/goffice/graph/gog-object.c @@ -39,10 +39,6 @@ #include #include -#ifndef HAVE_GLIB26 -#include "goffice/glib24_26-compat.h" -#endif - GogEditor * gog_editor_new (void) { diff --git a/lib/goffice-0.0.4/goffice/graph/gog-plot.c b/lib/goffice-0.0.4/goffice/graph/gog-plot.c index 8194d384a1..4ac84dbb7e 100644 --- a/lib/goffice-0.0.4/goffice/graph/gog-plot.c +++ b/lib/goffice-0.0.4/goffice/graph/gog-plot.c @@ -43,10 +43,6 @@ #include #include -#ifndef HAVE_GLIB26 -#include "goffice/glib24_26-compat.h" -#endif - #define GOG_PLOT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GOG_PLOT_TYPE, GogPlotClass)) enum { diff --git a/lib/goffice-0.0.4/goffice/gtk/goffice-gtk.c b/lib/goffice-0.0.4/goffice/gtk/goffice-gtk.c index eec6030e5f..3be3041048 100644 --- a/lib/goffice-0.0.4/goffice/gtk/goffice-gtk.c +++ b/lib/goffice-0.0.4/goffice/gtk/goffice-gtk.c @@ -48,15 +48,6 @@ #include #include -#ifndef HAVE_GTK26 -// +jsled: maybe not needed due to cascading imports under gtk+-2.6? -#include -#endif - -#ifndef HAVE_GLIB26 -#include "goffice/glib24_26-compat.h" -#endif - #define PREVIEW_HSIZE 150 #define PREVIEW_VSIZE 150 diff --git a/lib/goffice-0.0.4/goffice/utils/datetime.c b/lib/goffice-0.0.4/goffice/utils/datetime.c index a102b78e5d..32b53a78b4 100644 --- a/lib/goffice-0.0.4/goffice/utils/datetime.c +++ b/lib/goffice-0.0.4/goffice/utils/datetime.c @@ -14,10 +14,6 @@ #include -#ifndef HAVE_GLIB26 -#include "goffice/glib24_26-compat.h" -#endif - #define SECS_PER_DAY (24 * 60 * 60) #define HALF_SEC (0.5 / SECS_PER_DAY) diff --git a/lib/goffice-0.0.4/goffice/utils/go-libxml-extras.c b/lib/goffice-0.0.4/goffice/utils/go-libxml-extras.c index 66926a2e10..6ddec5fc05 100644 --- a/lib/goffice-0.0.4/goffice/utils/go-libxml-extras.c +++ b/lib/goffice-0.0.4/goffice/utils/go-libxml-extras.c @@ -17,10 +17,6 @@ #include #include -#ifndef HAVE_GLIB26 -#include "goffice/glib24_26-compat.h" -#endif - #define CC2XML(s) ((xmlChar const *)(s)) #define CXML2C(s) ((char const *)(s)) diff --git a/lib/libgsf-1.12.3/gsf/Makefile.am b/lib/libgsf-1.12.3/gsf/Makefile.am index 3ff415466f..7b0f264c65 100644 --- a/lib/libgsf-1.12.3/gsf/Makefile.am +++ b/lib/libgsf-1.12.3/gsf/Makefile.am @@ -70,10 +70,6 @@ libgsf_1_la_SOURCES = \ # gsf-command-context.c \ # gsf-io-context.c -if !HAVE_GLIB26 - libgsf_1_la_SOURCES += glib24_26-compat.c -endif - libgsf_1_includedir = $(includedir)/libgsf-1/gsf noinst_HEADERS = \ gsf.h \ @@ -125,10 +121,6 @@ noinst_HEADERS = \ # gsf-command-context.h \ # gsf-io-context.h -if !HAVE_GLIB26 - noinst_HEADERS += glib24_26-compat.h -endif - install-data-local: install-libtool-import-lib uninstall-local: uninstall-libtool-import-lib diff --git a/lib/libgsf-1.12.3/gsf/glib24_26-compat.c b/lib/libgsf-1.12.3/gsf/glib24_26-compat.c deleted file mode 100644 index 70255b9d9b..0000000000 --- a/lib/libgsf-1.12.3/gsf/glib24_26-compat.c +++ /dev/null @@ -1,204 +0,0 @@ -/** jsled, 2005-11-08: copied from glib-2.6.6 to support libgsf compilation - against glib-2.4.14. **/ - -#include - -/* gstdio.c - wrappers for C library functions - * - * Copyright 2004 Tor Lillqvist - * - * GLib 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 of the - * License, or (at your option) any later version. - * - * GLib 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 GLib; see the file COPYING.LIB. If not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include "config.h" - -//#include -#include -//#include - -/** ------------------------------------------------------------ **/ -/* START gconvert.c */ - -#include -#include -#include - -typedef struct _GFilenameCharsetCache GFilenameCharsetCache; - -struct _GFilenameCharsetCache { - gboolean is_utf8; - gchar *charset; - gchar **filename_charsets; -}; - -/** - * g_get_filename_charsets: - * @charsets: return location for the %NULL-terminated list of encoding names - * - * Determines the preferred character sets used for filenames. - * The first character set from the @charsets is the filename encoding, the - * subsequent character sets are used when trying to generate a displayable - * representation of a filename, see g_filename_display_name(). - * - * On Unix, the character sets are determined by consulting the - * environment variables G_FILENAME_ENCODING and - * G_BROKEN_FILENAMES. On Windows, the character set - * used in the GLib API is always UTF-8 and said environment variables - * have no effect. - * - * G_FILENAME_ENCODING may be set to a comma-separated list - * of character set names. The special token "@locale" is taken to mean the - * character set for the current locale. If G_FILENAME_ENCODING - * is not set, but G_BROKEN_FILENAMES is, the character set of - * the current locale is taken as the filename encoding. If neither environment - * variable is set, UTF-8 is taken as the filename encoding, but the character - * set of the current locale is also put in the list of encodings. - * - * The returned @charsets belong to GLib and must not be freed. - * - * Note that on Unix, regardless of the locale character set or - * G_FILENAME_ENCODING value, the actual file names present on a - * system might be in any random encoding or just gibberish. - * - * Return value: %TRUE if the filename encoding is UTF-8. - * - * Since: 2.6 - */ -static gboolean -g_get_filename_charsets (G_CONST_RETURN gchar ***filename_charsets) -{ - static const gchar *charsets[] = { - "UTF-8", - NULL - }; - -#ifdef G_OS_WIN32 - /* On Windows GLib pretends that the filename charset is UTF-8 */ - if (filename_charsets) - *filename_charsets = charsets; - - return TRUE; -#else - gboolean result; - - /* Cygwin works like before */ - result = g_get_charset (&(charsets[0])); - - if (filename_charsets) - *filename_charsets = charsets; - - return result; -#endif -} - -static gchar * -make_valid_utf8 (const gchar *name) -{ - GString *string; - const gchar *remainder, *invalid; - gint remaining_bytes, valid_bytes; - - string = NULL; - remainder = name; - remaining_bytes = strlen (name); - - while (remaining_bytes != 0) - { - if (g_utf8_validate (remainder, remaining_bytes, &invalid)) - break; - valid_bytes = invalid - remainder; - - if (string == NULL) - string = g_string_sized_new (remaining_bytes); - - g_string_append_len (string, remainder, valid_bytes); - g_string_append_c (string, '?'); - - remaining_bytes -= valid_bytes + 1; - remainder = invalid + 1; - } - - if (string == NULL) - return g_strdup (name); - - g_string_append (string, remainder); - g_string_append (string, " (invalid encoding)"); - - g_assert (g_utf8_validate (string->str, -1, NULL)); - - return g_string_free (string, FALSE); -} - -/** - * g_filename_display_name: - * @filename: a pathname hopefully in the GLib file name encoding - * - * Converts a filename into a valid UTF-8 string. The - * conversion is not necessarily reversible, so you - * should keep the original around and use the return - * value of this function only for display purposes. - * Unlike g_filename_to_utf8(), the result is guaranteed - * to be non-NULL even if the filename actually isn't in the GLib - * file name encoding. - * - * If you know the whole pathname of the file you should use - * g_filename_display_basename(), since that allows location-based - * translation of filenames. - * - * Return value: a newly allocated string containing - * a rendition of the filename in valid UTF-8 - * - * Since: 2.6 - **/ -gchar * -g_filename_display_name (const gchar *filename) -{ - gint i; - const gchar **charsets; - gchar *display_name = NULL; - gboolean is_utf8; - - is_utf8 = g_get_filename_charsets (&charsets); - - if (is_utf8) - { - if (g_utf8_validate (filename, -1, NULL)) - display_name = g_strdup (filename); - } - - if (!display_name) - { - /* Try to convert from the filename charsets to UTF-8. - * Skip the first charset if it is UTF-8. - */ - for (i = is_utf8 ? 1 : 0; charsets[i]; i++) - { - display_name = g_convert (filename, -1, "UTF-8", charsets[i], - NULL, NULL, NULL); - - if (display_name) - break; - } - } - - /* if all conversions failed, we replace invalid UTF-8 - * by a question mark - */ - if (!display_name) - display_name = make_valid_utf8 (filename); - - return display_name; -} diff --git a/lib/libgsf-1.12.3/gsf/glib24_26-compat.h b/lib/libgsf-1.12.3/gsf/glib24_26-compat.h deleted file mode 100644 index ea609c1e3f..0000000000 --- a/lib/libgsf-1.12.3/gsf/glib24_26-compat.h +++ /dev/null @@ -1,79 +0,0 @@ -/* This file has been copied from glib-2.6.6 into libgsf-1.12.3 to support - * compilation against glib-2.4.14. -- jsled, 2005-11-08 - */ - -#ifndef __GLIB_24_26_COMPAT_H__ -#define __GLIB_24_26_COMPAT_H__ - -#include - -// START from gstdio.h -/* gstdio.h - GFilename wrappers for C library functions - * - * Copyright 2004 Tor Lillqvist - * - * GLib 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 of the - * License, or (at your option) any later version. - * - * GLib 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 GLib; see the file COPYING.LIB. If not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include - -/* Just pass on to the system functions, so there's no potential for data - * format mismatches, especially with large file interfaces. - */ - -#define g_open open -#define g_rename rename -#define g_mkdir mkdir -#define g_stat stat -#define g_lstat lstat -#define g_unlink unlink -#define g_remove remove -#define g_rmdir rmdir -#define g_fopen fopen -#define g_freopen freopen - -// END from gstdio.h - -// START from gconvert.h -gchar *g_filename_display_name (const gchar *filename); // G_GNUC_MALLOC; -// END from gconvert.h - -/* from glib-2.6[.6] gutils.h */ -#ifdef G_OS_WIN32 - -/* On Win32, the canonical directory separator is the backslash, and - * the search path separator is the semicolon. Note that also the - * (forward) slash works as directory separator. - */ -#define G_DIR_SEPARATOR '\\' -#define G_DIR_SEPARATOR_S "\\" -#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/') -#define G_SEARCHPATH_SEPARATOR ';' -#define G_SEARCHPATH_SEPARATOR_S ";" - -#else /* !G_OS_WIN32 */ - -/* Unix */ - -#define G_DIR_SEPARATOR '/' -#define G_DIR_SEPARATOR_S "/" -#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR) -#define G_SEARCHPATH_SEPARATOR ':' -#define G_SEARCHPATH_SEPARATOR_S ":" - -#endif /* !G_OS_WIN32 */ - -#endif /* __GLIB_24_26_COMPAT_H__ */ diff --git a/lib/libgsf-1.12.3/gsf/gsf-input-memory.c b/lib/libgsf-1.12.3/gsf/gsf-input-memory.c index aa808c5b50..b0702c7243 100644 --- a/lib/libgsf-1.12.3/gsf/gsf-input-memory.c +++ b/lib/libgsf-1.12.3/gsf/gsf-input-memory.c @@ -26,11 +26,7 @@ #include #include #include -#ifdef HAVE_GLIB26 #include -#else -#include "glib24_26-compat.h" -#endif // HAVE_GLIB26 #ifdef HAVE_MMAP diff --git a/lib/libgsf-1.12.3/gsf/gsf-input-stdio.c b/lib/libgsf-1.12.3/gsf/gsf-input-stdio.c index 09fa9876c8..33ef211680 100644 --- a/lib/libgsf-1.12.3/gsf/gsf-input-stdio.c +++ b/lib/libgsf-1.12.3/gsf/gsf-input-stdio.c @@ -24,11 +24,7 @@ #include #include #include -#ifdef HAVE_GLIB26 #include -#else -#include "glib24_26-compat.h" -#endif // HAVE_GLIB26 #include #include diff --git a/lib/libgsf-1.12.3/gsf/gsf-outfile-stdio.c b/lib/libgsf-1.12.3/gsf/gsf-outfile-stdio.c index 70c54c2491..9e2507e725 100644 --- a/lib/libgsf-1.12.3/gsf/gsf-outfile-stdio.c +++ b/lib/libgsf-1.12.3/gsf/gsf-outfile-stdio.c @@ -26,11 +26,7 @@ #include #include #include -#ifdef HAVE_GLIB26 #include -#else -#include "glib24_26-compat.h" -#endif // HAVE_GLIB26 #include #ifdef HAVE_UNISTD_H diff --git a/lib/libgsf-1.12.3/gsf/gsf-outfile-zip.c b/lib/libgsf-1.12.3/gsf/gsf-outfile-zip.c index 43e6104e6d..16a22537e1 100644 --- a/lib/libgsf-1.12.3/gsf/gsf-outfile-zip.c +++ b/lib/libgsf-1.12.3/gsf/gsf-outfile-zip.c @@ -30,10 +30,6 @@ #include #include -#ifndef HAVE_GLIB26 -#include -#endif - #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "libgsf:zip" diff --git a/lib/libgsf-1.12.3/gsf/gsf-output-stdio.c b/lib/libgsf-1.12.3/gsf/gsf-output-stdio.c index 4b436a1a42..0a6629a139 100644 --- a/lib/libgsf-1.12.3/gsf/gsf-output-stdio.c +++ b/lib/libgsf-1.12.3/gsf/gsf-output-stdio.c @@ -24,11 +24,7 @@ #include #include #include -#ifdef HAVE_GLIB26 #include -#else -#include "glib24_26-compat.h" -#endif // HAVE_GLIB26 #include #include diff --git a/lib/libgsf-1.12.3/gsf/gsf-utils.c b/lib/libgsf-1.12.3/gsf/gsf-utils.c index d9a6dc732a..c53e635883 100644 --- a/lib/libgsf-1.12.3/gsf/gsf-utils.c +++ b/lib/libgsf-1.12.3/gsf/gsf-utils.c @@ -29,10 +29,6 @@ #include #include -#ifndef HAVE_GLIB26 -#include -#endif - /* * Glib gets this wrong, really. ARM's floating point format is a weird * mixture. diff --git a/lib/libgsf-1.12.3/tests/test-cp-zip.c b/lib/libgsf-1.12.3/tests/test-cp-zip.c index 06842f8055..3128d65032 100644 --- a/lib/libgsf-1.12.3/tests/test-cp-zip.c +++ b/lib/libgsf-1.12.3/tests/test-cp-zip.c @@ -1,7 +1,3 @@ -#ifndef HAVE_GLIB26 - #include -#endif - /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * test-cp-zip.c: Test gsf-outfile-zip by cloning a file the hard way diff --git a/src/Makefile.am b/src/Makefile.am index 92e867d1b2..6e3527bb40 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -52,5 +52,4 @@ EXTRA_DIST = \ gnc-test-env \ valgrind-gnucash.supp \ guile-mappings.h \ - glib-compat.h \ - gtk-compat.h + glib-compat.h diff --git a/src/app-utils/file-utils.h b/src/app-utils/file-utils.h index 94d24aff9c..3a35c4c4ab 100644 --- a/src/app-utils/file-utils.h +++ b/src/app-utils/file-utils.h @@ -30,9 +30,6 @@ #define GNC_FILE_UTILS_H #include /* for FILE* */ -#ifndef HAVE_GLIB26 -#include "gkeyfile.h" -#endif char * gncFindFile (const char * filename); diff --git a/src/bin/gnucash-bin.c b/src/bin/gnucash-bin.c index 76382f4089..0edb91de29 100644 --- a/src/bin/gnucash-bin.c +++ b/src/bin/gnucash-bin.c @@ -197,56 +197,6 @@ gnucash_command_line(int *argc, char **argv) char *p; int debugging = 0; char *namespace_regexp = NULL; -#ifndef HAVE_GTK26 - poptContext pc; - int rc; - struct poptOption options[] = { - POPT_AUTOHELP - {"version", 'v', POPT_ARG_NONE, &gnucash_show_version, 1, - _("Show GnuCash version"), NULL}, - {"debug", '\0', POPT_ARG_NONE, &debugging, 0, - _("Enable debugging mode"), NULL}, - {"loglevel", '\0', POPT_ARG_INT, &loglevel, 0, - /* Translators: This is the command line option autohelp - text; see popt(3) */ - _("Set the logging level from 0 (least) to 6 (most)"), - /* Translators: Argument description for autohelp; see popt(3) */ - _("LOGLEVEL")}, - {"nofile", '\0', POPT_ARG_NONE, &nofile, 0, - _("Do not load the last file opened"), NULL}, - {"config-path", '\0', POPT_ARG_STRING, &config_path, 0, - _("Set configuration path"), - /* Translators: Argument description for autohelp; see popt(3) */ - _("CONFIGPATH")}, - {"share-path", '\0', POPT_ARG_STRING, &share_path, 0, - _("Set shared data file search path"), - /* Translators: Argument description for autohelp; see popt(3) */ - _("SHAREPATH")}, - {"doc-path", '\0', POPT_ARG_STRING, &help_path, 0, - _("Set the search path for documentation files"), - /* Translators: Argument description for autohelp; see popt(3) */ - _("DOCPATH")}, - {"add-price-quotes", '\0', POPT_ARG_STRING, &add_quotes_file, 0, - _("Add price quotes to given GnuCash datafile"), - /* Translators: Argument description for autohelp; see popt(3) */ - _("FILE")}, - {"namespace", '\0', POPT_ARG_STRING, &namespace_regexp, 0, - _("Regular expression determining which namespace commodities will be retrieved"), - /* Translators: Argument description for autohelp; see popt(3) */ - _("REGEXP")}, - POPT_TABLEEND - }; - - /* Pretend that argv[0] is "gnucash" */ - if ((p = strstr(argv[0], "-bin"))) *p = '\0'; - - pc = poptGetContext(NULL, *argc, (const char **)argv, options, 0); - poptSetOtherOptionHelp(pc, "[OPTIONS...] [datafile]"); - - while ((rc = poptGetNextOpt(pc)) > 0); - file_to_load = poptGetArg(pc); - poptFreeContext(pc); -#else GError *error = NULL; GOptionContext *context; GOptionEntry options[] = { @@ -302,7 +252,6 @@ gnucash_command_line(int *argc, char **argv) if (*argc > 0) file_to_load = argv[1]; -#endif if (gnucash_show_version) { if (is_development_version) diff --git a/src/business/business-gnome/dialog-invoice.c b/src/business/business-gnome/dialog-invoice.c index 181ecdcdfe..3023482dbd 100644 --- a/src/business/business-gnome/dialog-invoice.c +++ b/src/business/business-gnome/dialog-invoice.c @@ -53,10 +53,6 @@ #include "gncEntryLedger.h" -#ifndef HAVE_GLIB26 -#include "gkeyfile.h" -#endif - #include "gnc-plugin-page.h" #include "gnc-general-search.h" #include "dialog-date-close.h" diff --git a/src/core-utils/gnc-gkeyfile-utils.h b/src/core-utils/gnc-gkeyfile-utils.h index 0e51e88815..ab567efcde 100644 --- a/src/core-utils/gnc-gkeyfile-utils.h +++ b/src/core-utils/gnc-gkeyfile-utils.h @@ -37,10 +37,6 @@ #ifndef GNC_GKEYFILE_UTILS_H #define GNC_GKEYFILE_UTILS_H -#ifndef HAVE_GLIB26 -#include "gkeyfile.h" -#endif - /** Open and read a key/value file from disk into memory. * diff --git a/src/core-utils/gnc-gtk-utils.c b/src/core-utils/gnc-gtk-utils.c index 7b6002d9a9..52a58fb3c9 100644 --- a/src/core-utils/gnc-gtk-utils.c +++ b/src/core-utils/gnc-gtk-utils.c @@ -29,25 +29,6 @@ #define CHANGED_ID "changed_id" -#ifndef HAVE_GTK26 -/* Backwards compatability support for function introduced in gtk - * 2.6. */ -gchar * -gtk_combo_box_get_active_text (GtkComboBox *combo_box) -{ - GtkTreeModel *model; - GtkTreeIter iter; - gchar *text; - - if (!gtk_combo_box_get_active_iter(combo_box, &iter)) - return NULL; - model = gtk_combo_box_get_model(combo_box); - gtk_tree_model_get(model, &iter, 0, &text, -1); - return text; -} -#endif - - /** Find an entry in the GtkComboBoxEntry by its text value, and set * the widget to that value. This function also records the index of * that text value for use when the user leaves the widget. @@ -190,9 +171,7 @@ gnc_cbe_add_completion (GtkComboBoxEntry *cbe) model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbe)); gtk_entry_completion_set_model(completion, model); gtk_entry_completion_set_text_column(completion, 0); -#ifdef HAVE_GTK26 gtk_entry_completion_set_inline_completion(completion, TRUE); -#endif gtk_entry_set_completion(entry, completion); g_object_unref(completion); } diff --git a/src/core-utils/gnc-gtk-utils.h b/src/core-utils/gnc-gtk-utils.h index b20c5ea2c5..409b0727ae 100644 --- a/src/core-utils/gnc-gtk-utils.h +++ b/src/core-utils/gnc-gtk-utils.h @@ -39,16 +39,6 @@ #include -/** @name gtk Backwards Compatability Functions - @{ -*/ -#ifndef HAVE_GTK26 -gchar *gtk_combo_box_get_active_text (GtkComboBox *combo_box); -#endif - -/** @} */ - - /** @name gtk Miscellaneous Functions @{ */ diff --git a/src/engine/gnc-filepath-utils.c b/src/engine/gnc-filepath-utils.c index 14a1ec6207..ffb495c649 100644 --- a/src/engine/gnc-filepath-utils.c +++ b/src/engine/gnc-filepath-utils.c @@ -35,11 +35,7 @@ #include #include #include -#ifdef HAVE_GLIB26 #include -#else -#define g_mkdir(a,b) mkdir(a,b) -#endif #include #include diff --git a/src/gnome-utils/dialog-account.c b/src/gnome-utils/dialog-account.c index 8070d8762a..e39df5204b 100644 --- a/src/gnome-utils/dialog-account.c +++ b/src/gnome-utils/dialog-account.c @@ -25,9 +25,6 @@ #include "config.h" #include -#ifndef HAVE_GLIB26 -#include "gutils26.h" -#endif #include #include #include diff --git a/src/gnome-utils/dialog-options.c b/src/gnome-utils/dialog-options.c index 89ed9e4bb7..fc74a1d0e9 100644 --- a/src/gnome-utils/dialog-options.c +++ b/src/gnome-utils/dialog-options.c @@ -23,12 +23,7 @@ #include "config.h" -#ifdef HAVE_GTK26 #include -#else -#undef GNOME_DISABLE_DEPRECATED -#include -#endif #include #include #include "swig-runtime.h" @@ -221,7 +216,6 @@ gnc_rd_option_rel_set_cb(GtkWidget *widget, gpointer *raw_option) return; } -#ifdef HAVE_GTK26 static void gnc_image_option_update_preview_cb (GtkFileChooser *chooser, GNCOption *option) @@ -269,14 +263,6 @@ gnc_image_option_selection_changed_cb (GtkFileChooser *chooser, return; g_object_set_data_full(G_OBJECT(chooser), LAST_SELECTION, filename, g_free); } -#else -static void -gnc_image_option_clear_selection_cb (GtkButton *button, - GtkEntry *entry) -{ - gtk_entry_set_text(entry, ""); -} -#endif /********************************************************************\ * gnc_option_set_ui_value_internal * @@ -1999,9 +1985,6 @@ gnc_option_set_ui_widget_pixmap (GNCOption *option, GtkBox *page_box, GtkWidget *value; GtkWidget *label; GtkWidget *button; -#ifndef HAVE_GTK26 - GtkWidget *entry; -#endif gchar *colon_name; ENTER("option %p(%s), name %s", option, gnc_option_name(option), name); @@ -2015,7 +1998,6 @@ gnc_option_set_ui_widget_pixmap (GNCOption *option, GtkBox *page_box, button = gtk_button_new_with_label(_("Clear")); gtk_tooltips_set_tip(tooltips, button, _("Clear any selected image file."), NULL); -#ifdef HAVE_GTK26 value = gtk_file_chooser_button_new(_("Select image"), GTK_FILE_CHOOSER_ACTION_OPEN); gtk_tooltips_set_tip(tooltips, value, _("Select an image file."), NULL); @@ -2031,19 +2013,7 @@ gnc_option_set_ui_widget_pixmap (GNCOption *option, GtkBox *page_box, G_CALLBACK(gnc_image_option_update_preview_cb), option); g_signal_connect_swapped(G_OBJECT (button), "clicked", G_CALLBACK(gtk_file_chooser_unselect_all), value); -#else - value = gnome_pixmap_entry_new(NULL, _("Select pixmap"), - FALSE); - gtk_tooltips_set_tip(tooltips, value, _("Select an image file."), NULL); - gnome_pixmap_entry_set_preview(GNOME_PIXMAP_ENTRY(value), FALSE); - entry = gnome_pixmap_entry_gtk_entry (GNOME_PIXMAP_ENTRY(value)); - g_signal_connect(G_OBJECT (entry), "changed", - G_CALLBACK(gnc_option_changed_widget_cb), option); - g_signal_connect(G_OBJECT (button), "clicked", - G_CALLBACK(gnc_image_option_clear_selection_cb), entry); -#endif - gnc_option_set_widget (option, value); gnc_option_set_ui_value(option, FALSE); @@ -2490,7 +2460,6 @@ gnc_option_set_ui_value_pixmap (GNCOption *option, gboolean use_default, if (string && *string) { -#ifdef HAVE_GTK26 gchar *test; DEBUG("string = %s", string); gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(widget), string); @@ -2499,12 +2468,6 @@ gnc_option_set_ui_value_pixmap (GNCOption *option, gboolean use_default, g_strdup(string), g_free); DEBUG("Set %s, retrieved %s", string, test); gnc_image_option_update_preview_cb(GTK_FILE_CHOOSER(widget), option); -#else - GtkEntry *entry; - DEBUG("string = %s", string); - entry = GTK_ENTRY(gnome_pixmap_entry_gtk_entry(GNOME_PIXMAP_ENTRY(widget))); - gtk_entry_set_text(entry, string); -#endif } LEAVE("FALSE"); return FALSE; @@ -2880,7 +2843,6 @@ gnc_option_get_ui_value_font (GNCOption *option, GtkWidget *widget) static SCM gnc_option_get_ui_value_pixmap (GNCOption *option, GtkWidget *widget) { -#ifdef HAVE_GTK26 gchar *string; SCM result; @@ -2890,12 +2852,6 @@ gnc_option_get_ui_value_pixmap (GNCOption *option, GtkWidget *widget) if (string) g_free(string); return result; -#else - GnomePixmapEntry * p = GNOME_PIXMAP_ENTRY(widget); - char * string = gnome_pixmap_entry_get_filename(p); - - return (scm_makfrom0str(string ? string : "")); -#endif } static SCM diff --git a/src/gnome-utils/dialog-utils.c b/src/gnome-utils/dialog-utils.c index 9aac7b77e9..a721d575f9 100644 --- a/src/gnome-utils/dialog-utils.c +++ b/src/gnome-utils/dialog-utils.c @@ -905,16 +905,12 @@ gnc_gtk_dialog_add_button (GtkWidget *dialog, const gchar *label, const gchar *s GtkWidget *button; button = gtk_button_new_with_label(label); -#ifdef HAVE_GTK26 if (stock_id) { GtkWidget *image; image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON); gtk_button_set_image(GTK_BUTTON(button), image); } -#else - gtk_button_set_use_underline(GTK_BUTTON(button), TRUE); -#endif gtk_widget_show_all(button); gtk_dialog_add_action_widget(GTK_DIALOG(dialog), button, response); } @@ -983,61 +979,3 @@ gnc_dialog_run (GtkDialog *dialog, const gchar *gconf_key) return response; } - -#ifndef HAVE_GTK26 - -/** Find the first GtkLabel in a container. When called on a gtk2.4 - * message dialog, there is only one label in the dialog so theis - * should return it. */ -static void -find_label (GtkWidget *widget, gpointer data) -{ - GtkWidget **label = data; - - if (*label) - return; - - if (GTK_IS_LABEL(widget)) { - *label = widget; - return; - } - - if (GTK_IS_CONTAINER(widget)) { - gtk_container_foreach(GTK_CONTAINER(widget), find_label, data); - } -} - -/** Mimic the gtk2.6 function to add secondary information to a - * message dialog. */ -void -gtk_message_dialog_format_secondary_text(GtkMessageDialog *dialog, - const gchar *format, - ...) -{ - GtkWidget *label = NULL; - const gchar *current; - gchar *primary, *secondary; - va_list args; - - gtk_container_foreach(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), - find_label, &label); - if (!label) - return; - - /* Get the current markup. */ - current = gtk_label_get_label(GTK_LABEL(label)); - - /* Format the text to be added. */ - va_start(args, format); - secondary = g_strdup_vprintf(format, args); - va_end(args); - - /* Append the two strings, making the first one bold. */ - primary = g_strdup_printf("%s\n\n%s", current, secondary); - gtk_label_set_markup(GTK_LABEL(label), primary); - - g_free(primary); - g_free(secondary); -} - -#endif diff --git a/src/gnome-utils/dialog-utils.h b/src/gnome-utils/dialog-utils.h index 13e5c8593b..ada9c969bd 100644 --- a/src/gnome-utils/dialog-utils.h +++ b/src/gnome-utils/dialog-utils.h @@ -152,11 +152,4 @@ void gnc_gtk_dialog_add_button (GtkWidget *dialog, gint gnc_dialog_run(GtkDialog *dialog, const gchar *gconf_key); -#ifndef HAVE_GTK26 -void -gtk_message_dialog_format_secondary_text(GtkMessageDialog *dialog, - const gchar *message_format, - ...) G_GNUC_PRINTF (2, 3); -#endif - #endif diff --git a/src/gnome-utils/gnc-main-window.c b/src/gnome-utils/gnc-main-window.c index 34dfd78569..5ee3e3e008 100644 --- a/src/gnome-utils/gnc-main-window.c +++ b/src/gnome-utils/gnc-main-window.c @@ -39,10 +39,6 @@ #include #include #include "guile-mappings.h" -#ifndef HAVE_GLIB26 -#include "gkeyfile.h" -#endif -#include "gtk-compat.h" #include "gnc-plugin.h" #include "gnc-plugin-manager.h" @@ -3278,7 +3274,6 @@ gnc_main_window_cmd_help_contents (GtkAction *action, GncMainWindow *window) gnc_gnome_help (HF_HELP, NULL); } -#ifdef HAVE_GTK26 /** This is a helper function to find a data file and suck it into * memory. * @@ -3380,47 +3375,6 @@ gnc_main_window_cmd_help_about (GtkAction *action, GncMainWindow *window) if (authors) g_strfreev(authors); g_object_unref (logo); } -#else -static void -gnc_main_window_cmd_help_about (GtkAction *action, GncMainWindow *window) -{ - GtkWidget *about; - /* Translators: This is the "About" message. */ - const gchar *message = _("The GnuCash personal finance manager.\n" - "The GNU way to manage your money!\n" - "http://www.gnucash.org/"); - const gchar *copyright = "© 1998-2002 Linas Vepstas"; - const gchar *authors[] = { - "Derek Atkins ", - "Rob Browning ", - "Bill Gribble ", - "David Hampton ", - "James LewisMoss ", - "Robert Graham Merkel ", - "Dave Peticolas ", - "Joshua Sled ", - "Christian Stimming ", - "Linas Vepstas ", - NULL - }; - const gchar *documenters[] = { - NULL - }; - /* Translators: Insert your translator's credits here so that - they will be shown in the "About" dialog. */ - const gchar *translator_credits = _("translator_credits"); - GdkPixbuf *logo; - - logo = gnc_gnome_get_gdkpixbuf ("appicon.png"); - - about = gnome_about_new ("GnuCash", VERSION, copyright, message, authors, documenters, - strcmp (translator_credits, "translator_credits") != 0 ? translator_credits : NULL, - logo); - - g_object_unref (logo); - gtk_dialog_run (GTK_DIALOG (about)); -} -#endif /************************************************************ diff --git a/src/gnome-utils/gnc-plugin-file-history.c b/src/gnome-utils/gnc-plugin-file-history.c index 5de199e45b..4c00126d0a 100644 --- a/src/gnome-utils/gnc-plugin-file-history.c +++ b/src/gnome-utils/gnc-plugin-file-history.c @@ -34,7 +34,6 @@ #include #include #include -#include "gtk-compat.h" #include #include "gnc-gkeyfile-utils.h" diff --git a/src/gnome-utils/gnc-plugin-page.h b/src/gnome-utils/gnc-plugin-page.h index e9f44c00f0..c5eda12427 100644 --- a/src/gnome-utils/gnc-plugin-page.h +++ b/src/gnome-utils/gnc-plugin-page.h @@ -50,10 +50,6 @@ G_BEGIN_DECLS #define GNC_PLUGIN_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_PLUGIN_PAGE, GncPluginPageClass)) /* typedefs & structures */ -#ifndef HAVE_GLIB26 -#include "gkeyfile.h" -#endif - /** The instance data structure for a content plugin. */ typedef struct GncPluginPage { diff --git a/src/gnome-utils/gnc-tree-view-account.c b/src/gnome-utils/gnc-tree-view-account.c index 6437abcea0..fa1f456191 100644 --- a/src/gnome-utils/gnc-tree-view-account.c +++ b/src/gnome-utils/gnc-tree-view-account.c @@ -28,10 +28,6 @@ #include #include -#ifndef HAVE_GLIB26 -#include "gkeyfile.h" -#endif - #include "gnc-tree-view.h" #include "gnc-tree-model-account.h" #include "gnc-tree-model-account-types.h" diff --git a/src/gnome-utils/gnc-tree-view.c b/src/gnome-utils/gnc-tree-view.c index ec3114fd4f..37fc803563 100644 --- a/src/gnome-utils/gnc-tree-view.c +++ b/src/gnome-utils/gnc-tree-view.c @@ -1918,7 +1918,6 @@ gnc_tree_view_add_text_column (GncTreeView *view, return column; } -#if HAVE_GTK26 GtkTreeViewColumn * gnc_tree_view_add_combo_column (GncTreeView *view, const gchar *column_title, @@ -1976,7 +1975,6 @@ gnc_tree_view_add_combo_column (GncTreeView *view, gnc_tree_view_append_column (view, column); return column; } -#endif GtkCellRenderer * gnc_tree_view_column_get_renderer(GtkTreeViewColumn *column) diff --git a/src/gnome-utils/gnc-tree-view.h b/src/gnome-utils/gnc-tree-view.h index 9636c8bae0..b694282ac9 100644 --- a/src/gnome-utils/gnc-tree-view.h +++ b/src/gnome-utils/gnc-tree-view.h @@ -188,7 +188,7 @@ gnc_tree_view_add_text_column (GncTreeView *view, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn); -#if HAVE_GTK26 + /** This function adds a new combobox column to a GncTreeView base * view. The parameters it takes in common with * gnc_tree_view_add_text_column() behave the same as there. In @@ -206,7 +206,6 @@ gnc_tree_view_add_combo_column (GncTreeView *view, GtkTreeModel *combo_tree_model, gint combo_model_text_column, GtkTreeIterCompareFunc column_sort_fn); -#endif /** This function adds a new numeric column to a GncTreeView base * view. It takes all the parameters necessary to hook a diff --git a/src/gnome-utils/gnctreemodelsort.c b/src/gnome-utils/gnctreemodelsort.c index 28bf02c74a..8c0e11889f 100644 --- a/src/gnome-utils/gnctreemodelsort.c +++ b/src/gnome-utils/gnctreemodelsort.c @@ -58,7 +58,6 @@ Plus some minor changes that have been annotated with 'CAS:' #include "gtk/gtktreednd.h" //CAS: path changed //#include "gtk/gtkalias.h" //CAS: header commented #include //CAS: header added -#include "gtk-compat.h" //CAS: header added #define P_(x) _(x) //CAS: macro added typedef struct _SortElt SortElt; diff --git a/src/gnome/gnc-plugin-page-account-tree.c b/src/gnome/gnc-plugin-page-account-tree.c index f98aab04bd..81aeb6c6d2 100644 --- a/src/gnome/gnc-plugin-page-account-tree.c +++ b/src/gnome/gnc-plugin-page-account-tree.c @@ -36,9 +36,6 @@ #include #include -#ifndef HAVE_GLIB26 -#include "gkeyfile.h" -#endif #include "gnc-plugin-page-account-tree.h" #include "gnc-plugin-page-register.h" diff --git a/src/gnome/gnc-plugin-page-budget.c b/src/gnome/gnc-plugin-page-budget.c index c7d3737f65..2809d1685d 100644 --- a/src/gnome/gnc-plugin-page-budget.c +++ b/src/gnome/gnc-plugin-page-budget.c @@ -39,10 +39,6 @@ #include #include "gnc-date-edit.h" -#ifndef HAVE_GLIB26 -#include "gkeyfile.h" -#endif - #include "gnc-plugin-page-register.h" #include "gnc-budget.h" diff --git a/src/gnome/gnc-plugin-page-register.c b/src/gnome/gnc-plugin-page-register.c index 69810389e3..e2df41281c 100644 --- a/src/gnome/gnc-plugin-page-register.c +++ b/src/gnome/gnc-plugin-page-register.c @@ -38,9 +38,6 @@ #include "guile-mappings.h" #include #include -#ifndef HAVE_GLIB26 -#include "gkeyfile.h" -#endif #include "swig-runtime.h" #include "gnc-plugin-page-register.h" @@ -76,8 +73,6 @@ #include "window-reconcile.h" #include "window-report.h" -#include "gtk-compat.h" - /* This static indicates the debugging module that this .o belongs to. */ static QofLogModule log_module = GNC_MOD_GUI; diff --git a/src/gnome/gnc-plugin-page-sx-list.c b/src/gnome/gnc-plugin-page-sx-list.c index 6251a3ae2c..31536663d0 100644 --- a/src/gnome/gnc-plugin-page-sx-list.c +++ b/src/gnome/gnc-plugin-page-sx-list.c @@ -39,9 +39,6 @@ #include #include #include -#ifndef HAVE_GLIB26 -#include "gkeyfile.h" -#endif #include "gnc-exp-parser.h" #include "gnc-engine.h" #include "Transaction.h" diff --git a/src/gnome/window-reconcile.c b/src/gnome/window-reconcile.c index 5992c705a7..fd65a06711 100644 --- a/src/gnome/window-reconcile.c +++ b/src/gnome/window-reconcile.c @@ -31,7 +31,6 @@ #include "config.h" #include -#include "gtk-compat.h" #include #include "Scrub.h" diff --git a/src/gtk-compat.h b/src/gtk-compat.h deleted file mode 100644 index 321d3c8430..0000000000 --- a/src/gtk-compat.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * gtk-compat.h - GTK version compatability mappings - * Copyright (C) 2006, David Hampton - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#ifndef HAVE_GTK26 -#define gtk_action_set_sensitive(action, xxx) \ - g_object_set((action), "sensitive", (xxx), NULL) -#define gtk_action_set_visible(action, xxx) \ - g_object_set((action), "visible", (xxx), NULL) - -#define GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID -2 -#endif - diff --git a/src/import-export/hbci/dialog-hbcitrans.c b/src/import-export/hbci/dialog-hbcitrans.c index 78ecd3e73b..918b313128 100644 --- a/src/import-export/hbci/dialog-hbcitrans.c +++ b/src/import-export/hbci/dialog-hbcitrans.c @@ -43,7 +43,6 @@ #endif #include -#include "gtk-compat.h" #include "dialog-utils.h" #include "gnc-glib-utils.h" #include "gnc-ui.h" diff --git a/src/register/register-gnome/gnucash-item-list.c b/src/register/register-gnome/gnucash-item-list.c index b90fbf2d16..bac391f9d7 100644 --- a/src/register/register-gnome/gnucash-item-list.c +++ b/src/register/register-gnome/gnucash-item-list.c @@ -35,7 +35,6 @@ #include "gnc-engine.h" #include "gnucash-item-list.h" #include "gnucash-scrolled-window.h" -#include "gtk-compat.h" /* Item list signals */ enum { diff --git a/src/report/report-gnome/gnc-plugin-page-report.c b/src/report/report-gnome/gnc-plugin-page-report.c index aeec9653e2..2018fb1e86 100644 --- a/src/report/report-gnome/gnc-plugin-page-report.c +++ b/src/report/report-gnome/gnc-plugin-page-report.c @@ -41,10 +41,6 @@ #include #include -#include "gtk-compat.h" -#ifndef HAVE_GLIB26 -#include "gkeyfile.h" -#endif #include #include #include