Skip to content

Commit

Permalink
src: Convert gtk_compose_seqs_compact to GResource
Browse files Browse the repository at this point in the history
en-US Compose table had been a compact array with a special
algorithm but now it's converted to the general compose table
similar to other language compose tables and saved to GResource.
  • Loading branch information
fujiwarat committed Jan 5, 2023
1 parent f3a7772 commit 19ca106
Show file tree
Hide file tree
Showing 13 changed files with 559 additions and 5,721 deletions.
37 changes: 35 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# ibus - The Input Bus
#
# Copyright (c) 2007-2016 Peng Huang <shawn.p.huang@gmail.com>
# Copyright (c) 2015-2022 Takao Fujiwara <takao.fujiwara1@gmail.com>
# Copyright (c) 2007-2022 Red Hat, Inc.
# Copyright (c) 2015-2023 Takao Fujiwara <takao.fujiwara1@gmail.com>
# Copyright (c) 2007-2023 Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -151,6 +151,37 @@ AC_CHECK_FUNCS(daemon)
AC_CHECK_LIB(c, dlclose, LIBDL="", [AC_CHECK_LIB(dl, dlclose, LIBDL="-ldl")])
AC_SUBST(LIBDL)

# Check endianness.
AC_MSG_CHECKING([build system endianness])
ENDIAN=unknown
AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
[[
#include <endian.h>
#if __BYTE_ORDER != __LITTLE_ENDIAN
#error
#endif
]]
)],
[ENDIAN=little]
)
AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
[[
#include <endian.h>
#if __BYTE_ORDER != __BIG_ENDIAN
#error
#endif
]]
)],
[ENDIAN=big]
)
if test x"$ENDIAN" != xlittle -a x"$ENDIAN" != xbig; then
AC_MSG_ERROR([Cannot deermine endianness without endian.h])
fi
AC_MSG_RESULT($ENDIAN)
AC_SUBST(ENDIAN)

# Check packages.
# Check glib2.
AM_PATH_GLIB_2_0
Expand Down Expand Up @@ -844,6 +875,7 @@ m4/Makefile
portal/Makefile
setup/Makefile
src/Makefile
src/compose/Makefile
src/ibusversion.h
src/tests/Makefile
tools/Makefile
Expand All @@ -863,6 +895,7 @@ Build options:
Install prefix $prefix
Build shared libs $enable_shared
Build static libs $enable_static
Build endianness $ENDIAN
CFLAGS $CFLAGS
PYTHON $PYTHON
PYTHON2 $PYTHON2
Expand Down
68 changes: 56 additions & 12 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ibus - The Input Bus
#
# Copyright (c) 2007-2015 Peng Huang <shawn.p.huang@gmail.com>
# Copyright (c) 2015-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
# Copyright (c) 2015-2023 Takao Fujiwara <takao.fujiwara1@gmail.com>
# Copyright (c) 2007-2017 Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
Expand All @@ -27,7 +27,7 @@ if ENABLE_TESTS
TESTS_DIR = tests
endif

SUBDIRS = . $(TESTS_DIR)
SUBDIRS = . compose $(TESTS_DIR)

# libibus = libibus-@IBUS_API_VERSION@.la
libibus = libibus-1.0.la
Expand All @@ -41,7 +41,7 @@ INTROSPECTION_COMPILER_ARGS = \
$(NULL)
INTROSPECTION_GIRS =
CLEANFILES =
noinst_PROGRAMS =
noinst_PROGRAMS = gen-internal-compose-table

# C preprocessor flags
AM_CPPFLAGS = \
Expand Down Expand Up @@ -111,6 +111,7 @@ libibus_1_0_la_SOURCES = \
ibuscomposetable.c \
ibusenumtypes.c \
ibusmarshalers.c \
ibusresources.c \
$(ibus_sources) \
$(NULL)
ibus_marshalers_sources = \
Expand All @@ -121,6 +122,10 @@ ibus_enumtypes_sources = \
ibusenumtypes.c \
ibusenumtypes.h \
$(NULL)
ibus_resources_sources = \
ibusresources.c \
ibusresources.h \
$(NULL)
ibus_headers = \
ibus.h \
ibusaccelgroup.h \
Expand Down Expand Up @@ -171,21 +176,36 @@ ibusinclude_HEADERS = \
$(ibus_public_headers) \
$(NULL)
ibus_private_headers = \
gtkimcontextsimpleseqs.h \
ibuscomposetable.h \
ibusemojigen.h \
ibusenginesimpleprivate.h \
ibusinternal.h \
ibusresources.h \
ibusunicodegen.h \
keyname-table.h \
$(NULL)
noinst_HEADERS = \
$(ibus_private_headers) \
$(NULL)

gen_internal_compose_table_SOURCES = \
gencomposetable.c \
ibuscomposetable.c \
ibuserror.c \
ibuskeynames.c \
ibuskeyuni.c \
$(NULL)
gen_internal_compose_table_CFLAGS = $(AM_CFLAGS)
gen_internal_compose_table_LDADD = \
@GLIB2_LIBS@ \
@GOBJECT2_LIBS@ \
@GIO2_LIBS@ \
$(NULL)

BUILT_SOURCES = \
$(ibus_marshalers_sources) \
$(ibus_enumtypes_sources) \
$(ibus_resources_sources) \
$(NULL)

if HAVE_INTROSPECTION
Expand Down Expand Up @@ -242,6 +262,28 @@ ibusmarshalers.c: ibusmarshalers.h ibusmarshalers.list
$(GLIB_GENMARSHAL) --prefix=_ibus_marshal $(srcdir)/ibusmarshalers.list --body --internal) > $@.tmp && \
mv $@.tmp $@

# gen GResource
ibus.gresources.xml: ibus.gresources.xml.in
$(AM_V_GEN) sed -e "s|\@ENDIAN\@|$(ENDIAN)|g" \
$< > $@.tmp && \
mv $@.tmp $@

compose/sequences-$(ENDIAN)-endian: gen-internal-compose-table
$(AM_V_GEN) $(MKDIR_P) $(builddir)/compose && \
$(builddir)/gen-internal-compose-table && \
mv $(builddir)/sequences-big-endian $(builddir)/compose && \
mv $(builddir)/sequences-little-endian $(builddir)/compose

ibusresources.h: ibus.gresources.xml compose/sequences-$(ENDIAN)-endian
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --generate-header --internal \
--target=ibusresources.h --external-data --c-name _ibus \
--manual-register ibus.gresources.xml

ibusresources.c: ibus.gresources.xml compose/sequences-$(ENDIAN)-endian
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --generate-source --internal \
--target=ibusresources.c --c-name _ibus --manual-register \
ibus.gresources.xml

if ENABLE_EMOJI_DICT
AM_CPPFLAGS += -DENABLE_EMOJI_DICT

Expand Down Expand Up @@ -330,10 +372,6 @@ emoji_parser_LDADD = \
$(GLIB2_LIBS) \
$(GOBJECT2_LIBS) \
$(NULL)

clean-local:
-rm -rf dicts
$(NULL)
endif

if ENABLE_UNICODE_DICT
Expand Down Expand Up @@ -377,14 +415,11 @@ unicode_parser_LDADD = \
$(GLIB2_LIBS) \
$(libibus) \
$(NULL)

clean-local:
-rm -rf dicts
$(NULL)
endif

EXTRA_DIST = \
emoji-parser.c \
ibus.gresources.xml.in \
ibusversion.h.in \
ibusmarshalers.list \
ibusenumtypes.h.template \
Expand All @@ -394,6 +429,7 @@ EXTRA_DIST = \

CLEANFILES += \
$(BUILT_SOURCES) \
ibus.gresources.xml \
stamp-ibusmarshalers.h \
stamp-ibusenumtypes.h \
$(NULL)
Expand All @@ -410,4 +446,12 @@ DISTCLEANFILES = \
ibusversion.h \
$(NULL)

clean-local:
-rm -rf dicts; \
if test x"$(srcdir)" != x"$(builddir)" ; then \
rm -f $(builddir)/compose/sequences-big-endian; \
rm -f $(builddir)/compose/sequences-little-endian; \
fi;
$(NULL)

-include $(top_srcdir)/git.mk
33 changes: 33 additions & 0 deletions src/compose/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# vim:set noet ts=4:
#
# ibus - The Input Bus
#
# Copyright (c) 2023 Takao Fujiwara <takao.fujiwara1@gmail.com>
# Copyright (c) 2023 Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# USA

MAINTAINERCLEANFILES = \
sequences-big-endian \
sequences-little-endian \
$(NULL)

EXTRA_DIST = \
sequences-big-endian \
sequences-little-endian \
$(NULL)

-include $(top_srcdir)/git.mk
Empty file.
Empty file.
118 changes: 118 additions & 0 deletions src/gencomposetable.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
/* vim:set et sts=4: */
/* ibus - The Input Bus
* Copyright (C) 2023 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright (C) 2023 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/

#include <ibus.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <errno.h>

#include "ibuscomposetable.h"
#include "ibusenginesimpleprivate.h"

#define X11_DATADIR X11_DATA_PREFIX "/share/X11/locale"


static void
save_compose_table_endianness (IBusComposeTableEx *compose_table,
gboolean reverse_endianness)
{
GVariant *variant_table = NULL;
const char *contents = NULL;
gsize length = 0;
const char *destname_be = "sequences-big-endian";
const char *destname_le = "sequences-little-endian";
const char *destname;
GError *error = NULL;

variant_table = ibus_compose_table_serialize (compose_table,
reverse_endianness);
g_assert (variant_table);
contents = g_variant_get_data (variant_table);
length = g_variant_get_size (variant_table);
g_assert (contents && (length > 0));
#if G_BYTE_ORDER == G_BIG_ENDIAN
if (!reverse_endianness)
destname = destname_be;
else
destname = destname_le;
#else
if (!reverse_endianness)
destname = destname_le;
else
destname = destname_be;
#endif
if (g_file_test (destname, G_FILE_TEST_EXISTS))
g_unlink (destname);
if (!g_file_set_contents (destname, contents, length, &error)) {
g_warning ("Failed to save compose table %s: %s",
destname, error->message);
g_error_free (error);
}
g_variant_unref (variant_table);
}


int
main (int argc, char *argv[])
{
char * const sys_langs[] = { "en_US.UTF-8", "en_US", "en", NULL };
char * const *sys_lang = NULL;
char *path = NULL;
IBusComposeTableEx *compose_table;
char *basename = NULL;

path = g_strdup ("./Compose");
if (!path || !g_file_test (path, G_FILE_TEST_EXISTS)) {
g_clear_pointer (&path, g_free);
for (sys_lang = sys_langs; *sys_lang; sys_lang++) {
path = g_build_filename (X11_DATADIR, *sys_lang,
"Compose", NULL);
if (!path)
continue;
if (g_file_test (path, G_FILE_TEST_EXISTS))
break;
}
}
if (!path) {
g_warning ("en_US compose file is not found in %s.", X11_DATADIR);
return 1;
} else {
g_debug ("Create a cache of %s", path);
}
g_setenv ("IBUS_COMPOSE_CACHE_DIR", ".", TRUE);
compose_table = ibus_compose_table_load_cache (path);
if (!compose_table &&
(compose_table = ibus_compose_table_new_with_file (path, NULL))
== NULL) {
g_warning ("Failed to generate the compose table.");
return 1;
}
g_free (path);
basename = g_strdup_printf ("%08x.cache", compose_table->id);
g_debug ("Saving cache id %s", basename);
g_free (basename);


save_compose_table_endianness (compose_table, FALSE);
save_compose_table_endianness (compose_table, TRUE);
return 0;
}
Loading

0 comments on commit 19ca106

Please sign in to comment.