[vte/vte-0-32] Use a GResource for our default termcap
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/vte-0-32] Use a GResource for our default termcap
- Date: Wed, 15 Feb 2012 01:00:17 +0000 (UTC)
commit c7cab4b852e4958e71207e90c16ea33d3d591967
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 | 44 ++++++----------------------
src/vte.gresource.xml.in | 22 ++++++++++++++
src/vtetc.c | 69 +++++++++++++++++++++++++++++++++++----------
src/vtetc.h | 2 +-
termcaps/Makefile.am | 12 +------
9 files changed, 117 insertions(+), 82 deletions(-)
---
diff --git a/configure.in b/configure.in
index 970cfa3..5fa8704 100644
--- a/configure.in
+++ b/configure.in
@@ -195,23 +195,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)
@@ -379,6 +380,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 1971458..d8f8fd4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -72,6 +72,7 @@ libvte VTE_LIBRARY_SUFFIX_U@_la_SOURCES = \
vtepty-private.h \
vteregex.c \
vteregex.h \
+ vteresources.c \
vterowdata.c \
vterowdata.h \
vteseq.c \
@@ -93,10 +94,10 @@ libvte VTE_LIBRARY_SUFFIX_U@_la_SOURCES = \
libvte VTE_LIBRARY_SUFFIX_U@_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)
@@ -113,10 +114,10 @@ libvte VTE_LIBRARY_SUFFIX_U@_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 $< > $@
@@ -150,6 +151,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
@@ -233,14 +236,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 782d05b..2d73423 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 fae0c56..981bc79 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -152,7 +152,6 @@ struct _VteTerminalPrivate {
/* 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_terminal_flags { /* boolean termcap flags */
gboolean am;
diff --git a/src/vte.c b/src/vte.c
index fa30e6c..9f74405 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -82,8 +82,7 @@ typedef gunichar wint_t;
static void vte_terminal_set_visibility (VteTerminal *terminal, GdkVisibilityState state);
-static void vte_terminal_set_termcap(VteTerminal *terminal, const char *path,
- gboolean reset);
+static void vte_terminal_set_termcap(VteTerminal *terminal);
static void vte_terminal_paste(VteTerminal *terminal, GdkAtom board);
static void vte_terminal_real_copy_clipboard(VteTerminal *terminal);
static void vte_terminal_real_paste_clipboard(VteTerminal *terminal);
@@ -8192,7 +8191,7 @@ vte_terminal_set_emulation(VteTerminal *terminal, const char *emulation)
_vte_debug_print(VTE_DEBUG_MISC,
"Setting emulation to `%s'...\n", emulation);
/* Find and read the right termcap file. */
- vte_terminal_set_termcap(terminal, NULL, FALSE);
+ vte_terminal_set_termcap(terminal);
/* Create a table to hold the control sequences. */
if (terminal->pvt->matcher != NULL) {
@@ -8296,50 +8295,27 @@ _vte_terminal_inline_error_message(VteTerminal *terminal, const char *format, ..
/* Set the path to the termcap file we read, and read it in. */
static void
-vte_terminal_set_termcap(VteTerminal *terminal, const char *path,
- gboolean reset)
+vte_terminal_set_termcap(VteTerminal *terminal)
{
GObject *object = G_OBJECT(terminal);
- struct stat st;
- char *wpath;
-
- if (path == NULL) {
- wpath = g_build_filename(TERMCAPDIR,
- terminal->pvt->emulation ?
- terminal->pvt->emulation :
- vte_terminal_get_default_emulation(terminal),
- 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 == terminal->pvt->termcap_path) {
- return;
- }
+ const char *emulation;
g_object_freeze_notify(object);
- terminal->pvt->termcap_path = path;
+ emulation = terminal->pvt->emulation ? terminal->pvt->emulation
+ : vte_terminal_get_default_emulation(terminal);
_vte_debug_print(VTE_DEBUG_MISC, "Loading termcap `%s'...",
- terminal->pvt->termcap_path);
+ emulation);
if (terminal->pvt->termcap != NULL) {
_vte_termcap_free(terminal->pvt->termcap);
}
- terminal->pvt->termcap = _vte_termcap_new(terminal->pvt->termcap_path);
+ terminal->pvt->termcap = _vte_termcap_new(emulation);
_vte_debug_print(VTE_DEBUG_MISC, "\n");
if (terminal->pvt->termcap == NULL) {
_vte_terminal_inline_error_message(terminal,
- "Failed to load terminal capabilities from '%s'",
- terminal->pvt->termcap_path);
- }
- if (reset) {
- vte_terminal_set_emulation(terminal, terminal->pvt->emulation);
+ "Failed to load terminal 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 88e814c..2a76f38 100644
--- a/src/vtetc.c
+++ b/src/vtetc.c
@@ -20,6 +20,7 @@
#include <string.h>
#include <stdlib.h>
#include <glib.h>
+#include <gio/gio.h>
#include "vtetc.h"
@@ -28,7 +29,7 @@
*/
typedef struct _vte_termcap
{
- GMappedFile *file;
+ GBytes *data;
GTree *tree;
const char *end;
} VteTermcap;
@@ -470,35 +471,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),
+ file,
+ (GDestroyNotify) g_mapped_file_unref);
+
+ 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);
}
@@ -509,7 +546,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;
@@ -522,7 +559,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);
@@ -559,7 +596,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 d1bab8d..968945e 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]