[vte/vte-next] Use a GResource for our default termcap
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/vte-next] Use a GResource for our default termcap
- Date: Wed, 15 Feb 2012 01:13:02 +0000 (UTC)
commit 1093e3abd20b69ced9a3d73b78025f3aabb0fa7f
Author: Christian Persch <chpe gnome org>
Date: Wed Feb 15 01:59:28 2012 +0100
Use a GResource for our default termcap
configure.in | 24 ++++++++-------
src/Makefile.am | 15 ++++++---
src/interpret.c | 10 ++++--
src/vte-private.h | 1 -
src/vte.c | 45 ++++++-----------------------
src/vte.gresource.xml.in | 22 ++++++++++++++
src/vtetc.c | 69 +++++++++++++++++++++++++++++++++++----------
src/vtetc.h | 2 +-
termcaps/Makefile.am | 12 +------
9 files changed, 117 insertions(+), 83 deletions(-)
---
diff --git a/configure.in b/configure.in
index be38ac7..a7db000 100644
--- a/configure.in
+++ b/configure.in
@@ -203,23 +203,24 @@ case $host in
;;
esac
-GLIB_REQUIRED=2.26.0
+GLIB_REQUIRED=2.31.13
+GIO_REQUIRED=2.31.13
PANGO_REQUIRED=1.22.0
AC_DEFINE(GDK_MULTIHEAD_SAFE,1,[Force use of GDK's multihead-safe APIs.])
-PKG_CHECK_MODULES(GLIB,[glib-2.0 >= $GLIB_REQUIRED gobject-2.0])
-PKG_CHECK_MODULES(GTK,[glib-2.0 >= $GLIB_REQUIRED gobject-2.0 gtk+-$GTK_API_VERSION >= $GTK_REQUIRED])
+PKG_CHECK_MODULES(GLIB,[glib-2.0 >= $GLIB_REQUIRED gobject-2.0 gio-2.0 >= $GIO_REQUIRED])
+PKG_CHECK_MODULES(GTK,[glib-2.0 >= $GLIB_REQUIRED gobject-2.0 gio-2.0 >= $GIO_REQUIRED gtk+-$GTK_API_VERSION >= $GTK_REQUIRED])
AC_PATH_PROG([GLIB_GENMARSHAL],[glib-genmarshal])
AC_PATH_PROG([GLIB_MKENUMS],[glib-mkenums])
-# Let the user specify the default terminal emulation.
-AC_ARG_WITH(default-emulation,
-AS_HELP_STRING(--with-default-emulation=xterm,default terminal type to be emulated),
-emulation=$withval,emulation=xterm)
-AC_DEFINE_UNQUOTED(VTE_DEFAULT_EMULATION,"$emulation",[The default terminal type to be emulated.])
-VTE_DEFAULT_EMULATION=$emulation
-AC_SUBST(VTE_DEFAULT_EMULATION)
-AM_CONDITIONAL(VTE_DEFAULT_EMULATION, [test "$emulation" != xterm])
+AC_ARG_VAR([GLIB_COMPILE_RESOURCES],[the glib-compile-resources programme])
+AC_PATH_PROG([GLIB_COMPILE_RESOURCES],[glib-compile-resources],[])
+if test -z "$GLIB_COMPILE_RESOURCES"; then
+ AC_MSG_ERROR([glib-compile-resources not found])
+fi
+
+VTE_DEFAULT_EMULATION=xterm
+AC_DEFINE_UNQUOTED(VTE_DEFAULT_EMULATION,"$VTE_DEFAULT_EMULATION",[The default terminal type to be emulated.])
# Check for headers.
AC_CHECK_HEADERS(sys/select.h sys/syslimits.h sys/termios.h sys/un.h sys/wait.h stropts.h termios.h wchar.h)
@@ -376,6 +377,7 @@ AC_CONFIG_FILES([
Makefile
src/Makefile
src/vteversion.h
+src/vte.gresource.xml
termcaps/Makefile
perf/Makefile
po/Makefile.in
diff --git a/src/Makefile.am b/src/Makefile.am
index 34ff916..17e44e6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -66,6 +66,7 @@ libvte_ VTE_API_MAJOR_VERSION@_ VTE_API_MINOR_VERSION@_la_SOURCES = \
vtepalettecss.h \
vtepty.h \
vtepty-private.h \
+ vteresources.c \
vterowdata.c \
vterowdata.h \
vteseq.c \
@@ -87,10 +88,10 @@ libvte_ VTE_API_MAJOR_VERSION@_ VTE_API_MINOR_VERSION@_la_SOURCES = \
libvte_ VTE_API_MAJOR_VERSION@_ VTE_API_MINOR_VERSION@_la_CPPFLAGS = \
-DG_LOG_DOMAIN=\"Vte-$(VTE_API_VERSION)\" \
+ -DVTE_API_VERSION=\"$(VTE_API_VERSION)\" \
-DDATADIR='"$(datadir)"' \
-DLIBEXECDIR='"$(libexecdir)"' \
-DLOCALEDIR='"$(localedir)"' \
- -DTERMCAPDIR='"$(pkgdatadir)/termcap-$(VTE_API_VERSION)"' \
-DVTE_COMPILATION \
$(AM_CPPFLAGS)
@@ -107,10 +108,10 @@ libvte_ VTE_API_MAJOR_VERSION@_ VTE_API_MINOR_VERSION@_la_LDFLAGS = \
# Generated sources
VTESEQ_BUILTSOURCES = vteseq-list.h vteseq-2.c vteseq-n.c
-BUILT_SOURCES = marshal.c marshal.h vtetypebuiltins.c vtetypebuiltins.h $(VTESEQ_BUILTSOURCES)
+BUILT_SOURCES = marshal.c marshal.h vtetypebuiltins.c vtetypebuiltins.h vteresources.c $(VTESEQ_BUILTSOURCES)
MAINTAINERCLEANFILES = $(VTESEQ_BUILTSOURCES)
EXTRA_DIST += $(VTESEQ_BUILTSOURCES)
-CLEANFILES = marshal.c marshal.h vtetypebuiltins.c vtetypebuiltins.h stamp-vtetypebuiltins.h
+CLEANFILES = marshal.c marshal.h vtetypebuiltins.c vtetypebuiltins.h stamp-vtetypebuiltins.h vteresources.c
marshal.c: marshal.list
$(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix=_vte_marshal --header --body --internal $< > $@
@@ -144,6 +145,8 @@ vteseq-list.h: vteseq-2.gperf vteseq-n.gperf
cat $^ | grep -v '^#' | grep '\<VTE_SEQUENCE_HANDLER\>'| sed 's/.*, //' | LANG=C sort -u >> $ tmp && \
mv -f $ tmp $@
+vteresources.c: vte.gresource.xml Makefile $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies vte.gresource.xml)
+ $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target $@ --sourcedir . --generate --c-name vte $<
# vte the application
@@ -238,14 +241,16 @@ interpret_SOURCES = \
trie.h \
vteconv.c \
vteconv.h \
+ vteresources.c \
vtetc.c \
vtetc.h \
vtetree.c \
vtetree.h \
interpret.c
interpret_CPPFLAGS = \
- -DINTERPRET_MAIN \
- -DTERMCAPDIR='"$(pkgdatadir)/termcap-$(VTE_API_VERSION)"'
+ -DINTERPRET_MAIN \
+ -DVTE_API_VERSION=\"$(VTE_API_VERSION)\" \
+ $(AM_CPPFLAGS)
interpret_CFLAGS = $(GTK_CFLAGS)
interpret_LDADD = $(GTK_LIBS)
diff --git a/src/interpret.c b/src/interpret.c
index e0d5e5e..92dbbe6 100644
--- a/src/interpret.c
+++ b/src/interpret.c
@@ -72,10 +72,12 @@ main(int argc, char **argv)
g_type_init();
terminal = argv[1];
- termcap = _vte_termcap_new(g_build_filename(TERMCAPDIR, terminal, NULL));
- if (termcap == NULL) {
- termcap = _vte_termcap_new("/etc/termcap");
- }
+ termcap = _vte_termcap_new(terminal);
+ if (termcap == NULL) {
+ g_printerr ("No termcap entry for '%s'\n", terminal);
+ return 1;
+ }
+
array = g_array_new(FALSE, FALSE, sizeof(gunichar));
matcher = _vte_matcher_new(terminal, termcap);
diff --git a/src/vte-private.h b/src/vte-private.h
index 6d8dd3e..b31b126 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -170,7 +170,6 @@ struct _VteBufferPrivate {
/* Emulation setup data. */
struct _vte_termcap *termcap; /* termcap storage */
struct _vte_matcher *matcher; /* control sequence matcher */
- const char *termcap_path; /* path to termcap file */
const char *emulation; /* terminal type to emulate */
struct vte_view_flags { /* boolean termcap flags */
gboolean am;
diff --git a/src/vte.c b/src/vte.c
index 7dfc565..fad6ff0 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -74,8 +74,7 @@ static void vte_view_emit_paste_clipboard(VteView *terminal);
static void vte_view_emit_copy_primary(VteView *terminal);
static void vte_view_emit_paste_primary(VteView *terminal);
static void vte_view_set_visibility (VteView *terminal, GdkVisibilityState state);
-static void vte_buffer_set_termcap(VteBuffer *buffer, const char *path,
- gboolean reset);
+static void vte_buffer_set_termcap(VteBuffer *buffer);
static gboolean vte_buffer_io_read(GIOChannel *channel,
GIOCondition condition,
VteBuffer *buffer);
@@ -7843,7 +7842,7 @@ vte_buffer_set_emulation(VteBuffer *buffer, const char *emulation)
_vte_debug_print(VTE_DEBUG_MISC,
"Setting emulation to `%s'...\n", emulation);
/* Find and read the right termcap file. */
- vte_buffer_set_termcap(buffer, NULL, FALSE);
+ vte_buffer_set_termcap(buffer);
/* Create a table to hold the control sequences. */
if (buffer->pvt->matcher != NULL) {
@@ -7950,51 +7949,27 @@ vte_buffer_inline_error_message(VteBuffer *buffer,
/* Set the path to the termcap file we read, and read it in. */
static void
-vte_buffer_set_termcap(VteBuffer *buffer,
- const char *path,
- gboolean reset)
+vte_buffer_set_termcap(VteBuffer *buffer)
{
GObject *object = G_OBJECT(buffer);
- struct stat st;
- char *wpath;
-
- if (path == NULL) {
- wpath = g_build_filename(TERMCAPDIR,
- buffer->pvt->emulation ?
- buffer->pvt->emulation :
- vte_get_default_emulation(),
- NULL);
- if (g_stat(wpath, &st) != 0) {
- g_free(wpath);
- wpath = g_strdup("/etc/termcap");
- }
- path = g_intern_string (wpath);
- g_free(wpath);
- } else {
- path = g_intern_string (path);
- }
- if (path == buffer->pvt->termcap_path) {
- return;
- }
+ const char *emulation;
g_object_freeze_notify(object);
- buffer->pvt->termcap_path = path;
+ emulation = buffer->pvt->emulation ? buffer->pvt->emulation
+ : vte_get_default_emulation();
_vte_debug_print(VTE_DEBUG_MISC, "Loading termcap `%s'...",
- buffer->pvt->termcap_path);
+ emulation);
if (buffer->pvt->termcap != NULL) {
_vte_termcap_free(buffer->pvt->termcap);
}
- buffer->pvt->termcap = _vte_termcap_new(buffer->pvt->termcap_path);
+ buffer->pvt->termcap = _vte_termcap_new(emulation);
_vte_debug_print(VTE_DEBUG_MISC, "\n");
if (buffer->pvt->termcap == NULL) {
vte_buffer_inline_error_message(buffer,
- "Failed to load buffer capabilities from '%s'",
- buffer->pvt->termcap_path);
- }
- if (reset) {
- vte_buffer_set_emulation(buffer, buffer->pvt->emulation);
+ "Failed to load buffer capabilities for '%s'",
+ emulation);
}
g_object_thaw_notify(object);
diff --git a/src/vte.gresource.xml.in b/src/vte.gresource.xml.in
new file mode 100644
index 0000000..c04a134
--- /dev/null
+++ b/src/vte.gresource.xml.in
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright  2012 Christian Persch
+
+ This program 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, or (at your option)
+ any later version.
+
+ This program is distributed in the hope conf 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 program. If not, see <http://www.gnu.org/licenses/>.
+-->
+<gresources>
+ <gresource prefix="/org/gnome/vte/@VTE_API_VERSION@/termcap">
+ <file alias="xterm">@top_srcdir@/termcaps/xterm</file>
+ </gresource>
+</gresources>
diff --git a/src/vtetc.c b/src/vtetc.c
index 15ede1e..9b103e5 100644
--- a/src/vtetc.c
+++ b/src/vtetc.c
@@ -26,6 +26,7 @@
#include <string.h>
#include <stdlib.h>
#include <glib.h>
+#include <gio/gio.h>
#include "vtetc.h"
@@ -34,7 +35,7 @@
*/
typedef struct _vte_termcap
{
- GMappedFile *file;
+ GBytes *data;
GTree *tree;
const char *end;
} VteTermcap;
@@ -476,35 +477,71 @@ _vte_termcap_parse_file (const char *contents, int length)
}
static VteTermcap *
-_vte_termcap_create (const char *filename)
+_vte_termcap_new_take_bytes (GBytes *data)
{
- const char *contents;
VteTermcap *termcap;
- GMappedFile *file;
- int length;
-
- file = g_mapped_file_new (filename, FALSE, NULL);
- if (file == NULL)
- return NULL;
+ const char *contents;
+ gsize length;
- contents = g_mapped_file_get_contents (file);
- length = g_mapped_file_get_length (file);
+ contents = g_bytes_get_data (data, &length);
termcap = g_slice_new (VteTermcap);
- termcap->file = file;
+ termcap->data = data; /* adopted */
termcap->tree = _vte_termcap_parse_file (contents, length);
termcap->end = contents + length;
return termcap;
}
+static VteTermcap *
+_vte_termcap_new_from_file (const char *path)
+{
+ GMappedFile *file;
+ GBytes *data;
+
+ file = g_mapped_file_new (path, FALSE, NULL);
+ if (file == NULL)
+ return NULL;
+
+ data = g_bytes_new_with_free_func (g_mapped_file_get_contents (file),
+ g_mapped_file_get_length (file),
+ (GDestroyNotify) g_mapped_file_unref,
+ file);
+
+ return _vte_termcap_new_take_bytes (data);
+}
+
+static VteTermcap *
+_vte_termcap_create (const char *name)
+{
+#ifdef VTE_API_VERSION
+ char *path;
+ GBytes *data;
+
+ /* First try the builtin termcaps */
+ path = g_build_path ("/",
+ "/org/gnome/vte",
+ VTE_API_VERSION,
+ "termcap",
+ name,
+ NULL);
+ data = g_resources_lookup_data (path, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
+ g_free(path);
+ if (data != NULL)
+ return _vte_termcap_new_take_bytes (data);
+#endif /* VTE_API_VERSION */
+
+ /* Try /etc/termcap */
+ return _vte_termcap_new_from_file ("/etc/termcap");
+}
+
static void
_vte_termcap_destroy (VteTermcap *termcap)
{
if (!termcap)
return;
g_tree_destroy (termcap->tree);
- g_mapped_file_unref (termcap->file);
+ g_bytes_unref (termcap->data);
g_slice_free (VteTermcap, termcap);
}
@@ -515,7 +552,7 @@ static GStaticMutex _vte_termcap_mutex = G_STATIC_MUTEX_INIT;
static GCache *_vte_termcap_cache = NULL;
VteTermcap *
-_vte_termcap_new(const char *filename)
+_vte_termcap_new(const char *name)
{
VteTermcap *result;
@@ -528,7 +565,7 @@ _vte_termcap_new(const char *filename)
(GCacheDestroyFunc) g_free,
g_str_hash, g_direct_hash, g_str_equal);
- result = g_cache_insert (_vte_termcap_cache, (gpointer) filename);
+ result = g_cache_insert (_vte_termcap_cache, (gpointer) name);
g_static_mutex_unlock (&_vte_termcap_mutex);
@@ -565,7 +602,7 @@ main (int argc, char **argv)
return 1;
}
- tc = _vte_termcap_new (argv[1]);
+ tc = _vte_termcap_new_from_file (argv[1]);
if (tc == NULL)
{
diff --git a/src/vtetc.h b/src/vtetc.h
index 51c39bd..dfe41f8 100644
--- a/src/vtetc.h
+++ b/src/vtetc.h
@@ -29,7 +29,7 @@ G_BEGIN_DECLS
struct _vte_termcap;
/* Create a new termcap structure. */
-struct _vte_termcap *_vte_termcap_new(const char *filename);
+struct _vte_termcap *_vte_termcap_new(const char *name);
/* Free a termcap structure. */
void _vte_termcap_free(struct _vte_termcap *termcap);
diff --git a/termcaps/Makefile.am b/termcaps/Makefile.am
index 965071b..da5eeae 100644
--- a/termcaps/Makefile.am
+++ b/termcaps/Makefile.am
@@ -1,12 +1,4 @@
-EXTRA_DIST = xterm xterm.baseline
-termcapdir = $(pkgdatadir)/termcap-$(VTE_API_VERSION)
-termcap_DATA = xterm
-
-if VTE_DEFAULT_EMULATION
-termcap_DATA += $(VTE_DEFAULT_EMULATION)
-$(VTE_DEFAULT_EMULATION): xterm
- $(AM_V_GEN) $(SED) -e s,^xterm:,$(VTE_DEFAULT_EMULATION):,g \
- -e s,^xterm\|,$(VTE_DEFAULT_EMULATION)\|,g $< > $@
-endif
+EXTRA_DIST = xterm.baseline
+dist_noinst_DATA = xterm
-include $(top_srcdir)/git.mk
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]