[genius] Be better at finding termcap file



commit a5ea5573ba464dd08ae0f5fd6cbf07bd4620bdb8
Author: Jiri (George) Lebl <jiri lebl gmail com>
Date:   Mon May 14 16:35:25 2018 -0500

    Be better at finding termcap file

 src/calc.h          |    2 +
 src/genius.c        |    2 +-
 src/gnome-genius.c  |    2 +-
 vte/src/Makefile.am |    3 +-
 vte/src/vte.c       |   54 ++++++++++++++++++++++++++++++++++++++++++--------
 5 files changed, 51 insertions(+), 12 deletions(-)
---
diff --git a/src/calc.h b/src/calc.h
index cdd213d..647430d 100644
--- a/src/calc.h
+++ b/src/calc.h
@@ -237,4 +237,6 @@ extern GelOutput *gel_main_out;
 
 extern gboolean gel_got_eof;
 
+extern gboolean genius_in_dev_dir;
+
 #endif /* CALC_H_ */
diff --git a/src/genius.c b/src/genius.c
index 62bb0f3..e76a406 100644
--- a/src/genius.c
+++ b/src/genius.c
@@ -94,7 +94,7 @@ extern int parenth_depth;
 
 static int use_readline = TRUE;
 
-static gboolean genius_in_dev_dir = FALSE;
+gboolean genius_in_dev_dir = FALSE;
 
 static int errors_printed = 0;
 static long total_errors_printed = 0;
diff --git a/src/gnome-genius.c b/src/gnome-genius.c
index 2736178..04860c4 100644
--- a/src/gnome-genius.c
+++ b/src/gnome-genius.c
@@ -134,7 +134,7 @@ static GList *prog_menu_items = NULL;
 static char *genius_datadir = NULL;
 static char *genius_datadir_sourceview = NULL;
 
-static gboolean genius_in_dev_dir = FALSE;
+gboolean genius_in_dev_dir = FALSE;
 
 static gboolean genius_do_not_use_binreloc = FALSE;
 
diff --git a/vte/src/Makefile.am b/vte/src/Makefile.am
index 3e690cf..4b79083 100644
--- a/vte/src/Makefile.am
+++ b/vte/src/Makefile.am
@@ -95,8 +95,9 @@ libvte_a_CPPFLAGS = \
        -DDATADIR='"$(datadir)"' \
        -DLIBEXECDIR='"$(libexecdir)"' \
        -DLOCALEDIR='"$(localedir)"' \
-       -DTERMCAPDIR='"$(datadir)/genius"' \
        -DVTE_COMPILATION \
+       -I$(top_srcdir)/src \
+       -I$(top_builddir)/src \
        $(AM_CPPFLAGS)
 
 libvte_a_CFLAGS = $(VTE_CFLAGS) $(AM_CFLAGS)
diff --git a/vte/src/vte.c b/vte/src/vte.c
index 695d327..da7c3d3 100644
--- a/vte/src/vte.c
+++ b/vte/src/vte.c
@@ -59,6 +59,10 @@
 #include "vteregex.h"
 #include "vtetc.h"
 
+#include "binreloc.h"
+#include "calc.h"
+
+
 #ifdef HAVE_LOCALE_H
 #include <locale.h>
 #endif
@@ -8272,14 +8276,46 @@ vte_terminal_set_termcap(VteTerminal *terminal, const char *path,
        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");
+               char *datadir = gbr_find_data_dir (DATADIR);
+               char *origpath;
+               wpath = g_build_filename (datadir,
+                                         "genius",
+                                         terminal->pvt->emulation ?
+                                         terminal->pvt->emulation :
+                                         vte_terminal_get_default_emulation(terminal),
+                                         NULL);
+               origpath = g_strdup(wpath);
+               if (access (wpath, F_OK) != 0) {
+                       g_free (wpath);
+                       wpath = g_build_filename (datadir,
+                                                 "genius",
+                                                 "xterm",
+                                                 NULL);
+               }
+               if (access (wpath, F_OK) != 0) {
+                       g_free (wpath);
+                       wpath = g_build_filename (DATADIR,
+                                                 "genius",
+                                                 "xterm",
+                                                 NULL);
+               }
+
+               /* hmmm, maybe we're in the build directory, one more attempt */
+               if (genius_in_dev_dir && access(wpath, F_OK) != 0) {
+                       wpath = g_build_filename ("..",
+                                                 "vte",
+                                                 "termcaps",
+                                                 "xterm",
+                                                 NULL);
+               }
+
+               /* if we still can't find it, reset path to our preferred place
+                * so that we report that in the error */
+               if (access (wpath, F_OK) != 0) {
+                       g_free (wpath);
+                       wpath = origpath;
+               } else {
+                       g_free(origpath);
                }
                path = g_intern_string (wpath);
                g_free(wpath);
@@ -8303,7 +8339,7 @@ vte_terminal_set_termcap(VteTerminal *terminal, const char *path,
        _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'",
+                               "BROKEN GENIUS INSTALL!\nFailed to load terminal capabilities from '%s'",
                                terminal->pvt->termcap_path);
        }
        if (reset) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]